version 1.164.2.2, 2016/11/04 14:49:21 |
version 1.180, 2017/07/06 17:14:35 |
Line 69 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 69 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include "opt_inet.h" |
#include "opt_inet.h" |
#include "opt_inet6.h" |
#include "opt_inet6.h" |
#include "opt_ipsec.h" |
#include "opt_ipsec.h" |
#include "opt_compat_netbsd.h" |
|
#include "opt_net_mpsafe.h" |
#include "opt_net_mpsafe.h" |
#endif |
#endif |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/systm.h> |
#include <sys/systm.h> |
#include <sys/malloc.h> |
|
#include <sys/mbuf.h> |
#include <sys/mbuf.h> |
#include <sys/domain.h> |
#include <sys/domain.h> |
#include <sys/protosw.h> |
#include <sys/protosw.h> |
Line 88 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 86 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/proc.h> |
#include <sys/proc.h> |
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
#include <sys/cprng.h> |
#include <sys/cprng.h> |
|
#include <sys/percpu.h> |
|
|
#include <net/if.h> |
#include <net/if.h> |
#include <net/if_types.h> |
#include <net/if_types.h> |
Line 120 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 119 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <netipsec/key.h> |
#include <netipsec/key.h> |
#endif /* IPSEC */ |
#endif /* IPSEC */ |
|
|
#ifdef COMPAT_50 |
|
#include <compat/sys/time.h> |
|
#include <compat/sys/socket.h> |
|
#endif |
|
|
|
#include <netinet6/ip6protosw.h> |
#include <netinet6/ip6protosw.h> |
|
|
#include "faith.h" |
#include "faith.h" |
Line 144 pfil_head_t *inet6_pfil_hook; |
|
Line 138 pfil_head_t *inet6_pfil_hook; |
|
|
|
percpu_t *ip6stat_percpu; |
percpu_t *ip6stat_percpu; |
|
|
|
percpu_t *ip6_forward_rt_percpu __cacheline_aligned; |
|
|
static void ip6_init2(void); |
static void ip6_init2(void); |
static void ip6intr(void *); |
static void ip6intr(void *); |
static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *); |
static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *); |
|
|
KASSERT(inet6_pfil_hook != NULL); |
KASSERT(inet6_pfil_hook != NULL); |
|
|
ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS); |
ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS); |
|
ip6_forward_rt_percpu = percpu_alloc(sizeof(struct route)); |
} |
} |
|
|
static void |
static void |
Line 252 ip6intr(void *arg __unused) |
|
Line 249 ip6intr(void *arg __unused) |
|
#endif |
#endif |
} |
} |
|
|
extern struct route ip6_forward_rt; |
|
|
|
void |
void |
ip6_input(struct mbuf *m, struct ifnet *rcvif) |
ip6_input(struct mbuf *m, struct ifnet *rcvif) |
{ |
{ |
Line 264 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 259 ip6_input(struct mbuf *m, struct ifnet * |
|
int nxt, ours = 0, rh_present = 0; |
int nxt, ours = 0, rh_present = 0; |
struct ifnet *deliverifp = NULL; |
struct ifnet *deliverifp = NULL; |
int srcrt = 0; |
int srcrt = 0; |
const struct rtentry *rt; |
struct rtentry *rt = NULL; |
union { |
union { |
struct sockaddr dst; |
struct sockaddr dst; |
struct sockaddr_in6 dst6; |
struct sockaddr_in6 dst6; |
} u; |
} u; |
|
struct route *ro; |
|
|
/* |
/* |
* make sure we don't have onion peering information into m_tag. |
* make sure we don't have onion peering information into m_tag. |
Line 448 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 444 ip6_input(struct mbuf *m, struct ifnet * |
|
goto bad; |
goto bad; |
} |
} |
|
|
|
ro = percpu_getref(ip6_forward_rt_percpu); |
/* |
/* |
* Multicast check |
* Multicast check |
*/ |
*/ |
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { |
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { |
struct in6_multi *in6m = 0; |
bool ingroup; |
|
|
in6_ifstat_inc(rcvif, ifs6_in_mcast); |
in6_ifstat_inc(rcvif, ifs6_in_mcast); |
/* |
/* |
* See if we belong to the destination multicast group on the |
* See if we belong to the destination multicast group on the |
* arrival interface. |
* arrival interface. |
*/ |
*/ |
IN6_LOOKUP_MULTI(ip6->ip6_dst, rcvif, in6m); |
ingroup = in6_multi_group(&ip6->ip6_dst, rcvif); |
if (in6m) |
if (ingroup) |
ours = 1; |
ours = 1; |
else if (!ip6_mrouter) { |
else if (!ip6_mrouter) { |
uint64_t *ip6s = IP6_STAT_GETREF(); |
uint64_t *ip6s = IP6_STAT_GETREF(); |
Line 468 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 465 ip6_input(struct mbuf *m, struct ifnet * |
|
ip6s[IP6_STAT_CANTFORWARD]++; |
ip6s[IP6_STAT_CANTFORWARD]++; |
IP6_STAT_PUTREF(); |
IP6_STAT_PUTREF(); |
in6_ifstat_inc(rcvif, ifs6_in_discard); |
in6_ifstat_inc(rcvif, ifs6_in_discard); |
goto bad; |
goto bad_unref; |
} |
} |
deliverifp = rcvif; |
deliverifp = rcvif; |
goto hbhcheck; |
goto hbhcheck; |
Line 479 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 476 ip6_input(struct mbuf *m, struct ifnet * |
|
/* |
/* |
* Unicast check |
* Unicast check |
*/ |
*/ |
rt = rtcache_lookup2(&ip6_forward_rt, &u.dst, 1, &hit); |
rt = rtcache_lookup2(ro, &u.dst, 1, &hit); |
if (hit) |
if (hit) |
IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT); |
IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT); |
else |
else |
Line 514 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 511 ip6_input(struct mbuf *m, struct ifnet * |
|
* packets to a tentative, duplicated, or somehow invalid |
* packets to a tentative, duplicated, or somehow invalid |
* address must not be accepted. |
* address must not be accepted. |
*/ |
*/ |
if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) { |
if (!(ia6->ia6_flags & (IN6_IFF_NOTREADY | IN6_IFF_DETACHED))) { |
/* this address is ready */ |
/* this address is ready */ |
ours = 1; |
ours = 1; |
deliverifp = ia6->ia_ifp; /* correct? */ |
deliverifp = ia6->ia_ifp; /* correct? */ |
goto hbhcheck; |
goto hbhcheck; |
} else { |
} else { |
/* address is not ready, so discard the packet. */ |
/* address is not ready, so discard the packet. */ |
|
char ip6bufs[INET6_ADDRSTRLEN]; |
|
char ip6bufd[INET6_ADDRSTRLEN]; |
nd6log(LOG_INFO, "packet to an unready address %s->%s\n", |
nd6log(LOG_INFO, "packet to an unready address %s->%s\n", |
ip6_sprintf(&ip6->ip6_src), |
IN6_PRINT(ip6bufs, &ip6->ip6_src), |
ip6_sprintf(&ip6->ip6_dst)); |
IN6_PRINT(ip6bufd, &ip6->ip6_dst)); |
|
|
goto bad; |
goto bad_unref; |
} |
} |
} |
} |
|
|
Line 571 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 570 ip6_input(struct mbuf *m, struct ifnet * |
|
if (!ip6_forwarding) { |
if (!ip6_forwarding) { |
IP6_STATINC(IP6_STAT_CANTFORWARD); |
IP6_STATINC(IP6_STAT_CANTFORWARD); |
in6_ifstat_inc(rcvif, ifs6_in_discard); |
in6_ifstat_inc(rcvif, ifs6_in_discard); |
goto bad; |
goto bad_unref; |
} |
} |
|
|
hbhcheck: |
hbhcheck: |
Line 610 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 609 ip6_input(struct mbuf *m, struct ifnet * |
|
#if 0 /*touches NULL pointer*/ |
#if 0 /*touches NULL pointer*/ |
in6_ifstat_inc(rcvif, ifs6_in_discard); |
in6_ifstat_inc(rcvif, ifs6_in_discard); |
#endif |
#endif |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ip6_forward_rt_percpu); |
return; /* m have already been freed */ |
return; /* m have already been freed */ |
} |
} |
|
|
Line 633 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 634 ip6_input(struct mbuf *m, struct ifnet * |
|
icmp6_error(m, ICMP6_PARAM_PROB, |
icmp6_error(m, ICMP6_PARAM_PROB, |
ICMP6_PARAMPROB_HEADER, |
ICMP6_PARAMPROB_HEADER, |
(char *)&ip6->ip6_plen - (char *)ip6); |
(char *)&ip6->ip6_plen - (char *)ip6); |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ip6_forward_rt_percpu); |
return; |
return; |
} |
} |
IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), |
IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), |
sizeof(struct ip6_hbh)); |
sizeof(struct ip6_hbh)); |
if (hbh == NULL) { |
if (hbh == NULL) { |
IP6_STATINC(IP6_STAT_TOOSHORT); |
IP6_STATINC(IP6_STAT_TOOSHORT); |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ip6_forward_rt_percpu); |
return; |
return; |
} |
} |
KASSERT(IP6_HDR_ALIGNED_P(hbh)); |
KASSERT(IP6_HDR_ALIGNED_P(hbh)); |
Line 662 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 667 ip6_input(struct mbuf *m, struct ifnet * |
|
if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { |
if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { |
IP6_STATINC(IP6_STAT_TOOSHORT); |
IP6_STATINC(IP6_STAT_TOOSHORT); |
in6_ifstat_inc(rcvif, ifs6_in_truncated); |
in6_ifstat_inc(rcvif, ifs6_in_truncated); |
goto bad; |
goto bad_unref; |
} |
} |
if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) { |
if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) { |
if (m->m_len == m->m_pkthdr.len) { |
if (m->m_len == m->m_pkthdr.len) { |
Line 692 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 697 ip6_input(struct mbuf *m, struct ifnet * |
|
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
|
|
if (error != 0) { |
if (error != 0) { |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ip6_forward_rt_percpu); |
IP6_STATINC(IP6_STAT_CANTFORWARD); |
IP6_STATINC(IP6_STAT_CANTFORWARD); |
goto bad; |
goto bad; |
} |
} |
} |
} |
if (!ours) |
if (!ours) |
goto bad; |
goto bad_unref; |
} else if (!ours) { |
} else if (!ours) { |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ip6_forward_rt_percpu); |
ip6_forward(m, srcrt); |
ip6_forward(m, srcrt); |
return; |
return; |
} |
} |
Line 718 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 727 ip6_input(struct mbuf *m, struct ifnet * |
|
IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { |
IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { |
IP6_STATINC(IP6_STAT_BADSCOPE); |
IP6_STATINC(IP6_STAT_BADSCOPE); |
in6_ifstat_inc(rcvif, ifs6_in_addrerr); |
in6_ifstat_inc(rcvif, ifs6_in_addrerr); |
goto bad; |
goto bad_unref; |
} |
} |
|
|
/* |
/* |
Line 738 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 747 ip6_input(struct mbuf *m, struct ifnet * |
|
in6_ifstat_inc(deliverifp, ifs6_in_deliver); |
in6_ifstat_inc(deliverifp, ifs6_in_deliver); |
nest = 0; |
nest = 0; |
|
|
|
if (rt != NULL) { |
|
rtcache_unref(rt, ro); |
|
rt = NULL; |
|
} |
|
percpu_putref(ip6_forward_rt_percpu); |
|
|
rh_present = 0; |
rh_present = 0; |
while (nxt != IPPROTO_DONE) { |
while (nxt != IPPROTO_DONE) { |
if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { |
if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { |
Line 789 ip6_input(struct mbuf *m, struct ifnet * |
|
Line 804 ip6_input(struct mbuf *m, struct ifnet * |
|
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
} |
} |
return; |
return; |
|
|
|
bad_unref: |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ip6_forward_rt_percpu); |
bad: |
bad: |
m_freem(m); |
m_freem(m); |
|
return; |
} |
} |
|
|
/* |
/* |
|
|
ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, |
ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, |
struct ip6_hdr *ip6, struct mbuf *m) |
struct ip6_hdr *ip6, struct mbuf *m) |
{ |
{ |
|
struct socket *so = in6p->in6p_socket; |
#ifdef RFC2292 |
#ifdef RFC2292 |
#define IS2292(x, y) ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y)) |
#define IS2292(x, y) ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y)) |
#else |
#else |
#define IS2292(x, y) (y) |
#define IS2292(x, y) (y) |
#endif |
#endif |
|
|
if (in6p->in6p_socket->so_options & SO_TIMESTAMP |
if (SOOPT_TIMESTAMP(so->so_options)) |
#ifdef SO_OTIMESTAMP |
mp = sbsavetimestamp(so->so_options, m, mp); |
|| in6p->in6p_socket->so_options & SO_OTIMESTAMP |
|
#endif |
|
) { |
|
struct timeval tv; |
|
|
|
microtime(&tv); |
|
#ifdef SO_OTIMESTAMP |
|
if (in6p->in6p_socket->so_options & SO_OTIMESTAMP) { |
|
struct timeval50 tv50; |
|
timeval_to_timeval50(&tv, &tv50); |
|
*mp = sbcreatecontrol((void *) &tv50, sizeof(tv50), |
|
SCM_OTIMESTAMP, SOL_SOCKET); |
|
} else |
|
#endif |
|
*mp = sbcreatecontrol((void *) &tv, sizeof(tv), |
|
SCM_TIMESTAMP, SOL_SOCKET); |
|
if (*mp) |
|
mp = &(*mp)->m_next; |
|
} |
|
|
|
/* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */ |
/* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */ |
if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) |
if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) |
Line 1098 ip6_savecontrol(struct in6pcb *in6p, str |
|
Line 1100 ip6_savecontrol(struct in6pcb *in6p, str |
|
memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); |
memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); |
in6_clearscope(&pi6.ipi6_addr); /* XXX */ |
in6_clearscope(&pi6.ipi6_addr); /* XXX */ |
pi6.ipi6_ifindex = m->m_pkthdr.rcvif_index; |
pi6.ipi6_ifindex = m->m_pkthdr.rcvif_index; |
*mp = sbcreatecontrol((void *) &pi6, |
*mp = sbcreatecontrol(&pi6, sizeof(pi6), |
sizeof(struct in6_pktinfo), |
|
IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6); |
IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6); |
if (*mp) |
if (*mp) |
mp = &(*mp)->m_next; |
mp = &(*mp)->m_next; |
Line 1108 ip6_savecontrol(struct in6pcb *in6p, str |
|
Line 1109 ip6_savecontrol(struct in6pcb *in6p, str |
|
if (in6p->in6p_flags & IN6P_HOPLIMIT) { |
if (in6p->in6p_flags & IN6P_HOPLIMIT) { |
int hlim = ip6->ip6_hlim & 0xff; |
int hlim = ip6->ip6_hlim & 0xff; |
|
|
*mp = sbcreatecontrol((void *) &hlim, sizeof(int), |
*mp = sbcreatecontrol(&hlim, sizeof(hlim), |
IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6); |
IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6); |
if (*mp) |
if (*mp) |
mp = &(*mp)->m_next; |
mp = &(*mp)->m_next; |
Line 1122 ip6_savecontrol(struct in6pcb *in6p, str |
|
Line 1123 ip6_savecontrol(struct in6pcb *in6p, str |
|
flowinfo >>= 20; |
flowinfo >>= 20; |
|
|
tclass = flowinfo & 0xff; |
tclass = flowinfo & 0xff; |
*mp = sbcreatecontrol((void *)&tclass, sizeof(tclass), |
*mp = sbcreatecontrol(&tclass, sizeof(tclass), |
IPV6_TCLASS, IPPROTO_IPV6); |
IPV6_TCLASS, IPPROTO_IPV6); |
|
|
if (*mp) |
if (*mp) |
Line 1170 ip6_savecontrol(struct in6pcb *in6p, str |
|
Line 1171 ip6_savecontrol(struct in6pcb *in6p, str |
|
* be removed before returning in the RFC 2292. |
* be removed before returning in the RFC 2292. |
* Note: this constraint is removed in RFC3542. |
* Note: this constraint is removed in RFC3542. |
*/ |
*/ |
*mp = sbcreatecontrol((void *)hbh, hbhlen, |
*mp = sbcreatecontrol(hbh, hbhlen, |
IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS), |
IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS), |
IPPROTO_IPV6); |
IPPROTO_IPV6); |
if (*mp) |
if (*mp) |
Line 1232 ip6_savecontrol(struct in6pcb *in6p, str |
|
Line 1233 ip6_savecontrol(struct in6pcb *in6p, str |
|
if (!(in6p->in6p_flags & IN6P_DSTOPTS)) |
if (!(in6p->in6p_flags & IN6P_DSTOPTS)) |
break; |
break; |
|
|
*mp = sbcreatecontrol((void *)ip6e, elen, |
*mp = sbcreatecontrol(ip6e, elen, |
IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS), |
IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS), |
IPPROTO_IPV6); |
IPPROTO_IPV6); |
if (*mp) |
if (*mp) |
Line 1243 ip6_savecontrol(struct in6pcb *in6p, str |
|
Line 1244 ip6_savecontrol(struct in6pcb *in6p, str |
|
if (!(in6p->in6p_flags & IN6P_RTHDR)) |
if (!(in6p->in6p_flags & IN6P_RTHDR)) |
break; |
break; |
|
|
*mp = sbcreatecontrol((void *)ip6e, elen, |
*mp = sbcreatecontrol(ip6e, elen, |
IS2292(IPV6_2292RTHDR, IPV6_RTHDR), |
IS2292(IPV6_2292RTHDR, IPV6_RTHDR), |
IPPROTO_IPV6); |
IPPROTO_IPV6); |
if (*mp) |
if (*mp) |
Line 1293 ip6_notify_pmtu(struct in6pcb *in6p, con |
|
Line 1294 ip6_notify_pmtu(struct in6pcb *in6p, con |
|
if (mtu == NULL) |
if (mtu == NULL) |
return; |
return; |
|
|
#ifdef DIAGNOSTIC |
KASSERT(so != NULL); |
if (so == NULL) /* I believe this is impossible */ |
|
panic("ip6_notify_pmtu: socket is NULL"); |
|
#endif |
|
|
|
memset(&mtuctl, 0, sizeof(mtuctl)); /* zero-clear for safety */ |
memset(&mtuctl, 0, sizeof(mtuctl)); /* zero-clear for safety */ |
mtuctl.ip6m_mtu = *mtu; |
mtuctl.ip6m_mtu = *mtu; |
Line 1304 ip6_notify_pmtu(struct in6pcb *in6p, con |
|
Line 1302 ip6_notify_pmtu(struct in6pcb *in6p, con |
|
if (sa6_recoverscope(&mtuctl.ip6m_addr)) |
if (sa6_recoverscope(&mtuctl.ip6m_addr)) |
return; |
return; |
|
|
if ((m_mtu = sbcreatecontrol((void *)&mtuctl, sizeof(mtuctl), |
if ((m_mtu = sbcreatecontrol(&mtuctl, sizeof(mtuctl), |
IPV6_PATHMTU, IPPROTO_IPV6)) == NULL) |
IPV6_PATHMTU, IPPROTO_IPV6)) == NULL) |
return; |
return; |
|
|