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