batctl: tcpdump: Add support to identify missing packets
cover batctl: tcpdump: Add support to identify missing packets
Hi,
when running batctl's tcpdump today on a normal batman-adv slave interface, you will see warnings like:
Warning - packet contains unknown batman packet type: 0x41 Warning - packet contains unknown batman packet type: 0x02
This is caused by missing dumping routinges in the tcpdump implementation. Since these packets (coded, fragmented) cannot be decoded/reassembled easily these packets are only identified and some basic header informations are shown.
Also not all TVLVs in the header were shown. The mcast part was dropped and thus the debugging of the new mcast feature flags was not possible with batctl.
Kind regards,
Sven
Sven Eckelmann (3):
batctl: tcpdump: Add support for MCAST TVLV
batctl: tcpdump: Add support for unicast fragmentation
batctl: tcpdump: Add support for coded packets
tcpdump.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++- tcpdump.h | 1 + 2 files changed, 110 insertions(+), 1 deletion(-)
Signature · 1 line
2.20.1
PATCH 1/3 batctl: tcpdump: Add support for MCAST TVLV
The multicast support in batman-adv was introduced in commit 77ec494490d6 ("batman-adv: Announce new capability via multicast TVLV") but the tcpdump parser was not updated to parse this TVLV container.
The parser requires support of parsing the current TVLV container (v2) and the pre-bridging implementation (v1) to correctly show all TVLVs of OGMs (and related packets).
---
Cc: Linus Lüssing <[email protected]>
tcpdump.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
tcpdump.c +49 -0
@@ -196,6 +196,45 @@ static void batctl_tvlv_parse_roam_v1(void *buff, ssize_t buff_len) BATADV_PRINT_VID(ntohs(tvlv->vid))); } +static void batctl_tvlv_parse_mcast_v1 (void *buff__maybe_unused , +ssize_t buff_len) +{ +struct batadv_tvlv_mcast_data *tvlv = buff; +uint8_t flags; + +if (buff_len !=sizeof (*tvlv)) { +fprintf (stderr,"Warning - dropping received %s packet as it is not the correct size (%zu): %zu\n" , +"TVLV MCASTv1" ,sizeof (*tvlv), buff_len); +return ; + } + + flags = tvlv->flags; + +printf ("\tTVLV MCASTv1: [%c%c%c]\n" , + flags &BATADV_MCAST_WANT_ALL_UNSNOOPABLES ?'U' :'.' , + flags &BATADV_MCAST_WANT_ALL_IPV4 ?'4' :'.' , + flags &BATADV_MCAST_WANT_ALL_IPV6 ?'6' :'.' ); +} + +static void batctl_tvlv_parse_mcast_v2 (void *buff,ssize_t buff_len) +{ +struct batadv_tvlv_mcast_data *tvlv = buff; +uint8_t flags; + +if (buff_len !=sizeof (*tvlv)) { +fprintf (stderr,"Warning - dropping received %s packet as it is not the correct size (%zu): %zu\n" , +"TVLV MCASTv2" ,sizeof (*tvlv), buff_len); +return ; + } + + flags = tvlv->flags; + +printf ("\tTVLV MCASTv2: [%c%c%c]\n" , + flags &BATADV_MCAST_WANT_ALL_UNSNOOPABLES ?'U' :'.' , + flags &BATADV_MCAST_WANT_ALL_IPV4 ?'4' :'.' , + flags &BATADV_MCAST_WANT_ALL_IPV6 ?'6' :'.' ); +} +typedef void (*batctl_tvlv_parser_t )(void *buff,ssize_t buff_len);static batctl_tvlv_parser_t tvlv_parser_get (uint8_t type,uint8_t version)
@@ -241,6 +280,16 @@ static batctl_tvlv_parser_t tvlv_parser_get(uint8_t type, uint8_t version)return NULL ; } +case BATADV_TVLV_MCAST : +switch (version) { +case 1 : +return batctl_tvlv_parse_mcast_v1; +case 2 : +return batctl_tvlv_parse_mcast_v2; +default : +return NULL ; + } +default :return NULL ; }
Signature · 1 line
2.20.1
PATCH 2/3 batctl: tcpdump: Add support for unicast fragmentation
In reply to Sven EckelmannThe support for unicast fragmentation was implemented in commit 9b3eab61754d ("batman-adv: Receive fragmented packets and merge"). The support to identify such packets by batctl's tcpdump was never implemented.
This minimal implementation allows to identify these packets but is not able to reassemble the packets. Wireshark should be used when this advanced feature is required.
---
Cc: Martin Hundebøll <[email protected]>
tcpdump.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
tcpdump.c +28 -0
@@ -930,6 +930,30 @@ static void dump_batman_ucast(unsigned char *packet_buff, ssize_t buff_len, int read_opt, time_printed); } +static void dump_batman_ucast_frag (unsigned char *packet_buff,ssize_t buff_len,int read_opt,int time_printed) +{ +struct batadv_frag_packet *frag_packet; +struct ether_header *ether_header; + +LEN_CHECK ((size_t )buff_len -sizeof (*ether_header), +sizeof (*frag_packet),"BAT UCAST FRAG" ); + + ether_header = (struct ether_header *)packet_buff; + frag_packet = (struct batadv_frag_packet *)(packet_buff +sizeof (*ether_header)); + +if (!time_printed) + time_printed =print_time (); + +printf ("BAT %s > " , +get_name_by_macaddr ((struct ether_addr *)ether_header->ether_shost, + read_opt)); + +printf ("%s: UCAST FRAG, seqno %d, no %d, ttl %hhu\n" , +get_name_by_macaddr ((struct ether_addr *)frag_packet->dest, + read_opt), + frag_packet->seqno, frag_packet->no, frag_packet->ttl); +} +static void dump_batman_bcast (unsigned char *packet_buff,ssize_t buff_len,int read_opt,int time_printed) {struct ether_header *ether_header;
@@ -1041,6 +1065,10 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int readif (dump_level &DUMP_TYPE_BATUCAST )dump_batman_ucast (packet_buff, buff_len, read_opt, time_printed);break ; +case BATADV_UNICAST_FRAG : +if (dump_level &DUMP_TYPE_BATFRAG ) +dump_batman_ucast_frag (packet_buff, buff_len, read_opt, time_printed); +break ;case BATADV_BCAST :if (dump_level &DUMP_TYPE_BATBCAST )dump_batman_bcast (packet_buff, buff_len, read_opt, time_printed);
Signature · 1 line
2.20.1
PATCH 3/3 batctl: tcpdump: Add support for coded packets
In reply to Sven EckelmannThe network coding support in batman-adv was introduced with commit c3289f3650d3 ("batman-adv: network coding - code and transmit packets if possible"). The support to identify such packets by batctl's tcpdump was never implemented.
This minimal implementation allows to identify these packets but is not able to decode the packets.
---
Cc: Martin Hundebøll <[email protected]>
tcpdump.c | 33 ++++++++++++++++++++++++++++++++- tcpdump.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-)
tcpdump.c +32 -1
@@ -56,7 +56,7 @@ static unsigned short dump_level_all = DUMP_TYPE_BATOGM | DUMP_TYPE_BATOGM2 |DUMP_TYPE_BATELP |DUMP_TYPE_BATICMP |DUMP_TYPE_BATUCAST |DUMP_TYPE_BATBCAST |DUMP_TYPE_BATUTVLV |DUMP_TYPE_BATFRAG | -DUMP_TYPE_NONBAT ; +DUMP_TYPE_NONBAT |DUMP_TYPE_BATCODED ;static unsigned short dump_level;static void parse_eth_hdr (unsigned char *packet_buff,ssize_t buff_len,int read_opt,int time_printed);
@@ -80,6 +80,7 @@ static void tcpdump_usage(void)fprintf (stderr," \t\t%3d - batman fragmented packets\n" ,DUMP_TYPE_BATFRAG );fprintf (stderr," \t\t%3d - batman unicast tvlv packets\n" ,DUMP_TYPE_BATUTVLV );fprintf (stderr," \t\t%3d - non batman packets\n" ,DUMP_TYPE_NONBAT ); +fprintf (stderr," \t\t%3d - batman coded packets\n" ,DUMP_TYPE_BATCODED );fprintf (stderr," \t\t%3d - batman ogm & non batman packets\n" ,DUMP_TYPE_BATOGM |DUMP_TYPE_NONBAT ); }
@@ -981,6 +982,32 @@ static void dump_batman_bcast(unsigned char *packet_buff, ssize_t buff_len, int read_opt, time_printed); } +static void dump_batman_coded (unsigned char *packet_buff,ssize_t buff_len,int read_opt,int time_printed) +{ +struct batadv_coded_packet *coded_packet; +struct ether_header *ether_header; + +LEN_CHECK ((size_t )buff_len -sizeof (*ether_header),sizeof (*coded_packet),"BAT CODED" ); + + ether_header = (struct ether_header *)packet_buff; + coded_packet = (struct batadv_coded_packet *)(packet_buff +sizeof (*ether_header)); + +if (!time_printed) + time_printed =print_time (); + +printf ("BAT %s > " , +get_name_by_macaddr ((struct ether_addr *)ether_header->ether_shost, + read_opt)); + +printf ("%s|%s: CODED, ttvn %d|%d, ttl %hhu\n" , +get_name_by_macaddr ((struct ether_addr *)coded_packet->first_orig_dest, + read_opt), +get_name_by_macaddr ((struct ether_addr *)coded_packet->second_dest, + read_opt), + coded_packet->first_ttvn, coded_packet->second_ttvn, + coded_packet->ttl); +} +static void dump_batman_4addr (unsigned char *packet_buff,ssize_t buff_len,int read_opt,int time_printed) {struct ether_header *ether_header;
@@ -1073,6 +1100,10 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int readif (dump_level &DUMP_TYPE_BATBCAST )dump_batman_bcast (packet_buff, buff_len, read_opt, time_printed);break ; +case BATADV_CODED : +if (dump_level &DUMP_TYPE_BATCODED ) +dump_batman_coded (packet_buff, buff_len, read_opt, time_printed); +break ;case BATADV_UNICAST_4ADDR :if (dump_level &DUMP_TYPE_BATUCAST )dump_batman_4addr (packet_buff, buff_len, read_opt, time_printed);
tcpdump.h +1 -0
@@ -33,6 +33,7 @@#define DUMP_TYPE_BATUTVLV 64#define DUMP_TYPE_BATFRAG 128#define DUMP_TYPE_NONBAT 256 +#define DUMP_TYPE_BATCODED 512#define IEEE80211_FCTL_FTYPE 0x0c00#define IEEE80211_FCTL_TODS 0x0001
Signature · 1 line
2.20.1