From: George Neville-Neil Date: Sun, 20 Nov 2011 00:57:03 +0000 (-0800) Subject: Add support for CARP. X-Git-Tag: libpcap-1.2.1~25 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/59a971d93df078875f26430e9bddc4165b23697f Add support for CARP. Allow "carp" to be used as a filter, rather than requiring "ip proto 112" or one of "ip proto {vrrp,carp}" depending on whether you're running an OS that chooses to have 112 as CARP rather than VRRP in /etc/protocols. (Yes, that means that "carp" will capture VRRP packets. So it goes....) Reviewed-By: Guy Harris --- diff --git a/gencode.c b/gencode.c index b3d36a8c..ff90fbb8 100644 --- a/gencode.c +++ b/gencode.c @@ -4666,6 +4666,9 @@ gen_host(addr, mask, proto, dir, type) case Q_VRRP: bpf_error("'vrrp' modifier applied to %s", typestr); + case Q_CARP: + bpf_error("'carp' modifier applied to %s", typestr); + case Q_ATALK: bpf_error("ATALK host filtering not implemented"); @@ -4785,6 +4788,9 @@ gen_host6(addr, mask, proto, dir, type) case Q_VRRP: bpf_error("'vrrp' modifier applied to %s", typestr); + case Q_CARP: + bpf_error("'carp' modifier applied to %s", typestr); + case Q_ATALK: bpf_error("ATALK host filtering not implemented"); @@ -5000,6 +5006,14 @@ gen_proto_abbrev(proto) b1 = gen_proto(IPPROTO_VRRP, Q_IP, Q_DEFAULT); break; +#ifndef IPPROTO_CARP +#define IPPROTO_CARP 112 +#endif + + case Q_CARP: + b1 = gen_proto(IPPROTO_CARP, Q_IP, Q_DEFAULT); + break; + case Q_IP: b1 = gen_linktype(ETHERTYPE_IP); break; @@ -6159,6 +6173,10 @@ gen_proto(v, proto, dir) bpf_error("'vrrp proto' is bogus"); /* NOTREACHED */ + case Q_CARP: + bpf_error("'carp proto' is bogus"); + /* NOTREACHED */ + #ifdef INET6 case Q_IPV6: b0 = gen_linktype(ETHERTYPE_IPV6); @@ -7020,6 +7038,7 @@ gen_load(proto, inst, size) case Q_IGRP: case Q_PIM: case Q_VRRP: + case Q_CARP: /* * The offset is relative to the beginning of * the transport-layer header. diff --git a/gencode.h b/gencode.h index 4f710038..e8b0593d 100644 --- a/gencode.h +++ b/gencode.h @@ -126,6 +126,8 @@ #define Q_RADIO 40 +#define Q_CARP 41 + /* Directional qualifiers. */ #define Q_SRC 1 diff --git a/grammar.y b/grammar.y index cbb93639..f2ba28b1 100644 --- a/grammar.y +++ b/grammar.y @@ -272,7 +272,7 @@ pfaction_to_num(const char *action) %token DST SRC HOST GATEWAY %token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE -%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP +%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP %token ATALK AARP DECNET LAT SCA MOPRC MOPDL %token TK_BROADCAST TK_MULTICAST %token NUM INBOUND OUTBOUND @@ -466,6 +466,7 @@ pname: LINK { $$ = Q_LINK; } | IGRP { $$ = Q_IGRP; } | PIM { $$ = Q_PIM; } | VRRP { $$ = Q_VRRP; } + | CARP { $$ = Q_CARP; } | ATALK { $$ = Q_ATALK; } | AARP { $$ = Q_AARP; } | DECNET { $$ = Q_DECNET; } diff --git a/scanner.l b/scanner.l index 2b1f729d..064e9c88 100644 --- a/scanner.l +++ b/scanner.l @@ -203,6 +203,7 @@ igmp return IGMP; igrp return IGRP; pim return PIM; vrrp return VRRP; +carp return CARP; radio return RADIO; ip6 {