These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / net / batman-adv / main.c
index 12fc77b..d7f17c1 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors:
+/* Copyright (C) 2007-2015 B.A.T.M.A.N. contributors:
  *
  * Marek Lindner, Simon Wunderlich
  *
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "main.h"
+
+#include <linux/atomic.h>
+#include <linux/bug.h>
+#include <linux/byteorder/generic.h>
 #include <linux/crc32c.h>
-#include <linux/highmem.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/if_ether.h>
 #include <linux/if_vlan.h>
-#include <net/ip.h>
-#include <net/ipv6.h>
+#include <linux/init.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/lockdep.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/pkt_sched.h>
+#include <linux/rculist.h>
+#include <linux/rcupdate.h>
+#include <linux/seq_file.h>
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/stddef.h>
+#include <linux/string.h>
+#include <linux/workqueue.h>
 #include <net/dsfield.h>
-#include "main.h"
-#include "sysfs.h"
+#include <net/rtnetlink.h>
+
+#include "bat_algo.h"
+#include "bridge_loop_avoidance.h"
 #include "debugfs.h"
+#include "distributed-arp-table.h"
+#include "gateway_client.h"
+#include "gateway_common.h"
+#include "hard-interface.h"
+#include "icmp_socket.h"
+#include "multicast.h"
+#include "network-coding.h"
+#include "originator.h"
+#include "packet.h"
 #include "routing.h"
 #include "send.h"
-#include "originator.h"
 #include "soft-interface.h"
-#include "icmp_socket.h"
 #include "translation-table.h"
-#include "hard-interface.h"
-#include "gateway_client.h"
-#include "bridge_loop_avoidance.h"
-#include "distributed-arp-table.h"
-#include "multicast.h"
-#include "gateway_common.h"
-#include "hash.h"
-#include "bat_algo.h"
-#include "network-coding.h"
-#include "fragmentation.h"
 
 /* List manipulations on hardif_list have to be rtnl_lock()'ed,
  * list traversals just rcu-locked
@@ -126,7 +149,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
        INIT_HLIST_HEAD(&bat_priv->mcast.want_all_ipv6_list);
 #endif
        INIT_LIST_HEAD(&bat_priv->tt.changes_list);
-       INIT_LIST_HEAD(&bat_priv->tt.req_list);
+       INIT_HLIST_HEAD(&bat_priv->tt.req_list);
        INIT_LIST_HEAD(&bat_priv->tt.roam_list);
 #ifdef CONFIG_BATMAN_ADV_MCAST
        INIT_HLIST_HEAD(&bat_priv->mcast.mla_list);
@@ -176,7 +199,7 @@ void batadv_mesh_free(struct net_device *soft_iface)
 
        batadv_purge_outstanding_packets(bat_priv, NULL);
 
-       batadv_gw_node_purge(bat_priv);
+       batadv_gw_node_free(bat_priv);
        batadv_nc_mesh_free(bat_priv);
        batadv_dat_free(bat_priv);
        batadv_bla_free(bat_priv);
@@ -209,10 +232,13 @@ void batadv_mesh_free(struct net_device *soft_iface)
  * interfaces in the current mesh
  * @bat_priv: the bat priv with all the soft interface information
  * @addr: the address to check
+ *
+ * Returns 'true' if the mac address was found, false otherwise.
  */
-int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr)
+bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr)
 {
        const struct batadv_hard_iface *hard_iface;
+       bool is_my_mac = false;
 
        rcu_read_lock();
        list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
@@ -223,12 +249,12 @@ int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr)
                        continue;
 
                if (batadv_compare_eth(hard_iface->net_dev->dev_addr, addr)) {
-                       rcu_read_unlock();
-                       return 1;
+                       is_my_mac = true;
+                       break;
                }
        }
        rcu_read_unlock();
