Introduce a struct icmphdr which contains the type, code, and cksum

fields of an ICMP packet.

Use this to allow ipfw to pullup only these values since it does not use
the rest of the packet and it was failed on ICMP packets because they
were not long enough.

struct icmp should probably be modified to use these at some point, but
that will break a fair bit of code so it can wait for another day.

On the off chance that adding this struct breaks something in ports,
bump __FreeBSD_version.

Reported by:	Randy Bush <randy at psg dot com>
Tested by:	Randy Bush <randy at psg dot com>
This commit is contained in:
Brooks Davis 2005-04-26 18:10:21 +00:00
parent b190ee6140
commit 31519b13c8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=145565
3 changed files with 17 additions and 10 deletions

View file

@ -328,11 +328,11 @@ SYSCTL_INT(_net_inet_ip_fw, OID_AUTO, dyn_keepalive, CTLFLAG_RW,
#define L3HDR(T, ip) ((T *)((u_int32_t *)(ip) + (ip)->ip_hl))
#define TCP(p) ((struct tcphdr *)(p))
#define UDP(p) ((struct udphdr *)(p))
#define ICMP(p) ((struct icmp *)(p))
#define ICMP(p) ((struct icmphdr *)(p))
#define ICMP6(p) ((struct icmp6_hdr *)(p))
static __inline int
icmptype_match(struct icmp *icmp, ipfw_insn_u32 *cmd)
icmptype_match(struct icmphdr *icmp, ipfw_insn_u32 *cmd)
{
int type = icmp->icmp_type;
@ -343,7 +343,7 @@ icmptype_match(struct icmp *icmp, ipfw_insn_u32 *cmd)
(1 << ICMP_TSTAMP) | (1 << ICMP_IREQ) | (1 << ICMP_MASKREQ) )
static int
is_icmp_query(struct icmp *icmp)
is_icmp_query(struct icmphdr *icmp)
{
int type = icmp->icmp_type;
@ -760,7 +760,7 @@ ipfw_log(struct ip_fw *f, u_int hlen, struct ether_header *eh,
} else {
struct ip *ip = mtod(m, struct ip *);
/* these three are all aliases to the same thing */
struct icmp *const icmp = L3HDR(struct icmp, ip);
struct icmphdr *const icmp = L3HDR(struct icmphdr, ip);
struct tcphdr *const tcp = (struct tcphdr *)icmp;
struct udphdr *const udp = (struct udphdr *)icmp;
@ -2108,11 +2108,7 @@ do { \
break;
case IPPROTO_ICMP:
/*
* we only care for 4 bytes: type, code,
* checksum
*/
PULLUP_TO(hlen, ulp, struct icmp);
PULLUP_TO(hlen, ulp, struct icmphdr);
args->f_id.flags = ICMP(ulp)->icmp_type;
break;

View file

@ -49,6 +49,17 @@ struct icmp_ra_addr {
/*
* Structure of an icmp header.
*/
struct icmphdr {
u_char icmp_type; /* type of message, see below */
u_char icmp_code; /* type sub code */
u_short icmp_cksum; /* ones complement cksum of struct */
};
/*
* Structure of an icmp packet.
*
* XXX: should start with a struct icmphdr.
*/
struct icmp {
u_char icmp_type; /* type of message, see below */
u_char icmp_code; /* type sub code */

View file

@ -57,7 +57,7 @@
* is created, otherwise 1.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 600024 /* Master, propagated to newvers */
#define __FreeBSD_version 600025 /* Master, propagated to newvers */
#ifndef LOCORE
#include <sys/types.h>