Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/ip_icmp.c
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
#ifdef INET | #ifdef INET | ||||
#include <machine/in_cksum.h> | #include <machine/in_cksum.h> | ||||
#include <security/mac/mac_framework.h> | #include <security/mac/mac_framework.h> | ||||
#endif /* INET */ | #endif /* INET */ | ||||
extern ipproto_ctlinput_t *ip_ctlprotox[]; | |||||
/* | /* | ||||
* ICMP routines: error generation, receive packet processing, and | * ICMP routines: error generation, receive packet processing, and | ||||
* routines to turnaround packets back to the originator, and | * routines to turnaround packets back to the originator, and | ||||
* host table maintenance routines. | * host table maintenance routines. | ||||
*/ | */ | ||||
VNET_DEFINE_STATIC(int, icmplim) = 200; | VNET_DEFINE_STATIC(int, icmplim) = 200; | ||||
#define V_icmplim VNET(icmplim) | #define V_icmplim VNET(icmplim) | ||||
SYSCTL_INT(_net_inet_icmp, ICMPCTL_ICMPLIM, icmplim, CTLFLAG_VNET | CTLFLAG_RW, | SYSCTL_INT(_net_inet_icmp, ICMPCTL_ICMPLIM, icmplim, CTLFLAG_VNET | CTLFLAG_RW, | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
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); | ||||
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 | ||||
* support won't cause binary compatibility problems for kernel modules. | * support won't cause binary compatibility problems for kernel modules. | ||||
*/ | */ | ||||
void | void | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | icmp_input(struct mbuf **mp, int *offp, int proto) | ||||
struct icmp *icp; | struct icmp *icp; | ||||
struct in_ifaddr *ia; | struct in_ifaddr *ia; | ||||
struct mbuf *m = *mp; | struct mbuf *m = *mp; | ||||
struct ip *ip = mtod(m, struct ip *); | struct ip *ip = mtod(m, struct ip *); | ||||
struct sockaddr_in icmpsrc, icmpdst, icmpgw; | struct sockaddr_in icmpsrc, icmpdst, icmpgw; | ||||
int hlen = *offp; | int hlen = *offp; | ||||
int icmplen = ntohs(ip->ip_len) - *offp; | int icmplen = ntohs(ip->ip_len) - *offp; | ||||
int i, code; | int i, code; | ||||
void (*ctlfunc)(int, struct sockaddr *, void *); | |||||
int fibnum; | int fibnum; | ||||
NET_EPOCH_ASSERT(); | NET_EPOCH_ASSERT(); | ||||
*mp = NULL; | *mp = NULL; | ||||
/* | /* | ||||
* Locate icmp structure in mbuf, and check | * Locate icmp structure in mbuf, and check | ||||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | #endif | ||||
/* | /* | ||||
* 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. | ||||
*/ | */ | ||||
ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput; | if (ip_ctlprotox[icp->icmp_ip.ip_p] != NULL) | ||||
if (ctlfunc) | ip_ctlprotox[icp->icmp_ip.ip_p](code, | ||||
(*ctlfunc)(code, (struct sockaddr *)&icmpsrc, | (struct sockaddr *)&icmpsrc, &icp->icmp_ip); | ||||
(void *)&icp->icmp_ip); | |||||
break; | break; | ||||
melifaro: Shouldn't it be like the following, so we're sure that the condition always works as expected? | |||||
badcode: | badcode: | ||||
ICMPSTAT_INC(icps_badcode); | ICMPSTAT_INC(icps_badcode); | ||||
break; | break; | ||||
case ICMP_ECHO: | case ICMP_ECHO: | ||||
if (!V_icmpbmcastecho | if (!V_icmpbmcastecho | ||||
&& (m->m_flags & (M_MCAST | M_BCAST)) != 0) { | && (m->m_flags & (M_MCAST | M_BCAST)) != 0) { | ||||
▲ Show 20 Lines • Show All 569 Lines • Show Last 20 Lines |
Shouldn't it be like the following, so we're sure that the condition always works as expected?