Ejemplo n.º 1
0
void
test_parse_ether_succeeds() {
  buffer *buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) );

  assert_int_equal( parse_ether( buffer ), true );

  free_buffer( buffer );
}
Ejemplo n.º 2
0
void
test_parse_ether_fails_if_type_is_trancated_vlan() {
  buffer *buffer = setup_dummy_ether_packet(sizeof( ether_header_t ) );
  packet_info( buffer )->l2_data.eth->type = htons( ETH_ETHTYPE_TPID );

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Ejemplo n.º 3
0
void
test_parse_ether_fails_if_mac_address_is_wrong_mac() {
  buffer *buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) );
  packet_info( buffer )->l2_data.eth->macsa[ 0 ] = 0xff;

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Ejemplo n.º 4
0
void
test_parse_ether_fails_if_packet_size_is_short_ethernet_size() {
  buffer *buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) );
  buffer->length = sizeof( ether_header_t ) - ETH_ADDRLEN;

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Ejemplo n.º 5
0
static buffer *
setup_dummy_snap_packet() {
  buffer *snap_buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) + sizeof( snap_header_t ) );

  packet_info( snap_buffer )->l2_data.eth->type = htons( sizeof( ether_header_t ) + sizeof( snap_header_t ) - ETH_PREPADLEN );
  packet_info( snap_buffer )->vtag = ( void * ) ( packet_info( snap_buffer )->l2_data.eth + 1 );
  memcpy( ( char * ) packet_info( snap_buffer )->vtag, sntp_data, sizeof( snap_header_t ) );

  return snap_buffer;
}
Ejemplo n.º 6
0
static buffer *
setup_dummy_vlan_packet() {
  buffer *vlan_buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) + sizeof( vlantag_header_t ) );

  packet_info( vlan_buffer )->l2_data.eth->type = htons( sizeof( ether_header_t ) + sizeof( vlantag_header_t ) - ETH_PREPADLEN );
  packet_info( vlan_buffer )->l2_data.eth->type = htons( ETH_ETHTYPE_TPID );
  packet_info( vlan_buffer )->vtag = ( void * ) ( packet_info( vlan_buffer )->l2_data.eth + 1 );
  packet_info( vlan_buffer )->vtag->type = htons( ETH_ETHTYPE_IPV4 );

  return vlan_buffer;
}
Ejemplo n.º 7
0
static buffer *
setup_dummy_ether_arp_packet() {
  buffer *arp_buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) + sizeof( arp_header_t ) + arp_padding_size, ETH_ETHTYPE_ARP );

  arp_header_t *arp = packet_info( arp_buffer )->l3_data.arp;
  arp->ar_hrd = htons( ARPHRD_ETHER );
  arp->ar_pro = htons( ETH_ETHTYPE_IPV4 );
  arp->ar_hln = ETH_ADDRLEN;
  arp->ar_pln = IPV4_ADDRLEN;
  arp->ar_op = htons( ARPOP_REPLY );

  free( arp_buffer->user_data );
  arp_buffer->user_data = NULL;

  remove_front_buffer( arp_buffer, ETH_PREPADLEN );

  return arp_buffer;
}
Ejemplo n.º 8
0
static buffer *
setup_dummy_ether_ipv4_packet() {
  buffer *ipv4_buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) + sizeof( ipv4_header_t ) + ipv4_padding_size, ETH_ETHTYPE_IPV4 );

  ipv4_header_t *ipv4 = packet_info( ipv4_buffer )->l3_data.ipv4;
  ipv4->version = IPVERSION;
  ipv4->ihl = sizeof( ipv4_header_t ) / 4;
  ipv4->tot_len = htons( sizeof( ipv4_header_t ) );
  ipv4->ttl = 0;
  ipv4->check = 0;
  ipv4->protocol = IPPROTO_UDP;
  ipv4->saddr = htonl( 0xC0A80067 );
  ipv4->daddr = htonl( 0xC0A80036 );
  ipv4->frag_off = htons( 0 );
  ipv4->check = get_checksum( ( uint16_t * ) packet_info( ipv4_buffer )->l3_data.ipv4, sizeof( ipv4_header_t ) );

  free( ipv4_buffer->user_data );
  ipv4_buffer->user_data = NULL;

  remove_front_buffer( ipv4_buffer, ETH_PREPADLEN );

  return ipv4_buffer;
}