From 5e9ae478ac1220433a1c3bcad45985454034f01f Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Wed, 14 Sep 1994 03:10:15 +0000 Subject: [PATCH] Shuffle some functions and variables around to make it possible for multicast routing to be implemented as an LKM. (There's still a bit of work to do in this area.) --- sys/conf/files | 7 +---- sys/net/route.c | 7 ++--- sys/netinet/igmp.c | 6 +---- sys/netinet/in_proto.c | 8 ++---- sys/netinet/ip_input.c | 4 +-- sys/netinet/ip_mroute.c | 58 ++++++++++++++++++++++++++++++++--------- sys/netinet/ip_mroute.h | 6 ++--- sys/netinet/ip_output.c | 12 +++++---- sys/netinet/ip_var.h | 4 +-- sys/netinet/raw_ip.c | 10 +------ 10 files changed, 66 insertions(+), 56 deletions(-) diff --git a/sys/conf/files b/sys/conf/files index bc9d1ae80c3f..3ba963bf57f2 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -68,11 +68,6 @@ kern/subr_xxx.c standard kern/sys_generic.c standard kern/sys_process.c standard kern/sys_socket.c standard -kern/sysv_ipc.c optional sysvshm -kern/sysv_ipc.c optional sysvmsg -kern/sysv_ipc.c optional sysvsem -kern/sysv_msg.c optional sysvmsg -kern/sysv_sem.c optional sysvsem kern/sysv_shm.c optional sysvshm kern/tty.c standard kern/tty_compat.c standard @@ -166,7 +161,7 @@ netinet/in_pcb.c optional inet netinet/in_proto.c optional inet netinet/ip_icmp.c optional inet netinet/ip_input.c optional inet -netinet/ip_mroute.c optional inet mrouting +netinet/ip_mroute.c optional inet netinet/ip_output.c optional inet netinet/raw_ip.c optional inet netinet/tcp_debug.c optional inet diff --git a/sys/net/route.c b/sys/net/route.c index ca9c68c92b0b..e1d730d116c0 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)route.c 8.2 (Berkeley) 11/15/93 - * $Id: route.c,v 1.5 1994/09/07 19:50:42 se Exp $ + * $Id: route.c,v 1.6 1994/09/08 00:17:22 wollman Exp $ */ #include @@ -273,12 +273,9 @@ rtioctl(req, data, p) caddr_t data; struct proc *p; { -#ifdef MROUTING + extern int (*mrt_ioctl)(int, caddr_t, struct proc *); /* Multicast goop, grrr... */ return mrt_ioctl(req, data, p); -#else - return (EOPNOTSUPP); -#endif } struct ifaddr * diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index ca1db1ea69d2..0986acf303a1 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * @(#)igmp.c 8.1 (Berkeley) 7/19/93 - * $Id: igmp.c,v 1.3 1994/08/02 07:48:04 davidg Exp $ + * $Id: igmp.c,v 1.4 1994/09/06 22:42:16 wollman Exp $ */ /* @@ -607,11 +607,7 @@ igmp_sendpkt(inm, type) * Request loopback of the report if we are acting as a multicast * router, so that the process-level routing demon can hear it. */ -#ifdef MROUTING imo->imo_multicast_loop = (ip_mrouter != NULL); -#else - imo->imo_multicast_loop = 0; -#endif ip_output(m, (struct mbuf *)0, (struct route *)0, 0, imo); diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index b3a8841bcfb8..2d33383827b5 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in_proto.c 8.1 (Berkeley) 6/10/93 - * $Id: in_proto.c,v 1.3 1994/08/02 07:48:23 davidg Exp $ + * $Id: in_proto.c,v 1.4 1994/09/06 22:42:19 wollman Exp $ */ #include @@ -77,9 +77,7 @@ void eoninput(), eonctlinput(), eonprotoinit(); #endif /* EON */ - #ifdef MROUTING - void multiencap_decap(struct mbuf *); - #endif +void multiencap_decap(struct mbuf *); extern struct domain inetdomain; @@ -119,13 +117,11 @@ rip_usrreq, 0, 0, 0, 0, }, -#ifdef MROUTING { SOCK_RAW, &inetdomain, IPPROTO_ENCAP, PR_ATOMIC|PR_ADDR, multiencap_decap, rip_output, 0, rip_ctloutput, rip_usrreq, 0, 0, 0, 0, }, -#endif /* MROUTING */ #ifdef TPIP { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD, tpip_input, 0, tpip_ctlinput, tp_ctloutput, diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 40dd6bf93c06..85fa95c94b7b 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 - * $Id: ip_input.c,v 1.4 1994/08/18 22:35:30 wollman Exp $ + * $Id: ip_input.c,v 1.5 1994/09/06 22:42:21 wollman Exp $ */ #include @@ -282,7 +282,6 @@ ipintr() } if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) { struct in_multi *inm; -#ifdef MROUTING if (ip_mrouter) { /* * If we are acting as a multicast router, all @@ -313,7 +312,6 @@ ipintr() goto ours; ipstat.ips_forward++; } -#endif /* * See if we belong to the destination multicast group on the * arrival interface. diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index b14951d7450d..4b7a8ba0bfb3 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -48,6 +48,8 @@ #endif #endif +struct mrtstat mrtstat; + #ifndef MROUTING /* * Dummy routines and globals used when multicast routing is not compiled in. @@ -57,7 +59,7 @@ struct socket *ip_mrouter = NULL; u_int ip_mrtproto = 0; int -ip_mrouter_cmd(cmd, so, m) +_ip_mrouter_cmd(cmd, so, m) int cmd; struct socket *so; struct mbuf *m; @@ -65,20 +67,43 @@ ip_mrouter_cmd(cmd, so, m) return(EOPNOTSUPP); } +int (*ip_mrouter_cmd)(int, struct socket *, struct mbuf *) = _ip_mrouter_cmd; + int -ip_mrouter_done() +_ip_mrouter_done() { return(0); } +int (*ip_mrouter_done)(void) = _ip_mrouter_done; + int -ip_mforward(ip, ifp, m) +_ip_mforward(ip, ifp, m, imo) struct ip *ip; struct ifnet *ifp; struct mbuf *m; + struct ip_moptions *imo; { return(0); } + +int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *, + struct ip_moptions *) = _ip_mforward; + +int +_mrt_ioctl(int req, caddr_t data, struct proc *p) +{ + return EOPNOTSUPP; +} + +int (*mrt_ioctl)(int, caddr_t, struct proc *) = _mrt_ioctl; + +void multiencap_decap(struct mbuf *m) { /* XXX must fixup manually */ + rip_input(m); +} + +int (*legal_vif_num)(int) = 0; + #else #define INSIZ sizeof(struct in_addr) @@ -99,7 +124,6 @@ int ip_mrtproto = IGMP_DVMRP; /* for netstat only */ struct mbuf *mfctable[MFCTBLSIZ]; struct vif viftable[MAXVIFS]; -struct mrtstat mrtstat; u_int mrtdebug = 0; /* debug level */ u_int tbfdebug = 0; /* tbf debug level */ @@ -129,7 +153,7 @@ struct ifnet multicast_decap_if[MAXVIFS]; /* prototype IP hdr for encapsulated packets */ struct ip multicast_encap_iphdr = { -#if defined(ultrix) || defined(i386) +#if BYTE_ORDER == LITTLE_ENDIAN sizeof(struct ip) >> 2, IPVERSION, #else IPVERSION, sizeof(struct ip) >> 2, @@ -166,7 +190,7 @@ static int del_mfc(struct delmfcctl *); static void cleanup_cache(void *); static int ip_mdq(struct mbuf *, struct ifnet *, u_long, struct mfc *, struct ip_moptions *); -int legal_vif_num(int); +extern int (*legal_vif_num)(int); static void phyint_send(struct ip *, struct vif *, struct mbuf *); static void srcrt_send(struct ip *, struct vif *, struct mbuf *); static void encap_send(struct ip *, struct vif *, struct mbuf *); @@ -285,7 +309,7 @@ mfcfind(origin, mcastgrp) * Handle DVMRP setsockopt commands to modify the multicast routing tables. */ int -ip_mrouter_cmd(cmd, so, m) +_ip_mrouter_cmd(cmd, so, m) int cmd; struct socket *so; struct mbuf *m; @@ -303,12 +327,13 @@ ip_mrouter_cmd(cmd, so, m) } } +int (*ip_mrouter_cmd)(int, struct socket *, struct mbuf *) = _ip_mrouter_cmd; /* * Handle ioctl commands to obtain information from the cache */ int -mrt_ioctl(cmd, data) +_mrt_ioctl(cmd, data) int cmd; caddr_t data; { @@ -331,6 +356,8 @@ mrt_ioctl(cmd, data) return error; } +int (*mrt_ioctl)(int, caddr_t, struct proc *) = _mrt_ioctl; + /* * returns the packet count for the source group provided */ @@ -429,7 +456,7 @@ ip_mrouter_init(so) * Disable multicast routing */ int -ip_mrouter_done() +_ip_mrouter_done() { vifi_t vifi; int i; @@ -509,6 +536,8 @@ ip_mrouter_done() return 0; } +int (*ip_mrouter_done)(void) = _ip_mrouter_done; + /* * Add a vif to the vif table */ @@ -869,10 +898,10 @@ del_mfc(mfccp) #define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */ int -ip_mforward(ip, ifp, m, imo) - struct mbuf *m; +_ip_mforward(ip, ifp, m, imo) register struct ip *ip; struct ifnet *ifp; + struct mbuf *m; struct ip_moptions *imo; { register struct mfc *rt; @@ -1090,6 +1119,9 @@ ip_mforward(ip, ifp, m, imo) } } +int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *, + struct ip_moptions *) = _ip_mforward; + /* * Clean up the cache entry if upcall is not serviced */ @@ -1225,7 +1257,7 @@ ip_mdq(m, ifp, tunnel_src, rt, imo) * numvifs there, */ int -legal_vif_num(vif) +_legal_vif_num(vif) int vif; { if (vif>=0 && vif<=numvifs) return(1); @@ -1233,6 +1265,8 @@ legal_vif_num(vif) return(0); } +int (*legal_vif_num)(int) = _legal_vif_num; + static void phyint_send(ip, vifp, m) struct ip *ip; diff --git a/sys/netinet/ip_mroute.h b/sys/netinet/ip_mroute.h index 304b3ceebf1f..2d6540eacb2b 100644 --- a/sys/netinet/ip_mroute.h +++ b/sys/netinet/ip_mroute.h @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * @(#)ip_mroute.h 8.1 (Berkeley) 6/10/93 - * $Id: ip_mroute.h,v 1.3 1994/08/21 05:27:32 paul Exp $ + * $Id: ip_mroute.h,v 1.4 1994/09/06 22:42:23 wollman Exp $ */ #ifndef _NETINET_IP_MROUTE_H_ @@ -246,8 +246,8 @@ struct tbf u_long q_len; /* length of queue at this vif */ }; -int ip_mrouter_cmd __P((int, struct socket *, struct mbuf *)); -int ip_mrouter_done __P((void)); +extern int (*ip_mrouter_cmd) __P((int, struct socket *, struct mbuf *)); +extern int (*ip_mrouter_done) __P((void)); #endif /* KERNEL */ diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index adf76b42d14c..358b42f8b23a 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 - * $Id: ip_output.c,v 1.6 1994/09/06 22:42:24 wollman Exp $ + * $Id: ip_output.c,v 1.7 1994/09/09 22:05:02 wollman Exp $ */ #include @@ -211,7 +211,6 @@ ip_output(m0, opt, ro, flags, imo) */ ip_mloopback(ifp, m, dst); } -#ifdef MROUTING else { /* * If we are acting as a multicast router, perform @@ -240,7 +239,7 @@ ip_output(m0, opt, ro, flags, imo) } } } -#endif + /* * Multicasts with a time-to-live of zero may be looped- * back, above, but must not be transmitted on a network. @@ -790,9 +789,13 @@ ip_setmoptions(optname, imop, m) } switch (optname) { -#ifdef MROUTING + extern int (*legal_vif_num)(int); /* store an index number for the vif you wanna use in the send */ case IP_MULTICAST_VIF: + if (!legal_vif_num) { + error = EOPNOTSUPP; + break; + } if (m == NULL || m->m_len != sizeof(int)) { error = EINVAL; break; @@ -804,7 +807,6 @@ ip_setmoptions(optname, imop, m) } imo->imo_multicast_vif = i; break; -#endif case IP_MULTICAST_IF: /* diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 3e8db9640335..0dd2fd9abb99 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_var.h 8.1 (Berkeley) 6/10/93 - * $Id: ip_var.h,v 1.4 1994/08/21 05:27:33 paul Exp $ + * $Id: ip_var.h,v 1.5 1994/09/06 22:42:25 wollman Exp $ */ #ifndef _NETINET_IP_VAR_H_ @@ -169,7 +169,7 @@ void ip_freef __P((struct ipq *)); void ip_freemoptions __P((struct ip_moptions *)); int ip_getmoptions __P((int, struct ip_moptions *, struct mbuf **)); void ip_init __P((void)); -int ip_mforward __P((struct ip *, struct ifnet *, struct mbuf *, +extern int (*ip_mforward) __P((struct ip *, struct ifnet *, struct mbuf *, struct ip_moptions *)); int ip_optcopy __P((struct ip *, struct ip *)); int ip_output __P((struct mbuf *, diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index e0cddca4fe42..fee9fb15cd0b 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)raw_ip.c 8.2 (Berkeley) 1/4/94 - * $Id: raw_ip.c,v 1.2 1994/08/02 07:48:49 davidg Exp $ + * $Id: raw_ip.c,v 1.3 1994/09/06 22:42:26 wollman Exp $ */ #include @@ -217,7 +217,6 @@ rip_ctloutput(op, so, level, optname, m) case DVMRP_DEL_VIF: case DVMRP_ADD_MFC: case DVMRP_DEL_MFC: -#ifdef MROUTING if (op == PRCO_SETOPT) { error = ip_mrouter_cmd(optname, so, *m); if (*m) @@ -225,11 +224,6 @@ rip_ctloutput(op, so, level, optname, m) } else error = EINVAL; return (error); -#else - if (op == PRCO_SETOPT && *m) - (void)m_free(*m); - return (EOPNOTSUPP); -#endif } return (ip_ctloutput(op, so, level, optname, m)); } @@ -274,10 +268,8 @@ rip_usrreq(so, req, m, nam, control) case PRU_DETACH: if (inp == 0) panic("rip_detach"); -#ifdef MROUTING if (so == ip_mrouter) ip_mrouter_done(); -#endif in_pcbdetach(inp); break;