Skip to content

Commit 9b15cc6

Browse files
committed
Support both "igrp" and "eigrp" in filters.
Use our own header to define IPPROTO_ values, rather than leaving them up to the OS for which we're building. Always use IP protocol 9 for "igrp", and use IP protocol 88 for "eigrp". 9 is assigned to "any private Internet gateway protocol", and is mainly used for Cisco's IGRP. 88 is for Cisco's EIGRP, which is not compatible on-the-wire with IGRP. FreeBSD, DragonFly BSD and macOS define IPPROTO_IGRP as 88, rather than as 9, and their libpcaps use IP protocol 88 for "igrp". Everybody else uses IP protocol 9 for "igrp".
1 parent b33f396 commit 9b15cc6

File tree

7 files changed

+203
-35
lines changed

7 files changed

+203
-35
lines changed

Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ HDR = $(PUBHDR) \
126126
ftmacros.h \
127127
gencode.h \
128128
ieee80211.h \
129+
ipproto.h \
129130
llc.h \
130131
nametoaddr.h \
131132
optimize.h \

gencode.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121

2222
#include <config.h>
2323

24-
#ifdef _WIN32
25-
#include <ws2tcpip.h>
26-
#else
27-
#include <netinet/in.h>
28-
#endif /* _WIN32 */
29-
3024
#include <stdlib.h>
3125
#include <string.h>
3226
#include <memory.h>
@@ -41,6 +35,7 @@
4135

4236
#include "ethertype.h"
4337
#include "llc.h"
38+
#include "ipproto.h"
4439
#include "gencode.h"
4540
#include "ieee80211.h"
4641
#include "pflog.h"
@@ -5190,6 +5185,9 @@ gen_host(compiler_state_t *cstate, bpf_u_int32 addr, bpf_u_int32 mask,
51905185
case Q_IGRP:
51915186
bpf_error(cstate, "'igrp' modifier applied to %s", typestr);
51925187

5188+
case Q_EIGRP:
5189+
bpf_error(cstate, "'eigrp' modifier applied to %s", typestr);
5190+
51935191
case Q_ATALK:
51945192
bpf_error(cstate, "AppleTalk host filtering not implemented");
51955193

@@ -5330,6 +5328,9 @@ gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
53305328
case Q_IGRP:
53315329
bpf_error(cstate, "'igrp' modifier applied to ip6 %s", typestr);
53325330

5331+
case Q_EIGRP:
5332+
bpf_error(cstate, "'eigrp' modifier applied to ip6 %s", typestr);
5333+
53335334
case Q_ATALK:
53345335
bpf_error(cstate, "AppleTalk modifier applied to ip6 %s", typestr);
53355336

@@ -5554,41 +5555,39 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
55545555
b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT);
55555556
break;
55565557

5557-
#ifndef IPPROTO_IGMP
5558-
#define IPPROTO_IGMP 2
5559-
#endif
5560-
55615558
case Q_IGMP:
55625559
b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT);
55635560
break;
55645561

5565-
#ifndef IPPROTO_IGRP
5566-
#define IPPROTO_IGRP 9
5567-
#endif
55685562
case Q_IGRP:
5569-
b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT);
5563+
/*
5564+
* XXX - the current IANA protocol number assignments
5565+
* page lists 9 as "any private interior gateway
5566+
* (used by Cisco for their IGRP)" and 88 as
5567+
* "EIGRP" from Cisco.
5568+
*
5569+
* Recent FreeBSD, DragonFly BSD, and macOS <netinet/in.h>
5570+
* headers define IPPROTO_PIGP ("private interior gateway
5571+
* protocol") as 9 and IPPROTO_IGRP as 88. We define
5572+
* IPPROTO_PIGP as 9 and IPPROTO_EIGRP as 88; those
5573+
* names better match what the current protocol number
5574+
* assignments say.
5575+
*/
5576+
b1 = gen_proto(cstate, IPPROTO_PIGP, Q_IP, Q_DEFAULT);
55705577
break;
55715578

