summaryrefslogtreecommitdiff
path: root/trafgen_l3.c
diff options
context:
space:
mode:
authorKen Wu <abawwu@gmail.com>2016-12-05 00:39:36 +0800
committerTobias Klauser <tklauser@distanz.ch>2016-12-05 08:43:37 +0100
commitc4e07d5142c8991d532804ff60b5cf16029c0497 (patch)
tree06f5acbe1802fca18153167bb964bf277b012638 /trafgen_l3.c
parent630c65e6794d548f757d904948ef2a6dfd466abe (diff)
trafgen: l3: Support interface without IP address
Move default source address setting to packet_finish so that we do not need to get the device's address if the source address is set in the packet. Without this, trafgen does not work with an interface without address configured. In addition, in the case failing to get the address for an interface, intead of panic, it now prints a warning and uses a value of 0.0.0.0. Signed-off-by: Ken Wu <abawwu@gmail.com> Reviewed-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.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/trafgen_l3.c b/trafgen_l3.c
index e6aa516..bce8ca9 100644
--- a/trafgen_l3.c
+++ b/trafgen_l3.c
@@ -40,7 +40,6 @@ static void ipv4_header_init(struct proto_hdr *hdr)
proto_field_set_default_u8(hdr, IP4_VER, 4);
proto_field_set_default_u8(hdr, IP4_IHL, 5);
- proto_field_set_default_dev_ipv4(hdr, IP4_SADDR);
}
static void ipv4_field_changed(struct proto_field *field)
@@ -81,6 +80,7 @@ static void ipv4_packet_finish(struct proto_hdr *hdr)
total_len = pkt->len - hdr->pkt_offset;
proto_field_set_default_be16(hdr, IP4_LEN, total_len);
+ proto_field_set_default_dev_ipv4(hdr, IP4_SADDR);
ipv4_csum_update(hdr);
}
@@ -140,7 +140,6 @@ static void ipv6_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, ipv6_fields, array_size(ipv6_fields));
proto_field_set_default_be32(hdr, IP6_VER, 6);
- proto_field_set_default_dev_ipv6(hdr, IP6_SADDR);
}
static void ipv6_field_changed(struct proto_field *field)
@@ -161,6 +160,7 @@ static void ipv6_packet_finish(struct proto_hdr *hdr)
uint16_t total_len = pkt->len - hdr->pkt_offset - IPV6_HDR_LEN;
proto_field_set_default_be16(hdr, IP6_LEN, total_len);
+ proto_field_set_default_dev_ipv6(hdr, IP6_SADDR);
}
static void ipv6_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)