2 /* $OpenBSD: ipsec_input.c,v 1.63 2003/02/20 18:35:43 deraadt Exp $ */
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).
8 * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
11 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
12 * by Angelos D. Keromytis.
14 * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
17 * Additional features in 1999 by Angelos D. Keromytis.
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.
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
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
40 * IPsec input processing.
44 #include "opt_inet6.h"
45 #include "opt_ipsec.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
51 #include <sys/domain.h>
52 #include <sys/protosw.h>
53 #include <sys/socket.h>
54 #include <sys/errno.h>
55 #include <sys/syslog.h>
58 #include <net/route.h>
59 #include <net/netisr.h>
61 #include <netinet/in.h>
62 #include <netinet/in_systm.h>
63 #include <netinet/ip.h>
64 #include <netinet/ip_var.h>
65 #include <netinet/in_var.h>
67 #include <netinet/ip6.h>
69 #include <netinet6/ip6_var.h>
71 #include <netinet/in_pcb.h>
73 #include <netinet/icmp6.h>
76 #include <netipsec/ipsec.h>
78 #include <netipsec/ipsec6.h>
80 #include <netipsec/ah_var.h>
81 #include <netipsec/esp.h>
82 #include <netipsec/esp_var.h>
83 #include <netipsec/ipcomp_var.h>
85 #include <netipsec/key.h>
86 #include <netipsec/keydb.h>
88 #include <netipsec/xform.h>
89 #include <netinet6/ip6protosw.h>
91 #include <machine/in_cksum.h>
92 #include <machine/stdarg.h>
94 #define IPSEC_ISTAT(p,x,y,z) ((p) == IPPROTO_ESP ? (x)++ : \
95 (p) == IPPROTO_AH ? (y)++ : (z)++)
97 static void ipsec4_common_ctlinput(int, struct sockaddr *, void *, int);
100 * ipsec_common_input gets called when an IPsec-protected packet
101 * is received by IPv4 or IPv6. It's job is to find the right SA
102 # and call the appropriate transform. The transform callback
103 * takes care of further processing (like ingress filtering).
106 ipsec_common_input(struct mbuf *m, int skip, int protoff, int af, int sproto)
108 union sockaddr_union dst_address;
109 struct secasvar *sav;
113 IPSEC_ISTAT(sproto, espstat.esps_input, ahstat.ahs_input,
114 ipcompstat.ipcomps_input);
116 IPSEC_ASSERT(m != NULL, ("null packet"));
118 if ((sproto == IPPROTO_ESP && !esp_enable) ||
119 (sproto == IPPROTO_AH && !ah_enable) ||
120 (sproto == IPPROTO_IPCOMP && !ipcomp_enable)) {
122 IPSEC_ISTAT(sproto, espstat.esps_pdrops, ahstat.ahs_pdrops,
123 ipcompstat.ipcomps_pdrops);
127 if (m->m_pkthdr.len - skip < 2 * sizeof (u_int32_t)) {
129 IPSEC_ISTAT(sproto, espstat.esps_hdrops, ahstat.ahs_hdrops,
130 ipcompstat.ipcomps_hdrops);
131 DPRINTF(("%s: packet too small\n", __func__));
135 /* Retrieve the SPI from the relevant IPsec header */
136 if (sproto == IPPROTO_ESP)
137 m_copydata(m, skip, sizeof(u_int32_t), (caddr_t) &spi);
138 else if (sproto == IPPROTO_AH)
139 m_copydata(m, skip + sizeof(u_int32_t), sizeof(u_int32_t),
141 else if (sproto == IPPROTO_IPCOMP) {
143 m_copydata(m, skip + sizeof(u_int16_t), sizeof(u_int16_t),
145 spi = ntohl(htons(cpi));
149 * Find the SA and (indirectly) call the appropriate
150 * kernel crypto routine. The resulting mbuf chain is a valid
151 * IP packet ready to go through input processing.
153 bzero(&dst_address, sizeof (dst_address));
154 dst_address.sa.sa_family = af;
158 dst_address.sin.sin_len = sizeof(struct sockaddr_in);
159 m_copydata(m, offsetof(struct ip, ip_dst),
160 sizeof(struct in_addr),
161 (caddr_t) &dst_address.sin.sin_addr);
166 dst_address.sin6.sin6_len = sizeof(struct sockaddr_in6);
167 m_copydata(m, offsetof(struct ip6_hdr, ip6_dst),
168 sizeof(struct in6_addr),
169 (caddr_t) &dst_address.sin6.sin6_addr);
173 DPRINTF(("%s: unsupported protocol family %u\n", __func__, af));
175 IPSEC_ISTAT(sproto, espstat.esps_nopf, ahstat.ahs_nopf,
176 ipcompstat.ipcomps_nopf);
180 /* NB: only pass dst since key_allocsa follows RFC2401 */
181 sav = KEY_ALLOCSA(&dst_address, sproto, spi);
183 DPRINTF(("%s: no key association found for SA %s/%08lx/%u\n",
184 __func__, ipsec_address(&dst_address),
185 (u_long) ntohl(spi), sproto));
186 IPSEC_ISTAT(sproto, espstat.esps_notdb, ahstat.ahs_notdb,
187 ipcompstat.ipcomps_notdb);
192 if (sav->tdb_xform == NULL) {
193 DPRINTF(("%s: attempted to use uninitialized SA %s/%08lx/%u\n",
194 __func__, ipsec_address(&dst_address),
195 (u_long) ntohl(spi), sproto));
196 IPSEC_ISTAT(sproto, espstat.esps_noxform, ahstat.ahs_noxform,
197 ipcompstat.ipcomps_noxform);
204 * Call appropriate transform and return -- callback takes care of
207 error = (*sav->tdb_xform->xf_input)(m, sav, skip, protoff);
214 * Common input handler for IPv4 AH, ESP, and IPCOMP.
217 ipsec4_common_input(struct mbuf *m, ...)
223 off = va_arg(ap, int);
224 nxt = va_arg(ap, int);
227 return ipsec_common_input(m, off, offsetof(struct ip, ip_p),
232 ah4_input(struct mbuf *m, int off)
234 ipsec4_common_input(m, off, IPPROTO_AH);
237 ah4_ctlinput(int cmd, struct sockaddr *sa, void *v)
239 if (sa->sa_family == AF_INET &&
240 sa->sa_len == sizeof(struct sockaddr_in))
241 ipsec4_common_ctlinput(cmd, sa, v, IPPROTO_AH);
245 esp4_input(struct mbuf *m, int off)
247 ipsec4_common_input(m, off, IPPROTO_ESP);
250 esp4_ctlinput(int cmd, struct sockaddr *sa, void *v)
252 if (sa->sa_family == AF_INET &&
253 sa->sa_len == sizeof(struct sockaddr_in))
254 ipsec4_common_ctlinput(cmd, sa, v, IPPROTO_ESP);
258 ipcomp4_input(struct mbuf *m, int off)
260 ipsec4_common_input(m, off, IPPROTO_IPCOMP);
264 * IPsec input callback for INET protocols.
265 * This routine is called as the transform callback.
266 * Takes care of filtering and other sanity checks on
267 * the processed packet.
270 ipsec4_common_input_cb(struct mbuf *m, struct secasvar *sav,
271 int skip, int protoff, struct m_tag *mt)
273 int prot, af, sproto;
276 struct tdb_ident *tdbi;
277 struct secasindex *saidx;
280 IPSEC_SPLASSERT_SOFTNET(__func__);
282 IPSEC_ASSERT(m != NULL, ("null mbuf"));
283 IPSEC_ASSERT(sav != NULL, ("null SA"));
284 IPSEC_ASSERT(sav->sah != NULL, ("null SAH"));
285 saidx = &sav->sah->saidx;
286 af = saidx->dst.sa.sa_family;
287 IPSEC_ASSERT(af == AF_INET, ("unexpected af %u", af));
288 sproto = saidx->proto;
289 IPSEC_ASSERT(sproto == IPPROTO_ESP || sproto == IPPROTO_AH ||
290 sproto == IPPROTO_IPCOMP,
291 ("unexpected security protocol %u", sproto));
295 DPRINTF(("%s: null mbuf", __func__));
296 IPSEC_ISTAT(sproto, espstat.esps_badkcr, ahstat.ahs_badkcr,
297 ipcompstat.ipcomps_badkcr);
303 /* Fix IPv4 header */
304 if (m->m_len < skip && (m = m_pullup(m, skip)) == NULL) {
305 DPRINTF(("%s: processing failed for SA %s/%08lx\n",
306 __func__, ipsec_address(&sav->sah->saidx.dst),
307 (u_long) ntohl(sav->spi)));
308 IPSEC_ISTAT(sproto, espstat.esps_hdrops, ahstat.ahs_hdrops,
309 ipcompstat.ipcomps_hdrops);
314 ip = mtod(m, struct ip *);
315 ip->ip_len = htons(m->m_pkthdr.len);
316 ip->ip_off = htons(ip->ip_off);
318 ip->ip_sum = in_cksum(m, ip->ip_hl << 2);
320 ip = mtod(m, struct ip *);
324 /* IP-in-IP encapsulation */
325 if (prot == IPPROTO_IPIP) {
328 if (m->m_pkthdr.len - skip < sizeof(struct ip)) {
329 IPSEC_ISTAT(sproto, espstat.esps_hdrops,
331 ipcompstat.ipcomps_hdrops);
335 /* ipn will now contain the inner IPv4 header */
336 m_copydata(m, ip->ip_hl << 2, sizeof(struct ip),
340 /* XXX PROXY address isn't recorded in SAH */
342 * Check that the inner source address is the same as
343 * the proxy address, if available.
345 if ((saidx->proxy.sa.sa_family == AF_INET &&
346 saidx->proxy.sin.sin_addr.s_addr !=
349 saidx->proxy.sin.sin_addr.s_addr) ||
350 (saidx->proxy.sa.sa_family != AF_INET &&
351 saidx->proxy.sa.sa_family != 0)) {
353 DPRINTF(("%s: inner source address %s doesn't "
354 "correspond to expected proxy source %s, "
355 "SA %s/%08lx\n", __func__,
356 inet_ntoa4(ipn.ip_src),
357 ipsp_address(saidx->proxy),
358 ipsp_address(saidx->dst),
359 (u_long) ntohl(sav->spi)));
361 IPSEC_ISTAT(sproto, espstat.esps_pdrops,
363 ipcompstat.ipcomps_pdrops);
370 /* IPv6-in-IP encapsulation. */
371 if (prot == IPPROTO_IPV6) {
374 if (m->m_pkthdr.len - skip < sizeof(struct ip6_hdr)) {
375 IPSEC_ISTAT(sproto, espstat.esps_hdrops,
377 ipcompstat.ipcomps_hdrops);
381 /* ip6n will now contain the inner IPv6 header. */
382 m_copydata(m, ip->ip_hl << 2, sizeof(struct ip6_hdr),
387 * Check that the inner source address is the same as
388 * the proxy address, if available.
390 if ((saidx->proxy.sa.sa_family == AF_INET6 &&
391 !IN6_IS_ADDR_UNSPECIFIED(&saidx->proxy.sin6.sin6_addr) &&
392 !IN6_ARE_ADDR_EQUAL(&ip6n.ip6_src,
393 &saidx->proxy.sin6.sin6_addr)) ||
394 (saidx->proxy.sa.sa_family != AF_INET6 &&
395 saidx->proxy.sa.sa_family != 0)) {
397 DPRINTF(("%s: inner source address %s doesn't "
398 "correspond to expected proxy source %s, "
399 "SA %s/%08lx\n", __func__,
400 ip6_sprintf(&ip6n.ip6_src),
401 ipsec_address(&saidx->proxy),
402 ipsec_address(&saidx->dst),
403 (u_long) ntohl(sav->spi)));
405 IPSEC_ISTAT(sproto, espstat.esps_pdrops,
407 ipcompstat.ipcomps_pdrops);
416 * Record what we've done to the packet (under what SA it was
417 * processed). If we've been passed an mtag, it means the packet
418 * was already processed by an ethernet/crypto combo card and
419 * thus has a tag attached with all the right information, but
420 * with a PACKET_TAG_IPSEC_IN_CRYPTO_DONE as opposed to
421 * PACKET_TAG_IPSEC_IN_DONE type; in that case, just change the type.
423 if (mt == NULL && sproto != IPPROTO_IPCOMP) {
424 mtag = m_tag_get(PACKET_TAG_IPSEC_IN_DONE,
425 sizeof(struct tdb_ident), M_NOWAIT);
427 DPRINTF(("%s: failed to get tag\n", __func__));
428 IPSEC_ISTAT(sproto, espstat.esps_hdrops,
429 ahstat.ahs_hdrops, ipcompstat.ipcomps_hdrops);
434 tdbi = (struct tdb_ident *)(mtag + 1);
435 bcopy(&saidx->dst, &tdbi->dst, saidx->dst.sa.sa_len);
436 tdbi->proto = sproto;
437 tdbi->spi = sav->spi;
439 m_tag_prepend(m, mtag);
441 mt->m_tag_id = PACKET_TAG_IPSEC_IN_DONE;
442 /* XXX do we need to mark m_flags??? */
445 key_sa_recordxfer(sav, m); /* record data transfer */
448 * Re-dispatch via software interrupt.
450 if ((error = netisr_queue(NETISR_IP, m))) {
451 IPSEC_ISTAT(sproto, espstat.esps_qfull, ahstat.ahs_qfull,
452 ipcompstat.ipcomps_qfull);
454 DPRINTF(("%s: queue full; proto %u packet dropped\n",
465 ipsec4_common_ctlinput(int cmd, struct sockaddr *sa, void *v, int proto)
467 /* XXX nothing just yet */
472 /* IPv6 AH wrapper. */
474 ipsec6_common_input(struct mbuf **mp, int *offp, int proto)
480 if (*offp < sizeof(struct ip6_hdr)) {
481 DPRINTF(("%s: bad offset %u\n", __func__, *offp));
483 } else if (*offp == sizeof(struct ip6_hdr)) {
484 protoff = offsetof(struct ip6_hdr, ip6_nxt);
486 /* Chase down the header chain... */
487 protoff = sizeof(struct ip6_hdr);
491 m_copydata(*mp, protoff, sizeof(ip6e),
494 if (ip6e.ip6e_nxt == IPPROTO_AH)
495 l = (ip6e.ip6e_len + 2) << 2;
497 l = (ip6e.ip6e_len + 1) << 3;
498 IPSEC_ASSERT(l > 0, ("l went zero or negative"));
499 } while (protoff + l < *offp);
501 /* Malformed packet check */
502 if (protoff + l != *offp) {
503 DPRINTF(("%s: bad packet header chain, protoff %u, "
504 "l %u, off %u\n", __func__, protoff, l, *offp));
505 IPSEC_ISTAT(proto, espstat.esps_hdrops,
507 ipcompstat.ipcomps_hdrops);
512 protoff += offsetof(struct ip6_ext, ip6e_nxt);
514 (void) ipsec_common_input(*mp, *offp, protoff, AF_INET6, proto);
519 * IPsec input callback, called by the transform callback. Takes care of
520 * filtering and other sanity checks on the processed packet.
523 ipsec6_common_input_cb(struct mbuf *m, struct secasvar *sav, int skip, int protoff,
526 int prot, af, sproto;
529 struct tdb_ident *tdbi;
530 struct secasindex *saidx;
535 IPSEC_ASSERT(m != NULL, ("null mbuf"));
536 IPSEC_ASSERT(sav != NULL, ("null SA"));
537 IPSEC_ASSERT(sav->sah != NULL, ("null SAH"));
538 saidx = &sav->sah->saidx;
539 af = saidx->dst.sa.sa_family;
540 IPSEC_ASSERT(af == AF_INET6, ("unexpected af %u", af));
541 sproto = saidx->proto;
542 IPSEC_ASSERT(sproto == IPPROTO_ESP || sproto == IPPROTO_AH ||
543 sproto == IPPROTO_IPCOMP,
544 ("unexpected security protocol %u", sproto));
548 DPRINTF(("%s: null mbuf", __func__));
549 IPSEC_ISTAT(sproto, espstat.esps_badkcr, ahstat.ahs_badkcr,
550 ipcompstat.ipcomps_badkcr);
555 /* Fix IPv6 header */
556 if (m->m_len < sizeof(struct ip6_hdr) &&
557 (m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
559 DPRINTF(("%s: processing failed for SA %s/%08lx\n",
560 __func__, ipsec_address(&sav->sah->saidx.dst),
561 (u_long) ntohl(sav->spi)));
563 IPSEC_ISTAT(sproto, espstat.esps_hdrops, ahstat.ahs_hdrops,
564 ipcompstat.ipcomps_hdrops);
569 ip6 = mtod(m, struct ip6_hdr *);
570 ip6->ip6_plen = htons(m->m_pkthdr.len - sizeof(struct ip6_hdr));
573 m_copydata(m, protoff, 1, (unsigned char *) &prot);
576 /* IP-in-IP encapsulation */
577 if (prot == IPPROTO_IPIP) {
580 if (m->m_pkthdr.len - skip < sizeof(struct ip)) {
581 IPSEC_ISTAT(sproto, espstat.esps_hdrops,
583 ipcompstat.ipcomps_hdrops);
587 /* ipn will now contain the inner IPv4 header */
588 m_copydata(m, skip, sizeof(struct ip), (caddr_t) &ipn);
592 * Check that the inner source address is the same as
593 * the proxy address, if available.
595 if ((saidx->proxy.sa.sa_family == AF_INET &&
596 saidx->proxy.sin.sin_addr.s_addr != INADDR_ANY &&
597 ipn.ip_src.s_addr != saidx->proxy.sin.sin_addr.s_addr) ||
598 (saidx->proxy.sa.sa_family != AF_INET &&
599 saidx->proxy.sa.sa_family != 0)) {
601 DPRINTF(("%s: inner source address %s doesn't "
602 "correspond to expected proxy source %s, "
603 "SA %s/%08lx\n", __func__,
604 inet_ntoa4(ipn.ip_src),
605 ipsec_address(&saidx->proxy),
606 ipsec_address(&saidx->dst),
607 (u_long) ntohl(sav->spi)));
609 IPSEC_ISTATsproto, (espstat.esps_pdrops,
610 ahstat.ahs_pdrops, ipcompstat.ipcomps_pdrops);
618 /* IPv6-in-IP encapsulation */
619 if (prot == IPPROTO_IPV6) {
622 if (m->m_pkthdr.len - skip < sizeof(struct ip6_hdr)) {
623 IPSEC_ISTAT(sproto, espstat.esps_hdrops,
625 ipcompstat.ipcomps_hdrops);
629 /* ip6n will now contain the inner IPv6 header. */
630 m_copydata(m, skip, sizeof(struct ip6_hdr),
635 * Check that the inner source address is the same as
636 * the proxy address, if available.
638 if ((saidx->proxy.sa.sa_family == AF_INET6 &&
639 !IN6_IS_ADDR_UNSPECIFIED(&saidx->proxy.sin6.sin6_addr) &&
640 !IN6_ARE_ADDR_EQUAL(&ip6n.ip6_src,
641 &saidx->proxy.sin6.sin6_addr)) ||
642 (saidx->proxy.sa.sa_family != AF_INET6 &&
643 saidx->proxy.sa.sa_family != 0)) {
645 DPRINTF(("%s: inner source address %s doesn't "
646 "correspond to expected proxy source %s, "
647 "SA %s/%08lx\n", __func__,
648 ip6_sprintf(&ip6n.ip6_src),
649 ipsec_address(&saidx->proxy),
650 ipsec_address(&saidx->dst),
651 (u_long) ntohl(sav->spi)));
653 IPSEC_ISTAT(sproto, espstat.esps_pdrops,
654 ahstat.ahs_pdrops, ipcompstat.ipcomps_pdrops);
662 * Record what we've done to the packet (under what SA it was
663 * processed). If we've been passed an mtag, it means the packet
664 * was already processed by an ethernet/crypto combo card and
665 * thus has a tag attached with all the right information, but
666 * with a PACKET_TAG_IPSEC_IN_CRYPTO_DONE as opposed to
667 * PACKET_TAG_IPSEC_IN_DONE type; in that case, just change the type.
669 if (mt == NULL && sproto != IPPROTO_IPCOMP) {
670 mtag = m_tag_get(PACKET_TAG_IPSEC_IN_DONE,
671 sizeof(struct tdb_ident), M_NOWAIT);
673 DPRINTF(("%s: failed to get tag\n", __func__));
674 IPSEC_ISTAT(sproto, espstat.esps_hdrops,
675 ahstat.ahs_hdrops, ipcompstat.ipcomps_hdrops);
680 tdbi = (struct tdb_ident *)(mtag + 1);
681 bcopy(&saidx->dst, &tdbi->dst, sizeof(union sockaddr_union));
682 tdbi->proto = sproto;
683 tdbi->spi = sav->spi;
685 m_tag_prepend(m, mtag);
688 mt->m_tag_id = PACKET_TAG_IPSEC_IN_DONE;
689 /* XXX do we need to mark m_flags??? */
692 key_sa_recordxfer(sav, m);
694 /* Retrieve new protocol */
695 m_copydata(m, protoff, sizeof(u_int8_t), (caddr_t) &nxt8);
698 * See the end of ip6_input for this logic.
699 * IPPROTO_IPV[46] case will be processed just like other ones
703 while (nxt != IPPROTO_DONE) {
704 if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
705 ip6stat.ip6s_toomanyhdr++;
711 * Protection against faulty packet - there should be
712 * more sanity checks in header chain processing.
714 if (m->m_pkthdr.len < skip) {
715 ip6stat.ip6s_tooshort++;
716 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
721 * Enforce IPsec policy checking if we are seeing last header.
722 * note that we do not visit this with protocols with pcb layer
723 * code - like udp/tcp/raw ip.
725 if ((inet6sw[ip6_protox[nxt]].pr_flags & PR_LASTHDR) != 0 &&
726 ipsec6_in_reject(m, NULL)) {
730 nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &skip, nxt);
740 esp6_ctlinput(int cmd, struct sockaddr *sa, void *d)
742 if (sa->sa_family != AF_INET6 ||
743 sa->sa_len != sizeof(struct sockaddr_in6))
745 if ((unsigned)cmd >= PRC_NCMDS)
748 /* if the parameter is from icmp6, decode it. */
750 struct ip6ctlparam *ip6cp = (struct ip6ctlparam *)d;
751 struct mbuf *m = ip6cp->ip6c_m;
752 int off = ip6cp->ip6c_off;
754 struct ip6ctlparam ip6cp1;
757 * Notify the error to all possible sockets via pfctlinput2.
758 * Since the upper layer information (such as protocol type,
759 * source and destination ports) is embedded in the encrypted
760 * data and might have been cut, we can't directly call
761 * an upper layer ctlinput function. However, the pcbnotify
762 * function will consider source and destination addresses
763 * as well as the flow info value, and may be able to find
764 * some PCB that should be notified.
765 * Although pfctlinput2 will call esp6_ctlinput(), there is
766 * no possibility of an infinite loop of function calls,
767 * because we don't pass the inner IPv6 header.
769 bzero(&ip6cp1, sizeof(ip6cp1));
770 ip6cp1.ip6c_src = ip6cp->ip6c_src;
771 pfctlinput2(cmd, sa, (void *)&ip6cp1);
774 * Then go to special cases that need ESP header information.
775 * XXX: We assume that when ip6 is non NULL,
776 * M and OFF are valid.
779 if (cmd == PRC_MSGSIZE) {
780 struct secasvar *sav;
784 /* check header length before using m_copydata */
785 if (m->m_pkthdr.len < off + sizeof (struct esp))
787 m_copydata(m, off + offsetof(struct esp, esp_spi),
788 sizeof(u_int32_t), (caddr_t) &spi);
790 * Check to see if we have a valid SA corresponding to
791 * the address in the ICMP message payload.
793 sav = KEY_ALLOCSA((union sockaddr_union *)sa,
795 valid = (sav != NULL);
799 /* XXX Further validation? */
802 * Depending on whether the SA is "valid" and
803 * routing table size (mtudisc_{hi,lo}wat), we will:
804 * - recalcurate the new MTU and create the
805 * corresponding routing entry, or
806 * - ignore the MTU change notification.
808 icmp6_mtudisc_update(ip6cp, valid);
811 /* we normally notify any pcb here */