batman-adv: split hard_iface struct for each routing protocol
authorMarek Lindner <lindner_marek@yahoo.de>
Thu, 2 Aug 2012 15:20:26 +0000 (17:20 +0200)
committerAntonio Quartulli <ordex@autistici.org>
Mon, 29 Oct 2012 08:39:05 +0000 (09:39 +0100)
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
net/batman-adv/bat_iv_ogm.c
net/batman-adv/hard-interface.c
net/batman-adv/types.h

index b02b75dae3a8a5dfeb015838ba5eca2ecb5d6109..75403a49189265c211bf08fed1120ab7dede5827 100644 (file)
@@ -57,20 +57,22 @@ out:
 static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
 {
        struct batadv_ogm_packet *batadv_ogm_packet;
+       unsigned char *ogm_buff;
        uint32_t random_seqno;
        int res = -ENOMEM;
 
        /* randomize initial seqno to avoid collision */
        get_random_bytes(&random_seqno, sizeof(random_seqno));
-       atomic_set(&hard_iface->seqno, random_seqno);
+       atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
 
-       hard_iface->packet_len = BATADV_OGM_HLEN;
-       hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
-
-       if (!hard_iface->packet_buff)
+       hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
+       ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
+       if (!ogm_buff)
                goto out;
 
-       batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
+       hard_iface->bat_iv.ogm_buff = ogm_buff;
+
+       batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
        batadv_ogm_packet->header.packet_type = BATADV_IV_OGM;
        batadv_ogm_packet->header.version = BATADV_COMPAT_VERSION;
        batadv_ogm_packet->header.ttl = 2;
@@ -87,15 +89,16 @@ out:
 
 static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
 {
-       kfree(hard_iface->packet_buff);
-       hard_iface->packet_buff = NULL;
+       kfree(hard_iface->bat_iv.ogm_buff);
+       hard_iface->bat_iv.ogm_buff = NULL;
 }
 
 static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
 {
        struct batadv_ogm_packet *batadv_ogm_packet;
+       unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff;
 
-       batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
+       batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
        memcpy(batadv_ogm_packet->orig,
               hard_iface->net_dev->dev_addr, ETH_ALEN);
        memcpy(batadv_ogm_packet->prev_sender,
@@ -106,8 +109,9 @@ static void
 batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
 {
        struct batadv_ogm_packet *batadv_ogm_packet;
+       unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff;
 
-       batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
+       batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
        batadv_ogm_packet->flags = BATADV_PRIMARIES_FIRST_HOP;
        batadv_ogm_packet->header.ttl = BATADV_TTL;
 }
@@ -590,8 +594,10 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
 static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
 {
        struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
+       unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff;
        struct batadv_ogm_packet *batadv_ogm_packet;
        struct batadv_hard_iface *primary_if;
+       int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
        int vis_server, tt_num_changes = 0;
        uint32_t seqno;
        uint8_t bandwidth;
@@ -600,17 +606,16 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
        primary_if = batadv_primary_if_get_selected(bat_priv);
 
        if (hard_iface == primary_if)
-               tt_num_changes = batadv_tt_append_diff(bat_priv,
-                                                      &hard_iface->packet_buff,
-                                                      &hard_iface->packet_len,
+               tt_num_changes = batadv_tt_append_diff(bat_priv, ogm_buff,
+                                                      ogm_buff_len,
                                                       BATADV_OGM_HLEN);
 
-       batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
+       batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
 
        /* change sequence number to network order */
-       seqno = (uint32_t)atomic_read(&hard_iface->seqno);
+       seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
        batadv_ogm_packet->seqno = htonl(seqno);
-       atomic_inc(&hard_iface->seqno);
+       atomic_inc(&hard_iface->bat_iv.ogm_seqno);
 
        batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
        batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
@@ -631,8 +636,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
        }
 
        batadv_slide_own_bcast_window(hard_iface);
-       batadv_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
-                               hard_iface->packet_len, hard_iface, 1,
+       batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
+                               hard_iface->bat_iv.ogm_buff_len, hard_iface, 1,
                                batadv_iv_ogm_emit_send_time(bat_priv));
 
        if (primary_if)
@@ -1015,7 +1020,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
                return;
 
        /* could be changed by schedule_own_packet() */
-       if_incoming_seqno = atomic_read(&if_incoming->seqno);
+       if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
 
        if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
                has_directlink_flag = 1;
index d112fd6750b0564e1b08232482eb8c1261b749ad..fab9e4158dc2f6b63e89574dd16da5dd81bcd8c2 100644 (file)
@@ -450,8 +450,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
        /* This can't be called via a bat_priv callback because
         * we have no bat_priv yet.
         */
-       atomic_set(&hard_iface->seqno, 1);
-       hard_iface->packet_buff = NULL;
+       atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
+       hard_iface->bat_iv.ogm_buff = NULL;
 
        return hard_iface;
 
index ac1e07a8045475ed9ce367d39440940f29ab0852..faaebd6c81408217a38c6c4cf660551374ca0c8a 100644 (file)
        (ETH_HLEN + max(sizeof(struct batadv_unicast_packet), \
                        sizeof(struct batadv_bcast_packet)))
 
+/**
+ * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
+ * @ogm_buff: buffer holding the OGM packet
+ * @ogm_buff_len: length of the OGM packet buffer
+ * @ogm_seqno: OGM sequence number - used to identify each OGM
+ */
+struct batadv_hard_iface_bat_iv {
+       unsigned char *ogm_buff;
+       int ogm_buff_len;
+       atomic_t ogm_seqno;
+};
+
 struct batadv_hard_iface {
        struct list_head list;
        int16_t if_num;
        char if_status;
        struct net_device *net_dev;
-       atomic_t seqno;
        atomic_t frag_seqno;
-       unsigned char *packet_buff;
-       int packet_len;
        struct kobject *hardif_obj;
        atomic_t refcount;
        struct packet_type batman_adv_ptype;
        struct net_device *soft_iface;
        struct rcu_head rcu;
+       struct batadv_hard_iface_bat_iv bat_iv;
 };
 
 /**