diff --git a/docs/config.md b/docs/config.md index a7284884..16256a5b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -546,5 +546,7 @@ Attribute | Description | Default `vlan-priority` | VLAN priority | 0 `length` | Layer 3 (IP + payload) traffic length (76 - 1500) | 128 `pps` | Stream traffic rate in packets per second | 1 +`source-ipv4-address` | Overwrite source IPv4 address (downstream only) | +`source-ipv6-address` | Overwrite source IPv6 address (downstream only) | For L2TP downstream traffic the IPv4 TOS is applied to the outer IPv4 and inner IPv4 header. \ No newline at end of file diff --git a/src/bbl_config.c b/src/bbl_config.c index 09481f6f..900efdd6 100644 --- a/src/bbl_config.c +++ b/src/bbl_config.c @@ -319,6 +319,20 @@ json_parse_stream (json_t *stream, bbl_stream_config *stream_config) { } else { stream_config->pps = 1; } + + if (json_unpack(stream, "{s:s}", "source-ipv4-address", &s) == 0) { + if(!inet_pton(AF_INET, s, &stream_config->ipv4_source_address)) { + fprintf(stderr, "JSON config error: Invalid value for stream->source-ipv4-address\n"); + return false; + } + } + + if (json_unpack(stream, "{s:s}", "source-ipv6-address", &s) == 0) { + if(!inet_pton(AF_INET6, s, &stream_config->ipv6_source_address)) { + fprintf(stderr, "JSON config error: Invalid value for stream->source-ipv6-address\n"); + return false; + } + } return true; } diff --git a/src/bbl_stream.c b/src/bbl_stream.c index 6a9e1e6c..6aa3dc5d 100644 --- a/src/bbl_stream.c +++ b/src/bbl_stream.c @@ -285,7 +285,11 @@ bbl_stream_build_network_packet(bbl_stream *stream) { eth.type = ETH_TYPE_IPV4; eth.next = &ipv4; ipv4.dst = session->ip_address; - ipv4.src = ctx->op.network_if->ip; + if(stream->config->ipv4_source_address) { + ipv4.src = stream->config->ipv4_source_address; + } else { + ipv4.src = ctx->op.network_if->ip; + } ipv4.ttl = 64; ipv4.tos = config->priority; ipv4.protocol = PROTOCOL_IPV4_UDP; @@ -299,7 +303,11 @@ bbl_stream_build_network_packet(bbl_stream *stream) { eth.type = ETH_TYPE_IPV6; eth.next = &ipv6; ipv6.dst = session->ipv6_address; - ipv6.src = ctx->op.network_if->ip6.address; + if(*(uint64_t*)stream->config->ipv6_source_address) { + ipv6.src = stream->config->ipv6_source_address; + } else { + ipv6.src = ctx->op.network_if->ip6.address; + } ipv6.ttl = 64; ipv6.tos = config->priority; ipv6.protocol = IPV6_NEXT_HEADER_UDP; @@ -313,7 +321,11 @@ bbl_stream_build_network_packet(bbl_stream *stream) { eth.type = ETH_TYPE_IPV6; eth.next = &ipv6; ipv6.dst = session->delegated_ipv6_address; - ipv6.src = ctx->op.network_if->ip6.address; + if(*(uint64_t*)stream->config->ipv6_source_address) { + ipv6.src = stream->config->ipv6_source_address; + } else { + ipv6.src = ctx->op.network_if->ip6.address; + } ipv6.ttl = 64; ipv6.tos = config->priority; ipv6.protocol = IPV6_NEXT_HEADER_UDP;