version 1.319.4.6, 2016/07/09 20:25:22 |
version 1.319.4.7, 2016/10/05 20:56:09 |
Line 225 pfil_head_t * inet_pfil_hook __read_mo |
|
Line 225 pfil_head_t * inet_pfil_hook __read_mo |
|
ipid_state_t * ip_ids __read_mostly; |
ipid_state_t * ip_ids __read_mostly; |
percpu_t * ipstat_percpu __read_mostly; |
percpu_t * ipstat_percpu __read_mostly; |
|
|
static struct route ipforward_rt __cacheline_aligned; |
static percpu_t *ipforward_rt_percpu __cacheline_aligned; |
|
|
uint16_t ip_id; |
uint16_t ip_id; |
|
|
|
|
#endif /* MBUFTRACE */ |
#endif /* MBUFTRACE */ |
|
|
ipstat_percpu = percpu_alloc(sizeof(uint64_t) * IP_NSTATS); |
ipstat_percpu = percpu_alloc(sizeof(uint64_t) * IP_NSTATS); |
|
|
|
ipforward_rt_percpu = percpu_alloc(sizeof(struct route)); |
|
if (ipforward_rt_percpu == NULL) |
|
panic("failed to allocate ipforward_rt_percpu"); |
} |
} |
|
|
static struct in_ifaddr * |
static struct in_ifaddr * |
Line 378 ip_match_our_address(struct ifnet *ifp, |
|
Line 382 ip_match_our_address(struct ifnet *ifp, |
|
continue; |
continue; |
if (checkif && ia->ia_ifp != ifp) |
if (checkif && ia->ia_ifp != ifp) |
continue; |
continue; |
if ((ia->ia_ifp->if_flags & IFF_UP) != 0) |
if ((ia->ia_ifp->if_flags & IFF_UP) != 0 && |
|
(ia->ia4_flags & IN_IFF_DETACHED) == 0) |
break; |
break; |
else |
else |
downmatch++; |
(*downmatch)++; |
} |
} |
} |
} |
|
|
Line 398 ip_match_our_address_broadcast(struct if |
|
Line 403 ip_match_our_address_broadcast(struct if |
|
if (ifa->ifa_addr->sa_family != AF_INET) |
if (ifa->ifa_addr->sa_family != AF_INET) |
continue; |
continue; |
ia = ifatoia(ifa); |
ia = ifatoia(ifa); |
if (ia->ia4_flags & IN_IFF_NOTREADY) |
if (ia->ia4_flags & (IN_IFF_NOTREADY | IN_IFF_DETACHED)) |
continue; |
continue; |
if (in_hosteq(ip->ip_dst, ia->ia_broadaddr.sin_addr) || |
if (in_hosteq(ip->ip_dst, ia->ia_broadaddr.sin_addr) || |
in_hosteq(ip->ip_dst, ia->ia_netbroadcast) || |
in_hosteq(ip->ip_dst, ia->ia_netbroadcast) || |
|
|
ip_input(struct mbuf *m) |
ip_input(struct mbuf *m) |
{ |
{ |
struct ip *ip = NULL; |
struct ip *ip = NULL; |
struct in_ifaddr *ia; |
struct in_ifaddr *ia = NULL; |
int hlen = 0, len; |
int hlen = 0, len; |
int downmatch; |
int downmatch; |
int srcrt = 0; |
int srcrt = 0; |
ifnet_t *ifp; |
ifnet_t *ifp; |
struct psref psref; |
struct psref psref; |
|
int s; |
|
|
KASSERTMSG(cpu_softintr_p(), "ip_input: not in the software " |
KASSERTMSG(cpu_softintr_p(), "ip_input: not in the software " |
"interrupt handler; synchronization assumptions violated"); |
"interrupt handler; synchronization assumptions violated"); |
Line 665 ip_input(struct mbuf *m) |
|
Line 671 ip_input(struct mbuf *m) |
|
* or IN_IFF_NOTREADY addresses as not mine. |
* or IN_IFF_NOTREADY addresses as not mine. |
*/ |
*/ |
downmatch = 0; |
downmatch = 0; |
|
s = pserialize_read_enter(); |
ia = ip_match_our_address(ifp, ip, &downmatch); |
ia = ip_match_our_address(ifp, ip, &downmatch); |
if (ia != NULL) |
if (ia != NULL) { |
|
pserialize_read_exit(s); |
goto ours; |
goto ours; |
|
} |
|
|
if (ifp->if_flags & IFF_BROADCAST) { |
if (ifp->if_flags & IFF_BROADCAST) { |
ia = ip_match_our_address_broadcast(ifp, ip); |
ia = ip_match_our_address_broadcast(ifp, ip); |
if (ia != NULL) |
if (ia != NULL) { |
|
pserialize_read_exit(s); |
goto ours; |
goto ours; |
|
} |
} |
} |
|
pserialize_read_exit(s); |
|
|
if (IN_MULTICAST(ip->ip_dst.s_addr)) { |
if (IN_MULTICAST(ip->ip_dst.s_addr)) { |
#ifdef MROUTING |
#ifdef MROUTING |
|
|
* Switch out to protocol's input routine. |
* Switch out to protocol's input routine. |
*/ |
*/ |
#if IFA_STATS |
#if IFA_STATS |
if (ia && ip) |
if (ia && ip) { |
ia->ia_ifa.ifa_data.ifad_inbytes += ntohs(ip->ip_len); |
struct in_ifaddr *_ia; |
|
/* |
|
* Keep a reference from ip_match_our_address with psref |
|
* is expensive, so explore ia here again. |
|
*/ |
|
s = pserialize_read_enter(); |
|
_ia = in_get_ia(ip->ip_dst.s_addr); |
|
_ia->ia_ifa.ifa_data.ifad_inbytes += ntohs(ip->ip_len); |
|
pserialize_read_exit(s); |
|
} |
#endif |
#endif |
IP_STATINC(IP_STAT_DELIVERED); |
IP_STATINC(IP_STAT_DELIVERED); |
|
|
Line 873 ip_dooptions(struct mbuf *m) |
|
Line 894 ip_dooptions(struct mbuf *m) |
|
int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0; |
int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0; |
struct in_addr dst; |
struct in_addr dst; |
n_time ntime; |
n_time ntime; |
|
struct ifaddr *ifa; |
|
int s; |
|
|
dst = ip->ip_dst; |
dst = ip->ip_dst; |
cp = (u_char *)(ip + 1); |
cp = (u_char *)(ip + 1); |
Line 924 ip_dooptions(struct mbuf *m) |
|
Line 947 ip_dooptions(struct mbuf *m) |
|
goto bad; |
goto bad; |
} |
} |
ipaddr.sin_addr = ip->ip_dst; |
ipaddr.sin_addr = ip->ip_dst; |
ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr))); |
|
if (ia == 0) { |
s = pserialize_read_enter(); |
|
ifa = ifa_ifwithaddr(sintosa(&ipaddr)); |
|
if (ifa == NULL) { |
|
pserialize_read_exit(s); |
if (opt == IPOPT_SSRR) { |
if (opt == IPOPT_SSRR) { |
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_SRCFAIL; |
code = ICMP_UNREACH_SRCFAIL; |
Line 937 ip_dooptions(struct mbuf *m) |
|
Line 963 ip_dooptions(struct mbuf *m) |
|
*/ |
*/ |
break; |
break; |
} |
} |
|
pserialize_read_exit(s); |
|
|
off--; /* 0 origin */ |
off--; /* 0 origin */ |
if ((off + sizeof(struct in_addr)) > optlen) { |
if ((off + sizeof(struct in_addr)) > optlen) { |
/* |
/* |
Line 950 ip_dooptions(struct mbuf *m) |
|
Line 978 ip_dooptions(struct mbuf *m) |
|
*/ |
*/ |
memcpy((void *)&ipaddr.sin_addr, (void *)(cp + off), |
memcpy((void *)&ipaddr.sin_addr, (void *)(cp + off), |
sizeof(ipaddr.sin_addr)); |
sizeof(ipaddr.sin_addr)); |
if (opt == IPOPT_SSRR) |
s = pserialize_read_enter(); |
ia = ifatoia(ifa_ifwithladdr(sintosa(&ipaddr))); |
if (opt == IPOPT_SSRR) { |
else |
ifa = ifa_ifwithladdr(sintosa(&ipaddr)); |
|
if (ifa != NULL) |
|
ia = ifatoia(ifa); |
|
else |
|
ia = NULL; |
|
} else { |
ia = ip_rtaddr(ipaddr.sin_addr); |
ia = ip_rtaddr(ipaddr.sin_addr); |
if (ia == 0) { |
} |
|
if (ia == NULL) { |
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_SRCFAIL; |
code = ICMP_UNREACH_SRCFAIL; |
|
pserialize_read_exit(s); |
goto bad; |
goto bad; |
} |
} |
ip->ip_dst = ipaddr.sin_addr; |
ip->ip_dst = ipaddr.sin_addr; |
bcopy((void *)&ia->ia_addr.sin_addr, |
bcopy((void *)&ia->ia_addr.sin_addr, |
(void *)(cp + off), sizeof(struct in_addr)); |
(void *)(cp + off), sizeof(struct in_addr)); |
|
pserialize_read_exit(s); |
cp[IPOPT_OFFSET] += sizeof(struct in_addr); |
cp[IPOPT_OFFSET] += sizeof(struct in_addr); |
/* |
/* |
* Let ip_intr's mcast routing check handle mcast pkts |
* Let ip_intr's mcast routing check handle mcast pkts |
Line 990 ip_dooptions(struct mbuf *m) |
|
Line 1026 ip_dooptions(struct mbuf *m) |
|
* locate outgoing interface; if we're the destination, |
* locate outgoing interface; if we're the destination, |
* use the incoming interface (should be same). |
* use the incoming interface (should be same). |
*/ |
*/ |
if ((ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)))) |
s = pserialize_read_enter(); |
== NULL && |
ifa = ifa_ifwithaddr(sintosa(&ipaddr)); |
(ia = ip_rtaddr(ipaddr.sin_addr)) == NULL) { |
if (ifa == NULL) { |
type = ICMP_UNREACH; |
ia = ip_rtaddr(ipaddr.sin_addr); |
code = ICMP_UNREACH_HOST; |
if (ia == NULL) { |
goto bad; |
pserialize_read_exit(s); |
|
type = ICMP_UNREACH; |
|
code = ICMP_UNREACH_HOST; |
|
goto bad; |
|
} |
|
} else { |
|
ia = ifatoia(ifa); |
} |
} |
bcopy((void *)&ia->ia_addr.sin_addr, |
bcopy((void *)&ia->ia_addr.sin_addr, |
(void *)(cp + off), sizeof(struct in_addr)); |
(void *)(cp + off), sizeof(struct in_addr)); |
|
pserialize_read_exit(s); |
cp[IPOPT_OFFSET] += sizeof(struct in_addr); |
cp[IPOPT_OFFSET] += sizeof(struct in_addr); |
break; |
break; |
|
|
Line 1029 ip_dooptions(struct mbuf *m) |
|
Line 1072 ip_dooptions(struct mbuf *m) |
|
|
|
case IPOPT_TS_TSANDADDR: { |
case IPOPT_TS_TSANDADDR: { |
struct ifnet *rcvif; |
struct ifnet *rcvif; |
int s; |
int _s, _ss; |
|
|
if (ipt->ipt_ptr - 1 + sizeof(n_time) + |
if (ipt->ipt_ptr - 1 + sizeof(n_time) + |
sizeof(struct in_addr) > ipt->ipt_len) { |
sizeof(struct in_addr) > ipt->ipt_len) { |
Line 1038 ip_dooptions(struct mbuf *m) |
|
Line 1081 ip_dooptions(struct mbuf *m) |
|
goto bad; |
goto bad; |
} |
} |
ipaddr.sin_addr = dst; |
ipaddr.sin_addr = dst; |
rcvif = m_get_rcvif(m, &s); |
_ss = pserialize_read_enter(); |
ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr), |
rcvif = m_get_rcvif(m, &_s); |
rcvif)); |
ifa = ifaof_ifpforaddr(sintosa(&ipaddr), rcvif); |
m_put_rcvif(rcvif, &s); |
m_put_rcvif(rcvif, &_s); |
if (ia == 0) |
if (ifa == NULL) { |
continue; |
pserialize_read_exit(_ss); |
|
break; |
|
} |
|
ia = ifatoia(ifa); |
bcopy(&ia->ia_addr.sin_addr, |
bcopy(&ia->ia_addr.sin_addr, |
cp0, sizeof(struct in_addr)); |
cp0, sizeof(struct in_addr)); |
|
pserialize_read_exit(_ss); |
ipt->ipt_ptr += sizeof(struct in_addr); |
ipt->ipt_ptr += sizeof(struct in_addr); |
break; |
break; |
} |
} |
Line 1059 ip_dooptions(struct mbuf *m) |
|
Line 1106 ip_dooptions(struct mbuf *m) |
|
} |
} |
memcpy(&ipaddr.sin_addr, cp0, |
memcpy(&ipaddr.sin_addr, cp0, |
sizeof(struct in_addr)); |
sizeof(struct in_addr)); |
if (ifatoia(ifa_ifwithaddr(sintosa(&ipaddr))) |
s = pserialize_read_enter(); |
== NULL) |
ifa = ifa_ifwithaddr(sintosa(&ipaddr)); |
|
if (ifa == NULL) { |
|
pserialize_read_exit(s); |
continue; |
continue; |
|
} |
|
pserialize_read_exit(s); |
ipt->ipt_ptr += sizeof(struct in_addr); |
ipt->ipt_ptr += sizeof(struct in_addr); |
break; |
break; |
|
|
Line 1080 ip_dooptions(struct mbuf *m) |
|
Line 1131 ip_dooptions(struct mbuf *m) |
|
} |
} |
if (forward) { |
if (forward) { |
struct ifnet *rcvif; |
struct ifnet *rcvif; |
struct psref psref; |
struct psref _psref; |
|
|
if (ip_forwsrcrt == 0) { |
if (ip_forwsrcrt == 0) { |
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
Line 1088 ip_dooptions(struct mbuf *m) |
|
Line 1139 ip_dooptions(struct mbuf *m) |
|
goto bad; |
goto bad; |
} |
} |
|
|
rcvif = m_get_rcvif_psref(m, &psref); |
rcvif = m_get_rcvif_psref(m, &_psref); |
if (__predict_false(rcvif == NULL)) { |
if (__predict_false(rcvif == NULL)) { |
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_HOST; |
code = ICMP_UNREACH_HOST; |
goto bad; |
goto bad; |
} |
} |
ip_forward(m, 1, rcvif); |
ip_forward(m, 1, rcvif); |
m_put_rcvif_psref(rcvif, &psref); |
m_put_rcvif_psref(rcvif, &_psref); |
return true; |
return true; |
} |
} |
return false; |
return false; |
Line 1117 ip_rtaddr(struct in_addr dst) |
|
Line 1168 ip_rtaddr(struct in_addr dst) |
|
struct sockaddr dst; |
struct sockaddr dst; |
struct sockaddr_in dst4; |
struct sockaddr_in dst4; |
} u; |
} u; |
|
struct route *ro; |
|
|
sockaddr_in_init(&u.dst4, &dst, 0); |
sockaddr_in_init(&u.dst4, &dst, 0); |
|
|
SOFTNET_LOCK(); |
SOFTNET_LOCK(); |
rt = rtcache_lookup(&ipforward_rt, &u.dst); |
ro = percpu_getref(ipforward_rt_percpu); |
|
rt = rtcache_lookup(ro, &u.dst); |
|
percpu_putref(ipforward_rt_percpu); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
if (rt == NULL) |
if (rt == NULL) |
return NULL; |
return NULL; |
Line 1254 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1308 ip_forward(struct mbuf *m, int srcrt, st |
|
struct sockaddr_in dst4; |
struct sockaddr_in dst4; |
} u; |
} u; |
uint64_t *ips; |
uint64_t *ips; |
|
struct route *ro; |
|
|
KASSERTMSG(cpu_softintr_p(), "ip_forward: not in the software " |
KASSERTMSG(cpu_softintr_p(), "ip_forward: not in the software " |
"interrupt handler; synchronization assumptions violated"); |
"interrupt handler; synchronization assumptions violated"); |
Line 1285 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1340 ip_forward(struct mbuf *m, int srcrt, st |
|
|
|
sockaddr_in_init(&u.dst4, &ip->ip_dst, 0); |
sockaddr_in_init(&u.dst4, &ip->ip_dst, 0); |
|
|
if ((rt = rtcache_lookup(&ipforward_rt, &u.dst)) == NULL) { |
ro = percpu_getref(ipforward_rt_percpu); |
|
if ((rt = rtcache_lookup(ro, &u.dst)) == NULL) { |
|
percpu_putref(ipforward_rt_percpu); |
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, dest, 0); |
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, dest, 0); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
return; |
return; |
Line 1330 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1387 ip_forward(struct mbuf *m, int srcrt, st |
|
} |
} |
} |
} |
|
|
error = ip_output(m, NULL, &ipforward_rt, |
error = ip_output(m, NULL, ro, |
(IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), |
(IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), |
NULL, NULL); |
NULL, NULL); |
|
|
Line 1352 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1409 ip_forward(struct mbuf *m, int srcrt, st |
|
if (mcopy) { |
if (mcopy) { |
#ifdef GATEWAY |
#ifdef GATEWAY |
if (mcopy->m_flags & M_CANFASTFWD) |
if (mcopy->m_flags & M_CANFASTFWD) |
ipflow_create(&ipforward_rt, mcopy); |
ipflow_create(ro, mcopy); |
#endif |
#endif |
m_freem(mcopy); |
m_freem(mcopy); |
} |
} |
|
|
|
percpu_putref(ipforward_rt_percpu); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
return; |
return; |
|
|
redirect: |
redirect: |
error: |
error: |
if (mcopy == NULL) { |
if (mcopy == NULL) { |
|
percpu_putref(ipforward_rt_percpu); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
return; |
return; |
} |
} |
|
|
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_NEEDFRAG; |
code = ICMP_UNREACH_NEEDFRAG; |
|
|
if ((rt = rtcache_validate(&ipforward_rt)) != NULL) |
if ((rt = rtcache_validate(ro)) != NULL) |
destmtu = rt->rt_ifp->if_mtu; |
destmtu = rt->rt_ifp->if_mtu; |
#ifdef IPSEC |
#ifdef IPSEC |
if (ipsec_used) |
if (ipsec_used) |
|
|
*/ |
*/ |
if (mcopy) |
if (mcopy) |
m_freem(mcopy); |
m_freem(mcopy); |
|
percpu_putref(ipforward_rt_percpu); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
return; |
return; |
} |
} |
icmp_error(mcopy, type, code, dest, destmtu); |
icmp_error(mcopy, type, code, dest, destmtu); |
|
percpu_putref(ipforward_rt_percpu); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
} |
} |
|
|