From patchwork Sun Jun 9 16:56:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17937 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 115D9823FB; Sun, 9 Jun 2019 18:57:06 +0200 (CEST) Received: from durin.narfation.org (durin.narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 2B9B3821DA for ; Sun, 9 Jun 2019 18:57:04 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f1fc::4065]) by durin.narfation.org (Postfix) with ESMTPSA id CC9DD1100D0; Sun, 9 Jun 2019 18:57:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1560099421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kXoLtvJNISlefRQ1aQfx7ffdnhPYbLQ0VeqAQN5TVQg=; b=on0rM7d36m5gLm1ipiClvNbBLYzeSkv09qDpkIksUyNy6rmXraLnWsVf9TPPlJVNA2c4cC hxF6B0OVG3eDy99RGRRAyYdLvIPACA+Ce7Vh8xWo2PA3EorIM975aqLI120EfQX2BMcpcC 5zyEhlWRQV0vjh/xJ0Y1FlG9moH694c= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH 1/3] batctl: tcpdump: Add support for MCAST TVLV Date: Sun, 9 Jun 2019 18:56:50 +0200 Message-Id: <20190609165652.12841-2-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190609165652.12841-1-sven@narfation.org> References: <20190609165652.12841-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1560099423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kXoLtvJNISlefRQ1aQfx7ffdnhPYbLQ0VeqAQN5TVQg=; b=qw5FQ0ZQ5Y3buhNH3qZshem6xEQ9R9yaLJUI2C0baiQ2MXK+vbDVDK/Ua7x0GbEGJUvOkn i1S/k0dOKZKODjleUb20wuXWM/nfcIpWa4nw5c11DT8fGNyt9vyyb8pwF4GjL16hQ1UIer gecPy+gHSvpIJWqMSwmnmD1HwmOTEEg= ARC-Seal: i=1; s=20121; d=narfation.org; t=1560099423; a=rsa-sha256; cv=none; b=q8o5vWnevtZaNzSPfYhL4s/q7wi46NrKxSeMjl5wqKQF5oVEPW53pCrmGipQSxqT/ew8ii eQIB+guEmjxalRdMxIFIDEDODTzu+LeqRhRAukgZxX846ciQdsTIjO0b/PSwqk7xu6mIb3 duamnD16lITtk7msUbct28MuY3s4gbc= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" 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). Signed-off-by: Sven Eckelmann --- Cc: Linus Lüssing tcpdump.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tcpdump.c b/tcpdump.c index 8106a64..9153fc4 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -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; } From patchwork Sun Jun 9 16:56:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17938 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 1A1FC8266B; Sun, 9 Jun 2019 18:57:15 +0200 (CEST) Received: from durin.narfation.org (durin.narfation.org [IPv6:2001:4d88:2000:7::2]) by open-mesh.org (Postfix) with ESMTPS id 03F3482540 for ; Sun, 9 Jun 2019 18:57:12 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f1fc::4065]) by durin.narfation.org (Postfix) with ESMTPSA id 07FB21100D0; Sun, 9 Jun 2019 18:57:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1560099431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JjNXFA8zWg1IHa5NTP+hN0Wm6uNUnF/RnL7cAoHkeUI=; b=Krgi52okNW/G7qhNnx3M7Tta1sPzi2fHMz0Uc51t+7/R2b4ogHKlRpCad97n8UGOU4Vb1E ptQFhTkRVqHLcKXIBYbcF/3xmc+HCUKyOexl8mJ/Ltieuh4ajLecEFf2k3LmmKlHqDRp77 EDV6C2eQ9IcBvU2q7yDZM0yJllg+29E= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH 2/3] batctl: tcpdump: Add support for unicast fragmentation Date: Sun, 9 Jun 2019 18:56:51 +0200 Message-Id: <20190609165652.12841-3-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190609165652.12841-1-sven@narfation.org> References: <20190609165652.12841-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1560099431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JjNXFA8zWg1IHa5NTP+hN0Wm6uNUnF/RnL7cAoHkeUI=; b=PHZT69dqF5sdR6raoaA19koKMnbRJHOB1GVNx1cTcua5qghhX0Zm5n0WtnosqNbbhKgJKz jlA3x7Cue+AAgCrSgZQjHBGC+ywmYMTWmOG6IWUuuqhxoabmedAfHuK2niqOH+fbzKCX3z vt1mWLNU0mHqorD743OJFfd3sb2kleA= ARC-Seal: i=1; s=20121; d=narfation.org; t=1560099431; a=rsa-sha256; cv=none; b=OcImqairPJoLbyY20FvimutdSV623LzMceBmR+DkNCpRByQ2DnCoPD6LLd6Ry0cUEIWLX3 0TM3MbHWFBHsAJ54VTBJGHgoJJocOeRjM6X49CLNco2KEY392WAQERwfCRqvCtYRHyncHK AgljdfzSDdixg3IHFXqPvTwAcgh6868= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Cc: =?utf-8?q?Martin_Hundeb=C3=B8ll?= Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The 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. Signed-off-by: Sven Eckelmann --- Cc: Martin Hundebøll tcpdump.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tcpdump.c b/tcpdump.c index 9153fc4..7d04dd5 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -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 read if (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); From patchwork Sun Jun 9 16:56:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17939 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id CE65A8268E; Sun, 9 Jun 2019 18:57:20 +0200 (CEST) Received: from durin.narfation.org (durin.narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id E79428267F for ; Sun, 9 Jun 2019 18:57:16 +0200 (CEST) Received: from sven-desktop.home.narfation.org (unknown [IPv6:2a00:1ca0:1480:f1fc::4065]) by durin.narfation.org (Postfix) with ESMTPSA id F0E061100D0; Sun, 9 Jun 2019 18:57:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1560099435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K07//YnMq2ayadnuAMooGPtD1fXsPJ1oagTcUSh5KOM=; b=lePz0KPgstF6o07gh4wmibo580QvVwQsRarbUAJW0zauuWyTgwu6kX1NBZrm81XTENNbn+ apmnxedupGYRqr0c4mP+wD4yfkRplWbK6OnAOQOHO6YH/PNmeeJqT4AIDQw84MKWYHY4Js ykezjNwIg0wurVJOA0nI+0JQiX2bpZw= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Subject: [PATCH 3/3] batctl: tcpdump: Add support for coded packets Date: Sun, 9 Jun 2019 18:56:52 +0200 Message-Id: <20190609165652.12841-4-sven@narfation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190609165652.12841-1-sven@narfation.org> References: <20190609165652.12841-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1560099435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K07//YnMq2ayadnuAMooGPtD1fXsPJ1oagTcUSh5KOM=; b=EQAhk4xFrcj1fzWSrqEwcGt1C/CoomzqoHeqs7yfIahWT/lQqIkww7wGsDUcJwY2J99zVB OO8K8y2gf3+hL4XO4pMXj4SjYciH6qs7FpiL2wibSPzbPyAfdqYvKly8bh2iA6O6l5e/26 MPd/KVQ5T/h2SRp8UUgtIjzfUyMyYlE= ARC-Seal: i=1; s=20121; d=narfation.org; t=1560099435; a=rsa-sha256; cv=none; b=Zsiw18Cu/VQTObI/HcasZIH+S9rbqWam3oCIA3AYXnPKaC6COAmYV9XqfN+Qp7VpCcpXHr lvOEYHoVnomIAiaiidgR4OzgWf7unzRTEQ13yVlCCXU4Rzw3wmnX1zl7K0FarBT1gnej2H OjIfzE2M0V8uVtOYHMJHhnD/mN0TRlw= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sven smtp.mailfrom=sven@narfation.org X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Cc: =?utf-8?q?Martin_Hundeb=C3=B8ll?= Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The 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. Signed-off-by: Sven Eckelmann --- Cc: Martin Hundebøll tcpdump.c | 33 ++++++++++++++++++++++++++++++++- tcpdump.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tcpdump.c b/tcpdump.c index 7d04dd5..158b82e 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -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 read if (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); diff --git a/tcpdump.h b/tcpdump.h index 6e9ae01..470b96a 100644 --- a/tcpdump.h +++ b/tcpdump.h @@ -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