-       return 0;
+       return is_my_mac;
 }
 
 /**
@@ -362,7 +388,7 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
        struct batadv_priv *bat_priv;
        struct batadv_ogm_packet *batadv_ogm_packet;
        struct batadv_hard_iface *hard_iface;
-       uint8_t idx;
+       u8 idx;
        int ret;
 
        hard_iface = container_of(ptype, struct batadv_hard_iface,
@@ -471,7 +497,7 @@ static void batadv_recv_handler_init(void)
 }
 
 int
-batadv_recv_handler_register(uint8_t packet_type,
+batadv_recv_handler_register(u8 packet_type,
                             int (*recv_handler)(struct sk_buff *,
                                                 struct batadv_hard_iface *))
 {
@@ -487,7 +513,7 @@ batadv_recv_handler_register(uint8_t packet_type,
        return 0;
 }
 
-void batadv_recv_handler_unregister(uint8_t packet_type)
+void batadv_recv_handler_unregister(u8 packet_type)
 {
        batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
 }
@@ -510,14 +536,12 @@ static struct batadv_algo_ops *batadv_algo_get(char *name)
 int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
 {
        struct batadv_algo_ops *bat_algo_ops_tmp;
-       int ret;
 
        bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
        if (bat_algo_ops_tmp) {
                pr_info("Trying to register already registered routing algorithm: %s\n",
                        bat_algo_ops->name);
-               ret = -EEXIST;
-               goto out;
+               return -EEXIST;
        }
 
        /* all algorithms must implement all ops (for now) */
@@ -531,32 +555,26 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
            !bat_algo_ops->bat_neigh_is_equiv_or_better) {
                pr_info("Routing algo '%s' does not implement required ops\n",
                        bat_algo_ops->name);
-               ret = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
 
        INIT_HLIST_NODE(&bat_algo_ops->list);
        hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
-       ret = 0;
 
-out:
-       return ret;
+       return 0;
 }
 
 int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
 {
        struct batadv_algo_ops *bat_algo_ops;
-       int ret = -EINVAL;
 
        bat_algo_ops = batadv_algo_get(name);
        if (!bat_algo_ops)
-               goto out;
+               return -EINVAL;
 
        bat_priv->bat_algo_ops = bat_algo_ops;
-       ret = 0;
 
-out:
-       return ret;
+       return 0;
 }
 
 int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
@@ -566,7 +584,7 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
        seq_puts(seq, "Available routing algorithms:\n");
 
        hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
-               seq_printf(seq, "%s\n", bat_algo_ops->name);
+               seq_printf(seq, " * %s\n", bat_algo_ops->name);
        }
 
        return 0;
@@ -625,8 +643,7 @@ batadv_tvlv_handler_free_ref(struct batadv_tvlv_handler *tvlv_handler)
  * Returns tvlv handler if found or NULL otherwise.
  */
 static struct batadv_tvlv_handler
