batman-adv: reorder packet types
authorSimon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>
Thu, 25 Apr 2013 08:37:23 +0000 (10:37 +0200)
committerAntonio Quartulli <antonio@meshcoding.com>
Wed, 9 Oct 2013 19:22:34 +0000 (21:22 +0200)
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>
net/batman-adv/main.c
net/batman-adv/packet.h
net/batman-adv/routing.c
net/batman-adv/routing.h

index b22368e66895b5198bc00da985c2baf32755147c..8b195e63e70e0433500e3a25fff7ace87305eb6a 100644 (file)
@@ -393,6 +393,9 @@ static void batadv_recv_handler_init(void)
        for (i = 0; i < ARRAY_SIZE(batadv_rx_handler); i++)
                batadv_rx_handler[i] = batadv_recv_unhandled_packet;
 
+       for (i = BATADV_UNICAST_MIN; i <= BATADV_UNICAST_MAX; i++)
+               batadv_rx_handler[i] = batadv_recv_unhandled_unicast_packet;
+
        /* compile time checks for struct member offsets */
        BUILD_BUG_ON(offsetof(struct batadv_unicast_4addr_packet, src) != 10);
        BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4);
@@ -401,18 +404,20 @@ static void batadv_recv_handler_init(void)
        BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, dst) != 4);
        BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, dst) != 4);
 
-       /* batman icmp packet */
-       batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
+       /* broadcast packet */
+       batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
+
+       /* unicast packets ... */
        /* unicast with 4 addresses packet */
        batadv_rx_handler[BATADV_UNICAST_4ADDR] = batadv_recv_unicast_packet;
        /* unicast packet */
        batadv_rx_handler[BATADV_UNICAST] = batadv_recv_unicast_packet;
        /* fragmented unicast packet */
        batadv_rx_handler[BATADV_UNICAST_FRAG] = batadv_recv_ucast_frag_packet;
-       /* broadcast packet */
-       batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
        /* unicast tvlv packet */
        batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv;
+       /* batman icmp packet */
+       batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
 }
 
 int
@@ -420,7 +425,12 @@ batadv_recv_handler_register(uint8_t packet_type,
                             int (*recv_handler)(struct sk_buff *,
                                                 struct batadv_hard_iface *))
 {
-       if (batadv_rx_handler[packet_type] != &batadv_recv_unhandled_packet)
+       int (*curr)(struct sk_buff *,
+                   struct batadv_hard_iface *);
+       curr = batadv_rx_handler[packet_type];
+
+       if ((curr != batadv_recv_unhandled_packet) &&
+           (curr != batadv_recv_unhandled_unicast_packet))
                return -EBUSY;
 
        batadv_rx_handler[packet_type] = recv_handler;
index 87fcf2e7883c8dbb449e2328579b8d7128271e0a..f02dbb1892dd4ee5f2d7c1d647c5784e53120602 100644 (file)
 
 /**
  * enum batadv_packettype - types for batman-adv encapsulated packets
+ * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
+ * @BATADV_BCAST: broadcast packets carrying broadcast payload
+ * @BATADV_CODED: network coded packets
+ *
+ * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
+ * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
+ *     payload packet
+ * @BATADV_UNICAST_4ADDR: unicast packet including the originator address of
+ *     the sender
+ * @BATADV_ICMP: unicast packet like IP ICMP used for ping or traceroute
  * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers
  */
 enum batadv_packettype {
-       BATADV_IV_OGM           = 0x01,
-       BATADV_ICMP             = 0x02,
-       BATADV_UNICAST          = 0x03,
-       BATADV_BCAST            = 0x04,
-       BATADV_UNICAST_FRAG     = 0x06,
-       BATADV_UNICAST_4ADDR    = 0x09,
-       BATADV_CODED            = 0x0a,
-       BATADV_UNICAST_TVLV     = 0x0b,
+       /* 0x00 - 0x3f: local packets or special rules for handling */
+       BATADV_IV_OGM           = 0x00,
+       BATADV_BCAST            = 0x01,
+       BATADV_CODED            = 0x02,
+       /* 0x40 - 0x7f: unicast */
+#define BATADV_UNICAST_MIN     0x40
+       BATADV_UNICAST          = 0x40,
+       BATADV_UNICAST_FRAG     = 0x41,
+       BATADV_UNICAST_4ADDR    = 0x42,
+       BATADV_ICMP             = 0x43,
+       BATADV_UNICAST_TVLV     = 0x44,
+#define BATADV_UNICAST_MAX     0x7f
+       /* 0x80 - 0xff: reserved */
 };
 
 /**
index 2a9318bd9026eab4eac36bed008ae74645aaa6ec..457dfef9c5fcac4d7fc92d74e22c77054579c8bc 100644 (file)
@@ -911,6 +911,34 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
        return 1;
 }
 
+/**
+ * batadv_recv_unhandled_unicast_packet - receive and process packets which
+ *     are in the unicast number space but not yet known to the implementation
+ * @skb: unicast tvlv packet to process
+ * @recv_if: pointer to interface this packet was received on
+ *
+ * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
+ * otherwise.
+ */
+int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
+                                        struct batadv_hard_iface *recv_if)
+{
+       struct batadv_unicast_packet *unicast_packet;
+       struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
+       int check, hdr_size = sizeof(*unicast_packet);
+
+       check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
+       if (check < 0)
+               return NET_RX_DROP;
+
+       /* we don't know about this type, drop it. */
+       unicast_packet = (struct batadv_unicast_packet *)skb->data;
+       if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
+               return NET_RX_DROP;
+
+       return batadv_route_unicast_packet(skb, recv_if);
+}
+
 int batadv_recv_unicast_packet(struct sk_buff *skb,
                               struct batadv_hard_iface *recv_if)
 {
index b3f53d492b3c7dc1bc67397f7a9030413b5e8cc3..ea15fa6302ad9baccdd459f3400bec9a2629ecae 100644 (file)
@@ -40,6 +40,8 @@ int batadv_recv_roam_adv(struct sk_buff *skb,
                         struct batadv_hard_iface *recv_if);
 int batadv_recv_unicast_tvlv(struct sk_buff *skb,
                             struct batadv_hard_iface *recv_if);
+int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
+                                        struct batadv_hard_iface *recv_if);
 struct batadv_neigh_node *
 batadv_find_router(struct batadv_priv *bat_priv,
                   struct batadv_orig_node *orig_node,