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
10 * Modified by Ahmed Helmy, SGI, June 1996
11 * Modified by George Edmond Eddy (Rusty), ISI, February 1998
12 * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000
13 * Modified by Hitoshi Asaeda, WIDE, August 2000
14 * Modified by Pavlin Radoslavov, ICSI, October 2002
16 * MROUTING Revision: 3.5
17 * and PIM-SMv2 and PIM-DM support, advanced API support,
18 * bandwidth metering and signaling
24 #include "opt_mrouting.h"
25 #include "opt_random_ip_id.h"
31 #include <sys/param.h>
32 #include <sys/kernel.h>
35 #include <sys/malloc.h>
37 #include <sys/module.h>
38 #include <sys/protosw.h>
39 #include <sys/signalvar.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
42 #include <sys/sockio.h>
44 #include <sys/sysctl.h>
45 #include <sys/syslog.h>
46 #include <sys/systm.h>
49 #include <net/netisr.h>
50 #include <net/route.h>
51 #include <netinet/in.h>
52 #include <netinet/igmp.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/in_var.h>
55 #include <netinet/ip.h>
56 #include <netinet/ip_encap.h>
57 #include <netinet/ip_mroute.h>
58 #include <netinet/ip_var.h>
60 #include <netinet/pim.h>
61 #include <netinet/pim_var.h>
63 #include <netinet/udp.h>
64 #include <machine/in_cksum.h>
67 * Control debugging code for rsvp and multicast routing code.
68 * Can only set them with the debugger.
70 static u_int rsvpdebug; /* non-zero enables debugging */
72 static u_int mrtdebug; /* any set of the flags below */
73 #define DEBUG_MFC 0x02
74 #define DEBUG_FORWARD 0x04
75 #define DEBUG_EXPIRE 0x08
76 #define DEBUG_XMIT 0x10
77 #define DEBUG_PIM 0x20
79 #define VIFI_INVALID ((vifi_t) -1)
81 #define M_HASCL(m) ((m)->m_flags & M_EXT)
83 static MALLOC_DEFINE(M_MRTABLE, "mroutetbl", "multicast routing tables");
86 * Locking. We use two locks: one for the virtual interface table and
87 * one for the forwarding table. These locks may be nested in which case
88 * the VIF lock must always be taken first. Note that each lock is used
89 * to cover not only the specific data structure but also related data
90 * structures. It may be better to add more fine-grained locking later;
91 * it's not clear how performance-critical this code is.
94 static struct mrtstat mrtstat;
95 SYSCTL_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW,
97 "Multicast Routing Statistics (struct mrtstat, netinet/ip_mroute.h)");
99 static struct mfc *mfctable[MFCTBLSIZ];
100 SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, mfctable, CTLFLAG_RD,
101 &mfctable, sizeof(mfctable), "S,*mfc[MFCTBLSIZ]",
102 "Multicast Forwarding Table (struct *mfc[MFCTBLSIZ], netinet/ip_mroute.h)");
104 static struct mtx mfc_mtx;
105 #define MFC_LOCK() mtx_lock(&mfc_mtx)
106 #define MFC_UNLOCK() mtx_unlock(&mfc_mtx)
107 #define MFC_LOCK_ASSERT() mtx_assert(&mfc_mtx, MA_OWNED)
108 #define MFC_LOCK_INIT() mtx_init(&mfc_mtx, "mroute mfc table", NULL, MTX_DEF)
109 #define MFC_LOCK_DESTROY() mtx_destroy(&mfc_mtx)
111 static struct vif viftable[MAXVIFS];
112 SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD,
113 &viftable, sizeof(viftable), "S,vif[MAXVIFS]",
114 "Multicast Virtual Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)");
116 static struct mtx vif_mtx;
117 #define VIF_LOCK() mtx_lock(&vif_mtx)
118 #define VIF_UNLOCK() mtx_unlock(&vif_mtx)
119 #define VIF_LOCK_ASSERT() mtx_assert(&vif_mtx, MA_OWNED)
120 #define VIF_LOCK_INIT() mtx_init(&vif_mtx, "mroute vif table", NULL, MTX_DEF)
121 #define VIF_LOCK_DESTROY() mtx_destroy(&vif_mtx)
123 static u_char nexpire[MFCTBLSIZ];
125 static struct callout expire_upcalls_ch;
127 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
128 #define UPCALL_EXPIRE 6 /* number of timeouts */
131 * Define the token bucket filter structures
132 * tbftable -> each vif has one of these for storing info
135 static struct tbf tbftable[MAXVIFS];
136 #define TBF_REPROCESS (hz / 100) /* 100x / second */
139 * 'Interfaces' associated with decapsulator (so we can tell
140 * packets that went through it from ones that get reflected
141 * by a broken gateway). These interfaces are never linked into
142 * the system ifnet list & no routes point to them. I.e., packets
143 * can't be sent this way. They only exist as a placeholder for
144 * multicast source verification.
146 static struct ifnet multicast_decap_if[MAXVIFS];
149 #define ENCAP_PROTO IPPROTO_IPIP /* 4 */
151 /* prototype IP hdr for encapsulated packets */
152 static struct ip multicast_encap_iphdr = {
153 #if BYTE_ORDER == LITTLE_ENDIAN
154 sizeof(struct ip) >> 2, IPVERSION,
156 IPVERSION, sizeof(struct ip) >> 2,
159 sizeof(struct ip), /* total length */
162 ENCAP_TTL, ENCAP_PROTO,
167 * Bandwidth meter variables and constants
169 static MALLOC_DEFINE(M_BWMETER, "bwmeter", "multicast upcall bw meters");
171 * Pending timeouts are stored in a hash table, the key being the
172 * expiration time. Periodically, the entries are analysed and processed.
174 #define BW_METER_BUCKETS 1024
175 static struct bw_meter *bw_meter_timers[BW_METER_BUCKETS];
176 static struct callout bw_meter_ch;
177 #define BW_METER_PERIOD (hz) /* periodical handling of bw meters */
180 * Pending upcalls are stored in a vector which is flushed when
181 * full, or periodically
183 static struct bw_upcall bw_upcalls[BW_UPCALLS_MAX];
184 static u_int bw_upcalls_n; /* # of pending upcalls */
185 static struct callout bw_upcalls_ch;
186 #define BW_UPCALLS_PERIOD (hz) /* periodical flush of bw upcalls */
189 static struct pimstat pimstat;
190 SYSCTL_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD,
192 "PIM Statistics (struct pimstat, netinet/pim_var.h)");
195 * Note: the PIM Register encapsulation adds the following in front of a
198 * struct pim_encap_hdr {
200 * struct pim_encap_pimhdr pim;
205 struct pim_encap_pimhdr {
210 static struct ip pim_encap_iphdr = {
211 #if BYTE_ORDER == LITTLE_ENDIAN
212 sizeof(struct ip) >> 2,
216 sizeof(struct ip) >> 2,
219 sizeof(struct ip), /* total length */
227 static struct pim_encap_pimhdr pim_encap_pimhdr = {
229 PIM_MAKE_VT(PIM_VERSION, PIM_REGISTER), /* PIM vers and message type */
236 static struct ifnet multicast_register_if;
237 static vifi_t reg_vif_num = VIFI_INVALID;
243 static vifi_t numvifs;
244 static const struct encaptab *encap_cookie;
247 * one-back cache used by mroute_encapcheck to locate a tunnel's vif
248 * given a datagram's src ip address.
250 static u_long last_encap_src;
251 static struct vif *last_encap_vif;
254 * Callout for queue processing.
256 static struct callout tbf_reprocess_ch;
258 static u_long X_ip_mcast_src(int vifi);
259 static int X_ip_mforward(struct ip *ip, struct ifnet *ifp,
260 struct mbuf *m, struct ip_moptions *imo);
261 static int X_ip_mrouter_done(void);
262 static int X_ip_mrouter_get(struct socket *so, struct sockopt *m);
263 static int X_ip_mrouter_set(struct socket *so, struct sockopt *m);
264 static int X_legal_vif_num(int vif);
265 static int X_mrt_ioctl(int cmd, caddr_t data);
267 static int get_sg_cnt(struct sioc_sg_req *);
268 static int get_vif_cnt(struct sioc_vif_req *);
269 static int ip_mrouter_init(struct socket *, int);
270 static int add_vif(struct vifctl *);
271 static int del_vif(vifi_t);
272 static int add_mfc(struct mfcctl2 *);
273 static int del_mfc(struct mfcctl2 *);
274 static int set_api_config(uint32_t *); /* chose API capabilities */
275 static int socket_send(struct socket *, struct mbuf *, struct sockaddr_in *);
276 static int set_assert(int);
277 static void expire_upcalls(void *);
278 static int ip_mdq(struct mbuf *, struct ifnet *, struct mfc *, vifi_t);
279 static void phyint_send(struct ip *, struct vif *, struct mbuf *);
280 static void encap_send(struct ip *, struct vif *, struct mbuf *);
281 static void tbf_control(struct vif *, struct mbuf *, struct ip *, u_long);
282 static void tbf_queue(struct vif *, struct mbuf *);
283 static void tbf_process_q(struct vif *);
284 static void tbf_reprocess_q(void *);
285 static int tbf_dq_sel(struct vif *, struct ip *);
286 static void tbf_send_packet(struct vif *, struct mbuf *);
287 static void tbf_update_tokens(struct vif *);
288 static int priority(struct vif *, struct ip *);
291 * Bandwidth monitoring
293 static void free_bw_list(struct bw_meter *list);
294 static int add_bw_upcall(struct bw_upcall *);
295 static int del_bw_upcall(struct bw_upcall *);
296 static void bw_meter_receive_packet(struct bw_meter *x, int plen,
297 struct timeval *nowp);
298 static void bw_meter_prepare_upcall(struct bw_meter *x, struct timeval *nowp);
299 static void bw_upcalls_send(void);
300 static void schedule_bw_meter(struct bw_meter *x, struct timeval *nowp);
301 static void unschedule_bw_meter(struct bw_meter *x);
302 static void bw_meter_process(void);
303 static void expire_bw_upcalls_send(void *);
304 static void expire_bw_meter_process(void *);
307 static int pim_register_send(struct ip *, struct vif *,
308 struct mbuf *, struct mfc *);
309 static int pim_register_send_rp(struct ip *, struct vif *,
310 struct mbuf *, struct mfc *);
311 static int pim_register_send_upcall(struct ip *, struct vif *,
312 struct mbuf *, struct mfc *);
313 static struct mbuf *pim_register_prepare(struct ip *, struct mbuf *);
317 * whether or not special PIM assert processing is enabled.
319 static int pim_assert;
321 * Rate limit for assert notification messages, in usec
323 #define ASSERT_MSG_TIME 3000000
326 * Kernel multicast routing API capabilities and setup.
327 * If more API capabilities are added to the kernel, they should be
328 * recorded in `mrt_api_support'.
330 static const uint32_t mrt_api_support = (MRT_MFC_FLAGS_DISABLE_WRONGVIF |
331 MRT_MFC_FLAGS_BORDER_VIF |
334 static uint32_t mrt_api_config = 0;
337 * Hash function for a source, group entry
339 #define MFCHASH(a, g) MFCHASHMOD(((a) >> 20) ^ ((a) >> 10) ^ (a) ^ \
340 ((g) >> 20) ^ ((g) >> 10) ^ (g))
343 * Find a route for a given origin IP address and Multicast group address
344 * Type of service parameter to be added in the future!!!
345 * Statistics are updated by the caller if needed
346 * (mrtstat.mrts_mfc_lookups and mrtstat.mrts_mfc_misses)
349 mfc_find(in_addr_t o, in_addr_t g)
355 for (rt = mfctable[MFCHASH(o,g)]; rt; rt = rt->mfc_next)
356 if ((rt->mfc_origin.s_addr == o) &&
357 (rt->mfc_mcastgrp.s_addr == g) && (rt->mfc_stall == NULL))
363 * Macros to compute elapsed time efficiently
364 * Borrowed from Van Jacobson's scheduling code
366 #define TV_DELTA(a, b, delta) { \
368 delta = (a).tv_usec - (b).tv_usec; \
369 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
378 delta += (1000000 * xxs); \
383 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
384 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
387 * Handle MRT setsockopt commands to modify the multicast routing tables.
390 X_ip_mrouter_set(struct socket *so, struct sockopt *sopt)
396 struct bw_upcall bw_upcall;
399 if (so != ip_mrouter && sopt->sopt_name != MRT_INIT)
403 switch (sopt->sopt_name) {
405 error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval);
408 error = ip_mrouter_init(so, optval);
412 error = ip_mrouter_done();
416 error = sooptcopyin(sopt, &vifc, sizeof vifc, sizeof vifc);
419 error = add_vif(&vifc);
423 error = sooptcopyin(sopt, &vifi, sizeof vifi, sizeof vifi);
426 error = del_vif(vifi);
432 * select data size depending on API version.
434 if (sopt->sopt_name == MRT_ADD_MFC &&
435 mrt_api_config & MRT_API_FLAGS_ALL) {
436 error = sooptcopyin(sopt, &mfc, sizeof(struct mfcctl2),
437 sizeof(struct mfcctl2));
439 error = sooptcopyin(sopt, &mfc, sizeof(struct mfcctl),
440 sizeof(struct mfcctl));
441 bzero((caddr_t)&mfc + sizeof(struct mfcctl),
442 sizeof(mfc) - sizeof(struct mfcctl));
446 if (sopt->sopt_name == MRT_ADD_MFC)
447 error = add_mfc(&mfc);
449 error = del_mfc(&mfc);
453 error = sooptcopyin(sopt, &optval, sizeof optval, sizeof optval);
460 error = sooptcopyin(sopt, &i, sizeof i, sizeof i);
462 error = set_api_config(&i);
464 error = sooptcopyout(sopt, &i, sizeof i);
467 case MRT_ADD_BW_UPCALL:
468 case MRT_DEL_BW_UPCALL:
469 error = sooptcopyin(sopt, &bw_upcall, sizeof bw_upcall,
473 if (sopt->sopt_name == MRT_ADD_BW_UPCALL)
474 error = add_bw_upcall(&bw_upcall);
476 error = del_bw_upcall(&bw_upcall);
487 * Handle MRT getsockopt commands
490 X_ip_mrouter_get(struct socket *so, struct sockopt *sopt)
493 static int version = 0x0305; /* !!! why is this here? XXX */
495 switch (sopt->sopt_name) {
497 error = sooptcopyout(sopt, &version, sizeof version);
501 error = sooptcopyout(sopt, &pim_assert, sizeof pim_assert);
504 case MRT_API_SUPPORT:
505 error = sooptcopyout(sopt, &mrt_api_support, sizeof mrt_api_support);
509 error = sooptcopyout(sopt, &mrt_api_config, sizeof mrt_api_config);
520 * Handle ioctl commands to obtain information from the cache
523 X_mrt_ioctl(int cmd, caddr_t data)
528 case (SIOCGETVIFCNT):
529 error = get_vif_cnt((struct sioc_vif_req *)data);
533 error = get_sg_cnt((struct sioc_sg_req *)data);
544 * returns the packet, byte, rpf-failure count for the source group provided
547 get_sg_cnt(struct sioc_sg_req *req)
552 rt = mfc_find(req->src.s_addr, req->grp.s_addr);
555 req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
556 return EADDRNOTAVAIL;
558 req->pktcnt = rt->mfc_pkt_cnt;
559 req->bytecnt = rt->mfc_byte_cnt;
560 req->wrong_if = rt->mfc_wrong_if;
566 * returns the input and output packet and byte counts on the vif provided
569 get_vif_cnt(struct sioc_vif_req *req)
571 vifi_t vifi = req->vifi;
574 if (vifi >= numvifs) {
579 req->icount = viftable[vifi].v_pkt_in;
580 req->ocount = viftable[vifi].v_pkt_out;
581 req->ibytes = viftable[vifi].v_bytes_in;
582 req->obytes = viftable[vifi].v_bytes_out;
589 ip_mrouter_reset(void)
591 bzero((caddr_t)mfctable, sizeof(mfctable));
592 bzero((caddr_t)nexpire, sizeof(nexpire));
597 callout_init(&expire_upcalls_ch, CALLOUT_MPSAFE);
600 bzero((caddr_t)bw_meter_timers, sizeof(bw_meter_timers));
601 callout_init(&bw_upcalls_ch, CALLOUT_MPSAFE);
602 callout_init(&bw_meter_ch, CALLOUT_MPSAFE);
604 callout_init(&tbf_reprocess_ch, CALLOUT_MPSAFE);
607 static struct mtx mrouter_mtx; /* used to synch init/done work */
610 * Enable multicast routing
613 ip_mrouter_init(struct socket *so, int version)
616 log(LOG_DEBUG, "ip_mrouter_init: so_type = %d, pr_protocol = %d\n",
617 so->so_type, so->so_proto->pr_protocol);
619 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_IGMP)
625 mtx_lock(&mrouter_mtx);
627 if (ip_mrouter != NULL) {
628 mtx_unlock(&mrouter_mtx);
632 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL);
634 callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
635 expire_bw_upcalls_send, NULL);
636 callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL);
640 mtx_unlock(&mrouter_mtx);
643 log(LOG_DEBUG, "ip_mrouter_init\n");
649 * Disable multicast routing
652 X_ip_mrouter_done(void)
661 mtx_lock(&mrouter_mtx);
663 if (ip_mrouter == NULL) {
664 mtx_unlock(&mrouter_mtx);
669 * Detach/disable hooks to the reset of the system.
676 const struct encaptab *c = encap_cookie;
682 callout_stop(&tbf_reprocess_ch);
686 * For each phyint in use, disable promiscuous reception of all IP
689 for (vifi = 0; vifi < numvifs; vifi++) {
690 if (viftable[vifi].v_lcl_addr.s_addr != 0 &&
691 !(viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) {
692 struct sockaddr_in *so = (struct sockaddr_in *)&(ifr.ifr_addr);
694 so->sin_len = sizeof(struct sockaddr_in);
695 so->sin_family = AF_INET;
696 so->sin_addr.s_addr = INADDR_ANY;
697 ifp = viftable[vifi].v_ifp;
701 bzero((caddr_t)tbftable, sizeof(tbftable));
702 bzero((caddr_t)viftable, sizeof(viftable));
708 * Free all multicast forwarding cache entries.
710 callout_stop(&expire_upcalls_ch);
711 callout_stop(&bw_upcalls_ch);
712 callout_stop(&bw_meter_ch);
715 for (i = 0; i < MFCTBLSIZ; i++) {
716 for (rt = mfctable[i]; rt != NULL; ) {
717 struct mfc *nr = rt->mfc_next;
719 for (rte = rt->mfc_stall; rte != NULL; ) {
720 struct rtdetq *n = rte->next;
723 free(rte, M_MRTABLE);
726 free_bw_list(rt->mfc_bw_meter);
731 bzero((caddr_t)mfctable, sizeof(mfctable));
732 bzero((caddr_t)nexpire, sizeof(nexpire));
734 bzero(bw_meter_timers, sizeof(bw_meter_timers));
738 * Reset de-encapsulation cache
740 last_encap_src = INADDR_ANY;
741 last_encap_vif = NULL;
743 reg_vif_num = VIFI_INVALID;
746 mtx_unlock(&mrouter_mtx);
749 log(LOG_DEBUG, "ip_mrouter_done\n");
755 * Set PIM assert processing global
760 if ((i != 1) && (i != 0))
769 * Configure API capabilities
772 set_api_config(uint32_t *apival)
777 * We can set the API capabilities only if it is the first operation
778 * after MRT_INIT. I.e.:
779 * - there are no vifs installed
780 * - pim_assert is not enabled
781 * - the MFC table is empty
791 for (i = 0; i < MFCTBLSIZ; i++) {
792 if (mfctable[i] != NULL) {
798 mrt_api_config = *apival & mrt_api_support;
799 *apival = mrt_api_config;
805 * Decide if a packet is from a tunnelled peer.
806 * Return 0 if not, 64 if so. XXX yuck.. 64 ???
809 mroute_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
811 struct ip *ip = mtod(m, struct ip *);
812 int hlen = ip->ip_hl << 2;
815 * don't claim the packet if it's not to a multicast destination or if
816 * we don't have an encapsulating tunnel with the source.
817 * Note: This code assumes that the remote site IP address
818 * uniquely identifies the tunnel (i.e., that this site has
819 * at most one tunnel with the remote site).
821 if (!IN_MULTICAST(ntohl(((struct ip *)((char *)ip+hlen))->ip_dst.s_addr)))
823 if (ip->ip_src.s_addr != last_encap_src) {
824 struct vif *vifp = viftable;
825 struct vif *vife = vifp + numvifs;
827 last_encap_src = ip->ip_src.s_addr;
828 last_encap_vif = NULL;
829 for ( ; vifp < vife; ++vifp)
830 if (vifp->v_rmt_addr.s_addr == ip->ip_src.s_addr) {
831 if ((vifp->v_flags & (VIFF_TUNNEL|VIFF_SRCRT)) == VIFF_TUNNEL)
832 last_encap_vif = vifp;
836 if (last_encap_vif == NULL) {
837 last_encap_src = INADDR_ANY;
844 * De-encapsulate a packet and feed it back through ip input (this
845 * routine is called whenever IP gets a packet that mroute_encap_func()
849 mroute_encap_input(struct mbuf *m, int off)
851 struct ip *ip = mtod(m, struct ip *);
852 int hlen = ip->ip_hl << 2;
854 if (hlen > sizeof(struct ip))
855 ip_stripoptions(m, (struct mbuf *) 0);
856 m->m_data += sizeof(struct ip);
857 m->m_len -= sizeof(struct ip);
858 m->m_pkthdr.len -= sizeof(struct ip);
860 m->m_pkthdr.rcvif = last_encap_vif->v_ifp;
862 netisr_queue(NETISR_IP, m);
864 * normally we would need a "schednetisr(NETISR_IP)"
865 * here but we were called by ip_input and it is going
866 * to loop back & try to dequeue the packet we just
867 * queued as soon as we return so we avoid the
868 * unnecessary software interrrupt.
871 * This no longer holds - we may have direct-dispatched the packet,
872 * or there may be a queue processing limit.
876 extern struct domain inetdomain;
877 static struct protosw mroute_encap_protosw =
878 { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR,
879 mroute_encap_input, 0, 0, rip_ctloutput,
886 * Add a vif to the vif table
889 add_vif(struct vifctl *vifcp)
891 struct vif *vifp = viftable + vifcp->vifc_vifi;
892 struct sockaddr_in sin = {sizeof sin, AF_INET};
896 struct tbf *v_tbf = tbftable + vifcp->vifc_vifi;
899 if (vifcp->vifc_vifi >= MAXVIFS) {
903 if (vifp->v_lcl_addr.s_addr != INADDR_ANY) {
907 if (vifcp->vifc_lcl_addr.s_addr == INADDR_ANY) {
909 return EADDRNOTAVAIL;
912 /* Find the interface with an address in AF_INET family */
914 if (vifcp->vifc_flags & VIFF_REGISTER) {
916 * XXX: Because VIFF_REGISTER does not really need a valid
917 * local interface (e.g. it could be 127.0.0.2), we don't
924 sin.sin_addr = vifcp->vifc_lcl_addr;
925 ifa = ifa_ifwithaddr((struct sockaddr *)&sin);
928 return EADDRNOTAVAIL;
933 if (vifcp->vifc_flags & VIFF_TUNNEL) {
934 if ((vifcp->vifc_flags & VIFF_SRCRT) == 0) {
936 * An encapsulating tunnel is wanted. Tell
937 * mroute_encap_input() to start paying attention
938 * to encapsulated packets.
940 if (encap_cookie == NULL) {
943 encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
945 (struct protosw *)&mroute_encap_protosw, NULL);
947 if (encap_cookie == NULL) {
948 printf("ip_mroute: unable to attach encap\n");
950 return EIO; /* XXX */
952 for (i = 0; i < MAXVIFS; ++i) {
953 if_initname(&multicast_decap_if[i], "mdecap", i);
957 * Set interface to fake encapsulator interface
959 ifp = &multicast_decap_if[vifcp->vifc_vifi];
961 * Prepare cached route entry
963 bzero(&vifp->v_route, sizeof(vifp->v_route));
965 log(LOG_ERR, "source routed tunnels not supported\n");
970 } else if (vifcp->vifc_flags & VIFF_REGISTER) {
971 ifp = &multicast_register_if;
973 log(LOG_DEBUG, "Adding a register vif, ifp: %p\n",
974 (void *)&multicast_register_if);
975 if (reg_vif_num == VIFI_INVALID) {
976 if_initname(&multicast_register_if, "register_vif", 0);
977 multicast_register_if.if_flags = IFF_LOOPBACK;
978 bzero(&vifp->v_route, sizeof(vifp->v_route));
979 reg_vif_num = vifcp->vifc_vifi;
982 } else { /* Make sure the interface supports multicast */
983 if ((ifp->if_flags & IFF_MULTICAST) == 0) {
988 /* Enable promiscuous reception of all IP multicasts from the if */
989 error = if_allmulti(ifp, 1);
996 /* define parameters for the tbf structure */
998 GET_TIME(vifp->v_tbf->tbf_last_pkt_t);
999 vifp->v_tbf->tbf_n_tok = 0;
1000 vifp->v_tbf->tbf_q_len = 0;
1001 vifp->v_tbf->tbf_max_q_len = MAXQSIZE;
1002 vifp->v_tbf->tbf_q = vifp->v_tbf->tbf_t = NULL;
1004 vifp->v_flags = vifcp->vifc_flags;
1005 vifp->v_threshold = vifcp->vifc_threshold;
1006 vifp->v_lcl_addr = vifcp->vifc_lcl_addr;
1007 vifp->v_rmt_addr = vifcp->vifc_rmt_addr;
1009 /* scaling up here allows division by 1024 in critical code */
1010 vifp->v_rate_limit= vifcp->vifc_rate_limit * 1024 / 1000;
1011 vifp->v_rsvp_on = 0;
1012 vifp->v_rsvpd = NULL;
1013 /* initialize per vif pkt counters */
1015 vifp->v_pkt_out = 0;
1016 vifp->v_bytes_in = 0;
1017 vifp->v_bytes_out = 0;
1019 /* Adjust numvifs up if the vifi is higher than numvifs */
1020 if (numvifs <= vifcp->vifc_vifi) numvifs = vifcp->vifc_vifi + 1;
1025 log(LOG_DEBUG, "add_vif #%d, lcladdr %lx, %s %lx, thresh %x, rate %d\n",
1027 (u_long)ntohl(vifcp->vifc_lcl_addr.s_addr),
1028 (vifcp->vifc_flags & VIFF_TUNNEL) ? "rmtaddr" : "mask",
1029 (u_long)ntohl(vifcp->vifc_rmt_addr.s_addr),
1030 vifcp->vifc_threshold,
1031 vifcp->vifc_rate_limit);
1037 * Delete a vif from the vif table
1040 del_vif(vifi_t vifi)
1046 if (vifi >= numvifs) {
1050 vifp = &viftable[vifi];
1051 if (vifp->v_lcl_addr.s_addr == INADDR_ANY) {
1053 return EADDRNOTAVAIL;
1056 if (!(vifp->v_flags & (VIFF_TUNNEL | VIFF_REGISTER)))
1057 if_allmulti(vifp->v_ifp, 0);
1059 if (vifp == last_encap_vif) {
1060 last_encap_vif = NULL;
1061 last_encap_src = INADDR_ANY;
1065 * Free packets queued at the interface
1067 while (vifp->v_tbf->tbf_q) {
1068 struct mbuf *m = vifp->v_tbf->tbf_q;
1070 vifp->v_tbf->tbf_q = m->m_act;
1075 if (vifp->v_flags & VIFF_REGISTER)
1076 reg_vif_num = VIFI_INVALID;
1079 bzero((caddr_t)vifp->v_tbf, sizeof(*(vifp->v_tbf)));
1080 bzero((caddr_t)vifp, sizeof (*vifp));
1083 log(LOG_DEBUG, "del_vif %d, numvifs %d\n", vifi, numvifs);
1085 /* Adjust numvifs down */
1086 for (vifi = numvifs; vifi > 0; vifi--)
1087 if (viftable[vifi-1].v_lcl_addr.s_addr != INADDR_ANY)
1097 * update an mfc entry without resetting counters and S,G addresses.
1100 update_mfc_params(struct mfc *rt, struct mfcctl2 *mfccp)
1104 rt->mfc_parent = mfccp->mfcc_parent;
1105 for (i = 0; i < numvifs; i++) {
1106 rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
1107 rt->mfc_flags[i] = mfccp->mfcc_flags[i] & mrt_api_config &
1110 /* set the RP address */
1111 if (mrt_api_config & MRT_MFC_RP)
1112 rt->mfc_rp = mfccp->mfcc_rp;
1114 rt->mfc_rp.s_addr = INADDR_ANY;
1118 * fully initialize an mfc entry from the parameter.
1121 init_mfc_params(struct mfc *rt, struct mfcctl2 *mfccp)
1123 rt->mfc_origin = mfccp->mfcc_origin;
1124 rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
1126 update_mfc_params(rt, mfccp);
1128 /* initialize pkt counters per src-grp */
1129 rt->mfc_pkt_cnt = 0;
1130 rt->mfc_byte_cnt = 0;
1131 rt->mfc_wrong_if = 0;
1132 rt->mfc_last_assert.tv_sec = rt->mfc_last_assert.tv_usec = 0;
1140 add_mfc(struct mfcctl2 *mfccp)
1150 rt = mfc_find(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
1152 /* If an entry already exists, just update the fields */
1154 if (mrtdebug & DEBUG_MFC)
1155 log(LOG_DEBUG,"add_mfc update o %lx g %lx p %x\n",
1156 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1157 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1158 mfccp->mfcc_parent);
1160 update_mfc_params(rt, mfccp);
1167 * Find the entry for which the upcall was made and update
1169 hash = MFCHASH(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
1170 for (rt = mfctable[hash], nstl = 0; rt; rt = rt->mfc_next) {
1172 if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
1173 (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr) &&
1174 (rt->mfc_stall != NULL)) {
1177 log(LOG_ERR, "add_mfc %s o %lx g %lx p %x dbx %p\n",
1178 "multiple kernel entries",
1179 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1180 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1181 mfccp->mfcc_parent, (void *)rt->mfc_stall);
1183 if (mrtdebug & DEBUG_MFC)
1184 log(LOG_DEBUG,"add_mfc o %lx g %lx p %x dbg %p\n",
1185 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1186 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1187 mfccp->mfcc_parent, (void *)rt->mfc_stall);
1189 init_mfc_params(rt, mfccp);
1191 rt->mfc_expire = 0; /* Don't clean this guy up */
1194 /* free packets Qed at the end of this entry */
1195 for (rte = rt->mfc_stall; rte != NULL; ) {
1196 struct rtdetq *n = rte->next;
1198 ip_mdq(rte->m, rte->ifp, rt, -1);
1200 free(rte, M_MRTABLE);
1203 rt->mfc_stall = NULL;
1208 * It is possible that an entry is being inserted without an upcall
1211 if (mrtdebug & DEBUG_MFC)
1212 log(LOG_DEBUG,"add_mfc no upcall h %lu o %lx g %lx p %x\n",
1213 hash, (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1214 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1215 mfccp->mfcc_parent);
1217 for (rt = mfctable[hash]; rt != NULL; rt = rt->mfc_next) {
1218 if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
1219 (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr)) {
1220 init_mfc_params(rt, mfccp);
1227 if (rt == NULL) { /* no upcall, so make a new entry */
1228 rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
1235 init_mfc_params(rt, mfccp);
1237 rt->mfc_stall = NULL;
1239 rt->mfc_bw_meter = NULL;
1240 /* insert new entry at head of hash chain */
1241 rt->mfc_next = mfctable[hash];
1242 mfctable[hash] = rt;
1251 * Delete an mfc entry
1254 del_mfc(struct mfcctl2 *mfccp)
1256 struct in_addr origin;
1257 struct in_addr mcastgrp;
1261 struct bw_meter *list;
1263 origin = mfccp->mfcc_origin;
1264 mcastgrp = mfccp->mfcc_mcastgrp;
1266 if (mrtdebug & DEBUG_MFC)
1267 log(LOG_DEBUG,"del_mfc orig %lx mcastgrp %lx\n",
1268 (u_long)ntohl(origin.s_addr), (u_long)ntohl(mcastgrp.s_addr));
1272 hash = MFCHASH(origin.s_addr, mcastgrp.s_addr);
1273 for (nptr = &mfctable[hash]; (rt = *nptr) != NULL; nptr = &rt->mfc_next)
1274 if (origin.s_addr == rt->mfc_origin.s_addr &&
1275 mcastgrp.s_addr == rt->mfc_mcastgrp.s_addr &&
1276 rt->mfc_stall == NULL)
1280 return EADDRNOTAVAIL;
1283 *nptr = rt->mfc_next;
1286 * free the bw_meter entries
1288 list = rt->mfc_bw_meter;
1289 rt->mfc_bw_meter = NULL;
1291 free(rt, M_MRTABLE);
1301 * Send a message to mrouted on the multicast routing socket
1304 socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src)
1307 mtx_lock(&Giant); /* XXX until sockets are locked */
1308 if (sbappendaddr(&s->so_rcv, (struct sockaddr *)src, mm, NULL) != 0) {
1320 * IP multicast forwarding function. This function assumes that the packet
1321 * pointed to by "ip" has arrived on (or is about to be sent to) the interface
1322 * pointed to by "ifp", and the packet is to be relayed to other networks
1323 * that have members of the packet's destination IP multicast group.
1325 * The packet is returned unscathed to the caller, unless it is
1326 * erroneous, in which case a non-zero return value tells the caller to
1330 #define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */
1333 X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m,
1334 struct ip_moptions *imo)
1340 if (mrtdebug & DEBUG_FORWARD)
1341 log(LOG_DEBUG, "ip_mforward: src %lx, dst %lx, ifp %p\n",
1342 (u_long)ntohl(ip->ip_src.s_addr), (u_long)ntohl(ip->ip_dst.s_addr),
1345 if (ip->ip_hl < (sizeof(struct ip) + TUNNEL_LEN) >> 2 ||
1346 ((u_char *)(ip + 1))[1] != IPOPT_LSRR ) {
1348 * Packet arrived via a physical interface or
1349 * an encapsulated tunnel or a register_vif.
1353 * Packet arrived through a source-route tunnel.
1354 * Source-route tunnels are no longer supported.
1356 static int last_log;
1357 if (last_log != time_second) {
1358 last_log = time_second;
1360 "ip_mforward: received source-routed packet from %lx\n",
1361 (u_long)ntohl(ip->ip_src.s_addr));
1368 if (imo && ((vifi = imo->imo_multicast_vif) < numvifs)) {
1369 if (ip->ip_ttl < 255)
1370 ip->ip_ttl++; /* compensate for -1 in *_send routines */
1371 if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
1372 struct vif *vifp = viftable + vifi;
1374 printf("Sending IPPROTO_RSVP from %lx to %lx on vif %d (%s%s)\n",
1375 (long)ntohl(ip->ip_src.s_addr), (long)ntohl(ip->ip_dst.s_addr),
1377 (vifp->v_flags & VIFF_TUNNEL) ? "tunnel on " : "",
1378 vifp->v_ifp->if_xname);
1380 error = ip_mdq(m, ifp, NULL, vifi);
1385 if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
1386 printf("Warning: IPPROTO_RSVP from %lx to %lx without vif option\n",
1387 (long)ntohl(ip->ip_src.s_addr), (long)ntohl(ip->ip_dst.s_addr));
1389 printf("In fact, no options were specified at all\n");
1393 * Don't forward a packet with time-to-live of zero or one,
1394 * or a packet destined to a local-only group.
1396 if (ip->ip_ttl <= 1 || ntohl(ip->ip_dst.s_addr) <= INADDR_MAX_LOCAL_GROUP) {
1403 * Determine forwarding vifs from the forwarding cache table
1405 ++mrtstat.mrts_mfc_lookups;
1406 rt = mfc_find(ip->ip_src.s_addr, ip->ip_dst.s_addr);
1408 /* Entry exists, so forward if necessary */
1410 error = ip_mdq(m, ifp, rt, -1);
1416 * If we don't have a route for packet's origin,
1417 * Make a copy of the packet & send message to routing daemon
1423 int hlen = ip->ip_hl << 2;
1425 ++mrtstat.mrts_mfc_misses;
1427 mrtstat.mrts_no_route++;
1428 if (mrtdebug & (DEBUG_FORWARD | DEBUG_MFC))
1429 log(LOG_DEBUG, "ip_mforward: no rte s %lx g %lx\n",
1430 (u_long)ntohl(ip->ip_src.s_addr),
1431 (u_long)ntohl(ip->ip_dst.s_addr));
1434 * Allocate mbufs early so that we don't do extra work if we are
1435 * just going to fail anyway. Make sure to pullup the header so
1436 * that other people can't step on it.
1438 rte = (struct rtdetq *)malloc((sizeof *rte), M_MRTABLE, M_NOWAIT);
1444 mb0 = m_copypacket(m, M_DONTWAIT);
1445 if (mb0 && (M_HASCL(mb0) || mb0->m_len < hlen))
1446 mb0 = m_pullup(mb0, hlen);
1448 free(rte, M_MRTABLE);
1454 /* is there an upcall waiting for this flow ? */
1455 hash = MFCHASH(ip->ip_src.s_addr, ip->ip_dst.s_addr);
1456 for (rt = mfctable[hash]; rt; rt = rt->mfc_next) {
1457 if ((ip->ip_src.s_addr == rt->mfc_origin.s_addr) &&
1458 (ip->ip_dst.s_addr == rt->mfc_mcastgrp.s_addr) &&
1459 (rt->mfc_stall != NULL))
1466 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
1470 * Locate the vifi for the incoming interface for this packet.
1471 * If none found, drop packet.
1473 for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++)
1475 if (vifi >= numvifs) /* vif not found, drop packet */
1478 /* no upcall, so make a new entry */
1479 rt = (struct mfc *)malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
1482 /* Make a copy of the header to send to the user level process */
1483 mm = m_copy(mb0, 0, hlen);
1488 * Send message to routing daemon to install
1489 * a route into the kernel table
1492 im = mtod(mm, struct igmpmsg *);
1493 im->im_msgtype = IGMPMSG_NOCACHE;
1497 mrtstat.mrts_upcalls++;
1499 k_igmpsrc.sin_addr = ip->ip_src;
1500 if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
1501 log(LOG_WARNING, "ip_mforward: ip_mrouter socket queue full\n");
1502 ++mrtstat.mrts_upq_sockfull;
1504 free(rt, M_MRTABLE);
1506 free(rte, M_MRTABLE);
1513 /* insert new entry at head of hash chain */
1514 rt->mfc_origin.s_addr = ip->ip_src.s_addr;
1515 rt->mfc_mcastgrp.s_addr = ip->ip_dst.s_addr;
1516 rt->mfc_expire = UPCALL_EXPIRE;
1518 for (i = 0; i < numvifs; i++) {
1519 rt->mfc_ttls[i] = 0;
1520 rt->mfc_flags[i] = 0;
1522 rt->mfc_parent = -1;
1524 rt->mfc_rp.s_addr = INADDR_ANY; /* clear the RP address */
1526 rt->mfc_bw_meter = NULL;
1528 /* link into table */
1529 rt->mfc_next = mfctable[hash];
1530 mfctable[hash] = rt;
1531 rt->mfc_stall = rte;
1534 /* determine if q has overflowed */
1539 * XXX ouch! we need to append to the list, but we
1540 * only have a pointer to the front, so we have to
1541 * scan the entire list every time.
1543 for (p = &rt->mfc_stall; *p != NULL; p = &(*p)->next)
1546 if (npkts > MAX_UPQ) {
1547 mrtstat.mrts_upq_ovflw++;
1549 free(rte, M_MRTABLE);
1556 /* Add this entry to the end of the queue */
1572 * Clean up the cache entry if upcall is not serviced
1575 expire_upcalls(void *unused)
1578 struct mfc *mfc, **nptr;
1582 for (i = 0; i < MFCTBLSIZ; i++) {
1583 if (nexpire[i] == 0)
1585 nptr = &mfctable[i];
1586 for (mfc = *nptr; mfc != NULL; mfc = *nptr) {
1588 * Skip real cache entries
1589 * Make sure it wasn't marked to not expire (shouldn't happen)
1592 if (mfc->mfc_stall != NULL && mfc->mfc_expire != 0 &&
1593 --mfc->mfc_expire == 0) {
1594 if (mrtdebug & DEBUG_EXPIRE)
1595 log(LOG_DEBUG, "expire_upcalls: expiring (%lx %lx)\n",
1596 (u_long)ntohl(mfc->mfc_origin.s_addr),
1597 (u_long)ntohl(mfc->mfc_mcastgrp.s_addr));
1599 * drop all the packets
1600 * free the mbuf with the pkt, if, timing info
1602 for (rte = mfc->mfc_stall; rte; ) {
1603 struct rtdetq *n = rte->next;
1606 free(rte, M_MRTABLE);
1609 ++mrtstat.mrts_cache_cleanups;
1613 * free the bw_meter entries
1615 while (mfc->mfc_bw_meter != NULL) {
1616 struct bw_meter *x = mfc->mfc_bw_meter;
1618 mfc->mfc_bw_meter = x->bm_mfc_next;
1622 *nptr = mfc->mfc_next;
1623 free(mfc, M_MRTABLE);
1625 nptr = &mfc->mfc_next;
1631 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL);
1635 * Packet forwarding routine once entry in the cache is made
1638 ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
1640 struct ip *ip = mtod(m, struct ip *);
1642 int plen = ip->ip_len;
1646 * Macro to send packet on vif. Since RSVP packets don't get counted on
1647 * input, they shouldn't get counted on output, so statistics keeping is
1650 #define MC_SEND(ip,vifp,m) { \
1651 if ((vifp)->v_flags & VIFF_TUNNEL) \
1652 encap_send((ip), (vifp), (m)); \
1654 phyint_send((ip), (vifp), (m)); \
1658 * If xmt_vif is not -1, send on only the requested vif.
1660 * (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.)
1662 if (xmt_vif < numvifs) {
1664 if (viftable[xmt_vif].v_flags & VIFF_REGISTER)
1665 pim_register_send(ip, viftable + xmt_vif, m, rt);
1668 MC_SEND(ip, viftable + xmt_vif, m);
1673 * Don't forward if it didn't arrive from the parent vif for its origin.
1675 vifi = rt->mfc_parent;
1676 if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) {
1677 /* came in the wrong interface */
1678 if (mrtdebug & DEBUG_FORWARD)
1679 log(LOG_DEBUG, "wrong if: ifp %p vifi %d vififp %p\n",
1680 (void *)ifp, vifi, (void *)viftable[vifi].v_ifp);
1681 ++mrtstat.mrts_wrong_if;
1684 * If we are doing PIM assert processing, send a message
1685 * to the routing daemon.
1687 * XXX: A PIM-SM router needs the WRONGVIF detection so it
1688 * can complete the SPT switch, regardless of the type
1689 * of the iif (broadcast media, GRE tunnel, etc).
1691 if (pim_assert && (vifi < numvifs) && viftable[vifi].v_ifp) {
1696 if (ifp == &multicast_register_if)
1697 pimstat.pims_rcv_registers_wrongiif++;
1700 /* Get vifi for the incoming packet */
1701 for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++)
1703 if (vifi >= numvifs)
1704 return 0; /* The iif is not found: ignore the packet. */
1706 if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_DISABLE_WRONGVIF)
1707 return 0; /* WRONGVIF disabled: ignore the packet */
1711 TV_DELTA(rt->mfc_last_assert, now, delta);
1713 if (delta > ASSERT_MSG_TIME) {
1714 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
1716 int hlen = ip->ip_hl << 2;
1717 struct mbuf *mm = m_copy(m, 0, hlen);
1719 if (mm && (M_HASCL(mm) || mm->m_len < hlen))
1720 mm = m_pullup(mm, hlen);
1724 rt->mfc_last_assert = now;
1726 im = mtod(mm, struct igmpmsg *);
1727 im->im_msgtype = IGMPMSG_WRONGVIF;
1731 mrtstat.mrts_upcalls++;
1733 k_igmpsrc.sin_addr = im->im_src;
1734 if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
1736 "ip_mforward: ip_mrouter socket queue full\n");
1737 ++mrtstat.mrts_upq_sockfull;
1745 /* If I sourced this packet, it counts as output, else it was input. */
1746 if (ip->ip_src.s_addr == viftable[vifi].v_lcl_addr.s_addr) {
1747 viftable[vifi].v_pkt_out++;
1748 viftable[vifi].v_bytes_out += plen;
1750 viftable[vifi].v_pkt_in++;
1751 viftable[vifi].v_bytes_in += plen;
1754 rt->mfc_byte_cnt += plen;
1757 * For each vif, decide if a copy of the packet should be forwarded.
1759 * - the ttl exceeds the vif's threshold
1760 * - there are group members downstream on interface
1762 for (vifi = 0; vifi < numvifs; vifi++)
1763 if ((rt->mfc_ttls[vifi] > 0) && (ip->ip_ttl > rt->mfc_ttls[vifi])) {
1764 viftable[vifi].v_pkt_out++;
1765 viftable[vifi].v_bytes_out += plen;
1767 if (viftable[vifi].v_flags & VIFF_REGISTER)
1768 pim_register_send(ip, viftable + vifi, m, rt);
1771 MC_SEND(ip, viftable+vifi, m);
1775 * Perform upcall-related bw measuring.
1777 if (rt->mfc_bw_meter != NULL) {
1783 for (x = rt->mfc_bw_meter; x != NULL; x = x->bm_mfc_next)
1784 bw_meter_receive_packet(x, plen, &now);
1791 * check if a vif number is legal/ok. This is used by ip_output.
1794 X_legal_vif_num(int vif)
1796 /* XXX unlocked, matter? */
1797 return (vif >= 0 && vif < numvifs);
1801 * Return the local address used by this vif
1804 X_ip_mcast_src(int vifi)
1806 /* XXX unlocked, matter? */
1807 if (vifi >= 0 && vifi < numvifs)
1808 return viftable[vifi].v_lcl_addr.s_addr;
1814 phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
1816 struct mbuf *mb_copy;
1817 int hlen = ip->ip_hl << 2;
1822 * Make a new reference to the packet; make sure that
1823 * the IP header is actually copied, not just referenced,
1824 * so that ip_output() only scribbles on the copy.
1826 mb_copy = m_copypacket(m, M_DONTWAIT);
1827 if (mb_copy && (M_HASCL(mb_copy) || mb_copy->m_len < hlen))
1828 mb_copy = m_pullup(mb_copy, hlen);
1829 if (mb_copy == NULL)
1832 if (vifp->v_rate_limit == 0)
1833 tbf_send_packet(vifp, mb_copy);
1835 tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *), ip->ip_len);
1839 encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
1841 struct mbuf *mb_copy;
1843 int i, len = ip->ip_len;
1847 /* Take care of delayed checksums */
1848 if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) {
1849 in_delayed_cksum(m);
1850 m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
1854 * copy the old packet & pullup its IP header into the
1855 * new mbuf so we can modify it. Try to fill the new
1856 * mbuf since if we don't the ethernet driver will.
1858 MGETHDR(mb_copy, M_DONTWAIT, MT_HEADER);
1859 if (mb_copy == NULL)
1862 mac_create_mbuf_multicast_encap(m, vifp->v_ifp, mb_copy);
1864 mb_copy->m_data += max_linkhdr;
1865 mb_copy->m_len = sizeof(multicast_encap_iphdr);
1867 if ((mb_copy->m_next = m_copypacket(m, M_DONTWAIT)) == NULL) {
1871 i = MHLEN - M_LEADINGSPACE(mb_copy);
1874 mb_copy = m_pullup(mb_copy, i);
1875 if (mb_copy == NULL)
1877 mb_copy->m_pkthdr.len = len + sizeof(multicast_encap_iphdr);
1880 * fill in the encapsulating IP header.
1882 ip_copy = mtod(mb_copy, struct ip *);
1883 *ip_copy = multicast_encap_iphdr;
1885 ip_copy->ip_id = ip_randomid();
1887 ip_copy->ip_id = htons(ip_id++);
1889 ip_copy->ip_len += len;
1890 ip_copy->ip_src = vifp->v_lcl_addr;
1891 ip_copy->ip_dst = vifp->v_rmt_addr;
1894 * turn the encapsulated IP header back into a valid one.
1896 ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
1898 ip->ip_len = htons(ip->ip_len);
1899 ip->ip_off = htons(ip->ip_off);
1901 mb_copy->m_data += sizeof(multicast_encap_iphdr);
1902 ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
1903 mb_copy->m_data -= sizeof(multicast_encap_iphdr);
1905 if (vifp->v_rate_limit == 0)
1906 tbf_send_packet(vifp, mb_copy);
1908 tbf_control(vifp, mb_copy, ip, ip_copy->ip_len);
1912 * Token bucket filter module
1916 tbf_control(struct vif *vifp, struct mbuf *m, struct ip *ip, u_long p_len)
1918 struct tbf *t = vifp->v_tbf;
1922 if (p_len > MAX_BKT_SIZE) { /* drop if packet is too large */
1923 mrtstat.mrts_pkt2large++;
1928 tbf_update_tokens(vifp);
1930 if (t->tbf_q_len == 0) { /* queue empty... */
1931 if (p_len <= t->tbf_n_tok) { /* send packet if enough tokens */
1932 t->tbf_n_tok -= p_len;
1933 tbf_send_packet(vifp, m);
1934 } else { /* no, queue packet and try later */
1936 callout_reset(&tbf_reprocess_ch, TBF_REPROCESS,
1937 tbf_reprocess_q, vifp);
1939 } else if (t->tbf_q_len < t->tbf_max_q_len) {
1940 /* finite queue length, so queue pkts and process queue */
1942 tbf_process_q(vifp);
1944 /* queue full, try to dq and queue and process */
1945 if (!tbf_dq_sel(vifp, ip)) {
1946 mrtstat.mrts_q_overflow++;
1950 tbf_process_q(vifp);
1956 * adds a packet to the queue at the interface
1959 tbf_queue(struct vif *vifp, struct mbuf *m)
1961 struct tbf *t = vifp->v_tbf;
1965 if (t->tbf_t == NULL) /* Queue was empty */
1967 else /* Insert at tail */
1968 t->tbf_t->m_act = m;
1970 t->tbf_t = m; /* Set new tail pointer */
1973 /* Make sure we didn't get fed a bogus mbuf */
1975 panic("tbf_queue: m_act");
1983 * processes the queue at the interface
1986 tbf_process_q(struct vif *vifp)
1988 struct tbf *t = vifp->v_tbf;
1992 /* loop through the queue at the interface and send as many packets
1995 while (t->tbf_q_len > 0) {
1996 struct mbuf *m = t->tbf_q;
1997 int len = mtod(m, struct ip *)->ip_len;
1999 /* determine if the packet can be sent */
2000 if (len > t->tbf_n_tok) /* not enough tokens, we are done */
2002 /* ok, reduce no of tokens, dequeue and send the packet. */
2003 t->tbf_n_tok -= len;
2005 t->tbf_q = m->m_act;
2006 if (--t->tbf_q_len == 0)
2010 tbf_send_packet(vifp, m);
2015 tbf_reprocess_q(void *xvifp)
2017 struct vif *vifp = xvifp;
2019 if (ip_mrouter == NULL)
2022 tbf_update_tokens(vifp);
2023 tbf_process_q(vifp);
2024 if (vifp->v_tbf->tbf_q_len)
2025 callout_reset(&tbf_reprocess_ch, TBF_REPROCESS, tbf_reprocess_q, vifp);
2029 /* function that will selectively discard a member of the queue
2030 * based on the precedence value and the priority
2033 tbf_dq_sel(struct vif *vifp, struct ip *ip)
2036 struct mbuf *m, *last;
2038 struct tbf *t = vifp->v_tbf;
2042 p = priority(vifp, ip);
2046 while ((m = *np) != NULL) {
2047 if (p > priority(vifp, mtod(m, struct ip *))) {
2049 /* If we're removing the last packet, fix the tail pointer */
2053 /* It's impossible for the queue to be empty, but check anyways. */
2054 if (--t->tbf_q_len == 0)
2056 mrtstat.mrts_drop_sel++;
2066 tbf_send_packet(struct vif *vifp, struct mbuf *m)
2070 if (vifp->v_flags & VIFF_TUNNEL) /* If tunnel options */
2071 ip_output(m, NULL, &vifp->v_route, IP_FORWARDING, NULL, NULL);
2073 struct ip_moptions imo;
2075 static struct route ro; /* XXX check this */
2077 imo.imo_multicast_ifp = vifp->v_ifp;
2078 imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
2079 imo.imo_multicast_loop = 1;
2080 imo.imo_multicast_vif = -1;
2083 * Re-entrancy should not be a problem here, because
2084 * the packets that we send out and are looped back at us
2085 * should get rejected because they appear to come from
2086 * the loopback interface, thus preventing looping.
2088 error = ip_output(m, NULL, &ro, IP_FORWARDING, &imo, NULL);
2090 if (mrtdebug & DEBUG_XMIT)
2091 log(LOG_DEBUG, "phyint_send on vif %d err %d\n",
2092 (int)(vifp - viftable), error);
2096 /* determine the current time and then
2097 * the elapsed time (between the last time and time now)
2098 * in milliseconds & update the no. of tokens in the bucket
2101 tbf_update_tokens(struct vif *vifp)
2105 struct tbf *t = vifp->v_tbf;
2111 TV_DELTA(tp, t->tbf_last_pkt_t, tm);
2114 * This formula is actually
2115 * "time in seconds" * "bytes/second".
2117 * (tm / 1000000) * (v_rate_limit * 1000 * (1000/1024) / 8)
2119 * The (1000/1024) was introduced in add_vif to optimize
2120 * this divide into a shift.
2122 t->tbf_n_tok += tm * vifp->v_rate_limit / 1024 / 8;
2123 t->tbf_last_pkt_t = tp;
2125 if (t->tbf_n_tok > MAX_BKT_SIZE)
2126 t->tbf_n_tok = MAX_BKT_SIZE;
2130 priority(struct vif *vifp, struct ip *ip)
2132 int prio = 50; /* the lowest priority -- default case */
2134 /* temporary hack; may add general packet classifier some day */
2137 * The UDP port space is divided up into four priority ranges:
2138 * [0, 16384) : unclassified - lowest priority
2139 * [16384, 32768) : audio - highest priority
2140 * [32768, 49152) : whiteboard - medium priority
2141 * [49152, 65536) : video - low priority
2143 * Everything else gets lowest priority.
2145 if (ip->ip_p == IPPROTO_UDP) {
2146 struct udphdr *udp = (struct udphdr *)(((char *)ip) + (ip->ip_hl << 2));
2147 switch (ntohs(udp->uh_dport) & 0xc000) {
2163 * End of token bucket filter modifications
2167 X_ip_rsvp_vif(struct socket *so, struct sockopt *sopt)
2171 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
2174 error = sooptcopyin(sopt, &vifi, sizeof vifi, sizeof vifi);
2180 if (vifi < 0 || vifi >= numvifs) { /* Error if vif is invalid */
2182 return EADDRNOTAVAIL;
2185 if (sopt->sopt_name == IP_RSVP_VIF_ON) {
2186 /* Check if socket is available. */
2187 if (viftable[vifi].v_rsvpd != NULL) {
2192 viftable[vifi].v_rsvpd = so;
2193 /* This may seem silly, but we need to be sure we don't over-increment
2194 * the RSVP counter, in case something slips up.
2196 if (!viftable[vifi].v_rsvp_on) {
2197 viftable[vifi].v_rsvp_on = 1;
2200 } else { /* must be VIF_OFF */
2202 * XXX as an additional consistency check, one could make sure
2203 * that viftable[vifi].v_rsvpd == so, otherwise passing so as
2204 * first parameter is pretty useless.
2206 viftable[vifi].v_rsvpd = NULL;
2208 * This may seem silly, but we need to be sure we don't over-decrement
2209 * the RSVP counter, in case something slips up.
2211 if (viftable[vifi].v_rsvp_on) {
2212 viftable[vifi].v_rsvp_on = 0;
2221 X_ip_rsvp_force_done(struct socket *so)
2225 /* Don't bother if it is not the right type of socket. */
2226 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
2231 /* The socket may be attached to more than one vif...this
2232 * is perfectly legal.
2234 for (vifi = 0; vifi < numvifs; vifi++) {
2235 if (viftable[vifi].v_rsvpd == so) {
2236 viftable[vifi].v_rsvpd = NULL;
2237 /* This may seem silly, but we need to be sure we don't
2238 * over-decrement the RSVP counter, in case something slips up.
2240 if (viftable[vifi].v_rsvp_on) {
2241 viftable[vifi].v_rsvp_on = 0;
2251 X_rsvp_input(struct mbuf *m, int off)
2254 struct ip *ip = mtod(m, struct ip *);
2255 struct sockaddr_in rsvp_src = { sizeof rsvp_src, AF_INET };
2259 printf("rsvp_input: rsvp_on %d\n",rsvp_on);
2261 /* Can still get packets with rsvp_on = 0 if there is a local member
2262 * of the group to which the RSVP packet is addressed. But in this
2263 * case we want to throw the packet away.
2271 printf("rsvp_input: check vifs\n");
2277 ifp = m->m_pkthdr.rcvif;
2280 /* Find which vif the packet arrived on. */
2281 for (vifi = 0; vifi < numvifs; vifi++)
2282 if (viftable[vifi].v_ifp == ifp)
2285 if (vifi == numvifs || viftable[vifi].v_rsvpd == NULL) {
2287 * Drop the lock here to avoid holding it across rip_input.
2288 * This could make rsvpdebug printfs wrong. If you care,
2289 * record the state of stuff before dropping the lock.
2293 * If the old-style non-vif-associated socket is set,
2294 * then use it. Otherwise, drop packet since there
2295 * is no specific socket for this vif.
2297 if (ip_rsvpd != NULL) {
2299 printf("rsvp_input: Sending packet up old-style socket\n");
2300 rip_input(m, off); /* xxx */
2302 if (rsvpdebug && vifi == numvifs)
2303 printf("rsvp_input: Can't find vif for packet.\n");
2304 else if (rsvpdebug && viftable[vifi].v_rsvpd == NULL)
2305 printf("rsvp_input: No socket defined for vif %d\n",vifi);
2310 rsvp_src.sin_addr = ip->ip_src;
2313 printf("rsvp_input: m->m_len = %d, sbspace() = %ld\n",
2314 m->m_len,sbspace(&(viftable[vifi].v_rsvpd->so_rcv)));
2316 if (socket_send(viftable[vifi].v_rsvpd, m, &rsvp_src) < 0) {
2318 printf("rsvp_input: Failed to append to socket\n");
2321 printf("rsvp_input: send packet up\n");
2327 * Code for bandwidth monitors
2331 * Define common interface for timeval-related methods
2333 #define BW_TIMEVALCMP(tvp, uvp, cmp) timevalcmp((tvp), (uvp), cmp)
2334 #define BW_TIMEVALDECR(vvp, uvp) timevalsub((vvp), (uvp))
2335 #define BW_TIMEVALADD(vvp, uvp) timevaladd((vvp), (uvp))
2338 compute_bw_meter_flags(struct bw_upcall *req)
2342 if (req->bu_flags & BW_UPCALL_UNIT_PACKETS)
2343 flags |= BW_METER_UNIT_PACKETS;
2344 if (req->bu_flags & BW_UPCALL_UNIT_BYTES)
2345 flags |= BW_METER_UNIT_BYTES;
2346 if (req->bu_flags & BW_UPCALL_GEQ)
2347 flags |= BW_METER_GEQ;
2348 if (req->bu_flags & BW_UPCALL_LEQ)
2349 flags |= BW_METER_LEQ;
2355 * Add a bw_meter entry
2358 add_bw_upcall(struct bw_upcall *req)
2361 struct timeval delta = { BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC,
2362 BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC };
2367 if (!(mrt_api_config & MRT_MFC_BW_UPCALL))
2370 /* Test if the flags are valid */
2371 if (!(req->bu_flags & (BW_UPCALL_UNIT_PACKETS | BW_UPCALL_UNIT_BYTES)))
2373 if (!(req->bu_flags & (BW_UPCALL_GEQ | BW_UPCALL_LEQ)))
2375 if ((req->bu_flags & (BW_UPCALL_GEQ | BW_UPCALL_LEQ))
2376 == (BW_UPCALL_GEQ | BW_UPCALL_LEQ))
2379 /* Test if the threshold time interval is valid */
2380 if (BW_TIMEVALCMP(&req->bu_threshold.b_time, &delta, <))
2383 flags = compute_bw_meter_flags(req);
2386 * Find if we have already same bw_meter entry
2389 mfc = mfc_find(req->bu_src.s_addr, req->bu_dst.s_addr);
2392 return EADDRNOTAVAIL;
2394 for (x = mfc->mfc_bw_meter; x != NULL; x = x->bm_mfc_next) {
2395 if ((BW_TIMEVALCMP(&x->bm_threshold.b_time,
2396 &req->bu_threshold.b_time, ==)) &&
2397 (x->bm_threshold.b_packets == req->bu_threshold.b_packets) &&
2398 (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) &&
2399 (x->bm_flags & BW_METER_USER_FLAGS) == flags) {
2401 return 0; /* XXX Already installed */
2405 /* Allocate the new bw_meter entry */
2406 x = (struct bw_meter *)malloc(sizeof(*x), M_BWMETER, M_NOWAIT);
2412 /* Set the new bw_meter entry */
2413 x->bm_threshold.b_time = req->bu_threshold.b_time;
2415 x->bm_start_time = now;
2416 x->bm_threshold.b_packets = req->bu_threshold.b_packets;
2417 x->bm_threshold.b_bytes = req->bu_threshold.b_bytes;
2418 x->bm_measured.b_packets = 0;
2419 x->bm_measured.b_bytes = 0;
2420 x->bm_flags = flags;
2421 x->bm_time_next = NULL;
2422 x->bm_time_hash = BW_METER_BUCKETS;
2424 /* Add the new bw_meter entry to the front of entries for this MFC */
2426 x->bm_mfc_next = mfc->mfc_bw_meter;
2427 mfc->mfc_bw_meter = x;
2428 schedule_bw_meter(x, &now);
2435 free_bw_list(struct bw_meter *list)
2437 while (list != NULL) {
2438 struct bw_meter *x = list;
2440 list = list->bm_mfc_next;
2441 unschedule_bw_meter(x);
2447 * Delete one or multiple bw_meter entries
2450 del_bw_upcall(struct bw_upcall *req)
2455 if (!(mrt_api_config & MRT_MFC_BW_UPCALL))
2459 /* Find the corresponding MFC entry */
2460 mfc = mfc_find(req->bu_src.s_addr, req->bu_dst.s_addr);
2463 return EADDRNOTAVAIL;
2464 } else if (req->bu_flags & BW_UPCALL_DELETE_ALL) {
2466 * Delete all bw_meter entries for this mfc
2468 struct bw_meter *list;
2470 list = mfc->mfc_bw_meter;
2471 mfc->mfc_bw_meter = NULL;
2475 } else { /* Delete a single bw_meter entry */
2476 struct bw_meter *prev;
2479 flags = compute_bw_meter_flags(req);
2481 /* Find the bw_meter entry to delete */
2482 for (prev = NULL, x = mfc->mfc_bw_meter; x != NULL;
2483 x = x->bm_mfc_next) {
2484 if ((BW_TIMEVALCMP(&x->bm_threshold.b_time,
2485 &req->bu_threshold.b_time, ==)) &&
2486 (x->bm_threshold.b_packets == req->bu_threshold.b_packets) &&
2487 (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) &&
2488 (x->bm_flags & BW_METER_USER_FLAGS) == flags)
2491 if (x != NULL) { /* Delete entry from the list for this MFC */
2493 prev->bm_mfc_next = x->bm_mfc_next; /* remove from middle*/
2495 x->bm_mfc->mfc_bw_meter = x->bm_mfc_next;/* new head of list */
2497 unschedule_bw_meter(x);
2499 /* Free the bw_meter entry */
2511 * Perform bandwidth measurement processing that may result in an upcall
2514 bw_meter_receive_packet(struct bw_meter *x, int plen, struct timeval *nowp)
2516 struct timeval delta;
2521 BW_TIMEVALDECR(&delta, &x->bm_start_time);
2523 if (x->bm_flags & BW_METER_GEQ) {
2525 * Processing for ">=" type of bw_meter entry
2527 if (BW_TIMEVALCMP(&delta, &x->bm_threshold.b_time, >)) {
2528 /* Reset the bw_meter entry */
2529 x->bm_start_time = *nowp;
2530 x->bm_measured.b_packets = 0;
2531 x->bm_measured.b_bytes = 0;
2532 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
2535 /* Record that a packet is received */
2536 x->bm_measured.b_packets++;
2537 x->bm_measured.b_bytes += plen;
2540 * Test if we should deliver an upcall
2542 if (!(x->bm_flags & BW_METER_UPCALL_DELIVERED)) {
2543 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
2544 (x->bm_measured.b_packets >= x->bm_threshold.b_packets)) ||
2545 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
2546 (x->bm_measured.b_bytes >= x->bm_threshold.b_bytes))) {
2547 /* Prepare an upcall for delivery */
2548 bw_meter_prepare_upcall(x, nowp);
2549 x->bm_flags |= BW_METER_UPCALL_DELIVERED;
2552 } else if (x->bm_flags & BW_METER_LEQ) {
2554 * Processing for "<=" type of bw_meter entry
2556 if (BW_TIMEVALCMP(&delta, &x->bm_threshold.b_time, >)) {
2558 * We are behind time with the multicast forwarding table
2559 * scanning for "<=" type of bw_meter entries, so test now
2560 * if we should deliver an upcall.
2562 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
2563 (x->bm_measured.b_packets <= x->bm_threshold.b_packets)) ||
2564 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
2565 (x->bm_measured.b_bytes <= x->bm_threshold.b_bytes))) {
2566 /* Prepare an upcall for delivery */
2567 bw_meter_prepare_upcall(x, nowp);
2569 /* Reschedule the bw_meter entry */
2570 unschedule_bw_meter(x);
2571 schedule_bw_meter(x, nowp);
2574 /* Record that a packet is received */
2575 x->bm_measured.b_packets++;
2576 x->bm_measured.b_bytes += plen;
2579 * Test if we should restart the measuring interval
2581 if ((x->bm_flags & BW_METER_UNIT_PACKETS &&
2582 x->bm_measured.b_packets <= x->bm_threshold.b_packets) ||
2583 (x->bm_flags & BW_METER_UNIT_BYTES &&
2584 x->bm_measured.b_bytes <= x->bm_threshold.b_bytes)) {
2585 /* Don't restart the measuring interval */
2587 /* Do restart the measuring interval */
2589 * XXX: note that we don't unschedule and schedule, because this
2590 * might be too much overhead per packet. Instead, when we process
2591 * all entries for a given timer hash bin, we check whether it is
2592 * really a timeout. If not, we reschedule at that time.
2594 x->bm_start_time = *nowp;
2595 x->bm_measured.b_packets = 0;
2596 x->bm_measured.b_bytes = 0;
2597 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
2603 * Prepare a bandwidth-related upcall
2606 bw_meter_prepare_upcall(struct bw_meter *x, struct timeval *nowp)
2608 struct timeval delta;
2609 struct bw_upcall *u;
2614 * Compute the measured time interval
2617 BW_TIMEVALDECR(&delta, &x->bm_start_time);
2620 * If there are too many pending upcalls, deliver them now
2622 if (bw_upcalls_n >= BW_UPCALLS_MAX)
2626 * Set the bw_upcall entry
2628 u = &bw_upcalls[bw_upcalls_n++];
2629 u->bu_src = x->bm_mfc->mfc_origin;
2630 u->bu_dst = x->bm_mfc->mfc_mcastgrp;
2631 u->bu_threshold.b_time = x->bm_threshold.b_time;
2632 u->bu_threshold.b_packets = x->bm_threshold.b_packets;
2633 u->bu_threshold.b_bytes = x->bm_threshold.b_bytes;
2634 u->bu_measured.b_time = delta;
2635 u->bu_measured.b_packets = x->bm_measured.b_packets;
2636 u->bu_measured.b_bytes = x->bm_measured.b_bytes;
2638 if (x->bm_flags & BW_METER_UNIT_PACKETS)
2639 u->bu_flags |= BW_UPCALL_UNIT_PACKETS;
2640 if (x->bm_flags & BW_METER_UNIT_BYTES)
2641 u->bu_flags |= BW_UPCALL_UNIT_BYTES;
2642 if (x->bm_flags & BW_METER_GEQ)
2643 u->bu_flags |= BW_UPCALL_GEQ;
2644 if (x->bm_flags & BW_METER_LEQ)
2645 u->bu_flags |= BW_UPCALL_LEQ;
2649 * Send the pending bandwidth-related upcalls
2652 bw_upcalls_send(void)
2655 int len = bw_upcalls_n * sizeof(bw_upcalls[0]);
2656 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
2657 static struct igmpmsg igmpmsg = { 0, /* unused1 */
2659 IGMPMSG_BW_UPCALL,/* im_msgtype */
2664 { 0 } }; /* im_dst */
2668 if (bw_upcalls_n == 0)
2669 return; /* No pending upcalls */
2674 * Allocate a new mbuf, initialize it with the header and
2675 * the payload for the pending calls.
2677 MGETHDR(m, M_DONTWAIT, MT_HEADER);
2679 log(LOG_WARNING, "bw_upcalls_send: cannot allocate mbuf\n");
2683 m->m_len = m->m_pkthdr.len = 0;
2684 m_copyback(m, 0, sizeof(struct igmpmsg), (caddr_t)&igmpmsg);
2685 m_copyback(m, sizeof(struct igmpmsg), len, (caddr_t)&bw_upcalls[0]);
2689 * XXX do we need to set the address in k_igmpsrc ?
2691 mrtstat.mrts_upcalls++;
2692 if (socket_send(ip_mrouter, m, &k_igmpsrc) < 0) {
2693 log(LOG_WARNING, "bw_upcalls_send: ip_mrouter socket queue full\n");
2694 ++mrtstat.mrts_upq_sockfull;
2699 * Compute the timeout hash value for the bw_meter entries
2701 #define BW_METER_TIMEHASH(bw_meter, hash) \
2703 struct timeval next_timeval = (bw_meter)->bm_start_time; \
2705 BW_TIMEVALADD(&next_timeval, &(bw_meter)->bm_threshold.b_time); \
2706 (hash) = next_timeval.tv_sec; \
2707 if (next_timeval.tv_usec) \
2708 (hash)++; /* XXX: make sure we don't timeout early */ \
2709 (hash) %= BW_METER_BUCKETS; \
2713 * Schedule a timer to process periodically bw_meter entry of type "<="
2714 * by linking the entry in the proper hash bucket.
2717 schedule_bw_meter(struct bw_meter *x, struct timeval *nowp)
2723 if (!(x->bm_flags & BW_METER_LEQ))
2724 return; /* XXX: we schedule timers only for "<=" entries */
2727 * Reset the bw_meter entry
2729 x->bm_start_time = *nowp;
2730 x->bm_measured.b_packets = 0;
2731 x->bm_measured.b_bytes = 0;
2732 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
2735 * Compute the timeout hash value and insert the entry
2737 BW_METER_TIMEHASH(x, time_hash);
2738 x->bm_time_next = bw_meter_timers[time_hash];
2739 bw_meter_timers[time_hash] = x;
2740 x->bm_time_hash = time_hash;
2744 * Unschedule the periodic timer that processes bw_meter entry of type "<="
2745 * by removing the entry from the proper hash bucket.
2748 unschedule_bw_meter(struct bw_meter *x)
2751 struct bw_meter *prev, *tmp;
2755 if (!(x->bm_flags & BW_METER_LEQ))
2756 return; /* XXX: we schedule timers only for "<=" entries */
2759 * Compute the timeout hash value and delete the entry
2761 time_hash = x->bm_time_hash;
2762 if (time_hash >= BW_METER_BUCKETS)
2763 return; /* Entry was not scheduled */
2765 for (prev = NULL, tmp = bw_meter_timers[time_hash];
2766 tmp != NULL; prev = tmp, tmp = tmp->bm_time_next)
2771 panic("unschedule_bw_meter: bw_meter entry not found");
2774 prev->bm_time_next = x->bm_time_next;
2776 bw_meter_timers[time_hash] = x->bm_time_next;
2778 x->bm_time_next = NULL;
2779 x->bm_time_hash = BW_METER_BUCKETS;
2784 * Process all "<=" type of bw_meter that should be processed now,
2785 * and for each entry prepare an upcall if necessary. Each processed
2786 * entry is rescheduled again for the (periodic) processing.
2788 * This is run periodically (once per second normally). On each round,
2789 * all the potentially matching entries are in the hash slot that we are
2795 static uint32_t last_tv_sec; /* last time we processed this */
2799 struct timeval now, process_endtime;
2802 if (last_tv_sec == now.tv_sec)
2803 return; /* nothing to do */
2805 loops = now.tv_sec - last_tv_sec;
2806 last_tv_sec = now.tv_sec;
2807 if (loops > BW_METER_BUCKETS)
2808 loops = BW_METER_BUCKETS;
2812 * Process all bins of bw_meter entries from the one after the last
2813 * processed to the current one. On entry, i points to the last bucket
2814 * visited, so we need to increment i at the beginning of the loop.
2816 for (i = (now.tv_sec - loops) % BW_METER_BUCKETS; loops > 0; loops--) {
2817 struct bw_meter *x, *tmp_list;
2819 if (++i >= BW_METER_BUCKETS)
2822 /* Disconnect the list of bw_meter entries from the bin */
2823 tmp_list = bw_meter_timers[i];
2824 bw_meter_timers[i] = NULL;
2826 /* Process the list of bw_meter entries */
2827 while (tmp_list != NULL) {
2829 tmp_list = tmp_list->bm_time_next;
2831 /* Test if the time interval is over */
2832 process_endtime = x->bm_start_time;
2833 BW_TIMEVALADD(&process_endtime, &x->bm_threshold.b_time);
2834 if (BW_TIMEVALCMP(&process_endtime, &now, >)) {
2835 /* Not yet: reschedule, but don't reset */
2838 BW_METER_TIMEHASH(x, time_hash);
2839 if (time_hash == i && process_endtime.tv_sec == now.tv_sec) {
2841 * XXX: somehow the bin processing is a bit ahead of time.
2842 * Put the entry in the next bin.
2844 if (++time_hash >= BW_METER_BUCKETS)
2847 x->bm_time_next = bw_meter_timers[time_hash];
2848 bw_meter_timers[time_hash] = x;
2849 x->bm_time_hash = time_hash;
2855 * Test if we should deliver an upcall
2857 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
2858 (x->bm_measured.b_packets <= x->bm_threshold.b_packets)) ||
2859 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
2860 (x->bm_measured.b_bytes <= x->bm_threshold.b_bytes))) {
2861 /* Prepare an upcall for delivery */
2862 bw_meter_prepare_upcall(x, &now);
2866 * Reschedule for next processing
2868 schedule_bw_meter(x, &now);
2872 /* Send all upcalls that are pending delivery */
2879 * A periodic function for sending all upcalls that are pending delivery
2882 expire_bw_upcalls_send(void *unused)
2888 callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
2889 expire_bw_upcalls_send, NULL);
2893 * A periodic function for periodic scanning of the multicast forwarding
2894 * table for processing all "<=" bw_meter entries.
2897 expire_bw_meter_process(void *unused)
2899 if (mrt_api_config & MRT_MFC_BW_UPCALL)
2902 callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL);
2906 * End of bandwidth monitoring code
2911 * Send the packet up to the user daemon, or eventually do kernel encapsulation
2915 pim_register_send(struct ip *ip, struct vif *vifp,
2916 struct mbuf *m, struct mfc *rt)
2918 struct mbuf *mb_copy, *mm;
2920 if (mrtdebug & DEBUG_PIM)
2921 log(LOG_DEBUG, "pim_register_send: ");
2923 mb_copy = pim_register_prepare(ip, m);
2924 if (mb_copy == NULL)
2928 * Send all the fragments. Note that the mbuf for each fragment
2929 * is freed by the sending machinery.
2931 for (mm = mb_copy; mm; mm = mb_copy) {
2932 mb_copy = mm->m_nextpkt;
2934 mm = m_pullup(mm, sizeof(struct ip));
2936 ip = mtod(mm, struct ip *);
2937 if ((mrt_api_config & MRT_MFC_RP) &&
2938 (rt->mfc_rp.s_addr != INADDR_ANY)) {
2939 pim_register_send_rp(ip, vifp, mm, rt);
2941 pim_register_send_upcall(ip, vifp, mm, rt);
2950 * Return a copy of the data packet that is ready for PIM Register
2952 * XXX: Note that in the returned copy the IP header is a valid one.
2954 static struct mbuf *
2955 pim_register_prepare(struct ip *ip, struct mbuf *m)
2957 struct mbuf *mb_copy = NULL;
2960 /* Take care of delayed checksums */
2961 if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) {
2962 in_delayed_cksum(m);
2963 m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
2967 * Copy the old packet & pullup its IP header into the
2968 * new mbuf so we can modify it.
2970 mb_copy = m_copypacket(m, M_DONTWAIT);
2971 if (mb_copy == NULL)
2973 mb_copy = m_pullup(mb_copy, ip->ip_hl << 2);
2974 if (mb_copy == NULL)
2977 /* take care of the TTL */
2978 ip = mtod(mb_copy, struct ip *);
2981 /* Compute the MTU after the PIM Register encapsulation */
2982 mtu = 0xffff - sizeof(pim_encap_iphdr) - sizeof(pim_encap_pimhdr);
2984 if (ip->ip_len <= mtu) {
2985 /* Turn the IP header into a valid one */
2986 ip->ip_len = htons(ip->ip_len);
2987 ip->ip_off = htons(ip->ip_off);
2989 ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
2991 /* Fragment the packet */
2992 if (ip_fragment(ip, &mb_copy, mtu, 0, CSUM_DELAY_IP) != 0) {
3001 * Send an upcall with the data packet to the user-level process.
3004 pim_register_send_upcall(struct ip *ip, struct vif *vifp,
3005 struct mbuf *mb_copy, struct mfc *rt)
3007 struct mbuf *mb_first;
3008 int len = ntohs(ip->ip_len);
3010 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
3015 * Add a new mbuf with an upcall header
3017 MGETHDR(mb_first, M_DONTWAIT, MT_HEADER);
3018 if (mb_first == NULL) {
3022 mb_first->m_data += max_linkhdr;
3023 mb_first->m_pkthdr.len = len + sizeof(struct igmpmsg);
3024 mb_first->m_len = sizeof(struct igmpmsg);
3025 mb_first->m_next = mb_copy;
3027 /* Send message to routing daemon */
3028 im = mtod(mb_first, struct igmpmsg *);
3029 im->im_msgtype = IGMPMSG_WHOLEPKT;
3031 im->im_vif = vifp - viftable;
3032 im->im_src = ip->ip_src;
3033 im->im_dst = ip->ip_dst;
3035 k_igmpsrc.sin_addr = ip->ip_src;
3037 mrtstat.mrts_upcalls++;
3039 if (socket_send(ip_mrouter, mb_first, &k_igmpsrc) < 0) {
3040 if (mrtdebug & DEBUG_PIM)
3042 "mcast: pim_register_send_upcall: ip_mrouter socket queue full");
3043 ++mrtstat.mrts_upq_sockfull;
3047 /* Keep statistics */
3048 pimstat.pims_snd_registers_msgs++;
3049 pimstat.pims_snd_registers_bytes += len;
3055 * Encapsulate the data packet in PIM Register message and send it to the RP.
3058 pim_register_send_rp(struct ip *ip, struct vif *vifp,
3059 struct mbuf *mb_copy, struct mfc *rt)
3061 struct mbuf *mb_first;
3062 struct ip *ip_outer;
3063 struct pim_encap_pimhdr *pimhdr;
3064 int len = ntohs(ip->ip_len);
3065 vifi_t vifi = rt->mfc_parent;
3069 if ((vifi >= numvifs) || (viftable[vifi].v_lcl_addr.s_addr == 0)) {
3071 return EADDRNOTAVAIL; /* The iif vif is invalid */
3075 * Add a new mbuf with the encapsulating header
3077 MGETHDR(mb_first, M_DONTWAIT, MT_HEADER);
3078 if (mb_first == NULL) {
3082 mb_first->m_data += max_linkhdr;
3083 mb_first->m_len = sizeof(pim_encap_iphdr) + sizeof(pim_encap_pimhdr);
3084 mb_first->m_next = mb_copy;
3086 mb_first->m_pkthdr.len = len + mb_first->m_len;
3089 * Fill in the encapsulating IP and PIM header
3091 ip_outer = mtod(mb_first, struct ip *);
3092 *ip_outer = pim_encap_iphdr;
3094 ip_outer->ip_id = ip_randomid();
3096 ip_outer->ip_id = htons(ip_id++);
3098 ip_outer->ip_len = len + sizeof(pim_encap_iphdr) + sizeof(pim_encap_pimhdr);
3099 ip_outer->ip_src = viftable[vifi].v_lcl_addr;
3100 ip_outer->ip_dst = rt->mfc_rp;
3102 * Copy the inner header TOS to the outer header, and take care of the
3105 ip_outer->ip_tos = ip->ip_tos;
3106 if (ntohs(ip->ip_off) & IP_DF)
3107 ip_outer->ip_off |= IP_DF;
3108 pimhdr = (struct pim_encap_pimhdr *)((caddr_t)ip_outer
3109 + sizeof(pim_encap_iphdr));
3110 *pimhdr = pim_encap_pimhdr;
3111 /* If the iif crosses a border, set the Border-bit */
3112 if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_BORDER_VIF & mrt_api_config)
3113 pimhdr->flags |= htonl(PIM_BORDER_REGISTER);
3115 mb_first->m_data += sizeof(pim_encap_iphdr);
3116 pimhdr->pim.pim_cksum = in_cksum(mb_first, sizeof(pim_encap_pimhdr));
3117 mb_first->m_data -= sizeof(pim_encap_iphdr);
3119 if (vifp->v_rate_limit == 0)
3120 tbf_send_packet(vifp, mb_first);
3122 tbf_control(vifp, mb_first, ip, ip_outer->ip_len);
3124 /* Keep statistics */
3125 pimstat.pims_snd_registers_msgs++;
3126 pimstat.pims_snd_registers_bytes += len;
3132 * PIM-SMv2 and PIM-DM messages processing.
3133 * Receives and verifies the PIM control messages, and passes them
3134 * up to the listening socket, using rip_input().
3135 * The only message with special processing is the PIM_REGISTER message
3136 * (used by PIM-SM): the PIM header is stripped off, and the inner packet
3137 * is passed to if_simloop().
3140 pim_input(struct mbuf *m, int off)
3142 struct ip *ip = mtod(m, struct ip *);
3145 int datalen = ip->ip_len;
3149 /* Keep statistics */
3150 pimstat.pims_rcv_total_msgs++;
3151 pimstat.pims_rcv_total_bytes += datalen;
3156 if (datalen < PIM_MINLEN) {
3157 pimstat.pims_rcv_tooshort++;
3158 log(LOG_ERR, "pim_input: packet size too small %d from %lx\n",
3159 datalen, (u_long)ip->ip_src.s_addr);
3165 * If the packet is at least as big as a REGISTER, go agead
3166 * and grab the PIM REGISTER header size, to avoid another
3167 * possible m_pullup() later.
3169 * PIM_MINLEN == pimhdr + u_int32_t == 4 + 4 = 8
3170 * PIM_REG_MINLEN == pimhdr + reghdr + encap_iphdr == 4 + 4 + 20 = 28
3172 minlen = iphlen + (datalen >= PIM_REG_MINLEN ? PIM_REG_MINLEN : PIM_MINLEN);
3174 * Get the IP and PIM headers in contiguous memory, and
3175 * possibly the PIM REGISTER header.
3177 if ((m->m_flags & M_EXT || m->m_len < minlen) &&
3178 (m = m_pullup(m, minlen)) == 0) {
3179 log(LOG_ERR, "pim_input: m_pullup failure\n");
3182 /* m_pullup() may have given us a new mbuf so reset ip. */
3183 ip = mtod(m, struct ip *);
3184 ip_tos = ip->ip_tos;
3186 /* adjust mbuf to point to the PIM header */
3187 m->m_data += iphlen;
3189 pim = mtod(m, struct pim *);
3192 * Validate checksum. If PIM REGISTER, exclude the data packet.
3194 * XXX: some older PIMv2 implementations don't make this distinction,
3195 * so for compatibility reason perform the checksum over part of the
3196 * message, and if error, then over the whole message.
3198 if (PIM_VT_T(pim->pim_vt) == PIM_REGISTER && in_cksum(m, PIM_MINLEN) == 0) {
3199 /* do nothing, checksum okay */
3200 } else if (in_cksum(m, datalen)) {
3201 pimstat.pims_rcv_badsum++;
3202 if (mrtdebug & DEBUG_PIM)
3203 log(LOG_DEBUG, "pim_input: invalid checksum");
3208 /* PIM version check */
3209 if (PIM_VT_V(pim->pim_vt) < PIM_VERSION) {
3210 pimstat.pims_rcv_badversion++;
3211 log(LOG_ERR, "pim_input: incorrect version %d, expecting %d\n",
3212 PIM_VT_V(pim->pim_vt), PIM_VERSION);
3217 /* restore mbuf back to the outer IP */
3218 m->m_data -= iphlen;
3221 if (PIM_VT_T(pim->pim_vt) == PIM_REGISTER) {
3223 * Since this is a REGISTER, we'll make a copy of the register
3224 * headers ip + pim + u_int32 + encap_ip, to be passed up to the
3227 struct sockaddr_in dst = { sizeof(dst), AF_INET };
3229 struct ip *encap_ip;
3234 if ((reg_vif_num >= numvifs) || (reg_vif_num == VIFI_INVALID)) {
3236 if (mrtdebug & DEBUG_PIM)
3238 "pim_input: register vif not set: %d\n", reg_vif_num);
3242 /* XXX need refcnt? */
3243 vifp = viftable[reg_vif_num].v_ifp;
3249 if (datalen < PIM_REG_MINLEN) {
3250 pimstat.pims_rcv_tooshort++;
3251 pimstat.pims_rcv_badregisters++;
3253 "pim_input: register packet size too small %d from %lx\n",
3254 datalen, (u_long)ip->ip_src.s_addr);
3259 reghdr = (u_int32_t *)(pim + 1);
3260 encap_ip = (struct ip *)(reghdr + 1);
3262 if (mrtdebug & DEBUG_PIM) {
3264 "pim_input[register], encap_ip: %lx -> %lx, encap_ip len %d\n",
3265 (u_long)ntohl(encap_ip->ip_src.s_addr),
3266 (u_long)ntohl(encap_ip->ip_dst.s_addr),
3267 ntohs(encap_ip->ip_len));
3270 /* verify the version number of the inner packet */
3271 if (encap_ip->ip_v != IPVERSION) {
3272 pimstat.pims_rcv_badregisters++;
3273 if (mrtdebug & DEBUG_PIM) {
3274 log(LOG_DEBUG, "pim_input: invalid IP version (%d) "
3275 "of the inner packet\n", encap_ip->ip_v);
3281 /* verify the inner packet is destined to a mcast group */
3282 if (!IN_MULTICAST(ntohl(encap_ip->ip_dst.s_addr))) {
3283 pimstat.pims_rcv_badregisters++;
3284 if (mrtdebug & DEBUG_PIM)
3286 "pim_input: inner packet of register is not "
3288 (u_long)ntohl(encap_ip->ip_dst.s_addr));
3293 /* If a NULL_REGISTER, pass it to the daemon */
3294 if ((ntohl(*reghdr) & PIM_NULL_REGISTER))
3295 goto pim_input_to_daemon;
3298 * Copy the TOS from the outer IP header to the inner IP header.
3300 if (encap_ip->ip_tos != ip_tos) {
3301 /* Outer TOS -> inner TOS */
3302 encap_ip->ip_tos = ip_tos;
3303 /* Recompute the inner header checksum. Sigh... */
3305 /* adjust mbuf to point to the inner IP header */
3306 m->m_data += (iphlen + PIM_MINLEN);
3307 m->m_len -= (iphlen + PIM_MINLEN);
3309 encap_ip->ip_sum = 0;
3310 encap_ip->ip_sum = in_cksum(m, encap_ip->ip_hl << 2);
3312 /* restore mbuf to point back to the outer IP header */
3313 m->m_data -= (iphlen + PIM_MINLEN);
3314 m->m_len += (iphlen + PIM_MINLEN);
3318 * Decapsulate the inner IP packet and loopback to forward it
3319 * as a normal multicast packet. Also, make a copy of the
3320 * outer_iphdr + pimhdr + reghdr + encap_iphdr
3321 * to pass to the daemon later, so it can take the appropriate
3322 * actions (e.g., send back PIM_REGISTER_STOP).
3323 * XXX: here m->m_data points to the outer IP header.
3325 mcp = m_copy(m, 0, iphlen + PIM_REG_MINLEN);
3328 "pim_input: pim register: could not copy register head\n");
3333 /* Keep statistics */
3334 /* XXX: registers_bytes include only the encap. mcast pkt */
3335 pimstat.pims_rcv_registers_msgs++;
3336 pimstat.pims_rcv_registers_bytes += ntohs(encap_ip->ip_len);
3339 * forward the inner ip packet; point m_data at the inner ip.
3341 m_adj(m, iphlen + PIM_MINLEN);
3343 if (mrtdebug & DEBUG_PIM) {
3345 "pim_input: forwarding decapsulated register: "
3346 "src %lx, dst %lx, vif %d\n",
3347 (u_long)ntohl(encap_ip->ip_src.s_addr),
3348 (u_long)ntohl(encap_ip->ip_dst.s_addr),
3351 /* NB: vifp was collected above; can it change on us? */
3352 if_simloop(vifp, m, dst.sin_family, 0);
3354 /* prepare the register head to send to the mrouting daemon */
3358 pim_input_to_daemon:
3360 * Pass the PIM message up to the daemon; if it is a Register message,
3361 * pass the 'head' only up to the daemon. This includes the
3362 * outer IP header, PIM header, PIM-Register header and the
3364 * XXX: the outer IP header pkt size of a Register is not adjust to
3365 * reflect the fact that the inner multicast data is truncated.
3367 rip_input(m, iphlen);
3374 ip_mroute_modevent(module_t mod, int type, void *unused)
3378 mtx_init(&mrouter_mtx, "mrouter initialization", NULL, MTX_DEF);
3382 ip_mcast_src = X_ip_mcast_src;
3383 ip_mforward = X_ip_mforward;
3384 ip_mrouter_done = X_ip_mrouter_done;
3385 ip_mrouter_get = X_ip_mrouter_get;
3386 ip_mrouter_set = X_ip_mrouter_set;
3387 ip_rsvp_force_done = X_ip_rsvp_force_done;
3388 ip_rsvp_vif = X_ip_rsvp_vif;
3389 legal_vif_num = X_legal_vif_num;
3390 mrt_ioctl = X_mrt_ioctl;
3391 rsvp_input_p = X_rsvp_input;
3396 * Typically module unload happens after the user-level
3397 * process has shutdown the kernel services (the check
3398 * below insures someone can't just yank the module out
3399 * from under a running process). But if the module is
3400 * just loaded and then unloaded w/o starting up a user
3401 * process we still need to cleanup.
3406 X_ip_mrouter_done();
3407 ip_mcast_src = NULL;
3409 ip_mrouter_done = NULL;
3410 ip_mrouter_get = NULL;
3411 ip_mrouter_set = NULL;
3412 ip_rsvp_force_done = NULL;
3414 legal_vif_num = NULL;
3416 rsvp_input_p = NULL;
3419 mtx_destroy(&mrouter_mtx);
3425 static moduledata_t ip_mroutemod = {
3430 DECLARE_MODULE(ip_mroute, ip_mroutemod, SI_SUB_PSEUDO, SI_ORDER_ANY);