version 1.319, 2014/06/16 00:33:39 |
version 1.327, 2016/01/21 15:27:48 |
|
|
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
__KERNEL_RCSID(0, "$NetBSD$"); |
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
|
#ifdef _KERNEL_OPT |
#include "opt_inet.h" |
#include "opt_inet.h" |
#include "opt_compat_netbsd.h" |
#include "opt_compat_netbsd.h" |
#include "opt_gateway.h" |
#include "opt_gateway.h" |
Line 100 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 101 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include "opt_mrouting.h" |
#include "opt_mrouting.h" |
#include "opt_mbuftrace.h" |
#include "opt_mbuftrace.h" |
#include "opt_inet_csum.h" |
#include "opt_inet_csum.h" |
|
#endif |
|
|
|
#include "arp.h" |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/systm.h> |
#include <sys/systm.h> |
|
|
ip_init(void) |
ip_init(void) |
{ |
{ |
const struct protosw *pr; |
const struct protosw *pr; |
|
const struct ipprotosw *ippr; |
|
size_t i; |
|
|
in_init(); |
in_init(); |
sysctl_net_inet_ip_setup(NULL); |
sysctl_net_inet_ip_setup(NULL); |
|
|
|
for (i = 0; i < inetdomain.dom_nprotosw; i++) { |
|
inetdomain.dom_protosw[i] = &inetsw[i].ippr_protosw; |
|
} |
|
|
pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); |
pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); |
KASSERT(pr != NULL); |
KASSERT(pr != NULL); |
|
ippr = container_of(pr, struct ipprotosw, ippr_protosw); |
|
|
ip_pktq = pktq_create(IFQ_MAXLEN, ipintr, NULL); |
ip_pktq = pktq_create(IFQ_MAXLEN, ipintr, NULL); |
KASSERT(ip_pktq != NULL); |
KASSERT(ip_pktq != NULL); |
|
|
for (u_int i = 0; i < IPPROTO_MAX; i++) { |
for (i = 0; i < IPPROTO_MAX; i++) { |
ip_protox[i] = pr - inetsw; |
ip_protox[i] = ippr - inetsw; |
} |
} |
for (pr = inetdomain.dom_protosw; |
for (i = 0; i < inetdomain.dom_nprotosw; i++) { |
pr < inetdomain.dom_protoswNPROTOSW; pr++) |
pr = inetdomain.dom_protosw[i]; |
|
ippr = container_of(pr, struct ipprotosw, ippr_protosw); |
if (pr->pr_domain->dom_family == PF_INET && |
if (pr->pr_domain->dom_family == PF_INET && |
pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) |
pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) |
ip_protox[pr->pr_protocol] = pr - inetsw; |
ip_protox[pr->pr_protocol] = ippr - inetsw; |
|
} |
|
|
ip_reass_init(); |
ip_reass_init(); |
|
|
ip_ids = ip_id_init(); |
ip_ids = ip_id_init(); |
ip_id = time_second & 0xfffff; |
ip_id = time_uptime & 0xfffff; |
|
|
ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); |
ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); |
#ifdef GATEWAY |
#ifdef GATEWAY |
Line 593 ip_input(struct mbuf *m) |
|
Line 606 ip_input(struct mbuf *m) |
|
* |
* |
* Traditional 4.4BSD did not consult IFF_UP at all. |
* Traditional 4.4BSD did not consult IFF_UP at all. |
* The behavior here is to treat addresses on !IFF_UP interface |
* The behavior here is to treat addresses on !IFF_UP interface |
* as not mine. |
* or IN_IFF_NOTREADY addresses as not mine. |
*/ |
*/ |
downmatch = 0; |
downmatch = 0; |
LIST_FOREACH(ia, &IN_IFADDR_HASH(ip->ip_dst.s_addr), ia_hash) { |
LIST_FOREACH(ia, &IN_IFADDR_HASH(ip->ip_dst.s_addr), ia_hash) { |
if (in_hosteq(ia->ia_addr.sin_addr, ip->ip_dst)) { |
if (in_hosteq(ia->ia_addr.sin_addr, ip->ip_dst)) { |
|
if (ia->ia4_flags & IN_IFF_NOTREADY) |
|
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) |
Line 613 ip_input(struct mbuf *m) |
|
Line 628 ip_input(struct mbuf *m) |
|
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) |
|
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) || |
/* |
/* |
|
|
* code - like UDP/TCP/raw IP. |
* code - like UDP/TCP/raw IP. |
*/ |
*/ |
if (ipsec_used && |
if (ipsec_used && |
(inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) { |
((inetsw[ip_protox[ip->ip_p]].ippr_protosw.pr_flags & PR_LASTHDR) |
|
!= 0)) { |
SOFTNET_LOCK(); |
SOFTNET_LOCK(); |
if (ipsec4_input(m, 0) != 0) { |
if (ipsec4_input(m, 0) != 0) { |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
|
|
const int off = hlen, nh = ip->ip_p; |
const int off = hlen, nh = ip->ip_p; |
|
|
SOFTNET_LOCK(); |
SOFTNET_LOCK(); |
(*inetsw[ip_protox[nh]].pr_input)(m, off, nh); |
(*inetsw[ip_protox[nh]].ippr_input)(m, off, nh); |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
return; |
return; |
bad: |
bad: |
Line 1189 ip_forward(struct mbuf *m, int srcrt) |
|
Line 1207 ip_forward(struct mbuf *m, int srcrt) |
|
struct sockaddr dst; |
struct sockaddr dst; |
struct sockaddr_in dst4; |
struct sockaddr_in dst4; |
} u; |
} u; |
|
uint64_t *ips; |
|
|
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 1269 ip_forward(struct mbuf *m, int srcrt) |
|
Line 1288 ip_forward(struct mbuf *m, int srcrt) |
|
(IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), |
(IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), |
NULL, NULL); |
NULL, NULL); |
|
|
if (error) |
if (error) { |
IP_STATINC(IP_STAT_CANTFORWARD); |
IP_STATINC(IP_STAT_CANTFORWARD); |
else { |
goto error; |
uint64_t *ips = IP_STAT_GETREF(); |
} |
ips[IP_STAT_FORWARD]++; |
|
if (type) { |
ips = IP_STAT_GETREF(); |
ips[IP_STAT_REDIRECTSENT]++; |
ips[IP_STAT_FORWARD]++; |
IP_STAT_PUTREF(); |
|
} else { |
if (type) { |
IP_STAT_PUTREF(); |
ips[IP_STAT_REDIRECTSENT]++; |
if (mcopy) { |
IP_STAT_PUTREF(); |
|
goto redirect; |
|
} |
|
|
|
IP_STAT_PUTREF(); |
|
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(&ipforward_rt, mcopy); |
#endif |
#endif |
m_freem(mcopy); |
m_freem(mcopy); |
} |
|
SOFTNET_UNLOCK(); |
|
return; |
|
} |
|
} |
} |
|
|
|
SOFTNET_UNLOCK(); |
|
return; |
|
|
|
redirect: |
|
error: |
if (mcopy == NULL) { |
if (mcopy == NULL) { |
SOFTNET_UNLOCK(); |
SOFTNET_UNLOCK(); |
return; |
return; |
Line 1568 sysctl_net_inet_ip_setup(struct sysctllo |
|
Line 1594 sysctl_net_inet_ip_setup(struct sysctllo |
|
sysctl_net_inet_ip_pmtudto, 0, (void *)&ip_mtudisc_timeout, 0, |
sysctl_net_inet_ip_pmtudto, 0, (void *)&ip_mtudisc_timeout, 0, |
CTL_NET, PF_INET, IPPROTO_IP, |
CTL_NET, PF_INET, IPPROTO_IP, |
IPCTL_MTUDISCTIMEOUT, CTL_EOL); |
IPCTL_MTUDISCTIMEOUT, CTL_EOL); |
#if NGIF > 0 |
|
sysctl_createv(clog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
|
CTLTYPE_INT, "gifttl", |
|
SYSCTL_DESCR("Default TTL for a gif tunnel datagram"), |
|
NULL, 0, &ip_gif_ttl, 0, |
|
CTL_NET, PF_INET, IPPROTO_IP, |
|
IPCTL_GIF_TTL, CTL_EOL); |
|
#endif /* NGIF */ |
|
#ifndef IPNOPRIVPORTS |
#ifndef IPNOPRIVPORTS |
sysctl_createv(clog, 0, NULL, NULL, |
sysctl_createv(clog, 0, NULL, NULL, |
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
Line 1633 sysctl_net_inet_ip_setup(struct sysctllo |
|
Line 1650 sysctl_net_inet_ip_setup(struct sysctllo |
|
sysctl_net_inet_ip_stats, 0, NULL, 0, |
sysctl_net_inet_ip_stats, 0, NULL, 0, |
CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS, |
CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS, |
CTL_EOL); |
CTL_EOL); |
|
#if NARP |
|
sysctl_createv(clog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
|
CTLTYPE_INT, "dad_count", |
|
SYSCTL_DESCR("Number of Duplicate Address Detection " |
|
"probes to send"), |
|
NULL, 0, &ip_dad_count, 0, |
|
CTL_NET, PF_INET, IPPROTO_IP, |
|
IPCTL_DAD_COUNT, CTL_EOL); |
|
#endif |
|
|
/* anonportalgo RFC6056 subtree */ |
/* anonportalgo RFC6056 subtree */ |
const struct sysctlnode *portalgo_node; |
const struct sysctlnode *portalgo_node; |