Deleted Added
sdiff udiff text old ( 193744 ) new ( 193947 )
full compact
1/* $FreeBSD: head/sys/netipsec/xform_ipip.c 193744 2009-06-08 19:57:35Z bz $ */
2/* $OpenBSD: ip_ipip.c,v 1.25 2002/06/10 18:04:55 itojun Exp $ */
3/*-
4 * The authors of this code are John Ioannidis (ji@tla.org),
5 * Angelos D. Keromytis (kermit@csd.uch.gr) and
6 * Niels Provos (provos@physnet.uni-hamburg.de).
7 *
8 * The original version of this code was written by John Ioannidis
9 * for BSD/OS in Athens, Greece, in November 1995.
10 *
11 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
12 * by Angelos D. Keromytis.
13 *
14 * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
15 * and Niels Provos.
16 *
17 * Additional features in 1999 by Angelos D. Keromytis.
18 *
19 * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
20 * Angelos D. Keromytis and Niels Provos.
21 * Copyright (c) 2001, Angelos D. Keromytis.
22 *
23 * Permission to use, copy, and modify this software with or without fee
24 * is hereby granted, provided that this entire notice is included in
25 * all copies of any software which is or includes a copy or
26 * modification of this software.
27 * You may use this code under the GNU public license if you so wish. Please
28 * contribute changes back to the authors under this freer than GPL license
29 * so that we may further the use of strong encryption without limitations to
30 * all.
31 *
32 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
33 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
34 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
35 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
36 * PURPOSE.
37 */
38
39/*
40 * IP-inside-IP processing
41 */
42#include "opt_inet.h"
43#include "opt_inet6.h"
44#include "opt_enc.h"
45
46#include <sys/param.h>
47#include <sys/systm.h>
48#include <sys/mbuf.h>
49#include <sys/socket.h>
50#include <sys/kernel.h>
51#include <sys/protosw.h>
52#include <sys/sysctl.h>
53#include <sys/vimage.h>
54
55#include <net/if.h>
56#include <net/pfil.h>
57#include <net/route.h>
58#include <net/netisr.h>
59#include <net/vnet.h>
60
61#include <netinet/in.h>
62#include <netinet/in_systm.h>
63#include <netinet/in_var.h>
64#include <netinet/ip.h>
65#include <netinet/ip_ecn.h>
66#include <netinet/ip_var.h>
67#include <netinet/ip_encap.h>
68#ifdef MROUTING
69#include <netinet/ip_mroute.h>
70#endif
71#include <netinet/vinet.h>
72
73#include <netipsec/ipsec.h>
74#include <netipsec/xform.h>
75
76#include <netipsec/ipip_var.h>
77
78#ifdef INET6
79#include <netinet/ip6.h>
80#include <netipsec/ipsec6.h>
81#include <netinet6/ip6_ecn.h>
82#include <netinet6/in6_var.h>
83#include <netinet6/ip6protosw.h>
84#endif
85
86#include <netipsec/key.h>
87#include <netipsec/key_debug.h>
88
89#include <machine/stdarg.h>
90
91/*
92 * We can control the acceptance of IP4 packets by altering the sysctl
93 * net.inet.ipip.allow value. Zero means drop them, all else is acceptance.
94 */
95#ifdef VIMAGE_GLOBALS
96int ipip_allow;
97struct ipipstat ipipstat;
98#endif
99
100SYSCTL_DECL(_net_inet_ipip);
101SYSCTL_V_INT(V_NET, vnet_ipsec, _net_inet_ipip, OID_AUTO,
102 ipip_allow, CTLFLAG_RW, ipip_allow, 0, "");
103SYSCTL_V_STRUCT(V_NET, vnet_ipsec, _net_inet_ipip, IPSECCTL_STATS,
104 stats, CTLFLAG_RD, ipipstat, ipipstat, "");
105
106/* XXX IPCOMP */
107#define M_IPSEC (M_AUTHIPHDR|M_AUTHIPDGM|M_DECRYPTED)
108
109static void _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp);
110static int ipe4_iattach(const void *);
111
112#ifndef VIMAGE_GLOBALS
113static const vnet_modinfo_t vnet_ipip_modinfo = {
114 .vmi_id = VNET_MOD_IPIP,
115 .vmi_name = "ipsec_ipip",
116 .vmi_dependson = VNET_MOD_IPSEC,
117 .vmi_iattach = ipe4_iattach
118};
119#endif /* !VIMAGE_GLOBALS */
120
121#ifdef INET6
122/*
123 * Really only a wrapper for ipip_input(), for use with IPv6.
124 */
125int
126ip4_input6(struct mbuf **m, int *offp, int proto)
127{
128#if 0
129 /* If we do not accept IP-in-IP explicitly, drop. */
130 if (!V_ipip_allow && ((*m)->m_flags & M_IPSEC) == 0) {
131 DPRINTF(("%s: dropped due to policy\n", __func__));
132 V_ipipstat.ipips_pdrops++;
133 m_freem(*m);
134 return IPPROTO_DONE;
135 }
136#endif
137 _ipip_input(*m, *offp, NULL);
138 return IPPROTO_DONE;
139}
140#endif /* INET6 */
141
142#ifdef INET
143/*
144 * Really only a wrapper for ipip_input(), for use with IPv4.
145 */
146void
147ip4_input(struct mbuf *m, int off)
148{
149#if 0
150 /* If we do not accept IP-in-IP explicitly, drop. */
151 if (!V_ipip_allow && (m->m_flags & M_IPSEC) == 0) {
152 DPRINTF(("%s: dropped due to policy\n", __func__));
153 V_ipipstat.ipips_pdrops++;
154 m_freem(m);
155 return;
156 }
157#endif
158 _ipip_input(m, off, NULL);
159}
160#endif /* INET */
161
162/*
163 * ipip_input gets called when we receive an IP{46} encapsulated packet,
164 * either because we got it at a real interface, or because AH or ESP
165 * were being used in tunnel mode (in which case the rcvif element will
166 * contain the address of the encX interface associated with the tunnel.
167 */
168
169static void
170_ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp)
171{
172 INIT_VNET_NET(curvnet);
173 INIT_VNET_IPSEC(curvnet);
174 register struct sockaddr_in *sin;
175 register struct ifnet *ifp;
176 register struct ifaddr *ifa;
177 struct ip *ipo;
178#ifdef INET6
179 register struct sockaddr_in6 *sin6;
180 struct ip6_hdr *ip6 = NULL;
181 u_int8_t itos;
182#endif
183 u_int8_t nxt;
184 int isr;
185 u_int8_t otos;
186 u_int8_t v;
187 int hlen;
188
189 V_ipipstat.ipips_ipackets++;
190
191 m_copydata(m, 0, 1, &v);
192
193 switch (v >> 4) {
194#ifdef INET
195 case 4:
196 hlen = sizeof(struct ip);
197 break;
198#endif /* INET */
199#ifdef INET6
200 case 6:
201 hlen = sizeof(struct ip6_hdr);
202 break;
203#endif
204 default:
205 V_ipipstat.ipips_family++;
206 m_freem(m);
207 return /* EAFNOSUPPORT */;
208 }
209
210 /* Bring the IP header in the first mbuf, if not there already */
211 if (m->m_len < hlen) {
212 if ((m = m_pullup(m, hlen)) == NULL) {
213 DPRINTF(("%s: m_pullup (1) failed\n", __func__));
214 V_ipipstat.ipips_hdrops++;
215 return;
216 }
217 }
218
219 ipo = mtod(m, struct ip *);
220
221#ifdef MROUTING
222 if (ipo->ip_v == IPVERSION && ipo->ip_p == IPPROTO_IPV4) {
223 if (IN_MULTICAST(((struct ip *)((char *) ipo + iphlen))->ip_dst.s_addr)) {
224 ipip_mroute_input (m, iphlen);
225 return;
226 }
227 }
228#endif /* MROUTING */
229
230 /* Keep outer ecn field. */
231 switch (v >> 4) {
232#ifdef INET
233 case 4:
234 otos = ipo->ip_tos;
235 break;
236#endif /* INET */
237#ifdef INET6
238 case 6:
239 otos = (ntohl(mtod(m, struct ip6_hdr *)->ip6_flow) >> 20) & 0xff;
240 break;
241#endif
242 default:
243 panic("ipip_input: unknown ip version %u (outer)", v>>4);
244 }
245
246 /* Remove outer IP header */
247 m_adj(m, iphlen);
248
249 /* Sanity check */
250 if (m->m_pkthdr.len < sizeof(struct ip)) {
251 V_ipipstat.ipips_hdrops++;
252 m_freem(m);
253 return;
254 }
255
256 m_copydata(m, 0, 1, &v);
257
258 switch (v >> 4) {
259#ifdef INET
260 case 4:
261 hlen = sizeof(struct ip);
262 break;
263#endif /* INET */
264
265#ifdef INET6
266 case 6:
267 hlen = sizeof(struct ip6_hdr);
268 break;
269#endif
270 default:
271 V_ipipstat.ipips_family++;
272 m_freem(m);
273 return; /* EAFNOSUPPORT */
274 }
275
276 /*
277 * Bring the inner IP header in the first mbuf, if not there already.
278 */
279 if (m->m_len < hlen) {
280 if ((m = m_pullup(m, hlen)) == NULL) {
281 DPRINTF(("%s: m_pullup (2) failed\n", __func__));
282 V_ipipstat.ipips_hdrops++;
283 return;
284 }
285 }
286
287 /*
288 * RFC 1853 specifies that the inner TTL should not be touched on
289 * decapsulation. There's no reason this comment should be here, but
290 * this is as good as any a position.
291 */
292
293 /* Some sanity checks in the inner IP header */
294 switch (v >> 4) {
295#ifdef INET
296 case 4:
297 ipo = mtod(m, struct ip *);
298 nxt = ipo->ip_p;
299 ip_ecn_egress(V_ip4_ipsec_ecn, &otos, &ipo->ip_tos);
300 break;
301#endif /* INET */
302#ifdef INET6
303 case 6:
304 ip6 = (struct ip6_hdr *) ipo;
305 nxt = ip6->ip6_nxt;
306 itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
307 ip_ecn_egress(V_ip6_ipsec_ecn, &otos, &itos);
308 ip6->ip6_flow &= ~htonl(0xff << 20);
309 ip6->ip6_flow |= htonl((u_int32_t) itos << 20);
310 break;
311#endif
312 default:
313 panic("ipip_input: unknown ip version %u (inner)", v>>4);
314 }
315
316 /* Check for local address spoofing. */
317 if ((m->m_pkthdr.rcvif == NULL ||
318 !(m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK)) &&
319 V_ipip_allow != 2) {
320 IFNET_RLOCK();
321 TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
322 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
323#ifdef INET
324 if (ipo) {
325 if (ifa->ifa_addr->sa_family !=
326 AF_INET)
327 continue;
328
329 sin = (struct sockaddr_in *) ifa->ifa_addr;
330
331 if (sin->sin_addr.s_addr ==
332 ipo->ip_src.s_addr) {
333 V_ipipstat.ipips_spoof++;
334 m_freem(m);
335 IFNET_RUNLOCK();
336 return;
337 }
338 }
339#endif /* INET */
340
341#ifdef INET6
342 if (ip6) {
343 if (ifa->ifa_addr->sa_family !=
344 AF_INET6)
345 continue;
346
347 sin6 = (struct sockaddr_in6 *) ifa->ifa_addr;
348
349 if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &ip6->ip6_src)) {
350 V_ipipstat.ipips_spoof++;
351 m_freem(m);
352 IFNET_RUNLOCK();
353 return;
354 }
355
356 }
357#endif /* INET6 */
358 }
359 }
360 IFNET_RUNLOCK();
361 }
362
363 /* Statistics */
364 V_ipipstat.ipips_ibytes += m->m_pkthdr.len - iphlen;
365
366#ifdef DEV_ENC
367 switch (v >> 4) {
368#ifdef INET
369 case 4:
370 ipsec_bpf(m, NULL, AF_INET, ENC_IN|ENC_AFTER);
371 break;
372#endif
373#ifdef INET6
374 case 6:
375 ipsec_bpf(m, NULL, AF_INET6, ENC_IN|ENC_AFTER);
376 break;
377#endif
378 default:
379 panic("%s: bogus ip version %u", __func__, v>>4);
380 }
381 /* pass the mbuf to enc0 for packet filtering */
382 if (ipsec_filter(&m, PFIL_IN, ENC_IN|ENC_AFTER) != 0)
383 return;
384#endif
385
386 /*
387 * Interface pointer stays the same; if no IPsec processing has
388 * been done (or will be done), this will point to a normal
389 * interface. Otherwise, it'll point to an enc interface, which
390 * will allow a packet filter to distinguish between secure and
391 * untrusted packets.
392 */
393
394 switch (v >> 4) {
395#ifdef INET
396 case 4:
397 isr = NETISR_IP;
398 break;
399#endif
400#ifdef INET6
401 case 6:
402 isr = NETISR_IPV6;
403 break;
404#endif
405 default:
406 panic("%s: bogus ip version %u", __func__, v>>4);
407 }
408
409 if (netisr_queue(isr, m)) { /* (0) on success. */
410 V_ipipstat.ipips_qfull++;
411 DPRINTF(("%s: packet dropped because of full queue\n",
412 __func__));
413 }
414}
415
416int
417ipip_output(
418 struct mbuf *m,
419 struct ipsecrequest *isr,
420 struct mbuf **mp,
421 int skip,
422 int protoff
423)
424{
425 INIT_VNET_IPSEC(curvnet);
426#ifdef INET
427 INIT_VNET_INET(curvnet);
428#endif /* INET */
429 struct secasvar *sav;
430 u_int8_t tp, otos;
431 struct secasindex *saidx;
432 int error;
433#ifdef INET
434 u_int8_t itos;
435 struct ip *ipo;
436#endif /* INET */
437#ifdef INET6
438 struct ip6_hdr *ip6, *ip6o;
439#endif /* INET6 */
440
441 sav = isr->sav;
442 IPSEC_ASSERT(sav != NULL, ("null SA"));
443 IPSEC_ASSERT(sav->sah != NULL, ("null SAH"));
444
445 /* XXX Deal with empty TDB source/destination addresses. */
446
447 m_copydata(m, 0, 1, &tp);
448 tp = (tp >> 4) & 0xff; /* Get the IP version number. */
449
450 saidx = &sav->sah->saidx;
451 switch (saidx->dst.sa.sa_family) {
452#ifdef INET
453 case AF_INET:
454 if (saidx->src.sa.sa_family != AF_INET ||
455 saidx->src.sin.sin_addr.s_addr == INADDR_ANY ||
456 saidx->dst.sin.sin_addr.s_addr == INADDR_ANY) {
457 DPRINTF(("%s: unspecified tunnel endpoint "
458 "address in SA %s/%08lx\n", __func__,
459 ipsec_address(&saidx->dst),
460 (u_long) ntohl(sav->spi)));
461 V_ipipstat.ipips_unspec++;
462 error = EINVAL;
463 goto bad;
464 }
465
466 M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
467 if (m == 0) {
468 DPRINTF(("%s: M_PREPEND failed\n", __func__));
469 V_ipipstat.ipips_hdrops++;
470 error = ENOBUFS;
471 goto bad;
472 }
473
474 ipo = mtod(m, struct ip *);
475
476 ipo->ip_v = IPVERSION;
477 ipo->ip_hl = 5;
478 ipo->ip_len = htons(m->m_pkthdr.len);
479 ipo->ip_ttl = V_ip_defttl;
480 ipo->ip_sum = 0;
481 ipo->ip_src = saidx->src.sin.sin_addr;
482 ipo->ip_dst = saidx->dst.sin.sin_addr;
483
484 ipo->ip_id = ip_newid();
485
486 /* If the inner protocol is IP... */
487 if (tp == IPVERSION) {
488 /* Save ECN notification */
489 m_copydata(m, sizeof(struct ip) +
490 offsetof(struct ip, ip_tos),
491 sizeof(u_int8_t), (caddr_t) &itos);
492
493 ipo->ip_p = IPPROTO_IPIP;
494
495 /*
496 * We should be keeping tunnel soft-state and
497 * send back ICMPs if needed.
498 */
499 m_copydata(m, sizeof(struct ip) +
500 offsetof(struct ip, ip_off),
501 sizeof(u_int16_t), (caddr_t) &ipo->ip_off);
502 ipo->ip_off = ntohs(ipo->ip_off);
503 ipo->ip_off &= ~(IP_DF | IP_MF | IP_OFFMASK);
504 ipo->ip_off = htons(ipo->ip_off);
505 }
506#ifdef INET6
507 else if (tp == (IPV6_VERSION >> 4)) {
508 u_int32_t itos32;
509
510 /* Save ECN notification. */
511 m_copydata(m, sizeof(struct ip) +
512 offsetof(struct ip6_hdr, ip6_flow),
513 sizeof(u_int32_t), (caddr_t) &itos32);
514 itos = ntohl(itos32) >> 20;
515 ipo->ip_p = IPPROTO_IPV6;
516 ipo->ip_off = 0;
517 }
518#endif /* INET6 */
519 else {
520 goto nofamily;
521 }
522
523 otos = 0;
524 ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
525 ipo->ip_tos = otos;
526 break;
527#endif /* INET */
528
529#ifdef INET6
530 case AF_INET6:
531 if (IN6_IS_ADDR_UNSPECIFIED(&saidx->dst.sin6.sin6_addr) ||
532 saidx->src.sa.sa_family != AF_INET6 ||
533 IN6_IS_ADDR_UNSPECIFIED(&saidx->src.sin6.sin6_addr)) {
534 DPRINTF(("%s: unspecified tunnel endpoint "
535 "address in SA %s/%08lx\n", __func__,
536 ipsec_address(&saidx->dst),
537 (u_long) ntohl(sav->spi)));
538 V_ipipstat.ipips_unspec++;
539 error = ENOBUFS;
540 goto bad;
541 }
542
543 /* scoped address handling */
544 ip6 = mtod(m, struct ip6_hdr *);
545 if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
546 ip6->ip6_src.s6_addr16[1] = 0;
547 if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
548 ip6->ip6_dst.s6_addr16[1] = 0;
549
550 M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT);
551 if (m == 0) {
552 DPRINTF(("%s: M_PREPEND failed\n", __func__));
553 V_ipipstat.ipips_hdrops++;
554 error = ENOBUFS;
555 goto bad;
556 }
557
558 /* Initialize IPv6 header */
559 ip6o = mtod(m, struct ip6_hdr *);
560 ip6o->ip6_flow = 0;
561 ip6o->ip6_vfc &= ~IPV6_VERSION_MASK;
562 ip6o->ip6_vfc |= IPV6_VERSION;
563 ip6o->ip6_plen = htons(m->m_pkthdr.len);
564 ip6o->ip6_hlim = V_ip_defttl;
565 ip6o->ip6_dst = saidx->dst.sin6.sin6_addr;
566 ip6o->ip6_src = saidx->src.sin6.sin6_addr;
567
568#ifdef INET
569 if (tp == IPVERSION) {
570 /* Save ECN notification */
571 m_copydata(m, sizeof(struct ip6_hdr) +
572 offsetof(struct ip, ip_tos), sizeof(u_int8_t),
573 (caddr_t) &itos);
574
575 /* This is really IPVERSION. */
576 ip6o->ip6_nxt = IPPROTO_IPIP;
577 } else
578#endif /* INET */
579 if (tp == (IPV6_VERSION >> 4)) {
580 u_int32_t itos32;
581
582 /* Save ECN notification. */
583 m_copydata(m, sizeof(struct ip6_hdr) +
584 offsetof(struct ip6_hdr, ip6_flow),
585 sizeof(u_int32_t), (caddr_t) &itos32);
586 itos = ntohl(itos32) >> 20;
587
588 ip6o->ip6_nxt = IPPROTO_IPV6;
589 } else {
590 goto nofamily;
591 }
592
593 otos = 0;
594 ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
595 ip6o->ip6_flow |= htonl((u_int32_t) otos << 20);
596 break;
597#endif /* INET6 */
598
599 default:
600nofamily:
601 DPRINTF(("%s: unsupported protocol family %u\n", __func__,
602 saidx->dst.sa.sa_family));
603 V_ipipstat.ipips_family++;
604 error = EAFNOSUPPORT; /* XXX diffs from openbsd */
605 goto bad;
606 }
607
608 V_ipipstat.ipips_opackets++;
609 *mp = m;
610
611#ifdef INET
612 if (saidx->dst.sa.sa_family == AF_INET) {
613#if 0
614 if (sav->tdb_xform->xf_type == XF_IP4)
615 tdb->tdb_cur_bytes +=
616 m->m_pkthdr.len - sizeof(struct ip);
617#endif
618 V_ipipstat.ipips_obytes += m->m_pkthdr.len - sizeof(struct ip);
619 }
620#endif /* INET */
621
622#ifdef INET6
623 if (saidx->dst.sa.sa_family == AF_INET6) {
624#if 0
625 if (sav->tdb_xform->xf_type == XF_IP4)
626 tdb->tdb_cur_bytes +=
627 m->m_pkthdr.len - sizeof(struct ip6_hdr);
628#endif
629 V_ipipstat.ipips_obytes +=
630 m->m_pkthdr.len - sizeof(struct ip6_hdr);
631 }
632#endif /* INET6 */
633
634 return 0;
635bad:
636 if (m)
637 m_freem(m);
638 *mp = NULL;
639 return (error);
640}
641
642#ifdef IPSEC
643static int
644ipe4_init(struct secasvar *sav, struct xformsw *xsp)
645{
646 sav->tdb_xform = xsp;
647 return 0;
648}
649
650static int
651ipe4_zeroize(struct secasvar *sav)
652{
653 sav->tdb_xform = NULL;
654 return 0;
655}
656
657static int
658ipe4_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
659{
660 /* This is a rather serious mistake, so no conditional printing. */
661 printf("%s: should never be called\n", __func__);
662 if (m)
663 m_freem(m);
664 return EOPNOTSUPP;
665}
666
667static struct xformsw ipe4_xformsw = {
668 XF_IP4, 0, "IPv4 Simple Encapsulation",
669 ipe4_init, ipe4_zeroize, ipe4_input, ipip_output,
670};
671
672extern struct domain inetdomain;
673static struct protosw ipe4_protosw = {
674 .pr_type = SOCK_RAW,
675 .pr_domain = &inetdomain,
676 .pr_protocol = IPPROTO_IPV4,
677 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
678 .pr_input = ip4_input,
679 .pr_ctloutput = rip_ctloutput,
680 .pr_usrreqs = &rip_usrreqs
681};
682#ifdef INET6
683static struct ip6protosw ipe6_protosw = {
684 .pr_type = SOCK_RAW,
685 .pr_domain = &inetdomain,
686 .pr_protocol = IPPROTO_IPV6,
687 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
688 .pr_input = ip4_input6,
689 .pr_ctloutput = rip_ctloutput,
690 .pr_usrreqs = &rip_usrreqs
691};
692#endif
693
694/*
695 * Check the encapsulated packet to see if we want it
696 */
697static int
698ipe4_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
699{
700 /*
701 * Only take packets coming from IPSEC tunnels; the rest
702 * must be handled by the gif tunnel code. Note that we
703 * also return a minimum priority when we want the packet
704 * so any explicit gif tunnels take precedence.
705 */
706 return ((m->m_flags & M_IPSEC) != 0 ? 1 : 0);
707}
708
709static int
710ipe4_iattach(const void *unused __unused)
711{
712 INIT_VNET_IPSEC(curvnet);
713
714 V_ipip_allow = 0;
715 return (0);
716}
717
718static void
719ipe4_attach(void)
720{
721
722 xform_register(&ipe4_xformsw);
723 /* attach to encapsulation framework */
724 /* XXX save return cookie for detach on module remove */
725 (void) encap_attach_func(AF_INET, -1,
726 ipe4_encapcheck, &ipe4_protosw, NULL);
727#ifdef INET6
728 (void) encap_attach_func(AF_INET6, -1,
729 ipe4_encapcheck, (struct protosw *)&ipe6_protosw, NULL);
730#endif
731#ifndef VIMAGE_GLOBALS
732 vnet_mod_register(&vnet_ipip_modinfo);
733#else
734 ipe4_iattach(NULL);
735#endif
736}
737SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL);
738#endif /* IPSEC */