diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2016-04-22 16:55:31 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-04-25 17:56:34 +0200 |
commit | c09e06a6efaa94768660636a9c58ce9666e29d05 (patch) | |
tree | a41455899d30c7a8de30fdc9eb917702d9769975 /trafgen_proto.c | |
parent | 0cf15c320f9211d59b055157c895537e4b682a07 (diff) |
trafgen: proto: Add IPv6 header generation
Support for generating simple IPv6 headers using the 'ip6()/ipv6()'
trafgen generation function.
Fields supported:
ver|version Version (default: 6)
tc|tclass Traffic class (default: 0)
fl|flow Flow Label (default: 0)
len|length Payload length (calculated by default)
nh|nexthdr Type of next header (default: 0)
hl|hoplimit|ttl Hop Limit, TTL (default: 0)
sa|saddr Source IPv6 address (default: device address)
da|daddr Destination IPv6 address (default: 0:0:0:0:0:0:0:0)
Examples:
{ eth(), ipv6(daddr=1:2:3:4:5:6:7:8) }
{ ipv6(tc=2, hl=3, daddr=::1) }
{ eth(), ipv6(nh=58, sa=2001:db8::, da=::1), 128, 0, 0x52, 0x03, 0, 0, 0, 0 }
If not explicitely specified, the lower header is initialized as Ethernet.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_proto.c')
-rw-r--r-- | trafgen_proto.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c index e3704d8..1babba5 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -348,7 +348,6 @@ static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid, { struct sockaddr_storage ss = { }; struct sockaddr_in *ss4; - uint32_t ip_addr; int ret; if (proto_field_is_set(hdr, fid)) @@ -359,9 +358,7 @@ static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid, panic("Could not get device IPv4 address\n"); ss4 = (struct sockaddr_in *) &ss; - ip_addr = ss4->sin_addr.s_addr; - - __proto_field_set_bytes(hdr, fid, (uint8_t *)&ip_addr, is_default, false); + __proto_field_set_bytes(hdr, fid, (uint8_t *)&ss4->sin_addr.s_addr, is_default, false); } void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid) @@ -374,6 +371,34 @@ void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid) __proto_field_set_dev_ipv4(hdr, fid, true); } +static void __proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid, + bool is_default) +{ + struct sockaddr_storage ss = { }; + struct sockaddr_in6 *ss6; + int ret; + + if (proto_field_is_set(hdr, fid)) + return; + + ret = device_address(hdr->ctx->dev, AF_INET6, &ss); + if (ret < 0) + panic("Could not get device IPv6 address\n"); + + ss6 = (struct sockaddr_in6 *) &ss; + __proto_field_set_bytes(hdr, fid, (uint8_t *)&ss6->sin6_addr.s6_addr, is_default, false); +} + +void proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid) +{ + __proto_field_set_dev_ipv6(hdr, fid, false); +} + +void proto_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid) +{ + __proto_field_set_dev_ipv6(hdr, fid, true); +} + void protos_init(const char *dev) { struct proto_hdr *p; |