Fri Jan 22 05:15:10 2016 UTC ()
Don't abuse struct protosw for ip_encap -- introduce struct encapsw.

Mostly mechanical change to replace it, culling some now-needless
boilerplate around all the users.

This does not substantively change the ip_encap API or eliminate
abuse of sketchy pointer casts -- that will come later, and will be
easier now that it is not tangled up with struct protosw.


(riastradh)
diff -r1.83 -r1.84 src/sys/net/if_stf.c
diff -r1.69 -r1.70 src/sys/netinet/in_gif.c
diff -r1.48 -r1.49 src/sys/netinet/ip_encap.c
diff -r1.13 -r1.14 src/sys/netinet/ip_encap.h
diff -r1.134 -r1.135 src/sys/netinet/ip_mroute.c
diff -r1.66 -r1.67 src/sys/netinet6/in6_gif.c
diff -r1.33 -r1.34 src/sys/netipsec/xform_ipip.c

cvs diff -r1.83 -r1.84 src/sys/net/if_stf.c (expand / switch to unified diff)

--- src/sys/net/if_stf.c 2016/01/20 21:43:59 1.83
+++ src/sys/net/if_stf.c 2016/01/22 05:15:10 1.84
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_stf.c,v 1.83 2016/01/20 21:43:59 riastradh Exp $ */ 1/* $NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $ */
2/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */ 2/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 2000 WIDE Project. 5 * Copyright (C) 2000 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -65,45 +65,44 @@ @@ -65,45 +65,44 @@
65 * Even if we assign link-locals to interface, we cannot really 65 * Even if we assign link-locals to interface, we cannot really
66 * use link-local unicast/multicast on top of 6to4 cloud (since there's no 66 * use link-local unicast/multicast on top of 6to4 cloud (since there's no
67 * encapsulation defined for link-local address), and the above analysis does 67 * encapsulation defined for link-local address), and the above analysis does
68 * not change. RFC3056 does not mandate the assignment of link-local address 68 * not change. RFC3056 does not mandate the assignment of link-local address
69 * either. 69 * either.
70 * 70 *
71 * 6to4 interface has security issues. Refer to 71 * 6to4 interface has security issues. Refer to
72 * http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt 72 * http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt
73 * for details. The code tries to filter out some of malicious packets. 73 * for details. The code tries to filter out some of malicious packets.
74 * Note that there is no way to be 100% secure. 74 * Note that there is no way to be 100% secure.
75 */ 75 */
76 76
77#include <sys/cdefs.h> 77#include <sys/cdefs.h>
78__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.83 2016/01/20 21:43:59 riastradh Exp $"); 78__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $");
79 79
80#ifdef _KERNEL_OPT 80#ifdef _KERNEL_OPT
81#include "opt_inet.h" 81#include "opt_inet.h"
82#endif 82#endif
83 83
84#ifndef INET6 84#ifndef INET6
85 #error "pseudo-device stf requires options INET6" 85 #error "pseudo-device stf requires options INET6"
86#endif 86#endif
87 87
88#include <sys/param.h> 88#include <sys/param.h>
89#include <sys/systm.h> 89#include <sys/systm.h>
90#include <sys/socket.h> 90#include <sys/socket.h>
91#include <sys/sockio.h> 91#include <sys/sockio.h>
92#include <sys/mbuf.h> 92#include <sys/mbuf.h>
93#include <sys/errno.h> 93#include <sys/errno.h>
94#include <sys/ioctl.h> 94#include <sys/ioctl.h>
95#include <sys/proc.h> 95#include <sys/proc.h>
96#include <sys/protosw.h> 
97#include <sys/queue.h> 96#include <sys/queue.h>
98#include <sys/syslog.h> 97#include <sys/syslog.h>
99 98
100#include <sys/cpu.h> 99#include <sys/cpu.h>
101 100
102#include <net/if.h> 101#include <net/if.h>
103#include <net/route.h> 102#include <net/route.h>
104#include <net/netisr.h> 103#include <net/netisr.h>
105#include <net/if_types.h> 104#include <net/if_types.h>
106#include <net/if_stf.h> 105#include <net/if_stf.h>
107 106
108#include <netinet/in.h> 107#include <netinet/in.h>
109#include <netinet/in_systm.h> 108#include <netinet/in_systm.h>
@@ -146,38 +145,29 @@ static LIST_HEAD(, stf_softc) stf_softc_ @@ -146,38 +145,29 @@ static LIST_HEAD(, stf_softc) stf_softc_
146 145
147static int stf_clone_create(struct if_clone *, int); 146static int stf_clone_create(struct if_clone *, int);
148static int stf_clone_destroy(struct ifnet *); 147static int stf_clone_destroy(struct ifnet *);
149 148
150struct if_clone stf_cloner = 149struct if_clone stf_cloner =
151 IF_CLONE_INITIALIZER("stf", stf_clone_create, stf_clone_destroy); 150 IF_CLONE_INITIALIZER("stf", stf_clone_create, stf_clone_destroy);
152 151
153#if NGIF > 0 152#if NGIF > 0
154extern int ip_gif_ttl; /*XXX*/ 153extern int ip_gif_ttl; /*XXX*/
155#else 154#else
156static int ip_gif_ttl = 40; /*XXX*/ 155static int ip_gif_ttl = 40; /*XXX*/
157#endif 156#endif
158 157
159extern struct domain inetdomain; 158static const struct encapsw in_stf_encapsw = {
160 159 .en_input = in_stf_input,
161static const struct protosw in_stf_protosw = 160 .en_ctlinput = NULL,
162{ 
163 .pr_type = SOCK_RAW, 
164 .pr_domain = &inetdomain, 
165 .pr_protocol = IPPROTO_IPV6, 
166 .pr_flags = PR_ATOMIC|PR_ADDR, 
167 .pr_input = in_stf_input, 
168 .pr_ctlinput = NULL, 
169 .pr_ctloutput = rip_ctloutput, 
170 .pr_usrreqs = &rip_usrreqs, 
171}; 161};
172 162
173static int stf_encapcheck(struct mbuf *, int, int, void *); 163static int stf_encapcheck(struct mbuf *, int, int, void *);
174static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *); 164static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *);
175static int stf_output(struct ifnet *, struct mbuf *, const struct sockaddr *, 165static int stf_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
176 struct rtentry *); 166 struct rtentry *);
177static int isrfc1918addr(const struct in_addr *); 167static int isrfc1918addr(const struct in_addr *);
178static int stf_checkaddr4(struct stf_softc *, const struct in_addr *, 168static int stf_checkaddr4(struct stf_softc *, const struct in_addr *,
179 struct ifnet *); 169 struct ifnet *);
180static int stf_checkaddr6(struct stf_softc *, const struct in6_addr *, 170static int stf_checkaddr6(struct stf_softc *, const struct in6_addr *,
181 struct ifnet *); 171 struct ifnet *);
182static void stf_rtrequest(int, struct rtentry *, const struct rt_addrinfo *); 172static void stf_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
183static int stf_ioctl(struct ifnet *, u_long, void *); 173static int stf_ioctl(struct ifnet *, u_long, void *);
@@ -196,27 +186,27 @@ stf_clone_create(struct if_clone *ifc, i @@ -196,27 +186,27 @@ stf_clone_create(struct if_clone *ifc, i
196{ 186{
197 struct stf_softc *sc; 187 struct stf_softc *sc;
198 188
199 if (LIST_FIRST(&stf_softc_list) != NULL) { 189 if (LIST_FIRST(&stf_softc_list) != NULL) {
200 /* Only one stf interface is allowed. */ 190 /* Only one stf interface is allowed. */
201 return (EEXIST); 191 return (EEXIST);
202 } 192 }
203 193
204 sc = malloc(sizeof(struct stf_softc), M_DEVBUF, M_WAIT|M_ZERO); 194 sc = malloc(sizeof(struct stf_softc), M_DEVBUF, M_WAIT|M_ZERO);
205 195
206 if_initname(&sc->sc_if, ifc->ifc_name, unit); 196 if_initname(&sc->sc_if, ifc->ifc_name, unit);
207 197
208 sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6, 198 sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
209 stf_encapcheck, &in_stf_protosw, sc); 199 stf_encapcheck, &in_stf_encapsw, sc);
210 if (sc->encap_cookie == NULL) { 200 if (sc->encap_cookie == NULL) {
211 printf("%s: unable to attach encap\n", if_name(&sc->sc_if)); 201 printf("%s: unable to attach encap\n", if_name(&sc->sc_if));
212 free(sc, M_DEVBUF); 202 free(sc, M_DEVBUF);
213 return (EIO); /* XXX */ 203 return (EIO); /* XXX */
214 } 204 }
215 205
216 sc->sc_if.if_mtu = STF_MTU; 206 sc->sc_if.if_mtu = STF_MTU;
217 sc->sc_if.if_flags = 0; 207 sc->sc_if.if_flags = 0;
218 sc->sc_if.if_ioctl = stf_ioctl; 208 sc->sc_if.if_ioctl = stf_ioctl;
219 sc->sc_if.if_output = stf_output; 209 sc->sc_if.if_output = stf_output;
220 sc->sc_if.if_type = IFT_STF; 210 sc->sc_if.if_type = IFT_STF;
221 sc->sc_if.if_dlt = DLT_NULL; 211 sc->sc_if.if_dlt = DLT_NULL;
222 if_attach(&sc->sc_if); 212 if_attach(&sc->sc_if);

cvs diff -r1.69 -r1.70 src/sys/netinet/in_gif.c (expand / switch to unified diff)

--- src/sys/netinet/in_gif.c 2016/01/20 21:43:59 1.69
+++ src/sys/netinet/in_gif.c 2016/01/22 05:15:10 1.70
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in_gif.c,v 1.69 2016/01/20 21:43:59 riastradh Exp $ */ 1/* $NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $ */
2/* $KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $ */ 2/* $KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -21,41 +21,40 @@ @@ -21,41 +21,40 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.69 2016/01/20 21:43:59 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $");
35 35
36#ifdef _KERNEL_OPT 36#ifdef _KERNEL_OPT
37#include "opt_inet.h" 37#include "opt_inet.h"
38#endif 38#endif
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/socket.h> 42#include <sys/socket.h>
43#include <sys/sockio.h> 43#include <sys/sockio.h>
44#include <sys/mbuf.h> 44#include <sys/mbuf.h>
45#include <sys/errno.h> 45#include <sys/errno.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
47#include <sys/syslog.h> 47#include <sys/syslog.h>
48#include <sys/protosw.h> 
49#include <sys/kernel.h> 48#include <sys/kernel.h>
50 49
51#include <net/if.h> 50#include <net/if.h>
52#include <net/route.h> 51#include <net/route.h>
53 52
54#include <netinet/in.h> 53#include <netinet/in.h>
55#include <netinet/in_systm.h> 54#include <netinet/in_systm.h>
56#include <netinet/ip.h> 55#include <netinet/ip.h>
57#include <netinet/ip_var.h> 56#include <netinet/ip_var.h>
58#include <netinet/in_gif.h> 57#include <netinet/in_gif.h>
59#include <netinet/in_var.h> 58#include <netinet/in_var.h>
60#include <netinet/ip_encap.h> 59#include <netinet/ip_encap.h>
61#include <netinet/ip_ecn.h> 60#include <netinet/ip_ecn.h>
@@ -69,35 +68,29 @@ __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1 @@ -69,35 +68,29 @@ __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1
69#include "gif.h" 68#include "gif.h"
70 69
71#include <net/net_osdep.h> 70#include <net/net_osdep.h>
72 71
73static int gif_validate4(const struct ip *, struct gif_softc *, 72static int gif_validate4(const struct ip *, struct gif_softc *,
74 struct ifnet *); 73 struct ifnet *);
75 74
76#if NGIF > 0 75#if NGIF > 0
77int ip_gif_ttl = GIF_TTL; 76int ip_gif_ttl = GIF_TTL;
78#else 77#else
79int ip_gif_ttl = 0; 78int ip_gif_ttl = 0;
80#endif 79#endif
81 80
82static const struct protosw in_gif_protosw = { 81static const struct encapsw in_gif_encapsw = {
83 .pr_type = SOCK_RAW, 82 .en_input = in_gif_input,
84 .pr_domain = &inetdomain, 83 .en_ctlinput = NULL,
85 .pr_protocol = 0 /* IPPROTO_IPV[46] */, 
86 .pr_flags = PR_ATOMIC|PR_ADDR, 
87 .pr_input = in_gif_input, 
88 .pr_ctlinput = NULL, 
89 .pr_ctloutput = rip_ctloutput, 
90 .pr_usrreqs = &rip_usrreqs, 
91}; 84};
92 85
93int 86int
94in_gif_output(struct ifnet *ifp, int family, struct mbuf *m) 87in_gif_output(struct ifnet *ifp, int family, struct mbuf *m)
95{ 88{
96 struct rtentry *rt; 89 struct rtentry *rt;
97 struct gif_softc *sc = ifp->if_softc; 90 struct gif_softc *sc = ifp->if_softc;
98 struct sockaddr_in *sin_src = satosin(sc->gif_psrc); 91 struct sockaddr_in *sin_src = satosin(sc->gif_psrc);
99 struct sockaddr_in *sin_dst = satosin(sc->gif_pdst); 92 struct sockaddr_in *sin_dst = satosin(sc->gif_pdst);
100 struct ip iphdr; /* capsule IP header, host byte ordered */ 93 struct ip iphdr; /* capsule IP header, host byte ordered */
101 int proto, error; 94 int proto, error;
102 u_int8_t tos; 95 u_int8_t tos;
103 union { 96 union {
@@ -371,30 +364,30 @@ int @@ -371,30 +364,30 @@ int
371in_gif_attach(struct gif_softc *sc) 364in_gif_attach(struct gif_softc *sc)
372{ 365{
373#ifndef GIF_ENCAPCHECK 366#ifndef GIF_ENCAPCHECK
374 struct sockaddr_in mask4; 367 struct sockaddr_in mask4;
375 368
376 memset(&mask4, 0, sizeof(mask4)); 369 memset(&mask4, 0, sizeof(mask4));
377 mask4.sin_len = sizeof(struct sockaddr_in); 370 mask4.sin_len = sizeof(struct sockaddr_in);
378 mask4.sin_addr.s_addr = ~0; 371 mask4.sin_addr.s_addr = ~0;
379 372
380 if (!sc->gif_psrc || !sc->gif_pdst) 373 if (!sc->gif_psrc || !sc->gif_pdst)
381 return EINVAL; 374 return EINVAL;
382 sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc, 375 sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc,
383 (struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4, 376 (struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4,
384 (const struct protosw *)&in_gif_protosw, sc); 377 &in_gif_encapsw, sc);
385#else 378#else
386 sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck, 379 sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
387 &in_gif_protosw, sc); 380 &in_gif_encapsw, sc);
388#endif 381#endif
389 if (sc->encap_cookie4 == NULL) 382 if (sc->encap_cookie4 == NULL)
390 return EEXIST; 383 return EEXIST;
391 return 0; 384 return 0;
392} 385}
393 386
394int 387int
395in_gif_detach(struct gif_softc *sc) 388in_gif_detach(struct gif_softc *sc)
396{ 389{
397 int error; 390 int error;
398 391
399 error = encap_detach(sc->encap_cookie4); 392 error = encap_detach(sc->encap_cookie4);
400 if (error == 0) 393 if (error == 0)

cvs diff -r1.48 -r1.49 src/sys/netinet/ip_encap.c (expand / switch to unified diff)

--- src/sys/netinet/ip_encap.c 2016/01/20 05:58:49 1.48
+++ src/sys/netinet/ip_encap.c 2016/01/22 05:15:10 1.49
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_encap.c,v 1.48 2016/01/20 05:58:49 knakahara Exp $ */ 1/* $NetBSD: ip_encap.c,v 1.49 2016/01/22 05:15:10 riastradh Exp $ */
2/* $KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $ */ 2/* $KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 */ 57 */
58/* XXX is M_NETADDR correct? */ 58/* XXX is M_NETADDR correct? */
59 59
60/* 60/*
61 * The code will use radix table for tunnel lookup, for 61 * The code will use radix table for tunnel lookup, for
62 * tunnels registered with encap_attach() with a addr/mask pair. 62 * tunnels registered with encap_attach() with a addr/mask pair.
63 * Faster on machines with thousands of tunnel registerations (= interfaces). 63 * Faster on machines with thousands of tunnel registerations (= interfaces).
64 * 64 *
65 * The code assumes that radix table code can handle non-continuous netmask, 65 * The code assumes that radix table code can handle non-continuous netmask,
66 * as it will pass radix table memory region with (src + dst) sockaddr pair. 66 * as it will pass radix table memory region with (src + dst) sockaddr pair.
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.48 2016/01/20 05:58:49 knakahara Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.49 2016/01/22 05:15:10 riastradh Exp $");
71 71
72#ifdef _KERNEL_OPT 72#ifdef _KERNEL_OPT
73#include "opt_mrouting.h" 73#include "opt_mrouting.h"
74#include "opt_inet.h" 74#include "opt_inet.h"
75#endif 75#endif
76 76
77#include <sys/param.h> 77#include <sys/param.h>
78#include <sys/systm.h> 78#include <sys/systm.h>
79#include <sys/socket.h> 79#include <sys/socket.h>
80#include <sys/sockio.h> 80#include <sys/sockio.h>
81#include <sys/mbuf.h> 81#include <sys/mbuf.h>
82#include <sys/errno.h> 82#include <sys/errno.h>
83#include <sys/protosw.h> 83#include <sys/protosw.h>
@@ -230,42 +230,42 @@ encap4_lookup(struct mbuf *m, int off, i @@ -230,42 +230,42 @@ encap4_lookup(struct mbuf *m, int off, i
230 matchprio = prio; 230 matchprio = prio;
231 match = ep; 231 match = ep;
232 } 232 }
233 } 233 }
234 234
235 return match; 235 return match;
236} 236}
237 237
238void 238void
239encap4_input(struct mbuf *m, ...) 239encap4_input(struct mbuf *m, ...)
240{ 240{
241 int off, proto; 241 int off, proto;
242 va_list ap; 242 va_list ap;
243 const struct protosw *psw; 243 const struct encapsw *esw;
244 struct encaptab *match; 244 struct encaptab *match;
245 245
246 va_start(ap, m); 246 va_start(ap, m);
247 off = va_arg(ap, int); 247 off = va_arg(ap, int);
248 proto = va_arg(ap, int); 248 proto = va_arg(ap, int);
249 va_end(ap); 249 va_end(ap);
250 250
251 match = encap4_lookup(m, off, proto, INBOUND); 251 match = encap4_lookup(m, off, proto, INBOUND);
252 252
253 if (match) { 253 if (match) {
254 /* found a match, "match" has the best one */ 254 /* found a match, "match" has the best one */
255 psw = match->psw; 255 esw = match->esw;
256 if (psw && psw->pr_input) { 256 if (esw && esw->en_input) {
257 encap_fillarg(m, match); 257 encap_fillarg(m, match);
258 (*psw->pr_input)(m, off, proto); 258 (*esw->en_input)(m, off, proto);
259 } else 259 } else
260 m_freem(m); 260 m_freem(m);
261 return; 261 return;
262 } 262 }
263 263
264 /* last resort: inject to raw socket */ 264 /* last resort: inject to raw socket */
265 rip_input(m, off, proto); 265 rip_input(m, off, proto);
266} 266}
267#endif 267#endif
268 268
269#ifdef INET6 269#ifdef INET6
270static struct encaptab * 270static struct encaptab *
271encap6_lookup(struct mbuf *m, int off, int proto, enum direction dir) 271encap6_lookup(struct mbuf *m, int off, int proto, enum direction dir)
@@ -319,37 +319,40 @@ encap6_lookup(struct mbuf *m, int off, i @@ -319,37 +319,40 @@ encap6_lookup(struct mbuf *m, int off, i
319 if (prio > matchprio) { 319 if (prio > matchprio) {
320 matchprio = prio; 320 matchprio = prio;
321 match = ep; 321 match = ep;
322 } 322 }
323 } 323 }
324 324
325 return match; 325 return match;
326} 326}
327 327
328int 328int
329encap6_input(struct mbuf **mp, int *offp, int proto) 329encap6_input(struct mbuf **mp, int *offp, int proto)
330{ 330{
331 struct mbuf *m = *mp; 331 struct mbuf *m = *mp;
332 const struct ip6protosw *psw; 332 const struct encapsw *esw;
333 struct encaptab *match; 333 struct encaptab *match;
334 334
335 match = encap6_lookup(m, *offp, proto, INBOUND); 335 match = encap6_lookup(m, *offp, proto, INBOUND);
336 336
337 if (match) { 337 if (match) {
338 /* found a match */ 338 /* found a match */
339 psw = (const struct ip6protosw *)match->psw; 339 esw = match->esw;
340 if (psw && psw->pr_input) { 340 if (esw && esw->en_input) {
 341 /* XXX IPv6 cast, eliminate me */
 342 int (*input)(struct mbuf **, int *, int) =
 343 (int (*)(struct mbuf **, int *, int))esw->en_input;
341 encap_fillarg(m, match); 344 encap_fillarg(m, match);
342 return (*psw->pr_input)(mp, offp, proto); 345 return (*input)(mp, offp, proto);
343 } else { 346 } else {
344 m_freem(m); 347 m_freem(m);
345 return IPPROTO_DONE; 348 return IPPROTO_DONE;
346 } 349 }
347 } 350 }
348 351
349 /* last resort: inject to raw socket */ 352 /* last resort: inject to raw socket */
350 return rip6_input(mp, offp, proto); 353 return rip6_input(mp, offp, proto);
351} 354}
352#endif 355#endif
353 356
354static int 357static int
355encap_add(struct encaptab *ep) 358encap_add(struct encaptab *ep)
@@ -421,27 +424,27 @@ encap_afcheck(int af, const struct socka @@ -421,27 +424,27 @@ encap_afcheck(int af, const struct socka
421 424
422 return 0; 425 return 0;
423} 426}
424 427
425/* 428/*
426 * sp (src ptr) is always my side, and dp (dst ptr) is always remote side. 429 * sp (src ptr) is always my side, and dp (dst ptr) is always remote side.
427 * length of mask (sm and dm) is assumed to be same as sp/dp. 430 * length of mask (sm and dm) is assumed to be same as sp/dp.
428 * Return value will be necessary as input (cookie) for encap_detach(). 431 * Return value will be necessary as input (cookie) for encap_detach().
429 */ 432 */
430const struct encaptab * 433const struct encaptab *
431encap_attach(int af, int proto, 434encap_attach(int af, int proto,
432 const struct sockaddr *sp, const struct sockaddr *sm, 435 const struct sockaddr *sp, const struct sockaddr *sm,
433 const struct sockaddr *dp, const struct sockaddr *dm, 436 const struct sockaddr *dp, const struct sockaddr *dm,
434 const struct protosw *psw, void *arg) 437 const struct encapsw *esw, void *arg)
435{ 438{
436 struct encaptab *ep; 439 struct encaptab *ep;
437 int error; 440 int error;
438 int s; 441 int s;
439 size_t l; 442 size_t l;
440 struct ip_pack4 *pack4; 443 struct ip_pack4 *pack4;
441#ifdef INET6 444#ifdef INET6
442 struct ip_pack6 *pack6; 445 struct ip_pack6 *pack6;
443#endif 446#endif
444 447
445 s = splsoftnet(); 448 s = splsoftnet();
446 /* sanity check on args */ 449 /* sanity check on args */
447 error = encap_afcheck(af, sp, dp); 450 error = encap_afcheck(af, sp, dp);
@@ -524,80 +527,80 @@ encap_attach(int af, int proto, @@ -524,80 +527,80 @@ encap_attach(int af, int proto,
524 ep->src = (struct sockaddr *)&pack6->mine; 527 ep->src = (struct sockaddr *)&pack6->mine;
525 ep->dst = (struct sockaddr *)&pack6->yours; 528 ep->dst = (struct sockaddr *)&pack6->yours;
526 pack6 = (struct ip_pack6 *)ep->maskpack; 529 pack6 = (struct ip_pack6 *)ep->maskpack;
527 ep->srcmask = (struct sockaddr *)&pack6->mine; 530 ep->srcmask = (struct sockaddr *)&pack6->mine;
528 ep->dstmask = (struct sockaddr *)&pack6->yours; 531 ep->dstmask = (struct sockaddr *)&pack6->yours;
529 break; 532 break;
530#endif 533#endif
531 } 534 }
532 535
533 memcpy(ep->src, sp, sp->sa_len); 536 memcpy(ep->src, sp, sp->sa_len);
534 memcpy(ep->srcmask, sm, sp->sa_len); 537 memcpy(ep->srcmask, sm, sp->sa_len);
535 memcpy(ep->dst, dp, dp->sa_len); 538 memcpy(ep->dst, dp, dp->sa_len);
536 memcpy(ep->dstmask, dm, dp->sa_len); 539 memcpy(ep->dstmask, dm, dp->sa_len);
537 ep->psw = psw; 540 ep->esw = esw;
538 ep->arg = arg; 541 ep->arg = arg;
539 542
540 error = encap_add(ep); 543 error = encap_add(ep);
541 if (error) 544 if (error)
542 goto gc; 545 goto gc;
543 546
544 error = 0; 547 error = 0;
545 splx(s); 548 splx(s);
546 return ep; 549 return ep;
547 550
548gc: 551gc:
549 if (ep->addrpack) 552 if (ep->addrpack)
550 kmem_free(ep->addrpack, l); 553 kmem_free(ep->addrpack, l);
551 if (ep->maskpack) 554 if (ep->maskpack)
552 kmem_free(ep->maskpack, l); 555 kmem_free(ep->maskpack, l);
553 if (ep) 556 if (ep)
554 kmem_free(ep, sizeof(*ep)); 557 kmem_free(ep, sizeof(*ep));
555fail: 558fail:
556 splx(s); 559 splx(s);
557 return NULL; 560 return NULL;
558} 561}
559 562
560const struct encaptab * 563const struct encaptab *
561encap_attach_func(int af, int proto, 564encap_attach_func(int af, int proto,
562 int (*func)(struct mbuf *, int, int, void *), 565 int (*func)(struct mbuf *, int, int, void *),
563 const struct protosw *psw, void *arg) 566 const struct encapsw *esw, void *arg)
564{ 567{
565 struct encaptab *ep; 568 struct encaptab *ep;
566 int error; 569 int error;
567 int s; 570 int s;
568 571
569 s = splsoftnet(); 572 s = splsoftnet();
570 /* sanity check on args */ 573 /* sanity check on args */
571 if (!func) { 574 if (!func) {
572 error = EINVAL; 575 error = EINVAL;
573 goto fail; 576 goto fail;
574 } 577 }
575 578
576 error = encap_afcheck(af, NULL, NULL); 579 error = encap_afcheck(af, NULL, NULL);
577 if (error) 580 if (error)
578 goto fail; 581 goto fail;
579 582
580 ep = kmem_alloc(sizeof(*ep), KM_NOSLEEP); /*XXX*/ 583 ep = kmem_alloc(sizeof(*ep), KM_NOSLEEP); /*XXX*/
581 if (ep == NULL) { 584 if (ep == NULL) {
582 error = ENOBUFS; 585 error = ENOBUFS;
583 goto fail; 586 goto fail;
584 } 587 }
585 memset(ep, 0, sizeof(*ep)); 588 memset(ep, 0, sizeof(*ep));
586 589
587 ep->af = af; 590 ep->af = af;
588 ep->proto = proto; 591 ep->proto = proto;
589 ep->func = func; 592 ep->func = func;
590 ep->psw = psw; 593 ep->esw = esw;
591 ep->arg = arg; 594 ep->arg = arg;
592 595
593 error = encap_add(ep); 596 error = encap_add(ep);
594 if (error) 597 if (error)
595 goto fail; 598 goto fail;
596 599
597 error = 0; 600 error = 0;
598 splx(s); 601 splx(s);
599 return ep; 602 return ep;
600 603
601fail: 604fail:
602 splx(s); 605 splx(s);
603 return NULL; 606 return NULL;
@@ -606,27 +609,27 @@ fail: @@ -606,27 +609,27 @@ fail:
606/* XXX encap4_ctlinput() is necessary if we set DF=1 on outer IPv4 header */ 609/* XXX encap4_ctlinput() is necessary if we set DF=1 on outer IPv4 header */
607 610
608#ifdef INET6 611#ifdef INET6
609void * 612void *
610encap6_ctlinput(int cmd, const struct sockaddr *sa, void *d0) 613encap6_ctlinput(int cmd, const struct sockaddr *sa, void *d0)
611{ 614{
612 void *d = d0; 615 void *d = d0;
613 struct ip6_hdr *ip6; 616 struct ip6_hdr *ip6;
614 struct mbuf *m; 617 struct mbuf *m;
615 int off; 618 int off;
616 struct ip6ctlparam *ip6cp = NULL; 619 struct ip6ctlparam *ip6cp = NULL;
617 int nxt; 620 int nxt;
618 struct encaptab *ep; 621 struct encaptab *ep;
619 const struct ip6protosw *psw; 622 const struct encapsw *esw;
620 623
621 if (sa->sa_family != AF_INET6 || 624 if (sa->sa_family != AF_INET6 ||
622 sa->sa_len != sizeof(struct sockaddr_in6)) 625 sa->sa_len != sizeof(struct sockaddr_in6))
623 return NULL; 626 return NULL;
624 627
625 if ((unsigned)cmd >= PRC_NCMDS) 628 if ((unsigned)cmd >= PRC_NCMDS)
626 return NULL; 629 return NULL;
627 if (cmd == PRC_HOSTDEAD) 630 if (cmd == PRC_HOSTDEAD)
628 d = NULL; 631 d = NULL;
629 else if (cmd == PRC_MSGSIZE) 632 else if (cmd == PRC_MSGSIZE)
630 ; /* special code is present, see below */ 633 ; /* special code is present, see below */
631 else if (inet6ctlerrmap[cmd] == 0) 634 else if (inet6ctlerrmap[cmd] == 0)
632 return NULL; 635 return NULL;
@@ -665,29 +668,29 @@ encap6_ctlinput(int cmd, const struct so @@ -665,29 +668,29 @@ encap6_ctlinput(int cmd, const struct so
665 nxt = -1; 668 nxt = -1;
666 } 669 }
667 670
668 /* inform all listeners */ 671 /* inform all listeners */
669 LIST_FOREACH(ep, &encaptab, chain) { 672 LIST_FOREACH(ep, &encaptab, chain) {
670 if (ep->af != AF_INET6) 673 if (ep->af != AF_INET6)
671 continue; 674 continue;
672 if (ep->proto >= 0 && ep->proto != nxt) 675 if (ep->proto >= 0 && ep->proto != nxt)
673 continue; 676 continue;
674 677
675 /* should optimize by looking at address pairs */ 678 /* should optimize by looking at address pairs */
676 679
677 /* XXX need to pass ep->arg or ep itself to listeners */ 680 /* XXX need to pass ep->arg or ep itself to listeners */
678 psw = (const struct ip6protosw *)ep->psw; 681 esw = ep->esw;
679 if (psw && psw->pr_ctlinput) 682 if (esw && esw->en_ctlinput)
680 (*psw->pr_ctlinput)(cmd, sa, d); 683 (*esw->en_ctlinput)(cmd, sa, d);
681 } 684 }
682 685
683 rip6_ctlinput(cmd, sa, d0); 686 rip6_ctlinput(cmd, sa, d0);
684 return NULL; 687 return NULL;
685} 688}
686#endif 689#endif
687 690
688int 691int
689encap_detach(const struct encaptab *cookie) 692encap_detach(const struct encaptab *cookie)
690{ 693{
691 const struct encaptab *ep = cookie; 694 const struct encaptab *ep = cookie;
692 struct encaptab *p, *np; 695 struct encaptab *p, *np;
693 int error; 696 int error;

cvs diff -r1.13 -r1.14 src/sys/netinet/ip_encap.h (expand / switch to unified diff)

--- src/sys/netinet/ip_encap.h 2008/11/25 18:28:05 1.13
+++ src/sys/netinet/ip_encap.h 2016/01/22 05:15:10 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_encap.h,v 1.13 2008/11/25 18:28:05 pooka Exp $ */ 1/* $NetBSD: ip_encap.h,v 1.14 2016/01/22 05:15:10 riastradh Exp $ */
2/* $KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $ */ 2/* $KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -29,62 +29,67 @@ @@ -29,62 +29,67 @@
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#ifndef _NETINET_IP_ENCAP_H_ 33#ifndef _NETINET_IP_ENCAP_H_
34#define _NETINET_IP_ENCAP_H_ 34#define _NETINET_IP_ENCAP_H_
35 35
36#ifdef _KERNEL 36#ifdef _KERNEL
37 37
38#ifndef RNF_NORMAL 38#ifndef RNF_NORMAL
39#include <net/radix.h> 39#include <net/radix.h>
40#endif 40#endif
41 41
 42struct encapsw {
 43 void (*en_input)(struct mbuf *, ...);
 44 void *(*en_ctlinput)(int, const struct sockaddr *, void *);
 45};
 46
42struct encaptab { 47struct encaptab {
43 struct radix_node nodes[2]; 48 struct radix_node nodes[2];
44 LIST_ENTRY(encaptab) chain; 49 LIST_ENTRY(encaptab) chain;
45 int af; 50 int af;
46 int proto; /* -1: don't care, I'll check myself */ 51 int proto; /* -1: don't care, I'll check myself */
47 struct sockaddr *addrpack; /* malloc'ed, for radix lookup */ 52 struct sockaddr *addrpack; /* malloc'ed, for radix lookup */
48 struct sockaddr *maskpack; /* ditto */ 53 struct sockaddr *maskpack; /* ditto */
49 struct sockaddr *src; /* my addr */ 54 struct sockaddr *src; /* my addr */
50 struct sockaddr *srcmask; 55 struct sockaddr *srcmask;
51 struct sockaddr *dst; /* remote addr */ 56 struct sockaddr *dst; /* remote addr */
52 struct sockaddr *dstmask; 57 struct sockaddr *dstmask;
53 int (*func) (struct mbuf *, int, int, void *); 58 int (*func) (struct mbuf *, int, int, void *);
54 const struct protosw *psw; /* only pr_input will be used */ 59 const struct encapsw *esw;
55 void *arg; /* passed via PACKET_TAG_ENCAP */ 60 void *arg; /* passed via PACKET_TAG_ENCAP */
56}; 61};
57 62
58/* to lookup a pair of address using radix tree */ 63/* to lookup a pair of address using radix tree */
59struct sockaddr_pack { 64struct sockaddr_pack {
60 u_int8_t sp_len; 65 u_int8_t sp_len;
61 u_int8_t sp_family; /* not really used */ 66 u_int8_t sp_family; /* not really used */
62 /* followed by variable-length data */ 67 /* followed by variable-length data */
63}; 68};
64 69
65struct ip_pack4 { 70struct ip_pack4 {
66 struct sockaddr_pack p; 71 struct sockaddr_pack p;
67 struct sockaddr_in mine; 72 struct sockaddr_in mine;
68 struct sockaddr_in yours; 73 struct sockaddr_in yours;
69}; 74};
70struct ip_pack6 { 75struct ip_pack6 {
71 struct sockaddr_pack p; 76 struct sockaddr_pack p;
72 struct sockaddr_in6 mine; 77 struct sockaddr_in6 mine;
73 struct sockaddr_in6 yours; 78 struct sockaddr_in6 yours;
74}; 79};
75 80
76void encap_init(void); 81void encap_init(void);
77void encap4_input(struct mbuf *, ...); 82void encap4_input(struct mbuf *, ...);
78int encap6_input(struct mbuf **, int *, int); 83int encap6_input(struct mbuf **, int *, int);
79const struct encaptab *encap_attach(int, int, const struct sockaddr *, 84const struct encaptab *encap_attach(int, int, const struct sockaddr *,
80 const struct sockaddr *, const struct sockaddr *, 85 const struct sockaddr *, const struct sockaddr *,
81 const struct sockaddr *, const struct protosw *, void *); 86 const struct sockaddr *, const struct encapsw *, void *);
82const struct encaptab *encap_attach_func(int, int, 87const struct encaptab *encap_attach_func(int, int,
83 int (*)(struct mbuf *, int, int, void *), 88 int (*)(struct mbuf *, int, int, void *),
84 const struct protosw *, void *); 89 const struct encapsw *, void *);
85void *encap6_ctlinput(int, const struct sockaddr *, void *); 90void *encap6_ctlinput(int, const struct sockaddr *, void *);
86int encap_detach(const struct encaptab *); 91int encap_detach(const struct encaptab *);
87void *encap_getarg(struct mbuf *); 92void *encap_getarg(struct mbuf *);
88#endif 93#endif
89 94
90#endif /* !_NETINET_IP_ENCAP_H_ */ 95#endif /* !_NETINET_IP_ENCAP_H_ */

cvs diff -r1.134 -r1.135 src/sys/netinet/ip_mroute.c (expand / switch to unified diff)

--- src/sys/netinet/ip_mroute.c 2016/01/20 21:43:59 1.134
+++ src/sys/netinet/ip_mroute.c 2016/01/22 05:15:10 1.135
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_mroute.c,v 1.134 2016/01/20 21:43:59 riastradh Exp $ */ 1/* $NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Stephen Deering of Stanford University. 8 * Stephen Deering of Stanford University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -83,27 +83,27 @@ @@ -83,27 +83,27 @@
83 * Modified by Charles M. Hannum, NetBSD, May 1995. 83 * Modified by Charles M. Hannum, NetBSD, May 1995.
84 * Modified by Ahmed Helmy, SGI, June 1996 84 * Modified by Ahmed Helmy, SGI, June 1996
85 * Modified by George Edmond Eddy (Rusty), ISI, February 1998 85 * Modified by George Edmond Eddy (Rusty), ISI, February 1998
86 * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000 86 * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000
87 * Modified by Hitoshi Asaeda, WIDE, August 2000 87 * Modified by Hitoshi Asaeda, WIDE, August 2000
88 * Modified by Pavlin Radoslavov, ICSI, October 2002 88 * Modified by Pavlin Radoslavov, ICSI, October 2002
89 * 89 *
90 * MROUTING Revision: 1.2 90 * MROUTING Revision: 1.2
91 * and PIM-SMv2 and PIM-DM support, advanced API support, 91 * and PIM-SMv2 and PIM-DM support, advanced API support,
92 * bandwidth metering and signaling 92 * bandwidth metering and signaling
93 */ 93 */
94 94
95#include <sys/cdefs.h> 95#include <sys/cdefs.h>
96__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.134 2016/01/20 21:43:59 riastradh Exp $"); 96__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $");
97 97
98#ifdef _KERNEL_OPT 98#ifdef _KERNEL_OPT
99#include "opt_inet.h" 99#include "opt_inet.h"
100#include "opt_ipsec.h" 100#include "opt_ipsec.h"
101#include "opt_pim.h" 101#include "opt_pim.h"
102#endif 102#endif
103 103
104#ifdef PIM 104#ifdef PIM
105#define _PIM_VT 1 105#define _PIM_VT 1
106#endif 106#endif
107 107
108#include <sys/param.h> 108#include <sys/param.h>
109#include <sys/systm.h> 109#include <sys/systm.h>
@@ -183,34 +183,29 @@ u_int tbfdebug = 0; /* tbf de @@ -183,34 +183,29 @@ u_int tbfdebug = 0; /* tbf de
183#ifdef RSVP_ISI 183#ifdef RSVP_ISI
184u_int rsvpdebug = 0; /* rsvp debug level */ 184u_int rsvpdebug = 0; /* rsvp debug level */
185#define RSVP_DPRINTF(a) do if (rsvpdebug) printf a; while (/*CONSTCOND*/0) 185#define RSVP_DPRINTF(a) do if (rsvpdebug) printf a; while (/*CONSTCOND*/0)
186extern struct socket *ip_rsvpd; 186extern struct socket *ip_rsvpd;
187extern int rsvp_on; 187extern int rsvp_on;
188#else 188#else
189#define RSVP_DPRINTF(a) do {} while (/*CONSTCOND*/0) 189#define RSVP_DPRINTF(a) do {} while (/*CONSTCOND*/0)
190#endif /* RSVP_ISI */ 190#endif /* RSVP_ISI */
191 191
192/* vif attachment using sys/netinet/ip_encap.c */ 192/* vif attachment using sys/netinet/ip_encap.c */
193static void vif_input(struct mbuf *, ...); 193static void vif_input(struct mbuf *, ...);
194static int vif_encapcheck(struct mbuf *, int, int, void *); 194static int vif_encapcheck(struct mbuf *, int, int, void *);
195 195
196static const struct protosw vif_protosw = { 196static const struct encapsw vif_encapsw = {
197 .pr_type = SOCK_RAW, 197 .en_input = vif_input,
198 .pr_domain = &inetdomain, 198 .en_ctlinput = NULL,
199 .pr_protocol = IPPROTO_IPV4, 
200 .pr_flags = PR_ATOMIC|PR_ADDR, 
201 .pr_input = vif_input, 
202 .pr_ctloutput = rip_ctloutput, 
203 .pr_usrreqs = &rip_usrreqs, 
204}; 199};
205 200
206#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */ 201#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
207#define UPCALL_EXPIRE 6 /* number of timeouts */ 202#define UPCALL_EXPIRE 6 /* number of timeouts */
208 203
209/* 204/*
210 * Define the token bucket filter structures 205 * Define the token bucket filter structures
211 */ 206 */
212 207
213#define TBF_REPROCESS (hz / 100) /* 100x / second */ 208#define TBF_REPROCESS (hz / 100) /* 100x / second */
214 209
215static int get_sg_cnt(struct sioc_sg_req *); 210static int get_sg_cnt(struct sioc_sg_req *);
216static int get_vif_cnt(struct sioc_vif_req *); 211static int get_vif_cnt(struct sioc_vif_req *);
@@ -827,27 +822,27 @@ add_vif(struct vifctl *vifcp) @@ -827,27 +822,27 @@ add_vif(struct vifctl *vifcp)
827 log(LOG_ERR, "source routed tunnels not supported\n"); 822 log(LOG_ERR, "source routed tunnels not supported\n");
828 return (EOPNOTSUPP); 823 return (EOPNOTSUPP);
829 } 824 }
830 825
831 /* attach this vif to decapsulator dispatch table */ 826 /* attach this vif to decapsulator dispatch table */
832 /* 827 /*
833 * XXX Use addresses in registration so that matching 828 * XXX Use addresses in registration so that matching
834 * can be done with radix tree in decapsulator. But, 829 * can be done with radix tree in decapsulator. But,
835 * we need to check inner header for multicast, so 830 * we need to check inner header for multicast, so
836 * this requires both radix tree lookup and then a 831 * this requires both radix tree lookup and then a
837 * function to check, and this is not supported yet. 832 * function to check, and this is not supported yet.
838 */ 833 */
839 vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4, 834 vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
840 vif_encapcheck, &vif_protosw, vifp); 835 vif_encapcheck, &vif_encapsw, vifp);
841 if (!vifp->v_encap_cookie) 836 if (!vifp->v_encap_cookie)
842 return (EINVAL); 837 return (EINVAL);
843 838
844 /* Create a fake encapsulation interface. */ 839 /* Create a fake encapsulation interface. */
845 ifp = malloc(sizeof(*ifp), M_MRTABLE, M_WAITOK|M_ZERO); 840 ifp = malloc(sizeof(*ifp), M_MRTABLE, M_WAITOK|M_ZERO);
846 snprintf(ifp->if_xname, sizeof(ifp->if_xname), 841 snprintf(ifp->if_xname, sizeof(ifp->if_xname),
847 "mdecap%d", vifcp->vifc_vifi); 842 "mdecap%d", vifcp->vifc_vifi);
848 843
849 /* Prepare cached route entry. */ 844 /* Prepare cached route entry. */
850 memset(&vifp->v_route, 0, sizeof(vifp->v_route)); 845 memset(&vifp->v_route, 0, sizeof(vifp->v_route));
851#ifdef PIM 846#ifdef PIM
852 } else if (vifcp->vifc_flags & VIFF_REGISTER) { 847 } else if (vifcp->vifc_flags & VIFF_REGISTER) {
853 ifp = &multicast_register_if; 848 ifp = &multicast_register_if;

cvs diff -r1.66 -r1.67 src/sys/netinet6/in6_gif.c (expand / switch to unified diff)

--- src/sys/netinet6/in6_gif.c 2016/01/20 21:44:00 1.66
+++ src/sys/netinet6/in6_gif.c 2016/01/22 05:15:10 1.67
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6_gif.c,v 1.66 2016/01/20 21:44:00 riastradh Exp $ */ 1/* $NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $ */
2/* $KAME: in6_gif.c,v 1.62 2001/07/29 04:27:25 itojun Exp $ */ 2/* $KAME: in6_gif.c,v 1.62 2001/07/29 04:27:25 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -21,75 +21,74 @@ @@ -21,75 +21,74 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.66 2016/01/20 21:44:00 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $");
35 35
36#ifdef _KERNEL_OPT 36#ifdef _KERNEL_OPT
37#include "opt_inet.h" 37#include "opt_inet.h"
38#endif 38#endif
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/socket.h> 42#include <sys/socket.h>
43#include <sys/sockio.h> 43#include <sys/sockio.h>
44#include <sys/mbuf.h> 44#include <sys/mbuf.h>
45#include <sys/errno.h> 45#include <sys/errno.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
47#include <sys/queue.h> 47#include <sys/queue.h>
48#include <sys/syslog.h> 48#include <sys/syslog.h>
49#include <sys/protosw.h> 
50#include <sys/kernel.h> 49#include <sys/kernel.h>
51 50
52#include <net/if.h> 51#include <net/if.h>
53#include <net/route.h> 52#include <net/route.h>
54 53
55#include <netinet/in.h> 54#include <netinet/in.h>
56#include <netinet/in_systm.h> 55#include <netinet/in_systm.h>
57#ifdef INET 56#ifdef INET
58#include <netinet/ip.h> 57#include <netinet/ip.h>
59#endif 58#endif
60#include <netinet/ip_encap.h> 59#include <netinet/ip_encap.h>
61#ifdef INET6 60#ifdef INET6
62#include <netinet/ip6.h> 61#include <netinet/ip6.h>
63#include <netinet6/ip6_var.h> 62#include <netinet6/ip6_var.h>
64#include <netinet6/ip6_private.h> 63#include <netinet6/ip6_private.h>
65#include <netinet6/in6_gif.h> 64#include <netinet6/in6_gif.h>
66#include <netinet6/in6_var.h> 65#include <netinet6/in6_var.h>
67#endif 
68#include <netinet6/ip6protosw.h> 66#include <netinet6/ip6protosw.h>
 67#endif
69#include <netinet/ip_ecn.h> 68#include <netinet/ip_ecn.h>
70 69
71#include <net/if_gif.h> 70#include <net/if_gif.h>
72 71
73#include <net/net_osdep.h> 72#include <net/net_osdep.h>
74 73
75static int gif_validate6(const struct ip6_hdr *, struct gif_softc *, 74static int gif_validate6(const struct ip6_hdr *, struct gif_softc *,
76 struct ifnet *); 75 struct ifnet *);
77 76
78int ip6_gif_hlim = GIF_HLIM; 77int ip6_gif_hlim = GIF_HLIM;
79 78
80extern LIST_HEAD(, gif_softc) gif_softc_list; 79extern LIST_HEAD(, gif_softc) gif_softc_list;
81 80
82static const struct ip6protosw in6_gif_protosw; 81static const struct encapsw in6_gif_encapsw;
83 82
84/*  83/*
85 * family - family of the packet to be encapsulate.  84 * family - family of the packet to be encapsulate.
86 */ 85 */
87 86
88int 87int
89in6_gif_output(struct ifnet *ifp, int family, struct mbuf *m) 88in6_gif_output(struct ifnet *ifp, int family, struct mbuf *m)
90{ 89{
91 struct rtentry *rt; 90 struct rtentry *rt;
92 struct gif_softc *sc = ifp->if_softc; 91 struct gif_softc *sc = ifp->if_softc;
93 struct sockaddr_in6 *sin6_src = satosin6(sc->gif_psrc); 92 struct sockaddr_in6 *sin6_src = satosin6(sc->gif_psrc);
94 struct sockaddr_in6 *sin6_dst = satosin6(sc->gif_pdst); 93 struct sockaddr_in6 *sin6_dst = satosin6(sc->gif_pdst);
95 struct ip6_hdr *ip6; 94 struct ip6_hdr *ip6;
@@ -364,30 +363,30 @@ in6_gif_attach(struct gif_softc *sc) @@ -364,30 +363,30 @@ in6_gif_attach(struct gif_softc *sc)
364{ 363{
365#ifndef GIF_ENCAPCHECK 364#ifndef GIF_ENCAPCHECK
366 struct sockaddr_in6 mask6; 365 struct sockaddr_in6 mask6;
367 366
368 memset(&mask6, 0, sizeof(mask6)); 367 memset(&mask6, 0, sizeof(mask6));
369 mask6.sin6_len = sizeof(struct sockaddr_in6); 368 mask6.sin6_len = sizeof(struct sockaddr_in6);
370 mask6.sin6_addr.s6_addr32[0] = mask6.sin6_addr.s6_addr32[1] = 369 mask6.sin6_addr.s6_addr32[0] = mask6.sin6_addr.s6_addr32[1] =
371 mask6.sin6_addr.s6_addr32[2] = mask6.sin6_addr.s6_addr32[3] = ~0; 370 mask6.sin6_addr.s6_addr32[2] = mask6.sin6_addr.s6_addr32[3] = ~0;
372 371
373 if (!sc->gif_psrc || !sc->gif_pdst) 372 if (!sc->gif_psrc || !sc->gif_pdst)
374 return EINVAL; 373 return EINVAL;
375 sc->encap_cookie6 = encap_attach(AF_INET6, -1, sc->gif_psrc, 374 sc->encap_cookie6 = encap_attach(AF_INET6, -1, sc->gif_psrc,
376 (struct sockaddr *)&mask6, sc->gif_pdst, (struct sockaddr *)&mask6, 375 (struct sockaddr *)&mask6, sc->gif_pdst, (struct sockaddr *)&mask6,
377 (const void *)&in6_gif_protosw, sc); 376 &in6_gif_encapsw, sc);
378#else 377#else
379 sc->encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck, 378 sc->encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck,
380 (struct protosw *)&in6_gif_protosw, sc); 379 &in6_gif_encapsw, sc);
381#endif 380#endif
382 if (sc->encap_cookie6 == NULL) 381 if (sc->encap_cookie6 == NULL)
383 return EEXIST; 382 return EEXIST;
384 return 0; 383 return 0;
385} 384}
386 385
387int 386int
388in6_gif_detach(struct gif_softc *sc) 387in6_gif_detach(struct gif_softc *sc)
389{ 388{
390 int error; 389 int error;
391 390
392 error = encap_detach(sc->encap_cookie6); 391 error = encap_detach(sc->encap_cookie6);
393 if (error == 0) 392 if (error == 0)
@@ -441,30 +440,20 @@ in6_gif_ctlinput(int cmd, const struct s @@ -441,30 +440,20 @@ in6_gif_ctlinput(int cmd, const struct s
441 440
442 dst6 = satocsin6(rtcache_getdst(&sc->gif_ro)); 441 dst6 = satocsin6(rtcache_getdst(&sc->gif_ro));
443 /* XXX scope */ 442 /* XXX scope */
444 if (dst6 == NULL) 443 if (dst6 == NULL)
445 ; 444 ;
446 else if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst6->sin6_addr)) 445 else if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst6->sin6_addr))
447 rtcache_free(&sc->gif_ro); 446 rtcache_free(&sc->gif_ro);
448 } 447 }
449 448
450 return NULL; 449 return NULL;
451} 450}
452 451
453PR_WRAP_CTLINPUT(in6_gif_ctlinput) 452PR_WRAP_CTLINPUT(in6_gif_ctlinput)
454PR_WRAP_CTLOUTPUT(rip6_ctloutput) 
455 453
456#define in6_gif_ctlinput in6_gif_ctlinput_wrapper 454#define in6_gif_ctlinput in6_gif_ctlinput_wrapper
457#define rip6_ctloutput rip6_ctloutput_wrapper 
458 
459extern struct domain inet6domain; 
460 455
461static const struct ip6protosw in6_gif_protosw = { 456static const struct encapsw in6_gif_encapsw = {
462 .pr_type = SOCK_RAW, 457 .en_input = (void (*)(struct mbuf *, ...))in6_gif_input,
463 .pr_domain = &inet6domain, 458 .en_ctlinput = in6_gif_ctlinput,
464 .pr_protocol = 0 /* IPPROTO_IPV[46] */, 
465 .pr_flags = PR_ATOMIC | PR_ADDR, 
466 .pr_input = in6_gif_input, 
467 .pr_ctlinput = in6_gif_ctlinput, 
468 .pr_ctloutput = rip6_ctloutput, 
469 .pr_usrreqs = &rip6_usrreqs, 
470}; 459};

