Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.149.2.1.6.2 retrieving revision 1.158 diff -u -p -r1.149.2.1.6.2 -r1.158 --- src/sys/netinet6/ip6_input.c 2018/02/25 23:17:37 1.149.2.1.6.2 +++ src/sys/netinet6/ip6_input.c 2016/04/04 07:37:07 1.158 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.149.2.1.6.2 2018/02/25 23:17:37 snj Exp $ */ +/* $NetBSD: ip6_input.c,v 1.158 2016/04/04 07:37:07 ozaki-r Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -62,13 +62,15 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.149.2.1.6.2 2018/02/25 23:17:37 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.158 2016/04/04 07:37:07 ozaki-r Exp $"); +#ifdef _KERNEL_OPT #include "opt_gateway.h" #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" #include "opt_compat_netbsd.h" +#endif #include #include @@ -125,11 +127,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #include "faith.h" -#include "gif.h" - -#if NGIF > 0 -#include -#endif #include @@ -139,8 +136,6 @@ u_char ip6_protox[IPPROTO_MAX]; struct in6_ifaddr *in6_ifaddr; pktqueue_t *ip6_pktq __read_mostly; -extern callout_t in6_tmpaddrtimer_ch; - int ip6_forward_srcrt; /* XXX */ int ip6_sourcecheck; /* XXX */ int ip6_sourcecheck_interval; /* XXX */ @@ -149,7 +144,7 @@ pfil_head_t *inet6_pfil_hook; percpu_t *ip6stat_percpu; -static void ip6_init2(void *); +static void ip6_init2(void); static void ip6intr(void *); static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *); @@ -189,7 +184,7 @@ ip6_init(void) frag6_init(); ip6_desync_factor = cprng_fast32() % MAX_TEMP_DESYNC_FACTOR; - ip6_init2(NULL); + ip6_init2(); #ifdef GATEWAY ip6flow_init(ip6_hashsize); #endif @@ -201,13 +196,9 @@ ip6_init(void) } static void -ip6_init2(void *dummy) +ip6_init2(void) { - /* nd6_timer_init */ - callout_init(&nd6_timer_ch, CALLOUT_MPSAFE); - callout_reset(&nd6_timer_ch, hz, nd6_timer, NULL); - /* timer for regeneranation of temporary addresses randomize ID */ callout_init(&in6_tmpaddrtimer_ch, CALLOUT_MPSAFE); callout_reset(&in6_tmpaddrtimer_ch, @@ -249,7 +240,7 @@ ip6_input(struct mbuf *m) int hit, off = sizeof(struct ip6_hdr), nest; u_int32_t plen; u_int32_t rtalert = ~0; - int nxt, ours = 0, rh_present = 0, frg_present; + int nxt, ours = 0, rh_present = 0; struct ifnet *deliverifp = NULL; int srcrt = 0; const struct rtentry *rt; @@ -485,7 +476,6 @@ ip6_input(struct mbuf *m) */ if (rt != NULL && (rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST && - !(rt->rt_flags & RTF_CLONED) && #if 0 /* * The check below is redundant since the comparison of @@ -509,10 +499,9 @@ ip6_input(struct mbuf *m) goto hbhcheck; } else { /* address is not ready, so discard the packet. */ - nd6log((LOG_INFO, - "ip6_input: packet to an unready address %s->%s\n", + nd6log(LOG_INFO, "packet to an unready address %s->%s\n", ip6_sprintf(&ip6->ip6_src), - ip6_sprintf(&ip6->ip6_dst))); + ip6_sprintf(&ip6->ip6_dst)); goto bad; } @@ -720,7 +709,6 @@ ip6_input(struct mbuf *m) nest = 0; rh_present = 0; - frg_present = 0; while (nxt != IPPROTO_DONE) { if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { IP6_STATINC(IP6_STAT_TOOMANYHDR); @@ -745,22 +733,10 @@ ip6_input(struct mbuf *m) IP6_STATINC(IP6_STAT_BADOPTIONS); goto bad; } - } else if (nxt == IPPROTO_FRAGMENT) { - if (frg_present++) { - in6_ifstat_inc(m->m_pkthdr.rcvif, - ifs6_in_hdrerr); - IP6_STATINC(IP6_STAT_BADOPTIONS); - goto bad; - } } #ifdef IPSEC if (ipsec_used) { - struct m_tag *mtag; - struct tdb_ident *tdbi; - struct secpolicy *sp; - int s, error; - /* * enforce IPsec policy checking if we are seeing last * header. note that we do not visit this with @@ -768,39 +744,7 @@ ip6_input(struct mbuf *m) */ if ((inet6sw[ip_protox[nxt]].pr_flags & PR_LASTHDR) != 0) { - /* - * Check if the packet has already had IPsec - * processing done. If so, then just pass it - * along. This tag gets set during AH, ESP, - * etc. input handling, before the packet is - * returned to the ip input queue for delivery. - */ - mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, - NULL); - s = splsoftnet(); - if (mtag != NULL) { - tdbi = (struct tdb_ident *)(mtag + 1); - sp = ipsec_getpolicy(tdbi, - IPSEC_DIR_INBOUND); - } else { - sp = ipsec_getpolicybyaddr(m, - IPSEC_DIR_INBOUND, IP_FORWARDING, - &error); - } - if (sp != NULL) { - /* - * Check security policy against packet - * attributes. - */ - error = ipsec_in_reject(sp, m); - KEY_FREESP(&sp); - } else { - /* XXX error stat??? */ - error = EINVAL; - DPRINTF(("ip6_input: no SP, packet" - " discarded\n"));/*XXX*/ - } - splx(s); + int error = ipsec6_input(m); if (error) goto bad; } @@ -1392,44 +1336,50 @@ ip6_pullexthdr(struct mbuf *m, size_t of } /* - * Get offset to the previous header followed by the header + * Get pointer to the previous header followed by the header * currently processed. + * XXX: This function supposes that + * M includes all headers, + * the next header field and the header length field of each header + * are valid, and + * the sum of each header length equals to OFF. + * Because of these assumptions, this function must be called very + * carefully. Moreover, it will not be used in the near future when + * we develop `neater' mechanism to process extension headers. */ -int +u_int8_t * ip6_get_prevhdr(struct mbuf *m, int off) { struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); - if (off == sizeof(struct ip6_hdr)) { - return offsetof(struct ip6_hdr, ip6_nxt); - } else if (off < sizeof(struct ip6_hdr)) { - panic("%s: off < sizeof(struct ip6_hdr)", __func__); - } else { - int len, nlen, nxt; - struct ip6_ext ip6e; + if (off == sizeof(struct ip6_hdr)) + return (&ip6->ip6_nxt); + else { + int len, nxt; + struct ip6_ext *ip6e = NULL; nxt = ip6->ip6_nxt; len = sizeof(struct ip6_hdr); - nlen = 0; while (len < off) { - m_copydata(m, len, sizeof(ip6e), &ip6e); + ip6e = (struct ip6_ext *)(mtod(m, char *) + len); switch (nxt) { case IPPROTO_FRAGMENT: - nlen = sizeof(struct ip6_frag); + len += sizeof(struct ip6_frag); break; case IPPROTO_AH: - nlen = (ip6e.ip6e_len + 2) << 2; + len += (ip6e->ip6e_len + 2) << 2; break; default: - nlen = (ip6e.ip6e_len + 1) << 3; + len += (ip6e->ip6e_len + 1) << 3; break; } - len += nlen; - nxt = ip6e.ip6e_nxt; + nxt = ip6e->ip6e_nxt; } - - return (len - nlen); + if (ip6e) + return (&ip6e->ip6e_nxt); + else + return NULL; } } @@ -1648,6 +1598,8 @@ const u_char inet6ctlerrmap[PRC_NCMDS] = ENOPROTOOPT }; +extern int sysctl_net_inet6_addrctlpolicy(SYSCTLFN_ARGS); + static int sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS) { @@ -1813,15 +1765,6 @@ sysctl_net_inet6_ip6_setup(struct sysctl NULL, 0, &ip6_defmcasthlim, 0, CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_DEFMCASTHLIM, CTL_EOL); -#if NGIF > 0 - sysctl_createv(clog, 0, NULL, NULL, - CTLFLAG_PERMANENT|CTLFLAG_READWRITE, - CTLTYPE_INT, "gifhlim", - SYSCTL_DESCR("Default hop limit for a gif tunnel datagram"), - NULL, 0, &ip6_gif_hlim, 0, - CTL_NET, PF_INET6, IPPROTO_IPV6, - IPV6CTL_GIF_HLIM, CTL_EOL); -#endif /* NGIF */ sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_STRING, "kame_version", @@ -1856,15 +1799,6 @@ sysctl_net_inet6_ip6_setup(struct sysctl IPV6CTL_V6ONLY, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT|CTLFLAG_READWRITE, - CTLTYPE_INT, "auto_linklocal", - SYSCTL_DESCR("Default value of per-interface flag for " - "adding an IPv6 link-local address to " - "interfaces when attached"), - NULL, 0, &ip6_auto_linklocal, 0, - CTL_NET, PF_INET6, IPPROTO_IPV6, - IPV6CTL_AUTO_LINKLOCAL, CTL_EOL); - sysctl_createv(clog, 0, NULL, NULL, - CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "anonportmin", SYSCTL_DESCR("Lowest ephemeral port number to assign"), sysctl_net_inet_ip_ports, 0, &ip6_anonportmin, 0, @@ -1897,6 +1831,23 @@ sysctl_net_inet6_ip6_setup(struct sysctl #endif /* IPNOPRIVPORTS */ sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "auto_linklocal", + SYSCTL_DESCR("Default value of per-interface flag for " + "adding an IPv6 link-local address to " + "interfaces when attached"), + NULL, 0, &ip6_auto_linklocal, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + IPV6CTL_AUTO_LINKLOCAL, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READONLY, + CTLTYPE_STRUCT, "addctlpolicy", + SYSCTL_DESCR("Return the current address control" + " policy"), + sysctl_net_inet6_addrctlpolicy, 0, NULL, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + IPV6CTL_ADDRCTLPOLICY, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "use_tempaddr", SYSCTL_DESCR("Use temporary address"), NULL, 0, &ip6_use_tempaddr, 0,