-*batadv_tvlv_handler_get(struct batadv_priv *bat_priv,
-                        uint8_t type, uint8_t version)
+*batadv_tvlv_handler_get(struct batadv_priv *bat_priv, u8 type, u8 version)
 {
        struct batadv_tvlv_handler *tvlv_handler_tmp, *tvlv_handler = NULL;
 
@@ -674,8 +691,7 @@ static void batadv_tvlv_container_free_ref(struct batadv_tvlv_container *tvlv)
  * Returns tvlv container if found or NULL otherwise.
  */
 static struct batadv_tvlv_container
-*batadv_tvlv_container_get(struct batadv_priv *bat_priv,
-                          uint8_t type, uint8_t version)
+*batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version)
 {
        struct batadv_tvlv_container *tvlv_tmp, *tvlv = NULL;
 
@@ -706,10 +722,10 @@ static struct batadv_tvlv_container
  *
  * Returns size of all currently registered tvlv containers in bytes.
  */
-static uint16_t batadv_tvlv_container_list_size(struct batadv_priv *bat_priv)
+static u16 batadv_tvlv_container_list_size(struct batadv_priv *bat_priv)
 {
        struct batadv_tvlv_container *tvlv;
-       uint16_t tvlv_len = 0;
+       u16 tvlv_len = 0;
 
        hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) {
                tvlv_len += sizeof(struct batadv_tvlv_hdr);
@@ -722,13 +738,17 @@ static uint16_t batadv_tvlv_container_list_size(struct batadv_priv *bat_priv)
 /**
  * batadv_tvlv_container_remove - remove tvlv container from the tvlv container
  *  list
+ * @bat_priv: the bat priv with all the soft interface information
  * @tvlv: the to be removed tvlv container
  *
  * Has to be called with the appropriate locks being acquired
  * (tvlv.container_list_lock).
  */
-static void batadv_tvlv_container_remove(struct batadv_tvlv_container *tvlv)
+static void batadv_tvlv_container_remove(struct batadv_priv *bat_priv,
+                                        struct batadv_tvlv_container *tvlv)
 {
+       lockdep_assert_held(&bat_priv->tvlv.handler_list_lock);
+
        if (!tvlv)
                return;
 
@@ -747,13 +767,13 @@ static void batadv_tvlv_container_remove(struct batadv_tvlv_container *tvlv)
  * @version: tvlv container type to unregister
  */
 void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
-                                     uint8_t type, uint8_t version)
+                                     u8 type, u8 version)
 {
        struct batadv_tvlv_container *tvlv;
 
        spin_lock_bh(&bat_priv->tvlv.container_list_lock);
        tvlv = batadv_tvlv_container_get(bat_priv, type, version);
-       batadv_tvlv_container_remove(tvlv);
+       batadv_tvlv_container_remove(bat_priv, tvlv);
        spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
 }
 
@@ -770,8 +790,8 @@ void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
  * content is going to replace the old one.
  */
 void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
-                                   uint8_t type, uint8_t version,
-                                   void *tvlv_value, uint16_t tvlv_value_len)
+                                   u8 type, u8 version,
+                                   void *tvlv_value, u16 tvlv_value_len)
 {
        struct batadv_tvlv_container *tvlv_old, *tvlv_new;
 
@@ -792,7 +812,7 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
 
        spin_lock_bh(&bat_priv->tvlv.container_list_lock);
        tvlv_old = batadv_tvlv_container_get(bat_priv, type, version);
-       batadv_tvlv_container_remove(tvlv_old);
+       batadv_tvlv_container_remove(bat_priv, tvlv_old);
        hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list);
        spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
 }
@@ -819,15 +839,15 @@ static bool batadv_tvlv_realloc_packet_buff(unsigned char **packet_buff,
        new_buff = kmalloc(min_packet_len + additional_packet_len, GFP_ATOMIC);
 
        /* keep old buffer if kmalloc should fail */
-       if (new_buff) {
-               memcpy(new_buff, *packet_buff, min_packet_len);
-               kfree(*packet_buff);
-               *packet_buff = new_buff;
-               *packet_buff_len = min_packet_len + additional_packet_len;
-               return true;
-       }
+       if (!new_buff)
+               return false;
+
+       memcpy(new_buff, *packet_buff, min_packet_len);
+       kfree(*packet_buff);
+       *packet_buff = new_buff;
+       *packet_buff_len = min_packet_len + additional_packet_len;
 
-       return false;
+       return true;
 }
 
 /**
@@ -844,14 +864,13 @@ static bool batadv_tvlv_realloc_packet_buff(unsigned char **packet_buff,
  *
  * Returns size of all appended tvlv containers in bytes.
  */
-uint16_t batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
-                                         unsigned char **packet_buff,
-                                         int *packet_buff_len,
-                                         int packet_min_len)
+u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
+                                    unsigned char **packet_buff,
+                                    int *packet_buff_len, int packet_min_len)
 {
        struct batadv_tvlv_container *tvlv;
        struct batadv_tvlv_hdr *tvlv_hdr;
-       uint16_t tvlv_value_len;
+       u16 tvlv_value_len;
        void *tvlv_value;
        bool ret;
 
@@ -876,7 +895,7 @@ uint16_t batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
                tvlv_hdr->len = tvlv->tvlv_hdr.len;
                tvlv_value = tvlv_hdr + 1;
                memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len));
