From c4e07d5142c8991d532804ff60b5cf16029c0497 Mon Sep 17 00:00:00 2001 From: Ken Wu Date: Mon, 5 Dec 2016 00:39:36 +0800 Subject: 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 Reviewed-by: Vadim Kochan Signed-off-by: Tobias Klauser --- trafgen_proto.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'trafgen_proto.c') diff --git a/trafgen_proto.c b/trafgen_proto.c index 316fa97..62ac831 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -364,8 +364,10 @@ static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid, return; ret = device_address(ctx.dev, AF_INET, &ss); - if (ret < 0) - panic("Could not get device IPv4 address\n"); + if (ret < 0) { + fprintf(stderr, "Warning: Could not get device IPv4 address for %s\n", ctx.dev); + return; + } ss4 = (struct sockaddr_in *) &ss; __proto_field_set_bytes(hdr, fid, (uint8_t *)&ss4->sin_addr.s_addr, is_default, false); @@ -392,8 +394,10 @@ static void __proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid, return; ret = device_address(ctx.dev, AF_INET6, &ss); - if (ret < 0) - panic("Could not get device IPv6 address\n"); + if (ret < 0) { + fprintf(stderr, "Warning: Could not get device IPv6 address for %s\n", ctx.dev); + return; + } ss6 = (struct sockaddr_in6 *) &ss; __proto_field_set_bytes(hdr, fid, (uint8_t *)&ss6->sin6_addr.s6_addr, is_default, false); -- cgit v1.2.3-54-g00ecf