+
+void
+ah6_ctlinput(int cmd, struct sockaddr *sa, void *d)
+{
+ const struct newah *ahp;
+ struct newah ah;
+ struct secasvar *sav;
+ struct ip6_hdr *ip6;
+ struct mbuf *m;
+ struct ip6ctlparam *ip6cp = NULL;
+ int off;
+ struct sockaddr_in6 *sa6_src, *sa6_dst;
+
+ if (sa->sa_family != AF_INET6 ||
+ sa->sa_len != sizeof(struct sockaddr_in6))
+ return;
+ if ((unsigned)cmd >= PRC_NCMDS)
+ return;
+
+ /* if the parameter is from icmp6, decode it. */
+ if (d != NULL) {
+ ip6cp = (struct ip6ctlparam *)d;
+ m = ip6cp->ip6c_m;
+ ip6 = ip6cp->ip6c_ip6;
+ off = ip6cp->ip6c_off;
+ } else {
+ m = NULL;
+ ip6 = NULL;
+ }
+
+ if (ip6) {
+ /*
+ * XXX: We assume that when ip6 is non NULL,
+ * M and OFF are valid.
+ */
+
+ /* check if we can safely examine src and dst ports */
+ if (m->m_pkthdr.len < off + sizeof(ah))
+ return;
+
+ if (m->m_len < off + sizeof(ah)) {
+ /*
+ * this should be rare case,
+ * so we compromise on this copy...
+ */
+ m_copydata(m, off, sizeof(ah), (caddr_t)&ah);
+ ahp = &ah;
+ } else
+ ahp = (struct newah *)(void *)(mtod(m, caddr_t) + off);
+
+ if (cmd == PRC_MSGSIZE) {
+ int valid = 0;
+
+ /*
+ * Check to see if we have a valid SA corresponding to
+ * the address in the ICMP message payload.
+ */
+ sa6_src = ip6cp->ip6c_src;
+ sa6_dst = (struct sockaddr_in6 *)(void *)sa;
+ sav = key_allocsa(AF_INET6,
+ (caddr_t)&sa6_src->sin6_addr,
+ (caddr_t)&sa6_dst->sin6_addr,
+ IPPROTO_AH, ahp->ah_spi);
+ if (sav) {
+ if (sav->state == SADB_SASTATE_MATURE ||
+ sav->state == SADB_SASTATE_DYING)
+ valid++;
+ key_freesav(sav, KEY_SADB_UNLOCKED);
+ }
+
+ /* XXX Further validation? */
+
+ /*
+ * Depending on the value of "valid" and routing table
+ * size (mtudisc_{hi,lo}wat), we will:
+ * - recalcurate the new MTU and create the
+ * corresponding routing entry, or
+ * - ignore the MTU change notification.
+ */
+ icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
+ }
+
+ /* we normally notify single pcb here */
+ } else {
+ /* we normally notify any pcb here */
+ }
+}