batctl: tcpdump bugfixes
cover batctl: tcpdump bugfixes
I have now splitted the bugfixes for batctl in topic branches to make it a little bit easier to review. Similar to the "random bugfixes 2026-06-21" patchset, they are just various (mostly minor) problems which should be tackled at some point.
---
Sven Eckelmann (9):
batctl: tcpdump: fix "subtybe" typo in 4ADDR output
batctl: tcpdump: return EXIT_SUCCESS on normal termination
batctl: tcpdump: check frame length before reading the ethernet header
batctl: tcpdump: resolve bat-host name for ROAMv1 client
batctl: tcpdump: print the unreachable host for ICMP port unreachable
batctl: tcpdump: skip partial line for oversized ICMPv6 errors
batctl: tcpdump: don't label unknown ICMPv6 types as unreachable
batctl: tcpdump: reject invalid packet type arguments
batctl: tcpdump: fix source address selection for 802.11 data frames
tcpdump.c | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-)
---
base-commit: eb9597d4ca6db17c579f5ae9443c51b013e2fe65
change-id: 20260704-bugfixes-tcpdump-3fc6bf0295de
Best regards,
Signature · 1 line
Sven Eckelmann <[email protected]>
PATCH 1/9 batctl: tcpdump: fix "subtybe" typo in 4ADDR output
The unicast-4addr packet dump prints the field label as "subtybe" instead of "subtype".
--- tcpdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcpdump.c +1 -1
@@ -1184,7 +1184,7 @@ static void dump_batman_4addr(unsigned char *packet_buff, ssize_t buff_len,printf ("BAT %s > " ,get_name_by_macaddr ((struct ether_addr *)ether_header->ether_shost, read_opt)); -printf ("%s: 4ADDR, subtybe %hhu, ttvn %d, ttl %hhu, " , +printf ("%s: 4ADDR, subtype %hhu, ttvn %d, ttl %hhu, " ,get_name_by_macaddr ((struct ether_addr *)unicast_4addr_packet->u.dest, read_opt), unicast_4addr_packet->subtype, unicast_4addr_packet->u.ttvn, unicast_4addr_packet->u.ttl);
Signature · 1 line
2.47.3
PATCH 2/9 batctl: tcpdump: return EXIT_SUCCESS on normal termination
In reply to Sven EckelmannThe main capture loop of tcpdump ends when SIGINT/SIGTERM sets is_aborted. In this case, the return value should reflect this clean shutdown.
--- tcpdump.c | 2 ++ 1 file changed, 2 insertions(+)
tcpdump.c +2 -0
@@ -1618,6 +1618,8 @@ static int tcpdump(struct state *state __maybe_unused, int argc, char **argv) } } + ret =EXIT_SUCCESS ; + out:list_for_each_entry_safe (dump_if, dump_if_tmp, &dump_if_list, list) {if (dump_if->raw_sock >=0 )
Signature · 1 line
2.47.3
PATCH 3/9 batctl: tcpdump: check frame length before reading the ethernet header
In reply to Sven Eckelmannparse_eth_hdr() reads ether_type without checking that the buffer actually contains a complete ethernet header. Use an header length check like in all other functions.
--- tcpdump.c | 2 ++ 1 file changed, 2 insertions(+)
tcpdump.c +2 -0
@@ -1200,6 +1200,8 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len,struct batadv_ogm_packet *batman_ogm_packet;struct ether_header *eth_hdr; +LEN_CHECK (buff_len,sizeof (*eth_hdr),"ETH HEADER" ); + eth_hdr = (struct ether_header *)packet_buff;switch (ntohs (eth_hdr->ether_type)) {
Signature · 1 line
2.47.3
PATCH 4/9 batctl: tcpdump: resolve bat-host name for ROAMv1 client
In reply to Sven EckelmannEvery packet parser in tcpdump forwards its read_opt argument to get_name_by_macaddr(), which only consults the bat-hosts table when read_opt carries USE_BAT_HOSTS. This was (without reason) not done in the TVLV ROAMv1 parser and the NO_FLAGS is hardcoded for the get_name_by_macaddr().
Just forward the read_opts flags like in all other functions to have the same user experience.
--- tcpdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tcpdump.c +2 -2
@@ -202,7 +202,7 @@ static void batctl_tvlv_parse_tt_v1(void *buff, ssize_t buff_len, }static void batctl_tvlv_parse_roam_v1 (void *buff,ssize_t buff_len, -int read_opt__maybe_unused ) +int read_opt) {struct batadv_tvlv_roam_adv *tvlv = buff;
@@ -214,7 +214,7 @@ static void batctl_tvlv_parse_roam_v1(void *buff, ssize_t buff_len, }printf ("\tTVLV ROAMv1: client %s, VLAN ID %d\n" , -get_name_by_macaddr ((struct ether_addr *)tvlv->client,NO_FLAGS ), +get_name_by_macaddr ((struct ether_addr *)tvlv->client, read_opt),BATADV_PRINT_VID (ntohs (tvlv->vid))); }
Signature · 1 line
2.47.3
PATCH 5/9 batctl: tcpdump: print the unreachable host for ICMP port unreachable
In reply to Sven EckelmannWhen decoding an ICMP port-unreachable message, tcpdump prints the destination of the ICMP repply packet. The actual relevant IP (the original destination) is only in the inner IP header.
The destinatin IP from the already validated tmp_udphdr must be used instead.
--- tcpdump.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tcpdump.c +8 -1
@@ -714,6 +714,7 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, int time_printed) {static const char ip_string[] ="IP" ; +char ipinner[INET_ADDRSTRLEN ];char ipsrc[INET_ADDRSTRLEN ];char ipdst[INET_ADDRSTRLEN ];struct udphdr *tmp_udphdr;
@@ -770,9 +771,15 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, tmp_udphdr = (struct udphdr *)(((char *)tmp_iphdr) + (tmp_iphdr->ihl *4 )); +if (!inet_ntop (AF_INET , &tmp_iphdr->daddr, ipinner, +sizeof (ipinner))) { +fprintf (stderr,"Cannot decode unreachable destination IP\n" ); +return ; + } +printf ("%s: ICMP " , ipdst);printf ("%s udp port %hu unreachable, length %zu\n" , - ipdst,ntohs (tmp_udphdr->dest), + ipinner,ntohs (tmp_udphdr->dest), (size_t )buff_len - (iphdr->ihl *4 ));break ;default :
Signature · 1 line
2.47.3
PATCH 6/9 batctl: tcpdump: skip partial line for oversized ICMPv6 errors
In reply to Sven Eckelmanndump_ipv6() prints the "IP6 <src> > <dst> " line prefix before it checks whether an ICMPv6 error message exceeds IPV6_MIN_MTU. The length check might just stop the processing and causes some truncated output on stdout. Which is then also not terminated by a newline.
Move the size check ahead of the printf to avoid this partial line.
--- tcpdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcpdump.c +1 -1
@@ -624,7 +624,6 @@ static void dump_ipv6(unsigned char *packet_buff, ssize_t buff_len, icmphdr = (struct icmp6_hdr *)(packet_buff +sizeof (struct ip6_hdr )); -printf ("%s %s > %s " , ip_string, ipsrc, ipdst);if (icmphdr->icmp6_type <ICMP6_INFOMSG_MASK && (size_t )(buff_len) >IPV6_MIN_MTU ) { fprintf(stderr,
@@ -633,6 +632,7 @@ static void dump_ipv6(unsigned char *packet_buff, ssize_t buff_len,return ; } +printf ("%s %s > %s " , ip_string, ipsrc, ipdst);printf ("ICMP6" );switch (icmphdr->icmp6_type) {case ICMP6_DST_UNREACH :
Signature · 1 line
2.47.3
PATCH 7/9 batctl: tcpdump: don't label unknown ICMPv6 types as unreachable
In reply to Sven EckelmannThe default case of the ICMPv6 type switch prints ", destination unreachable, unknown icmp6 type (N)". Every ICMPv6 type that is not explicitly handled is therefore mislabelled as a destination unreachable message.
Just report "unknown icmp6 type" instead.
--- tcpdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcpdump.c +1 -1
@@ -692,7 +692,7 @@ static void dump_ipv6(unsigned char *packet_buff, ssize_t buff_len, nd_nas_target, buff_len);break ;default : -printf (", destination unreachable, unknown icmp6 type (%u)\n" , +printf (", unknown icmp6 type (%u)\n" , icmphdr->icmp6_type);break ; }
Signature · 1 line
2.47.3
PATCH 8/9 batctl: tcpdump: reject invalid packet type arguments
In reply to Sven EckelmannThe strtol error handling is rather complicated and it is not only about checking the return value. The possible error indicators are:
* endptr is NULL
* endptr is not pointing to end delimiter
* endptr is pointing at nptr (because it might have been an empty string)
* returned value is larger/smaller than the expected maximum/minimum value range
The first tree conditions were not checked even when it is a potential problem for multiple places. And the user was never informed about the parsing errors. The old value was simply used.
Perform the needed validation steps and stop with an user readable error on parsing problems. At the same time, switch to the unsigned number parsing function strtoul because no negative numbers are allowed as inputs.
--- tcpdump.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
tcpdump.c +22 -7
@@ -1506,12 +1506,13 @@ static int tcpdump(struct state *state __maybe_unused, int argc, char **argv)fd_set tmp_wait_sockets;int ret =EXIT_FAILURE ;fd_set wait_sockets; +unsigned long tmp;struct timeval tv;int max_sock =0 ;ssize_t read_len; +char *endptr;int optchar;int res; -int tmp; dump_level = dump_level_all;
@@ -1527,14 +1528,28 @@ static int tcpdump(struct state *state __maybe_unused, int argc, char **argv) read_opt &= ~USE_BAT_HOSTS ;break ;case 'p' : - tmp =strtol (optarg,NULL ,10 ); -if (tmp >0 && tmp <= dump_level_all) - dump_level = tmp; + tmp =strtoul (optarg, &endptr,10 ); +if (!endptr || *endptr !='\0' || endptr == optarg || + tmp ==0 || tmp > dump_level_all) { +fprintf (stderr, +"Error - the supplied packet type is invalid: %s\n" , + optarg); +tcpdump_usage (); +return EXIT_FAILURE ; + } + dump_level = tmp;break ;case 'x' : - tmp =strtol (optarg,NULL ,10 ); -if (tmp >0 && tmp <= dump_level_all) - dump_level &= ~tmp; + tmp =strtoul (optarg, &endptr,10 ); +if (!endptr || *endptr !='\0' || endptr == optarg || + tmp ==0 || tmp > dump_level_all) { +fprintf (stderr, +"Error - the supplied packet type is invalid: %s\n" , + optarg); +tcpdump_usage (); +return EXIT_FAILURE ; + } + dump_level &= ~tmp;break ;default :tcpdump_usage ();
Signature · 1 line
2.47.3
PATCH 9/9 batctl: tcpdump: fix source address selection for 802.11 data frames
In reply to Sven EckelmannFor non-AMSDU data frame, we need to select as source host:
* neither from/to DS: addr2
* from DS: addr3
* to DS: addr2
* from+to DS: addr4
But the code is actually selecting:
* neither from/to DS: addr2
* from DS: addr3
* to DS: addr4
* from+to DS: addr3
Instead of checking single bits, the special cases "from+to DS" and "from DS" have to be checked separately.
--- tcpdump.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tcpdump.c +3 -3
@@ -1369,10 +1369,10 @@ static void parse_wifi_hdr(unsigned char *packet_buff, ssize_t buff_len,return ; shost = wifi_hdr->addr2; -if (fc &IEEE80211_FCTL_FROMDS ) - shost = wifi_hdr->addr3; -else if (fc &IEEE80211_FCTL_TODS ) +if ((fc &IEEE80211_FCTL_FROMDS ) && (fc &IEEE80211_FCTL_TODS )) shost = wifi_hdr->addr4; +else if (fc &IEEE80211_FCTL_FROMDS ) + shost = wifi_hdr->addr3; dhost = wifi_hdr->addr1;if (fc &IEEE80211_FCTL_TODS )
Signature · 1 line
2.47.3