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