Refactor #n: go back to generic entry point, use if in apply{}
This commit is contained in:
parent
8095189acc
commit
f32ad44e0b
6 changed files with 210 additions and 79 deletions
|
|
@ -48,7 +48,6 @@ control MyIngress(inout headers hdr,
|
|||
|
||||
/********************** NAT64 / NAT46 ACTIONS ***********************************/
|
||||
|
||||
|
||||
/* changes for icmp6 -> icmp */
|
||||
action nat64_icmp6_generic()
|
||||
{
|
||||
|
|
@ -58,6 +57,8 @@ control MyIngress(inout headers hdr,
|
|||
/* trigger checksumming */
|
||||
meta.switch_task = TASK_CHECKSUM_ICMP;
|
||||
|
||||
meta.chk_icmp = true;
|
||||
|
||||
hdr.icmp6.setInvalid();
|
||||
|
||||
/* not needed, as we don't translate them (yet/ever) */
|
||||
|
|
@ -74,8 +75,10 @@ control MyIngress(inout headers hdr,
|
|||
hdr.ipv4.diff_serv = (bit<6>)0; // no ToS
|
||||
hdr.ipv4.ecn = (bit<2>)0; // unsupported
|
||||
|
||||
hdr.ipv4.ihl = (bit<4>) 5; // internet header length -- needs to be dynamic!?
|
||||
hdr.ipv4.totalLen = (bit<16>) hdr.ipv6.payload_length + 5; // should probably also dynamic
|
||||
/* 5 is ok as long as we don't use options / padding /
|
||||
anything after the destination address */
|
||||
hdr.ipv4.ihl = (bit<4>) 5; // internet header length - static for us
|
||||
hdr.ipv4.totalLen = (bit<16>) hdr.ipv6.payload_length + 5; // ok under above constraints
|
||||
|
||||
hdr.ipv4.identification = (bit<16>) 0; // no support for fragments
|
||||
hdr.ipv4.flags = (bit<3>) 0; // DF bit and more fragments, unsupported ATM
|
||||
|
|
@ -91,10 +94,6 @@ control MyIngress(inout headers hdr,
|
|||
|
||||
hdr.ipv4.protocol = hdr.ipv6.next_header;
|
||||
|
||||
if(hdr.ipv6.next_header == PROTO_ICMP6) {
|
||||
// nat64_icmp6();
|
||||
}
|
||||
|
||||
hdr.ipv6.setInvalid();
|
||||
}
|
||||
|
||||
|
|
@ -108,12 +107,61 @@ control MyIngress(inout headers hdr,
|
|||
nat64_generic(src, dst);
|
||||
}
|
||||
|
||||
/* From https://tools.ietf.org/html/rfc792 (IPv4)
|
||||
|
||||
Echo or Echo Reply Message
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Type | Code | Checksum |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Identifier | Sequence Number |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Data ...
|
||||
+-+-+-+-+-
|
||||
|
||||
|
||||
From https://tools.ietf.org/html/rfc4443#section-4.1
|
||||
|
||||
4.1. Echo Request Message
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Type | Code | Checksum |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Identifier | Sequence Number |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Data ...
|
||||
+-+-+-+-+-
|
||||
|
||||
4.2. Echo Reply Message
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Type | Code | Checksum |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Identifier | Sequence Number |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Data ...
|
||||
+-+-+-+-+-
|
||||
|
||||
|
||||
Type / code are different in ICMP4 and ICMP6!
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* if replacing actions */
|
||||
action nat64_icmp6_echo_request(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) {
|
||||
nat64_static(v6_src, v4_dst, nat64_prefix);
|
||||
nat64_icmp6_generic();
|
||||
|
||||
hdr.icmp.type = ICMP_ECHO_REQUEST;
|
||||
|
||||
/* fix length, sequence number, etc */
|
||||
}
|
||||
|
||||
action nat64_icmp6_echo_reply(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) {
|
||||
|
|
@ -162,6 +210,22 @@ control MyIngress(inout headers hdr,
|
|||
nat46_generic(src, dst);
|
||||
}
|
||||
|
||||
table nat64 {
|
||||
key = {
|
||||
hdr.ipv6.dst_addr: lpm;
|
||||
}
|
||||
actions = { /* FIXME: actions need to be updated */
|
||||
controller_debug;
|
||||
nat64_generic;
|
||||
nat64_icmp6_echo_reply;
|
||||
nat64_icmp6_echo_request;
|
||||
controller_debug_table_id;
|
||||
NoAction;
|
||||
}
|
||||
size = NAT64_TABLE_SIZE;
|
||||
default_action = controller_debug_table_id(TABLE_NAT64);
|
||||
}
|
||||
|
||||
table nat64_icmp6 {
|
||||
key = {
|
||||
hdr.ipv6.dst_addr: lpm;
|
||||
|
|
@ -378,17 +442,28 @@ control MyIngress(inout headers hdr,
|
|||
if(hdr.ipv6.isValid()) {
|
||||
icmp6.apply(); /* icmp6 echo, icmp6 ndp */
|
||||
|
||||
if(nat64_icmp6.apply().hit) {
|
||||
if(nat64.apply().hit) { /* generic nat64 done */
|
||||
if(hdr.icmp6.isValid()) {
|
||||
nat64_icmp6_generic();
|
||||
|
||||
if(hdr.icmp6.type == ICMP6_ECHO_REPLY) {
|
||||
hdr.icmp.type = ICMP_ECHO_REPLY;
|
||||
}
|
||||
if(hdr.icmp6.type == ICMP6_ECHO_REQUEST) {
|
||||
hdr.icmp.type = ICMP_ECHO_REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
v4_networks.apply(); /* apply egress for IPv4 */
|
||||
exit; /* no further v6 processing */
|
||||
}
|
||||
|
||||
v6_networks.apply(); /* egress / routing */
|
||||
v6_networks.apply(); /* regular egress / routing */
|
||||
} else if(hdr.ipv4.isValid()) {
|
||||
if(nat46_icmp.apply().hit) { /* v4->v6 */
|
||||
v6_networks.apply(); /* Now apply v6 egress */
|
||||
exit; /* no further v4 processing */
|
||||
}
|
||||
// if(nat46_icmp.apply().hit) { /* v4->v6 */
|
||||
// v6_networks.apply(); /* Now apply v6 egress */
|
||||
// exit; /* no further v4 processing */
|
||||
// }
|
||||
v4_networks.apply(); /* routing, egress */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue