kernel: Use NULL for pointers.
[dragonfly.git] / sys / netproto / ipsec / xform_ipip.c
1 /*      $FreeBSD: src/sys/netipsec/xform_ipip.c,v 1.3.2.1 2003/01/24 05:11:36 sam Exp $ */
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
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/mbuf.h>
48 #include <sys/socket.h>
49 #include <sys/kernel.h>
50 #include <sys/protosw.h>
51 #include <sys/sysctl.h>
52
53 #include <net/if.h>
54 #include <net/route.h>
55 #include <net/netisr.h>
56
57 #include <netinet/in.h>
58 #include <netinet/in_systm.h>
59 #include <netinet/in_var.h>
60 #include <netinet/ip.h>
61 #include <netinet/ip_ecn.h>
62 #include <netinet/ip_var.h>
63 #include <netinet/ip_encap.h>
64
65 #include <netproto/ipsec/ipsec.h>
66 #include <netproto/ipsec/xform.h>
67
68 #include <netproto/ipsec/ipip_var.h>
69
70 #ifdef MROUTING
71 #include <netinet/ip_mroute.h>
72 #endif
73
74 #ifdef INET6
75 #include <netinet/ip6.h>
76 #include <netproto/ipsec/ipsec6.h>
77 #include <netinet6/ip6_ecn.h>
78 #include <netinet6/in6_var.h>
79 #include <netinet6/ip6protosw.h>
80 #endif
81
82 #include <netproto/ipsec/key.h>
83 #include <netproto/ipsec/key_debug.h>
84
85 #include <machine/stdarg.h>
86
87 typedef void    pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */
88
89 /*
90  * We can control the acceptance of IP4 packets by altering the sysctl
91  * net.inet.ipip.allow value.  Zero means drop them, all else is acceptance.
92  */
93 int     ipip_allow = 0;
94 struct  ipipstat ipipstat;
95
96 SYSCTL_DECL(_net_inet_ipip);
97 SYSCTL_INT(_net_inet_ipip, OID_AUTO,
98         ipip_allow,     CTLFLAG_RW,     &ipip_allow,    0, "");
99 SYSCTL_STRUCT(_net_inet_ipip, IPSECCTL_STATS,
100         stats,          CTLFLAG_RD,     &ipipstat,      ipipstat, "");
101
102 /* XXX IPCOMP */
103 #define M_IPSEC (M_AUTHIPHDR|M_AUTHIPDGM|M_DECRYPTED)
104
105 static void _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp);
106
107 #ifdef INET6
108 /*
109  * Really only a wrapper for ipip_input(), for use with IPv6.
110  */
111 int
112 ip4_input6(struct mbuf **m, int *offp, int proto)
113 {
114 #if 0
115         /* If we do not accept IP-in-IP explicitly, drop.  */
116         if (!ipip_allow && ((*m)->m_flags & M_IPSEC) == 0) {
117                 DPRINTF(("ip4_input6: dropped due to policy\n"));
118                 ipipstat.ipips_pdrops++;
119                 m_freem(*m);
120                 return IPPROTO_DONE;
121         }
122 #endif
123         _ipip_input(*m, *offp, NULL);
124         return IPPROTO_DONE;
125 }
126 #endif /* INET6 */
127
128 #ifdef INET
129 /*
130  * Really only a wrapper for ipip_input(), for use with IPv4.
131  */
132 void
133 ip4_input(struct mbuf *m, ...)
134 {
135         __va_list ap;
136         int iphlen;
137
138 #if 0
139         /* If we do not accept IP-in-IP explicitly, drop.  */
140         if (!ipip_allow && (m->m_flags & M_IPSEC) == 0) {
141                 DPRINTF(("ip4_input: dropped due to policy\n"));
142                 ipipstat.ipips_pdrops++;
143                 m_freem(m);
144                 return;
145         }
146 #endif
147         __va_start(ap, m);
148         iphlen = __va_arg(ap, int);
149         __va_end(ap);
150
151         _ipip_input(m, iphlen, NULL);
152 }
153 #endif /* INET */
154
155 /*
156  * ipip_input gets called when we receive an IP{46} encapsulated packet,
157  * either because we got it at a real interface, or because AH or ESP
158  * were being used in tunnel mode (in which case the rcvif element will
159  * contain the address of the encX interface associated with the tunnel.
160  */
161
162 static void
163 _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp)
164 {
165         struct sockaddr_in *sin;
166         struct ifnet *ifp;
167         struct ifaddr *ifa;
168         struct ip *ipo;
169 #ifdef INET6
170         struct sockaddr_in6 *sin6;
171         struct ip6_hdr *ip6 = NULL;
172         u_int8_t itos;
173 #endif
174         u_int8_t nxt;
175         int isr;
176         u_int8_t otos;
177         u_int8_t v;
178         int hlen;
179
180         ipipstat.ipips_ipackets++;
181
182         m_copydata(m, 0, 1, &v);
183
184         switch (v >> 4) {
185 #ifdef INET
186         case 4:
187                 hlen = sizeof(struct ip);
188                 break;
189 #endif /* INET */
190 #ifdef INET6
191         case 6:
192                 hlen = sizeof(struct ip6_hdr);
193                 break;
194 #endif
195         default:
196                 DPRINTF(("_ipip_input: bad protocol version 0x%x (%u) "
197                         "for outer header\n", v, v>>4));
198                 ipipstat.ipips_family++;
199                 m_freem(m);
200                 return /* EAFNOSUPPORT */;
201         }
202
203         /* Bring the IP header in the first mbuf, if not there already */
204         if (m->m_len < hlen) {
205                 if ((m = m_pullup(m, hlen)) == NULL) {
206                         DPRINTF(("ipip_input: m_pullup (1) failed\n"));
207                         ipipstat.ipips_hdrops++;
208                         return;
209                 }
210         }
211
212         ipo = mtod(m, struct ip *);
213
214 #ifdef MROUTING
215         if (ipo->ip_v == IPVERSION && ipo->ip_p == IPPROTO_IPV4) {
216                 if (IN_MULTICAST(((struct ip *)((char *) ipo + iphlen))->ip_dst.s_addr)) {
217                         ipip_mroute_input (m, iphlen);
218                         return;
219                 }
220         }
221 #endif /* MROUTING */
222
223         /* Keep outer ecn field. */
224         switch (v >> 4) {
225 #ifdef INET
226         case 4:
227                 otos = ipo->ip_tos;
228                 break;
229 #endif /* INET */
230 #ifdef INET6
231         case 6:
232                 otos = (ntohl(mtod(m, struct ip6_hdr *)->ip6_flow) >> 20) & 0xff;
233                 break;
234 #endif
235         default:
236                 panic("ipip_input: unknown ip version %u (outer)", v>>4);
237         }
238
239         /* Remove outer IP header */
240         m_adj(m, iphlen);
241
242         /* Sanity check */
243         if (m->m_pkthdr.len < sizeof(struct ip))  {
244                 ipipstat.ipips_hdrops++;
245                 m_freem(m);
246                 return;
247         }
248
249         m_copydata(m, 0, 1, &v);
250
251         switch (v >> 4) {
252 #ifdef INET
253         case 4:
254                 hlen = sizeof(struct ip);
255                 break;
256 #endif /* INET */
257
258 #ifdef INET6
259         case 6:
260                 hlen = sizeof(struct ip6_hdr);
261                 break;
262 #endif
263         default:
264                 DPRINTF(("_ipip_input: bad protocol version 0x%x (%u) "
265                         "for inner header\n", v, v>>4));
266                 ipipstat.ipips_family++;
267                 m_freem(m);
268                 return; /* EAFNOSUPPORT */
269         }
270
271         /*
272          * Bring the inner IP header in the first mbuf, if not there already.
273          */
274         if (m->m_len < hlen) {
275                 if ((m = m_pullup(m, hlen)) == NULL) {
276                         DPRINTF(("ipip_input: m_pullup (2) failed\n"));
277                         ipipstat.ipips_hdrops++;
278                         return;
279                 }
280         }
281
282         /*
283          * RFC 1853 specifies that the inner TTL should not be touched on
284          * decapsulation. There's no reason this comment should be here, but
285          * this is as good as any a position.
286          */
287
288         /* Some sanity checks in the inner IP header */
289         switch (v >> 4) {
290 #ifdef INET
291         case 4:
292                 ipo = mtod(m, struct ip *);
293                 nxt = ipo->ip_p;
294                 ip_ecn_egress(ip4_ipsec_ecn, &otos, &ipo->ip_tos);
295                 break;
296 #endif /* INET */
297 #ifdef INET6
298         case 6:
299                 ip6 = (struct ip6_hdr *) ipo;
300                 nxt = ip6->ip6_nxt;
301                 itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
302                 ip_ecn_egress(ip6_ipsec_ecn, &otos, &itos);
303                 ip6->ip6_flow &= ~htonl(0xff << 20);
304                 ip6->ip6_flow |= htonl((u_int32_t) itos << 20);
305                 break;
306 #endif
307         default:
308                 panic("ipip_input: unknown ip version %u (inner)", v>>4);
309         }
310
311         /* Check for local address spoofing. */
312         if ((m->m_pkthdr.rcvif == NULL ||
313             !(m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK)) &&
314             ipip_allow != 2) {
315                 TAILQ_FOREACH(ifp, &ifnet, if_link) {
316                         TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_link) {
317 #ifdef INET
318                                 if (ipo) {
319                                         if (ifa->ifa_addr->sa_family !=
320                                             AF_INET)
321                                                 continue;
322
323                                         sin = (struct sockaddr_in *) ifa->ifa_addr;
324
325                                         if (sin->sin_addr.s_addr ==
326                                             ipo->ip_src.s_addr) {
327                                                 ipipstat.ipips_spoof++;
328                                                 m_freem(m);
329                                                 return;
330                                         }
331                                 }
332 #endif /* INET */
333
334 #ifdef INET6
335                                 if (ip6) {
336                                         if (ifa->ifa_addr->sa_family !=
337                                             AF_INET6)
338                                                 continue;
339
340                                         sin6 = (struct sockaddr_in6 *) ifa->ifa_addr;
341
342                                         if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &ip6->ip6_src)) {
343                                                 ipipstat.ipips_spoof++;
344                                                 m_freem(m);
345                                                 return;
346                                         }
347
348                                 }
349 #endif /* INET6 */
350                         }
351                 }
352         }
353
354         /* Statistics */
355         ipipstat.ipips_ibytes += m->m_pkthdr.len - iphlen;
356
357         /*
358          * Interface pointer stays the same; if no IPsec processing has
359          * been done (or will be done), this will point to a normal
360          * interface. Otherwise, it'll point to an enc interface, which
361          * will allow a packet filter to distinguish between secure and
362          * untrusted packets.
363          */
364
365         switch (v >> 4) {
366 #ifdef INET
367         case 4:
368                 isr = NETISR_IP;
369                 break;
370 #endif
371 #ifdef INET6
372         case 6:
373                 isr = NETISR_IPV6;
374                 break;
375 #endif
376         default:
377                 panic("ipip_input: should never reach here");
378         }
379
380         if (netisr_queue(isr, m)) {
381                 ipipstat.ipips_qfull++;
382
383                 DPRINTF(("ipip_input: packet dropped because of full queue\n"));
384         }
385 }
386
387 int
388 ipip_output(
389         struct mbuf *m,
390         struct ipsecrequest *isr,
391         struct mbuf **mp,
392         int skip,
393         int protoff
394 )
395 {
396         struct secasvar *sav;
397         u_int8_t tp, otos;
398         struct secasindex *saidx;
399         int error;
400 #ifdef INET
401         u_int8_t itos;
402         struct ip *ipo;
403 #endif /* INET */
404 #ifdef INET6
405         struct ip6_hdr *ip6, *ip6o;
406 #endif /* INET6 */
407
408         sav = isr->sav;
409         KASSERT(sav != NULL, ("ipip_output: null SA"));
410         KASSERT(sav->sah != NULL, ("ipip_output: null SAH"));
411
412         /* XXX Deal with empty TDB source/destination addresses. */
413
414         m_copydata(m, 0, 1, &tp);
415         tp = (tp >> 4) & 0xff;  /* Get the IP version number. */
416
417         saidx = &sav->sah->saidx;
418         switch (saidx->dst.sa.sa_family) {
419 #ifdef INET
420         case AF_INET:
421                 if (saidx->src.sa.sa_family != AF_INET ||
422                     saidx->src.sin.sin_addr.s_addr == INADDR_ANY ||
423                     saidx->dst.sin.sin_addr.s_addr == INADDR_ANY) {
424                         DPRINTF(("ipip_output: unspecified tunnel endpoint "
425                             "address in SA %s/%08lx\n",
426                             ipsec_address(&saidx->dst),
427                             (u_long) ntohl(sav->spi)));
428                         ipipstat.ipips_unspec++;
429                         error = EINVAL;
430                         goto bad;
431                 }
432
433                 M_PREPEND(m, sizeof(struct ip), MB_DONTWAIT);
434                 if (m == NULL) {
435                         DPRINTF(("ipip_output: M_PREPEND failed\n"));
436                         ipipstat.ipips_hdrops++;
437                         error = ENOBUFS;
438                         goto bad;
439                 }
440
441                 ipo = mtod(m, struct ip *);
442
443                 ipo->ip_v = IPVERSION;
444                 ipo->ip_hl = 5;
445                 ipo->ip_len = htons(m->m_pkthdr.len);
446                 ipo->ip_ttl = ip_defttl;
447                 ipo->ip_sum = 0;
448                 ipo->ip_src = saidx->src.sin.sin_addr;
449                 ipo->ip_dst = saidx->dst.sin.sin_addr;
450
451                 ipo->ip_id = ip_newid();
452
453                 /* If the inner protocol is IP... */
454                 if (tp == IPVERSION) {
455                         /* Save ECN notification */
456                         m_copydata(m, sizeof(struct ip) +
457                             offsetof(struct ip, ip_tos),
458                             sizeof(u_int8_t), (caddr_t) &itos);
459
460                         ipo->ip_p = IPPROTO_IPIP;
461
462                         /*
463                          * We should be keeping tunnel soft-state and
464                          * send back ICMPs if needed.
465                          */
466                         m_copydata(m, sizeof(struct ip) +
467                             offsetof(struct ip, ip_off),
468                             sizeof(u_int16_t), (caddr_t) &ipo->ip_off);
469                         ipo->ip_off = ntohs(ipo->ip_off);
470                         ipo->ip_off &= ~(IP_DF | IP_MF | IP_OFFMASK);
471                         ipo->ip_off = htons(ipo->ip_off);
472                 }
473 #ifdef INET6
474                 else if (tp == (IPV6_VERSION >> 4)) {
475                         u_int32_t itos32;
476
477                         /* Save ECN notification. */
478                         m_copydata(m, sizeof(struct ip) +
479                             offsetof(struct ip6_hdr, ip6_flow),
480                             sizeof(u_int32_t), (caddr_t) &itos32);
481                         itos = ntohl(itos32) >> 20;
482                         ipo->ip_p = IPPROTO_IPV6;
483                         ipo->ip_off = 0;
484                 }
485 #endif /* INET6 */
486                 else {
487                         goto nofamily;
488                 }
489
490                 otos = 0;
491                 ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
492                 ipo->ip_tos = otos;
493                 break;
494 #endif /* INET */
495
496 #ifdef INET6
497         case AF_INET6:
498                 if (IN6_IS_ADDR_UNSPECIFIED(&saidx->dst.sin6.sin6_addr) ||
499                     saidx->src.sa.sa_family != AF_INET6 ||
500                     IN6_IS_ADDR_UNSPECIFIED(&saidx->src.sin6.sin6_addr)) {
501                         DPRINTF(("ipip_output: unspecified tunnel endpoint "
502                             "address in SA %s/%08lx\n",
503                             ipsec_address(&saidx->dst),
504                             (u_long) ntohl(sav->spi)));
505                         ipipstat.ipips_unspec++;
506                         error = ENOBUFS;
507                         goto bad;
508                 }
509
510                 /* scoped address handling */
511                 ip6 = mtod(m, struct ip6_hdr *);
512                 if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
513                         ip6->ip6_src.s6_addr16[1] = 0;
514                 if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
515                         ip6->ip6_dst.s6_addr16[1] = 0;
516
517                 M_PREPEND(m, sizeof(struct ip6_hdr), MB_DONTWAIT);
518                 if (m == NULL) {
519                         DPRINTF(("ipip_output: M_PREPEND failed\n"));
520                         ipipstat.ipips_hdrops++;
521                         *mp = NULL;
522                         error = ENOBUFS;
523                         goto bad;
524                 }
525
526                 /* Initialize IPv6 header */
527                 ip6o = mtod(m, struct ip6_hdr *);
528                 ip6o->ip6_flow = 0;
529                 ip6o->ip6_vfc &= ~IPV6_VERSION_MASK;
530                 ip6o->ip6_vfc |= IPV6_VERSION;
531                 ip6o->ip6_plen = htons(m->m_pkthdr.len);
532                 ip6o->ip6_hlim = ip_defttl;
533                 ip6o->ip6_dst = saidx->dst.sin6.sin6_addr;
534                 ip6o->ip6_src = saidx->src.sin6.sin6_addr;
535
536 #ifdef INET
537                 if (tp == IPVERSION) {
538                         /* Save ECN notification */
539                         m_copydata(m, sizeof(struct ip6_hdr) +
540                             offsetof(struct ip, ip_tos), sizeof(u_int8_t),
541                             (caddr_t) &itos);
542
543                         /* This is really IPVERSION. */
544                         ip6o->ip6_nxt = IPPROTO_IPIP;
545                 } else
546 #endif /* INET */
547                         if (tp == (IPV6_VERSION >> 4)) {
548                                 u_int32_t itos32;
549
550                                 /* Save ECN notification. */
551                                 m_copydata(m, sizeof(struct ip6_hdr) +
552                                     offsetof(struct ip6_hdr, ip6_flow),
553                                     sizeof(u_int32_t), (caddr_t) &itos32);
554                                 itos = ntohl(itos32) >> 20;
555
556                                 ip6o->ip6_nxt = IPPROTO_IPV6;
557                         } else {
558                                 goto nofamily;
559                         }
560
561                 otos = 0;
562                 ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
563                 ip6o->ip6_flow |= htonl((u_int32_t) otos << 20);
564                 break;
565 #endif /* INET6 */
566
567         default:
568 nofamily:
569                 DPRINTF(("ipip_output: unsupported protocol family %u\n",
570                     saidx->dst.sa.sa_family));
571                 ipipstat.ipips_family++;
572                 error = EAFNOSUPPORT;           /* XXX diffs from openbsd */
573                 goto bad;
574         }
575
576         ipipstat.ipips_opackets++;
577         *mp = m;
578
579 #ifdef INET
580         if (saidx->dst.sa.sa_family == AF_INET) {
581 #if 0
582                 if (sav->tdb_xform->xf_type == XF_IP4)
583                         tdb->tdb_cur_bytes +=
584                             m->m_pkthdr.len - sizeof(struct ip);
585 #endif
586                 ipipstat.ipips_obytes += m->m_pkthdr.len - sizeof(struct ip);
587         }
588 #endif /* INET */
589
590 #ifdef INET6
591         if (saidx->dst.sa.sa_family == AF_INET6) {
592 #if 0
593                 if (sav->tdb_xform->xf_type == XF_IP4)
594                         tdb->tdb_cur_bytes +=
595                             m->m_pkthdr.len - sizeof(struct ip6_hdr);
596 #endif
597                 ipipstat.ipips_obytes +=
598                     m->m_pkthdr.len - sizeof(struct ip6_hdr);
599         }
600 #endif /* INET6 */
601
602         return 0;
603 bad:
604         if (m)
605                 m_freem(m), *mp = NULL;
606         return (error);
607 }
608
609 #ifdef FAST_IPSEC
610 static int
611 ipe4_init(struct secasvar *sav, struct xformsw *xsp)
612 {
613         sav->tdb_xform = xsp;
614         return 0;
615 }
616
617 static int
618 ipe4_zeroize(struct secasvar *sav)
619 {
620         sav->tdb_xform = NULL;
621         return 0;
622 }
623
624 static int
625 ipe4_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
626 {
627         /* This is a rather serious mistake, so no conditional printing. */
628         kprintf("ipe4_input: should never be called\n");
629         if (m)
630                 m_freem(m);
631         return EOPNOTSUPP;
632 }
633
634 static struct xformsw ipe4_xformsw = {
635         XF_IP4,         0,              "IPv4 Simple Encapsulation",
636         ipe4_init,      ipe4_zeroize,   ipe4_input,     ipip_output,
637 };
638
639 extern struct domain inetdomain;
640 static struct protosw ipe4_protosw[] = {
641 { SOCK_RAW,     &inetdomain,    IPPROTO_IPV4,   PR_ATOMIC|PR_ADDR|PR_LASTHDR,
642   ip4_input,    0,              0,              rip_ctloutput,
643   cpu0_soport,  NULL,
644   0,            0,              0,              0,
645   &rip_usrreqs
646 },
647 #ifdef INET6
648 { SOCK_RAW,     &inetdomain,    IPPROTO_IPV6,   PR_ATOMIC|PR_ADDR|PR_LASTHDR,
649   ip4_input,
650                 0,              0,              rip_ctloutput,
651   cpu0_soport,
652   0,            0,              0,              0,
653   &rip_usrreqs
654 }
655 #endif
656 };
657
658 /*
659  * Check the encapsulated packet to see if we want it
660  */
661 static int
662 ipe4_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
663 {
664         /*
665          * Only take packets coming from IPSEC tunnels; the rest
666          * must be handled by the gif tunnel code.  Note that we
667          * also return a minimum priority when we want the packet
668          * so any explicit gif tunnels take precedence.
669          */
670         return ((m->m_flags & M_IPSEC) != 0 ? 1 : 0);
671 }
672
673 static void
674 ipe4_attach(void)
675 {
676         xform_register(&ipe4_xformsw);
677         /* attach to encapsulation framework */
678         /* XXX save return cookie for detach on module remove */
679         encap_attach_func(AF_INET, -1,
680                 ipe4_encapcheck, (struct protosw*) &ipe4_protosw[0], NULL);
681 #ifdef INET6
682         encap_attach_func(AF_INET6, -1,
683                 ipe4_encapcheck, (struct protosw*) &ipe4_protosw[1], NULL);
684 #endif
685 }
686 SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL);
687 #endif  /* FAST_IPSEC */