1
0

300-Add-support-for-B.A.T.M.A.N.-Advanced.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. From 3d8d268320d2381021a409ff8d03533698dd6242 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@c0d3.blue>
  3. Date: Mon, 23 Nov 2020 00:38:22 +0100
  4. Subject: [PATCH] Add support for B.A.T.M.A.N. Advanced
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This adds support for the layer 2 mesh routing protocol
  9. B.A.T.M.A.N. Advanced. "batadv" can be used to filter on batman-adv
  10. packets. It also allows later filters to look at frames inside the
  11. tunnel when both "version" and "type" are specified.
  12. Documentation for the batman-adv protocol can be found at the following
  13. locations:
  14. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/batman-adv.rst
  15. https://www.open-mesh.org/
  16. Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
  17. ---
  18. Makefile.in | 2 +
  19. batadv_legacy_packet.h | 77 +++++++++++++++++++
  20. batadv_packet.h | 78 ++++++++++++++++++++
  21. ethertype.h | 3 +
  22. gencode.c | 164 +++++++++++++++++++++++++++++++++++++++++
  23. gencode.h | 3 +
  24. grammar.y.in | 32 +++++++-
  25. nametoaddr.c | 59 +++++++++++++++
  26. pcap-filter.manmisc.in | 35 ++++++++-
  27. pcap/namedb.h | 2 +
  28. scanner.l | 1 +
  29. 11 files changed, 453 insertions(+), 3 deletions(-)
  30. create mode 100644 batadv_legacy_packet.h
  31. create mode 100644 batadv_packet.h
  32. --- a/Makefile.in
  33. +++ b/Makefile.in
  34. @@ -133,6 +133,8 @@ PUBHDR = \
  35. HDR = $(PUBHDR) \
  36. arcnet.h \
  37. atmuni31.h \
  38. + batadv_legacy_packet.h \
  39. + batadv_packet.h \
  40. diag-control.h \
  41. ethertype.h \
  42. extract.h \
  43. --- /dev/null
  44. +++ b/batadv_legacy_packet.h
  45. @@ -0,0 +1,77 @@
  46. +/* SPDX-License-Identifier: BSD-3 */
  47. +/* Copyright (C) 2020 Linus Lüssing */
  48. +
  49. +#ifndef _BATADV_LEGACY_PACKET_H_
  50. +#define _BATADV_LEGACY_PACKET_H_
  51. +
  52. +enum batadv_legacy_packettype {
  53. + BATADV_LEGACY_IV_OGM = 0x01,
  54. + BATADV_LEGACY_ICMP = 0x02,
  55. + BATADV_LEGACY_UNICAST = 0x03,
  56. + BATADV_LEGACY_BCAST = 0x04,
  57. + BATADV_LEGACY_VIS = 0x05,
  58. + BATADV_LEGACY_UNICAST_FRAG = 0x06,
  59. + BATADV_LEGACY_TT_QUERY = 0x07,
  60. + BATADV_LEGACY_ROAM_ADV = 0x08,
  61. + BATADV_LEGACY_UNICAST_4ADDR = 0x09,
  62. + BATADV_LEGACY_CODED = 0x0a,
  63. +};
  64. +
  65. +#define ETH_ALEN 6
  66. +
  67. +struct batadv_legacy_unicast_packet {
  68. + uint8_t packet_type;
  69. + uint8_t version;
  70. + uint8_t ttl;
  71. + uint8_t ttvn;
  72. + uint8_t dest[ETH_ALEN];
  73. +};
  74. +
  75. +struct batadv_legacy_unicast_4addr_packet {
  76. + uint8_t packet_type;
  77. + uint8_t version;
  78. + uint8_t ttl;
  79. + uint8_t src[ETH_ALEN];
  80. + uint8_t subtype;
  81. + uint8_t reserved;
  82. +};
  83. +
  84. +struct batadv_legacy_unicast_frag_packet {
  85. + uint8_t packet_type;
  86. + uint8_t version;
  87. + uint8_t ttl;
  88. + uint8_t ttvn;
  89. + uint8_t dest[ETH_ALEN];
  90. + uint8_t flags;
  91. + uint8_t align;
  92. + uint8_t orig[ETH_ALEN];
  93. + uint8_t seqno[2]; /* 2-byte integral value */
  94. +};
  95. +
  96. +struct batadv_legacy_bcast_packet {
  97. + uint8_t packet_type;
  98. + uint8_t version;
  99. + uint8_t ttl;
  100. + uint8_t reserved;
  101. + uint8_t seqno[4]; /* 4-byte integral value */
  102. + uint8_t orig[ETH_ALEN];
  103. +};
  104. +
  105. +struct batadv_legacy_coded_packet {
  106. + uint8_t packet_type;
  107. + uint8_t version;
  108. + uint8_t ttl;
  109. + uint8_t first_ttvn;
  110. + uint8_t first_source[ETH_ALEN];
  111. + uint8_t first_orig_dest[ETH_ALEN];
  112. + uint8_t first_crc[4]; /* 4-byte integral value */
  113. + uint8_t second_ttl;
  114. + uint8_t second_ttvn;
  115. + uint8_t second_dest[ETH_ALEN];
  116. + uint8_t second_source[ETH_ALEN];
  117. + uint8_t second_orig_dest[ETH_ALEN];
  118. + uint8_t second_crc[4]; /* 4-byte integral value */
  119. + uint8_t coded_len[2]; /* 2-byte integral value */
  120. +};
  121. +
  122. +#endif /* _BATADV_LEGACY_PACKET_H_ */
  123. --- /dev/null
  124. +++ b/batadv_packet.h
  125. @@ -0,0 +1,78 @@
  126. +/* SPDX-License-Identifier: BSD-3 */
  127. +/* Copyright (C) 2020 Linus Lüssing */
  128. +
  129. +#ifndef _BATADV_PACKET_H_
  130. +#define _BATADV_PACKET_H_
  131. +
  132. +/* For the definitive and most recent packet format definition,
  133. + * see the batadv_packet.h in the Linux kernel.
  134. + */
  135. +
  136. +enum batadv_packettype {
  137. + BATADV_IV_OGM = 0x00,
  138. + BATADV_BCAST = 0x01,
  139. + BATADV_CODED = 0x02,
  140. + BATADV_ELP = 0x03,
  141. + BATADV_OGM2 = 0x04,
  142. + BATADV_UNICAST = 0x40,
  143. + BATADV_UNICAST_FRAG = 0x41,
  144. + BATADV_UNICAST_4ADDR = 0x42,
  145. + BATADV_ICMP = 0x43,
  146. + BATADV_UNICAST_TVLV = 0x44,
  147. +};
  148. +
  149. +#define ETH_ALEN 6
  150. +
  151. +struct batadv_unicast_packet {
  152. + uint8_t packet_type;
  153. + uint8_t version;
  154. + uint8_t ttl;
  155. + uint8_t ttvn;
  156. + uint8_t dest[ETH_ALEN];
  157. +};
  158. +
  159. +struct batadv_unicast_4addr_packet {
  160. + struct batadv_unicast_packet u;
  161. + uint8_t src[ETH_ALEN];
  162. + uint8_t subtype;
  163. + uint8_t reserved;
  164. +};
  165. +
  166. +struct batadv_frag_packet {
  167. + uint8_t packet_type;
  168. + uint8_t version;
  169. + uint8_t ttl;
  170. + uint8_t num_pri; /* number and priority */
  171. + uint8_t dest[ETH_ALEN];
  172. + uint8_t orig[ETH_ALEN];
  173. + uint8_t seqno[2]; /* 2-byte integral value */
  174. + uint8_t total_size[2]; /* 2-byte integral value */
  175. +};
  176. +
  177. +struct batadv_bcast_packet {
  178. + uint8_t packet_type;
  179. + uint8_t version;
  180. + uint8_t ttl;
  181. + uint8_t reserved;
  182. + uint8_t seqno[4]; /* 4-byte integral value */
  183. + uint8_t orig[ETH_ALEN];
  184. +};
  185. +
  186. +struct batadv_coded_packet {
  187. + uint8_t packet_type;
  188. + uint8_t version;
  189. + uint8_t ttl;
  190. + uint8_t first_ttvn;
  191. + uint8_t first_source[ETH_ALEN];
  192. + uint8_t first_orig_dest[ETH_ALEN];
  193. + uint8_t first_crc[4]; /* 4-byte integral value */
  194. + uint8_t second_ttl;
  195. + uint8_t second_ttvn;
  196. + uint8_t second_dest[ETH_ALEN];
  197. + uint8_t second_source[ETH_ALEN];
  198. + uint8_t second_orig_dest[ETH_ALEN];
  199. + uint8_t second_crc[4]; /* 4-byte integral value */
  200. + uint8_t coded_len[2]; /* 2-byte integral value */
  201. +};
  202. +
  203. +#endif /* _BATADV_PACKET_H_ */
  204. --- a/ethertype.h
  205. +++ b/ethertype.h
  206. @@ -49,6 +49,9 @@
  207. #ifndef ETHERTYPE_TRAIL
  208. #define ETHERTYPE_TRAIL 0x1000
  209. #endif
  210. +#ifndef ETHERTYPE_BATMAN
  211. +#define ETHERTYPE_BATMAN 0x4305 /* B.A.T.M.A.N. Advanced */
  212. +#endif
  213. #ifndef ETHERTYPE_MOPDL
  214. #define ETHERTYPE_MOPDL 0x6001
  215. #endif
  216. --- a/gencode.c
  217. +++ b/gencode.c
  218. @@ -60,6 +60,8 @@
  219. #include "sunatmpos.h"
  220. #include "pflog.h"
  221. #include "ppp.h"
  222. +#include "batadv_packet.h"
  223. +#include "batadv_legacy_packet.h"
  224. #include "pcap/sll.h"
  225. #include "pcap/ipnet.h"
  226. #include "arcnet.h"
  227. @@ -9436,6 +9438,168 @@ gen_geneve(compiler_state_t *cstate, bpf
  228. return b1;
  229. }
  230. +static struct block *
  231. +gen_batadv_check_version(compiler_state_t *cstate, struct block *b0, bpf_u_int32 version)
  232. +{
  233. + struct block *b1;
  234. +
  235. + if (version > UINT8_MAX)
  236. + bpf_error(cstate,
  237. + "batman-adv compatibility version number %u unsupported",
  238. + version);
  239. +
  240. + b1 = gen_cmp(cstate, OR_LINKPL, 1, BPF_B, version);
  241. + gen_and(b0, b1);
  242. +
  243. + return b1;
  244. +}
  245. +
  246. +static struct block *
  247. +gen_batadv_check_type(compiler_state_t *cstate, struct block *b0,
  248. + bpf_u_int32 version, bpf_u_int32 type)
  249. +{
  250. + struct block *b1;
  251. +
  252. + switch (version) {
  253. + case 14:
  254. + case 15:
  255. + if (type > UINT8_MAX)
  256. + bpf_error(cstate,
  257. + "batman-adv packet type %u unsupported for compatibility version %u",
  258. + type, version);
  259. +
  260. + b1 = gen_cmp(cstate, OR_LINKPL, 0, BPF_B, type);
  261. + gen_and(b0, b1);
  262. + b0 = b1;
  263. +
  264. + break;
  265. + default:
  266. + bpf_error(cstate,
  267. + "batman-adv compatibility version number %u unsupported",
  268. + version);
  269. + }
  270. +
  271. + return b0;
  272. +}
  273. +
  274. +
  275. +static void gen_batadv_push_offset(compiler_state_t *cstate, u_int offset)
  276. +{
  277. + PUSH_LINKHDR(cstate, DLT_EN10MB, cstate->off_linkpl.is_variable,
  278. + cstate->off_linkpl.constant_part + cstate->off_nl + offset,
  279. + cstate->off_linkpl.reg);
  280. +
  281. + cstate->off_linktype.constant_part += cstate->off_linkhdr.constant_part;
  282. + cstate->off_linkpl.constant_part += cstate->off_linkhdr.constant_part;
  283. +
  284. + cstate->off_nl = 0;
  285. + cstate->off_nl_nosnap = 0; /* no 802.2 LLC */
  286. +}
  287. +
  288. +static void
  289. +gen_batadv_offsets_v14(compiler_state_t *cstate, bpf_u_int32 type)
  290. +{
  291. + size_t offset;
  292. +
  293. + switch (type) {
  294. + case BATADV_LEGACY_UNICAST: /* 0x03 */
  295. + offset = sizeof(struct batadv_legacy_unicast_packet);
  296. + break;
  297. + case BATADV_LEGACY_BCAST: /* 0x04 */
  298. + offset = sizeof(struct batadv_legacy_bcast_packet);
  299. + break;
  300. + case BATADV_LEGACY_UNICAST_FRAG: /* 0x06 */
  301. + offset = sizeof(struct batadv_legacy_unicast_frag_packet);
  302. + break;
  303. + case BATADV_LEGACY_UNICAST_4ADDR: /* 0x09 */
  304. + offset = sizeof(struct batadv_legacy_unicast_4addr_packet);
  305. + break;
  306. + case BATADV_LEGACY_CODED: /* 0x0a */
  307. + offset = sizeof(struct batadv_legacy_coded_packet);
  308. + break;
  309. + default:
  310. + offset = 0;
  311. + }
  312. +
  313. + if (offset)
  314. + gen_batadv_push_offset(cstate, (u_int)offset);
  315. +}
  316. +
  317. +static void
  318. +gen_batadv_offsets_v15(compiler_state_t *cstate, bpf_u_int32 type)
  319. +{
  320. + size_t offset;
  321. +
  322. + switch (type) {
  323. + case BATADV_BCAST: /* 0x01 */
  324. + offset = sizeof(struct batadv_bcast_packet);
  325. + break;
  326. + case BATADV_CODED: /* 0x02 */
  327. + offset = sizeof(struct batadv_coded_packet);
  328. + break;
  329. + case BATADV_UNICAST: /* 0x40 */
  330. + offset = sizeof(struct batadv_unicast_packet);
  331. + break;
  332. + case BATADV_UNICAST_FRAG: /* 0x41 */
  333. + offset = sizeof(struct batadv_frag_packet);
  334. + break;
  335. + case BATADV_UNICAST_4ADDR: /* 0x42 */
  336. + offset = sizeof(struct batadv_unicast_4addr_packet);
  337. + break;
  338. + case BATADV_UNICAST_TVLV:
  339. + /* unsupported for now, needs variable offset to
  340. + * take tvlv_len into account
  341. + */
  342. + /* fall through */
  343. + default:
  344. + offset = 0;
  345. + }
  346. +
  347. + if (offset)
  348. + gen_batadv_push_offset(cstate, (u_int)offset);
  349. +}
  350. +
  351. +static void
  352. +gen_batadv_offsets(compiler_state_t *cstate, bpf_u_int32 version, bpf_u_int32 type)
  353. +{
  354. + switch (version) {
  355. + case 14:
  356. + gen_batadv_offsets_v14(cstate, type);
  357. + break;
  358. + case 15:
  359. + gen_batadv_offsets_v15(cstate, type);
  360. + break;
  361. + default:
  362. + break;
  363. + }
  364. +}
  365. +
  366. +struct block *
  367. +gen_batadv(compiler_state_t *cstate, bpf_u_int32 version, int has_version,
  368. + bpf_u_int32 type, int has_type)
  369. +{
  370. + struct block *b0;
  371. +
  372. + /*
  373. + * Catch errors reported by us and routines below us, and return NULL
  374. + * on an error.
  375. + */
  376. + if (setjmp(cstate->top_ctx))
  377. + return (NULL);
  378. +
  379. + b0 = gen_linktype(cstate, ETHERTYPE_BATMAN);
  380. +
  381. + if (has_version)
  382. + b0 = gen_batadv_check_version(cstate, b0, version);
  383. +
  384. + if (has_type) {
  385. + b0 = gen_batadv_check_type(cstate, b0, version, type);
  386. + gen_batadv_offsets(cstate, version, type);
  387. + }
  388. +
  389. + return b0;
  390. +}
  391. +
  392. /* Check that the encapsulated frame has a link layer header
  393. * for Ethernet filters. */
  394. static struct block *
  395. --- a/gencode.h
  396. +++ b/gencode.h
  397. @@ -358,6 +358,9 @@ struct block *gen_pppoes(compiler_state_
  398. struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int);
  399. +struct block *gen_batadv(compiler_state_t *, bpf_u_int32, int,
  400. + bpf_u_int32, int);
  401. +
  402. struct block *gen_atmfield_code(compiler_state_t *, int, bpf_u_int32,
  403. int, int);
  404. struct block *gen_atmtype_abbrev(compiler_state_t *, int);
  405. --- a/grammar.y.in
  406. +++ b/grammar.y.in
  407. @@ -375,6 +375,7 @@ DIAG_OFF_BISON_BYACC
  408. %type <i> mtp2type
  409. %type <blk> mtp3field
  410. %type <blk> mtp3fieldvalue mtp3value mtp3listvalue
  411. +%type <rblk> pbatadv
  412. %token DST SRC HOST GATEWAY
  413. @@ -393,7 +394,7 @@ DIAG_OFF_BISON_BYACC
  414. %token LEN
  415. %token IPV6 ICMPV6 AH ESP
  416. %token VLAN MPLS
  417. -%token PPPOED PPPOES GENEVE
  418. +%token PPPOED PPPOES GENEVE BATADV
  419. %token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
  420. %token STP
  421. %token IPX
  422. @@ -620,11 +621,40 @@ other: pqual TK_BROADCAST { CHECK_PTR_
  423. | PPPOES { CHECK_PTR_VAL(($$ = gen_pppoes(cstate, 0, 0))); }
  424. | GENEVE pnum { CHECK_PTR_VAL(($$ = gen_geneve(cstate, $2, 1))); }
  425. | GENEVE { CHECK_PTR_VAL(($$ = gen_geneve(cstate, 0, 0))); }
  426. + | BATADV pbatadv { $$ = $2; }
  427. | pfvar { $$ = $1; }
  428. | pqual p80211 { $$ = $2; }
  429. | pllc { $$ = $1; }
  430. ;
  431. +pbatadv: { CHECK_PTR_VAL(($$ = gen_batadv(cstate, 0, 0, 0, 0))); }
  432. + | pnum { CHECK_PTR_VAL(($$ = gen_batadv(cstate, $1, 1, 0, 0))); }
  433. + | pnum pnum { CHECK_PTR_VAL(($$ = gen_batadv(cstate, $1, 1, $2, 1))); }
  434. + | pnum ID
  435. + {
  436. + int type;
  437. +
  438. + switch ($1) {
  439. + case 14:
  440. + type = pcap_nametobatadvtype_v14($2);
  441. + break;
  442. + case 15:
  443. + type = pcap_nametobatadvtype_v15($2);
  444. + break;
  445. + default:
  446. + bpf_set_error(cstate, "batman-adv compatibility version number %u unsupported", $1);
  447. + YYABORT;
  448. + }
  449. +
  450. + if (type == PROTO_UNDEF) {
  451. + bpf_set_error(cstate, "invalid batman-adv packet type value \"%s\"", $2);
  452. + YYABORT;
  453. + }
  454. +
  455. + CHECK_PTR_VAL(($$ = gen_batadv(cstate, $1, 1, type, 1)));
  456. + }
  457. + ;
  458. +
  459. pfvar: PF_IFNAME ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ifname(cstate, $2))); }
  460. | PF_RSET ID { CHECK_PTR_VAL($2); CHECK_PTR_VAL(($$ = gen_pf_ruleset(cstate, $2))); }
  461. | PF_RNR NUM { CHECK_PTR_VAL(($$ = gen_pf_rnr(cstate, $2))); }
  462. --- a/nametoaddr.c
  463. +++ b/nametoaddr.c
  464. @@ -136,8 +136,12 @@
  465. #include "diag-control.h"
  466. +#include "batadv_packet.h"
  467. +#include "batadv_legacy_packet.h"
  468. +
  469. #include "gencode.h"
  470. #include <pcap/namedb.h>
  471. +
  472. #include "nametoaddr.h"
  473. #ifdef HAVE_OS_PROTO_H
  474. @@ -604,6 +608,7 @@ PCAP_API_DEF struct eproto eproto_db[] =
  475. { "moprc", ETHERTYPE_MOPRC },
  476. { "rarp", ETHERTYPE_REVARP },
  477. { "sca", ETHERTYPE_SCA },
  478. + { "batadv", ETHERTYPE_BATMAN },
  479. { (char *)0, 0 }
  480. };
  481. @@ -638,6 +643,60 @@ pcap_nametollc(const char *s)
  482. while (p->s != 0) {
  483. if (strcmp(p->s, s) == 0)
  484. + return p->p;
  485. + p += 1;
  486. + }
  487. + return PROTO_UNDEF;
  488. +}
  489. +
  490. +/* Static data base of batman-adv v14 packet type values. */
  491. +static struct eproto batadv_type_db_v14[] = {
  492. + { "iv_ogm", BATADV_LEGACY_IV_OGM },
  493. + { "icmp", BATADV_LEGACY_ICMP },
  494. + { "unicast", BATADV_LEGACY_UNICAST },
  495. + { "bcast", BATADV_LEGACY_BCAST },
  496. + { "vis", BATADV_LEGACY_VIS },
  497. + { "unicast_frag", BATADV_LEGACY_UNICAST_FRAG },
  498. + { "tt_query", BATADV_LEGACY_TT_QUERY },
  499. + { "roam_adv", BATADV_LEGACY_ROAM_ADV },
  500. + { "unicast_4addr", BATADV_LEGACY_UNICAST_4ADDR },
  501. + { "coded", BATADV_LEGACY_CODED },
  502. + { (char *)0, 0 }
  503. +};
  504. +
  505. +int pcap_nametobatadvtype_v14(const char *s)
  506. +{
  507. + struct eproto *p = batadv_type_db_v14;
  508. +
  509. + while (p->s != 0) {
  510. + if (strcmp(p->s, s) == 0)
  511. + return p->p;
  512. + p += 1;
  513. + }
  514. + return PROTO_UNDEF;
  515. +}
  516. +
  517. +/* Static data base of batman-adv v15 packet type values. */
  518. +static struct eproto batadv_type_db_v15[] = {
  519. + { "iv_ogm", BATADV_IV_OGM },
  520. + { "bcast", BATADV_BCAST },
  521. + { "coded", BATADV_CODED },
  522. + { "elp", BATADV_ELP },
  523. + { "ogm2", BATADV_OGM2 },
  524. + { "unicast", BATADV_UNICAST },
  525. + { "unicast_frag", BATADV_UNICAST_FRAG },
  526. + { "unicast_4addr", BATADV_UNICAST_4ADDR },
  527. + { "icmp", BATADV_ICMP },
  528. + { "unicast_tvlv", BATADV_UNICAST_TVLV },
  529. + { (char *)0, 0 }
  530. +};
  531. +
  532. +int pcap_nametobatadvtype_v15(const char *s)
  533. +{
  534. + struct eproto *p = batadv_type_db_v15;
  535. +
  536. + while (p->s != 0) {
  537. + if (strcmp(p->s, s) == 0)
  538. return p->p;
  539. p += 1;
  540. }
  541. --- a/pcap-filter.manmisc.in
  542. +++ b/pcap-filter.manmisc.in
  543. @@ -98,6 +98,7 @@ protocols are:
  544. .BR arp ,
  545. .BR rarp ,
  546. .BR decnet ,
  547. +.BR batadv ,
  548. .BR sctp ,
  549. .B tcp
  550. and
  551. @@ -400,7 +401,7 @@ True if the packet is an IPv6 multicast
  552. .IP "\fBether proto \fIprotocol\fR"
  553. True if the packet is of ether type \fIprotocol\fR.
  554. \fIProtocol\fP can be a number or one of the names
  555. -\fBaarp\fP, \fBarp\fP, \fBatalk\fP, \fBdecnet\fP, \fBip\fP, \fBip6\fP,
  556. +\fBaarp\fP, \fBarp\fP, \fBatalk\fP, \fBbatadv\fP, \fBdecnet\fP, \fBip\fP, \fBip6\fP,
  557. \fBipx\fP, \fBiso\fP, \fBlat\fP, \fBloopback\fP, \fBmopdl\fP, \fBmoprc\fP, \fBnetbeui\fP,
  558. \fBrarp\fP, \fBsca\fP or \fBstp\fP.
  559. Note these identifiers (except \fBloopback\fP) are also keywords
  560. @@ -454,7 +455,7 @@ the filter checks for the IPX etype in a
  561. DSAP in the LLC header, the 802.3-with-no-LLC-header encapsulation of
  562. IPX, and the IPX etype in a SNAP frame.
  563. .RE
  564. -.IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fBnetbeui\fP"
  565. +.IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fBnetbeui\fP, \fBbatadv\fP"
  566. Abbreviations for:
  567. .in +.5i
  568. .nf
  569. @@ -792,6 +793,36 @@ For example:
  570. filters IPv4 protocol encapsulated in Geneve with VNI 0xb. This will
  571. match both IPv4 directly encapsulated in Geneve as well as IPv4 contained
  572. inside an Ethernet frame.
  573. +.IP "\fBbatadv \fI[version] \fI[type]\fR"
  574. +True if the packet is a B.A.T.M.A.N. Advanced packet (Ethernet type 0x4305).
  575. +If the optional \fIversion\fR is specified, only true if the packet has the
  576. +specified batman-adv compatibility \fIversion\fR. If the optional \fIversion\fR
  577. +and \fItype\fR are specified, only true if the packet has both the specified
  578. +batman-adv compatibility \fIversion\fR and batman-adv packet \fItype\fR.
  579. +.IP
  580. +\fIversion\fR may be a number from 0 to 255, though only compatibility version
  581. +14 and 15 were actually deployed in the wild. Version 15 is the current version,
  582. +14 is considered deprecated.
  583. +.IP
  584. +\fItype\fR is currently only defined for compatibility \fIversion\fR 14 and 15.
  585. +\fItype\fR may be a number from 0 to 255 for compatibility \fIversion\fR 14 and 15.
  586. +.IP
  587. +The following packet \fItype\fR aliases are available for compat \fIversion\fR 14:
  588. +\fBiv_ogm\fP, \fBicmp\fP, \fBunicast\fP, \fBbcast\fP, \fBvis\fP, \fBunicast-frag\fP,
  589. +\fBtt_query\fP, \fBroam_adv\fP, \fBunicast_4addr\fP, \fPcoded\fP.
  590. +.IP
  591. +The following packet \fItype\fR aliases are available for compat \fIversion\fR 15:
  592. +\fBiv_ogm\fP, \fBbcast\fP, \fBcoded\fP, \fBelp\fP, \fBogm2\fP, \fBunicast\fP,
  593. +\fBunicast_frag\fP, \fBunicast_4addr\fP, \fBicmp\fP, \fPunicast_tvlv\fP.
  594. +.IP
  595. +Note that when the \fBbatadv\fR keyword is encountered in an expression and
  596. +a batman-adv packet \fItype\fR is provided which specifies an encapsulating
  597. +packet type then it changes the decoding offsets for the remainder of the
  598. +expression on the assumption that the packet is a batman-adv packet. For compat
  599. +\fIversion\fR 14 these are packet \fItype\fRs \fBunicast\fP, \fBbcast\fP,
  600. +\fBunicast_frag\fP, \fBunicast_4addr\fP and \fBcoded\fP. For compat \fIversion\fR
  601. +15 these are currently packet \fItype\fRs \fBbcast\fP, \fBcoded\fP, \fBunicast\fP,
  602. +\fBunicast_frag\fP and \fBunicast_4addr\fP.
  603. .IP "\fBiso proto \fIprotocol\fR"
  604. True if the packet is an OSI packet of protocol type \fIprotocol\fP.
  605. \fIProtocol\fP can be a number or one of the names
  606. --- a/pcap/namedb.h
  607. +++ b/pcap/namedb.h
  608. @@ -70,6 +70,8 @@ PCAP_API int pcap_nametoportrange(const
  609. PCAP_API int pcap_nametoproto(const char *);
  610. PCAP_API int pcap_nametoeproto(const char *);
  611. PCAP_API int pcap_nametollc(const char *);
  612. +PCAP_API int pcap_nametobatadvtype_v14(const char *);
  613. +PCAP_API int pcap_nametobatadvtype_v15(const char *);
  614. /*
  615. * If a protocol is unknown, PROTO_UNDEF is returned.
  616. * Also, pcap_nametoport() returns the protocol along with the port number.
  617. --- a/scanner.l
  618. +++ b/scanner.l
  619. @@ -347,6 +347,7 @@ mpls return MPLS;
  620. pppoed return PPPOED;
  621. pppoes return PPPOES;
  622. geneve return GENEVE;
  623. +batadv return BATADV;
  624. lane return LANE;
  625. llc return LLC;