]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - net/batman-adv/originator.c
batman-adv: Consolidate logging related functions
[mirror_ubuntu-zesty-kernel.git] / net / batman-adv / originator.c
index 7f51bc2c06eb7699492c41f2fe46fe85b26147a2..8ad17ad477e41d765c4dc2bb555309d2bcb9ecf7 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
 
+#include "bat_algo.h"
 #include "distributed-arp-table.h"
 #include "fragmentation.h"
 #include "gateway_client.h"
 #include "hard-interface.h"
 #include "hash.h"
+#include "log.h"
 #include "multicast.h"
 #include "network-coding.h"
 #include "routing.h"
@@ -251,10 +253,8 @@ static void batadv_neigh_node_release(struct kref *ref)
        struct hlist_node *node_tmp;
        struct batadv_neigh_node *neigh_node;
        struct batadv_neigh_ifinfo *neigh_ifinfo;
-       struct batadv_algo_ops *bao;
 
        neigh_node = container_of(ref, struct batadv_neigh_node, refcount);
-       bao = neigh_node->orig_node->bat_priv->bat_algo_ops;
 
        hlist_for_each_entry_safe(neigh_ifinfo, node_tmp,
                                  &neigh_node->ifinfo_list, list) {
@@ -263,9 +263,6 @@ static void batadv_neigh_node_release(struct kref *ref)
 
        batadv_hardif_neigh_put(neigh_node->hardif_neigh);
 
-       if (bao->bat_neigh_free)
-               bao->bat_neigh_free(neigh_node);
-
        batadv_hardif_put(neigh_node->if_incoming);
 
        kfree_rcu(neigh_node, rcu);
@@ -602,19 +599,19 @@ batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
 }
 
 /**
- * batadv_neigh_node_new - create and init a new neigh_node object
+ * batadv_neigh_node_create - create a neigh node object
  * @orig_node: originator object representing the neighbour
  * @hard_iface: the interface where the neighbour is connected to
  * @neigh_addr: the mac address of the neighbour interface
  *
  * Allocates a new neigh_node object and initialises all the generic fields.
  *
- * Return: neighbor when found. Othwerwise NULL
+ * Return: the neighbour node if found or created or NULL otherwise.
  */
-struct batadv_neigh_node *
-batadv_neigh_node_new(struct batadv_orig_node *orig_node,
-                     struct batadv_hard_iface *hard_iface,
-                     const u8 *neigh_addr)
+static struct batadv_neigh_node *
+batadv_neigh_node_create(struct batadv_orig_node *orig_node,
+                        struct batadv_hard_iface *hard_iface,
+                        const u8 *neigh_addr)
 {
        struct batadv_neigh_node *neigh_node;
        struct batadv_hardif_neigh_node *hardif_neigh = NULL;
@@ -666,6 +663,29 @@ out:
        return neigh_node;
 }
 
+/**
+ * batadv_neigh_node_get_or_create - retrieve or create a neigh node object
+ * @orig_node: originator object representing the neighbour
+ * @hard_iface: the interface where the neighbour is connected to
+ * @neigh_addr: the mac address of the neighbour interface
+ *
+ * Return: the neighbour node if found or created or NULL otherwise.
+ */
+struct batadv_neigh_node *
+batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
+                               struct batadv_hard_iface *hard_iface,
+                               const u8 *neigh_addr)
+{
+       struct batadv_neigh_node *neigh_node = NULL;
+
+       /* first check without locking to avoid the overhead */
+       neigh_node = batadv_neigh_node_get(orig_node, hard_iface, neigh_addr);
+       if (neigh_node)
+               return neigh_node;
+
+       return batadv_neigh_node_create(orig_node, hard_iface, neigh_addr);
+}
+
 /**
  * batadv_hardif_neigh_seq_print_text - print the single hop neighbour list
  * @seq: neighbour table seq_file struct