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
20 * $FreeBSD: src/sys/netinet/ip_mroute.c,v 1.56.2.10 2003/08/24 21:37:34 hsu Exp $
21 * $DragonFly: src/sys/net/ip_mroute/ip_mroute.c,v 1.23 2008/06/17 20:50:11 aggelos Exp $
24 #include "opt_mrouting.h"
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/malloc.h>
34 #include <sys/protosw.h>
35 #include <sys/socket.h>
36 #include <sys/socketvar.h>
37 #include <sys/sockio.h>
38 #include <sys/sysctl.h>
39 #include <sys/syslog.h>
40 #include <sys/systm.h>
41 #include <sys/thread2.h>
43 #include <sys/in_cksum.h>
45 #include <machine/stdarg.h>
48 #include <net/netisr.h>
49 #include <net/route.h>
50 #include <netinet/in.h>
51 #include <netinet/igmp.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_var.h>
54 #include <netinet/ip.h>
55 #include "ip_mroute.h"
56 #include <netinet/ip_var.h>
58 #include <netinet/pim.h>
59 #include <netinet/pim_var.h>
62 #include <netinet/in_pcb.h>
64 #include <netinet/udp.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 */
74 #define DEBUG_MFC 0x02
75 #define DEBUG_FORWARD 0x04
76 #define DEBUG_EXPIRE 0x08
77 #define DEBUG_XMIT 0x10
78 #define DEBUG_PIM 0x20
80 #define VIFI_INVALID ((vifi_t) -1)
82 #define M_HASCL(m) ((m)->m_flags & M_EXT)
84 static MALLOC_DEFINE(M_MRTABLE, "mroutetbl", "multicast routing tables");
86 static struct mrtstat mrtstat;
87 SYSCTL_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW,
89 "Multicast Routing Statistics (struct mrtstat, netinet/ip_mroute.h)");
91 static struct mfc *mfctable[MFCTBLSIZ];
92 SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, mfctable, CTLFLAG_RD,
93 &mfctable, sizeof(mfctable), "S,*mfc[MFCTBLSIZ]",
94 "Multicast Forwarding Table (struct *mfc[MFCTBLSIZ], netinet/ip_mroute.h)");
96 static struct vif viftable[MAXVIFS];
97 SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD,
98 &viftable, sizeof(viftable), "S,vif[MAXVIFS]",
99 "Multicast Virtual Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)");
101 static u_char nexpire[MFCTBLSIZ];
103 struct lwkt_token mroute_token = LWKT_TOKEN_MP_INITIALIZER(mroute_token);
106 static struct callout expire_upcalls_ch;
107 static struct callout tbf_reprocess_q_ch;
108 #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
109 #define UPCALL_EXPIRE 6 /* number of timeouts */
112 * Define the token bucket filter structures
113 * tbftable -> each vif has one of these for storing info
116 static struct tbf tbftable[MAXVIFS];
117 #define TBF_REPROCESS (hz / 100) /* 100x / second */
120 * 'Interfaces' associated with decapsulator (so we can tell
121 * packets that went through it from ones that get reflected
122 * by a broken gateway). These interfaces are never linked into
123 * the system ifnet list & no routes point to them. I.e., packets
124 * can't be sent this way. They only exist as a placeholder for
125 * multicast source verification.
127 static struct ifnet multicast_decap_if[MAXVIFS];
130 #define ENCAP_PROTO IPPROTO_IPIP /* 4 */
132 /* prototype IP hdr for encapsulated packets */
133 static struct ip multicast_encap_iphdr = {
134 #if BYTE_ORDER == LITTLE_ENDIAN
135 sizeof(struct ip) >> 2, IPVERSION,
137 IPVERSION, sizeof(struct ip) >> 2,
140 sizeof(struct ip), /* total length */
143 ENCAP_TTL, ENCAP_PROTO,
148 * Bandwidth meter variables and constants
150 static MALLOC_DEFINE(M_BWMETER, "bwmeter", "multicast upcall bw meters");
152 * Pending timeouts are stored in a hash table, the key being the
153 * expiration time. Periodically, the entries are analysed and processed.
155 #define BW_METER_BUCKETS 1024
156 static struct bw_meter *bw_meter_timers[BW_METER_BUCKETS];
157 static struct callout bw_meter_ch;
158 #define BW_METER_PERIOD (hz) /* periodical handling of bw meters */
161 * Pending upcalls are stored in a vector which is flushed when
162 * full, or periodically
164 static struct bw_upcall bw_upcalls[BW_UPCALLS_MAX];
165 static u_int bw_upcalls_n; /* # of pending upcalls */
166 static struct callout bw_upcalls_ch;
167 #define BW_UPCALLS_PERIOD (hz) /* periodical flush of bw upcalls */
170 static struct pimstat pimstat;
171 SYSCTL_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD,
173 "PIM Statistics (struct pimstat, netinet/pim_var.h)");
176 * Note: the PIM Register encapsulation adds the following in front of a
179 * struct pim_encap_hdr {
181 * struct pim_encap_pimhdr pim;
186 struct pim_encap_pimhdr {
191 static struct ip pim_encap_iphdr = {
192 #if BYTE_ORDER == LITTLE_ENDIAN
193 sizeof(struct ip) >> 2,
197 sizeof(struct ip) >> 2,
200 sizeof(struct ip), /* total length */
208 static struct pim_encap_pimhdr pim_encap_pimhdr = {
210 PIM_MAKE_VT(PIM_VERSION, PIM_REGISTER), /* PIM vers and message type */
217 static struct ifnet multicast_register_if;
218 static vifi_t reg_vif_num = VIFI_INVALID;
224 static vifi_t numvifs;
225 static int have_encap_tunnel;
228 * one-back cache used by ipip_input to locate a tunnel's vif
229 * given a datagram's src ip address.
231 static u_long last_encap_src;
232 static struct vif *last_encap_vif;
234 static u_long X_ip_mcast_src(int vifi);
235 static int X_ip_mforward(struct ip *ip, struct ifnet *ifp,
236 struct mbuf *m, struct ip_moptions *imo);
237 static int X_ip_mrouter_done(void);
238 static int X_ip_mrouter_get(struct socket *so, struct sockopt *m);
239 static int X_ip_mrouter_set(struct socket *so, struct sockopt *m);
240 static int X_legal_vif_num(int vif);
241 static int X_mrt_ioctl(int cmd, caddr_t data);
243 static int get_sg_cnt(struct sioc_sg_req *);
244 static int get_vif_cnt(struct sioc_vif_req *);
245 static int ip_mrouter_init(struct socket *, int);
246 static int add_vif(struct vifctl *);
247 static int del_vif(vifi_t);
248 static int add_mfc(struct mfcctl2 *);
249 static int del_mfc(struct mfcctl2 *);
250 static int set_api_config(uint32_t *); /* chose API capabilities */
251 static int socket_send(struct socket *, struct mbuf *, struct sockaddr_in *);
252 static int set_assert(int);
253 static void expire_upcalls(void *);
254 static int ip_mdq(struct mbuf *, struct ifnet *, struct mfc *, vifi_t);
255 static void phyint_send(struct ip *, struct vif *, struct mbuf *);
256 static void encap_send(struct ip *, struct vif *, struct mbuf *);
257 static void tbf_control(struct vif *, struct mbuf *, struct ip *, u_long);
258 static void tbf_queue(struct vif *, struct mbuf *);
259 static void tbf_process_q(struct vif *);
260 static void tbf_reprocess_q(void *);
261 static int tbf_dq_sel(struct vif *, struct ip *);
262 static void tbf_send_packet(struct vif *, struct mbuf *);
263 static void tbf_update_tokens(struct vif *);
264 static int priority(struct vif *, struct ip *);
267 * Bandwidth monitoring
269 static void free_bw_list(struct bw_meter *list);
270 static int add_bw_upcall(struct bw_upcall *);
271 static int del_bw_upcall(struct bw_upcall *);
272 static void bw_meter_receive_packet(struct bw_meter *x, int plen,
273 struct timeval *nowp);
274 static void bw_meter_prepare_upcall(struct bw_meter *x, struct timeval *nowp);
275 static void bw_upcalls_send(void);
276 static void schedule_bw_meter(struct bw_meter *x, struct timeval *nowp);
277 static void unschedule_bw_meter(struct bw_meter *x);
278 static void bw_meter_process(void);
279 static void expire_bw_upcalls_send(void *);
280 static void expire_bw_meter_process(void *);
283 static int pim_register_send(struct ip *, struct vif *,
284 struct mbuf *, struct mfc *);
285 static int pim_register_send_rp(struct ip *, struct vif *,
286 struct mbuf *, struct mfc *);
287 static int pim_register_send_upcall(struct ip *, struct vif *,
288 struct mbuf *, struct mfc *);
289 static struct mbuf *pim_register_prepare(struct ip *, struct mbuf *);
293 * whether or not special PIM assert processing is enabled.
295 static int pim_assert;
297 * Rate limit for assert notification messages, in usec
299 #define ASSERT_MSG_TIME 3000000
302 * Kernel multicast routing API capabilities and setup.
303 * If more API capabilities are added to the kernel, they should be
304 * recorded in `mrt_api_support'.
306 static const uint32_t mrt_api_support = (MRT_MFC_FLAGS_DISABLE_WRONGVIF |
307 MRT_MFC_FLAGS_BORDER_VIF |
310 static uint32_t mrt_api_config = 0;
313 * Hash function for a source, group entry
315 #define MFCHASH(a, g) MFCHASHMOD(((a) >> 20) ^ ((a) >> 10) ^ (a) ^ \
316 ((g) >> 20) ^ ((g) >> 10) ^ (g))
319 * Find a route for a given origin IP address and Multicast group address
320 * Type of service parameter to be added in the future!!!
321 * Statistics are updated by the caller if needed
322 * (mrtstat.mrts_mfc_lookups and mrtstat.mrts_mfc_misses)
325 mfc_find(in_addr_t o, in_addr_t g)
329 for (rt = mfctable[MFCHASH(o,g)]; rt; rt = rt->mfc_next)
330 if ((rt->mfc_origin.s_addr == o) &&
331 (rt->mfc_mcastgrp.s_addr == g) && (rt->mfc_stall == NULL))
337 * Macros to compute elapsed time efficiently
338 * Borrowed from Van Jacobson's scheduling code
340 #define TV_DELTA(a, b, delta) { \
342 delta = (a).tv_usec - (b).tv_usec; \
343 if ((xxs = (a).tv_sec - (b).tv_sec)) { \
352 delta += (1000000 * xxs); \
357 #define TV_LT(a, b) (((a).tv_usec < (b).tv_usec && \
358 (a).tv_sec <= (b).tv_sec) || (a).tv_sec < (b).tv_sec)
361 * Handle MRT setsockopt commands to modify the multicast routing tables.
364 X_ip_mrouter_set(struct socket *so, struct sockopt *sopt)
370 struct bw_upcall bw_upcall;
373 if (so != ip_mrouter && sopt->sopt_name != MRT_INIT)
377 switch (sopt->sopt_name) {
379 error = soopt_to_kbuf(sopt, &optval, sizeof optval, sizeof optval);
382 error = ip_mrouter_init(so, optval);
386 error = ip_mrouter_done();
390 error = soopt_to_kbuf(sopt, &vifc, sizeof vifc, sizeof vifc);
393 error = add_vif(&vifc);
397 error = soopt_to_kbuf(sopt, &vifi, sizeof vifi, sizeof vifi);
400 error = del_vif(vifi);
406 * select data size depending on API version.
408 if (sopt->sopt_name == MRT_ADD_MFC &&
409 mrt_api_config & MRT_API_FLAGS_ALL) {
410 error = soopt_to_kbuf(sopt, &mfc, sizeof(struct mfcctl2),
411 sizeof(struct mfcctl2));
413 error = soopt_to_kbuf(sopt, &mfc, sizeof(struct mfcctl),
414 sizeof(struct mfcctl));
415 bzero((caddr_t)&mfc + sizeof(struct mfcctl),
416 sizeof(mfc) - sizeof(struct mfcctl));
420 if (sopt->sopt_name == MRT_ADD_MFC)
421 error = add_mfc(&mfc);
423 error = del_mfc(&mfc);
427 error = soopt_to_kbuf(sopt, &optval, sizeof optval, sizeof optval);
434 error = soopt_to_kbuf(sopt, &i, sizeof i, sizeof i);
436 error = set_api_config(&i);
438 soopt_from_kbuf(sopt, &i, sizeof i);
441 case MRT_ADD_BW_UPCALL:
442 case MRT_DEL_BW_UPCALL:
443 error = soopt_to_kbuf(sopt, &bw_upcall, sizeof bw_upcall, sizeof bw_upcall);
446 if (sopt->sopt_name == MRT_ADD_BW_UPCALL)
447 error = add_bw_upcall(&bw_upcall);
449 error = del_bw_upcall(&bw_upcall);
460 * Handle MRT getsockopt commands
463 X_ip_mrouter_get(struct socket *so, struct sockopt *sopt)
466 static int version = 0x0305; /* !!! why is this here? XXX */
469 switch (sopt->sopt_name) {
471 soopt_from_kbuf(sopt, &version, sizeof version);
475 soopt_from_kbuf(sopt, &pim_assert, sizeof pim_assert);
478 case MRT_API_SUPPORT:
479 soopt_from_kbuf(sopt, &mrt_api_support, sizeof mrt_api_support);
483 soopt_from_kbuf(sopt, &mrt_api_config, sizeof mrt_api_config);
494 * Handle ioctl commands to obtain information from the cache
497 X_mrt_ioctl(int cmd, caddr_t data)
503 error = get_vif_cnt((struct sioc_vif_req *)data);
507 error = get_sg_cnt((struct sioc_sg_req *)data);
518 * returns the packet, byte, rpf-failure count for the source group provided
521 get_sg_cnt(struct sioc_sg_req *req)
525 lwkt_gettoken(&mroute_token);
526 rt = mfc_find(req->src.s_addr, req->grp.s_addr);
528 req->pktcnt = req->bytecnt = req->wrong_if = 0xffffffff;
529 lwkt_reltoken(&mroute_token);
530 return EADDRNOTAVAIL;
532 req->pktcnt = rt->mfc_pkt_cnt;
533 req->bytecnt = rt->mfc_byte_cnt;
534 req->wrong_if = rt->mfc_wrong_if;
535 lwkt_reltoken(&mroute_token);
540 * returns the input and output packet and byte counts on the vif provided
543 get_vif_cnt(struct sioc_vif_req *req)
545 vifi_t vifi = req->vifi;
550 req->icount = viftable[vifi].v_pkt_in;
551 req->ocount = viftable[vifi].v_pkt_out;
552 req->ibytes = viftable[vifi].v_bytes_in;
553 req->obytes = viftable[vifi].v_bytes_out;
559 * Enable multicast routing
562 ip_mrouter_init(struct socket *so, int version)
565 log(LOG_DEBUG, "ip_mrouter_init: so_type = %d, pr_protocol = %d\n",
566 so->so_type, so->so_proto->pr_protocol);
568 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_IGMP)
574 if (ip_mrouter != NULL)
579 bzero((caddr_t)mfctable, sizeof(mfctable));
580 bzero((caddr_t)nexpire, sizeof(nexpire));
584 bzero((caddr_t)bw_meter_timers, sizeof(bw_meter_timers));
586 callout_init(&expire_upcalls_ch);
587 callout_init(&bw_upcalls_ch);
588 callout_init(&bw_meter_ch);
589 callout_init(&tbf_reprocess_q_ch);
591 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL);
592 callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
593 expire_bw_upcalls_send, NULL);
594 callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL);
599 log(LOG_DEBUG, "ip_mrouter_init\n");
605 * Disable multicast routing
608 X_ip_mrouter_done(void)
617 lwkt_gettoken(&mroute_token);
620 * For each phyint in use, disable promiscuous reception of all IP
623 for (vifi = 0; vifi < numvifs; vifi++) {
624 if (viftable[vifi].v_lcl_addr.s_addr != 0 &&
625 !(viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) {
626 struct sockaddr_in *so = (struct sockaddr_in *)&(ifr.ifr_addr);
628 so->sin_len = sizeof(struct sockaddr_in);
629 so->sin_family = AF_INET;
630 so->sin_addr.s_addr = INADDR_ANY;
631 ifp = viftable[vifi].v_ifp;
635 bzero((caddr_t)tbftable, sizeof(tbftable));
636 bzero((caddr_t)viftable, sizeof(viftable));
640 callout_stop(&expire_upcalls_ch);
644 callout_stop(&bw_upcalls_ch);
645 callout_stop(&bw_meter_ch);
646 callout_stop(&tbf_reprocess_q_ch);
649 * Free all multicast forwarding cache entries.
651 for (i = 0; i < MFCTBLSIZ; i++) {
652 for (rt = mfctable[i]; rt != NULL; ) {
653 struct mfc *nr = rt->mfc_next;
655 for (rte = rt->mfc_stall; rte != NULL; ) {
656 struct rtdetq *n = rte->next;
659 kfree(rte, M_MRTABLE);
662 free_bw_list(rt->mfc_bw_meter);
663 kfree(rt, M_MRTABLE);
668 bzero((caddr_t)mfctable, sizeof(mfctable));
670 bzero(bw_meter_timers, sizeof(bw_meter_timers));
673 * Reset de-encapsulation cache
675 last_encap_src = INADDR_ANY;
676 last_encap_vif = NULL;
678 reg_vif_num = VIFI_INVALID;
680 have_encap_tunnel = 0;
684 lwkt_reltoken(&mroute_token);
687 log(LOG_DEBUG, "ip_mrouter_done\n");
693 * Set PIM assert processing global
698 if ((i != 1) && (i != 0))
707 * Configure API capabilities
710 set_api_config(uint32_t *apival)
715 * We can set the API capabilities only if it is the first operation
716 * after MRT_INIT. I.e.:
717 * - there are no vifs installed
718 * - pim_assert is not enabled
719 * - the MFC table is empty
729 for (i = 0; i < MFCTBLSIZ; i++) {
730 if (mfctable[i] != NULL) {
736 mrt_api_config = *apival & mrt_api_support;
737 *apival = mrt_api_config;
743 * Add a vif to the vif table
746 add_vif(struct vifctl *vifcp)
748 struct vif *vifp = viftable + vifcp->vifc_vifi;
749 struct sockaddr_in sin = {sizeof sin, AF_INET};
753 struct tbf *v_tbf = tbftable + vifcp->vifc_vifi;
755 if (vifcp->vifc_vifi >= MAXVIFS)
757 if (vifp->v_lcl_addr.s_addr != INADDR_ANY)
759 if (vifcp->vifc_lcl_addr.s_addr == INADDR_ANY)
760 return EADDRNOTAVAIL;
762 /* Find the interface with an address in AF_INET family */
764 if (vifcp->vifc_flags & VIFF_REGISTER) {
766 * XXX: Because VIFF_REGISTER does not really need a valid
767 * local interface (e.g. it could be 127.0.0.2), we don't
774 sin.sin_addr = vifcp->vifc_lcl_addr;
775 ifa = ifa_ifwithaddr((struct sockaddr *)&sin);
777 return EADDRNOTAVAIL;
781 if (vifcp->vifc_flags & VIFF_TUNNEL) {
782 if ((vifcp->vifc_flags & VIFF_SRCRT) == 0) {
784 * An encapsulating tunnel is wanted. Tell ipip_input() to
785 * start paying attention to encapsulated packets.
787 if (have_encap_tunnel == 0) {
788 have_encap_tunnel = 1;
789 for (i = 0; i < MAXVIFS; i++) {
790 if_initname(&multicast_decap_if[i], "mdecap", i);
794 * Set interface to fake encapsulator interface
796 ifp = &multicast_decap_if[vifcp->vifc_vifi];
798 * Prepare cached route entry
800 bzero(&vifp->v_route, sizeof(vifp->v_route));
802 log(LOG_ERR, "source routed tunnels not supported\n");
806 } else if (vifcp->vifc_flags & VIFF_REGISTER) {
807 ifp = &multicast_register_if;
809 log(LOG_DEBUG, "Adding a register vif, ifp: %p\n",
810 (void *)&multicast_register_if);
811 if (reg_vif_num == VIFI_INVALID) {
812 if_initname(&multicast_register_if, "register_vif", 0);
813 multicast_register_if.if_flags = IFF_LOOPBACK;
814 bzero(&vifp->v_route, sizeof(vifp->v_route));
815 reg_vif_num = vifcp->vifc_vifi;
818 } else { /* Make sure the interface supports multicast */
819 if ((ifp->if_flags & IFF_MULTICAST) == 0)
822 /* Enable promiscuous reception of all IP multicasts from the if */
823 lwkt_gettoken(&mroute_token);
824 error = if_allmulti(ifp, 1);
825 lwkt_reltoken(&mroute_token);
830 lwkt_gettoken(&mroute_token);
831 /* define parameters for the tbf structure */
833 GET_TIME(vifp->v_tbf->tbf_last_pkt_t);
834 vifp->v_tbf->tbf_n_tok = 0;
835 vifp->v_tbf->tbf_q_len = 0;
836 vifp->v_tbf->tbf_max_q_len = MAXQSIZE;
837 vifp->v_tbf->tbf_q = vifp->v_tbf->tbf_t = NULL;
839 vifp->v_flags = vifcp->vifc_flags;
840 vifp->v_threshold = vifcp->vifc_threshold;
841 vifp->v_lcl_addr = vifcp->vifc_lcl_addr;
842 vifp->v_rmt_addr = vifcp->vifc_rmt_addr;
844 /* scaling up here allows division by 1024 in critical code */
845 vifp->v_rate_limit= vifcp->vifc_rate_limit * 1024 / 1000;
847 vifp->v_rsvpd = NULL;
848 /* initialize per vif pkt counters */
851 vifp->v_bytes_in = 0;
852 vifp->v_bytes_out = 0;
854 /* Adjust numvifs up if the vifi is higher than numvifs */
855 if (numvifs <= vifcp->vifc_vifi) numvifs = vifcp->vifc_vifi + 1;
857 lwkt_reltoken(&mroute_token);
860 log(LOG_DEBUG, "add_vif #%d, lcladdr %lx, %s %lx, thresh %x, rate %d\n",
862 (u_long)ntohl(vifcp->vifc_lcl_addr.s_addr),
863 (vifcp->vifc_flags & VIFF_TUNNEL) ? "rmtaddr" : "mask",
864 (u_long)ntohl(vifcp->vifc_rmt_addr.s_addr),
865 vifcp->vifc_threshold,
866 vifcp->vifc_rate_limit);
872 * Delete a vif from the vif table
881 vifp = &viftable[vifi];
882 if (vifp->v_lcl_addr.s_addr == INADDR_ANY)
883 return EADDRNOTAVAIL;
885 lwkt_gettoken(&mroute_token);
887 if (!(vifp->v_flags & (VIFF_TUNNEL | VIFF_REGISTER)))
888 if_allmulti(vifp->v_ifp, 0);
890 if (vifp == last_encap_vif) {
891 last_encap_vif = NULL;
892 last_encap_src = INADDR_ANY;
896 * Free packets queued at the interface
898 while (vifp->v_tbf->tbf_q) {
899 struct mbuf *m = vifp->v_tbf->tbf_q;
901 vifp->v_tbf->tbf_q = m->m_nextpkt;
906 if (vifp->v_flags & VIFF_REGISTER)
907 reg_vif_num = VIFI_INVALID;
910 bzero((caddr_t)vifp->v_tbf, sizeof(*(vifp->v_tbf)));
911 bzero((caddr_t)vifp, sizeof (*vifp));
914 log(LOG_DEBUG, "del_vif %d, numvifs %d\n", vifi, numvifs);
916 /* Adjust numvifs down */
917 for (vifi = numvifs; vifi > 0; vifi--)
918 if (viftable[vifi-1].v_lcl_addr.s_addr != INADDR_ANY)
922 lwkt_reltoken(&mroute_token);
928 * update an mfc entry without resetting counters and S,G addresses.
931 update_mfc_params(struct mfc *rt, struct mfcctl2 *mfccp)
935 rt->mfc_parent = mfccp->mfcc_parent;
936 for (i = 0; i < numvifs; i++) {
937 rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
938 rt->mfc_flags[i] = mfccp->mfcc_flags[i] & mrt_api_config &
941 /* set the RP address */
942 if (mrt_api_config & MRT_MFC_RP)
943 rt->mfc_rp = mfccp->mfcc_rp;
945 rt->mfc_rp.s_addr = INADDR_ANY;
949 * fully initialize an mfc entry from the parameter.
952 init_mfc_params(struct mfc *rt, struct mfcctl2 *mfccp)
954 rt->mfc_origin = mfccp->mfcc_origin;
955 rt->mfc_mcastgrp = mfccp->mfcc_mcastgrp;
957 update_mfc_params(rt, mfccp);
959 /* initialize pkt counters per src-grp */
961 rt->mfc_byte_cnt = 0;
962 rt->mfc_wrong_if = 0;
963 rt->mfc_last_assert.tv_sec = rt->mfc_last_assert.tv_usec = 0;
971 add_mfc(struct mfcctl2 *mfccp)
978 rt = mfc_find(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
980 /* If an entry already exists, just update the fields */
982 if (mrtdebug & DEBUG_MFC)
983 log(LOG_DEBUG,"add_mfc update o %lx g %lx p %x\n",
984 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
985 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
988 lwkt_gettoken(&mroute_token);
989 update_mfc_params(rt, mfccp);
990 lwkt_reltoken(&mroute_token);
995 * Find the entry for which the upcall was made and update
997 lwkt_gettoken(&mroute_token);
998 hash = MFCHASH(mfccp->mfcc_origin.s_addr, mfccp->mfcc_mcastgrp.s_addr);
999 for (rt = mfctable[hash], nstl = 0; rt; rt = rt->mfc_next) {
1001 if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
1002 (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr) &&
1003 (rt->mfc_stall != NULL)) {
1006 log(LOG_ERR, "add_mfc %s o %lx g %lx p %x dbx %p\n",
1007 "multiple kernel entries",
1008 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1009 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1010 mfccp->mfcc_parent, (void *)rt->mfc_stall);
1012 if (mrtdebug & DEBUG_MFC)
1013 log(LOG_DEBUG,"add_mfc o %lx g %lx p %x dbg %p\n",
1014 (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1015 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1016 mfccp->mfcc_parent, (void *)rt->mfc_stall);
1018 init_mfc_params(rt, mfccp);
1020 rt->mfc_expire = 0; /* Don't clean this guy up */
1023 /* free packets Qed at the end of this entry */
1024 for (rte = rt->mfc_stall; rte != NULL; ) {
1025 struct rtdetq *n = rte->next;
1027 ip_mdq(rte->m, rte->ifp, rt, -1);
1029 kfree(rte, M_MRTABLE);
1032 rt->mfc_stall = NULL;
1037 * It is possible that an entry is being inserted without an upcall
1040 if (mrtdebug & DEBUG_MFC)
1041 log(LOG_DEBUG,"add_mfc no upcall h %lu o %lx g %lx p %x\n",
1042 hash, (u_long)ntohl(mfccp->mfcc_origin.s_addr),
1043 (u_long)ntohl(mfccp->mfcc_mcastgrp.s_addr),
1044 mfccp->mfcc_parent);
1046 for (rt = mfctable[hash]; rt != NULL; rt = rt->mfc_next) {
1047 if ((rt->mfc_origin.s_addr == mfccp->mfcc_origin.s_addr) &&
1048 (rt->mfc_mcastgrp.s_addr == mfccp->mfcc_mcastgrp.s_addr)) {
1049 init_mfc_params(rt, mfccp);
1056 if (rt == NULL) { /* no upcall, so make a new entry */
1057 rt = kmalloc(sizeof(*rt), M_MRTABLE, M_INTWAIT | M_NULLOK);
1059 lwkt_reltoken(&mroute_token);
1063 init_mfc_params(rt, mfccp);
1065 rt->mfc_stall = NULL;
1067 rt->mfc_bw_meter = NULL;
1068 /* insert new entry at head of hash chain */
1069 rt->mfc_next = mfctable[hash];
1070 mfctable[hash] = rt;
1073 lwkt_reltoken(&mroute_token);
1078 * Delete an mfc entry
1081 del_mfc(struct mfcctl2 *mfccp)
1083 struct in_addr origin;
1084 struct in_addr mcastgrp;
1088 struct bw_meter *list;
1090 origin = mfccp->mfcc_origin;
1091 mcastgrp = mfccp->mfcc_mcastgrp;
1093 if (mrtdebug & DEBUG_MFC)
1094 log(LOG_DEBUG,"del_mfc orig %lx mcastgrp %lx\n",
1095 (u_long)ntohl(origin.s_addr), (u_long)ntohl(mcastgrp.s_addr));
1097 lwkt_gettoken(&mroute_token);
1099 hash = MFCHASH(origin.s_addr, mcastgrp.s_addr);
1100 for (nptr = &mfctable[hash]; (rt = *nptr) != NULL; nptr = &rt->mfc_next)
1101 if (origin.s_addr == rt->mfc_origin.s_addr &&
1102 mcastgrp.s_addr == rt->mfc_mcastgrp.s_addr &&
1103 rt->mfc_stall == NULL)
1106 lwkt_reltoken(&mroute_token);
1107 return EADDRNOTAVAIL;
1110 *nptr = rt->mfc_next;
1113 * free the bw_meter entries
1115 list = rt->mfc_bw_meter;
1116 rt->mfc_bw_meter = NULL;
1117 lwkt_reltoken(&mroute_token);
1119 kfree(rt, M_MRTABLE);
1126 * Send a message to mrouted on the multicast routing socket
1129 socket_send(struct socket *s, struct mbuf *mm, struct sockaddr_in *src)
1132 if (ssb_appendaddr(&s->so_rcv, (struct sockaddr *)src, mm, NULL) != 0) {
1142 * IP multicast forwarding function. This function assumes that the packet
1143 * pointed to by "ip" has arrived on (or is about to be sent to) the interface
1144 * pointed to by "ifp", and the packet is to be relayed to other networks
1145 * that have members of the packet's destination IP multicast group.
1147 * The packet is returned unscathed to the caller, unless it is
1148 * erroneous, in which case a non-zero return value tells the caller to
1152 #define TUNNEL_LEN 12 /* # bytes of IP option for tunnel encapsulation */
1155 X_ip_mforward(struct ip *ip, struct ifnet *ifp, struct mbuf *m,
1156 struct ip_moptions *imo)
1161 if (mrtdebug & DEBUG_FORWARD)
1162 log(LOG_DEBUG, "ip_mforward: src %lx, dst %lx, ifp %p\n",
1163 (u_long)ntohl(ip->ip_src.s_addr), (u_long)ntohl(ip->ip_dst.s_addr),
1166 if (ip->ip_hl < (sizeof(struct ip) + TUNNEL_LEN) >> 2 ||
1167 ((u_char *)(ip + 1))[1] != IPOPT_LSRR ) {
1169 * Packet arrived via a physical interface or
1170 * an encapsulated tunnel or a register_vif.
1174 * Packet arrived through a source-route tunnel.
1175 * Source-route tunnels are no longer supported.
1177 static int last_log;
1178 if (last_log != time_second) {
1179 last_log = time_second;
1181 "ip_mforward: received source-routed packet from %lx\n",
1182 (u_long)ntohl(ip->ip_src.s_addr));
1187 if (imo && ((vifi = imo->imo_multicast_vif) < numvifs)) {
1188 if (ip->ip_ttl < 255)
1189 ip->ip_ttl++; /* compensate for -1 in *_send routines */
1190 if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
1191 struct vif *vifp = viftable + vifi;
1193 kprintf("Sending IPPROTO_RSVP from %lx to %lx on vif %d (%s%s)\n",
1194 (long)ntohl(ip->ip_src.s_addr), (long)ntohl(ip->ip_dst.s_addr),
1196 (vifp->v_flags & VIFF_TUNNEL) ? "tunnel on " : "",
1197 vifp->v_ifp->if_xname);
1199 return ip_mdq(m, ifp, NULL, vifi);
1201 if (rsvpdebug && ip->ip_p == IPPROTO_RSVP) {
1202 kprintf("Warning: IPPROTO_RSVP from %lx to %lx without vif option\n",
1203 (long)ntohl(ip->ip_src.s_addr), (long)ntohl(ip->ip_dst.s_addr));
1205 kprintf("In fact, no options were specified at all\n");
1209 * Don't forward a packet with time-to-live of zero or one,
1210 * or a packet destined to a local-only group.
1212 if (ip->ip_ttl <= 1 || ntohl(ip->ip_dst.s_addr) <= INADDR_MAX_LOCAL_GROUP)
1216 * Determine forwarding vifs from the forwarding cache table
1218 lwkt_gettoken(&mroute_token);
1219 ++mrtstat.mrts_mfc_lookups;
1220 rt = mfc_find(ip->ip_src.s_addr, ip->ip_dst.s_addr);
1222 /* Entry exists, so forward if necessary */
1224 int ipres = ip_mdq(m, ifp, rt, -1);
1225 lwkt_reltoken(&mroute_token);
1229 * If we don't have a route for packet's origin,
1230 * Make a copy of the packet & send message to routing daemon
1236 int hlen = ip->ip_hl << 2;
1238 ++mrtstat.mrts_mfc_misses;
1240 mrtstat.mrts_no_route++;
1241 if (mrtdebug & (DEBUG_FORWARD | DEBUG_MFC))
1242 log(LOG_DEBUG, "ip_mforward: no rte s %lx g %lx\n",
1243 (u_long)ntohl(ip->ip_src.s_addr),
1244 (u_long)ntohl(ip->ip_dst.s_addr));
1247 * Allocate mbufs early so that we don't do extra work if we are
1248 * just going to fail anyway. Make sure to pullup the header so
1249 * that other people can't step on it.
1251 rte = kmalloc((sizeof *rte), M_MRTABLE, M_INTWAIT | M_NULLOK);
1253 lwkt_reltoken(&mroute_token);
1257 mb0 = m_copypacket(m, MB_DONTWAIT);
1258 if (mb0 && (M_HASCL(mb0) || mb0->m_len < hlen))
1259 mb0 = m_pullup(mb0, hlen);
1261 kfree(rte, M_MRTABLE);
1262 lwkt_reltoken(&mroute_token);
1266 /* is there an upcall waiting for this flow ? */
1267 hash = MFCHASH(ip->ip_src.s_addr, ip->ip_dst.s_addr);
1268 for (rt = mfctable[hash]; rt; rt = rt->mfc_next) {
1269 if ((ip->ip_src.s_addr == rt->mfc_origin.s_addr) &&
1270 (ip->ip_dst.s_addr == rt->mfc_mcastgrp.s_addr) &&
1271 (rt->mfc_stall != NULL))
1278 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
1282 * Locate the vifi for the incoming interface for this packet.
1283 * If none found, drop packet.
1285 for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++)
1287 if (vifi >= numvifs) /* vif not found, drop packet */
1290 /* no upcall, so make a new entry */
1291 rt = kmalloc(sizeof(*rt), M_MRTABLE, M_INTWAIT | M_NULLOK);
1295 /* Make a copy of the header to send to the user level process */
1296 mm = m_copy(mb0, 0, hlen);
1301 * Send message to routing daemon to install
1302 * a route into the kernel table
1305 im = mtod(mm, struct igmpmsg *);
1306 im->im_msgtype = IGMPMSG_NOCACHE;
1310 mrtstat.mrts_upcalls++;
1312 k_igmpsrc.sin_addr = ip->ip_src;
1313 if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
1314 log(LOG_WARNING, "ip_mforward: ip_mrouter socket queue full\n");
1315 ++mrtstat.mrts_upq_sockfull;
1317 kfree(rt, M_MRTABLE);
1319 kfree(rte, M_MRTABLE);
1321 lwkt_reltoken(&mroute_token);
1325 /* insert new entry at head of hash chain */
1326 rt->mfc_origin.s_addr = ip->ip_src.s_addr;
1327 rt->mfc_mcastgrp.s_addr = ip->ip_dst.s_addr;
1328 rt->mfc_expire = UPCALL_EXPIRE;
1330 for (i = 0; i < numvifs; i++) {
1331 rt->mfc_ttls[i] = 0;
1332 rt->mfc_flags[i] = 0;
1334 rt->mfc_parent = -1;
1336 rt->mfc_rp.s_addr = INADDR_ANY; /* clear the RP address */
1338 rt->mfc_bw_meter = NULL;
1340 /* link into table */
1341 rt->mfc_next = mfctable[hash];
1342 mfctable[hash] = rt;
1343 rt->mfc_stall = rte;
1346 /* determine if q has overflowed */
1351 * XXX ouch! we need to append to the list, but we
1352 * only have a pointer to the front, so we have to
1353 * scan the entire list every time.
1355 for (p = &rt->mfc_stall; *p != NULL; p = &(*p)->next)
1358 if (npkts > MAX_UPQ) {
1359 mrtstat.mrts_upq_ovflw++;
1361 kfree(rte, M_MRTABLE);
1363 lwkt_reltoken(&mroute_token);
1367 /* Add this entry to the end of the queue */
1375 lwkt_reltoken(&mroute_token);
1381 * Clean up the cache entry if upcall is not serviced
1384 expire_upcalls(void *unused)
1387 struct mfc *mfc, **nptr;
1390 lwkt_gettoken(&mroute_token);
1391 for (i = 0; i < MFCTBLSIZ; i++) {
1392 if (nexpire[i] == 0)
1394 nptr = &mfctable[i];
1395 for (mfc = *nptr; mfc != NULL; mfc = *nptr) {
1397 * Skip real cache entries
1398 * Make sure it wasn't marked to not expire (shouldn't happen)
1401 if (mfc->mfc_stall != NULL && mfc->mfc_expire != 0 &&
1402 --mfc->mfc_expire == 0) {
1403 if (mrtdebug & DEBUG_EXPIRE)
1404 log(LOG_DEBUG, "expire_upcalls: expiring (%lx %lx)\n",
1405 (u_long)ntohl(mfc->mfc_origin.s_addr),
1406 (u_long)ntohl(mfc->mfc_mcastgrp.s_addr));
1408 * drop all the packets
1409 * free the mbuf with the pkt, if, timing info
1411 for (rte = mfc->mfc_stall; rte; ) {
1412 struct rtdetq *n = rte->next;
1415 kfree(rte, M_MRTABLE);
1418 ++mrtstat.mrts_cache_cleanups;
1422 * free the bw_meter entries
1424 while (mfc->mfc_bw_meter != NULL) {
1425 struct bw_meter *x = mfc->mfc_bw_meter;
1427 mfc->mfc_bw_meter = x->bm_mfc_next;
1428 kfree(x, M_BWMETER);
1431 *nptr = mfc->mfc_next;
1432 kfree(mfc, M_MRTABLE);
1434 nptr = &mfc->mfc_next;
1438 callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL);
1439 lwkt_reltoken(&mroute_token);
1443 * Packet forwarding routine once entry in the cache is made
1446 ip_mdq(struct mbuf *m, struct ifnet *ifp, struct mfc *rt, vifi_t xmt_vif)
1448 struct ip *ip = mtod(m, struct ip *);
1450 int plen = ip->ip_len;
1453 * Macro to send packet on vif. Since RSVP packets don't get counted on
1454 * input, they shouldn't get counted on output, so statistics keeping is
1457 #define MC_SEND(ip,vifp,m) { \
1458 if ((vifp)->v_flags & VIFF_TUNNEL) \
1459 encap_send((ip), (vifp), (m)); \
1461 phyint_send((ip), (vifp), (m)); \
1465 * If xmt_vif is not -1, send on only the requested vif.
1467 * (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.)
1469 if (xmt_vif < numvifs) {
1471 if (viftable[xmt_vif].v_flags & VIFF_REGISTER)
1472 pim_register_send(ip, viftable + xmt_vif, m, rt);
1475 MC_SEND(ip, viftable + xmt_vif, m);
1480 * Don't forward if it didn't arrive from the parent vif for its origin.
1482 vifi = rt->mfc_parent;
1483 if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) {
1484 /* came in the wrong interface */
1485 if (mrtdebug & DEBUG_FORWARD)
1486 log(LOG_DEBUG, "wrong if: ifp %p vifi %d vififp %p\n",
1487 (void *)ifp, vifi, (void *)viftable[vifi].v_ifp);
1488 ++mrtstat.mrts_wrong_if;
1491 * If we are doing PIM assert processing, send a message
1492 * to the routing daemon.
1494 * XXX: A PIM-SM router needs the WRONGVIF detection so it
1495 * can complete the SPT switch, regardless of the type
1496 * of the iif (broadcast media, GRE tunnel, etc).
1498 if (pim_assert && (vifi < numvifs) && viftable[vifi].v_ifp) {
1503 if (ifp == &multicast_register_if)
1504 pimstat.pims_rcv_registers_wrongiif++;
1507 /* Get vifi for the incoming packet */
1508 for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++)
1510 if (vifi >= numvifs)
1511 return 0; /* The iif is not found: ignore the packet. */
1513 if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_DISABLE_WRONGVIF)
1514 return 0; /* WRONGVIF disabled: ignore the packet */
1518 TV_DELTA(rt->mfc_last_assert, now, delta);
1520 if (delta > ASSERT_MSG_TIME) {
1521 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
1523 int hlen = ip->ip_hl << 2;
1524 struct mbuf *mm = m_copy(m, 0, hlen);
1526 if (mm && (M_HASCL(mm) || mm->m_len < hlen))
1527 mm = m_pullup(mm, hlen);
1531 rt->mfc_last_assert = now;
1533 im = mtod(mm, struct igmpmsg *);
1534 im->im_msgtype = IGMPMSG_WRONGVIF;
1538 mrtstat.mrts_upcalls++;
1540 k_igmpsrc.sin_addr = im->im_src;
1541 if (socket_send(ip_mrouter, mm, &k_igmpsrc) < 0) {
1543 "ip_mforward: ip_mrouter socket queue full\n");
1544 ++mrtstat.mrts_upq_sockfull;
1552 /* If I sourced this packet, it counts as output, else it was input. */
1553 if (ip->ip_src.s_addr == viftable[vifi].v_lcl_addr.s_addr) {
1554 viftable[vifi].v_pkt_out++;
1555 viftable[vifi].v_bytes_out += plen;
1557 viftable[vifi].v_pkt_in++;
1558 viftable[vifi].v_bytes_in += plen;
1561 rt->mfc_byte_cnt += plen;
1564 * For each vif, decide if a copy of the packet should be forwarded.
1566 * - the ttl exceeds the vif's threshold
1567 * - there are group members downstream on interface
1569 for (vifi = 0; vifi < numvifs; vifi++)
1570 if ((rt->mfc_ttls[vifi] > 0) && (ip->ip_ttl > rt->mfc_ttls[vifi])) {
1571 viftable[vifi].v_pkt_out++;
1572 viftable[vifi].v_bytes_out += plen;
1574 if (viftable[vifi].v_flags & VIFF_REGISTER)
1575 pim_register_send(ip, viftable + vifi, m, rt);
1578 MC_SEND(ip, viftable+vifi, m);
1582 * Perform upcall-related bw measuring.
1584 if (rt->mfc_bw_meter != NULL) {
1589 for (x = rt->mfc_bw_meter; x != NULL; x = x->bm_mfc_next)
1590 bw_meter_receive_packet(x, plen, &now);
1597 * check if a vif number is legal/ok. This is used by ip_output.
1600 X_legal_vif_num(int vif)
1602 return (vif >= 0 && vif < numvifs);
1606 * Return the local address used by this vif
1609 X_ip_mcast_src(int vifi)
1611 if (vifi >= 0 && vifi < numvifs)
1612 return viftable[vifi].v_lcl_addr.s_addr;
1618 phyint_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
1620 struct mbuf *mb_copy;
1621 int hlen = ip->ip_hl << 2;
1624 * Make a new reference to the packet; make sure that
1625 * the IP header is actually copied, not just referenced,
1626 * so that ip_output() only scribbles on the copy.
1628 mb_copy = m_copypacket(m, MB_DONTWAIT);
1629 if (mb_copy && (M_HASCL(mb_copy) || mb_copy->m_len < hlen))
1630 mb_copy = m_pullup(mb_copy, hlen);
1631 if (mb_copy == NULL)
1634 if (vifp->v_rate_limit == 0)
1635 tbf_send_packet(vifp, mb_copy);
1637 tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *), ip->ip_len);
1641 encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m)
1643 struct mbuf *mb_copy;
1645 int i, len = ip->ip_len;
1647 /* Take care of delayed checksums */
1648 if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) {
1649 in_delayed_cksum(m);
1650 m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
1654 * copy the old packet & pullup its IP header into the
1655 * new mbuf so we can modify it. Try to fill the new
1656 * mbuf since if we don't the ethernet driver will.
1658 MGETHDR(mb_copy, MB_DONTWAIT, MT_HEADER);
1659 if (mb_copy == NULL)
1661 mb_copy->m_data += max_linkhdr;
1662 mb_copy->m_len = sizeof(multicast_encap_iphdr);
1664 if ((mb_copy->m_next = m_copypacket(m, MB_DONTWAIT)) == NULL) {
1668 i = MHLEN - M_LEADINGSPACE(mb_copy);
1671 mb_copy = m_pullup(mb_copy, i);
1672 if (mb_copy == NULL)
1674 mb_copy->m_pkthdr.len = len + sizeof(multicast_encap_iphdr);
1677 * fill in the encapsulating IP header.
1679 ip_copy = mtod(mb_copy, struct ip *);
1680 *ip_copy = multicast_encap_iphdr;
1681 ip_copy->ip_id = ip_newid();
1682 ip_copy->ip_len += len;
1683 ip_copy->ip_src = vifp->v_lcl_addr;
1684 ip_copy->ip_dst = vifp->v_rmt_addr;
1687 * turn the encapsulated IP header back into a valid one.
1689 ip = (struct ip *)((caddr_t)ip_copy + sizeof(multicast_encap_iphdr));
1691 ip->ip_len = htons(ip->ip_len);
1692 ip->ip_off = htons(ip->ip_off);
1694 mb_copy->m_data += sizeof(multicast_encap_iphdr);
1695 ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
1696 mb_copy->m_data -= sizeof(multicast_encap_iphdr);
1698 if (vifp->v_rate_limit == 0)
1699 tbf_send_packet(vifp, mb_copy);
1701 tbf_control(vifp, mb_copy, ip, ip_copy->ip_len);
1705 * De-encapsulate a packet and feed it back through ip input (this
1706 * routine is called whenever IP gets a packet with proto type
1707 * ENCAP_PROTO and a local destination address).
1709 * This is similar to mroute_encapcheck() + mroute_encap_input() in -current.
1712 X_ipip_input(struct mbuf *m, int off, int proto)
1714 struct ip *ip = mtod(m, struct ip *);
1715 int hlen = ip->ip_hl << 2;
1717 if (!have_encap_tunnel) {
1718 rip_input(m, off, proto);
1722 * dump the packet if it's not to a multicast destination or if
1723 * we don't have an encapsulating tunnel with the source.
1724 * Note: This code assumes that the remote site IP address
1725 * uniquely identifies the tunnel (i.e., that this site has
1726 * at most one tunnel with the remote site).
1728 if (!IN_MULTICAST(ntohl(((struct ip *)((char *)ip+hlen))->ip_dst.s_addr))) {
1729 ++mrtstat.mrts_bad_tunnel;
1733 if (ip->ip_src.s_addr != last_encap_src) {
1734 struct vif *vifp = viftable;
1735 struct vif *vife = vifp + numvifs;
1737 last_encap_src = ip->ip_src.s_addr;
1738 last_encap_vif = NULL;
1739 for ( ; vifp < vife; ++vifp)
1740 if (vifp->v_rmt_addr.s_addr == ip->ip_src.s_addr) {
1741 if ((vifp->v_flags & (VIFF_TUNNEL|VIFF_SRCRT))
1743 last_encap_vif = vifp;
1747 if (last_encap_vif == NULL) {
1748 last_encap_src = INADDR_ANY;
1749 mrtstat.mrts_cant_tunnel++; /*XXX*/
1752 log(LOG_DEBUG, "ip_mforward: no tunnel with %lx\n",
1753 (u_long)ntohl(ip->ip_src.s_addr));
1757 if (hlen > sizeof(struct ip))
1759 m->m_data += sizeof(struct ip);
1760 m->m_len -= sizeof(struct ip);
1761 m->m_pkthdr.len -= sizeof(struct ip);
1762 m->m_pkthdr.rcvif = last_encap_vif->v_ifp;
1764 netisr_queue(NETISR_IP, m);
1768 * Token bucket filter module
1772 tbf_control(struct vif *vifp, struct mbuf *m, struct ip *ip, u_long p_len)
1774 struct tbf *t = vifp->v_tbf;
1776 if (p_len > MAX_BKT_SIZE) { /* drop if packet is too large */
1777 mrtstat.mrts_pkt2large++;
1782 tbf_update_tokens(vifp);
1784 if (t->tbf_q_len == 0) { /* queue empty... */
1785 if (p_len <= t->tbf_n_tok) { /* send packet if enough tokens */
1786 t->tbf_n_tok -= p_len;
1787 tbf_send_packet(vifp, m);
1788 } else { /* no, queue packet and try later */
1790 callout_reset(&tbf_reprocess_q_ch, TBF_REPROCESS,
1791 tbf_reprocess_q, vifp);
1793 } else if (t->tbf_q_len < t->tbf_max_q_len) {
1794 /* finite queue length, so queue pkts and process queue */
1796 tbf_process_q(vifp);
1798 /* queue full, try to dq and queue and process */
1799 if (!tbf_dq_sel(vifp, ip)) {
1800 mrtstat.mrts_q_overflow++;
1804 tbf_process_q(vifp);
1810 * adds a packet to the queue at the interface
1813 tbf_queue(struct vif *vifp, struct mbuf *m)
1815 struct tbf *t = vifp->v_tbf;
1817 lwkt_gettoken(&mroute_token);
1819 if (t->tbf_t == NULL) /* Queue was empty */
1821 else /* Insert at tail */
1822 t->tbf_t->m_nextpkt = m;
1824 t->tbf_t = m; /* Set new tail pointer */
1827 /* Make sure we didn't get fed a bogus mbuf */
1829 panic("tbf_queue: m_nextpkt");
1831 m->m_nextpkt = NULL;
1835 lwkt_reltoken(&mroute_token);
1839 * processes the queue at the interface
1842 tbf_process_q(struct vif *vifp)
1844 struct tbf *t = vifp->v_tbf;
1846 lwkt_gettoken(&mroute_token);
1848 /* loop through the queue at the interface and send as many packets
1851 while (t->tbf_q_len > 0) {
1852 struct mbuf *m = t->tbf_q;
1853 int len = mtod(m, struct ip *)->ip_len;
1855 /* determine if the packet can be sent */
1856 if (len > t->tbf_n_tok) /* not enough tokens, we are done */
1858 /* ok, reduce no of tokens, dequeue and send the packet. */
1859 t->tbf_n_tok -= len;
1861 t->tbf_q = m->m_nextpkt;
1862 if (--t->tbf_q_len == 0)
1865 m->m_nextpkt = NULL;
1866 tbf_send_packet(vifp, m);
1868 lwkt_reltoken(&mroute_token);
1872 tbf_reprocess_q(void *xvifp)
1874 struct vif *vifp = xvifp;
1876 if (ip_mrouter == NULL)
1878 tbf_update_tokens(vifp);
1879 tbf_process_q(vifp);
1880 if (vifp->v_tbf->tbf_q_len)
1881 callout_reset(&tbf_reprocess_q_ch, TBF_REPROCESS,
1882 tbf_reprocess_q, vifp);
1885 /* function that will selectively discard a member of the queue
1886 * based on the precedence value and the priority
1889 tbf_dq_sel(struct vif *vifp, struct ip *ip)
1892 struct mbuf *m, *last;
1894 struct tbf *t = vifp->v_tbf;
1896 lwkt_gettoken(&mroute_token);
1898 p = priority(vifp, ip);
1902 while ((m = *np) != NULL) {
1903 if (p > priority(vifp, mtod(m, struct ip *))) {
1905 /* If we're removing the last packet, fix the tail pointer */
1909 /* It's impossible for the queue to be empty, but check anyways. */
1910 if (--t->tbf_q_len == 0)
1912 mrtstat.mrts_drop_sel++;
1913 lwkt_reltoken(&mroute_token);
1919 lwkt_reltoken(&mroute_token);
1924 tbf_send_packet(struct vif *vifp, struct mbuf *m)
1926 lwkt_gettoken(&mroute_token);
1928 if (vifp->v_flags & VIFF_TUNNEL) /* If tunnel options */
1929 ip_output(m, NULL, &vifp->v_route, IP_FORWARDING, NULL, NULL);
1931 struct ip_moptions imo;
1933 static struct route ro; /* XXX check this */
1935 imo.imo_multicast_ifp = vifp->v_ifp;
1936 imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
1937 imo.imo_multicast_loop = 1;
1938 imo.imo_multicast_vif = -1;
1941 * Re-entrancy should not be a problem here, because
1942 * the packets that we send out and are looped back at us
1943 * should get rejected because they appear to come from
1944 * the loopback interface, thus preventing looping.
1946 error = ip_output(m, NULL, &ro, IP_FORWARDING, &imo, NULL);
1948 if (mrtdebug & DEBUG_XMIT)
1949 log(LOG_DEBUG, "phyint_send on vif %d err %d\n",
1950 (int)(vifp - viftable), error);
1952 lwkt_reltoken(&mroute_token);
1955 /* determine the current time and then
1956 * the elapsed time (between the last time and time now)
1957 * in milliseconds & update the no. of tokens in the bucket
1960 tbf_update_tokens(struct vif *vifp)
1964 struct tbf *t = vifp->v_tbf;
1966 lwkt_gettoken(&mroute_token);
1970 TV_DELTA(tp, t->tbf_last_pkt_t, tm);
1973 * This formula is actually
1974 * "time in seconds" * "bytes/second".
1976 * (tm / 1000000) * (v_rate_limit * 1000 * (1000/1024) / 8)
1978 * The (1000/1024) was introduced in add_vif to optimize
1979 * this divide into a shift.
1981 t->tbf_n_tok += tm * vifp->v_rate_limit / 1024 / 8;
1982 t->tbf_last_pkt_t = tp;
1984 if (t->tbf_n_tok > MAX_BKT_SIZE)
1985 t->tbf_n_tok = MAX_BKT_SIZE;
1987 lwkt_reltoken(&mroute_token);
1991 priority(struct vif *vifp, struct ip *ip)
1993 int prio = 50; /* the lowest priority -- default case */
1995 /* temporary hack; may add general packet classifier some day */
1998 * The UDP port space is divided up into four priority ranges:
1999 * [0, 16384) : unclassified - lowest priority
2000 * [16384, 32768) : audio - highest priority
2001 * [32768, 49152) : whiteboard - medium priority
2002 * [49152, 65536) : video - low priority
2004 * Everything else gets lowest priority.
2006 if (ip->ip_p == IPPROTO_UDP) {
2007 struct udphdr *udp = (struct udphdr *)(((char *)ip) + (ip->ip_hl << 2));
2008 switch (ntohs(udp->uh_dport) & 0xc000) {
2024 * End of token bucket filter modifications
2028 X_ip_rsvp_vif(struct socket *so, struct sockopt *sopt)
2032 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
2035 error = soopt_to_kbuf(sopt, &vifi, sizeof vifi, sizeof vifi);
2039 lwkt_gettoken(&mroute_token);
2041 if (vifi < 0 || vifi >= numvifs) { /* Error if vif is invalid */
2042 lwkt_reltoken(&mroute_token);
2043 return EADDRNOTAVAIL;
2046 if (sopt->sopt_name == IP_RSVP_VIF_ON) {
2047 /* Check if socket is available. */
2048 if (viftable[vifi].v_rsvpd != NULL) {
2049 lwkt_reltoken(&mroute_token);
2053 viftable[vifi].v_rsvpd = so;
2054 /* This may seem silly, but we need to be sure we don't over-increment
2055 * the RSVP counter, in case something slips up.
2057 if (!viftable[vifi].v_rsvp_on) {
2058 viftable[vifi].v_rsvp_on = 1;
2061 } else { /* must be VIF_OFF */
2063 * XXX as an additional consistency check, one could make sure
2064 * that viftable[vifi].v_rsvpd == so, otherwise passing so as
2065 * first parameter is pretty useless.
2067 viftable[vifi].v_rsvpd = NULL;
2069 * This may seem silly, but we need to be sure we don't over-decrement
2070 * the RSVP counter, in case something slips up.
2072 if (viftable[vifi].v_rsvp_on) {
2073 viftable[vifi].v_rsvp_on = 0;
2077 lwkt_reltoken(&mroute_token);
2082 X_ip_rsvp_force_done(struct socket *so)
2086 /* Don't bother if it is not the right type of socket. */
2087 if (so->so_type != SOCK_RAW || so->so_proto->pr_protocol != IPPROTO_RSVP)
2090 lwkt_gettoken(&mroute_token);
2092 /* The socket may be attached to more than one vif...this
2093 * is perfectly legal.
2095 for (vifi = 0; vifi < numvifs; vifi++) {
2096 if (viftable[vifi].v_rsvpd == so) {
2097 viftable[vifi].v_rsvpd = NULL;
2098 /* This may seem silly, but we need to be sure we don't
2099 * over-decrement the RSVP counter, in case something slips up.
2101 if (viftable[vifi].v_rsvp_on) {
2102 viftable[vifi].v_rsvp_on = 0;
2108 lwkt_reltoken(&mroute_token);
2112 X_rsvp_input(struct mbuf *m, ...)
2115 struct ip *ip = mtod(m, struct ip *);
2116 struct sockaddr_in rsvp_src = { sizeof rsvp_src, AF_INET };
2120 /* support IP_RECVIF used by rsvpd rel4.2a1 */
2128 off = __va_arg(ap, int);
2129 proto = __va_arg(ap, int);
2133 kprintf("rsvp_input: rsvp_on %d\n",rsvp_on);
2135 /* Can still get packets with rsvp_on = 0 if there is a local member
2136 * of the group to which the RSVP packet is addressed. But in this
2137 * case we want to throw the packet away.
2144 lwkt_gettoken(&mroute_token);
2147 kprintf("rsvp_input: check vifs\n");
2150 if (!(m->m_flags & M_PKTHDR))
2151 panic("rsvp_input no hdr");
2154 ifp = m->m_pkthdr.rcvif;
2155 /* Find which vif the packet arrived on. */
2156 for (vifi = 0; vifi < numvifs; vifi++)
2157 if (viftable[vifi].v_ifp == ifp)
2161 if (vifi == numvifs || (so = viftable[vifi].v_rsvpd) == NULL) {
2163 if (vifi == numvifs || viftable[vifi].v_rsvpd == NULL) {
2166 * If the old-style non-vif-associated socket is set,
2167 * then use it. Otherwise, drop packet since there
2168 * is no specific socket for this vif.
2170 if (ip_rsvpd != NULL) {
2172 kprintf("rsvp_input: Sending packet up old-style socket\n");
2173 rip_input(m, off, proto); /* xxx */
2175 if (rsvpdebug && vifi == numvifs)
2176 kprintf("rsvp_input: Can't find vif for packet.\n");
2177 else if (rsvpdebug && viftable[vifi].v_rsvpd == NULL)
2178 kprintf("rsvp_input: No socket defined for vif %d\n",vifi);
2181 lwkt_reltoken(&mroute_token);
2184 rsvp_src.sin_addr = ip->ip_src;
2187 kprintf("rsvp_input: m->m_len = %d, ssb_space() = %ld\n",
2188 m->m_len,ssb_space(&(viftable[vifi].v_rsvpd->so_rcv)));
2192 inp = (struct inpcb *)so->so_pcb;
2193 if (inp->inp_flags & INP_CONTROLOPTS ||
2194 inp->inp_socket->so_options & SO_TIMESTAMP)
2195 ip_savecontrol(inp, &opts, ip, m);
2196 if (ssb_appendaddr(&so->so_rcv,
2197 (struct sockaddr *)&rsvp_src,m, opts) == 0) {
2202 kprintf("rsvp_input: Failed to append to socket\n");
2207 kprintf("rsvp_input: send packet up\n");
2210 if (socket_send(viftable[vifi].v_rsvpd, m, &rsvp_src) < 0) {
2212 kprintf("rsvp_input: Failed to append to socket\n");
2215 kprintf("rsvp_input: send packet up\n");
2219 lwkt_reltoken(&mroute_token);
2223 * Code for bandwidth monitors
2227 * Define common interface for timeval-related methods
2229 #define BW_TIMEVALCMP(tvp, uvp, cmp) timevalcmp((tvp), (uvp), cmp)
2230 #define BW_TIMEVALDECR(vvp, uvp) timevalsub((vvp), (uvp))
2231 #define BW_TIMEVALADD(vvp, uvp) timevaladd((vvp), (uvp))
2234 compute_bw_meter_flags(struct bw_upcall *req)
2238 if (req->bu_flags & BW_UPCALL_UNIT_PACKETS)
2239 flags |= BW_METER_UNIT_PACKETS;
2240 if (req->bu_flags & BW_UPCALL_UNIT_BYTES)
2241 flags |= BW_METER_UNIT_BYTES;
2242 if (req->bu_flags & BW_UPCALL_GEQ)
2243 flags |= BW_METER_GEQ;
2244 if (req->bu_flags & BW_UPCALL_LEQ)
2245 flags |= BW_METER_LEQ;
2251 * Add a bw_meter entry
2254 add_bw_upcall(struct bw_upcall *req)
2257 struct timeval delta = { BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC,
2258 BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC };
2263 if (!(mrt_api_config & MRT_MFC_BW_UPCALL))
2266 /* Test if the flags are valid */
2267 if (!(req->bu_flags & (BW_UPCALL_UNIT_PACKETS | BW_UPCALL_UNIT_BYTES)))
2269 if (!(req->bu_flags & (BW_UPCALL_GEQ | BW_UPCALL_LEQ)))
2271 if ((req->bu_flags & (BW_UPCALL_GEQ | BW_UPCALL_LEQ))
2272 == (BW_UPCALL_GEQ | BW_UPCALL_LEQ))
2275 /* Test if the threshold time interval is valid */
2276 if (BW_TIMEVALCMP(&req->bu_threshold.b_time, &delta, <))
2279 flags = compute_bw_meter_flags(req);
2282 * Find if we have already same bw_meter entry
2284 lwkt_gettoken(&mroute_token);
2285 mfc = mfc_find(req->bu_src.s_addr, req->bu_dst.s_addr);
2287 lwkt_reltoken(&mroute_token);
2288 return EADDRNOTAVAIL;
2290 for (x = mfc->mfc_bw_meter; x != NULL; x = x->bm_mfc_next) {
2291 if ((BW_TIMEVALCMP(&x->bm_threshold.b_time,
2292 &req->bu_threshold.b_time, ==)) &&
2293 (x->bm_threshold.b_packets == req->bu_threshold.b_packets) &&
2294 (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) &&
2295 (x->bm_flags & BW_METER_USER_FLAGS) == flags) {
2296 lwkt_reltoken(&mroute_token);
2297 return 0; /* XXX Already installed */
2300 lwkt_reltoken(&mroute_token);
2302 /* Allocate the new bw_meter entry */
2303 x = kmalloc(sizeof(*x), M_BWMETER, M_INTWAIT);
2305 /* Set the new bw_meter entry */
2306 x->bm_threshold.b_time = req->bu_threshold.b_time;
2308 x->bm_start_time = now;
2309 x->bm_threshold.b_packets = req->bu_threshold.b_packets;
2310 x->bm_threshold.b_bytes = req->bu_threshold.b_bytes;
2311 x->bm_measured.b_packets = 0;
2312 x->bm_measured.b_bytes = 0;
2313 x->bm_flags = flags;
2314 x->bm_time_next = NULL;
2315 x->bm_time_hash = BW_METER_BUCKETS;
2317 /* Add the new bw_meter entry to the front of entries for this MFC */
2318 lwkt_gettoken(&mroute_token);
2320 x->bm_mfc_next = mfc->mfc_bw_meter;
2321 mfc->mfc_bw_meter = x;
2322 schedule_bw_meter(x, &now);
2323 lwkt_reltoken(&mroute_token);
2329 free_bw_list(struct bw_meter *list)
2331 while (list != NULL) {
2332 struct bw_meter *x = list;
2334 list = list->bm_mfc_next;
2335 unschedule_bw_meter(x);
2336 kfree(x, M_BWMETER);
2341 * Delete one or multiple bw_meter entries
2344 del_bw_upcall(struct bw_upcall *req)
2349 if (!(mrt_api_config & MRT_MFC_BW_UPCALL))
2352 lwkt_gettoken(&mroute_token);
2353 /* Find the corresponding MFC entry */
2354 mfc = mfc_find(req->bu_src.s_addr, req->bu_dst.s_addr);
2356 lwkt_reltoken(&mroute_token);
2357 return EADDRNOTAVAIL;
2358 } else if (req->bu_flags & BW_UPCALL_DELETE_ALL) {
2360 * Delete all bw_meter entries for this mfc
2362 struct bw_meter *list;
2364 list = mfc->mfc_bw_meter;
2365 mfc->mfc_bw_meter = NULL;
2366 lwkt_reltoken(&mroute_token);
2369 } else { /* Delete a single bw_meter entry */
2370 struct bw_meter *prev;
2373 flags = compute_bw_meter_flags(req);
2375 /* Find the bw_meter entry to delete */
2376 for (prev = NULL, x = mfc->mfc_bw_meter; x != NULL;
2377 prev = x, x = x->bm_mfc_next) {
2378 if ((BW_TIMEVALCMP(&x->bm_threshold.b_time,
2379 &req->bu_threshold.b_time, ==)) &&
2380 (x->bm_threshold.b_packets == req->bu_threshold.b_packets) &&
2381 (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) &&
2382 (x->bm_flags & BW_METER_USER_FLAGS) == flags)
2385 if (x != NULL) { /* Delete entry from the list for this MFC */
2387 prev->bm_mfc_next = x->bm_mfc_next; /* remove from middle*/
2389 x->bm_mfc->mfc_bw_meter = x->bm_mfc_next;/* new head of list */
2390 unschedule_bw_meter(x);
2391 lwkt_reltoken(&mroute_token);
2392 /* Free the bw_meter entry */
2393 kfree(x, M_BWMETER);
2396 lwkt_reltoken(&mroute_token);
2404 * Perform bandwidth measurement processing that may result in an upcall
2407 bw_meter_receive_packet(struct bw_meter *x, int plen, struct timeval *nowp)
2409 struct timeval delta;
2411 lwkt_gettoken(&mroute_token);
2413 BW_TIMEVALDECR(&delta, &x->bm_start_time);
2415 if (x->bm_flags & BW_METER_GEQ) {
2417 * Processing for ">=" type of bw_meter entry
2419 if (BW_TIMEVALCMP(&delta, &x->bm_threshold.b_time, >)) {
2420 /* Reset the bw_meter entry */
2421 x->bm_start_time = *nowp;
2422 x->bm_measured.b_packets = 0;
2423 x->bm_measured.b_bytes = 0;
2424 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
2427 /* Record that a packet is received */
2428 x->bm_measured.b_packets++;
2429 x->bm_measured.b_bytes += plen;
2432 * Test if we should deliver an upcall
2434 if (!(x->bm_flags & BW_METER_UPCALL_DELIVERED)) {
2435 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
2436 (x->bm_measured.b_packets >= x->bm_threshold.b_packets)) ||
2437 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
2438 (x->bm_measured.b_bytes >= x->bm_threshold.b_bytes))) {
2439 /* Prepare an upcall for delivery */
2440 bw_meter_prepare_upcall(x, nowp);
2441 x->bm_flags |= BW_METER_UPCALL_DELIVERED;
2444 } else if (x->bm_flags & BW_METER_LEQ) {
2446 * Processing for "<=" type of bw_meter entry
2448 if (BW_TIMEVALCMP(&delta, &x->bm_threshold.b_time, >)) {
2450 * We are behind time with the multicast forwarding table
2451 * scanning for "<=" type of bw_meter entries, so test now
2452 * if we should deliver an upcall.
2454 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
2455 (x->bm_measured.b_packets <= x->bm_threshold.b_packets)) ||
2456 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
2457 (x->bm_measured.b_bytes <= x->bm_threshold.b_bytes))) {
2458 /* Prepare an upcall for delivery */
2459 bw_meter_prepare_upcall(x, nowp);
2461 /* Reschedule the bw_meter entry */
2462 unschedule_bw_meter(x);
2463 schedule_bw_meter(x, nowp);
2466 /* Record that a packet is received */
2467 x->bm_measured.b_packets++;
2468 x->bm_measured.b_bytes += plen;
2471 * Test if we should restart the measuring interval
2473 if ((x->bm_flags & BW_METER_UNIT_PACKETS &&
2474 x->bm_measured.b_packets <= x->bm_threshold.b_packets) ||
2475 (x->bm_flags & BW_METER_UNIT_BYTES &&
2476 x->bm_measured.b_bytes <= x->bm_threshold.b_bytes)) {
2477 /* Don't restart the measuring interval */
2479 /* Do restart the measuring interval */
2481 * XXX: note that we don't unschedule and schedule, because this
2482 * might be too much overhead per packet. Instead, when we process
2483 * all entries for a given timer hash bin, we check whether it is
2484 * really a timeout. If not, we reschedule at that time.
2486 x->bm_start_time = *nowp;
2487 x->bm_measured.b_packets = 0;
2488 x->bm_measured.b_bytes = 0;
2489 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
2492 lwkt_reltoken(&mroute_token);
2496 * Prepare a bandwidth-related upcall
2499 bw_meter_prepare_upcall(struct bw_meter *x, struct timeval *nowp)
2501 struct timeval delta;
2502 struct bw_upcall *u;
2504 lwkt_gettoken(&mroute_token);
2507 * Compute the measured time interval
2510 BW_TIMEVALDECR(&delta, &x->bm_start_time);
2513 * If there are too many pending upcalls, deliver them now
2515 if (bw_upcalls_n >= BW_UPCALLS_MAX)
2519 * Set the bw_upcall entry
2521 u = &bw_upcalls[bw_upcalls_n++];
2522 u->bu_src = x->bm_mfc->mfc_origin;
2523 u->bu_dst = x->bm_mfc->mfc_mcastgrp;
2524 u->bu_threshold.b_time = x->bm_threshold.b_time;
2525 u->bu_threshold.b_packets = x->bm_threshold.b_packets;
2526 u->bu_threshold.b_bytes = x->bm_threshold.b_bytes;
2527 u->bu_measured.b_time = delta;
2528 u->bu_measured.b_packets = x->bm_measured.b_packets;
2529 u->bu_measured.b_bytes = x->bm_measured.b_bytes;
2531 if (x->bm_flags & BW_METER_UNIT_PACKETS)
2532 u->bu_flags |= BW_UPCALL_UNIT_PACKETS;
2533 if (x->bm_flags & BW_METER_UNIT_BYTES)
2534 u->bu_flags |= BW_UPCALL_UNIT_BYTES;
2535 if (x->bm_flags & BW_METER_GEQ)
2536 u->bu_flags |= BW_UPCALL_GEQ;
2537 if (x->bm_flags & BW_METER_LEQ)
2538 u->bu_flags |= BW_UPCALL_LEQ;
2540 lwkt_reltoken(&mroute_token);
2544 * Send the pending bandwidth-related upcalls
2547 bw_upcalls_send(void)
2550 int len = bw_upcalls_n * sizeof(bw_upcalls[0]);
2551 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
2552 static struct igmpmsg igmpmsg = { 0, /* unused1 */
2554 IGMPMSG_BW_UPCALL,/* im_msgtype */
2559 { 0 } }; /* im_dst */
2561 if (bw_upcalls_n == 0)
2562 return; /* No pending upcalls */
2567 * Allocate a new mbuf, initialize it with the header and
2568 * the payload for the pending calls.
2570 MGETHDR(m, MB_DONTWAIT, MT_HEADER);
2572 log(LOG_WARNING, "bw_upcalls_send: cannot allocate mbuf\n");
2576 m->m_len = m->m_pkthdr.len = 0;
2577 m_copyback(m, 0, sizeof(struct igmpmsg), (caddr_t)&igmpmsg);
2578 m_copyback(m, sizeof(struct igmpmsg), len, (caddr_t)&bw_upcalls[0]);
2582 * XXX do we need to set the address in k_igmpsrc ?
2584 mrtstat.mrts_upcalls++;
2585 if (socket_send(ip_mrouter, m, &k_igmpsrc) < 0) {
2586 log(LOG_WARNING, "bw_upcalls_send: ip_mrouter socket queue full\n");
2587 ++mrtstat.mrts_upq_sockfull;
2592 * Compute the timeout hash value for the bw_meter entries
2594 #define BW_METER_TIMEHASH(bw_meter, hash) \
2596 struct timeval next_timeval = (bw_meter)->bm_start_time; \
2598 BW_TIMEVALADD(&next_timeval, &(bw_meter)->bm_threshold.b_time); \
2599 (hash) = next_timeval.tv_sec; \
2600 if (next_timeval.tv_usec) \
2601 (hash)++; /* XXX: make sure we don't timeout early */ \
2602 (hash) %= BW_METER_BUCKETS; \
2606 * Schedule a timer to process periodically bw_meter entry of type "<="
2607 * by linking the entry in the proper hash bucket.
2610 schedule_bw_meter(struct bw_meter *x, struct timeval *nowp)
2614 if (!(x->bm_flags & BW_METER_LEQ))
2615 return; /* XXX: we schedule timers only for "<=" entries */
2618 * Reset the bw_meter entry
2620 lwkt_gettoken(&mroute_token);
2621 x->bm_start_time = *nowp;
2622 x->bm_measured.b_packets = 0;
2623 x->bm_measured.b_bytes = 0;
2624 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
2627 * Compute the timeout hash value and insert the entry
2629 BW_METER_TIMEHASH(x, time_hash);
2630 x->bm_time_next = bw_meter_timers[time_hash];
2631 bw_meter_timers[time_hash] = x;
2632 x->bm_time_hash = time_hash;
2634 lwkt_reltoken(&mroute_token);
2638 * Unschedule the periodic timer that processes bw_meter entry of type "<="
2639 * by removing the entry from the proper hash bucket.
2642 unschedule_bw_meter(struct bw_meter *x)
2645 struct bw_meter *prev, *tmp;
2647 if (!(x->bm_flags & BW_METER_LEQ))
2648 return; /* XXX: we schedule timers only for "<=" entries */
2651 * Compute the timeout hash value and delete the entry
2653 time_hash = x->bm_time_hash;
2654 if (time_hash >= BW_METER_BUCKETS)
2655 return; /* Entry was not scheduled */
2657 for (prev = NULL, tmp = bw_meter_timers[time_hash];
2658 tmp != NULL; prev = tmp, tmp = tmp->bm_time_next)
2663 panic("unschedule_bw_meter: bw_meter entry not found");
2666 prev->bm_time_next = x->bm_time_next;
2668 bw_meter_timers[time_hash] = x->bm_time_next;
2670 x->bm_time_next = NULL;
2671 x->bm_time_hash = BW_METER_BUCKETS;
2676 * Process all "<=" type of bw_meter that should be processed now,
2677 * and for each entry prepare an upcall if necessary. Each processed
2678 * entry is rescheduled again for the (periodic) processing.
2680 * This is run periodically (once per second normally). On each round,
2681 * all the potentially matching entries are in the hash slot that we are
2685 bw_meter_process(void)
2687 static uint32_t last_tv_sec; /* last time we processed this */
2691 struct timeval now, process_endtime;
2694 if (last_tv_sec == now.tv_sec)
2695 return; /* nothing to do */
2697 lwkt_gettoken(&mroute_token);
2698 loops = now.tv_sec - last_tv_sec;
2699 last_tv_sec = now.tv_sec;
2700 if (loops > BW_METER_BUCKETS)
2701 loops = BW_METER_BUCKETS;
2704 * Process all bins of bw_meter entries from the one after the last
2705 * processed to the current one. On entry, i points to the last bucket
2706 * visited, so we need to increment i at the beginning of the loop.
2708 for (i = (now.tv_sec - loops) % BW_METER_BUCKETS; loops > 0; loops--) {
2709 struct bw_meter *x, *tmp_list;
2711 if (++i >= BW_METER_BUCKETS)
2714 /* Disconnect the list of bw_meter entries from the bin */
2715 tmp_list = bw_meter_timers[i];
2716 bw_meter_timers[i] = NULL;
2718 /* Process the list of bw_meter entries */
2719 while (tmp_list != NULL) {
2721 tmp_list = tmp_list->bm_time_next;
2723 /* Test if the time interval is over */
2724 process_endtime = x->bm_start_time;
2725 BW_TIMEVALADD(&process_endtime, &x->bm_threshold.b_time);
2726 if (BW_TIMEVALCMP(&process_endtime, &now, >)) {
2727 /* Not yet: reschedule, but don't reset */
2730 BW_METER_TIMEHASH(x, time_hash);
2731 if (time_hash == i && process_endtime.tv_sec == now.tv_sec) {
2733 * XXX: somehow the bin processing is a bit ahead of time.
2734 * Put the entry in the next bin.
2736 if (++time_hash >= BW_METER_BUCKETS)
2739 x->bm_time_next = bw_meter_timers[time_hash];
2740 bw_meter_timers[time_hash] = x;
2741 x->bm_time_hash = time_hash;
2747 * Test if we should deliver an upcall
2749 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
2750 (x->bm_measured.b_packets <= x->bm_threshold.b_packets)) ||
2751 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
2752 (x->bm_measured.b_bytes <= x->bm_threshold.b_bytes))) {
2753 /* Prepare an upcall for delivery */
2754 bw_meter_prepare_upcall(x, &now);
2758 * Reschedule for next processing
2760 schedule_bw_meter(x, &now);
2763 /* Send all upcalls that are pending delivery */
2765 lwkt_reltoken(&mroute_token);
2769 * A periodic function for sending all upcalls that are pending delivery
2772 expire_bw_upcalls_send(void *unused)
2776 callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
2777 expire_bw_upcalls_send, NULL);
2781 * A periodic function for periodic scanning of the multicast forwarding
2782 * table for processing all "<=" bw_meter entries.
2785 expire_bw_meter_process(void *unused)
2787 if (mrt_api_config & MRT_MFC_BW_UPCALL)
2790 callout_reset(&bw_meter_ch, BW_METER_PERIOD,
2791 expire_bw_meter_process, NULL);
2795 * End of bandwidth monitoring code
2800 * Send the packet up to the user daemon, or eventually do kernel encapsulation
2804 pim_register_send(struct ip *ip, struct vif *vifp,
2805 struct mbuf *m, struct mfc *rt)
2807 struct mbuf *mb_copy, *mm;
2809 if (mrtdebug & DEBUG_PIM)
2810 log(LOG_DEBUG, "pim_register_send: ");
2812 mb_copy = pim_register_prepare(ip, m);
2813 if (mb_copy == NULL)
2817 * Send all the fragments. Note that the mbuf for each fragment
2818 * is freed by the sending machinery.
2820 for (mm = mb_copy; mm; mm = mb_copy) {
2821 mb_copy = mm->m_nextpkt;
2823 mm = m_pullup(mm, sizeof(struct ip));
2825 ip = mtod(mm, struct ip *);
2826 if ((mrt_api_config & MRT_MFC_RP) &&
2827 (rt->mfc_rp.s_addr != INADDR_ANY)) {
2828 pim_register_send_rp(ip, vifp, mm, rt);
2830 pim_register_send_upcall(ip, vifp, mm, rt);
2839 * Return a copy of the data packet that is ready for PIM Register
2841 * XXX: Note that in the returned copy the IP header is a valid one.
2843 static struct mbuf *
2844 pim_register_prepare(struct ip *ip, struct mbuf *m)
2846 struct mbuf *mb_copy = NULL;
2849 /* Take care of delayed checksums */
2850 if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) {
2851 in_delayed_cksum(m);
2852 m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
2856 * Copy the old packet & pullup its IP header into the
2857 * new mbuf so we can modify it.
2859 mb_copy = m_copypacket(m, MB_DONTWAIT);
2860 if (mb_copy == NULL)
2862 mb_copy = m_pullup(mb_copy, ip->ip_hl << 2);
2863 if (mb_copy == NULL)
2866 /* take care of the TTL */
2867 ip = mtod(mb_copy, struct ip *);
2870 /* Compute the MTU after the PIM Register encapsulation */
2871 mtu = 0xffff - sizeof(pim_encap_iphdr) - sizeof(pim_encap_pimhdr);
2873 if (ip->ip_len <= mtu) {
2874 /* Turn the IP header into a valid one */
2875 ip->ip_len = htons(ip->ip_len);
2876 ip->ip_off = htons(ip->ip_off);
2878 ip->ip_sum = in_cksum(mb_copy, ip->ip_hl << 2);
2880 /* Fragment the packet */
2881 if (ip_fragment(ip, &mb_copy, mtu, 0, CSUM_DELAY_IP) != 0) {
2890 * Send an upcall with the data packet to the user-level process.
2893 pim_register_send_upcall(struct ip *ip, struct vif *vifp,
2894 struct mbuf *mb_copy, struct mfc *rt)
2896 struct mbuf *mb_first;
2897 int len = ntohs(ip->ip_len);
2899 struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
2902 * Add a new mbuf with an upcall header
2904 MGETHDR(mb_first, MB_DONTWAIT, MT_HEADER);
2905 if (mb_first == NULL) {
2909 mb_first->m_data += max_linkhdr;
2910 mb_first->m_pkthdr.len = len + sizeof(struct igmpmsg);
2911 mb_first->m_len = sizeof(struct igmpmsg);
2912 mb_first->m_next = mb_copy;
2914 /* Send message to routing daemon */
2915 im = mtod(mb_first, struct igmpmsg *);
2916 im->im_msgtype = IGMPMSG_WHOLEPKT;
2918 im->im_vif = vifp - viftable;
2919 im->im_src = ip->ip_src;
2920 im->im_dst = ip->ip_dst;
2922 k_igmpsrc.sin_addr = ip->ip_src;
2924 mrtstat.mrts_upcalls++;
2926 if (socket_send(ip_mrouter, mb_first, &k_igmpsrc) < 0) {
2927 if (mrtdebug & DEBUG_PIM)
2929 "mcast: pim_register_send_upcall: ip_mrouter socket queue full");
2930 ++mrtstat.mrts_upq_sockfull;
2934 /* Keep statistics */
2935 pimstat.pims_snd_registers_msgs++;
2936 pimstat.pims_snd_registers_bytes += len;
2942 * Encapsulate the data packet in PIM Register message and send it to the RP.
2945 pim_register_send_rp(struct ip *ip, struct vif *vifp,
2946 struct mbuf *mb_copy, struct mfc *rt)
2948 struct mbuf *mb_first;
2949 struct ip *ip_outer;
2950 struct pim_encap_pimhdr *pimhdr;
2951 int len = ntohs(ip->ip_len);
2952 vifi_t vifi = rt->mfc_parent;
2954 if ((vifi >= numvifs) || (viftable[vifi].v_lcl_addr.s_addr == 0)) {
2956 return EADDRNOTAVAIL; /* The iif vif is invalid */
2960 * Add a new mbuf with the encapsulating header
2962 MGETHDR(mb_first, MB_DONTWAIT, MT_HEADER);
2963 if (mb_first == NULL) {
2967 mb_first->m_data += max_linkhdr;
2968 mb_first->m_len = sizeof(pim_encap_iphdr) + sizeof(pim_encap_pimhdr);
2969 mb_first->m_next = mb_copy;
2971 mb_first->m_pkthdr.len = len + mb_first->m_len;
2974 * Fill in the encapsulating IP and PIM header
2976 ip_outer = mtod(mb_first, struct ip *);
2977 *ip_outer = pim_encap_iphdr;
2978 ip_outer->ip_id = ip_newid();
2979 ip_outer->ip_len = len + sizeof(pim_encap_iphdr) + sizeof(pim_encap_pimhdr);
2980 ip_outer->ip_src = viftable[vifi].v_lcl_addr;
2981 ip_outer->ip_dst = rt->mfc_rp;
2983 * Copy the inner header TOS to the outer header, and take care of the
2986 ip_outer->ip_tos = ip->ip_tos;
2987 if (ntohs(ip->ip_off) & IP_DF)
2988 ip_outer->ip_off |= IP_DF;
2989 pimhdr = (struct pim_encap_pimhdr *)((caddr_t)ip_outer
2990 + sizeof(pim_encap_iphdr));
2991 *pimhdr = pim_encap_pimhdr;
2992 /* If the iif crosses a border, set the Border-bit */
2993 if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_BORDER_VIF & mrt_api_config)
2994 pimhdr->flags |= htonl(PIM_BORDER_REGISTER);
2996 mb_first->m_data += sizeof(pim_encap_iphdr);
2997 pimhdr->pim.pim_cksum = in_cksum(mb_first, sizeof(pim_encap_pimhdr));
2998 mb_first->m_data -= sizeof(pim_encap_iphdr);
3000 if (vifp->v_rate_limit == 0)
3001 tbf_send_packet(vifp, mb_first);
3003 tbf_control(vifp, mb_first, ip, ip_outer->ip_len);
3005 /* Keep statistics */
3006 pimstat.pims_snd_registers_msgs++;
3007 pimstat.pims_snd_registers_bytes += len;
3013 * PIM-SMv2 and PIM-DM messages processing.
3014 * Receives and verifies the PIM control messages, and passes them
3015 * up to the listening socket, using rip_input().
3016 * The only message with special processing is the PIM_REGISTER message
3017 * (used by PIM-SM): the PIM header is stripped off, and the inner packet
3018 * is passed to if_simloop().
3021 pim_input(struct mbuf *m, ...)
3024 struct ip *ip = mtod(m, struct ip *);
3027 int datalen = ip->ip_len;
3033 off = __va_arg(ap, int);
3034 proto = __va_arg(ap, int);
3039 /* Keep statistics */
3040 pimstat.pims_rcv_total_msgs++;
3041 pimstat.pims_rcv_total_bytes += datalen;
3046 if (datalen < PIM_MINLEN) {
3047 pimstat.pims_rcv_tooshort++;
3048 log(LOG_ERR, "pim_input: packet size too small %d from %lx\n",
3049 datalen, (u_long)ip->ip_src.s_addr);
3055 * If the packet is at least as big as a REGISTER, go agead
3056 * and grab the PIM REGISTER header size, to avoid another
3057 * possible m_pullup() later.
3059 * PIM_MINLEN == pimhdr + u_int32_t == 4 + 4 = 8
3060 * PIM_REG_MINLEN == pimhdr + reghdr + encap_iphdr == 4 + 4 + 20 = 28
3062 minlen = iphlen + (datalen >= PIM_REG_MINLEN ? PIM_REG_MINLEN : PIM_MINLEN);
3064 * Get the IP and PIM headers in contiguous memory, and
3065 * possibly the PIM REGISTER header.
3067 if ((m->m_flags & M_EXT || m->m_len < minlen) &&
3068 (m = m_pullup(m, minlen)) == 0) {
3069 log(LOG_ERR, "pim_input: m_pullup failure\n");
3072 /* m_pullup() may have given us a new mbuf so reset ip. */
3073 ip = mtod(m, struct ip *);
3074 ip_tos = ip->ip_tos;
3076 /* adjust mbuf to point to the PIM header */
3077 m->m_data += iphlen;
3079 pim = mtod(m, struct pim *);
3082 * Validate checksum. If PIM REGISTER, exclude the data packet.
3084 * XXX: some older PIMv2 implementations don't make this distinction,
3085 * so for compatibility reason perform the checksum over part of the
3086 * message, and if error, then over the whole message.
3088 if (PIM_VT_T(pim->pim_vt) == PIM_REGISTER && in_cksum(m, PIM_MINLEN) == 0) {
3089 /* do nothing, checksum okay */
3090 } else if (in_cksum(m, datalen)) {
3091 pimstat.pims_rcv_badsum++;
3092 if (mrtdebug & DEBUG_PIM)
3093 log(LOG_DEBUG, "pim_input: invalid checksum");
3098 /* PIM version check */
3099 if (PIM_VT_V(pim->pim_vt) < PIM_VERSION) {
3100 pimstat.pims_rcv_badversion++;
3101 log(LOG_ERR, "pim_input: incorrect version %d, expecting %d\n",
3102 PIM_VT_V(pim->pim_vt), PIM_VERSION);
3107 /* restore mbuf back to the outer IP */
3108 m->m_data -= iphlen;
3111 if (PIM_VT_T(pim->pim_vt) == PIM_REGISTER) {
3113 * Since this is a REGISTER, we'll make a copy of the register
3114 * headers ip + pim + u_int32 + encap_ip, to be passed up to the
3117 struct sockaddr_in dst = { sizeof(dst), AF_INET };
3119 struct ip *encap_ip;
3122 if ((reg_vif_num >= numvifs) || (reg_vif_num == VIFI_INVALID)) {
3123 if (mrtdebug & DEBUG_PIM)
3125 "pim_input: register vif not set: %d\n", reg_vif_num);
3133 if (datalen < PIM_REG_MINLEN) {
3134 pimstat.pims_rcv_tooshort++;
3135 pimstat.pims_rcv_badregisters++;
3137 "pim_input: register packet size too small %d from %lx\n",
3138 datalen, (u_long)ip->ip_src.s_addr);
3143 reghdr = (u_int32_t *)(pim + 1);
3144 encap_ip = (struct ip *)(reghdr + 1);
3146 if (mrtdebug & DEBUG_PIM) {
3148 "pim_input[register], encap_ip: %lx -> %lx, encap_ip len %d\n",
3149 (u_long)ntohl(encap_ip->ip_src.s_addr),
3150 (u_long)ntohl(encap_ip->ip_dst.s_addr),
3151 ntohs(encap_ip->ip_len));
3154 /* verify the version number of the inner packet */
3155 if (encap_ip->ip_v != IPVERSION) {
3156 pimstat.pims_rcv_badregisters++;
3157 if (mrtdebug & DEBUG_PIM) {
3158 log(LOG_DEBUG, "pim_input: invalid IP version (%d) "
3159 "of the inner packet\n", encap_ip->ip_v);
3165 /* verify the inner packet is destined to a mcast group */
3166 if (!IN_MULTICAST(ntohl(encap_ip->ip_dst.s_addr))) {
3167 pimstat.pims_rcv_badregisters++;
3168 if (mrtdebug & DEBUG_PIM)
3170 "pim_input: inner packet of register is not "
3172 (u_long)ntohl(encap_ip->ip_dst.s_addr));
3177 /* If a NULL_REGISTER, pass it to the daemon */
3178 if ((ntohl(*reghdr) & PIM_NULL_REGISTER))
3179 goto pim_input_to_daemon;
3182 * Copy the TOS from the outer IP header to the inner IP header.
3184 if (encap_ip->ip_tos != ip_tos) {
3185 /* Outer TOS -> inner TOS */
3186 encap_ip->ip_tos = ip_tos;
3187 /* Recompute the inner header checksum. Sigh... */
3189 /* adjust mbuf to point to the inner IP header */
3190 m->m_data += (iphlen + PIM_MINLEN);
3191 m->m_len -= (iphlen + PIM_MINLEN);
3193 encap_ip->ip_sum = 0;
3194 encap_ip->ip_sum = in_cksum(m, encap_ip->ip_hl << 2);
3196 /* restore mbuf to point back to the outer IP header */
3197 m->m_data -= (iphlen + PIM_MINLEN);
3198 m->m_len += (iphlen + PIM_MINLEN);
3202 * Decapsulate the inner IP packet and loopback to forward it
3203 * as a normal multicast packet. Also, make a copy of the
3204 * outer_iphdr + pimhdr + reghdr + encap_iphdr
3205 * to pass to the daemon later, so it can take the appropriate
3206 * actions (e.g., send back PIM_REGISTER_STOP).
3207 * XXX: here m->m_data points to the outer IP header.
3209 mcp = m_copy(m, 0, iphlen + PIM_REG_MINLEN);
3212 "pim_input: pim register: could not copy register head\n");
3217 /* Keep statistics */
3218 /* XXX: registers_bytes include only the encap. mcast pkt */
3219 pimstat.pims_rcv_registers_msgs++;
3220 pimstat.pims_rcv_registers_bytes += ntohs(encap_ip->ip_len);
3223 * forward the inner ip packet; point m_data at the inner ip.
3225 m_adj(m, iphlen + PIM_MINLEN);
3227 if (mrtdebug & DEBUG_PIM) {
3229 "pim_input: forwarding decapsulated register: "
3230 "src %lx, dst %lx, vif %d\n",
3231 (u_long)ntohl(encap_ip->ip_src.s_addr),
3232 (u_long)ntohl(encap_ip->ip_dst.s_addr),
3235 if_simloop(viftable[reg_vif_num].v_ifp, m, dst.sin_family, 0);
3237 /* prepare the register head to send to the mrouting daemon */
3241 pim_input_to_daemon:
3243 * Pass the PIM message up to the daemon; if it is a Register message,
3244 * pass the 'head' only up to the daemon. This includes the
3245 * outer IP header, PIM header, PIM-Register header and the
3247 * XXX: the outer IP header pkt size of a Register is not adjust to
3248 * reflect the fact that the inner multicast data is truncated.
3250 rip_input(m, iphlen, proto);
3257 ip_mroute_modevent(module_t mod, int type, void *unused)
3261 lwkt_gettoken(&mroute_token);
3262 /* XXX Protect against multiple loading */
3263 ip_mcast_src = X_ip_mcast_src;
3264 ip_mforward = X_ip_mforward;
3265 ip_mrouter_done = X_ip_mrouter_done;
3266 ip_mrouter_get = X_ip_mrouter_get;
3267 ip_mrouter_set = X_ip_mrouter_set;
3268 ip_rsvp_force_done = X_ip_rsvp_force_done;
3269 ip_rsvp_vif = X_ip_rsvp_vif;
3270 ipip_input = X_ipip_input;
3271 legal_vif_num = X_legal_vif_num;
3272 mrt_ioctl = X_mrt_ioctl;
3273 rsvp_input_p = X_rsvp_input;
3274 lwkt_reltoken(&mroute_token);
3281 lwkt_gettoken(&mroute_token);
3282 ip_mcast_src = NULL;
3284 ip_mrouter_done = NULL;
3285 ip_mrouter_get = NULL;
3286 ip_mrouter_set = NULL;
3287 ip_rsvp_force_done = NULL;
3290 legal_vif_num = NULL;
3292 rsvp_input_p = NULL;
3293 lwkt_reltoken(&mroute_token);
3299 static moduledata_t ip_mroutemod = {
3304 DECLARE_MODULE(ip_mroute, ip_mroutemod, SI_SUB_PSEUDO, SI_ORDER_ANY);