Fri Jan 22 23:27:12 2016 UTC ()
Back out previous change to introduce struct encapsw.

This change was intended, but Nakahara-san had already made a better
one locally!  So I'll let him commit that one, and I'll try not to
step on anyone's toes again.


(riastradh)
diff -r1.84 -r1.85 src/sys/net/if_stf.c
diff -r1.70 -r1.71 src/sys/netinet/in_gif.c
diff -r1.49 -r1.50 src/sys/netinet/ip_encap.c
diff -r1.14 -r1.15 src/sys/netinet/ip_encap.h
diff -r1.135 -r1.136 src/sys/netinet/ip_mroute.c
diff -r1.67 -r1.68 src/sys/netinet6/in6_gif.c
diff -r1.34 -r1.35 src/sys/netipsec/xform_ipip.c

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

--- src/sys/net/if_stf.c 2016/01/22 05:15:10 1.84
+++ src/sys/net/if_stf.c 2016/01/22 23:27:12 1.85
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_stf.c,v 1.84 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: if_stf.c,v 1.85 2016/01/22 23:27:12 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,44 +65,45 @@ @@ -65,44 +65,45 @@
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.84 2016/01/22 05:15:10 riastradh Exp $"); 78__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.85 2016/01/22 23:27:12 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>
96#include <sys/queue.h> 97#include <sys/queue.h>
97#include <sys/syslog.h> 98#include <sys/syslog.h>
98 99
99#include <sys/cpu.h> 100#include <sys/cpu.h>
100 101
101#include <net/if.h> 102#include <net/if.h>
102#include <net/route.h> 103#include <net/route.h>
103#include <net/netisr.h> 104#include <net/netisr.h>
104#include <net/if_types.h> 105#include <net/if_types.h>
105#include <net/if_stf.h> 106#include <net/if_stf.h>
106 107
107#include <netinet/in.h> 108#include <netinet/in.h>
108#include <netinet/in_systm.h> 109#include <netinet/in_systm.h>
@@ -145,29 +146,38 @@ static LIST_HEAD(, stf_softc) stf_softc_ @@ -145,29 +146,38 @@ static LIST_HEAD(, stf_softc) stf_softc_
145 146
146static int stf_clone_create(struct if_clone *, int); 147static int stf_clone_create(struct if_clone *, int);
147static int stf_clone_destroy(struct ifnet *); 148static int stf_clone_destroy(struct ifnet *);
148 149
149struct if_clone stf_cloner = 150struct if_clone stf_cloner =
150 IF_CLONE_INITIALIZER("stf", stf_clone_create, stf_clone_destroy); 151 IF_CLONE_INITIALIZER("stf", stf_clone_create, stf_clone_destroy);
151 152
152#if NGIF > 0 153#if NGIF > 0
153extern int ip_gif_ttl; /*XXX*/ 154extern int ip_gif_ttl; /*XXX*/
154#else 155#else
155static int ip_gif_ttl = 40; /*XXX*/ 156static int ip_gif_ttl = 40; /*XXX*/
156#endif 157#endif
157 158
158static const struct encapsw in_stf_encapsw = { 159extern struct domain inetdomain;
159 .en_input = in_stf_input, 160
160 .en_ctlinput = NULL, 161static const struct protosw in_stf_protosw =
 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,
161}; 171};
162 172
163static int stf_encapcheck(struct mbuf *, int, int, void *); 173static int stf_encapcheck(struct mbuf *, int, int, void *);
164static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *); 174static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *);
165static int stf_output(struct ifnet *, struct mbuf *, const struct sockaddr *, 175static int stf_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
166 struct rtentry *); 176 struct rtentry *);
167static int isrfc1918addr(const struct in_addr *); 177static int isrfc1918addr(const struct in_addr *);
168static int stf_checkaddr4(struct stf_softc *, const struct in_addr *, 178static int stf_checkaddr4(struct stf_softc *, const struct in_addr *,
169 struct ifnet *); 179 struct ifnet *);
170static int stf_checkaddr6(struct stf_softc *, const struct in6_addr *, 180static int stf_checkaddr6(struct stf_softc *, const struct in6_addr *,
171 struct ifnet *); 181 struct ifnet *);
172static void stf_rtrequest(int, struct rtentry *, const struct rt_addrinfo *); 182static void stf_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
173static int stf_ioctl(struct ifnet *, u_long, void *); 183static int stf_ioctl(struct ifnet *, u_long, void *);
@@ -186,27 +196,27 @@ stf_clone_create(struct if_clone *ifc, i @@ -186,27 +196,27 @@ stf_clone_create(struct if_clone *ifc, i
186{ 196{
187 struct stf_softc *sc; 197 struct stf_softc *sc;
188 198
189 if (LIST_FIRST(&stf_softc_list) != NULL) { 199 if (LIST_FIRST(&stf_softc_list) != NULL) {
190 /* Only one stf interface is allowed. */ 200 /* Only one stf interface is allowed. */
191 return (EEXIST); 201 return (EEXIST);
192 } 202 }
193 203
194 sc = malloc(sizeof(struct stf_softc), M_DEVBUF, M_WAIT|M_ZERO); 204 sc = malloc(sizeof(struct stf_softc), M_DEVBUF, M_WAIT|M_ZERO);
195 205
196 if_initname(&sc->sc_if, ifc->ifc_name, unit); 206 if_initname(&sc->sc_if, ifc->ifc_name, unit);
197 207
198 sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6, 208 sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
199 stf_encapcheck, &in_stf_encapsw, sc); 209 stf_encapcheck, &in_stf_protosw, sc);
200 if (sc->encap_cookie == NULL) { 210 if (sc->encap_cookie == NULL) {
201 printf("%s: unable to attach encap\n", if_name(&sc->sc_if)); 211 printf("%s: unable to attach encap\n", if_name(&sc->sc_if));
202 free(sc, M_DEVBUF); 212 free(sc, M_DEVBUF);
203 return (EIO); /* XXX */ 213 return (EIO); /* XXX */
204 } 214 }
205 215
206 sc->sc_if.if_mtu = STF_MTU; 216 sc->sc_if.if_mtu = STF_MTU;
207 sc->sc_if.if_flags = 0; 217 sc->sc_if.if_flags = 0;
208 sc->sc_if.if_ioctl = stf_ioctl; 218 sc->sc_if.if_ioctl = stf_ioctl;
209 sc->sc_if.if_output = stf_output; 219 sc->sc_if.if_output = stf_output;
210 sc->sc_if.if_type = IFT_STF; 220 sc->sc_if.if_type = IFT_STF;
211 sc->sc_if.if_dlt = DLT_NULL; 221 sc->sc_if.if_dlt = DLT_NULL;
212 if_attach(&sc->sc_if); 222 if_attach(&sc->sc_if);

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

--- src/sys/netinet/in_gif.c 2016/01/22 05:15:10 1.70
+++ src/sys/netinet/in_gif.c 2016/01/22 23:27:12 1.71
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in_gif.c,v 1.70 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: in_gif.c,v 1.71 2016/01/22 23:27:12 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,40 +21,41 @@ @@ -21,40 +21,41 @@
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.70 2016/01/22 05:15:10 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.71 2016/01/22 23:27:12 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>
48#include <sys/kernel.h> 49#include <sys/kernel.h>
49 50
50#include <net/if.h> 51#include <net/if.h>
51#include <net/route.h> 52#include <net/route.h>
52 53
53#include <netinet/in.h> 54#include <netinet/in.h>
54#include <netinet/in_systm.h> 55#include <netinet/in_systm.h>
55#include <netinet/ip.h> 56#include <netinet/ip.h>
56#include <netinet/ip_var.h> 57#include <netinet/ip_var.h>
57#include <netinet/in_gif.h> 58#include <netinet/in_gif.h>
58#include <netinet/in_var.h> 59#include <netinet/in_var.h>
59#include <netinet/ip_encap.h> 60#include <netinet/ip_encap.h>
60#include <netinet/ip_ecn.h> 61#include <netinet/ip_ecn.h>
@@ -68,29 +69,35 @@ __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1 @@ -68,29 +69,35 @@ __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1
68#include "gif.h" 69#include "gif.h"
69 70
70#include <net/net_osdep.h> 71#include <net/net_osdep.h>
71 72
72static int gif_validate4(const struct ip *, struct gif_softc *, 73static int gif_validate4(const struct ip *, struct gif_softc *,
73 struct ifnet *); 74 struct ifnet *);
74 75
75#if NGIF > 0 76#if NGIF > 0
76int ip_gif_ttl = GIF_TTL; 77int ip_gif_ttl = GIF_TTL;
77#else 78#else
78int ip_gif_ttl = 0; 79int ip_gif_ttl = 0;
79#endif 80#endif
80 81
81static const struct encapsw in_gif_encapsw = { 82static const struct protosw in_gif_protosw = {
82 .en_input = in_gif_input, 83 .pr_type = SOCK_RAW,
83 .en_ctlinput = NULL, 84 .pr_domain = &inetdomain,
 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,
84}; 91};
85 92
86int 93int
87in_gif_output(struct ifnet *ifp, int family, struct mbuf *m) 94in_gif_output(struct ifnet *ifp, int family, struct mbuf *m)
88{ 95{
89 struct rtentry *rt; 96 struct rtentry *rt;
90 struct gif_softc *sc = ifp->if_softc; 97 struct gif_softc *sc = ifp->if_softc;
91 struct sockaddr_in *sin_src = satosin(sc->gif_psrc); 98 struct sockaddr_in *sin_src = satosin(sc->gif_psrc);
92 struct sockaddr_in *sin_dst = satosin(sc->gif_pdst); 99 struct sockaddr_in *sin_dst = satosin(sc->gif_pdst);
93 struct ip iphdr; /* capsule IP header, host byte ordered */ 100 struct ip iphdr; /* capsule IP header, host byte ordered */
94 int proto, error; 101 int proto, error;
95 u_int8_t tos; 102 u_int8_t tos;
96 union { 103 union {
@@ -364,36 +371,43 @@ int @@ -364,36 +371,43 @@ int
364in_gif_attach(struct gif_softc *sc) 371in_gif_attach(struct gif_softc *sc)
365{ 372{
366#ifndef GIF_ENCAPCHECK 373#ifndef GIF_ENCAPCHECK
367 struct sockaddr_in mask4; 374 struct sockaddr_in mask4;
368 375
369 memset(&mask4, 0, sizeof(mask4)); 376 memset(&mask4, 0, sizeof(mask4));
370 mask4.sin_len = sizeof(struct sockaddr_in); 377 mask4.sin_len = sizeof(struct sockaddr_in);
371 mask4.sin_addr.s_addr = ~0; 378 mask4.sin_addr.s_addr = ~0;
372 379
373 if (!sc->gif_psrc || !sc->gif_pdst) 380 if (!sc->gif_psrc || !sc->gif_pdst)
374 return EINVAL; 381 return EINVAL;
375 sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc, 382 sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc,
376 (struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4, 383 (struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4,
377 &in_gif_encapsw, sc); 384 (const struct protosw *)&in_gif_protosw, sc);
378#else 385#else
379 sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck, 386 sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
380 &in_gif_encapsw, sc); 387 &in_gif_protosw, sc);
381#endif 388#endif
382 if (sc->encap_cookie4 == NULL) 389 if (sc->encap_cookie4 == NULL)
383 return EEXIST; 390 return EEXIST;
384 return 0; 391 return 0;
385} 392}
386 393
387int 394int
388in_gif_detach(struct gif_softc *sc) 395in_gif_pause(struct gif_softc *sc)
389{ 396{
390 int error; 397 int error;
391 398
392 error = encap_detach(sc->encap_cookie4); 399 error = encap_detach(sc->encap_cookie4);
393 if (error == 0) 400 if (error == 0)
394 sc->encap_cookie4 = NULL; 401 sc->encap_cookie4 = NULL;
395 402
 403 return error;
 404}
 405
 406int
 407in_gif_detach(struct gif_softc *sc)
 408{
 409
396 rtcache_free(&sc->gif_ro); 410 rtcache_free(&sc->gif_ro);
397 411
398 return error; 412 return 0;
399} 413}

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

--- src/sys/netinet/ip_encap.c 2016/01/22 05:15:10 1.49
+++ src/sys/netinet/ip_encap.c 2016/01/22 23:27:12 1.50
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_encap.c,v 1.49 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: ip_encap.c,v 1.50 2016/01/22 23:27:12 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.49 2016/01/22 05:15:10 riastradh Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.50 2016/01/22 23:27:12 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 encapsw *esw; 243 const struct protosw *psw;
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 esw = match->esw; 255 psw = match->psw;
256 if (esw && esw->en_input) { 256 if (psw && psw->pr_input) {
257 encap_fillarg(m, match); 257 encap_fillarg(m, match);
258 (*esw->en_input)(m, off, proto); 258 (*psw->pr_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,40 +319,37 @@ encap6_lookup(struct mbuf *m, int off, i @@ -319,40 +319,37 @@ 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 encapsw *esw; 332 const struct ip6protosw *psw;
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 esw = match->esw; 339 psw = (const struct ip6protosw *)match->psw;
340 if (esw && esw->en_input) { 340 if (psw && psw->pr_input) {
341 /* XXX IPv6 cast, eliminate me */ 
342 int (*input)(struct mbuf **, int *, int) = 
343 (int (*)(struct mbuf **, int *, int))esw->en_input; 
344 encap_fillarg(m, match); 341 encap_fillarg(m, match);
345 return (*input)(mp, offp, proto); 342 return (*psw->pr_input)(mp, offp, proto);
346 } else { 343 } else {
347 m_freem(m); 344 m_freem(m);
348 return IPPROTO_DONE; 345 return IPPROTO_DONE;
349 } 346 }
350 } 347 }
351 348
352 /* last resort: inject to raw socket */ 349 /* last resort: inject to raw socket */
353 return rip6_input(mp, offp, proto); 350 return rip6_input(mp, offp, proto);
354} 351}
355#endif 352#endif
356 353
357static int 354static int
358encap_add(struct encaptab *ep) 355encap_add(struct encaptab *ep)
@@ -424,27 +421,27 @@ encap_afcheck(int af, const struct socka @@ -424,27 +421,27 @@ encap_afcheck(int af, const struct socka
424 421
425 return 0; 422 return 0;
426} 423}
427 424
428/* 425/*
429 * sp (src ptr) is always my side, and dp (dst ptr) is always remote side. 426 * sp (src ptr) is always my side, and dp (dst ptr) is always remote side.
430 * length of mask (sm and dm) is assumed to be same as sp/dp. 427 * length of mask (sm and dm) is assumed to be same as sp/dp.
431 * Return value will be necessary as input (cookie) for encap_detach(). 428 * Return value will be necessary as input (cookie) for encap_detach().
432 */ 429 */
433const struct encaptab * 430const struct encaptab *
434encap_attach(int af, int proto, 431encap_attach(int af, int proto,
435 const struct sockaddr *sp, const struct sockaddr *sm, 432 const struct sockaddr *sp, const struct sockaddr *sm,
436 const struct sockaddr *dp, const struct sockaddr *dm, 433 const struct sockaddr *dp, const struct sockaddr *dm,
437 const struct encapsw *esw, void *arg) 434 const struct protosw *psw, void *arg)
438{ 435{
439 struct encaptab *ep; 436 struct encaptab *ep;
440 int error; 437 int error;
441 int s; 438 int s;
442 size_t l; 439 size_t l;
443 struct ip_pack4 *pack4; 440 struct ip_pack4 *pack4;
444#ifdef INET6 441#ifdef INET6
445 struct ip_pack6 *pack6; 442 struct ip_pack6 *pack6;
446#endif 443#endif
447 444
448 s = splsoftnet(); 445 s = splsoftnet();
449 /* sanity check on args */ 446 /* sanity check on args */
450 error = encap_afcheck(af, sp, dp); 447 error = encap_afcheck(af, sp, dp);
@@ -527,80 +524,80 @@ encap_attach(int af, int proto, @@ -527,80 +524,80 @@ encap_attach(int af, int proto,
527 ep->src = (struct sockaddr *)&pack6->mine; 524 ep->src = (struct sockaddr *)&pack6->mine;
528 ep->dst = (struct sockaddr *)&pack6->yours; 525 ep->dst = (struct sockaddr *)&pack6->yours;
529 pack6 = (struct ip_pack6 *)ep->maskpack; 526 pack6 = (struct ip_pack6 *)ep->maskpack;
530 ep->srcmask = (struct sockaddr *)&pack6->mine; 527 ep->srcmask = (struct sockaddr *)&pack6->mine;
531 ep->dstmask = (struct sockaddr *)&pack6->yours; 528 ep->dstmask = (struct sockaddr *)&pack6->yours;
532 break; 529 break;
533#endif 530#endif
534 } 531 }
535 532
536 memcpy(ep->src, sp, sp->sa_len); 533 memcpy(ep->src, sp, sp->sa_len);
537 memcpy(ep->srcmask, sm, sp->sa_len); 534 memcpy(ep->srcmask, sm, sp->sa_len);
538 memcpy(ep->dst, dp, dp->sa_len); 535 memcpy(ep->dst, dp, dp->sa_len);
539 memcpy(ep->dstmask, dm, dp->sa_len); 536 memcpy(ep->dstmask, dm, dp->sa_len);
540 ep->esw = esw; 537 ep->psw = psw;
541 ep->arg = arg; 538 ep->arg = arg;
542 539
543 error = encap_add(ep); 540 error = encap_add(ep);
544 if (error) 541 if (error)
545 goto gc; 542 goto gc;
546 543
547 error = 0; 544 error = 0;
548 splx(s); 545 splx(s);
549 return ep; 546 return ep;
550 547
551gc: 548gc:
552 if (ep->addrpack) 549 if (ep->addrpack)
553 kmem_free(ep->addrpack, l); 550 kmem_free(ep->addrpack, l);
554 if (ep->maskpack) 551 if (ep->maskpack)
555 kmem_free(ep->maskpack, l); 552 kmem_free(ep->maskpack, l);
556 if (ep) 553 if (ep)
557 kmem_free(ep, sizeof(*ep)); 554 kmem_free(ep, sizeof(*ep));
558fail: 555fail:
559 splx(s); 556 splx(s);
560 return NULL; 557 return NULL;
561} 558}
562 559
563const struct encaptab * 560const struct encaptab *
564encap_attach_func(int af, int proto, 561encap_attach_func(int af, int proto,
565 int (*func)(struct mbuf *, int, int, void *), 562 int (*func)(struct mbuf *, int, int, void *),
566 const struct encapsw *esw, void *arg) 563 const struct protosw *psw, void *arg)
567{ 564{
568 struct encaptab *ep; 565 struct encaptab *ep;
569 int error; 566 int error;
570 int s; 567 int s;
571 568
572 s = splsoftnet(); 569 s = splsoftnet();
573 /* sanity check on args */ 570 /* sanity check on args */
574 if (!func) { 571 if (!func) {
575 error = EINVAL; 572 error = EINVAL;
576 goto fail; 573 goto fail;
577 } 574 }
578 575
579 error = encap_afcheck(af, NULL, NULL); 576 error = encap_afcheck(af, NULL, NULL);
580 if (error) 577 if (error)
581 goto fail; 578 goto fail;
582 579
583 ep = kmem_alloc(sizeof(*ep), KM_NOSLEEP); /*XXX*/ 580 ep = kmem_alloc(sizeof(*ep), KM_NOSLEEP); /*XXX*/
584 if (ep == NULL) { 581 if (ep == NULL) {
585 error = ENOBUFS; 582 error = ENOBUFS;
586 goto fail; 583 goto fail;
587 } 584 }
588 memset(ep, 0, sizeof(*ep)); 585 memset(ep, 0, sizeof(*ep));
589 586
590 ep->af = af; 587 ep->af = af;
591 ep->proto = proto; 588 ep->proto = proto;
592 ep->func = func; 589 ep->func = func;
593 ep->esw = esw; 590 ep->psw = psw;
594 ep->arg = arg; 591 ep->arg = arg;
595 592
596 error = encap_add(ep); 593 error = encap_add(ep);
597 if (error) 594 if (error)
598 goto fail; 595 goto fail;
599 596
600 error = 0; 597 error = 0;
601 splx(s); 598 splx(s);
602 return ep; 599 return ep;
603 600
604fail: 601fail:
605 splx(s); 602 splx(s);
606 return NULL; 603 return NULL;
@@ -609,27 +606,27 @@ fail: @@ -609,27 +606,27 @@ fail:
609/* XXX encap4_ctlinput() is necessary if we set DF=1 on outer IPv4 header */ 606/* XXX encap4_ctlinput() is necessary if we set DF=1 on outer IPv4 header */
610 607
611#ifdef INET6 608#ifdef INET6
612void * 609void *
613encap6_ctlinput(int cmd, const struct sockaddr *sa, void *d0) 610encap6_ctlinput(int cmd, const struct sockaddr *sa, void *d0)
614{ 611{
615 void *d = d0; 612 void *d = d0;
616 struct ip6_hdr *ip6; 613 struct ip6_hdr *ip6;
617 struct mbuf *m; 614 struct mbuf *m;
618 int off; 615 int off;
619 struct ip6ctlparam *ip6cp = NULL; 616 struct ip6ctlparam *ip6cp = NULL;
620 int nxt; 617 int nxt;
621 struct encaptab *ep; 618 struct encaptab *ep;
622 const struct encapsw *esw; 619 const struct ip6protosw *psw;
623 620
624 if (sa->sa_family != AF_INET6 || 621 if (sa->sa_family != AF_INET6 ||
625 sa->sa_len != sizeof(struct sockaddr_in6)) 622 sa->sa_len != sizeof(struct sockaddr_in6))
626 return NULL; 623 return NULL;
627 624
628 if ((unsigned)cmd >= PRC_NCMDS) 625 if ((unsigned)cmd >= PRC_NCMDS)
629 return NULL; 626 return NULL;
630 if (cmd == PRC_HOSTDEAD) 627 if (cmd == PRC_HOSTDEAD)
631 d = NULL; 628 d = NULL;
632 else if (cmd == PRC_MSGSIZE) 629 else if (cmd == PRC_MSGSIZE)
633 ; /* special code is present, see below */ 630 ; /* special code is present, see below */
634 else if (inet6ctlerrmap[cmd] == 0) 631 else if (inet6ctlerrmap[cmd] == 0)
635 return NULL; 632 return NULL;
@@ -668,29 +665,29 @@ encap6_ctlinput(int cmd, const struct so @@ -668,29 +665,29 @@ encap6_ctlinput(int cmd, const struct so
668 nxt = -1; 665 nxt = -1;
669 } 666 }
670 667
671 /* inform all listeners */ 668 /* inform all listeners */
672 LIST_FOREACH(ep, &encaptab, chain) { 669 LIST_FOREACH(ep, &encaptab, chain) {
673 if (ep->af != AF_INET6) 670 if (ep->af != AF_INET6)
674 continue; 671 continue;
675 if (ep->proto >= 0 && ep->proto != nxt) 672 if (ep->proto >= 0 && ep->proto != nxt)
676 continue; 673 continue;
677 674
678 /* should optimize by looking at address pairs */ 675 /* should optimize by looking at address pairs */
679 676
680 /* XXX need to pass ep->arg or ep itself to listeners */ 677 /* XXX need to pass ep->arg or ep itself to listeners */
681 esw = ep->esw; 678 psw = (const struct ip6protosw *)ep->psw;
682 if (esw && esw->en_ctlinput) 679 if (psw && psw->pr_ctlinput)
683 (*esw->en_ctlinput)(cmd, sa, d); 680 (*psw->pr_ctlinput)(cmd, sa, d);
684 } 681 }
685 682
686 rip6_ctlinput(cmd, sa, d0); 683 rip6_ctlinput(cmd, sa, d0);
687 return NULL; 684 return NULL;
688} 685}
689#endif 686#endif
690 687
691int 688int
692encap_detach(const struct encaptab *cookie) 689encap_detach(const struct encaptab *cookie)
693{ 690{
694 const struct encaptab *ep = cookie; 691 const struct encaptab *ep = cookie;
695 struct encaptab *p, *np; 692 struct encaptab *p, *np;
696 int error; 693 int error;

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

--- src/sys/netinet/ip_encap.h 2016/01/22 05:15:10 1.14
+++ src/sys/netinet/ip_encap.h 2016/01/22 23:27:12 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_encap.h,v 1.14 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: ip_encap.h,v 1.15 2016/01/22 23:27:12 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,67 +29,62 @@ @@ -29,67 +29,62 @@
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 
47struct encaptab { 42struct encaptab {
48 struct radix_node nodes[2]; 43 struct radix_node nodes[2];
49 LIST_ENTRY(encaptab) chain; 44 LIST_ENTRY(encaptab) chain;
50 int af; 45 int af;
51 int proto; /* -1: don't care, I'll check myself */ 46 int proto; /* -1: don't care, I'll check myself */
52 struct sockaddr *addrpack; /* malloc'ed, for radix lookup */ 47 struct sockaddr *addrpack; /* malloc'ed, for radix lookup */
53 struct sockaddr *maskpack; /* ditto */ 48 struct sockaddr *maskpack; /* ditto */
54 struct sockaddr *src; /* my addr */ 49 struct sockaddr *src; /* my addr */
55 struct sockaddr *srcmask; 50 struct sockaddr *srcmask;
56 struct sockaddr *dst; /* remote addr */ 51 struct sockaddr *dst; /* remote addr */
57 struct sockaddr *dstmask; 52 struct sockaddr *dstmask;
58 int (*func) (struct mbuf *, int, int, void *); 53 int (*func) (struct mbuf *, int, int, void *);
59 const struct encapsw *esw; 54 const struct protosw *psw; /* only pr_input will be used */
60 void *arg; /* passed via PACKET_TAG_ENCAP */ 55 void *arg; /* passed via PACKET_TAG_ENCAP */
61}; 56};
62 57
63/* to lookup a pair of address using radix tree */ 58/* to lookup a pair of address using radix tree */
64struct sockaddr_pack { 59struct sockaddr_pack {
65 u_int8_t sp_len; 60 u_int8_t sp_len;
66 u_int8_t sp_family; /* not really used */ 61 u_int8_t sp_family; /* not really used */
67 /* followed by variable-length data */ 62 /* followed by variable-length data */
68}; 63};
69 64
70struct ip_pack4 { 65struct ip_pack4 {
71 struct sockaddr_pack p; 66 struct sockaddr_pack p;
72 struct sockaddr_in mine; 67 struct sockaddr_in mine;
73 struct sockaddr_in yours; 68 struct sockaddr_in yours;
74}; 69};
75struct ip_pack6 { 70struct ip_pack6 {
76 struct sockaddr_pack p; 71 struct sockaddr_pack p;
77 struct sockaddr_in6 mine; 72 struct sockaddr_in6 mine;
78 struct sockaddr_in6 yours; 73 struct sockaddr_in6 yours;
79}; 74};
80 75
81void encap_init(void); 76void encap_init(void);
82void encap4_input(struct mbuf *, ...); 77void encap4_input(struct mbuf *, ...);
83int encap6_input(struct mbuf **, int *, int); 78int encap6_input(struct mbuf **, int *, int);
84const struct encaptab *encap_attach(int, int, const struct sockaddr *, 79const struct encaptab *encap_attach(int, int, const struct sockaddr *,
85 const struct sockaddr *, const struct sockaddr *, 80 const struct sockaddr *, const struct sockaddr *,
86 const struct sockaddr *, const struct encapsw *, void *); 81 const struct sockaddr *, const struct protosw *, void *);
87const struct encaptab *encap_attach_func(int, int, 82const struct encaptab *encap_attach_func(int, int,
88 int (*)(struct mbuf *, int, int, void *), 83 int (*)(struct mbuf *, int, int, void *),
89 const struct encapsw *, void *); 84 const struct protosw *, void *);
90void *encap6_ctlinput(int, const struct sockaddr *, void *); 85void *encap6_ctlinput(int, const struct sockaddr *, void *);
91int encap_detach(const struct encaptab *); 86int encap_detach(const struct encaptab *);
92void *encap_getarg(struct mbuf *); 87void *encap_getarg(struct mbuf *);
93#endif 88#endif
94 89
95#endif /* !_NETINET_IP_ENCAP_H_ */ 90#endif /* !_NETINET_IP_ENCAP_H_ */

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

--- src/sys/netinet/ip_mroute.c 2016/01/22 05:15:10 1.135
+++ src/sys/netinet/ip_mroute.c 2016/01/22 23:27:12 1.136
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_mroute.c,v 1.135 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: ip_mroute.c,v 1.136 2016/01/22 23:27:12 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.135 2016/01/22 05:15:10 riastradh Exp $"); 96__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.136 2016/01/22 23:27:12 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,29 +183,34 @@ u_int tbfdebug = 0; /* tbf de @@ -183,29 +183,34 @@ 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 encapsw vif_encapsw = { 196static const struct protosw vif_protosw = {
197 .en_input = vif_input, 197 .pr_type = SOCK_RAW,
198 .en_ctlinput = NULL, 198 .pr_domain = &inetdomain,
 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,
199}; 204};
200 205
201#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */ 206#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
202#define UPCALL_EXPIRE 6 /* number of timeouts */ 207#define UPCALL_EXPIRE 6 /* number of timeouts */
203 208
204/* 209/*
205 * Define the token bucket filter structures 210 * Define the token bucket filter structures
206 */ 211 */
207 212
208#define TBF_REPROCESS (hz / 100) /* 100x / second */ 213#define TBF_REPROCESS (hz / 100) /* 100x / second */
209 214
210static int get_sg_cnt(struct sioc_sg_req *); 215static int get_sg_cnt(struct sioc_sg_req *);
211static int get_vif_cnt(struct sioc_vif_req *); 216static int get_vif_cnt(struct sioc_vif_req *);
@@ -822,27 +827,27 @@ add_vif(struct vifctl *vifcp) @@ -822,27 +827,27 @@ add_vif(struct vifctl *vifcp)
822 log(LOG_ERR, "source routed tunnels not supported\n"); 827 log(LOG_ERR, "source routed tunnels not supported\n");
823 return (EOPNOTSUPP); 828 return (EOPNOTSUPP);
824 } 829 }
825 830
826 /* attach this vif to decapsulator dispatch table */ 831 /* attach this vif to decapsulator dispatch table */
827 /* 832 /*
828 * XXX Use addresses in registration so that matching 833 * XXX Use addresses in registration so that matching
829 * can be done with radix tree in decapsulator. But, 834 * can be done with radix tree in decapsulator. But,
830 * we need to check inner header for multicast, so 835 * we need to check inner header for multicast, so
831 * this requires both radix tree lookup and then a 836 * this requires both radix tree lookup and then a
832 * function to check, and this is not supported yet. 837 * function to check, and this is not supported yet.
833 */ 838 */
834 vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4, 839 vifp->v_encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV4,
835 vif_encapcheck, &vif_encapsw, vifp); 840 vif_encapcheck, &vif_protosw, vifp);
836 if (!vifp->v_encap_cookie) 841 if (!vifp->v_encap_cookie)
837 return (EINVAL); 842 return (EINVAL);
838 843
839 /* Create a fake encapsulation interface. */ 844 /* Create a fake encapsulation interface. */
840 ifp = malloc(sizeof(*ifp), M_MRTABLE, M_WAITOK|M_ZERO); 845 ifp = malloc(sizeof(*ifp), M_MRTABLE, M_WAITOK|M_ZERO);
841 snprintf(ifp->if_xname, sizeof(ifp->if_xname), 846 snprintf(ifp->if_xname, sizeof(ifp->if_xname),
842 "mdecap%d", vifcp->vifc_vifi); 847 "mdecap%d", vifcp->vifc_vifi);
843 848
844 /* Prepare cached route entry. */ 849 /* Prepare cached route entry. */
845 memset(&vifp->v_route, 0, sizeof(vifp->v_route)); 850 memset(&vifp->v_route, 0, sizeof(vifp->v_route));
846#ifdef PIM 851#ifdef PIM
847 } else if (vifcp->vifc_flags & VIFF_REGISTER) { 852 } else if (vifcp->vifc_flags & VIFF_REGISTER) {
848 ifp = &multicast_register_if; 853 ifp = &multicast_register_if;

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

--- src/sys/netinet6/in6_gif.c 2016/01/22 05:15:10 1.67
+++ src/sys/netinet6/in6_gif.c 2016/01/22 23:27:12 1.68
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6_gif.c,v 1.67 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: in6_gif.c,v 1.68 2016/01/22 23:27:12 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,74 +21,75 @@ @@ -21,74 +21,75 @@
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.67 2016/01/22 05:15:10 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.68 2016/01/22 23:27:12 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>
49#include <sys/kernel.h> 50#include <sys/kernel.h>
50 51
51#include <net/if.h> 52#include <net/if.h>
52#include <net/route.h> 53#include <net/route.h>
53 54
54#include <netinet/in.h> 55#include <netinet/in.h>
55#include <netinet/in_systm.h> 56#include <netinet/in_systm.h>
56#ifdef INET 57#ifdef INET
57#include <netinet/ip.h> 58#include <netinet/ip.h>
58#endif 59#endif
59#include <netinet/ip_encap.h> 60#include <netinet/ip_encap.h>
60#ifdef INET6 61#ifdef INET6
61#include <netinet/ip6.h> 62#include <netinet/ip6.h>
62#include <netinet6/ip6_var.h> 63#include <netinet6/ip6_var.h>
63#include <netinet6/ip6_private.h> 64#include <netinet6/ip6_private.h>
64#include <netinet6/in6_gif.h> 65#include <netinet6/in6_gif.h>
65#include <netinet6/in6_var.h> 66#include <netinet6/in6_var.h>
66#include <netinet6/ip6protosw.h> 
67#endif 67#endif
 68#include <netinet6/ip6protosw.h>
68#include <netinet/ip_ecn.h> 69#include <netinet/ip_ecn.h>
69 70
70#include <net/if_gif.h> 71#include <net/if_gif.h>
71 72
72#include <net/net_osdep.h> 73#include <net/net_osdep.h>
73 74
74static int gif_validate6(const struct ip6_hdr *, struct gif_softc *, 75static int gif_validate6(const struct ip6_hdr *, struct gif_softc *,
75 struct ifnet *); 76 struct ifnet *);
76 77
77int ip6_gif_hlim = GIF_HLIM; 78int ip6_gif_hlim = GIF_HLIM;
78 79
79extern LIST_HEAD(, gif_softc) gif_softc_list; 80extern LIST_HEAD(, gif_softc) gif_softc_list;
80 81
81static const struct encapsw in6_gif_encapsw; 82static const struct ip6protosw in6_gif_protosw;
82 83
83/*  84/*
84 * family - family of the packet to be encapsulate.  85 * family - family of the packet to be encapsulate.
85 */ 86 */
86 87
87int 88int
88in6_gif_output(struct ifnet *ifp, int family, struct mbuf *m) 89in6_gif_output(struct ifnet *ifp, int family, struct mbuf *m)
89{ 90{
90 struct rtentry *rt; 91 struct rtentry *rt;
91 struct gif_softc *sc = ifp->if_softc; 92 struct gif_softc *sc = ifp->if_softc;
92 struct sockaddr_in6 *sin6_src = satosin6(sc->gif_psrc); 93 struct sockaddr_in6 *sin6_src = satosin6(sc->gif_psrc);
93 struct sockaddr_in6 *sin6_dst = satosin6(sc->gif_pdst); 94 struct sockaddr_in6 *sin6_dst = satosin6(sc->gif_pdst);
94 struct ip6_hdr *ip6; 95 struct ip6_hdr *ip6;
@@ -363,48 +364,55 @@ in6_gif_attach(struct gif_softc *sc) @@ -363,48 +364,55 @@ in6_gif_attach(struct gif_softc *sc)
363{ 364{
364#ifndef GIF_ENCAPCHECK 365#ifndef GIF_ENCAPCHECK
365 struct sockaddr_in6 mask6; 366 struct sockaddr_in6 mask6;
366 367
367 memset(&mask6, 0, sizeof(mask6)); 368 memset(&mask6, 0, sizeof(mask6));
368 mask6.sin6_len = sizeof(struct sockaddr_in6); 369 mask6.sin6_len = sizeof(struct sockaddr_in6);
369 mask6.sin6_addr.s6_addr32[0] = mask6.sin6_addr.s6_addr32[1] = 370 mask6.sin6_addr.s6_addr32[0] = mask6.sin6_addr.s6_addr32[1] =
370 mask6.sin6_addr.s6_addr32[2] = mask6.sin6_addr.s6_addr32[3] = ~0; 371 mask6.sin6_addr.s6_addr32[2] = mask6.sin6_addr.s6_addr32[3] = ~0;
371 372
372 if (!sc->gif_psrc || !sc->gif_pdst) 373 if (!sc->gif_psrc || !sc->gif_pdst)
373 return EINVAL; 374 return EINVAL;
374 sc->encap_cookie6 = encap_attach(AF_INET6, -1, sc->gif_psrc, 375 sc->encap_cookie6 = encap_attach(AF_INET6, -1, sc->gif_psrc,
375 (struct sockaddr *)&mask6, sc->gif_pdst, (struct sockaddr *)&mask6, 376 (struct sockaddr *)&mask6, sc->gif_pdst, (struct sockaddr *)&mask6,
376 &in6_gif_encapsw, sc); 377 (const void *)&in6_gif_protosw, sc);
377#else 378#else
378 sc->encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck, 379 sc->encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck,
379 &in6_gif_encapsw, sc); 380 (struct protosw *)&in6_gif_protosw, sc);
380#endif 381#endif
381 if (sc->encap_cookie6 == NULL) 382 if (sc->encap_cookie6 == NULL)
382 return EEXIST; 383 return EEXIST;
383 return 0; 384 return 0;
384} 385}
385 386
386int 387int
387in6_gif_detach(struct gif_softc *sc) 388in6_gif_pause(struct gif_softc *sc)
388{ 389{
389 int error; 390 int error;
390 391
391 error = encap_detach(sc->encap_cookie6); 392 error = encap_detach(sc->encap_cookie6);
392 if (error == 0) 393 if (error == 0)
393 sc->encap_cookie6 = NULL; 394 sc->encap_cookie6 = NULL;
394 395
 396 return error;
 397}
 398
 399int
 400in6_gif_detach(struct gif_softc *sc)
 401{
 402
395 rtcache_free(&sc->gif_ro); 403 rtcache_free(&sc->gif_ro);
396 404
397 return error; 405 return 0;
398} 406}
399 407
400void * 408void *
401in6_gif_ctlinput(int cmd, const struct sockaddr *sa, void *d) 409in6_gif_ctlinput(int cmd, const struct sockaddr *sa, void *d)
402{ 410{
403 struct gif_softc *sc; 411 struct gif_softc *sc;
404 struct ip6ctlparam *ip6cp = NULL; 412 struct ip6ctlparam *ip6cp = NULL;
405 struct ip6_hdr *ip6; 413 struct ip6_hdr *ip6;
406 const struct sockaddr_in6 *dst6; 414 const struct sockaddr_in6 *dst6;
407 415
408 if (sa->sa_family != AF_INET6 || 416 if (sa->sa_family != AF_INET6 ||
409 sa->sa_len != sizeof(struct sockaddr_in6)) 417 sa->sa_len != sizeof(struct sockaddr_in6))
410 return NULL; 418 return NULL;
@@ -440,20 +448,30 @@ in6_gif_ctlinput(int cmd, const struct s @@ -440,20 +448,30 @@ in6_gif_ctlinput(int cmd, const struct s
440 448
441 dst6 = satocsin6(rtcache_getdst(&sc->gif_ro)); 449 dst6 = satocsin6(rtcache_getdst(&sc->gif_ro));
442 /* XXX scope */ 450 /* XXX scope */
443 if (dst6 == NULL) 451 if (dst6 == NULL)
444 ; 452 ;
445 else if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst6->sin6_addr)) 453 else if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst6->sin6_addr))
446 rtcache_free(&sc->gif_ro); 454 rtcache_free(&sc->gif_ro);
447 } 455 }
448 456
449 return NULL; 457 return NULL;
450} 458}
451 459
452PR_WRAP_CTLINPUT(in6_gif_ctlinput) 460PR_WRAP_CTLINPUT(in6_gif_ctlinput)
 461PR_WRAP_CTLOUTPUT(rip6_ctloutput)
