Commit a1f1ac5c4d045a1adc6662346733a6db3aee5a9d

Authored by Simon Wunderlich
Committed by Antonio Quartulli
1 parent 80067c8320

batman-adv: reorder packet types

Reordering the packet type numbers allows us to handle unicast
packets in a general way - even if we don't know the specific packet
type, we can still forward it. There was already code handling
this for a couple of unicast packets, and this is the more
generalized version to do that.

Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>

Showing 4 changed files with 68 additions and 13 deletions Side-by-side Diff

net/batman-adv/main.c
... ... @@ -393,6 +393,9 @@
393 393 for (i = 0; i < ARRAY_SIZE(batadv_rx_handler); i++)
394 394 batadv_rx_handler[i] = batadv_recv_unhandled_packet;
395 395  
  396 + for (i = BATADV_UNICAST_MIN; i <= BATADV_UNICAST_MAX; i++)
  397 + batadv_rx_handler[i] = batadv_recv_unhandled_unicast_packet;
  398 +
396 399 /* compile time checks for struct member offsets */
397 400 BUILD_BUG_ON(offsetof(struct batadv_unicast_4addr_packet, src) != 10);
398 401 BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4);
399 402  
400 403  
... ... @@ -401,18 +404,20 @@
401 404 BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, dst) != 4);
402 405 BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, dst) != 4);
403 406  
404   - /* batman icmp packet */
405   - batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
  407 + /* broadcast packet */
  408 + batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
  409 +
  410 + /* unicast packets ... */
406 411 /* unicast with 4 addresses packet */
407 412 batadv_rx_handler[BATADV_UNICAST_4ADDR] = batadv_recv_unicast_packet;
408 413 /* unicast packet */
409 414 batadv_rx_handler[BATADV_UNICAST] = batadv_recv_unicast_packet;
410 415 /* fragmented unicast packet */
411 416 batadv_rx_handler[BATADV_UNICAST_FRAG] = batadv_recv_ucast_frag_packet;
412   - /* broadcast packet */
413   - batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
414 417 /* unicast tvlv packet */
415 418 batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv;
  419 + /* batman icmp packet */
  420 + batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
416 421 }
417 422  
418 423 int
... ... @@ -420,7 +425,12 @@
420 425 int (*recv_handler)(struct sk_buff *,
421 426 struct batadv_hard_iface *))
422 427 {
423   - if (batadv_rx_handler[packet_type] != &batadv_recv_unhandled_packet)
  428 + int (*curr)(struct sk_buff *,
  429 + struct batadv_hard_iface *);
  430 + curr = batadv_rx_handler[packet_type];
  431 +
  432 + if ((curr != batadv_recv_unhandled_packet) &&
  433 + (curr != batadv_recv_unhandled_unicast_packet))
424 434 return -EBUSY;
425 435  
426 436 batadv_rx_handler[packet_type] = recv_handler;
net/batman-adv/packet.h
... ... @@ -22,17 +22,32 @@
22 22  
23 23 /**
24 24 * enum batadv_packettype - types for batman-adv encapsulated packets
  25 + * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
  26 + * @BATADV_BCAST: broadcast packets carrying broadcast payload
  27 + * @BATADV_CODED: network coded packets
  28 + *
  29 + * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
  30 + * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
  31 + * payload packet
  32 + * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
  33 + * the sender
  34 + * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
25 35 * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
26 36 */
27 37 enum batadv_packettype {
28   - BATADV_IV_OGM = 0x01,
29   - BATADV_ICMP = 0x02,
30   - BATADV_UNICAST = 0x03,
31   - BATADV_BCAST = 0x04,
32   - BATADV_UNICAST_FRAG = 0x06,
33   - BATADV_UNICAST_4ADDR = 0x09,
34   - BATADV_CODED = 0x0a,
35   - BATADV_UNICAST_TVLV = 0x0b,
  38 + /* 0x00 - 0x3f: local packets or special rules for handling */
  39 + BATADV_IV_OGM = 0x00,
  40 + BATADV_BCAST = 0x01,
  41 + BATADV_CODED = 0x02,
  42 + /* 0x40 - 0x7f: unicast */
  43 +#define BATADV_UNICAST_MIN 0x40
  44 + BATADV_UNICAST = 0x40,
  45 + BATADV_UNICAST_FRAG = 0x41,
  46 + BATADV_UNICAST_4ADDR = 0x42,
  47 + BATADV_ICMP = 0x43,
  48 + BATADV_UNICAST_TVLV = 0x44,
  49 +#define BATADV_UNICAST_MAX 0x7f
  50 + /* 0x80 - 0xff: reserved */
36 51 };
37 52  
38 53 /**
net/batman-adv/routing.c
... ... @@ -911,6 +911,34 @@
911 911 return 1;
912 912 }
913 913  
  914 +/**
  915 + * batadv_recv_unhandled_unicast_packet - receive and process packets which
  916 + * are in the unicast number space but not yet known to the implementation
  917 + * @skb: unicast tvlv packet to process
  918 + * @recv_if: pointer to interface this packet was received on
  919 + *
  920 + * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
  921 + * otherwise.
  922 + */
  923 +int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
  924 + struct batadv_hard_iface *recv_if)
  925 +{
  926 + struct batadv_unicast_packet *unicast_packet;
  927 + struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  928 + int check, hdr_size = sizeof(*unicast_packet);
  929 +
  930 + check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
  931 + if (check < 0)
  932 + return NET_RX_DROP;
  933 +
  934 + /* we don't know about this type, drop it. */
  935 + unicast_packet = (struct batadv_unicast_packet *)skb->data;
  936 + if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
  937 + return NET_RX_DROP;
  938 +
  939 + return batadv_route_unicast_packet(skb, recv_if);
  940 +}
  941 +
914 942 int batadv_recv_unicast_packet(struct sk_buff *skb,
915 943 struct batadv_hard_iface *recv_if)
916 944 {
net/batman-adv/routing.h
... ... @@ -40,6 +40,8 @@
40 40 struct batadv_hard_iface *recv_if);
41 41 int batadv_recv_unicast_tvlv(struct sk_buff *skb,
42 42 struct batadv_hard_iface *recv_if);
  43 +int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
  44 + struct batadv_hard_iface *recv_if);
43 45 struct batadv_neigh_node *
44 46 batadv_find_router(struct batadv_priv *bat_priv,
45 47 struct batadv_orig_node *orig_node,