Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Feb 2007 22:09:03 +0000
From:      Bruce M Simpson <bms@incunabulum.net>
To:        Pavlin Radoslavov <pavlin@icir.org>, Bill Fenner <fenner@research.att.com>
Cc:        net@FreeBSD.org
Subject:   [PATCH] Make INET6 MROUTING dynamically loadable in GENERIC
Message-ID:  <45CE427F.7070308@incunabulum.net>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------050805040700080004050009
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

This should do what it says on the tin...

Regards,
BMS

--------------050805040700080004050009
Content-Type: text/x-patch;
 name="mrouting-ipv6-dyn.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mrouting-ipv6-dyn.diff"

Make IPv6 multicast forwarding dynamically loadable into a GENERIC kernel.

Index: conf/files
===================================================================
RCS file: /home/ncvs/src/sys/conf/files,v
retrieving revision 1.1175
diff -u -p -r1.1175 files
--- conf/files	7 Feb 2007 18:55:29 -0000	1.1175
+++ conf/files	10 Feb 2007 22:07:19 -0000
@@ -1759,6 +1759,7 @@ netinet/ip_icmp.c		optional inet
 netinet/ip_input.c		optional inet
 netinet/ip_ipsec.c		optional ipsec
 netinet/ip_ipsec.c		optional fast_ipsec
+netinet/ip_mroute.c		optional inet | inet6
 netinet/ip_mroute.c		optional mrouting
 netinet/ip_options.c		optional inet
 netinet/ip_output.c		optional inet
@@ -1814,7 +1815,7 @@ netinet6/in6_src.c		optional inet6
 netinet6/ip6_forward.c		optional inet6
 netinet6/ip6_id.c		optional inet6
 netinet6/ip6_input.c		optional inet6
-netinet6/ip6_mroute.c		optional inet6
+netinet6/ip6_mroute.c		optional mrouting inet6
 netinet6/ip6_output.c		optional inet6
 netinet6/ipcomp_core.c		optional ipsec
 netinet6/ipcomp_input.c		optional ipsec
Index: modules/ip_mroute_mod/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/modules/ip_mroute_mod/Makefile,v
retrieving revision 1.14
diff -u -p -r1.14 Makefile
--- modules/ip_mroute_mod/Makefile	9 Feb 2007 01:42:43 -0000	1.14
+++ modules/ip_mroute_mod/Makefile	10 Feb 2007 22:07:19 -0000
@@ -1,13 +1,21 @@
 # $FreeBSD: src/sys/modules/ip_mroute_mod/Makefile,v 1.14 2007/02/09 01:42:43 bms Exp $
 
-.PATH: ${.CURDIR}/../../netinet
+.PATH: ${.CURDIR}/../../netinet ${.CURDIR}/../../netinet6
 
 KMOD=	ip_mroute
-SRCS=	ip_mroute.c opt_mac.h opt_mrouting.h
+SRCS=	ip_mroute.c
+SRCS+=	ip6_mroute.c
+SRCS+=	opt_inet.h opt_inet6.h opt_mac.h opt_mrouting.h
 
 .if !defined(KERNBUILDDIR)
+opt_inet.h:
+	echo "#define INET 1" > ${.TARGET}
+
+opt_inet6.h:
+	echo "#define INET6 1" > ${.TARGET}
+
 opt_mrouting.h:
-	echo "#define	MROUTING 1" > ${.TARGET}
+	echo "#define MROUTING 1" > ${.TARGET}
 .endif
 
 .include <bsd.kmod.mk>
Index: netinet/ip_mroute.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_mroute.c,v
retrieving revision 1.128
diff -u -p -r1.128 ip_mroute.c
--- netinet/ip_mroute.c	10 Feb 2007 14:48:42 -0000	1.128
+++ netinet/ip_mroute.c	10 Feb 2007 22:07:20 -0000
@@ -55,6 +55,8 @@
  * $FreeBSD: src/sys/netinet/ip_mroute.c,v 1.128 2007/02/10 14:48:42 bms Exp $
  */
 
+#include "opt_inet.h"
+#include "opt_inet6.h"
 #include "opt_mac.h"
 #include "opt_mrouting.h"
 
@@ -217,6 +219,12 @@ struct protosw in_pim_protosw = {
 	.pr_usrreqs =		&rip_usrreqs
 };
 static const struct encaptab *pim_encap_cookie;
+
+#ifdef INET6
+extern struct protosw in6_pim_protosw;	/* ip6_mroute.c: struct in6_protosw */
+static const struct encaptab *pim6_encap_cookie;
+#endif
+
 static int pim_encapcheck(const struct mbuf *, int, int, void *);
 
 /*
@@ -2737,7 +2745,7 @@ pim_register_send_rp(struct ip *ip, stru
 }
 
 /*
- * pim_encapcheck() is called by the encap4_input() path at runtime to
+ * pim_encapcheck() is called by the encap[46]_input() path at runtime to
  * determine if a packet is for PIM; allowing PIM to be dynamically loaded
  * into the kernel.
  */
