diff options
author | Tommy Beadle <tbeadle@gmail.com> | 2016-02-29 09:29:48 -0500 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-03-29 10:08:38 +0200 |
commit | 196fc0351c1e5b39697091c845c73d04510e070e (patch) | |
tree | d4fe5100574e7ac58733b103fcdcf579bd926f40 /staging/modifications.c | |
parent | 070337f8cb27c1c4d77217879a3e1a1f193cef8f (diff) |
mausezahn: Allow IPv6 ranges to be specified for source and dest addresses
This allows a user to pass a range of IPv6 addresses, either like:
fec0:5000::1-fec0:5000::100
or in CIDR notation:
fec0:5000::0/112
These can be used for the -A and/or -B command-line options.
The largest range that can be used is a /64. In other words, if using CIDR
notation, the masklen must be <= 128 and >= 64.
Signed-off-by: Tommy Beadle <tbeadle@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'staging/modifications.c')
-rw-r--r-- | staging/modifications.c | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/staging/modifications.c b/staging/modifications.c index e11ba0e..1affbbb 100644 --- a/staging/modifications.c +++ b/staging/modifications.c @@ -27,6 +27,8 @@ // int update_Eth_SA (libnet_t *l, libnet_ptag_t t) // int update_IP_SA (libnet_t *l, libnet_ptag_t t) // int update_IP_DA (libnet_t *l, libnet_ptag_t t) +// int update_IP6_SA (libnet_t *l, libnet_ptag_t t) +// int update_IP6_DA (libnet_t *l, libnet_ptag_t t) // int update_DPORT (libnet_t *l, libnet_ptag_t t) // int update_SPORT (libnet_t *l, libnet_ptag_t t) // int update_TCP_SQNR (libnet_t *l, libnet_ptag_t t) @@ -135,6 +137,10 @@ int update_IP_SA (libnet_t *l, libnet_ptag_t t) u_int8_t *x, *y; int i=0; + if (ipv6_mode) { + return update_IP6_SA(l, t); + } + if (tx.ip_src_rand) { tx.ip_src_h = (u_int32_t) ( ((float) rand()/RAND_MAX)*0xE0000000); //this is 224.0.0.0 @@ -190,6 +196,41 @@ int update_IP_SA (libnet_t *l, libnet_ptag_t t) } +int +update_IP6_SA(libnet_t *l, libnet_ptag_t t) +{ + int i = 0; + if (tx.ip_src_rand) { + fprintf(stderr, "Random source addresses are not supported in IPv6 mode.\n"); + exit(1); + } else if (tx.ip_src_isrange) { + if (incr_in6_addr(tx.ip6_src, &tx.ip6_src) + || (in6_addr_cmp(tx.ip6_src, tx.ip6_src_stop) > 0)) + { + tx.ip6_src = tx.ip6_src_start; + i = 1; + } + } + + t = libnet_build_ipv6(tx.ip_tos, + tx.ip_flow, + tx.ip_len, + tx.ip_proto, + tx.ip_ttl, + tx.ip6_src, + tx.ip6_dst, + (mode==IP) ? (tx.ip_payload_s) ? tx.ip_payload : NULL : NULL, + (mode==IP) ? tx.ip_payload_s : 0, + l, + t); + + if (t == -1) { + fprintf(stderr," mz/update_IP6_SA: IP address manipulation failed!\n"); + exit (1); + } + + return i; +} ///////////////////////////////////////////////////////////////////////////////////////// @@ -208,6 +249,9 @@ int update_IP_DA(libnet_t *l, libnet_ptag_t t) u_int8_t *x, *y; int i=0; + if (ipv6_mode) { + return update_IP6_DA(l, t); + } if (tx.ip_dst_isrange) { @@ -262,6 +306,39 @@ int update_IP_DA(libnet_t *l, libnet_ptag_t t) } +int +update_IP6_DA(libnet_t *l, libnet_ptag_t t) +{ + int i = 0; + if (tx.ip_dst_isrange) { + if (incr_in6_addr(tx.ip6_dst, &tx.ip6_dst) + || (in6_addr_cmp(tx.ip6_dst, tx.ip6_dst_stop) > 0)) + { + tx.ip6_dst = tx.ip6_dst_start; + i = 1; + } + } + + t = libnet_build_ipv6(tx.ip_tos, + tx.ip_flow, + tx.ip_len, + tx.ip_proto, + tx.ip_ttl, + tx.ip6_src, + tx.ip6_dst, + (mode==IP) ? (tx.ip_payload_s) ? tx.ip_payload : NULL : NULL, + (mode==IP) ? tx.ip_payload_s : 0, + l, + t); + + if (t == -1) { + fprintf(stderr," mz/update_IP6_DA: IP address manipulation failed!\n"); + exit (1); + } + + return i; +} + /////////////////////////////////////////////////////////////////////////////////////// @@ -399,7 +476,7 @@ int update_SPORT(libnet_t *l, libnet_ptag_t t) if (t == -1) { - fprintf(stderr, " mz/update_DPORT: Can't build TCP header: %s\n", libnet_geterror(l)); + fprintf(stderr, " mz/update_SPORT: Can't build TCP header: %s\n", libnet_geterror(l)); exit (0); } } @@ -448,6 +525,7 @@ int update_USUM(libnet_t *l, libnet_ptag_t t) tx.udp_payload_s, l, t); + tx.udp_sum = 0; return t; } @@ -504,6 +582,7 @@ int update_TSUM(libnet_t *l, libnet_ptag_t t) tx.tcp_payload_s, l, t); + tx.tcp_sum = 0; return t; } @@ -544,6 +623,7 @@ int update_ISUM(libnet_t *l, libnet_ptag_t t) tx.icmp_payload_s, l, t); + tx.icmp_chksum = 0; return t; } |