batctl: tcpdump - parse TVLV containers
PATCH v4 1/1 batctl: tcpdump - parse TVLV containers
From: Antonio Quartulli <[email protected]>
OGMs and unicast TVLV packets carry TVLV containers as payload.
With this patch such containers are now parsed and the relevant information is printed to screen.
---
changes since v3:
- undo unneeded style change in tcpdump.c
- remove unneeded sentence about style change sin commit message
changes since v2:
- extended doc in README and manpage
changes since v1:
- remove all the style changes
- make tvlv_len of type ssize_t in dump_batman_iv_ogm()
README | 1 + main.h | 7 +++ man/batctl.8 | 3 ++ tcpdump.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- tcpdump.h | 1 + 5 files changed, 177 insertions(+), 4 deletions(-)
README +1 -0
@@ -161,6 +161,7 @@ packet types: 2 - batman icmp packets 4 - batman unicast packets 8 - batman broadcast packets + 16 - batman unicast tvlv packets 32 - batman fragmented packets 64 - batman tt / roaming packets 128 - non batman packets
main.h +7 -0
@@ -49,4 +49,11 @@extern char module_ver_path[]; +#ifndef VLAN_VID_MASK +#define VLAN_VID_MASK 0xfff +#endif + +#define BATADV_PRINT_VID (vid) (vid & BATADV_VLAN_HAS_TAG ? \ + (int)(vid & VLAN_VID_MASK) : -1) +#endif
man/batctl.8 +3 -0
@@ -288,6 +288,9 @@ except specified). The following packet types are available: 8 - batman broadcast packets .RE .RS 16 +16 - batman unicast tvlv packets +.RE +.RS 16 32 - batman fragmented packets .RE .RS 16
tcpdump.c +165 -4
212 lines not on this page · raw message
tcpdump.h +1 -0
@@ -41,6 +41,7 @@#define DUMP_TYPE_BATICMP 2#define DUMP_TYPE_BATUCAST 4#define DUMP_TYPE_BATBCAST 8 +#define DUMP_TYPE_BATUTVLV 16#define DUMP_TYPE_BATFRAG 32#define DUMP_TYPE_NONBAT 128
Signature · 1 line
1.8.5.5
Quoted 15 lines · On Wednesday 20 August 2014 17:04:57 Antonio Quartulli wrote:
(quoted diff) +0
-1@@ -494,14 +632,32 @@ static void dump_batman_iv_ogm(unsigned char *packet_buff, ssize_t buff_len, int printf("BAT %s: ", get_name_by_macaddr((struct ether_addr *)batman_ogm_packet->orig, read_opt)); - printf("OGM IV via neigh %s, seq %u, tq %3d, ttl %2d, v %d, flags[%c%c%c], length %zu\n", +
tvlv_len=ntohs(batman_ogm_packet->tvlv_len);
+ printf("OGM IV via neigh %s, seq %u, tq %3d, ttl %2d, v %d, flags
[%c%c%c], length %zu,tvlv_len%zu\n",get_name_by_macaddr((struct ether_addr *)ether_header->ether_shost, read_opt),ntohl(batman_ogm_packet->seqno),batman_ogm_packet->tq,batman_ogm_packet->ttl,batman_ogm_packet->version, (batman_ogm_packet->flags&BATADV_NOT_BEST_NEXT_HOP? 'N' : '.'), (batman_ogm_packet->flags&BATADV_DIRECTLINK? 'D' : '.'), (batman_ogm_packet->flags&BATADV_PRIMARIES_FIRST_HOP? 'F' : '.'),
tcpdump.c static void dump_batman_iv_ogm(unsigned char *packet_buff, ssize_t buff_len, int · line 646
Quoted 5 lines
tcpdump.c +4
-1- (size_t)buff_len - sizeof(struct ether_header)); + check_len, tvlv_len); + + check_len -=sizeof (struct batadv_ogm_packet ); +LEN_CHECK (check_len, tvlv_len,"BAT OGM TVLV (containers)" );
CC tcpdump.otcpdump.c: In function ‘dump_batman_iv_ogm’:
tcpdump.c:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ((size_t)(buff_len) < (check_len)) { \
^tcpdump.c:646:2: note: in expansion of macro ‘LEN_CHECK’
LEN_CHECK(check_len, tvlv_len, "BAT OGM TVLV (containers)"); ^
Cheers,
Marek