@@ -2995,6 +3003,10 @@ pim_input_to_daemon:
     return;
 }
 
+/*
+ * XXX: This is common code for dealing with initialization for both
+ * the IPv4 and IPv6 multicast forwarding paths. It could do with cleanup.
+ */
 static int
 ip_mroute_modevent(module_t mod, int type, void *unused)
 {
@@ -3006,6 +3018,7 @@ ip_mroute_modevent(module_t mod, int typ
 	ip_mrouter_reset();
 	TUNABLE_ULONG_FETCH("net.inet.pim.squelch_wholepkt",
 	    &pim_squelch_wholepkt);
+
 	pim_encap_cookie = encap_attach_func(AF_INET, IPPROTO_PIM,
 	    pim_encapcheck, &in_pim_protosw, NULL);
 	if (pim_encap_cookie == NULL) {
@@ -3015,6 +3028,23 @@ ip_mroute_modevent(module_t mod, int typ
 		mtx_destroy(&mrouter_mtx);
 		return (EINVAL);
 	}
+
+#ifdef INET6
+	pim6_encap_cookie = encap_attach_func(AF_INET6, IPPROTO_PIM,
+	    pim_encapcheck, &in6_pim_protosw, NULL);
+	if (pim6_encap_cookie == NULL) {
+		printf("ip_mroute: unable to attach pim6 encap\n");
+		if (pim_encap_cookie) {
+		    encap_detach(pim_encap_cookie);
+		    pim_encap_cookie = NULL;
+		}
+		VIF_LOCK_DESTROY();
+		MFC_LOCK_DESTROY();
+		mtx_destroy(&mrouter_mtx);
+		return (EINVAL);
+	}
+#endif
+
 	ip_mcast_src = X_ip_mcast_src;
 	ip_mforward = X_ip_mforward;
 	ip_mrouter_done = X_ip_mrouter_done;
@@ -3039,6 +3069,12 @@ ip_mroute_modevent(module_t mod, int typ
 	if (ip_mrouter)
 	    return EINVAL;
 
+#ifdef INET6
+	if (pim6_encap_cookie) {
+	    encap_detach(pim6_encap_cookie);
+	    pim6_encap_cookie = NULL;
+	}
+#endif
 	if (pim_encap_cookie) {
 	    encap_detach(pim_encap_cookie);
 	    pim_encap_cookie = NULL;
Index: netinet6/in6_proto.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/in6_proto.c,v
retrieving revision 1.40
diff -u -p -r1.40 in6_proto.c
--- netinet6/in6_proto.c	3 Nov 2006 15:23:15 -0000	1.40
+++ netinet6/in6_proto.c	10 Feb 2007 22:07:21 -0000
@@ -335,7 +335,7 @@ struct ip6protosw inet6sw[] = {
 	.pr_domain =		&inet6domain,
 	.pr_protocol =		IPPROTO_PIM,
 	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
-	.pr_input =		pim6_input,
+	.pr_input =		encap6_input,
 	.pr_output =		rip6_output,
 	.pr_ctloutput =		rip6_ctloutput,
 	.pr_usrreqs =		&rip6_usrreqs
Index: netinet6/ip6_mroute.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/ip6_mroute.c,v
retrieving revision 1.39
diff -u -p -r1.39 ip6_mroute.c
--- netinet6/ip6_mroute.c	12 Dec 2006 12:17:57 -0000	1.39
+++ netinet6/ip6_mroute.c	10 Feb 2007 22:07:22 -0000
@@ -114,6 +114,7 @@
 #include <netinet6/scope6_var.h>
 #include <netinet6/nd6.h>
 #include <netinet6/ip6_mroute.h>
+#include <netinet6/ip6protosw.h>
 #include <netinet6/pim6.h>
 #include <netinet6/pim6_var.h>
 
@@ -130,6 +131,18 @@ static int socket_send __P((struct socke
 static int register_send __P((struct ip6_hdr *, struct mif6 *,
 	    struct mbuf *));
 
+extern struct domain inetdomain;
+struct ip6protosw in6_pim_protosw = {
+	.pr_type =		SOCK_RAW,
+	.pr_domain =		&inetdomain,
+	.pr_protocol =		IPPROTO_PIM,
+	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_LASTHDR,
+	.pr_input =		pim6_input,
+	.pr_output =		rip6_output,
+	.pr_ctloutput =		rip6_ctloutput,
+	.pr_usrreqs =		&rip6_usrreqs
+};
+
 /*
  * Globals.  All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
  * except for netstat or debugging purposes.

--------------050805040700080004050009--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45CE427F.7070308>