summaryrefslogtreecommitdiff
path: root/trafgen_l3.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-02-01 19:01:38 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-02-02 16:54:47 +0100
commit287e1d8899e2649395022b57230c1a93c125cc2c (patch)
tree11e5082db9fca5168089e4f958e8546c9a624f61 /trafgen_l3.c
parenta7f35557331a283f4064c578f76be6330d54eaf4 (diff)
trafgen: ipv4: Add setting next protocol id
Move setting lower protocol id field value from UDP & TCP protocols to IPv4 only, so lower layer will know exactly value to set in protocol id field. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_l3.c')
-rw-r--r--trafgen_l3.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/trafgen_l3.c b/trafgen_l3.c
index 58eaa01..0e923e0 100644
--- a/trafgen_l3.c
+++ b/trafgen_l3.c
@@ -5,6 +5,7 @@
#include <linux/if_ether.h>
+#include "die.h"
#include "csum.h"
#include "built_in.h"
#include "trafgen_l2.h"
@@ -33,12 +34,7 @@ static struct proto_field ipv4_fields[] = {
static void ipv4_header_init(struct proto_hdr *hdr)
{
- struct proto_hdr *lower;
-
- lower = proto_lower_default_add(hdr, PROTO_ETH);
-
- if (lower->id == PROTO_IP4)
- proto_field_set_default_u8(lower, IP4_PROTO, IPPROTO_IPIP);
+ proto_lower_default_add(hdr, PROTO_ETH);
proto_header_fields_add(hdr, ipv4_fields, array_size(ipv4_fields));
@@ -65,11 +61,33 @@ static void ipv4_packet_finish(struct proto_hdr *hdr)
}
}
+static void ipv4_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
+{
+ uint8_t ip_proto;
+
+ switch(pid) {
+ case PROTO_IP4:
+ ip_proto = IPPROTO_IPIP;
+ break;
+ case PROTO_UDP:
+ ip_proto = IPPROTO_UDP;
+ break;
+ case PROTO_TCP:
+ ip_proto = IPPROTO_TCP;
+ break;
+ default:
+ panic("ipv4: Not supported protocol id %u\n", pid);
+ }
+
+ proto_field_set_default_u8(hdr, IP4_PROTO, ip_proto);
+}
+
static struct proto_hdr ipv4_hdr = {
.id = PROTO_IP4,
.layer = PROTO_L3,
.header_init = ipv4_header_init,
.packet_finish = ipv4_packet_finish,
+ .set_next_proto = ipv4_set_next_proto,
};
void protos_l3_init(void)