The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netipsec/xform_ipip.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 8f5d3641c7731d7da81582ac6e026e06


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.