diff options
Diffstat (limited to 'gencode.c')
| -rw-r--r-- | gencode.c | 106 | 
1 files changed, 28 insertions, 78 deletions
| diff --git a/gencode.c b/gencode.c index 532229aae64a..cdb0d34e9f5a 100644 --- a/gencode.c +++ b/gencode.c @@ -107,6 +107,18 @@ static const char rcsid[] _U_ =  #define ETHERMTU	1500 +#ifndef IPPROTO_HOPOPTS +#define IPPROTO_HOPOPTS 0 +#endif +#ifndef IPPROTO_ROUTING +#define IPPROTO_ROUTING 43 +#endif +#ifndef IPPROTO_FRAGMENT +#define IPPROTO_FRAGMENT 44 +#endif +#ifndef IPPROTO_DSTOPTS +#define IPPROTO_DSTOPTS 60 +#endif  #ifndef IPPROTO_SCTP  #define IPPROTO_SCTP 132  #endif @@ -261,20 +273,16 @@ static struct block *gen_gateway(const u_char *, bpf_u_int32 **, int, int);  static struct block *gen_ipfrag(void);  static struct block *gen_portatom(int, bpf_int32);  static struct block *gen_portrangeatom(int, bpf_int32, bpf_int32); -#ifdef INET6  static struct block *gen_portatom6(int, bpf_int32);  static struct block *gen_portrangeatom6(int, bpf_int32, bpf_int32); -#endif  struct block *gen_portop(int, int, int);  static struct block *gen_port(int, int, int);  struct block *gen_portrangeop(int, int, int, int);  static struct block *gen_portrange(int, int, int, int); -#ifdef INET6  struct block *gen_portop6(int, int, int);  static struct block *gen_port6(int, int, int);  struct block *gen_portrangeop6(int, int, int, int);  static struct block *gen_portrange6(int, int, int, int); -#endif  static int lookup_proto(const char *, int);  static struct block *gen_protochain(int, int, int);  static struct block *gen_proto(int, int, int); @@ -425,6 +433,15 @@ pcap_compile(pcap_t *p, struct bpf_program *program,  	const char * volatile xbuf = buf;  	u_int len; +	/* +	 * If this pcap_t hasn't been activated, it doesn't have a +	 * link-layer type, so we can't use it. +	 */ +	if (!p->activated) { +		snprintf(p->errbuf, PCAP_ERRBUF_SIZE, +		    "not-yet-activated pcap_t passed to pcap_compile"); +		return (-1); +	}  	no_optimize = 0;  	n_errors = 0;  	root = NULL; @@ -2832,11 +2849,9 @@ ethertype_to_ppptype(proto)  		proto = PPP_IP;  		break; -#ifdef INET6  	case ETHERTYPE_IPV6:  		proto = PPP_IPV6;  		break; -#endif  	case ETHERTYPE_DN:  		proto = PPP_DECNET; @@ -3044,11 +3059,10 @@ gen_linktype(proto)  		case ETHERTYPE_IP:  			/* Check for a version number of 4. */  			return gen_mcmp(OR_LINK, 0, BPF_B, 0x40, 0xF0); -#ifdef INET6 +  		case ETHERTYPE_IPV6:  			/* Check for a version number of 6. */  			return gen_mcmp(OR_LINK, 0, BPF_B, 0x60, 0xF0); -#endif  		default:  			return gen_false();		/* always false */ @@ -3072,10 +3086,8 @@ gen_linktype(proto)  		/*  		 * Raw IPv6, so no type field.  		 */ -#ifdef INET6  		if (proto == ETHERTYPE_IPV6)  			return gen_true();		/* always true */ -#endif  		/* Checking for something other than IPv6; always false */  		return gen_false(); @@ -3197,11 +3209,9 @@ gen_linktype(proto)  		if (proto == ETHERTYPE_IP)  			return (gen_cmp(OR_LINK, offsetof(struct pfloghdr, af),  			    BPF_B, (bpf_int32)AF_INET)); -#ifdef INET6  		else if (proto == ETHERTYPE_IPV6)  			return (gen_cmp(OR_LINK, offsetof(struct pfloghdr, af),  			    BPF_B, (bpf_int32)AF_INET6)); -#endif /* INET6 */  		else  			return gen_false();  		/*NOTREACHED*/ @@ -3219,11 +3229,9 @@ gen_linktype(proto)  		default:  			return gen_false(); -#ifdef INET6  		case ETHERTYPE_IPV6:  			return (gen_cmp(OR_LINK, off_linktype, BPF_B,  				(bpf_int32)ARCTYPE_INET6)); -#endif /* INET6 */  		case ETHERTYPE_IP:  			b0 = gen_cmp(OR_LINK, off_linktype, BPF_B, @@ -3275,13 +3283,11 @@ gen_linktype(proto)  			 */  			return gen_cmp(OR_LINK, 2, BPF_H, (0x03<<8) | 0xcc); -#ifdef INET6  		case ETHERTYPE_IPV6:  			/*  			 * Check for the special NLPID for IPv6.  			 */  			return gen_cmp(OR_LINK, 2, BPF_H, (0x03<<8) | 0x8e); -#endif  		case LLCSAP_ISONS:  			/* @@ -3628,7 +3634,7 @@ gen_hostop6(addr, mask, dir, proto, src_off, dst_off)  	gen_and(b0, b1);  	return b1;  } -#endif /*INET6*/ +#endif  static struct block *  gen_ehostop(eaddr, dir) @@ -4506,13 +4512,11 @@ gen_host(addr, mask, proto, dir, type)  	case Q_MOPRC:  		bpf_error("MOPRC host filtering not implemented"); -#ifdef INET6  	case Q_IPV6:  		bpf_error("'ip6' modifier applied to ip host");  	case Q_ICMPV6:  		bpf_error("'icmp6' modifier applied to %s", typestr); -#endif /* INET6 */  	case Q_AH:  		bpf_error("'ah' modifier applied to %s", typestr); @@ -4669,7 +4673,7 @@ gen_host6(addr, mask, proto, dir, type)  	}  	/* NOTREACHED */  } -#endif /*INET6*/ +#endif  #ifndef INET6  static struct block * @@ -4761,26 +4765,20 @@ gen_proto_abbrev(proto)  	case Q_SCTP:  		b1 = gen_proto(IPPROTO_SCTP, Q_IP, Q_DEFAULT); -#ifdef INET6  		b0 = gen_proto(IPPROTO_SCTP, Q_IPV6, Q_DEFAULT);  		gen_or(b0, b1); -#endif  		break;  	case Q_TCP:  		b1 = gen_proto(IPPROTO_TCP, Q_IP, Q_DEFAULT); -#ifdef INET6  		b0 = gen_proto(IPPROTO_TCP, Q_IPV6, Q_DEFAULT);  		gen_or(b0, b1); -#endif  		break;  	case Q_UDP:  		b1 = gen_proto(IPPROTO_UDP, Q_IP, Q_DEFAULT); -#ifdef INET6  		b0 = gen_proto(IPPROTO_UDP, Q_IPV6, Q_DEFAULT);  		gen_or(b0, b1); -#endif  		break;  	case Q_ICMP: @@ -4808,10 +4806,8 @@ gen_proto_abbrev(proto)  	case Q_PIM:  		b1 = gen_proto(IPPROTO_PIM, Q_IP, Q_DEFAULT); -#ifdef INET6  		b0 = gen_proto(IPPROTO_PIM, Q_IPV6, Q_DEFAULT);  		gen_or(b0, b1); -#endif  		break;  #ifndef IPPROTO_VRRP @@ -4873,7 +4869,6 @@ gen_proto_abbrev(proto)  		b1 =  gen_linktype(ETHERTYPE_MOPRC);  		break; -#ifdef INET6  	case Q_IPV6:  		b1 = gen_linktype(ETHERTYPE_IPV6);  		break; @@ -4884,17 +4879,14 @@ gen_proto_abbrev(proto)  	case Q_ICMPV6:  		b1 = gen_proto(IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT);  		break; -#endif /* INET6 */  #ifndef IPPROTO_AH  #define IPPROTO_AH	51  #endif  	case Q_AH:  		b1 = gen_proto(IPPROTO_AH, Q_IP, Q_DEFAULT); -#ifdef INET6  		b0 = gen_proto(IPPROTO_AH, Q_IPV6, Q_DEFAULT);  		gen_or(b0, b1); -#endif  		break;  #ifndef IPPROTO_ESP @@ -4902,10 +4894,8 @@ gen_proto_abbrev(proto)  #endif  	case Q_ESP:  		b1 = gen_proto(IPPROTO_ESP, Q_IP, Q_DEFAULT); -#ifdef INET6  		b0 = gen_proto(IPPROTO_ESP, Q_IPV6, Q_DEFAULT);  		gen_or(b0, b1); -#endif  		break;  	case Q_ISO: @@ -5038,7 +5028,6 @@ gen_portatom(off, v)  	return gen_cmp(OR_TRAN_IPV4, off, BPF_H, v);  } -#ifdef INET6  static struct block *  gen_portatom6(off, v)  	int off; @@ -5046,7 +5035,6 @@ gen_portatom6(off, v)  {  	return gen_cmp(OR_TRAN_IPV6, off, BPF_H, v);  } -#endif/*INET6*/  struct block *  gen_portop(port, proto, dir) @@ -5138,7 +5126,6 @@ gen_port(port, ip_proto, dir)  	return b1;  } -#ifdef INET6  struct block *  gen_portop6(port, proto, dir)  	int port, proto, dir; @@ -5211,7 +5198,6 @@ gen_port6(port, ip_proto, dir)  	gen_and(b0, b1);  	return b1;  } -#endif /* INET6 */  /* gen_portrange code */  static struct block * @@ -5316,7 +5302,6 @@ gen_portrange(port1, port2, ip_proto, dir)  	return b1;  } -#ifdef INET6  static struct block *  gen_portrangeatom6(off, v1, v2)  	int off; @@ -5417,7 +5402,6 @@ gen_portrange6(port1, port2, ip_proto, dir)  	gen_and(b0, b1);  	return b1;  } -#endif /* INET6 */  static int  lookup_proto(name, proto) @@ -5552,7 +5536,7 @@ gen_protochain(v, proto, dir)  		s[i]->s.k = off_macpl + off_nl;  		i++;  		break; -#ifdef INET6 +  	case Q_IPV6:  		b0 = gen_linktype(ETHERTYPE_IPV6); @@ -5565,7 +5549,7 @@ gen_protochain(v, proto, dir)  		s[i]->s.k = 40;  		i++;  		break; -#endif +  	default:  		bpf_error("unsupported proto to gen_protochain");  		/*NOTREACHED*/ @@ -5592,7 +5576,6 @@ gen_protochain(v, proto, dir)  	fix2 = i;  	i++; -#ifdef INET6  	if (proto == Q_IPV6) {  		int v6start, v6end, v6advance, j; @@ -5674,9 +5657,7 @@ gen_protochain(v, proto, dir)  		/* fixup */  		for (j = v6start; j <= v6end; j++)  			s[j]->s.jt = s[v6advance]; -	} else -#endif -	{ +	} else {  		/* nop */  		s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K);  		s[i]->s.k = 0; @@ -5820,25 +5801,20 @@ gen_proto(v, proto, dir)  	int dir;  {  	struct block *b0, *b1; -#ifdef INET6  #ifndef CHASE_CHAIN  	struct block *b2;  #endif -#endif  	if (dir != Q_DEFAULT)  		bpf_error("direction applied to 'proto'");  	switch (proto) {  	case Q_DEFAULT: -#ifdef INET6  		b0 = gen_proto(v, Q_IP, dir);  		b1 = gen_proto(v, Q_IPV6, dir);  		gen_or(b0, b1);  		return b1; -#else -		/*FALLTHROUGH*/ -#endif +  	case Q_IP:  		/*  		 * For FDDI, RFC 1188 says that SNAP encapsulation is used, @@ -5989,7 +5965,6 @@ gen_proto(v, proto, dir)  		bpf_error("'carp proto' is bogus");  		/* NOTREACHED */ -#ifdef INET6  	case Q_IPV6:  		b0 = gen_linktype(ETHERTYPE_IPV6);  #ifndef CHASE_CHAIN @@ -6010,7 +5985,6 @@ gen_proto(v, proto, dir)  	case Q_ICMPV6:  		bpf_error("'icmp6 proto' is bogus"); -#endif /* INET6 */  	case Q_AH:  		bpf_error("'ah proto' is bogus"); @@ -6267,13 +6241,9 @@ gen_scode(name, q)  			bpf_error("illegal port number %d < 0", port);  		if (port > 65535)  			bpf_error("illegal port number %d > 65535", port); -#ifndef INET6 -		return gen_port(port, real_proto, dir); -#else  		b = gen_port(port, real_proto, dir);  		gen_or(gen_port6(port, real_proto, dir), b);  		return b; -#endif /* INET6 */  	case Q_PORTRANGE:  		if (proto != Q_DEFAULT && @@ -6317,13 +6287,9 @@ gen_scode(name, q)  		if (port2 > 65535)  			bpf_error("illegal port number %d > 65535", port2); -#ifndef INET6 -		return gen_portrange(port1, port2, real_proto, dir); -#else  		b = gen_portrange(port1, port2, real_proto, dir);  		gen_or(gen_portrange6(port1, port2, real_proto, dir), b);  		return b; -#endif /* INET6 */  	case Q_GATEWAY:  #ifndef INET6 @@ -6471,16 +6437,12 @@ gen_ncode(s, v, q)  		if (v > 65535)  			bpf_error("illegal port number %u > 65535", v); -#ifndef INET6 -		return gen_port((int)v, proto, dir); -#else  	    {  		struct block *b;  		b = gen_port((int)v, proto, dir);  		gen_or(gen_port6((int)v, proto, dir), b);  		return b;  	    } -#endif /* INET6 */  	case Q_PORTRANGE:  		if (proto == Q_UDP) @@ -6497,16 +6459,12 @@ gen_ncode(s, v, q)  		if (v > 65535)  			bpf_error("illegal port number %u > 65535", v); -#ifndef INET6 -		return gen_portrange((int)v, (int)v, proto, dir); -#else  	    {  		struct block *b;  		b = gen_portrange((int)v, (int)v, proto, dir);  		gen_or(gen_portrange6((int)v, (int)v, proto, dir), b);  		return b;  	    } -#endif /* INET6 */  	case Q_GATEWAY:  		bpf_error("'gateway' requires a name"); @@ -6796,9 +6754,7 @@ gen_load(proto, inst, size)  	case Q_LAT:  	case Q_MOPRC:  	case Q_MOPDL: -#ifdef INET6  	case Q_IPV6: -#endif  		/*  		 * The offset is relative to the beginning of  		 * the network-layer header. @@ -6907,16 +6863,12 @@ gen_load(proto, inst, size)  		gen_and(gen_proto_abbrev(proto), b = gen_ipfrag());  		if (inst->b)  			gen_and(inst->b, b); -#ifdef INET6  		gen_and(gen_proto_abbrev(Q_IP), b); -#endif  		inst->b = b;  		break; -#ifdef INET6  	case Q_ICMPV6:  		bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");  		/*NOTREACHED*/ -#endif  	}  	inst->regno = regno;  	s = new_stmt(BPF_ST); @@ -7468,13 +7420,11 @@ gen_multicast(proto)  		gen_and(b0, b1);  		return b1; -#ifdef INET6  	case Q_IPV6:  		b0 = gen_linktype(ETHERTYPE_IPV6);  		b1 = gen_cmp(OR_NET, 24, BPF_B, (bpf_int32)255);  		gen_and(b0, b1);  		return b1; -#endif /* INET6 */  	}  	bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");  	/* NOTREACHED */ | 
