From patchwork Sun May 29 17:17:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1069 Return-Path: Received: from nm10.bullet.mail.ukl.yahoo.com (nm10.bullet.mail.ukl.yahoo.com [217.146.182.251]) by open-mesh.org (Postfix) with SMTP id 4FE311542B6 for ; Sun, 29 May 2011 19:19:01 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.180] by nm10.bullet.mail.ukl.yahoo.com with NNFMP; 29 May 2011 17:19:00 -0000 Received: from [77.238.184.80] by tm11.bullet.mail.ukl.yahoo.com with NNFMP; 29 May 2011 17:19:00 -0000 Received: from [127.0.0.1] by smtp149.mail.ukl.yahoo.com with NNFMP; 29 May 2011 17:19:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1306689540; bh=T9B4Lyv09dUW4GyK7OS+/kDw5R44NPAo0otliLslRjM=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer; b=TwA//JsM9cOoOjcmKVpYNpaZQ6ktaeC9o0iLiuwWge7nTbush67QCPGYLdfD49rw1xRcZjmYy2z1EU0ZQrQMEYIyjf6+AnPmP3PjbdPrfLL4O51QWgMBUkj84ZlpWJh0LBSkGVt+Qrdhw1w4S5nunHIag9ZY4+FJsCMsbGH/42U= X-Yahoo-Newman-Id: 220073.94806.bm@smtp149.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: avH9.O4VM1k51U.KckHkgU8OYAjUXoVYu8u6nIrSzeQuCJk dbeP4md0BVz9iY7oupfxVnB8WipWU5Vh6NeK8A1YyEswGRX2rhD_Q8QErgYZ YAPhSMa_WX4xN8eDYlWcpbU9KQLwYGnamsvx1k.0KQ6bM_w.0mKrgUp6EORM DFMxEC6Ye1621P8lzicsf9mMlS_xYYJqlGaIcGI8zcvOGsq5BQx7zJIXU9jq ZMctjyLEDwoRqdysbpM9fEHPf5ddAoU.akveztckjlK_Yaf4MTgu71yWHCgv YcfESiat8ARdo4rBiu5tTEx59ExH96by78Qo8lws7f2YFntlESwNcWA-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@90.35.97.226 with plain) by smtp149.mail.ukl.yahoo.com with SMTP; 29 May 2011 17:18:59 +0000 GMT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 29 May 2011 19:17:39 +0200 Message-Id: <1306689460-30162-1-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.2.3 Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 1/2] batctl: tcpdump - add support for tt request / roaming advertisement packets X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 May 2011 17:19:01 -0000 Signed-off-by: Marek Lindner Acked-by: Antonio Quartulli --- tcpdump.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- tcpdump.h | 3 +- 2 files changed, 78 insertions(+), 16 deletions(-) diff --git a/tcpdump.c b/tcpdump.c index a715e27..6f1adc1 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -52,7 +52,7 @@ if ((size_t)(buff_len) < (check_len)) { \ } static unsigned short dump_level = DUMP_TYPE_BATOGM | DUMP_TYPE_BATICMP | DUMP_TYPE_BATUCAST | - DUMP_TYPE_BATBCAST | DUMP_TYPE_BATVIS | DUMP_TYPE_BATFRAG | DUMP_TYPE_NONBAT; + DUMP_TYPE_BATBCAST | DUMP_TYPE_BATVIS | DUMP_TYPE_BATFRAG | DUMP_TYPE_BATTT | DUMP_TYPE_NONBAT; static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed); @@ -63,14 +63,15 @@ static void tcpdump_usage(void) printf(" \t -h print this help\n"); printf(" \t -n don't convert addresses to bat-host names\n"); printf(" \t -p dump specific packet type\n"); - printf(" \t\t%d - batman ogm packets\n", DUMP_TYPE_BATOGM); - printf(" \t\t%d - batman icmp packets\n", DUMP_TYPE_BATICMP); - printf(" \t\t%d - batman unicast packets\n", DUMP_TYPE_BATUCAST); - printf(" \t\t%d - batman broadcast packets\n", DUMP_TYPE_BATBCAST); - printf(" \t\t%d - batman vis packets\n", DUMP_TYPE_BATVIS); - printf(" \t\t%d - batman fragmented packets\n", DUMP_TYPE_BATFRAG); - printf(" \t\t%d - non batman packets\n", DUMP_TYPE_NONBAT); - printf(" \t\t%d - batman ogm & non batman packets\n", DUMP_TYPE_BATOGM | DUMP_TYPE_NONBAT); + printf(" \t\t%3d - batman ogm packets\n", DUMP_TYPE_BATOGM); + printf(" \t\t%3d - batman icmp packets\n", DUMP_TYPE_BATICMP); + printf(" \t\t%3d - batman unicast packets\n", DUMP_TYPE_BATUCAST); + printf(" \t\t%3d - batman broadcast packets\n", DUMP_TYPE_BATBCAST); + printf(" \t\t%3d - batman vis packets\n", DUMP_TYPE_BATVIS); + printf(" \t\t%3d - batman fragmented packets\n", DUMP_TYPE_BATFRAG); + printf(" \t\t%3d - batman tt / roaming packets\n", DUMP_TYPE_BATTT); + printf(" \t\t%3d - non batman packets\n", DUMP_TYPE_NONBAT); + printf(" \t\t%3d - batman ogm & non batman packets\n", DUMP_TYPE_BATOGM | DUMP_TYPE_NONBAT); } static int print_time(void) @@ -247,6 +248,58 @@ static void dump_vlan(unsigned char *packet_buff, ssize_t buff_len, int read_opt parse_eth_hdr(packet_buff + 4, buff_len - 4, read_opt, time_printed); } +static void dump_batman_tt(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) +{ + struct ether_header *ether_header; + struct tt_query_packet *tt_query_packet; + + LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct tt_query_packet), "BAT TT"); + + ether_header = (struct ether_header *)packet_buff; + tt_query_packet = (struct tt_query_packet *)(packet_buff + sizeof(struct ether_header)); + + if (!time_printed) + print_time(); + + printf("BAT %s > ", + get_name_by_macaddr((struct ether_addr *)tt_query_packet->src, read_opt)); + + printf("%s: TT %s, ttvn %d, %s %d, ttl %2d, v %d, flags [%c%c%c], length %zu\n", + get_name_by_macaddr((struct ether_addr *)tt_query_packet->dst, read_opt), + tt_query_packet->flags & TT_RESPONSE ? "response" : "request", + tt_query_packet->ttvn, tt_query_packet->flags & TT_RESPONSE ? "entries" : "crc", + ntohs(tt_query_packet->tt_data), tt_query_packet->ttl, tt_query_packet->version, + (tt_query_packet->flags & TT_REQUEST ? 'Q' : '.'), + (tt_query_packet->flags & TT_RESPONSE ? 'P' : '.'), + (tt_query_packet->flags & TT_FULL_TABLE ? 'F' : '.'), + (size_t)buff_len - sizeof(struct ether_header)); +} + +static void dump_batman_roam(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) +{ + struct ether_header *ether_header; + struct roam_adv_packet *roam_adv_packet; + + LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct roam_adv_packet), "BAT ROAM"); + + ether_header = (struct ether_header *)packet_buff; + roam_adv_packet = (struct roam_adv_packet *)(packet_buff + sizeof(struct ether_header)); + + if (!time_printed) + print_time(); + + printf("BAT %s > ", + get_name_by_macaddr((struct ether_addr *)roam_adv_packet->src, read_opt)); + + printf("%s: ROAM, ", + get_name_by_macaddr((struct ether_addr *)roam_adv_packet->dst, read_opt)); + + printf("client %s, ttl %2d, v %d, length %zu\n", + get_name_by_macaddr((struct ether_addr *)roam_adv_packet->client, read_opt), + roam_adv_packet->ttl, roam_adv_packet->version, + (size_t)buff_len - sizeof(struct ether_header)); +} + static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) { struct ether_header *ether_header; @@ -263,9 +316,9 @@ static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int re printf("BAT %s: ", get_name_by_macaddr((struct ether_addr *)batman_packet->orig, read_opt)); - printf("OGM via neigh %s, seq %u, tq %3d, ttl %2d, v %d, flags [%c%c%c%c], length %zu\n", + printf("OGM via neigh %s, seq %u, tq %3d, ttvn %d, ttl %2d, v %d, flags [%c%c%c%c], length %zu\n", get_name_by_macaddr((struct ether_addr *)ether_header->ether_shost, read_opt), - ntohl(batman_packet->seqno), batman_packet->tq, + ntohl(batman_packet->seqno), batman_packet->tq, batman_packet->ttvn, batman_packet->ttl, batman_packet->version, (batman_packet->flags & DIRECTLINK ? 'D' : '.'), (batman_packet->flags & VIS_SERVER ? 'V' : '.'), @@ -334,9 +387,9 @@ static void dump_batman_ucast(unsigned char *packet_buff, ssize_t buff_len, int printf("BAT %s > ", get_name_by_macaddr((struct ether_addr *)ether_header->ether_shost, read_opt)); - printf("%s: UCAST, ttl %hhu, ", + printf("%s: UCAST, ttvn %d, ttl %hhu, ", get_name_by_macaddr((struct ether_addr *)unicast_packet->dest, read_opt), - unicast_packet->ttl); + unicast_packet->ttvn, unicast_packet->ttl); parse_eth_hdr(packet_buff + ETH_HLEN + sizeof(struct unicast_packet), buff_len - ETH_HLEN - sizeof(struct unicast_packet), @@ -385,9 +438,9 @@ static void dump_batman_frag(unsigned char *packet_buff, ssize_t buff_len, int r printf("BAT %s > ", get_name_by_macaddr((struct ether_addr *)unicast_frag_packet->orig, read_opt)); - printf("%s: FRAG, seq %hu, ttl %hhu, flags [%c%c], ", + printf("%s: FRAG, seq %hu, ttvn %d, ttl %hhu, flags [%c%c], ", get_name_by_macaddr((struct ether_addr *)unicast_frag_packet->dest, read_opt), - ntohs(unicast_frag_packet->seqno), unicast_frag_packet->ttl, + ntohs(unicast_frag_packet->seqno), unicast_frag_packet->ttvn, unicast_frag_packet->ttl, (unicast_frag_packet->flags & UNI_FRAG_HEAD ? 'H' : '.'), (unicast_frag_packet->flags & UNI_FRAG_LARGETAIL ? 'L' : '.')); @@ -447,6 +500,14 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int read if (dump_level & DUMP_TYPE_BATFRAG) dump_batman_frag(packet_buff, buff_len, read_opt, time_printed); break; + case BAT_TT_QUERY: + if (dump_level & DUMP_TYPE_BATTT) + dump_batman_tt(packet_buff, buff_len, read_opt, time_printed); + break; + case BAT_ROAM_ADV: + if (dump_level & DUMP_TYPE_BATTT) + dump_batman_roam(packet_buff, buff_len, read_opt, time_printed); + break; default: printf("Warning - packet contains unknown batman packet type: 0x%02x\n", batman_packet->packet_type); break; diff --git a/tcpdump.h b/tcpdump.h index 4364be1..925b116 100644 --- a/tcpdump.h +++ b/tcpdump.h @@ -37,7 +37,8 @@ #define DUMP_TYPE_BATBCAST 8 #define DUMP_TYPE_BATVIS 16 #define DUMP_TYPE_BATFRAG 32 -#define DUMP_TYPE_NONBAT 64 +#define DUMP_TYPE_BATTT 64 +#define DUMP_TYPE_NONBAT 128 #define IEEE80211_FCTL_FTYPE 0x0c00 #define IEEE80211_FCTL_TODS 0x0001