Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/ip_input.c
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
#include <netinet/in_pcb.h> | #include <netinet/in_pcb.h> | ||||
#include <netinet/ip_var.h> | #include <netinet/ip_var.h> | ||||
#include <netinet/ip_fw.h> | #include <netinet/ip_fw.h> | ||||
#include <netinet/ip_icmp.h> | #include <netinet/ip_icmp.h> | ||||
#include <netinet/ip_options.h> | #include <netinet/ip_options.h> | ||||
#include <machine/in_cksum.h> | #include <machine/in_cksum.h> | ||||
#include <netinet/ip_carp.h> | #include <netinet/ip_carp.h> | ||||
#include <netinet/in_rss.h> | #include <netinet/in_rss.h> | ||||
#include <netinet/ip_mroute.h> | |||||
#include <netipsec/ipsec_support.h> | #include <netipsec/ipsec_support.h> | ||||
#include <sys/socketvar.h> | #include <sys/socketvar.h> | ||||
#include <security/mac/mac_framework.h> | #include <security/mac/mac_framework.h> | ||||
#ifdef CTASSERT | #ifdef CTASSERT | ||||
▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Ip input routine. Checksum and byte swap header. If fragmented | * Ip input routine. Checksum and byte swap header. If fragmented | ||||
* try to reassemble. Process options. Pass to next level. | * try to reassemble. Process options. Pass to next level. | ||||
*/ | */ | ||||
void | void | ||||
ip_input(struct mbuf *m) | ip_input(struct mbuf *m) | ||||
{ | { | ||||
MROUTER_RLOCK_TRACKER; | |||||
struct rm_priotracker in_ifa_tracker; | struct rm_priotracker in_ifa_tracker; | ||||
struct ip *ip = NULL; | struct ip *ip = NULL; | ||||
struct in_ifaddr *ia = NULL; | struct in_ifaddr *ia = NULL; | ||||
struct ifaddr *ifa; | struct ifaddr *ifa; | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
int checkif, hlen = 0; | int checkif, hlen = 0; | ||||
uint16_t sum, ip_len; | uint16_t sum, ip_len; | ||||
int dchg = 0; /* dest changed after fw */ | int dchg = 0; /* dest changed after fw */ | ||||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
/* RFC 3927 2.7: Do not forward datagrams for 169.254.0.0/16. */ | /* RFC 3927 2.7: Do not forward datagrams for 169.254.0.0/16. */ | ||||
if (IN_LINKLOCAL(ntohl(ip->ip_dst.s_addr))) { | if (IN_LINKLOCAL(ntohl(ip->ip_dst.s_addr))) { | ||||
IPSTAT_INC(ips_cantforward); | IPSTAT_INC(ips_cantforward); | ||||
m_freem(m); | m_freem(m); | ||||
return; | return; | ||||
} | } | ||||
if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) { | if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) { | ||||
MROUTER_RLOCK(); | |||||
if (V_ip_mrouter) { | if (V_ip_mrouter) { | ||||
/* | /* | ||||
* If we are acting as a multicast router, all | * If we are acting as a multicast router, all | ||||
* incoming multicast packets are passed to the | * incoming multicast packets are passed to the | ||||
* kernel-level multicast forwarding function. | * kernel-level multicast forwarding function. | ||||
* The packet is returned (relatively) intact; if | * The packet is returned (relatively) intact; if | ||||
* ip_mforward() returns a non-zero value, the packet | * ip_mforward() returns a non-zero value, the packet | ||||
* must be discarded, else it may be accepted below. | * must be discarded, else it may be accepted below. | ||||
*/ | */ | ||||
if (ip_mforward && ip_mforward(ip, ifp, m, 0) != 0) { | if (ip_mforward && ip_mforward(ip, ifp, m, 0) != 0) { | ||||
MROUTER_RUNLOCK(); | |||||
IPSTAT_INC(ips_cantforward); | IPSTAT_INC(ips_cantforward); | ||||
m_freem(m); | m_freem(m); | ||||
return; | return; | ||||
} | } | ||||
/* | /* | ||||
* The process-level routing daemon needs to receive | * The process-level routing daemon needs to receive | ||||
* all multicast IGMP packets, whether or not this | * all multicast IGMP packets, whether or not this | ||||
* host belongs to their destination groups. | * host belongs to their destination groups. | ||||
*/ | */ | ||||
if (ip->ip_p == IPPROTO_IGMP) | if (ip->ip_p == IPPROTO_IGMP) { | ||||
MROUTER_RUNLOCK(); | |||||
goto ours; | goto ours; | ||||
} | |||||
IPSTAT_INC(ips_forward); | IPSTAT_INC(ips_forward); | ||||
} | } | ||||
MROUTER_RUNLOCK(); | |||||
/* | /* | ||||
* Assume the packet is for us, to avoid prematurely taking | * Assume the packet is for us, to avoid prematurely taking | ||||
* a lock on the in_multi hash. Protocols must perform | * a lock on the in_multi hash. Protocols must perform | ||||
* their own filtering and update statistics accordingly. | * their own filtering and update statistics accordingly. | ||||
*/ | */ | ||||
goto ours; | goto ours; | ||||
} | } | ||||
if (ip->ip_dst.s_addr == (u_long)INADDR_BROADCAST) | if (ip->ip_dst.s_addr == (u_long)INADDR_BROADCAST) | ||||
▲ Show 20 Lines • Show All 647 Lines • Show Last 20 Lines |