Introduce the icmp6 table

This commit is contained in:
Nico Schottelius 2019-03-23 15:03:42 +01:00
commit 5f14967a32
4 changed files with 94 additions and 80 deletions

View file

@ -10,5 +10,6 @@
#define ROUTING_TABLE_SIZE 64 /* maximum routes per protocol */
#define ADDRESS_TABLE_SIZE 64 /* maximum number of addresses per protocol */
#define NDP_TABLE_SIZE 64 /* maximum number of multicast groups */
#define ICMP6_TABLE_SIZE 64 /* maximum number of multicast groups */
#endif

View file

@ -42,60 +42,6 @@ control MyIngress(inout headers hdr,
standard_metadata.mcast_grp = mcast_grp;
}
action icmp6_neighbor_solicitation(ipv6_addr_t addr, mac_addr_t mac_addr) {
/* egress = ingress */
standard_metadata.egress_spec = standard_metadata.ingress_port;
/* 1. IPv6 changes */
hdr.ipv6.dst_addr = hdr.ipv6.src_addr;
hdr.ipv6.src_addr = addr;
/* 2. ICMP6 changes */
hdr.icmp6.type = ICMP6_NA;
hdr.icmp6.code = 0;
// checksum is calculated in deparser
/* 3. icmp6/neighbor advertisement: values taken from real world answers */
hdr.icmp6_na_ns.router = 0;
hdr.icmp6_na_ns.solicitated = 1;
hdr.icmp6_na_ns.override = 1;
hdr.icmp6_na_ns.reserved = 0;
hdr.icmp6_na_ns.target_addr = addr;
/* 4. Link layer options */
hdr.icmp6_option_link_layer_addr.type = ICMP6_NDP_OPT_TARGET_LL;
hdr.icmp6_option_link_layer_addr.ll_length = 1; /* 1* 64 bit */
hdr.icmp6_option_link_layer_addr.mac_addr = mac_addr;
/* version1: rebuilding packet */
/*
truncate((bit<32>)(112 + 320 + 32)/8);
hdr.icmp6_na.setValid();
hdr.icmp6_na.solicitated = 1;
hdr.icmp6_na.override = 1;
*/
/* checksum trigger / content */
meta.task = TASK_CHECKSUM_ICMP6_NA;
meta.cast_length = (bit<32>) hdr.ipv6.payload_length;
}
action icmp6_echo_reply() {
mac_addr_t mac_tmp = hdr.ethernet.dst_addr;
hdr.ethernet.dst_addr = hdr.ethernet.src_addr;
hdr.ethernet.src_addr = mac_tmp;
ipv6_addr_t addr_tmp = hdr.ipv6.dst_addr;
hdr.ipv6.dst_addr = hdr.ipv6.src_addr;
hdr.ipv6.src_addr = addr_tmp;
hdr.icmp6.type = ICMP6_ECHO_REPLY;
meta.task = TASK_CHECKSUM_ICMP6;
meta.cast_length = (bit<32>) hdr.ipv6.payload_length;
}
/********************** NAT64 / NAT46 ACTIONS ***********************************/
@ -167,18 +113,88 @@ control MyIngress(inout headers hdr,
}
/********************** Reply to NDP for US ***********************************/
table ndp_answer {
/********************** ICMP6 ***********************************/
/* old/unused action */
action icmp6_answer() {
if(hdr.icmp6.isValid()) {
if(hdr.icmp6.code == ICMP6_ECHO_REQUEST) {
ipv6_addr_t tmp = hdr.ipv6.src_addr;
hdr.ipv6.src_addr = hdr.ipv6.dst_addr;
hdr.ipv6.dst_addr = tmp;
hdr.icmp6.code = ICMP6_ECHO_REPLY;
}
}
}
action icmp6_neighbor_solicitation(ipv6_addr_t addr, mac_addr_t mac_addr) {
/* egress = ingress */
standard_metadata.egress_spec = standard_metadata.ingress_port;
/* 1. IPv6 changes */
hdr.ipv6.dst_addr = hdr.ipv6.src_addr;
hdr.ipv6.src_addr = addr;
/* 2. ICMP6 changes */
hdr.icmp6.type = ICMP6_NA;
hdr.icmp6.code = 0;
// checksum is calculated in deparser
/* 3. icmp6/neighbor advertisement: values taken from real world answers */
hdr.icmp6_na_ns.router = 0;
hdr.icmp6_na_ns.solicitated = 1;
hdr.icmp6_na_ns.override = 1;
hdr.icmp6_na_ns.reserved = 0;
hdr.icmp6_na_ns.target_addr = addr;
/* 4. Link layer options */
hdr.icmp6_option_link_layer_addr.type = ICMP6_NDP_OPT_TARGET_LL;
hdr.icmp6_option_link_layer_addr.ll_length = 1; /* 1* 64 bit */
hdr.icmp6_option_link_layer_addr.mac_addr = mac_addr;
/* version1: rebuilding packet */
/*
truncate((bit<32>)(112 + 320 + 32)/8);
hdr.icmp6_na.setValid();
hdr.icmp6_na.solicitated = 1;
hdr.icmp6_na.override = 1;
*/
/* checksum trigger / content */
meta.task = TASK_CHECKSUM_ICMP6_NA;
meta.cast_length = (bit<32>) hdr.ipv6.payload_length;
}
action icmp6_echo_reply() {
mac_addr_t mac_tmp = hdr.ethernet.dst_addr;
hdr.ethernet.dst_addr = hdr.ethernet.src_addr;
hdr.ethernet.src_addr = mac_tmp;
ipv6_addr_t addr_tmp = hdr.ipv6.dst_addr;
hdr.ipv6.dst_addr = hdr.ipv6.src_addr;
hdr.ipv6.src_addr = addr_tmp;
hdr.icmp6.type = ICMP6_ECHO_REPLY;
meta.task = TASK_CHECKSUM_ICMP6;
meta.cast_length = (bit<32>) hdr.ipv6.payload_length;
}
table icmp6 {
key = {
hdr.ipv6.dst_addr: exact; /* our multicast embedded mac address */
hdr.ipv6.dst_addr: lpm;
hdr.icmp6.type: exact;
}
actions = {
controller_debug;
icmp6_neighbor_solicitation;
icmp6_echo_reply;
NoAction;
}
size = NDP_TABLE_SIZE;
size = ICMP6_TABLE_SIZE;
default_action = NoAction;
}
@ -213,7 +229,7 @@ control MyIngress(inout headers hdr,
// default_action = controller_debug;
}
/********************** NDP support ***********************************/
/********************** NDP support for OTHERS (unused ATM) ***********************************/
table ndp {
key = {
@ -230,23 +246,6 @@ control MyIngress(inout headers hdr,
}
/********************** ADDRESS TABLES ***********************************/
action icmp6_answer() {
if(hdr.icmp6.isValid()) {
if(hdr.icmp6.code == ICMP6_ECHO_REQUEST) {
ipv6_addr_t tmp = hdr.ipv6.src_addr;
hdr.ipv6.src_addr = hdr.ipv6.dst_addr;
hdr.ipv6.dst_addr = tmp;
hdr.icmp6.code = ICMP6_ECHO_REPLY;
}
}
/* do something:
- change src/dst
- change type
*/
}
/********************** ROUTING (egress definiton) TABLES ***********************************/
@ -302,7 +301,9 @@ control MyIngress(inout headers hdr,
// ndp_answer.apply();
//ndp.apply(); /* flood or if it is us - answer */
v6_addresses.apply();
icmp6.apply();
v6_networks.apply();
}
if(hdr.ipv4.isValid()) {