Skip to content

Commit

Permalink
More variations on dstopt header sizes and counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
John E committed Mar 2, 2015
1 parent 6fd9b2e commit f80c149
Showing 1 changed file with 24 additions and 39 deletions.
63 changes: 24 additions & 39 deletions synfrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ enum TEST_TYPE {
TEST_IPV6_MANY_FRAG_NOMORE_TCP = 23,
TEST_IPV6_BIG_DSTOPT_TCP = 25,
TEST_IPV6_SMALL_DSTOPT_TCP = 27,
TEST_IPV6_MANY_DSTOPT_TCP = 29,
TEST_IPV6_FRAG_DSTOPT2_TCP = 31,
TEST_IPV6_MANY_SMALL_DSTOPT_TCP = 29,
TEST_IPV6_MANY_BIG_DSTOPT_TCP = 31,
TEST_IPV6_FRAG_DSTOPT2_TCP = 33,

TEST_IPV6_FRAG_ICMP6 = 12,
TEST_IPV6_DSTOPT_FRAG_ICMP6 = 14,
Expand Down Expand Up @@ -136,7 +137,8 @@ enum TEST_TYPE test_indexes[] = {
TEST_IPV6_FRAG_FRAG_TCP,
TEST_IPV6_FRAG_NOMORE_TCP,
TEST_IPV6_MANY_FRAG_NOMORE_TCP,
TEST_IPV6_MANY_DSTOPT_TCP,
TEST_IPV6_MANY_SMALL_DSTOPT_TCP,
TEST_IPV6_MANY_BIG_DSTOPT_TCP,
TEST_IPV6_BIG_DSTOPT_TCP,
TEST_IPV6_SMALL_DSTOPT_TCP,
TEST_IPV6_DSTOPT_FRAG_ICMP6,
Expand All @@ -160,7 +162,8 @@ const char *test_names[] = {
"v6-frag-frag-tcp",
"v6-frag-nomore-tcp",
"v6-many-frag-nomore-tcp",
"v6-many-dstopt-tcp",
"v6-many-small-dstopt-tcp",
"v6-many-big-dstopt-tcp",
"v6-big-dstopt-tcp",
"v6-small-dstopt-tcp",
"v6-dstopt-frag-icmp6",
Expand Down Expand Up @@ -1262,15 +1265,21 @@ void do_ipv6_many_frag_nomore_tcp( char *interface, char *srcip, char *dstip, ch
free( ethh );
}

void do_ipv6_many_dstopt_tcp( char *interface, char *srcip, char *dstip, char *srcmac, char *dstmac, unsigned short srcport, unsigned short dstport, uint32_t isn )
#define do_ipv6_big_dstopt_tcp( a, b, c, d, e, f, g, h ) do_ipv6_many_sized_dstopt_tcp( a, b, c, d, e, f, g, h, 1, 512 )
#define do_ipv6_small_dstopt_tcp( a, b, c, d, e, f, g, h ) do_ipv6_many_sized_dstopt_tcp( a, b, c, d, e, f, g, h, 1, 6 )
#define do_ipv6_many_big_dstopt_tcp( a, b, c, d, e, f, g, h ) do_ipv6_many_sized_dstopt_tcp( a, b, c, d, e, f, g, h, 14, 94 )
#define do_ipv6_many_small_dstopt_tcp( a, b, c, d, e, f, g, h ) do_ipv6_many_sized_dstopt_tcp( a, b, c, d, e, f, g, h, 14, 6 )

void do_ipv6_many_sized_dstopt_tcp( char *interface, char *srcip, char *dstip, char *srcmac, char *dstmac, unsigned short srcport, unsigned short dstport, uint32_t isn, size_t count, size_t dstopt_size )
{
struct ip6_hdr *ip6h;
struct tcphdr *tcph;
struct ether_header *ethh;
int packet_size;
void *next;
const int dstopt_headers = 14; // Must be >= 1. See above.
const int my_dstopt_size = SIZEOF_DESTOPT + 6;
const int optlen = fix_up_destination_options_length( dstopt_size );
const int my_dstopt_size = SIZEOF_DESTOPT + optlen;

packet_size = SIZEOF_ETHER + SIZEOF_IPV6 + ( my_dstopt_size * dstopt_headers ) + SIZEOF_TCP;

Expand All @@ -1281,43 +1290,16 @@ void do_ipv6_many_dstopt_tcp( char *interface, char *srcip, char *dstip, char *s
next = append_ethernet( ethh, srcmac, dstmac, ETHERTYPE_IPV6 );
next = append_ipv6( next, srcip, dstip, IPPROTO_DSTOPTS, ( my_dstopt_size * dstopt_headers ) + SIZEOF_TCP );
for ( int x = 0; x < dstopt_headers - 1; x++ ) {
next = append_dest( next, IPPROTO_DSTOPTS, 6 );
next = append_dest( next, IPPROTO_DSTOPTS, optlen );
}
next = append_dest( next, IPPROTO_TCP, 6 );
next = append_dest( next, IPPROTO_TCP, optlen );
append_tcp_syn( next, srcport, dstport, isn );
calc_checksum( ip6h, IPPROTO_TCP, SIZEOF_TCP );

synfrag_send( ethh, packet_size );
free( ethh );
}

#define do_ipv6_big_dstopt( a, b, c, d, e, f, g, h ) do_ipv6_sized_dstopt( a, b, c, d, e, f, g, h, 512 )
#define do_ipv6_small_dstopt( a, b, c, d, e, f, g, h ) do_ipv6_sized_dstopt( a, b, c, d, e, f, g, h, 6 )

void do_ipv6_sized_dstopt( char *interface, char *srcip, char *dstip, char *srcmac, char *dstmac, unsigned short srcport, unsigned short dstport, uint32_t isn, size_t dstopt_size )
{
struct ip6_hdr *ip6h;
struct tcphdr *tcph_optioned;
struct ether_header *ethh;
void *next;
int packet_size;
unsigned short optlen = fix_up_destination_options_length( dstopt_size );

packet_size = SIZEOF_ETHER + SIZEOF_IPV6 + SIZEOF_DESTOPT + optlen + SIZEOF_TCP;

ethh = (struct ether_header *) malloc_check( BIG_PACKET_SIZE );
ip6h = (struct ip6_hdr *) ( (char *) ethh + SIZEOF_ETHER );

next = append_ethernet( ethh, srcmac, dstmac, ETHERTYPE_IPV6 );
next = append_ipv6( next, srcip, dstip, IPPROTO_DSTOPTS, SIZEOF_DESTOPT + SIZEOF_TCP + optlen );
tcph_optioned = append_dest( next, IPPROTO_TCP, optlen );
append_tcp_syn( tcph_optioned, srcport, dstport, isn );
calc_checksum( ip6h, IPPROTO_TCP, SIZEOF_TCP );

synfrag_send( ethh, packet_size );
free( ethh );
}

/* Process functions. */
void fork_pcap_listener( char *dstip, char *srcip, unsigned short dstport, unsigned short srcport, enum TEST_TYPE test_type, long receive_timeout )
{
Expand Down Expand Up @@ -1682,14 +1664,17 @@ int main( int argc, char **argv )
case TEST_IPV6_MANY_FRAG_NOMORE_TCP:
do_ipv6_many_frag_nomore_tcp( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
break;
case TEST_IPV6_MANY_DSTOPT_TCP:
do_ipv6_many_dstopt_tcp( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
case TEST_IPV6_MANY_SMALL_DSTOPT_TCP:
do_ipv6_many_small_dstopt_tcp( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
break;
case TEST_IPV6_MANY_BIG_DSTOPT_TCP:
do_ipv6_many_big_dstopt_tcp( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
break;
case TEST_IPV6_SMALL_DSTOPT_TCP:
do_ipv6_small_dstopt( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
do_ipv6_small_dstopt_tcp( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
break;
case TEST_IPV6_BIG_DSTOPT_TCP:
do_ipv6_big_dstopt( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
do_ipv6_big_dstopt_tcp( interface, srcip, dstip, srcmac, dstmac, srcport, dstport, isn );
break;
case TEST_IPV6_DSTOPT_FRAG_ICMP6:
do_ipv6_dstopt_frag_icmp( interface, srcip, dstip, srcmac, dstmac );
Expand Down

0 comments on commit f80c149

Please sign in to comment.