5572-
#ifndef IPPROTO_PIM
5573-
#define IPPROTO_PIM 103
5574-
#endif
5579+
case Q_EIGRP:
5580+
b1 = gen_proto(cstate, IPPROTO_EIGRP, Q_IP, Q_DEFAULT);
5581+
break;
55755582

55765583
case Q_PIM:
55775584
b1 = gen_proto(cstate, IPPROTO_PIM, Q_DEFAULT, Q_DEFAULT);
55785585
break;
55795586

5580-
#ifndef IPPROTO_VRRP
5581-
#define IPPROTO_VRRP 112
5582-
#endif
5583-
55845587
case Q_VRRP:
55855588
b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT);
55865589
break;
55875590

5588-
#ifndef IPPROTO_CARP
5589-
#define IPPROTO_CARP 112
5590-
#endif
5591-
55925591
case Q_CARP:
55935592
b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT);
55945593
break;
@@ -5640,23 +5639,14 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
56405639
b1 = gen_linktype(cstate, ETHERTYPE_IPV6);
56415640
break;
56425641

5643-
#ifndef IPPROTO_ICMPV6
5644-
#define IPPROTO_ICMPV6 58
5645-
#endif
56465642
case Q_ICMPV6:
56475643
b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT);
56485644
break;
56495645

5650-
#ifndef IPPROTO_AH
5651-
#define IPPROTO_AH 51
5652-
#endif
56535646
case Q_AH:
56545647
b1 = gen_proto(cstate, IPPROTO_AH, Q_DEFAULT, Q_DEFAULT);
56555648
break;
56565649

5657-
#ifndef IPPROTO_ESP
5658-
#define IPPROTO_ESP 50
5659-
#endif
56605650
case Q_ESP:
56615651
b1 = gen_proto(cstate, IPPROTO_ESP, Q_DEFAULT, Q_DEFAULT);
56625652
break;
@@ -6659,6 +6649,10 @@ gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
66596649
bpf_error(cstate, "'igrp proto' is bogus");
66606650
/*NOTREACHED*/
66616651

6652+
case Q_EIGRP:
6653+
bpf_error(cstate, "'eigrp proto' is bogus");
6654+
/*NOTREACHED*/
6655+
66626656
case Q_ATALK:
66636657
bpf_error(cstate, "AppleTalk encapsulation is not specifiable");
66646658
/*NOTREACHED*/
@@ -7919,6 +7913,7 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst,
79197913
case Q_ICMP:
79207914
case Q_IGMP:
79217915
case Q_IGRP:
7916+
case Q_EIGRP:
79227917
case Q_PIM:
79237918
case Q_VRRP:
79247919
case Q_CARP:

gencode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134

135135
#define Q_CARP 39
136136

137+
#define Q_EIGRP 40
138+
137139
/* Directional qualifiers. */
138140

139141
#define Q_SRC 1

grammar.y.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ DIAG_OFF_BISON_BYACC
376376

377377
%token DST SRC HOST GATEWAY
378378
%token NET NETMASK PORT PORTRANGE LESS GREATER PROTO PROTOCHAIN CBYTE
379-
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP PIM VRRP CARP
379+
%token ARP RARP IP SCTP TCP UDP ICMP IGMP IGRP EIGRP PIM VRRP CARP
380380
%token ATALK AARP DECNET LAT SCA MOPRC MOPDL
381381
%token TK_BROADCAST TK_MULTICAST
382382
%token NUM INBOUND OUTBOUND
@@ -640,6 +640,7 @@ pname: LINK { $$ = Q_LINK; }
640640
| ICMP { $$ = Q_ICMP; }
641641
| IGMP { $$ = Q_IGMP; }
642642
| IGRP { $$ = Q_IGRP; }
643+
| EIGRP { $$ = Q_EIGRP; }
643644
| PIM { $$ = Q_PIM; }
644645
| VRRP { $$ = Q_VRRP; }
645646
| CARP { $$ = Q_CARP; }

