-
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 incorrect field extraction arithmetic when multiple non-byte alig…
…ned header fields are combined into single byte aligned field (#4301)
- Loading branch information
Showing
28 changed files
with
1,420 additions
and
803 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
Copyright 2023 Intel Corporation | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include <core.p4> | ||
#include "dpdk/pna.p4" | ||
|
||
|
||
typedef bit<48> EthernetAddress; | ||
|
||
header ethernet_t { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header ipv4_t { | ||
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; | ||
bit<32> srcAddr; | ||
bit<32> dstAddr; | ||
} | ||
|
||
struct user_metadata_t { | ||
bit<1> ipv4_hdr_truncated; | ||
} | ||
|
||
struct headers_t { | ||
ethernet_t ethernet; | ||
ipv4_t ipv4; | ||
} | ||
|
||
control PreControlImpl( | ||
in headers_t hdr, | ||
inout user_metadata_t meta, | ||
in pna_pre_input_metadata_t istd, | ||
inout pna_pre_output_metadata_t ostd) | ||
{ | ||
apply { | ||
} | ||
} | ||
|
||
parser MainParserImpl( | ||
packet_in pkt, | ||
out headers_t hdr, | ||
inout user_metadata_t user_meta, | ||
in pna_main_parser_input_metadata_t istd) | ||
{ | ||
state start { | ||
user_meta.ipv4_hdr_truncated = 0; | ||
pkt.extract(hdr.ethernet); | ||
transition select(hdr.ethernet.etherType) { | ||
0x0800: parse_ipv4; | ||
default: accept; | ||
} | ||
} | ||
state parse_ipv4 { | ||
bit<4> ihl = pkt.lookahead<ipv4_t>().ihl; | ||
transition select (ihl) { | ||
0x0 &&& 0xC : parse_ipv4_ihl_too_small; //0-3 | ||
0x4 : parse_ipv4_ihl_too_small; | ||
default : parse_ipv4_ok; | ||
} | ||
} | ||
state parse_ipv4_ihl_too_small { | ||
user_meta.ipv4_hdr_truncated = 1; | ||
transition accept; | ||
} | ||
state parse_ipv4_ok { | ||
pkt.extract(hdr.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control MainControlImpl( | ||
inout headers_t hdr, // from main parser | ||
inout user_metadata_t user_meta, // from main parser, to "next block" | ||
in pna_main_input_metadata_t istd, | ||
inout pna_main_output_metadata_t ostd) | ||
{ | ||
apply { | ||
if (hdr.ethernet.isValid()) { | ||
bit<8> tmp; | ||
tmp = 0; | ||
tmp[0:0] = user_meta.ipv4_hdr_truncated; | ||
tmp[1:1] = (bit<1>) hdr.ipv4.isValid(); | ||
hdr.ethernet.srcAddr[7:0] = tmp; | ||
} | ||
} | ||
} | ||
|
||
control MainDeparserImpl( | ||
packet_out pkt, | ||
in headers_t hdr, // from main control | ||
in user_metadata_t user_meta, // from main control | ||
in pna_main_output_metadata_t ostd) | ||
{ | ||
apply { | ||
pkt.emit(hdr.ethernet); | ||
pkt.emit(hdr.ipv4); | ||
} | ||
} | ||
|
||
// BEGIN:Package_Instantiation_Example | ||
PNA_NIC( | ||
MainParserImpl(), | ||
PreControlImpl(), | ||
MainControlImpl(), | ||
MainDeparserImpl() | ||
// Hoping to make this optional parameter later, but not supported | ||
// by p4c yet. | ||
//, PreParserImpl() | ||
) main; | ||
// END:Package_Instantiation_Example |
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
86 changes: 86 additions & 0 deletions
86
testdata/p4_16_samples_outputs/pna-dpdk-parser-wrong-arith-first.p4
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,86 @@ | ||
#include <core.p4> | ||
#include <dpdk/pna.p4> | ||
|
||
typedef bit<48> EthernetAddress; | ||
header ethernet_t { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header ipv4_t { | ||
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; | ||
bit<32> srcAddr; | ||
bit<32> dstAddr; | ||
} | ||
|
||
struct user_metadata_t { | ||
bit<1> ipv4_hdr_truncated; | ||
} | ||
|
||
struct headers_t { | ||
ethernet_t ethernet; | ||
ipv4_t ipv4; | ||
} | ||
|
||
control PreControlImpl(in headers_t hdr, inout user_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { | ||
apply { | ||
} | ||
} | ||
|
||
parser MainParserImpl(packet_in pkt, out headers_t hdr, inout user_metadata_t user_meta, in pna_main_parser_input_metadata_t istd) { | ||
state start { | ||
user_meta.ipv4_hdr_truncated = 1w0; | ||
pkt.extract<ethernet_t>(hdr.ethernet); | ||
transition select(hdr.ethernet.etherType) { | ||
16w0x800: parse_ipv4; | ||
default: accept; | ||
} | ||
} | ||
state parse_ipv4 { | ||
bit<4> ihl = (pkt.lookahead<ipv4_t>()).ihl; | ||
transition select(ihl) { | ||
4w0x0 &&& 4w0xc: parse_ipv4_ihl_too_small; | ||
4w0x4: parse_ipv4_ihl_too_small; | ||
default: parse_ipv4_ok; | ||
} | ||
} | ||
state parse_ipv4_ihl_too_small { | ||
user_meta.ipv4_hdr_truncated = 1w1; | ||
transition accept; | ||
} | ||
state parse_ipv4_ok { | ||
pkt.extract<ipv4_t>(hdr.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control MainControlImpl(inout headers_t hdr, inout user_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { | ||
apply { | ||
if (hdr.ethernet.isValid()) { | ||
bit<8> tmp; | ||
tmp = 8w0; | ||
tmp[0:0] = user_meta.ipv4_hdr_truncated; | ||
tmp[1:1] = (bit<1>)hdr.ipv4.isValid(); | ||
hdr.ethernet.srcAddr[7:0] = tmp; | ||
} | ||
} | ||
} | ||
|
||
control MainDeparserImpl(packet_out pkt, in headers_t hdr, in user_metadata_t user_meta, in pna_main_output_metadata_t ostd) { | ||
apply { | ||
pkt.emit<ethernet_t>(hdr.ethernet); | ||
pkt.emit<ipv4_t>(hdr.ipv4); | ||
} | ||
} | ||
|
||
PNA_NIC<headers_t, user_metadata_t, headers_t, user_metadata_t>(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; |
89 changes: 89 additions & 0 deletions
89
testdata/p4_16_samples_outputs/pna-dpdk-parser-wrong-arith-frontend.p4
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,89 @@ | ||
#include <core.p4> | ||
#include <dpdk/pna.p4> | ||
|
||
typedef bit<48> EthernetAddress; | ||
header ethernet_t { | ||
EthernetAddress dstAddr; | ||
EthernetAddress srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
header ipv4_t { | ||
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; | ||
bit<32> srcAddr; | ||
bit<32> dstAddr; | ||
} | ||
|
||
struct user_metadata_t { | ||
bit<1> ipv4_hdr_truncated; | ||
} | ||
|
||
struct headers_t { | ||
ethernet_t ethernet; | ||
ipv4_t ipv4; | ||
} | ||
|
||
control PreControlImpl(in headers_t hdr, inout user_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { | ||
apply { | ||
} | ||
} | ||
|
||
parser MainParserImpl(packet_in pkt, out headers_t hdr, inout user_metadata_t user_meta, in pna_main_parser_input_metadata_t istd) { | ||
@name("MainParserImpl.ihl") bit<4> ihl_0; | ||
@name("MainParserImpl.tmp") ipv4_t tmp; | ||
state start { | ||
user_meta.ipv4_hdr_truncated = 1w0; | ||
pkt.extract<ethernet_t>(hdr.ethernet); | ||
transition select(hdr.ethernet.etherType) { | ||
16w0x800: parse_ipv4; | ||
default: accept; | ||
} | ||
} | ||
state parse_ipv4 { | ||
tmp = pkt.lookahead<ipv4_t>(); | ||
ihl_0 = tmp.ihl; | ||
transition select(ihl_0) { | ||
4w0x0 &&& 4w0xc: parse_ipv4_ihl_too_small; | ||
4w0x4: parse_ipv4_ihl_too_small; | ||
default: parse_ipv4_ok; | ||
} | ||
} | ||
state parse_ipv4_ihl_too_small { | ||
user_meta.ipv4_hdr_truncated = 1w1; | ||
transition accept; | ||
} | ||
state parse_ipv4_ok { | ||
pkt.extract<ipv4_t>(hdr.ipv4); | ||
transition accept; | ||
} | ||
} | ||
|
||
control MainControlImpl(inout headers_t hdr, inout user_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { | ||
@name("MainControlImpl.tmp") bit<8> tmp_0; | ||
apply { | ||
if (hdr.ethernet.isValid()) { | ||
tmp_0 = 8w0; | ||
tmp_0[0:0] = user_meta.ipv4_hdr_truncated; | ||
tmp_0[1:1] = (bit<1>)hdr.ipv4.isValid(); | ||
hdr.ethernet.srcAddr[7:0] = tmp_0; | ||
} | ||
} | ||
} | ||
|
||
control MainDeparserImpl(packet_out pkt, in headers_t hdr, in user_metadata_t user_meta, in pna_main_output_metadata_t ostd) { | ||
apply { | ||
pkt.emit<ethernet_t>(hdr.ethernet); | ||
pkt.emit<ipv4_t>(hdr.ipv4); | ||
} | ||
} | ||
|
||
PNA_NIC<headers_t, user_metadata_t, headers_t, user_metadata_t>(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; |
Oops, something went wrong.