453 462
454#define in6_gif_ctlinput in6_gif_ctlinput_wrapper 463#define in6_gif_ctlinput in6_gif_ctlinput_wrapper
 464#define rip6_ctloutput rip6_ctloutput_wrapper
 465
 466extern struct domain inet6domain;
455 467
456static const struct encapsw in6_gif_encapsw = { 468static const struct ip6protosw in6_gif_protosw = {
457 .en_input = (void (*)(struct mbuf *, ...))in6_gif_input, 469 .pr_type = SOCK_RAW,
458 .en_ctlinput = in6_gif_ctlinput, 470 .pr_domain = &inet6domain,
 471 .pr_protocol = 0 /* IPPROTO_IPV[46] */,
 472 .pr_flags = PR_ATOMIC | PR_ADDR,
 473 .pr_input = in6_gif_input,
 474 .pr_ctlinput = in6_gif_ctlinput,
 475 .pr_ctloutput = rip6_ctloutput,
 476 .pr_usrreqs = &rip6_usrreqs,
459}; 477};

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

--- src/sys/netipsec/xform_ipip.c 2016/01/22 05:15:10 1.34
+++ src/sys/netipsec/xform_ipip.c 2016/01/22 23:27:12 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xform_ipip.c,v 1.34 2016/01/22 05:15:10 riastradh Exp $ */ 1/* $NetBSD: xform_ipip.c,v 1.35 2016/01/22 23:27:12 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,74 +29,79 @@ @@ -29,74 +29,79 @@
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.34 2016/01/22 05:15:10 riastradh Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: xform_ipip.c,v 1.35 2016/01/22 23:27:12 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>
59#include <sys/sysctl.h> 60#include <sys/sysctl.h>
60 61
61#include <net/if.h> 62#include <net/if.h>
62#include <net/route.h> 63#include <net/route.h>
63#include <net/netisr.h> 64#include <net/netisr.h>
64 65
65#include <netinet/in.h> 66#include <netinet/in.h>
66#include <netinet/in_systm.h> 67#include <netinet/in_systm.h>
67#include <netinet/in_var.h> 68#include <netinet/in_var.h>
68#include <netinet/ip.h> 69#include <netinet/ip.h>
69#include <netinet/ip_ecn.h> 70#include <netinet/ip_ecn.h>
70#include <netinet/ip_var.h> 71#include <netinet/ip_var.h>
71#include <netinet/ip_encap.h> 72#include <netinet/ip_encap.h>
 73#ifdef __FreeBSD__
 74#include <netinet/ipprotosw.h>
 75#endif
72 76
73#include <netipsec/ipsec.h> 77#include <netipsec/ipsec.h>
74#include <netipsec/ipsec_private.h> 78#include <netipsec/ipsec_private.h>
75#include <netipsec/xform.h> 79#include <netipsec/xform.h>
76 80
77#include <netipsec/ipip_var.h> 81#include <netipsec/ipip_var.h>
78 82
79#ifdef MROUTING 83#ifdef MROUTING
80#include <netinet/ip_mroute.h> 84#include <netinet/ip_mroute.h>
81#endif 85#endif
82 86
83#ifdef INET6 87#ifdef INET6
84#include <netinet/ip6.h> 88#include <netinet/ip6.h>
85#include <netipsec/ipsec6.h> 89#include <netipsec/ipsec6.h>
86# ifdef __FreeBSD__ 90# ifdef __FreeBSD__
87# include <netinet6/ip6_ecn.h> 91# include <netinet6/ip6_ecn.h>
88# endif 92# endif
89#include <netinet6/in6_var.h> 93#include <netinet6/in6_var.h>
 94#include <netinet6/ip6protosw.h>
90#endif 95#endif
91 96
92#include <netipsec/key.h> 97#include <netipsec/key.h>
93#include <netipsec/key_debug.h> 98#include <netipsec/key_debug.h>
94#include <netipsec/ipsec_osdep.h> 99#include <netipsec/ipsec_osdep.h>
95 100
96#ifdef __FreeBSD__ 101#ifdef __FreeBSD__
97typedef void pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */ 102typedef void pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */
98#else 103#else
99typedef void pr_in_input_t (struct mbuf *m, ...); 104typedef void pr_in_input_t (struct mbuf *m, ...);
100#endif 105#endif
101 106
102/* 107/*
@@ -667,35 +672,63 @@ ipe4_input( @@ -667,35 +672,63 @@ ipe4_input(
667 printf("ipe4_input: should never be called\n"); 672 printf("ipe4_input: should never be called\n");
668 if (m) 673 if (m)
669 m_freem(m); 674 m_freem(m);
670 return EOPNOTSUPP; 675 return EOPNOTSUPP;
671} 676}
672 677
673static struct xformsw ipe4_xformsw = { 678static struct xformsw ipe4_xformsw = {
674 XF_IP4, 0, "IPv4 Simple Encapsulation", 679 XF_IP4, 0, "IPv4 Simple Encapsulation",
675 ipe4_init, ipe4_zeroize, ipe4_input, ipip_output, 680 ipe4_init, ipe4_zeroize, ipe4_input, ipip_output,
676 NULL, 681 NULL,
677}; 682};
678 683
679#ifdef INET 684#ifdef INET
680static const struct encapsw ipe4_encapsw = { 685PR_WRAP_CTLOUTPUT(rip_ctloutput)
681 .en_input = ip4_input, 686#define rip_ctloutput rip_ctloutput_wrapper
682 .en_ctlinput = NULL, 687
 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,
683}; 702};
684#endif 703#endif
685#ifdef INET6 704#ifdef INET6
686static const struct encapsw ipe4_encapsw6 = { 705PR_WRAP_CTLOUTPUT(rip6_ctloutput)
687 .en_input = (void (*)(struct mbuf *, ...))ip4_input6, 706#define rip6_ctloutput rip6_ctloutput_wrapper
688 .en_ctlinput = NULL, 707
 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,
689}; 722};
690#endif 723#endif
691 724
692/* 725/*
693 * Check the encapsulated packet to see if we want it 726 * Check the encapsulated packet to see if we want it
694 */ 727 */
695static int 728static int
696ipe4_encapcheck(struct mbuf *m, 729ipe4_encapcheck(struct mbuf *m,
697 int off, 730 int off,
698 int proto, 731 int proto,
699 void *arg 732 void *arg
700) 733)
701{ 734{
@@ -709,25 +742,25 @@ ipe4_encapcheck(struct mbuf *m, @@ -709,25 +742,25 @@ ipe4_encapcheck(struct mbuf *m,
709} 742}
710 743
711INITFN void 744INITFN void
712ipe4_attach(void) 745ipe4_attach(void)
713{ 746{
714 747
715 ipipstat_percpu = percpu_alloc(sizeof(uint64_t) * IPIP_NSTATS); 748 ipipstat_percpu = percpu_alloc(sizeof(uint64_t) * IPIP_NSTATS);
716 749
717 xform_register(&ipe4_xformsw); 750 xform_register(&ipe4_xformsw);
718 /* attach to encapsulation framework */ 751 /* attach to encapsulation framework */
719 /* XXX save return cookie for detach on module remove */ 752 /* XXX save return cookie for detach on module remove */
720#ifdef INET 753#ifdef INET
721 (void) encap_attach_func(AF_INET, -1, 754 (void) encap_attach_func(AF_INET, -1,
722 ipe4_encapcheck, &ipe4_encapsw, NULL); 755 ipe4_encapcheck, (struct protosw*) &ipe4_protosw, NULL);
723#endif 756#endif
724#ifdef INET6 757#ifdef INET6
725 (void) encap_attach_func(AF_INET6, -1, 758 (void) encap_attach_func(AF_INET6, -1,
726 ipe4_encapcheck, &ipe4_encapsw6, NULL); 759 ipe4_encapcheck, (struct protosw*) &ipe4_protosw6, NULL);
727#endif 760#endif
728} 761}
729 762
730#ifdef SYSINIT 763#ifdef SYSINIT
731SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL); 764SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL);
732#endif 765#endif
733 766