cvs diff -r1.33 -r1.34 src/sys/netipsec/xform_ipip.c (expand / switch to unified diff)

--- src/sys/netipsec/xform_ipip.c 2016/01/20 21:44:00 1.33
+++ src/sys/netipsec/xform_ipip.c 2016/01/22 05:15:10 1.34
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xform_ipip.c,v 1.33 2016/01/20 21:44:00 riastradh Exp $ */ 1/* $NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Exp $ */
2/* $FreeBSD: src/sys/netipsec/xform_ipip.c,v 1.3.2.1 2003/01/24 05:11:36 sam Exp $ */ 2/* $FreeBSD: src/sys/netipsec/xform_ipip.c,v 1.3.2.1 2003/01/24 05:11:36 sam Exp $ */
3/* $OpenBSD: ip_ipip.c,v 1.25 2002/06/10 18:04:55 itojun Exp $ */ 3/* $OpenBSD: ip_ipip.c,v 1.25 2002/06/10 18:04:55 itojun Exp $ */
4 4
5/* 5/*
6 * The authors of this code are John Ioannidis (ji@tla.org), 6 * The authors of this code are John Ioannidis (ji@tla.org),
7 * Angelos D. Keromytis (kermit@csd.uch.gr) and 7 * Angelos D. Keromytis (kermit@csd.uch.gr) and
8 * Niels Provos (provos@physnet.uni-hamburg.de). 8 * Niels Provos (provos@physnet.uni-hamburg.de).
9 * 9 *
10 * The original version of this code was written by John Ioannidis 10 * The original version of this code was written by John Ioannidis
11 * for BSD/OS in Athens, Greece, in November 1995. 11 * for BSD/OS in Athens, Greece, in November 1995.
12 * 12 *
13 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, 13 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
14 * by Angelos D. Keromytis. 14 * by Angelos D. Keromytis.
@@ -29,79 +29,74 @@ @@ -29,79 +29,74 @@
29 * You may use this code under the GNU public license if you so wish. Please 29 * You may use this code under the GNU public license if you so wish. Please
30 * contribute changes back to the authors under this freer than GPL license 30 * contribute changes back to the authors under this freer than GPL license
31 * so that we may further the use of strong encryption without limitations to 31 * so that we may further the use of strong encryption without limitations to
32 * all. 32 * all.
33 * 33 *
34 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 34 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
35 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY 35 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
36 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 36 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
37 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 37 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
38 * PURPOSE. 38 * PURPOSE.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.33 2016/01/20 21:44:00 riastradh Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Exp $");
43 43
44/* 44/*
45 * IP-inside-IP processing 45 * IP-inside-IP processing
46 */ 46 */
47#include "opt_inet.h" 47#include "opt_inet.h"
48#ifdef __FreeBSD__ 48#ifdef __FreeBSD__
49#include "opt_inet6.h" 49#include "opt_inet6.h"
50#include "opt_random_ip_id.h" 50#include "opt_random_ip_id.h"
51#endif /* __FreeBSD__ */ 51#endif /* __FreeBSD__ */
52 52
53 53
54#include <sys/param.h> 54#include <sys/param.h>
55#include <sys/systm.h> 55#include <sys/systm.h>
56#include <sys/mbuf.h> 56#include <sys/mbuf.h>
57#include <sys/socket.h> 57#include <sys/socket.h>
58#include <sys/kernel.h> 58#include <sys/kernel.h>
59#include <sys/protosw.h> 
60#include <sys/sysctl.h> 59#include <sys/sysctl.h>
61 60
62#include <net/if.h> 61#include <net/if.h>
63#include <net/route.h> 62#include <net/route.h>
64#include <net/netisr.h> 63#include <net/netisr.h>
65 64
66#include <netinet/in.h> 65#include <netinet/in.h>
67#include <netinet/in_systm.h> 66#include <netinet/in_systm.h>
68#include <netinet/in_var.h> 67#include <netinet/in_var.h>
69#include <netinet/ip.h> 68#include <netinet/ip.h>
70#include <netinet/ip_ecn.h> 69#include <netinet/ip_ecn.h>
71#include <netinet/ip_var.h> 70#include <netinet/ip_var.h>
72#include <netinet/ip_encap.h> 71#include <netinet/ip_encap.h>
73#ifdef __FreeBSD__ 
74#include <netinet/ipprotosw.h> 
75#endif 
76 72
77#include <netipsec/ipsec.h> 73#include <netipsec/ipsec.h>
78#include <netipsec/ipsec_private.h> 74#include <netipsec/ipsec_private.h>
79#include <netipsec/xform.h> 75#include <netipsec/xform.h>
80 76
81#include <netipsec/ipip_var.h> 77#include <netipsec/ipip_var.h>
82 78
83#ifdef MROUTING 79#ifdef MROUTING
84#include <netinet/ip_mroute.h> 80#include <netinet/ip_mroute.h>
85#endif 81#endif
86 82
87#ifdef INET6 83#ifdef INET6
88#include <netinet/ip6.h> 84#include <netinet/ip6.h>
89#include <netipsec/ipsec6.h> 85#include <netipsec/ipsec6.h>
90# ifdef __FreeBSD__ 86# ifdef __FreeBSD__
91# include <netinet6/ip6_ecn.h> 87# include <netinet6/ip6_ecn.h>
92# endif 88# endif
93#include <netinet6/in6_var.h> 89#include <netinet6/in6_var.h>
94#include <netinet6/ip6protosw.h> 
95#endif 90#endif
96 91
97#include <netipsec/key.h> 92#include <netipsec/key.h>
98#include <netipsec/key_debug.h> 93#include <netipsec/key_debug.h>
99#include <netipsec/ipsec_osdep.h> 94#include <netipsec/ipsec_osdep.h>
100 95
101#ifdef __FreeBSD__ 96#ifdef __FreeBSD__
102typedef void pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */ 97typedef void pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */
103#else 98#else
104typedef void pr_in_input_t (struct mbuf *m, ...); 99typedef void pr_in_input_t (struct mbuf *m, ...);
105#endif 100#endif
106 101
107/* 102/*
@@ -672,63 +667,35 @@ ipe4_input( @@ -672,63 +667,35 @@ ipe4_input(
672 printf("ipe4_input: should never be called\n"); 667 printf("ipe4_input: should never be called\n");
673 if (m) 668 if (m)
674 m_freem(m); 669 m_freem(m);
675 return EOPNOTSUPP; 670 return EOPNOTSUPP;
676} 671}
677 672
678static struct xformsw ipe4_xformsw = { 673static struct xformsw ipe4_xformsw = {
679 XF_IP4, 0, "IPv4 Simple Encapsulation", 674 XF_IP4, 0, "IPv4 Simple Encapsulation",
680 ipe4_init, ipe4_zeroize, ipe4_input, ipip_output, 675 ipe4_init, ipe4_zeroize, ipe4_input, ipip_output,
681 NULL, 676 NULL,
682}; 677};
683 678
684#ifdef INET 679#ifdef INET
685PR_WRAP_CTLOUTPUT(rip_ctloutput) 680static const struct encapsw ipe4_encapsw = {
686#define rip_ctloutput rip_ctloutput_wrapper 681 .en_input = ip4_input,
687 682 .en_ctlinput = NULL,
688extern struct domain inetdomain; 
689static struct ipprotosw ipe4_protosw = { 
690 .pr_type = SOCK_RAW, 
691 .pr_domain = &inetdomain, 
692 .pr_protocol = IPPROTO_IPV4, 
693 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR, 
694 .pr_input = ip4_input, 
695 .pr_ctlinput = 0, 
696 .pr_ctloutput = rip_ctloutput, 
697 .pr_usrreqs = &rip_usrreqs, 
698 .pr_init = 0, 
699 .pr_fasttimo = 0, 
700 .pr_slowtimo = 0, 
701 .pr_drain = 0, 
702}; 683};
703#endif 684#endif
704#ifdef INET6 685#ifdef INET6
705PR_WRAP_CTLOUTPUT(rip6_ctloutput) 686static const struct encapsw ipe4_encapsw6 = {
706#define rip6_ctloutput rip6_ctloutput_wrapper 687 .en_input = (void (*)(struct mbuf *, ...))ip4_input6,
707 688 .en_ctlinput = NULL,
708extern struct domain inet6domain; 
709static struct ip6protosw ipe4_protosw6 = { 
710 .pr_type = SOCK_RAW, 
711 .pr_domain = &inet6domain, 
712 .pr_protocol = IPPROTO_IPV6, 
713 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR, 
714 .pr_input = ip4_input6, 
715 .pr_ctlinput = 0, 
716 .pr_ctloutput = rip6_ctloutput, 
717 .pr_usrreqs = &rip6_usrreqs, 
718 .pr_init = 0, 
719 .pr_fasttimo = 0, 
720 .pr_slowtimo = 0, 
721 .pr_drain = 0, 
722}; 689};
723#endif 690#endif
724 691
725/* 692/*
726 * Check the encapsulated packet to see if we want it 693 * Check the encapsulated packet to see if we want it
727 */ 694 */
728static int 695static int
729ipe4_encapcheck(struct mbuf *m, 696ipe4_encapcheck(struct mbuf *m,
730 int off, 697 int off,
731 int proto, 698 int proto,
732 void *arg 699 void *arg
733) 700)
734{ 701{
@@ -742,25 +709,25 @@ ipe4_encapcheck(struct mbuf *m, @@ -742,25 +709,25 @@ ipe4_encapcheck(struct mbuf *m,
742} 709}
743 710
744INITFN void 711INITFN void
745ipe4_attach(void) 712ipe4_attach(void)
746{ 713{
747 714
748 ipipstat_percpu = percpu_alloc(sizeof(uint64_t) * IPIP_NSTATS); 715 ipipstat_percpu = percpu_alloc(sizeof(uint64_t) * IPIP_NSTATS);
749 716
750 xform_register(&ipe4_xformsw); 717 xform_register(&ipe4_xformsw);
751 /* attach to encapsulation framework */ 718 /* attach to encapsulation framework */
752 /* XXX save return cookie for detach on module remove */ 719 /* XXX save return cookie for detach on module remove */
753#ifdef INET 720#ifdef INET
754 (void) encap_attach_func(AF_INET, -1, 721 (void) encap_attach_func(AF_INET, -1,
755 ipe4_encapcheck, (struct protosw*) &ipe4_protosw, NULL); 722 ipe4_encapcheck, &ipe4_encapsw, NULL);
756#endif 723#endif
757#ifdef INET6 724#ifdef INET6
758 (void) encap_attach_func(AF_INET6, -1, 725 (void) encap_attach_func(AF_INET6, -1,
759 ipe4_encapcheck, (struct protosw*) &ipe4_protosw6, NULL); 726 ipe4_encapcheck, &ipe4_encapsw6, NULL);
760#endif 727#endif
761} 728}
762 729
763#ifdef SYSINIT 730#ifdef SYSINIT
764SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL); 731SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL);
765#endif 732#endif
766 733