Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/ip_icmp.c
Show First 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | |||||
#ifdef ICMPPRINTFS | #ifdef ICMPPRINTFS | ||||
int icmpprintfs = 0; | int icmpprintfs = 0; | ||||
#endif | #endif | ||||
static void icmp_reflect(struct mbuf *); | static void icmp_reflect(struct mbuf *); | ||||
static void icmp_send(struct mbuf *, struct mbuf *); | static void icmp_send(struct mbuf *, struct mbuf *); | ||||
static int icmp_verify_redirect_gateway(struct sockaddr_in *, | static int icmp_verify_redirect_gateway(struct sockaddr_in *, | ||||
struct sockaddr_in *, struct sockaddr_in *, u_int); | struct sockaddr_in *, struct sockaddr_in *, u_int); | ||||
static void icmp_pmtu_update(const struct icmp *, const int); | |||||
extern struct protosw inetsw[]; | extern struct protosw inetsw[]; | ||||
/* | /* | ||||
* Kernel module interface for updating icmpstat. The argument is an index | * Kernel module interface for updating icmpstat. The argument is an index | ||||
* into icmpstat treated as an array of u_long. While this encodes the | * into icmpstat treated as an array of u_long. While this encodes the | ||||
* general layout of icmpstat into the caller, it doesn't encode its | * general layout of icmpstat into the caller, it doesn't encode its | ||||
* location, so that future changes to add, for example, per-CPU stats | * location, so that future changes to add, for example, per-CPU stats | ||||
▲ Show 20 Lines • Show All 363 Lines • ▼ Show 20 Lines | #endif | ||||
ip_stripoptions(m); | ip_stripoptions(m); | ||||
if (m->m_len < i && (m = m_pullup(m, i)) == NULL) { | if (m->m_len < i && (m = m_pullup(m, i)) == NULL) { | ||||
/* This should actually not happen */ | /* This should actually not happen */ | ||||
ICMPSTAT_INC(icps_tooshort); | ICMPSTAT_INC(icps_tooshort); | ||||
return (IPPROTO_DONE); | return (IPPROTO_DONE); | ||||
} | } | ||||
ip = mtod(m, struct ip *); | ip = mtod(m, struct ip *); | ||||
icp = (struct icmp *)(ip + 1); | icp = (struct icmp *)(ip + 1); | ||||
/* Update PMTU to make it available for upper layers. */ | |||||
if (V_rfc1191) | |||||
icmp_pmtu_update(icp, M_GETFIB(m)); | |||||
/* | /* | ||||
* The upper layer handler can rely on: | * The upper layer handler can rely on: | ||||
* - The outer IP header has no options. | * - The outer IP header has no options. | ||||
* - The outer IP header, the ICMP header, the inner IP header, | * - The outer IP header, the ICMP header, the inner IP header, | ||||
* and the first n bytes of the inner payload are contiguous. | * and the first n bytes of the inner payload are contiguous. | ||||
* n is at least 8, but might be larger based on | * n is at least 8, but might be larger based on | ||||
* ICMP_ADVLENPREF. See its definition in ip_icmp.h. | * ICMP_ADVLENPREF. See its definition in ip_icmp.h. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 484 Lines • ▼ Show 20 Lines | ip_next_mtu(int mtu, int dir) | ||||
} else { | } else { | ||||
for (i = size - 1; i >= 0; i--) | for (i = size - 1; i >= 0; i--) | ||||
if (mtu < mtutab[i]) | if (mtu < mtutab[i]) | ||||
return mtutab[i]; | return mtutab[i]; | ||||
if (mtu == mtutab[0]) | if (mtu == mtutab[0]) | ||||
return mtutab[0]; | return mtutab[0]; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | |||||
/* | |||||
* Update path MTU from an ICMP message into the hostcache. | |||||
* | |||||
* Update only happens if the new MTU is smaller than the nexthop MTU. Values | |||||
* smaller than IP_MMTU are ignored. | |||||
*/ | |||||
static void | |||||
icmp_pmtu_update(const struct icmp *icmp, const int fibnum) | |||||
{ | |||||
uint32_t mtu = ntohs(icmp->icmp_nextmtu); | |||||
struct in_conninfo inc; | |||||
/* Pre-RFC1191 routers don't specify the mtu. */ | |||||
if (mtu == 0) | |||||
mtu = ip_next_mtu(icmp->icmp_ip.ip_len, 1); | |||||
/* Ignore values less than minimum. */ | |||||
if (mtu < IP_MMTU) | |||||
return; | |||||
bzero(&inc, sizeof(inc)); | |||||
inc.inc_fibnum = fibnum; | |||||
inc.inc_faddr = icmp->icmp_ip.ip_dst; | |||||
if (mtu < tcp_maxmtu(&inc, NULL)) { | |||||
tcp_hc_updatemtu(&inc, mtu); | |||||
ICMPSTAT_INC(icps_pmtuchg); | |||||
} | |||||
} | } | ||||
#endif /* INET */ | #endif /* INET */ | ||||
/* | /* | ||||
* badport_bandlim() - check for ICMP bandwidth limit | * badport_bandlim() - check for ICMP bandwidth limit | ||||
* | * | ||||
* Return 0 if it is ok to send an ICMP error response, -1 if we have | * Return 0 if it is ok to send an ICMP error response, -1 if we have | ||||
* hit our bandwidth limit and it is not ok. | * hit our bandwidth limit and it is not ok. | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |