version 1.337.2.4, 2017/03/20 06:57:50 |
version 1.344, 2016/10/18 07:30:31 |
Line 226 pfil_head_t * inet_pfil_hook __read_mo |
|
Line 226 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; |
|
|
Line 287 static void ipintr(void *); |
|
Line 287 static void ipintr(void *); |
|
static void ip_input(struct mbuf *); |
static void ip_input(struct mbuf *); |
static void ip_forward(struct mbuf *, int, struct ifnet *); |
static void ip_forward(struct mbuf *, int, struct ifnet *); |
static bool ip_dooptions(struct mbuf *); |
static bool ip_dooptions(struct mbuf *); |
static struct in_ifaddr *ip_rtaddr(struct in_addr, struct psref *); |
static struct in_ifaddr *ip_rtaddr(struct in_addr); |
static void sysctl_net_inet_ip_setup(struct sysctllog **); |
static void sysctl_net_inet_ip_setup(struct sysctllog **); |
|
|
static struct in_ifaddr *ip_match_our_address(struct ifnet *, struct ip *, |
static struct in_ifaddr *ip_match_our_address(struct ifnet *, struct ip *, |
|
|
ip_ids = ip_id_init(); |
ip_ids = ip_id_init(); |
ip_id = time_uptime & 0xfffff; |
ip_id = time_uptime & 0xfffff; |
|
|
|
ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); |
#ifdef GATEWAY |
#ifdef GATEWAY |
ipflow_init(); |
ipflow_init(); |
#endif |
#endif |
|
|
ipforward_rt_percpu = percpu_alloc(sizeof(struct route)); |
ipforward_rt_percpu = percpu_alloc(sizeof(struct route)); |
if (ipforward_rt_percpu == NULL) |
if (ipforward_rt_percpu == NULL) |
panic("failed to allocate ipforward_rt_percpu"); |
panic("failed to allocate ipforward_rt_percpu"); |
|
|
ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); |
|
} |
} |
|
|
static struct in_ifaddr * |
static struct in_ifaddr * |
Line 388 ip_match_our_address(struct ifnet *ifp, |
|
Line 387 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 408 ip_match_our_address_broadcast(struct if |
|
Line 408 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_slowtimo(void) |
ip_slowtimo(void) |
{ |
{ |
|
|
#ifndef NET_MPSAFE |
|
mutex_enter(softnet_lock); |
mutex_enter(softnet_lock); |
KERNEL_LOCK(1, NULL); |
KERNEL_LOCK(1, NULL); |
#endif |
|
|
|
ip_reass_slowtimo(); |
ip_reass_slowtimo(); |
|
|
#ifndef NET_MPSAFE |
|
KERNEL_UNLOCK_ONE(NULL); |
KERNEL_UNLOCK_ONE(NULL); |
mutex_exit(softnet_lock); |
mutex_exit(softnet_lock); |
#endif |
|
} |
} |
|
|
/* |
/* |
Line 909 ip_dooptions(struct mbuf *m) |
|
Line 905 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 = NULL; |
struct ifaddr *ifa; |
int s; |
int s; |
|
|
dst = ip->ip_dst; |
dst = ip->ip_dst; |
Line 947 ip_dooptions(struct mbuf *m) |
|
Line 943 ip_dooptions(struct mbuf *m) |
|
* address is on directly accessible net. |
* address is on directly accessible net. |
*/ |
*/ |
case IPOPT_LSRR: |
case IPOPT_LSRR: |
case IPOPT_SSRR: { |
case IPOPT_SSRR: |
struct psref psref; |
|
if (ip_allowsrcrt == 0) { |
if (ip_allowsrcrt == 0) { |
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_NET_PROHIB; |
code = ICMP_UNREACH_NET_PROHIB; |
Line 994 ip_dooptions(struct mbuf *m) |
|
Line 989 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)); |
|
s = pserialize_read_enter(); |
if (opt == IPOPT_SSRR) { |
if (opt == IPOPT_SSRR) { |
ifa = ifa_ifwithladdr_psref(sintosa(&ipaddr), |
ifa = ifa_ifwithladdr(sintosa(&ipaddr)); |
&psref); |
|
if (ifa != NULL) |
if (ifa != NULL) |
ia = ifatoia(ifa); |
ia = ifatoia(ifa); |
else |
else |
ia = NULL; |
ia = NULL; |
} else { |
} else { |
ia = ip_rtaddr(ipaddr.sin_addr, &psref); |
ia = ip_rtaddr(ipaddr.sin_addr); |
} |
} |
if (ia == NULL) { |
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)); |
ia4_release(ia, &psref); |
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 |
*/ |
*/ |
forward = !IN_MULTICAST(ip->ip_dst.s_addr); |
forward = !IN_MULTICAST(ip->ip_dst.s_addr); |
break; |
break; |
} |
|
|
|
case IPOPT_RR: { |
case IPOPT_RR: |
struct psref psref; |
|
if (optlen < IPOPT_OFFSET + sizeof(*cp)) { |
if (optlen < IPOPT_OFFSET + sizeof(*cp)) { |
code = &cp[IPOPT_OLEN] - (u_char *)ip; |
code = &cp[IPOPT_OLEN] - (u_char *)ip; |
goto bad; |
goto bad; |
Line 1043 ip_dooptions(struct mbuf *m) |
|
Line 1037 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). |
*/ |
*/ |
ifa = ifa_ifwithaddr_psref(sintosa(&ipaddr), &psref); |
s = pserialize_read_enter(); |
|
ifa = ifa_ifwithaddr(sintosa(&ipaddr)); |
if (ifa == NULL) { |
if (ifa == NULL) { |
ia = ip_rtaddr(ipaddr.sin_addr, &psref); |
ia = ip_rtaddr(ipaddr.sin_addr); |
if (ia == NULL) { |
if (ia == NULL) { |
|
pserialize_read_exit(s); |
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_HOST; |
code = ICMP_UNREACH_HOST; |
goto bad; |
goto bad; |
Line 1056 ip_dooptions(struct mbuf *m) |
|
Line 1052 ip_dooptions(struct mbuf *m) |
|
} |
} |
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)); |
ia4_release(ia, &psref); |
pserialize_read_exit(s); |
cp[IPOPT_OFFSET] += sizeof(struct in_addr); |
cp[IPOPT_OFFSET] += sizeof(struct in_addr); |
break; |
break; |
} |
|
|
|
case IPOPT_TS: |
case IPOPT_TS: |
code = cp - (u_char *)ip; |
code = cp - (u_char *)ip; |
Line 1099 ip_dooptions(struct mbuf *m) |
|
Line 1094 ip_dooptions(struct mbuf *m) |
|
ipaddr.sin_addr = dst; |
ipaddr.sin_addr = dst; |
_ss = pserialize_read_enter(); |
_ss = pserialize_read_enter(); |
rcvif = m_get_rcvif(m, &_s); |
rcvif = m_get_rcvif(m, &_s); |
if (__predict_true(rcvif != NULL)) { |
ifa = ifaof_ifpforaddr(sintosa(&ipaddr), rcvif); |
ifa = ifaof_ifpforaddr(sintosa(&ipaddr), |
|
rcvif); |
|
} |
|
m_put_rcvif(rcvif, &_s); |
m_put_rcvif(rcvif, &_s); |
if (ifa == NULL) { |
if (ifa == NULL) { |
pserialize_read_exit(_ss); |
pserialize_read_exit(_ss); |
|
|
* return internet address info of interface to be used to get there. |
* return internet address info of interface to be used to get there. |
*/ |
*/ |
static struct in_ifaddr * |
static struct in_ifaddr * |
ip_rtaddr(struct in_addr dst, struct psref *psref) |
ip_rtaddr(struct in_addr dst) |
{ |
{ |
struct rtentry *rt; |
struct rtentry *rt; |
union { |
union { |
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(); |
ro = percpu_getref(ipforward_rt_percpu); |
ro = percpu_getref(ipforward_rt_percpu); |
rt = rtcache_lookup(ro, &u.dst); |
rt = rtcache_lookup(ro, &u.dst); |
if (rt == NULL) { |
|
percpu_putref(ipforward_rt_percpu); |
|
return NULL; |
|
} |
|
|
|
ia4_acquire(ifatoia(rt->rt_ifa), psref); |
|
rtcache_unref(rt, ro); |
|
percpu_putref(ipforward_rt_percpu); |
percpu_putref(ipforward_rt_percpu); |
|
SOFTNET_UNLOCK(); |
|
if (rt == NULL) |
|
return NULL; |
|
|
return ifatoia(rt->rt_ifa); |
return ifatoia(rt->rt_ifa); |
} |
} |
Line 1329 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1319 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 1358 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1349 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); |
|
|
ro = percpu_getref(ipforward_rt_percpu); |
ro = percpu_getref(ipforward_rt_percpu); |
rt = rtcache_lookup(ro, &u.dst); |
if ((rt = rtcache_lookup(ro, &u.dst)) == NULL) { |
if (rt == NULL) { |
|
percpu_putref(ipforward_rt_percpu); |
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); |
return; |
return; |
Line 1403 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1393 ip_forward(struct mbuf *m, int srcrt, st |
|
code = ICMP_REDIRECT_HOST; |
code = ICMP_REDIRECT_HOST; |
} |
} |
} |
} |
rtcache_unref(rt, ro); |
|
|
|
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 1427 ip_forward(struct mbuf *m, int srcrt, st |
|
Line 1416 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); |
} |
} |
|
|
type = ICMP_UNREACH; |
type = ICMP_UNREACH; |
code = ICMP_UNREACH_NEEDFRAG; |
code = ICMP_UNREACH_NEEDFRAG; |
|
|
if ((rt = rtcache_validate(ro)) != NULL) { |
if ((rt = rtcache_validate(ro)) != NULL) |
destmtu = rt->rt_ifp->if_mtu; |
destmtu = rt->rt_ifp->if_mtu; |
rtcache_unref(rt, ro); |
|
} |
|
#ifdef IPSEC |
#ifdef IPSEC |
if (ipsec_used) |
if (ipsec_used) |
(void)ipsec4_forward(mcopy, &destmtu); |
(void)ipsec4_forward(mcopy, &destmtu); |
Line 1600 sysctl_net_inet_ip_pmtudto(SYSCTLFN_ARGS |
|
Line 1587 sysctl_net_inet_ip_pmtudto(SYSCTLFN_ARGS |
|
int error, tmp; |
int error, tmp; |
struct sysctlnode node; |
struct sysctlnode node; |
|
|
icmp_mtudisc_lock(); |
|
|
|
node = *rnode; |
node = *rnode; |
tmp = ip_mtudisc_timeout; |
tmp = ip_mtudisc_timeout; |
node.sysctl_data = &tmp; |
node.sysctl_data = &tmp; |
error = sysctl_lookup(SYSCTLFN_CALL(&node)); |
error = sysctl_lookup(SYSCTLFN_CALL(&node)); |
if (error || newp == NULL) |
if (error || newp == NULL) |
goto out; |
return (error); |
if (tmp < 0) { |
if (tmp < 0) |
error = EINVAL; |
return (EINVAL); |
goto out; |
|
} |
mutex_enter(softnet_lock); |
|
|
ip_mtudisc_timeout = tmp; |
ip_mtudisc_timeout = tmp; |
rt_timer_queue_change(ip_mtudisc_timeout_q, ip_mtudisc_timeout); |
rt_timer_queue_change(ip_mtudisc_timeout_q, ip_mtudisc_timeout); |
error = 0; |
|
out: |
mutex_exit(softnet_lock); |
icmp_mtudisc_unlock(); |
|
return error; |
return (0); |
} |
} |
|
|
static int |
static int |