-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix off-by-one bug in ebpf backend mask computation (#2815)
* Fix off-by-one bug in ebpf backend
- Loading branch information
Mihai Budiu
authored
Jun 23, 2021
1 parent
138eb79
commit d9ba230
Showing
8 changed files
with
358 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <ebpf_model.p4> | ||
#include <core.p4> | ||
|
||
#include "ebpf_headers.p4" | ||
|
||
struct Headers_t { | ||
Ethernet_h ethernet; | ||
IPv4_h ipv4; | ||
} | ||
|
||
parser prs(packet_in p, out Headers_t headers) { | ||
state start { | ||
p.extract(headers.ethernet); | ||
transition select(headers.ethernet.etherType, 16w1) { | ||
(16w0x800, 16w1) : ip; | ||
default : reject; | ||
} | ||
} | ||
|
||
state ip { | ||
p.extract(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control pipe(inout Headers_t headers, out bool pass) { | ||
action invalidate() { | ||
headers.ipv4.setInvalid(); | ||
headers.ethernet.setInvalid(); | ||
pass = true; | ||
} | ||
action drop() { | ||
pass = false; | ||
} | ||
table t { | ||
key = { | ||
headers.ipv4.srcAddr : exact; | ||
headers.ipv4.dstAddr : exact; | ||
headers.ethernet.dstAddr : exact; | ||
headers.ethernet.srcAddr: exact; | ||
} | ||
actions = { | ||
invalidate; drop; | ||
} | ||
implementation = hash_table(10); | ||
default_action = drop; | ||
} | ||
|
||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
ebpfFilter(prs(), pipe()) main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <core.p4> | ||
#include <ebpf_model.p4> | ||
|
||
@ethernetaddress typedef bit<48> EthernetAddress; | ||
@ipv4address typedef bit<32> IPv4Address; | ||
header Ethernet_h { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header IPv4_h { | ||
bit<4> version; | ||
bit<4> ihl; | ||
bit<8> diffserv; | ||
bit<16> totalLen; | ||
bit<16> identification; | ||
bit<3> flags; | ||
bit<13> fragOffset; | ||
bit<8> ttl; | ||
bit<8> protocol; | ||
bit<16> hdrChecksum; | ||
IPv4Address srcAddr; | ||
IPv4Address dstAddr; | ||
} | ||
|
||
struct Headers_t { | ||
Ethernet_h ethernet; | ||
IPv4_h ipv4; | ||
} | ||
|
||
parser prs(packet_in p, out Headers_t headers) { | ||
state start { | ||
p.extract<Ethernet_h>(headers.ethernet); | ||
transition select(headers.ethernet.etherType, 16w1) { | ||
(16w0x800, 16w1): ip; | ||
default: reject; | ||
} | ||
} | ||
state ip { | ||
p.extract<IPv4_h>(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control pipe(inout Headers_t headers, out bool pass) { | ||
action invalidate() { | ||
headers.ipv4.setInvalid(); | ||
headers.ethernet.setInvalid(); | ||
pass = true; | ||
} | ||
action drop() { | ||
pass = false; | ||
} | ||
table t { | ||
key = { | ||
headers.ipv4.srcAddr : exact @name("headers.ipv4.srcAddr") ; | ||
headers.ipv4.dstAddr : exact @name("headers.ipv4.dstAddr") ; | ||
headers.ethernet.dstAddr: exact @name("headers.ethernet.dstAddr") ; | ||
headers.ethernet.srcAddr: exact @name("headers.ethernet.srcAddr") ; | ||
} | ||
actions = { | ||
invalidate(); | ||
drop(); | ||
} | ||
implementation = hash_table(32w10); | ||
default_action = drop(); | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
ebpfFilter<Headers_t>(prs(), pipe()) main; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <core.p4> | ||
#include <ebpf_model.p4> | ||
|
||
@ethernetaddress typedef bit<48> EthernetAddress; | ||
@ipv4address typedef bit<32> IPv4Address; | ||
header Ethernet_h { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header IPv4_h { | ||
bit<4> version; | ||
bit<4> ihl; | ||
bit<8> diffserv; | ||
bit<16> totalLen; | ||
bit<16> identification; | ||
bit<3> flags; | ||
bit<13> fragOffset; | ||
bit<8> ttl; | ||
bit<8> protocol; | ||
bit<16> hdrChecksum; | ||
IPv4Address srcAddr; | ||
IPv4Address dstAddr; | ||
} | ||
|
||
struct Headers_t { | ||
Ethernet_h ethernet; | ||
IPv4_h ipv4; | ||
} | ||
|
||
parser prs(packet_in p, out Headers_t headers) { | ||
state start { | ||
p.extract<Ethernet_h>(headers.ethernet); | ||
transition select(headers.ethernet.etherType, 16w1) { | ||
(16w0x800, 16w1): ip; | ||
default: reject; | ||
} | ||
} | ||
state ip { | ||
p.extract<IPv4_h>(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control pipe(inout Headers_t headers, out bool pass) { | ||
@name("pipe.invalidate") action invalidate() { | ||
headers.ipv4.setInvalid(); | ||
headers.ethernet.setInvalid(); | ||
pass = true; | ||
} | ||
@name("pipe.drop") action drop() { | ||
pass = false; | ||
} | ||
@name("pipe.t") table t_0 { | ||
key = { | ||
headers.ipv4.srcAddr : exact @name("headers.ipv4.srcAddr") ; | ||
headers.ipv4.dstAddr : exact @name("headers.ipv4.dstAddr") ; | ||
headers.ethernet.dstAddr: exact @name("headers.ethernet.dstAddr") ; | ||
headers.ethernet.srcAddr: exact @name("headers.ethernet.srcAddr") ; | ||
} | ||
actions = { | ||
invalidate(); | ||
drop(); | ||
} | ||
implementation = hash_table(32w10); | ||
default_action = drop(); | ||
} | ||
apply { | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
ebpfFilter<Headers_t>(prs(), pipe()) main; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <core.p4> | ||
#include <ebpf_model.p4> | ||
|
||
@ethernetaddress typedef bit<48> EthernetAddress; | ||
@ipv4address typedef bit<32> IPv4Address; | ||
header Ethernet_h { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header IPv4_h { | ||
bit<4> version; | ||
bit<4> ihl; | ||
bit<8> diffserv; | ||
bit<16> totalLen; | ||
bit<16> identification; | ||
bit<3> flags; | ||
bit<13> fragOffset; | ||
bit<8> ttl; | ||
bit<8> protocol; | ||
bit<16> hdrChecksum; | ||
IPv4Address srcAddr; | ||
IPv4Address dstAddr; | ||
} | ||
|
||
struct Headers_t { | ||
Ethernet_h ethernet; | ||
IPv4_h ipv4; | ||
} | ||
|
||
parser prs(packet_in p, out Headers_t headers) { | ||
state start { | ||
p.extract<Ethernet_h>(headers.ethernet); | ||
transition select(headers.ethernet.etherType, 16w1) { | ||
(16w0x800, 16w1): ip; | ||
default: reject; | ||
} | ||
} | ||
state ip { | ||
p.extract<IPv4_h>(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control pipe(inout Headers_t headers, out bool pass) { | ||
@name("pipe.invalidate") action invalidate() { | ||
headers.ipv4.setInvalid(); | ||
headers.ethernet.setInvalid(); | ||
pass = true; | ||
} | ||
@name("pipe.drop") action drop() { | ||
pass = false; | ||
} | ||
@name("pipe.t") table t_0 { | ||
key = { | ||
headers.ipv4.srcAddr : exact @name("headers.ipv4.srcAddr") ; | ||
headers.ipv4.dstAddr : exact @name("headers.ipv4.dstAddr") ; | ||
headers.ethernet.dstAddr: exact @name("headers.ethernet.dstAddr") ; | ||
headers.ethernet.srcAddr: exact @name("headers.ethernet.srcAddr") ; | ||
} | ||
actions = { | ||
invalidate(); | ||
drop(); | ||
} | ||
implementation = hash_table(32w10); | ||
default_action = drop(); | ||
} | ||
apply { | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
ebpfFilter<Headers_t>(prs(), pipe()) main; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <core.p4> | ||
#include <ebpf_model.p4> | ||
|
||
@ethernetaddress typedef bit<48> EthernetAddress; | ||
@ipv4address typedef bit<32> IPv4Address; | ||
header Ethernet_h { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header IPv4_h { | ||
bit<4> version; | ||
bit<4> ihl; | ||
bit<8> diffserv; | ||
bit<16> totalLen; | ||
bit<16> identification; | ||
bit<3> flags; | ||
bit<13> fragOffset; | ||
bit<8> ttl; | ||
bit<8> protocol; | ||
bit<16> hdrChecksum; | ||
IPv4Address srcAddr; | ||
IPv4Address dstAddr; | ||
} | ||
|
||
struct Headers_t { | ||
Ethernet_h ethernet; | ||
IPv4_h ipv4; | ||
} | ||
|
||
parser prs(packet_in p, out Headers_t headers) { | ||
state start { | ||
p.extract(headers.ethernet); | ||
transition select(headers.ethernet.etherType, 16w1) { | ||
(16w0x800, 16w1): ip; | ||
default: reject; | ||
} | ||
} | ||
state ip { | ||
p.extract(headers.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control pipe(inout Headers_t headers, out bool pass) { | ||
action invalidate() { | ||
headers.ipv4.setInvalid(); | ||
headers.ethernet.setInvalid(); | ||
pass = true; | ||
} | ||
action drop() { | ||
pass = false; | ||
} | ||
table t { | ||
key = { | ||
headers.ipv4.srcAddr : exact; | ||
headers.ipv4.dstAddr : exact; | ||
headers.ethernet.dstAddr: exact; | ||
headers.ethernet.srcAddr: exact; | ||
} | ||
actions = { | ||
invalidate; | ||
drop; | ||
} | ||
implementation = hash_table(10); | ||
default_action = drop; | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
ebpfFilter(prs(), pipe()) main; | ||
|
Empty file.