Skip to content

Commit 5200398

Browse files
committed
Add 'icmp' support to nbpf
1 parent 1772745 commit 5200398

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

userland/nbpf/grammar.y

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void yyerror(const char *msg) {
4949
%token OUTER INNER
5050
%token DST SRC HOST
5151
%token NET NETMASK PORT PORTRANGE PROTO
52-
%token ARP RARP IP SCTP TCP UDP
52+
%token ARP RARP IP SCTP TCP UDP ICMP
5353
%token NUM
5454
%token DIR
5555
%token LINK
@@ -177,6 +177,7 @@ pname: LINK { $$ = NBPF_Q_LINK; }
177177
| SCTP { $$ = NBPF_Q_SCTP; }
178178
| TCP { $$ = NBPF_Q_TCP; }
179179
| UDP { $$ = NBPF_Q_UDP; }
180+
| ICMP { $$ = NBPF_Q_ICMP; }
180181
| IPV6 { $$ = NBPF_Q_IPV6; }
181182
;
182183
other: VLAN pnum { $$.n = nbpf_create_vlan_node($2); }

userland/nbpf/nbpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ nbpf_ip_addr;
8585
#define NBPF_Q_UDP 5
8686
#define NBPF_Q_IPV6 6
8787
#define NBPF_Q_GTP 7
88+
#define NBPF_Q_ICMP 8
8889

8990
/* Direction qualifiers */
9091
#define NBPF_Q_SRC 1

userland/nbpf/nbpftest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static char *proto_to_string(int protoq) {
7676
switch(protoq) {
7777
case NBPF_Q_LINK: return "Eth";
7878
case NBPF_Q_IP: return "IP";
79+
case NBPF_Q_ICMP: return "ICMP";
7980
case NBPF_Q_SCTP: return "SCTP";
8081
case NBPF_Q_TCP: return "TCP";
8182
case NBPF_Q_UDP: return "UDP";

userland/nbpf/parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ nbpf_node_t *nbpf_create_protocol_node(int proto) {
530530
case NBPF_Q_TCP:
531531
case NBPF_Q_UDP:
532532
case NBPF_Q_SCTP:
533+
case NBPF_Q_ICMP:
533534
n->qualifiers.protocol = NBPF_Q_IP;
534535
break;
535536
default:
@@ -542,6 +543,7 @@ nbpf_node_t *nbpf_create_protocol_node(int proto) {
542543
case NBPF_Q_TCP: n->protocol = 6; break;
543544
case NBPF_Q_UDP: n->protocol = 17; break;
544545
case NBPF_Q_SCTP: n->protocol = 132; break;
546+
case NBPF_Q_ICMP: n->protocol = 1; break;
545547
//default: n->protocol = proto; break;
546548
}
547549

userland/nbpf/scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ ip return IP;
7474
sctp return SCTP;
7575
tcp return TCP;
7676
udp return UDP;
77+
icmp return ICMP;
7778
ip6 return IPV6;
7879

7980
host return HOST;

0 commit comments

Comments
 (0)