ipproto.h

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright (c) 1982, 1986, 1990, 1993
3+
* The Regents of the University of California. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. All advertising materials mentioning features or use of this software
14+
* must display the following acknowledgement:
15+
* This product includes software developed by the University of
16+
* California, Berkeley and its contributors.
17+
* 4. Neither the name of the University nor the names of its contributors
18+
* may be used to endorse or promote products derived from this software
19+
* without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31+
* SUCH DAMAGE.
32+
*
33+
* From:
34+
* @(#)in.h 8.3 (Berkeley) 1/3/94
35+
* $FreeBSD: src/sys/netinet/in.h,v 1.38.2.3 1999/08/29 16:29:34 peter Exp $
36+
*/
37+
38+
#ifndef IPPROTO_IP
39+
#define IPPROTO_IP 0 /* dummy for IP */
40+
#endif
41+
#ifndef IPPROTO_HOPOPTS
42+
#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */
43+
#endif
44+
#ifndef IPPROTO_ICMP
45+
#define IPPROTO_ICMP 1 /* control message protocol */
46+
#endif
47+
#ifndef IPPROTO_IGMP
48+
#define IPPROTO_IGMP 2 /* group mgmt protocol */
49+
#endif
50+
#ifndef IPPROTO_IPV4
51+
#define IPPROTO_IPV4 4
52+
#endif
53+
#ifndef IPPROTO_TCP
54+
#define IPPROTO_TCP 6 /* tcp */
55+
#endif
56+
#ifndef IPPROTO_EGP
57+
#define IPPROTO_EGP 8 /* exterior gateway protocol */
58+
#endif
59+
/*
60+
* XXX - the current IANA protocol number assignments page lists 9 as
61+
* "any private interior gateway (used by Cisco for their IGRP)" and
62+
* 88 as "EIGRP" from Cisco.
63+
*
64+
* Recent FreeBSD, DragonFly BSD, and macOS <netinet/in.h> headers define
65+
* IPPROTO_PIGP ("private interior gateway protocol") as 9 and
66+
* IPPROTO_IGRP as 88. We define IPPROTO_PIGP as 9 and IPPROTO_EIGRP
67+
* as 88; those names better match what the current protocol number
68+
* assignments say.
69+
*/
70+
#ifndef IPPROTO_PIGP
71+
#define IPPROTO_PIGP 9
72+
#endif
73+
#ifndef IPPROTO_UDP
74+
#define IPPROTO_UDP 17 /* user datagram protocol */
75+
#endif
76+
#ifndef IPPROTO_DCCP
77+
#define IPPROTO_DCCP 33 /* datagram congestion control protocol */
78+
#endif
79+
#ifndef IPPROTO_IPV6
80+
#define IPPROTO_IPV6 41
81+
#endif
82+
#ifndef IPPROTO_ROUTING
83+
#define IPPROTO_ROUTING 43 /* IPv6 routing header */
84+
#endif
85+
#ifndef IPPROTO_FRAGMENT
86+
#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */
87+
#endif
88+
#ifndef IPPROTO_RSVP
89+
#define IPPROTO_RSVP 46 /* resource reservation */
90+
#endif
91+
#ifndef IPPROTO_GRE
92+
#define IPPROTO_GRE 47 /* General Routing Encap. */
93+
#endif
94+
#ifndef IPPROTO_ESP
95+
#define IPPROTO_ESP 50 /* SIPP Encap Sec. Payload */
96+
#endif
97+
#ifndef IPPROTO_AH
98+
#define IPPROTO_AH 51 /* SIPP Auth Header */
99+
#endif
100+
#ifndef IPPROTO_NHRP
101+
#define IPPROTO_NHRP 54 /* Next Hop Resolution */
102+
#endif
103+
#ifndef IPPROTO_MOBILE
104+
#define IPPROTO_MOBILE 55
105+
#endif
106+
#ifndef IPPROTO_ICMPV6
107+
#define IPPROTO_ICMPV6 58 /* ICMPv6 */
108+
#endif
109+
#ifndef IPPROTO_NONE
110+
#define IPPROTO_NONE 59 /* IPv6 no next header */
111+
#endif
112+
#ifndef IPPROTO_DSTOPTS
113+
#define IPPROTO_DSTOPTS 60 /* IPv6 destination options */
114+
#endif
115+
#ifndef IPPROTO_MOBILITY_OLD
116+
/*
117+
* The current Protocol Numbers list says that the IP protocol number for
118+
* mobility headers is 135; it cites RFC 6275 (obsoletes RFC 3775).
119+
*
120+
* It appears that 62 used to be used, even though that's assigned to
121+
* a protocol called CFTP; however, the only reference for CFTP is a
122+
* Network Message from BBN back in 1982, so, for now, we support 62,
123+
* as well as 135, as a protocol number for mobility headers.
124+
*/
125+
#define IPPROTO_MOBILITY_OLD 62
126+
#endif
127+
#ifndef IPPROTO_ND
128+
#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */
129+
#endif
130+
#ifndef IPPROTO_EIGRP
131+
#define IPPROTO_EIGRP 88 /* Cisco/GXS IGRP */
132+
#endif
133+
#ifndef IPPROTO_OSPF
134+
#define IPPROTO_OSPF 89
135+
#endif
136+
#ifndef IPPROTO_PIM
137+
#define IPPROTO_PIM 103
138+
#endif
139+
#ifndef IPPROTO_IPCOMP
140+
#define IPPROTO_IPCOMP 108
141+
#endif
142+
#ifndef IPPROTO_VRRP
143+
#define IPPROTO_VRRP 112 /* See also CARP. */
144+
#endif
145+
#ifndef IPPROTO_CARP
146+
#define IPPROTO_CARP 112
147+
#endif
148+
#ifndef IPPROTO_PGM
149+
#define IPPROTO_PGM 113
150+
#endif
151+
#ifndef IPPROTO_SCTP
152+
#define IPPROTO_SCTP 132
153+
#endif
154+
#ifndef IPPROTO_MOBILITY
155+
#define IPPROTO_MOBILITY 135
156+
#endif
157+
#ifndef IPPROTO_ETHERNET
158+
#define IPPROTO_ETHERNET 143 /* TEMPORARY - registered 2020-01-31, expires 2021-01-31 */
159+
#endif

pcap-filter.manmisc.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ Abbreviation for:
354354
\fBip proto\fR 9
355355
.fi
356356
.in -.5i
357+
.IP "\fBeigrp\fR"
358+
Abbreviation for:
359+
.in +.5i
360+
.nf
361+
\fBip proto\fR 88
362+
.fi
363+
.in -.5i
357364
.IP "\fBip6 proto \fIprotocol\fR"
358365
True if the packet is an IPv6 packet of protocol type \fIprotocol\fP.
359366
(See `\fBip proto\fP' above for the meaning of \fIprotocol\fR.)
@@ -1015,6 +1022,7 @@ is one of
10151022
.BR atalk ,
10161023
.BR carp ,
10171024
.BR decnet ,
1025+
.BR eigrp ,
10181026
.BR ether ,
10191027
.BR fddi ,
10201028
.BR icmp ,
@@ -1075,6 +1083,7 @@ This check is implicitly applied to the
10751083
.BR igmp ,
10761084
.BR pim ,
10771085
.BR igrp ,
1086+
.BR eigrp ,
10781087
.BR vrrp
10791088
and
10801089
.BR carp

scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ udp return UDP;
258258
icmp return ICMP;
259259
igmp return IGMP;
260260
igrp return IGRP;
261+
eigrp return EIGRP;
261262
pim return PIM;
262263
vrrp return VRRP;
263264
carp return CARP;

0 commit comments

Comments
 (0)