Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/ip_input.c
Show First 20 Lines • Show All 436 Lines • ▼ Show 20 Lines | |||||
void | void | ||||
ip_input(struct mbuf *m) | ip_input(struct mbuf *m) | ||||
{ | { | ||||
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; | uint32_t ip_len; | ||||
uint16_t sum; | |||||
int dchg = 0; /* dest changed after fw */ | int dchg = 0; /* dest changed after fw */ | ||||
struct in_addr odst; /* original dst address */ | struct in_addr odst; /* original dst address */ | ||||
M_ASSERTPKTHDR(m); | M_ASSERTPKTHDR(m); | ||||
if (m->m_flags & M_FASTFWD_OURS) { | if (m->m_flags & M_FASTFWD_OURS) { | ||||
m->m_flags &= ~M_FASTFWD_OURS; | m->m_flags &= ~M_FASTFWD_OURS; | ||||
/* Set up some basics that will be used later. */ | /* Set up some basics that will be used later. */ | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | ip_input(struct mbuf *m) | ||||
} | } | ||||
#ifdef ALTQ | #ifdef ALTQ | ||||
if (altq_input != NULL && (*altq_input)(m, AF_INET) == 0) | if (altq_input != NULL && (*altq_input)(m, AF_INET) == 0) | ||||
/* packet is dropped by traffic conditioner */ | /* packet is dropped by traffic conditioner */ | ||||
return; | return; | ||||
#endif | #endif | ||||
if (M_HASHTYPE_GET(m) == M_HASHTYPE_LRO_TCP) | |||||
ip_len = m->m_pkthdr.len; | |||||
else | |||||
ip_len = ntohs(ip->ip_len); | ip_len = ntohs(ip->ip_len); | ||||
if (ip_len < hlen) { | if (ip_len < hlen) { | ||||
IPSTAT_INC(ips_badlen); | IPSTAT_INC(ips_badlen); | ||||
goto bad; | goto bad; | ||||
} | } | ||||
/* | /* | ||||
* Check that the amount of data in the buffers | * Check that the amount of data in the buffers | ||||
* is as at least much as the IP header would have us expect. | * is as at least much as the IP header would have us expect. | ||||
▲ Show 20 Lines • Show All 907 Lines • ▼ Show 20 Lines | |||||
ip_forward(struct mbuf *m, int srcrt) | ip_forward(struct mbuf *m, int srcrt) | ||||
{ | { | ||||
struct ip *ip = mtod(m, struct ip *); | struct ip *ip = mtod(m, struct ip *); | ||||
struct in_ifaddr *ia; | struct in_ifaddr *ia; | ||||
struct mbuf *mcopy; | struct mbuf *mcopy; | ||||
struct in_addr dest; | struct in_addr dest; | ||||
struct route ro; | struct route ro; | ||||
int error, type = 0, code = 0, mtu = 0; | int error, type = 0, code = 0, mtu = 0; | ||||
int ip_len; | |||||
imp: Shouldn't this be unsigned? | |||||
if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) { | if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) { | ||||
IPSTAT_INC(ips_cantforward); | IPSTAT_INC(ips_cantforward); | ||||
m_freem(m); | m_freem(m); | ||||
return; | return; | ||||
} | } | ||||
#ifdef IPSEC | #ifdef IPSEC | ||||
if (ip_ipsec_fwd(m) != 0) { | if (ip_ipsec_fwd(m) != 0) { | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (mcopy != NULL && !m_dup_pkthdr(mcopy, m, M_NOWAIT)) { | ||||
* It's probably ok if the pkthdr dup fails (because | * It's probably ok if the pkthdr dup fails (because | ||||
* the deep copy of the tag chain failed), but for now | * the deep copy of the tag chain failed), but for now | ||||
* be conservative and just discard the copy since | * be conservative and just discard the copy since | ||||
* code below may some day want the tags. | * code below may some day want the tags. | ||||
*/ | */ | ||||
m_free(mcopy); | m_free(mcopy); | ||||
mcopy = NULL; | mcopy = NULL; | ||||
} | } | ||||
if (M_HASHTYPE_GET(m) == M_HASHTYPE_LRO_TCP) | |||||
ip_len = m->m_pkthdr.len; | |||||
else | |||||
ip_len = ntohs(ip->ip_len); | |||||
if (mcopy != NULL) { | if (mcopy != NULL) { | ||||
mcopy->m_len = min(ntohs(ip->ip_len), M_TRAILINGSPACE(mcopy)); | mcopy->m_len = min(ip_len, M_TRAILINGSPACE(mcopy)); | ||||
mcopy->m_pkthdr.len = mcopy->m_len; | mcopy->m_pkthdr.len = mcopy->m_len; | ||||
m_copydata(m, 0, mcopy->m_len, mtod(mcopy, caddr_t)); | m_copydata(m, 0, mcopy->m_len, mtod(mcopy, caddr_t)); | ||||
} | } | ||||
#ifdef IPSTEALTH | #ifdef IPSTEALTH | ||||
if (!V_ipstealth) { | if (!V_ipstealth) { | ||||
#endif | #endif | ||||
ip->ip_ttl -= IPTTLDEC; | ip->ip_ttl -= IPTTLDEC; | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | #endif /* IPSEC */ | ||||
*/ | */ | ||||
if (mtu != 0) { | if (mtu != 0) { | ||||
if (ia != NULL) | if (ia != NULL) | ||||
mtu = min(mtu, ia->ia_ifp->if_mtu); | mtu = min(mtu, ia->ia_ifp->if_mtu); | ||||
} else { | } else { | ||||
if (ia != NULL) | if (ia != NULL) | ||||
mtu = ia->ia_ifp->if_mtu; | mtu = ia->ia_ifp->if_mtu; | ||||
else | else | ||||
mtu = ip_next_mtu(ntohs(ip->ip_len), 0); | mtu = ip_next_mtu(ip_len, 0); | ||||
} | } | ||||
IPSTAT_INC(ips_cantfrag); | IPSTAT_INC(ips_cantfrag); | ||||
break; | break; | ||||
case ENOBUFS: | case ENOBUFS: | ||||
case EACCES: /* ipfw denied packet */ | case EACCES: /* ipfw denied packet */ | ||||
m_freem(mcopy); | m_freem(mcopy); | ||||
if (ia != NULL) | if (ia != NULL) | ||||
▲ Show 20 Lines • Show All 227 Lines • Show Last 20 Lines |
Shouldn't this be unsigned?