2 * IP multicast forwarding procedures
4 * Written by David Waitzman, BBN Labs, August 1988.
5 * Modified by Steve Deering, Stanford, February 1989.
6 * Modified by Mark J. Steiglitz, Stanford, May, 1991
7 * Modified by Van Jacobson, LBL, January 1993
8 * Modified by Ajit Thyagarajan, PARC, August 1993
9 * Modified by Bill Fenner, PARC, April 1995
11 * MROUTING Revision: 3.5
12 * $FreeBSD: src/sys/netinet/ip_mroute.c,v 1.56.2.7 2003/01/23 21:06:45 sam Exp $
13 * $DragonFly: src/sys/net/ip_mroute/ip_mroute.c,v 1.2 2003/06/17 04:28:51 dillon Exp $
16 #include "opt_mrouting.h"
17 #include "opt_random_ip_id.h"
19 #include <sys/param.h>
20 #include <sys/kernel.h>
21 #include <sys/malloc.h>
23 #include <sys/protosw.h>
24 #include <sys/socket.h>
25 #include <sys/socketvar.h>
26 #include <sys/sockio.h>
27 #include <sys/sysctl.h>
28 #include <sys/syslog.h>
29 #include <sys/systm.h>
32 #include <net/route.h>
33 #include <netinet/in.h>
34 #include <netinet/igmp.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/in_var.h>
37 #include <netinet/ip.h>
38 #include <netinet/ip_mroute.h>
39 #include <netinet/ip_var.h>
40 #include <netinet/udp.h>
41 #include <machine/in_cksum.h>
44 * Control debugging code for rsvp and multicast routing code.
45 * Can only set them with the debugger.
47 static u_int rsvpdebug; /* non-zero enables debugging */
49 static u_int mrtdebug; /* any set of the flags below */
51 #define DEBUG_MFC 0x02
52 #define DEBUG_FORWARD 0x04
53 #define DEBUG_EXPIRE 0x08
54 #define DEBUG_XMIT 0x10
56 #define M_HASCL(m) ((m)->m_flags & M_EXT)
58 static MALLOC_DEFINE(M_MRTABLE, "mroutetbl", "multicast routing tables");
60 static struct mrtstat mrtstat;
61 SYSCTL_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW,
63 "Multicast Routing Statistics (struct mrtstat, netinet/ip_mroute.h)");
65 static struct mfc *mfctable[MFCTBLSIZ];
66 static u_char nexpire[MFCTBLSIZ];
67 static struct vif viftable[MAXVIFS];
69 static struct callout_handle expire_upcalls_ch;
71 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
72 #define UPCALL_EXPIRE 6 /* number of timeouts */
75 * Define the token bucket filter structures
76 * tbftable -> each vif has one of these for storing info
79 static struct tbf tbftable[MAXVIFS];
80 #define TBF_REPROCESS (hz / 100) /* 100x / second */
83 * 'Interfaces' associated with decapsulator (so we can tell
84 * packets that went through it from ones that get reflected
85 * by a broken gateway). These interfaces are never linked into
86 * the system ifnet list & no routes point to them. I.e., packets
87 * can't be sent this way. They only exist as a placeholder for
88 * multicast source verification.
90 static struct ifnet multicast_decap_if[MAXVIFS];
93 #define ENCAP_PROTO IPPROTO_IPIP /* 4 */
95 /* prototype IP hdr for encapsulated packets */
96 static struct ip multicast_encap_iphdr = {
97 #if BYTE_ORDER == LITTLE_ENDIAN
98 sizeof(struct ip) >> 2, IPVERSION,
100 IPVERSION, sizeof(struct ip) >> 2,
103 sizeof(struct ip), /* total length */
106 ENCAP_TTL, ENCAP_PROTO,
113 static vifi_t numvifs;
114 static int have_encap_tunnel;
117 * one-back cache used by ipip_input to locate a tunnel's vif
118 * given a datagram's src ip address.
120 static u_long last_encap_src;
121 static struct vif *last_encap_vif;
123 static u_long X_ip_mcast_src(int vifi);
124 static int X_ip_mforward(struct ip *ip, struct ifnet *ifp,
125 struct mbuf *m, struct ip_moptions *imo);
126 static int X_ip_mrouter_done(void);
127 static int X_ip_mrouter_get(struct socket *so, struct sockopt *m);
128 static int X_ip_mrouter_set(struct socket *so, struct sockopt *m);
129 static int X_legal_vif_num(int vif);
130 static int X_mrt_ioctl(int cmd, caddr_t data);
132 static int get_sg_cnt(struct sioc_sg_req *);
133 static int get_vif_cnt(struct sioc_vif_req *);
134 static int ip_mrouter_init(struct socket *, int);
135 static int add_vif(struct vifctl *);
136 static int del_vif(vifi_t);
137 static int add_mfc(struct mfcctl *);
138 static int del_mfc(struct mfcctl *);
139 static int socket_send(struct socket *, struct mbuf *, struct sockaddr_in *);
140 static int set_assert(int);
141 static void expire_upcalls(void *);
142 static int ip_mdq(struct mbuf *, struct ifnet *, struct mfc *, vifi_t);
143 static void phyint_send(struct ip *, struct vif *, struct mbuf *);
144 static void encap_send(struct ip *, struct vif *, struct mbuf *);
145 static void tbf_control(struct vif *, struct mbuf *, struct ip *, u_long);
146 static void tbf_queue(struct vif *, struct mbuf *);
147 static void tbf_process_q(struct vif *);
148 static void tbf_reprocess_q(void *);
149 static int tbf_dq_sel(struct vif *, struct ip *);
150 static void tbf_send_packet(struct vif *, struct mbuf *);
151 static void tbf_update_tokens(struct vif *);
152 static int priority(struct vif *, struct ip *);
155 * whether or not special PIM assert processing is enabled.
157 static int pim_assert;
159 * Rate limit for assert notification messages, in usec
161 #define ASSERT_MSG_TIME 3000000
164 * Hash function for a source, group entry
166 #define MFCHASH(a, g) MFCHASHMOD(((a) >> 20) ^ ((a) >> 10) ^ (a) ^ \
167 ((g) >> 20) ^ ((g) >> 10) ^ (g))
170 * Find a route for a given origin IP address and Multicast group address
171 * Type of service parameter to be added in the future!!!
172 * Statistics are updated by the caller if needed
173 * (mrtstat.mrts_mfc_lookups and mrtstat.mrts_mfc_misses)
176 mfc_find(in_addr_t o, in_addr_t g)
180 for (rt = mfctable[MFCHASH(o,g)]; rt; rt = rt->mfc_next)
181 if ((rt->mfc_origin.s_addr == o) &&
182 (rt->mfc_mcastgrp.s_addr == g) && (rt->mfc_stall == NULL))
188 * Macros to compute elapsed time efficiently
189 * Borrowed from Van Jacobson's scheduling code
191 #define TV_DELTA(a, b, delta) { \
193 delta = (a).tv_usec - (b).tv_usec; \
194 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
203 delta += (1000000 * xxs); \
208 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
209 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
212 * Handle MRT setsockopt commands to modify the multicast routing tables.
215 X_ip_mrouter_set(struct socket *so, struct sockopt *sopt)
222 if (so != ip_mrouter && sopt->sopt_name != MRT_INIT)
226 switch (sopt->sopt_name) {
228 error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval);
231 error = ip_mrouter_init(so, optval);
235 error = ip_mrouter_done();
239 error = sooptcopyin(sopt, &vifc, sizeof vifc, sizeof vifc);
242 error = add_vif(&vifc);
246 error = sooptcopyin(sopt, &vifi, sizeof vifi, sizeof vifi);
249 error = del_vif(vifi);
254 error = sooptcopyin(sopt, &mfc, sizeof mfc, sizeof mfc);
257 if (sopt->sopt_name == MRT_ADD_MFC)
258 error = add_mfc(&mfc);
260 error = del_mfc(&mfc);
264 error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval);
278 * Handle MRT getsockopt commands
281 X_ip_mrouter_get(struct socket *so, struct sockopt *sopt)
284 static int version = 0x0305; /* !!! why is this here? XXX */
286 switch (sopt->sopt_name) {
288 error = sooptcopyout(sopt, &version, sizeof version);
292 error = sooptcopyout(sopt, &pim_assert, sizeof pim_assert);
303 * Handle ioctl commands to obtain information from the cache
306 X_mrt_ioctl(int cmd, caddr_t data)
312 error = get_vif_cnt((struct sioc_vif_req *)data);
316 error = get_sg_cnt((struct sioc_sg_req *)data);
327 * returns the packet, byte, rpf-failure count for the source group provided
330 get_sg_cnt(struct sioc_sg_req *req)
336 rt = mfc_find(req->src.s_addr, req->grp.s_addr);
339 req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
340 return EADDRNOTAVAIL;
342 req->pktcnt = rt->mfc_pkt_cnt;
343 req->bytecnt = rt->mfc_byte_cnt;
344 req->wrong_if = rt->mfc_wrong_if;
349 * returns the input and output packet and byte counts on the vif provided
352 get_vif_cnt(struct sioc_vif_req *req)
354 vifi_t vifi = req->vifi;
359 req->icount = viftable[vifi].v_pkt_in;
360 req->ocount = viftable[vifi].v_pkt_out;
361 req->ibytes = viftable[vifi].v_bytes_in;
362 req->obytes = viftable[vifi].v_bytes_out;
368 * Enable multicast routing
371 ip_mrouter_init(struct socket *so, int version)
374 log(LOG_DEBUG, "ip_mrouter_init: so_type = %d, pr_protocol = %d\n",
375 so->so_type, so->so_proto->pr_protocol);
377 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_IGMP)
383 if (ip_mrouter != NULL)
388 bzero((caddr_t)mfctable, sizeof(mfctable));
389 bzero((caddr_t)nexpire, sizeof(nexpire));
393 expire_upcalls_ch = timeout(expire_upcalls, NULL, EXPIRE_TIMEOUT);
396 log(LOG_DEBUG, "ip_mrouter_init\n");
402 * Disable multicast routing
405 X_ip_mrouter_done(void)
418 * For each phyint in use, disable promiscuous reception of all IP
421 for (vifi = 0; vifi < numvifs; vifi++) {
422 if (viftable[vifi].v_lcl_addr.s_addr != 0 &&
423 !(viftable[vifi].v_flags & VIFF_TUNNEL)) {
424 struct sockaddr_in *so = (struct sockaddr_in *)&(ifr.ifr_addr);
426 so->sin_len = sizeof(struct sockaddr_in);
427 so->sin_family = AF_INET;
428 so->sin_addr.s_addr = INADDR_ANY;
429 ifp = viftable[vifi].v_ifp;
433 bzero((caddr_t)tbftable, sizeof(tbftable));
434 bzero((caddr_t)viftable, sizeof(viftable));
438 untimeout(expire_upcalls, NULL, expire_upcalls_ch);
441 * Free all multicast forwarding cache entries.
443 for (i = 0; i < MFCTBLSIZ; i++) {
444 for (rt = mfctable[i]; rt != NULL; ) {
445 struct mfc *nr = rt->mfc_next;
447 for (rte = rt->mfc_stall; rte != NULL; ) {
448 struct rtdetq *n = rte->next;
451 free(rte, M_MRTABLE);
459 bzero((caddr_t)mfctable, sizeof(mfctable));
462 * Reset de-encapsulation cache
464 last_encap_src = INADDR_ANY;
465 last_encap_vif = NULL;
466 have_encap_tunnel = 0;
473 log(LOG_DEBUG, "ip_mrouter_done\n");
479 * Set PIM assert processing global
484 if ((i != 1) && (i != 0))
493 * Add a vif to the vif table
496 add_vif(struct vifctl *vifcp)
498 struct vif *vifp = viftable + vifcp->vifc_vifi;
499 struct sockaddr_in sin = {sizeof sin, AF_INET};
503 struct tbf *v_tbf = tbftable + vifcp->vifc_vifi;
505 if (vifcp->vifc_vifi >= MAXVIFS)
507 if (vifp->v_lcl_addr.s_addr != INADDR_ANY)
509 if (vifcp->vifc_lcl_addr.s_addr == INADDR_ANY)
510 return EADDRNOTAVAIL;
512 /* Find the interface with an address in AF_INET family */
513 sin.sin_addr = vifcp->vifc_lcl_addr;
514 ifa = ifa_ifwithaddr((struct sockaddr *)&sin);
516 return EADDRNOTAVAIL;
519 if (vifcp->vifc_flags & VIFF_TUNNEL) {
520 if ((vifcp->vifc_flags & VIFF_SRCRT) == 0) {
522 * An encapsulating tunnel is wanted. Tell ipip_input() to
523 * start paying attention to encapsulated packets.
525 if (have_encap_tunnel == 0) {
526 have_encap_tunnel = 1;
527 for (s = 0; s < MAXVIFS; ++s) {
528 multicast_decap_if[s].if_name = "mdecap";
529 multicast_decap_if[s].if_unit = s;
533 * Set interface to fake encapsulator interface
535 ifp = &multicast_decap_if[vifcp->vifc_vifi];
537 * Prepare cached route entry
539 bzero(&vifp->v_route, sizeof(vifp->v_route));
541 log(LOG_ERR, "source routed tunnels not supported\n");
544 } else { /* Make sure the interface supports multicast */
545 if ((ifp->if_flags & IFF_MULTICAST) == 0)
548 /* Enable promiscuous reception of all IP multicasts from the if */
550 error = if_allmulti(ifp, 1);
557 /* define parameters for the tbf structure */
559 GET_TIME(vifp->v_tbf->tbf_last_pkt_t);
560 vifp->v_tbf->tbf_n_tok = 0;
561 vifp->v_tbf->tbf_q_len = 0;
562 vifp->v_tbf->tbf_max_q_len = MAXQSIZE;
563 vifp->v_tbf->tbf_q = vifp->v_tbf->tbf_t = NULL;
565 vifp->v_flags = vifcp->vifc_flags;
566 vifp->v_threshold = vifcp->vifc_threshold;
567 vifp->v_lcl_addr = vifcp->vifc_lcl_addr;
568 vifp->v_rmt_addr = vifcp->vifc_rmt_addr;
570 /* scaling up here allows division by 1024 in critical code */
571 vifp->v_rate_limit= vifcp->vifc_rate_limit * 1024 / 1000;
573 vifp->v_rsvpd = NULL;
574 /* initialize per vif pkt counters */
577 vifp->v_bytes_in = 0;
578 vifp->v_bytes_out = 0;
581 /* Adjust numvifs up if the vifi is higher than numvifs */
582 if (numvifs <= vifcp->vifc_vifi) numvifs = vifcp->vifc_vifi + 1;
585 log(LOG_DEBUG, "add_vif #%d, lcladdr %lx, %s %lx, thresh %x, rate %d\n",
587 (u_long)ntohl(vifcp->vifc_lcl_addr.s_addr),
588 (vifcp->vifc_flags & VIFF_TUNNEL) ? "rmtaddr" : "mask",
589 (u_long)ntohl(vifcp->vifc_rmt_addr.s_addr),
590 vifcp->vifc_threshold,
591 vifcp->vifc_rate_limit);
597 * Delete a vif from the vif table
607 vifp = &viftable[vifi];
608 if (vifp->v_lcl_addr.s_addr == INADDR_ANY)
609 return EADDRNOTAVAIL;
613 if (!(vifp->v_flags & VIFF_TUNNEL))
614 if_allmulti(vifp->v_ifp, 0);
616 if (vifp == last_encap_vif) {
617 last_encap_vif = NULL;
618 last_encap_src = INADDR_ANY;
622 * Free packets queued at the interface
624 while (vifp->v_tbf->tbf_q) {
625 struct mbuf *m = vifp->v_tbf->tbf_q;
627 vifp->v_tbf->tbf_q = m->m_act;
631 bzero((caddr_t)vifp->v_tbf, sizeof(*(vifp->v_tbf)));
632 bzero((caddr_t)vifp, sizeof (*vifp));
635 log(LOG_DEBUG, "del_vif %d, numvifs %d\n", vifi, numvifs);
637 /* Adjust numvifs down */
638 for (vifi = numvifs; vifi > 0; vifi--)
639 if (viftable[vifi-1].v_lcl_addr.s_addr != INADDR_ANY)
649 * update an mfc entry without resetting counters and S,G addresses.
652 update_mfc_params(struct mfc *rt, struct mfcctl *mfccp)
656 rt->mfc_parent = mfccp->mfcc_parent;
657 for (i = 0; i < numvifs; i++)
658 rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
662 * fully initialize an mfc entry from the parameter.
665 init_mfc_params(struct mfc *rt, struct mfcctl *mfccp)
667 rt->mfc_origin = mfccp->mfcc_origin;
668 rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
670 update_mfc_params(rt, mfccp);
672 /* initialize pkt counters per src-grp */
674 rt->mfc_byte_cnt = 0;
675 rt->mfc_wrong_if = 0;
676 rt->mfc_last_assert.tv_sec = rt->mfc_last_assert.tv_usec = 0;
684 add_mfc(struct mfcctl *mfccp)
692 rt = mfc_find(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
694 /* If an entry already exists, just update the fields */
696 if (mrtdebug & DEBUG_MFC)
697 log(LOG_DEBUG,"add_mfc update o %lx g %lx p %x\n",
698 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
699 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
703 update_mfc_params(rt, mfccp);
709 * Find the entry for which the upcall was made and update
712 hash = MFCHASH(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
713 for (rt = mfctable[hash], nstl = 0; rt; rt = rt->mfc_next) {
715 if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
716 (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr) &&
717 (rt->mfc_stall != NULL)) {
720 log(LOG_ERR, "add_mfc %s o %lx g %lx p %x dbx %p\n",
721 "multiple kernel entries",
722 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
723 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
724 mfccp->mfcc_parent, (void *)rt->mfc_stall);
726 if (mrtdebug & DEBUG_MFC)
727 log(LOG_DEBUG,"add_mfc o %lx g %lx p %x dbg %p\n",
728 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
729 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
730 mfccp->mfcc_parent, (void *)rt->mfc_stall);
732 init_mfc_params(rt, mfccp);
734 rt->mfc_expire = 0; /* Don't clean this guy up */
737 /* free packets Qed at the end of this entry */
738 for (rte = rt->mfc_stall; rte != NULL; ) {
739 struct rtdetq *n = rte->next;
741 ip_mdq(rte->m, rte->ifp, rt, -1);
743 free(rte, M_MRTABLE);
746 rt->mfc_stall = NULL;
751 * It is possible that an entry is being inserted without an upcall
754 if (mrtdebug & DEBUG_MFC)
755 log(LOG_DEBUG,"add_mfc no upcall h %lu o %lx g %lx p %x\n",
756 hash, (u_long)ntohl(mfccp->mfcc_origin.s_addr),
757 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
760 for (rt = mfctable[hash]; rt != NULL; rt = rt->mfc_next) {
761 if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
762 (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr)) {
763 init_mfc_params(rt, mfccp);
770 if (rt == NULL) { /* no upcall, so make a new entry */
771 rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
777 init_mfc_params(rt, mfccp);
779 rt->mfc_stall = NULL;
781 /* insert new entry at head of hash chain */
782 rt->mfc_next = mfctable[hash];
791 * Delete an mfc entry
794 del_mfc(struct mfcctl *mfccp)
796 struct in_addr origin;
797 struct in_addr mcastgrp;
803 origin = mfccp->mfcc_origin;
804 mcastgrp = mfccp->mfcc_mcastgrp;
806 if (mrtdebug & DEBUG_MFC)
807 log(LOG_DEBUG,"del_mfc orig %lx mcastgrp %lx\n",
808 (u_long)ntohl(origin.s_addr), (u_long)ntohl(mcastgrp.s_addr));
812 hash = MFCHASH(origin.s_addr, mcastgrp.s_addr);
813 for (nptr = &mfctable[hash]; (rt = *nptr) != NULL; nptr = &rt->mfc_next)
814 if (origin.s_addr == rt->mfc_origin.s_addr &&
815 mcastgrp.s_addr == rt->mfc_mcastgrp.s_addr &&
816 rt->mfc_stall == NULL)
820 return EADDRNOTAVAIL;
823 *nptr = rt->mfc_next;
832 * Send a message to mrouted on the multicast routing socket
835 socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src)
838 if (sbappendaddr(&s->so_rcv, (struct sockaddr *)src, mm, NULL) != 0) {
848 * IP multicast forwarding function. This function assumes that the packet
849 * pointed to by "ip" has arrived on (or is about to be sent to) the interface
850 * pointed to by "ifp", and the packet is to be relayed to other networks
851 * that have members of the packet's destination IP multicast group.
853 * The packet is returned unscathed to the caller, unless it is
854 * erroneous, in which case a non-zero return value tells the caller to
858 #define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */
861 X_ip_mforward(struct ip *ip, struct ifnet *ifp,
862 struct mbuf *m, struct ip_moptions *imo)
868 if (mrtdebug & DEBUG_FORWARD)
869 log(LOG_DEBUG, "ip_mforward: src %lx, dst %lx, ifp %p\n",
870 (u_long)ntohl(ip->ip_src.s_addr), (u_long)ntohl(ip->ip_dst.s_addr),
873 if (ip->ip_hl < (sizeof(struct ip) + TUNNEL_LEN) >> 2 ||
874 ((u_char *)(ip + 1))[1] != IPOPT_LSRR ) {
876 * Packet arrived via a physical interface or
877 * an encapsulated tunnel.
881 * Packet arrived through a source-route tunnel.
882 * Source-route tunnels are no longer supported.
885 if (last_log != time_second) {
886 last_log = time_second;
888 "ip_mforward: received source-routed packet from %lx\n",
889 (u_long)ntohl(ip->ip_src.s_addr));
894 if ((imo) && ((vifi = imo->imo_multicast_vif) < numvifs)) {
895 if (ip->ip_ttl < 255)
896 ip->ip_ttl++; /* compensate for -1 in *_send routines */
897 if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
898 struct vif *vifp = viftable + vifi;
900 printf("Sending IPPROTO_RSVP from %lx to %lx on vif %d (%s%s%d)\n",
901 (long)ntohl(ip->ip_src.s_addr), (long)ntohl(ip->ip_dst.s_addr),
903 (vifp->v_flags & VIFF_TUNNEL) ? "tunnel on " : "",
904 vifp->v_ifp->if_name, vifp->v_ifp->if_unit);
906 return ip_mdq(m, ifp, NULL, vifi);
908 if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
909 printf("Warning: IPPROTO_RSVP from %lx to %lx without vif option\n",
910 (long)ntohl(ip->ip_src.s_addr), (long)ntohl(ip->ip_dst.s_addr));
912 printf("In fact, no options were specified at all\n");
916 * Don't forward a packet with time-to-live of zero or one,
917 * or a packet destined to a local-only group.
919 if (ip->ip_ttl <= 1 || ntohl(ip->ip_dst.s_addr) <= INADDR_MAX_LOCAL_GROUP)
923 * Determine forwarding vifs from the forwarding cache table
926 ++mrtstat.mrts_mfc_lookups;
927 rt = mfc_find(ip->ip_src.s_addr, ip->ip_dst.s_addr);
929 /* Entry exists, so forward if necessary */
932 return ip_mdq(m, ifp, rt, -1);
935 * If we don't have a route for packet's origin,
936 * Make a copy of the packet & send message to routing daemon
942 int hlen = ip->ip_hl << 2;
944 ++mrtstat.mrts_mfc_misses;
946 mrtstat.mrts_no_route++;
947 if (mrtdebug & (DEBUG_FORWARD | DEBUG_MFC))
948 log(LOG_DEBUG, "ip_mforward: no rte s %lx g %lx\n",
949 (u_long)ntohl(ip->ip_src.s_addr),
950 (u_long)ntohl(ip->ip_dst.s_addr));
953 * Allocate mbufs early so that we don't do extra work if we are
954 * just going to fail anyway. Make sure to pullup the header so
955 * that other people can't step on it.
957 rte = (struct rtdetq *)malloc((sizeof *rte), M_MRTABLE, M_NOWAIT);
962 mb0 = m_copy(m, 0, M_COPYALL);
963 if (mb0 && (M_HASCL(mb0) || mb0->m_len < hlen))
964 mb0 = m_pullup(mb0, hlen);
966 free(rte, M_MRTABLE);
971 /* is there an upcall waiting for this flow ? */
972 hash = MFCHASH(ip->ip_src.s_addr, ip->ip_dst.s_addr);
973 for (rt = mfctable[hash]; rt; rt = rt->mfc_next) {
974 if ((ip->ip_src.s_addr == rt->mfc_origin.s_addr) &&
975 (ip->ip_dst.s_addr == rt->mfc_mcastgrp.s_addr) &&
976 (rt->mfc_stall != NULL))
983 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
987 * Locate the vifi for the incoming interface for this packet.
988 * If none found, drop packet.
990 for (vifi=0; vifi<numvifs && viftable[vifi].v_ifp != ifp; vifi++)
992 if (vifi >= numvifs) /* vif not found, drop packet */
995 /* no upcall, so make a new entry */
996 rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
999 /* Make a copy of the header to send to the user level process */
1000 mm = m_copy(mb0, 0, hlen);
1005 * Send message to routing daemon to install
1006 * a route into the kernel table
1009 im = mtod(mm, struct igmpmsg *);
1010 im->im_msgtype = IGMPMSG_NOCACHE;
1014 mrtstat.mrts_upcalls++;
1016 k_igmpsrc.sin_addr = ip->ip_src;
1017 if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
1018 log(LOG_WARNING, "ip_mforward: ip_mrouter socket queue full\n");
1019 ++mrtstat.mrts_upq_sockfull;
1021 free(rt, M_MRTABLE);
1023 free(rte, M_MRTABLE);
1029 /* insert new entry at head of hash chain */
1030 rt->mfc_origin.s_addr = ip->ip_src.s_addr;
1031 rt->mfc_mcastgrp.s_addr = ip->ip_dst.s_addr;
1032 rt->mfc_expire = UPCALL_EXPIRE;
1034 for (i = 0; i < numvifs; i++)
1035 rt->mfc_ttls[i] = 0;
1036 rt->mfc_parent = -1;
1038 /* link into table */
1039 rt->mfc_next = mfctable[hash];
1040 mfctable[hash] = rt;
1041 rt->mfc_stall = rte;
1044 /* determine if q has overflowed */
1049 * XXX ouch! we need to append to the list, but we
1050 * only have a pointer to the front, so we have to
1051 * scan the entire list every time.
1053 for (p = &rt->mfc_stall; *p != NULL; p = &(*p)->next)
1056 if (npkts > MAX_UPQ) {
1057 mrtstat.mrts_upq_ovflw++;
1059 free(rte, M_MRTABLE);
1065 /* Add this entry to the end of the queue */
1080 * Clean up the cache entry if upcall is not serviced
1083 expire_upcalls(void *unused)
1086 struct mfc *mfc, **nptr;
1091 for (i = 0; i < MFCTBLSIZ; i++) {
1092 if (nexpire[i] == 0)
1094 nptr = &mfctable[i];
1095 for (mfc = *nptr; mfc != NULL; mfc = *nptr) {
1097 * Skip real cache entries
1098 * Make sure it wasn't marked to not expire (shouldn't happen)
1101 if (mfc->mfc_stall != NULL && mfc->mfc_expire != 0 &&
1102 --mfc->mfc_expire == 0) {
1103 if (mrtdebug & DEBUG_EXPIRE)
1104 log(LOG_DEBUG, "expire_upcalls: expiring (%lx %lx)\n",
1105 (u_long)ntohl(mfc->mfc_origin.s_addr),
1106 (u_long)ntohl(mfc->mfc_mcastgrp.s_addr));
1108 * drop all the packets
1109 * free the mbuf with the pkt, if, timing info
1111 for (rte = mfc->mfc_stall; rte; ) {
1112 struct rtdetq *n = rte->next;
1115 free(rte, M_MRTABLE);
1118 ++mrtstat.mrts_cache_cleanups;
1121 *nptr = mfc->mfc_next;
1122 free(mfc, M_MRTABLE);
1124 nptr = &mfc->mfc_next;
1129 expire_upcalls_ch = timeout(expire_upcalls, NULL, EXPIRE_TIMEOUT);
1133 * Packet forwarding routine once entry in the cache is made
1136 ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
1138 struct ip *ip = mtod(m, struct ip *);
1140 int plen = ip->ip_len;
1143 * Macro to send packet on vif. Since RSVP packets don't get counted on
1144 * input, they shouldn't get counted on output, so statistics keeping is
1147 #define MC_SEND(ip,vifp,m) { \
1148 if ((vifp)->v_flags & VIFF_TUNNEL) \
1149 encap_send((ip), (vifp), (m)); \
1151 phyint_send((ip), (vifp), (m)); \
1155 * If xmt_vif is not -1, send on only the requested vif.
1157 * (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.)
1159 if (xmt_vif < numvifs) {
1160 MC_SEND(ip, viftable + xmt_vif, m);
1165 * Don't forward if it didn't arrive from the parent vif for its origin.
1167 vifi = rt->mfc_parent;
1168 if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) {
1169 /* came in the wrong interface */
1170 if (mrtdebug & DEBUG_FORWARD)
1171 log(LOG_DEBUG, "wrong if: ifp %p vifi %d vififp %p\n",
1172 (void *)ifp, vifi, (void *)viftable[vifi].v_ifp);
1173 ++mrtstat.mrts_wrong_if;
1176 * If we are doing PIM assert processing, and we are forwarding
1177 * packets on this interface, and it is a broadcast medium
1178 * interface (and not a tunnel), send a message to the routing daemon.
1180 if (pim_assert && rt->mfc_ttls[vifi] &&
1181 (ifp->if_flags & IFF_BROADCAST) &&
1182 !(viftable[vifi].v_flags & VIFF_TUNNEL)) {
1188 TV_DELTA(rt->mfc_last_assert, now, delta);
1190 if (delta > ASSERT_MSG_TIME) {
1191 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
1193 int hlen = ip->ip_hl << 2;
1194 struct mbuf *mm = m_copy(m, 0, hlen);
1196 if (mm && (M_HASCL(mm) || mm->m_len < hlen))
1197 mm = m_pullup(mm, hlen);
1201 rt->mfc_last_assert = now;
1203 im = mtod(mm, struct igmpmsg *);
1204 im->im_msgtype = IGMPMSG_WRONGVIF;
1208 k_igmpsrc.sin_addr = im->im_src;
1210 if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
1212 "ip_mforward: ip_mrouter socket queue full\n");
1213 ++mrtstat.mrts_upq_sockfull;
1221 /* If I sourced this packet, it counts as output, else it was input. */
1222 if (ip->ip_src.s_addr == viftable[vifi].v_lcl_addr.s_addr) {
1223 viftable[vifi].v_pkt_out++;
1224 viftable[vifi].v_bytes_out += plen;
1226 viftable[vifi].v_pkt_in++;
1227 viftable[vifi].v_bytes_in += plen;
1230 rt->mfc_byte_cnt += plen;
1233 * For each vif, decide if a copy of the packet should be forwarded.
1235 * - the ttl exceeds the vif's threshold
1236 * - there are group members downstream on interface
1238 for (vifi = 0; vifi < numvifs; vifi++)
1239 if ((rt->mfc_ttls[vifi] > 0) && (ip->ip_ttl > rt->mfc_ttls[vifi])) {
1240 viftable[vifi].v_pkt_out++;
1241 viftable[vifi].v_bytes_out += plen;
1242 MC_SEND(ip, viftable+vifi, m);
1249 * check if a vif number is legal/ok. This is used by ip_output.
1252 X_legal_vif_num(int vif)
1254 return (vif >= 0 && vif < numvifs);
1258 * Return the local address used by this vif
1261 X_ip_mcast_src(int vifi)
1263 if (vifi >= 0 && vifi < numvifs)
1264 return viftable[vifi].v_lcl_addr.s_addr;
1270 phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
1272 struct mbuf *mb_copy;
1273 int hlen = ip->ip_hl << 2;
1276 * Make a new reference to the packet; make sure that
1277 * the IP header is actually copied, not just referenced,
1278 * so that ip_output() only scribbles on the copy.
1280 mb_copy = m_copy(m, 0, M_COPYALL);
1281 if (mb_copy && (M_HASCL(mb_copy) || mb_copy->m_len < hlen))
1282 mb_copy = m_pullup(mb_copy, hlen);
1283 if (mb_copy == NULL)
1286 if (vifp->v_rate_limit == 0)
1287 tbf_send_packet(vifp, mb_copy);
1289 tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *), ip->ip_len);
1293 encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
1295 struct mbuf *mb_copy;
1297 int i, len = ip->ip_len;
1300 * XXX: take care of delayed checksums.
1301 * XXX: if network interfaces are capable of computing checksum for
1302 * encapsulated multicast data packets, we need to reconsider this.
1304 if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) {
1305 in_delayed_cksum(m);
1306 m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
1310 * copy the old packet & pullup its IP header into the
1311 * new mbuf so we can modify it. Try to fill the new
1312 * mbuf since if we don't the ethernet driver will.
1314 MGETHDR(mb_copy, M_DONTWAIT, MT_HEADER);
1315 if (mb_copy == NULL)
1317 mb_copy->m_data += max_linkhdr;
1318 mb_copy->m_len = sizeof(multicast_encap_iphdr);
1320 if ((mb_copy->m_next = m_copy(m, 0, M_COPYALL)) == NULL) {
1324 i = MHLEN - M_LEADINGSPACE(mb_copy);
1327 mb_copy = m_pullup(mb_copy, i);
1328 if (mb_copy == NULL)
1330 mb_copy->m_pkthdr.len = len + sizeof(multicast_encap_iphdr);
1333 * fill in the encapsulating IP header.
1335 ip_copy = mtod(mb_copy, struct ip *);
1336 *ip_copy = multicast_encap_iphdr;
1338 ip_copy->ip_id = ip_randomid();
1340 ip_copy->ip_id = htons(ip_id++);
1342 ip_copy->ip_len += len;
1343 ip_copy->ip_src = vifp->v_lcl_addr;
1344 ip_copy->ip_dst = vifp->v_rmt_addr;
1347 * turn the encapsulated IP header back into a valid one.
1349 ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
1351 ip->ip_len = htons(ip->ip_len);
1352 ip->ip_off = htons(ip->ip_off);
1354 mb_copy->m_data += sizeof(multicast_encap_iphdr);
1355 ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
1356 mb_copy->m_data -= sizeof(multicast_encap_iphdr);
1358 if (vifp->v_rate_limit == 0)
1359 tbf_send_packet(vifp, mb_copy);
1361 tbf_control(vifp, mb_copy, ip, ip_copy->ip_len);
1365 * De-encapsulate a packet and feed it back through ip input (this
1366 * routine is called whenever IP gets a packet with proto type
1367 * ENCAP_PROTO and a local destination address).
1369 * This is similar to mroute_encapcheck() + mroute_encap_input() in -current.
1372 X_ipip_input(struct mbuf *m, int off, int proto)
1374 struct ip *ip = mtod(m, struct ip *);
1375 int hlen = ip->ip_hl << 2;
1377 struct ifqueue *ifq;
1379 if (!have_encap_tunnel) {
1380 rip_input(m, off, proto);
1384 * dump the packet if it's not to a multicast destination or if
1385 * we don't have an encapsulating tunnel with the source.
1386 * Note: This code assumes that the remote site IP address
1387 * uniquely identifies the tunnel (i.e., that this site has
1388 * at most one tunnel with the remote site).
1390 if (!IN_MULTICAST(ntohl(((struct ip *)((char *)ip+hlen))->ip_dst.s_addr))) {
1391 ++mrtstat.mrts_bad_tunnel;
1395 if (ip->ip_src.s_addr != last_encap_src) {
1396 struct vif *vifp = viftable;
1397 struct vif *vife = vifp + numvifs;
1399 last_encap_src = ip->ip_src.s_addr;
1400 last_encap_vif = NULL;
1401 for ( ; vifp < vife; ++vifp)
1402 if (vifp->v_rmt_addr.s_addr == ip->ip_src.s_addr) {
1403 if ((vifp->v_flags & (VIFF_TUNNEL|VIFF_SRCRT))
1405 last_encap_vif = vifp;
1409 if (last_encap_vif == NULL) {
1410 last_encap_src = INADDR_ANY;
1411 mrtstat.mrts_cant_tunnel++; /*XXX*/
1414 log(LOG_DEBUG, "ip_mforward: no tunnel with %lx\n",
1415 (u_long)ntohl(ip->ip_src.s_addr));
1419 if (hlen > sizeof(struct ip))
1420 ip_stripoptions(m, NULL);
1421 m->m_data += sizeof(struct ip);
1422 m->m_len -= sizeof(struct ip);
1423 m->m_pkthdr.len -= sizeof(struct ip);
1424 m->m_pkthdr.rcvif = last_encap_vif->v_ifp;
1428 if (IF_QFULL(ifq)) {
1434 * normally we would need a "schednetisr(NETISR_IP)"
1435 * here but we were called by ip_input and it is going
1436 * to loop back & try to dequeue the packet we just
1437 * queued as soon as we return so we avoid the
1438 * unnecessary software interrrupt.
1445 * Token bucket filter module
1449 tbf_control(struct vif *vifp, struct mbuf *m, struct ip *ip, u_long p_len)
1451 struct tbf *t = vifp->v_tbf;
1453 if (p_len > MAX_BKT_SIZE) { /* drop if packet is too large */
1454 mrtstat.mrts_pkt2large++;
1459 tbf_update_tokens(vifp);
1461 if (t->tbf_q_len == 0) { /* queue empty... */
1462 if (p_len <= t->tbf_n_tok) { /* send packet if enough tokens */
1463 t->tbf_n_tok -= p_len;
1464 tbf_send_packet(vifp, m);
1465 } else { /* no, queue packet and try later */
1467 timeout(tbf_reprocess_q, (caddr_t)vifp, TBF_REPROCESS);
1469 } else if (t->tbf_q_len < t->tbf_max_q_len) {
1470 /* finite queue length, so queue pkts and process queue */
1472 tbf_process_q(vifp);
1474 /* queue full, try to dq and queue and process */
1475 if (!tbf_dq_sel(vifp, ip)) {
1476 mrtstat.mrts_q_overflow++;
1480 tbf_process_q(vifp);
1486 * adds a packet to the queue at the interface
1489 tbf_queue(struct vif *vifp, struct mbuf *m)
1492 struct tbf *t = vifp->v_tbf;
1494 if (t->tbf_t == NULL) /* Queue was empty */
1496 else /* Insert at tail */
1497 t->tbf_t->m_act = m;
1499 t->tbf_t = m; /* Set new tail pointer */
1502 /* Make sure we didn't get fed a bogus mbuf */
1504 panic("tbf_queue: m_act");
1514 * processes the queue at the interface
1517 tbf_process_q(struct vif *vifp)
1520 struct tbf *t = vifp->v_tbf;
1522 /* loop through the queue at the interface and send as many packets
1525 while (t->tbf_q_len > 0) {
1526 struct mbuf *m = t->tbf_q;
1527 int len = mtod(m, struct ip *)->ip_len;
1529 /* determine if the packet can be sent */
1530 if (len > t->tbf_n_tok) /* not enough tokens, we are done */
1532 /* ok, reduce no of tokens, dequeue and send the packet. */
1533 t->tbf_n_tok -= len;
1535 t->tbf_q = m->m_act;
1536 if (--t->tbf_q_len == 0)
1540 tbf_send_packet(vifp, m);
1546 tbf_reprocess_q(void *xvifp)
1548 struct vif *vifp = xvifp;
1550 if (ip_mrouter == NULL)
1552 tbf_update_tokens(vifp);
1553 tbf_process_q(vifp);
1554 if (vifp->v_tbf->tbf_q_len)
1555 timeout(tbf_reprocess_q, (caddr_t)vifp, TBF_REPROCESS);
1558 /* function that will selectively discard a member of the queue
1559 * based on the precedence value and the priority
1562 tbf_dq_sel(struct vif *vifp, struct ip *ip)
1566 struct mbuf *m, *last;
1568 struct tbf *t = vifp->v_tbf;
1570 p = priority(vifp, ip);
1574 while ((m = *np) != NULL) {
1575 if (p > priority(vifp, mtod(m, struct ip *))) {
1577 /* If we're removing the last packet, fix the tail pointer */
1581 /* It's impossible for the queue to be empty, but check anyways. */
1582 if (--t->tbf_q_len == 0)
1585 mrtstat.mrts_drop_sel++;
1596 tbf_send_packet(struct vif *vifp, struct mbuf *m)
1600 if (vifp->v_flags & VIFF_TUNNEL) /* If tunnel options */
1601 ip_output(m, NULL, &vifp->v_route, IP_FORWARDING, NULL, NULL);
1603 struct ip_moptions imo;
1605 static struct route ro; /* XXX check this */
1607 imo.imo_multicast_ifp = vifp->v_ifp;
1608 imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
1609 imo.imo_multicast_loop = 1;
1610 imo.imo_multicast_vif = -1;
1613 * Re-entrancy should not be a problem here, because
1614 * the packets that we send out and are looped back at us
1615 * should get rejected because they appear to come from
1616 * the loopback interface, thus preventing looping.
1618 error = ip_output(m, NULL, &ro, IP_FORWARDING, &imo, NULL);
1620 if (mrtdebug & DEBUG_XMIT)
1621 log(LOG_DEBUG, "phyint_send on vif %d err %d\n",
1622 (int)(vifp - viftable), error);
1627 /* determine the current time and then
1628 * the elapsed time (between the last time and time now)
1629 * in milliseconds & update the no. of tokens in the bucket
1632 tbf_update_tokens(struct vif *vifp)
1637 struct tbf *t = vifp->v_tbf;
1641 TV_DELTA(tp, t->tbf_last_pkt_t, tm);
1644 * This formula is actually
1645 * "time in seconds" * "bytes/second".
1647 * (tm / 1000000) * (v_rate_limit * 1000 * (1000/1024) / 8)
1649 * The (1000/1024) was introduced in add_vif to optimize
1650 * this divide into a shift.
1652 t->tbf_n_tok += tm * vifp->v_rate_limit / 1024 / 8;
1653 t->tbf_last_pkt_t = tp;
1655 if (t->tbf_n_tok > MAX_BKT_SIZE)
1656 t->tbf_n_tok = MAX_BKT_SIZE;
1662 priority(struct vif *vifp, struct ip *ip)
1664 int prio = 50; /* the lowest priority -- default case */
1666 /* temporary hack; may add general packet classifier some day */
1669 * The UDP port space is divided up into four priority ranges:
1670 * [0, 16384) : unclassified - lowest priority
1671 * [16384, 32768) : audio - highest priority
1672 * [32768, 49152) : whiteboard - medium priority
1673 * [49152, 65536) : video - low priority
1675 * Everything else gets lowest priority.
1677 if (ip->ip_p == IPPROTO_UDP) {
1678 struct udphdr *udp = (struct udphdr *)(((char *)ip) + (ip->ip_hl << 2));
1679 switch (ntohs(udp->uh_dport) & 0xc000) {
1695 * End of token bucket filter modifications
1699 X_ip_rsvp_vif(struct socket *so, struct sockopt *sopt)
1703 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
1706 error = sooptcopyin(sopt, &vifi, sizeof vifi, sizeof vifi);
1712 if (vifi < 0 || vifi >= numvifs) { /* Error if vif is invalid */
1714 return EADDRNOTAVAIL;
1717 if (sopt->sopt_name == IP_RSVP_VIF_ON) {
1718 /* Check if socket is available. */
1719 if (viftable[vifi].v_rsvpd != NULL) {
1724 viftable[vifi].v_rsvpd = so;
1725 /* This may seem silly, but we need to be sure we don't over-increment
1726 * the RSVP counter, in case something slips up.
1728 if (!viftable[vifi].v_rsvp_on) {
1729 viftable[vifi].v_rsvp_on = 1;
1732 } else { /* must be VIF_OFF */
1734 * XXX as an additional consistency check, one could make sure
1735 * that viftable[vifi].v_rsvpd == so, otherwise passing so as
1736 * first parameter is pretty useless.
1738 viftable[vifi].v_rsvpd = NULL;
1740 * This may seem silly, but we need to be sure we don't over-decrement
1741 * the RSVP counter, in case something slips up.
1743 if (viftable[vifi].v_rsvp_on) {
1744 viftable[vifi].v_rsvp_on = 0;
1753 X_ip_rsvp_force_done(struct socket *so)
1758 /* Don't bother if it is not the right type of socket. */
1759 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
1764 /* The socket may be attached to more than one vif...this
1765 * is perfectly legal.
1767 for (vifi = 0; vifi < numvifs; vifi++) {
1768 if (viftable[vifi].v_rsvpd == so) {
1769 viftable[vifi].v_rsvpd = NULL;
1770 /* This may seem silly, but we need to be sure we don't
1771 * over-decrement the RSVP counter, in case something slips up.
1773 if (viftable[vifi].v_rsvp_on) {
1774 viftable[vifi].v_rsvp_on = 0;
1784 X_rsvp_input(struct mbuf *m, int off, int proto)
1787 struct ip *ip = mtod(m, struct ip *);
1788 struct sockaddr_in rsvp_src = { sizeof rsvp_src, AF_INET };
1793 printf("rsvp_input: rsvp_on %d\n",rsvp_on);
1795 /* Can still get packets with rsvp_on = 0 if there is a local member
1796 * of the group to which the RSVP packet is addressed. But in this
1797 * case we want to throw the packet away.
1807 printf("rsvp_input: check vifs\n");
1810 if (!(m->m_flags & M_PKTHDR))
1811 panic("rsvp_input no hdr");
1814 ifp = m->m_pkthdr.rcvif;
1815 /* Find which vif the packet arrived on. */
1816 for (vifi = 0; vifi < numvifs; vifi++)
1817 if (viftable[vifi].v_ifp == ifp)
1820 if (vifi == numvifs || viftable[vifi].v_rsvpd == NULL) {
1822 * If the old-style non-vif-associated socket is set,
1823 * then use it. Otherwise, drop packet since there
1824 * is no specific socket for this vif.
1826 if (ip_rsvpd != NULL) {
1828 printf("rsvp_input: Sending packet up old-style socket\n");
1829 rip_input(m, off, proto); /* xxx */
1831 if (rsvpdebug && vifi == numvifs)
1832 printf("rsvp_input: Can't find vif for packet.\n");
1833 else if (rsvpdebug && viftable[vifi].v_rsvpd == NULL)
1834 printf("rsvp_input: No socket defined for vif %d\n",vifi);
1840 rsvp_src.sin_addr = ip->ip_src;
1843 printf("rsvp_input: m->m_len = %d, sbspace() = %ld\n",
1844 m->m_len,sbspace(&(viftable[vifi].v_rsvpd->so_rcv)));
1846 if (socket_send(viftable[vifi].v_rsvpd, m, &rsvp_src) < 0) {
1848 printf("rsvp_input: Failed to append to socket\n");
1851 printf("rsvp_input: send packet up\n");
1858 ip_mroute_modevent(module_t mod, int type, void *unused)
1865 /* XXX Protect against multiple loading */
1866 ip_mcast_src = X_ip_mcast_src;
1867 ip_mforward = X_ip_mforward;
1868 ip_mrouter_done = X_ip_mrouter_done;
1869 ip_mrouter_get = X_ip_mrouter_get;
1870 ip_mrouter_set = X_ip_mrouter_set;
1871 ip_rsvp_force_done = X_ip_rsvp_force_done;
1872 ip_rsvp_vif = X_ip_rsvp_vif;
1873 ipip_input = X_ipip_input;
1874 legal_vif_num = X_legal_vif_num;
1875 mrt_ioctl = X_mrt_ioctl;
1876 rsvp_input_p = X_rsvp_input;
1885 ip_mcast_src = NULL;
1887 ip_mrouter_done = NULL;
1888 ip_mrouter_get = NULL;
1889 ip_mrouter_set = NULL;
1890 ip_rsvp_force_done = NULL;
1893 legal_vif_num = NULL;
1895 rsvp_input_p = NULL;
1902 static moduledata_t ip_mroutemod = {
1907 DECLARE_MODULE(ip_mroute, ip_mroutemod, SI_SUB_PSEUDO, SI_ORDER_ANY);