-               tvlv_value = (uint8_t *)tvlv_value + ntohs(tvlv->tvlv_hdr.len);
+               tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len);
        }
 
 end:
@@ -903,8 +922,8 @@ static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv,
                                    struct batadv_tvlv_handler *tvlv_handler,
                                    bool ogm_source,
                                    struct batadv_orig_node *orig_node,
-                                   uint8_t *src, uint8_t *dst,
-                                   void *tvlv_value, uint16_t tvlv_value_len)
+                                   u8 *src, u8 *dst,
+                                   void *tvlv_value, u16 tvlv_value_len)
 {
        if (!tvlv_handler)
                return NET_RX_SUCCESS;
@@ -955,13 +974,13 @@ static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv,
 int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
                                   bool ogm_source,
                                   struct batadv_orig_node *orig_node,
-                                  uint8_t *src, uint8_t *dst,
-                                  void *tvlv_value, uint16_t tvlv_value_len)
+                                  u8 *src, u8 *dst,
+                                  void *tvlv_value, u16 tvlv_value_len)
 {
        struct batadv_tvlv_handler *tvlv_handler;
        struct batadv_tvlv_hdr *tvlv_hdr;
-       uint16_t tvlv_value_cont_len;
-       uint8_t cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;
+       u16 tvlv_value_cont_len;
+       u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;
        int ret = NET_RX_SUCCESS;
 
        while (tvlv_value_len >= sizeof(*tvlv_hdr)) {
@@ -983,7 +1002,7 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
                                                tvlv_value_cont_len);
                if (tvlv_handler)
                        batadv_tvlv_handler_free_ref(tvlv_handler);
-               tvlv_value = (uint8_t *)tvlv_value + tvlv_value_cont_len;
+               tvlv_value = (u8 *)tvlv_value + tvlv_value_cont_len;
                tvlv_value_len -= tvlv_value_cont_len;
        }
 
@@ -1017,7 +1036,7 @@ void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
                             struct batadv_orig_node *orig_node)
 {
        void *tvlv_value;
-       uint16_t tvlv_value_len;
+       u16 tvlv_value_len;
 
        if (!batadv_ogm_packet)
                return;
@@ -1049,14 +1068,14 @@ void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
 void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
                                  void (*optr)(struct batadv_priv *bat_priv,
                                               struct batadv_orig_node *orig,
-                                              uint8_t flags,
+                                              u8 flags,
                                               void *tvlv_value,
-                                              uint16_t tvlv_value_len),
+                                              u16 tvlv_value_len),
                                  int (*uptr)(struct batadv_priv *bat_priv,
-                                             uint8_t *src, uint8_t *dst,
+                                             u8 *src, u8 *dst,
                                              void *tvlv_value,
-                                             uint16_t tvlv_value_len),
-                                 uint8_t type, uint8_t version, uint8_t flags)
+                                             u16 tvlv_value_len),
+                                 u8 type, u8 version, u8 flags)
 {
        struct batadv_tvlv_handler *tvlv_handler;
 
@@ -1091,7 +1110,7 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
  * @version: tvlv handler version to be unregistered
  */
 void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv,
-                                   uint8_t type, uint8_t version)
+                                   u8 type, u8 version)
 {
        struct batadv_tvlv_handler *tvlv_handler;
 
@@ -1117,9 +1136,9 @@ void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv,
  * @tvlv_value: tvlv content
  * @tvlv_value_len: tvlv content length
  */
-void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, uint8_t *src,
-                             uint8_t *dst, uint8_t type, uint8_t version,
-                             void *tvlv_value, uint16_t tvlv_value_len)
+void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
+                             u8 *dst, u8 type, u8 version,
+                             void *tvlv_value, u16 tvlv_value_len)
 {
        struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
        struct batadv_tvlv_hdr *tvlv_hdr;