Lines Matching +full:interface +full:- +full:node

1 // SPDX-License-Identifier: GPL-2.0
32 #include "distributed-arp-table.h"
35 #include "hard-interface.h"
41 #include "translation-table.h"
47 * batadv_orig_hash_find() - Find and return originator from orig_hash
48 * @bat_priv: the bat priv with all the mesh interface information
56 struct batadv_hashtable *hash = bat_priv->orig_hash;
64 index = batadv_choose_orig(data, hash->size);
65 head = &hash->table[index];
72 if (!kref_get_unless_zero(&orig_node->refcount))
86 * batadv_compare_orig() - comparing function used in the originator hash table
87 * @node: node in the local table
88 * @data2: second object to compare the node to
92 bool batadv_compare_orig(const struct hlist_node *node, const void *data2)
94 const void *data1 = container_of(node, struct batadv_orig_node,
101 * batadv_orig_node_vlan_get() - get an orig_node_vlan object
115 hlist_for_each_entry_rcu(tmp, &orig_node->vlan_list, list) {
116 if (tmp->vid != vid)
119 if (!kref_get_unless_zero(&tmp->refcount))
132 * batadv_vlan_id_valid() - check if vlan id is in valid batman-adv encoding
155 * batadv_orig_node_vlan_new() - search and possibly create an orig_node_vlan
175 spin_lock_bh(&orig_node->vlan_list_lock);
186 kref_init(&vlan->refcount);
187 vlan->vid = vid;
189 kref_get(&vlan->refcount);
190 hlist_add_head_rcu(&vlan->list, &orig_node->vlan_list);
193 spin_unlock_bh(&orig_node->vlan_list_lock);
199 * batadv_orig_node_vlan_release() - release originator-vlan object from lists
201 * @ref: kref pointer of the originator-vlan object
213 * batadv_originator_init() - Initialize all originator structures
214 * @bat_priv: the bat priv with all the mesh interface information
220 if (bat_priv->orig_hash)
223 bat_priv->orig_hash = batadv_hash_new(1024);
225 if (!bat_priv->orig_hash)
228 batadv_hash_set_lock_class(bat_priv->orig_hash,
231 INIT_DELAYED_WORK(&bat_priv->orig_work, batadv_purge_orig);
233 &bat_priv->orig_work,
239 return -ENOMEM;
243 * batadv_neigh_ifinfo_release() - release neigh_ifinfo from lists and queue for
253 if (neigh_ifinfo->if_outgoing != BATADV_IF_DEFAULT)
254 batadv_hardif_put(neigh_ifinfo->if_outgoing);
260 * batadv_hardif_neigh_release() - release hardif neigh node from lists and
271 spin_lock_bh(&hardif_neigh->if_incoming->neigh_list_lock);
272 hlist_del_init_rcu(&hardif_neigh->list);
273 spin_unlock_bh(&hardif_neigh->if_incoming->neigh_list_lock);
275 batadv_hardif_put(hardif_neigh->if_incoming);
280 * batadv_neigh_node_release() - release neigh_node from lists and queue for
293 &neigh_node->ifinfo_list, list) {
297 batadv_hardif_neigh_put(neigh_node->hardif_neigh);
299 batadv_hardif_put(neigh_node->if_incoming);
305 * batadv_orig_router_get() - router to the originator depending on iface
306 * @orig_node: the orig node for the router
307 * @if_outgoing: the interface where the payload packet has been received or
322 hlist_for_each_entry_rcu(orig_ifinfo, &orig_node->ifinfo_list, list) {
323 if (orig_ifinfo->if_outgoing != if_outgoing)
326 router = rcu_dereference(orig_ifinfo->router);
330 if (router && !kref_get_unless_zero(&router->refcount))
338 * batadv_orig_to_router() - get next hop neighbor to an orig address
339 * @bat_priv: the bat priv with all the mesh interface information
341 * @if_outgoing: the interface where the payload packet has been received or
344 * Return: A neighbor node which is the best router towards the given originator
365 * batadv_orig_ifinfo_get() - find the ifinfo from an orig_node
366 * @orig_node: the orig node to be queried
367 * @if_outgoing: the interface for which the ifinfo should be acquired
380 hlist_for_each_entry_rcu(tmp, &orig_node->ifinfo_list,
382 if (tmp->if_outgoing != if_outgoing)
385 if (!kref_get_unless_zero(&tmp->refcount))
397 * batadv_orig_ifinfo_new() - search and possibly create an orig_ifinfo object
398 * @orig_node: the orig node to be queried
399 * @if_outgoing: the interface for which the ifinfo should be acquired
402 * interface otherwise. The object is created and added to the list
414 spin_lock_bh(&orig_node->neigh_list_lock);
425 kref_get(&if_outgoing->refcount);
427 reset_time = jiffies - 1;
428 reset_time -= msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
429 orig_ifinfo->batman_seqno_reset = reset_time;
430 orig_ifinfo->if_outgoing = if_outgoing;
431 INIT_HLIST_NODE(&orig_ifinfo->list);
432 kref_init(&orig_ifinfo->refcount);
434 kref_get(&orig_ifinfo->refcount);
435 hlist_add_head_rcu(&orig_ifinfo->list,
436 &orig_node->ifinfo_list);
438 spin_unlock_bh(&orig_node->neigh_list_lock);
443 * batadv_neigh_ifinfo_get() - find the ifinfo from an neigh_node
444 * @neigh: the neigh node to be queried
445 * @if_outgoing: the interface for which the ifinfo should be acquired
459 hlist_for_each_entry_rcu(tmp_neigh_ifinfo, &neigh->ifinfo_list,
461 if (tmp_neigh_ifinfo->if_outgoing != if_outgoing)
464 if (!kref_get_unless_zero(&tmp_neigh_ifinfo->refcount))
476 * batadv_neigh_ifinfo_new() - search and possibly create an neigh_ifinfo object
477 * @neigh: the neigh node to be queried
478 * @if_outgoing: the interface for which the ifinfo should be acquired
481 * if_outgoing interface otherwise. The object is created and added to the list
492 spin_lock_bh(&neigh->ifinfo_lock);
503 kref_get(&if_outgoing->refcount);
505 INIT_HLIST_NODE(&neigh_ifinfo->list);
506 kref_init(&neigh_ifinfo->refcount);
507 neigh_ifinfo->if_outgoing = if_outgoing;
509 kref_get(&neigh_ifinfo->refcount);
510 hlist_add_head_rcu(&neigh_ifinfo->list, &neigh->ifinfo_list);
513 spin_unlock_bh(&neigh->ifinfo_lock);
519 * batadv_neigh_node_get() - retrieve a neighbour from the list
521 * @hard_iface: the interface where this neighbour is connected to
525 * which is connected through the provided hard interface.
537 hlist_for_each_entry_rcu(tmp_neigh_node, &orig_node->neigh_list, list) {
538 if (!batadv_compare_eth(tmp_neigh_node->addr, addr))
541 if (tmp_neigh_node->if_incoming != hard_iface)
544 if (!kref_get_unless_zero(&tmp_neigh_node->refcount))
556 * batadv_hardif_neigh_create() - create a hardif neighbour node
557 * @hard_iface: the interface this neighbour is connected to
558 * @neigh_addr: the interface address of the neighbour to retrieve
561 * Return: the hardif neighbour node if found or created or NULL otherwise.
568 struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
571 spin_lock_bh(&hard_iface->neigh_list_lock);
582 kref_get(&hard_iface->refcount);
583 INIT_HLIST_NODE(&hardif_neigh->list);
584 ether_addr_copy(hardif_neigh->addr, neigh_addr);
585 ether_addr_copy(hardif_neigh->orig, orig_node->orig);
586 hardif_neigh->if_incoming = hard_iface;
587 hardif_neigh->last_seen = jiffies;
589 kref_init(&hardif_neigh->refcount);
591 if (bat_priv->algo_ops->neigh.hardif_init)
592 bat_priv->algo_ops->neigh.hardif_init(hardif_neigh);
594 hlist_add_head_rcu(&hardif_neigh->list, &hard_iface->neigh_list);
597 spin_unlock_bh(&hard_iface->neigh_list_lock);
602 * batadv_hardif_neigh_get_or_create() - retrieve or create a hardif neighbour
603 * node
604 * @hard_iface: the interface this neighbour is connected to
605 * @neigh_addr: the interface address of the neighbour to retrieve
608 * Return: the hardif neighbour node if found or created or NULL otherwise.
626 * batadv_hardif_neigh_get() - retrieve a hardif neighbour from the list
627 * @hard_iface: the interface where this neighbour is connected to
630 * Looks for and possibly returns a neighbour belonging to this hard interface.
642 &hard_iface->neigh_list, list) {
643 if (!batadv_compare_eth(tmp_hardif_neigh->addr, neigh_addr))
646 if (!kref_get_unless_zero(&tmp_hardif_neigh->refcount))
658 * batadv_neigh_node_create() - create a neigh node object
660 * @hard_iface: the interface where the neighbour is connected to
661 * @neigh_addr: the mac address of the neighbour interface
665 * Return: the neighbour node if found or created or NULL otherwise.
675 spin_lock_bh(&orig_node->neigh_list_lock);
690 INIT_HLIST_NODE(&neigh_node->list);
691 INIT_HLIST_HEAD(&neigh_node->ifinfo_list);
692 spin_lock_init(&neigh_node->ifinfo_lock);
694 kref_get(&hard_iface->refcount);
695 ether_addr_copy(neigh_node->addr, neigh_addr);
696 neigh_node->if_incoming = hard_iface;
697 neigh_node->orig_node = orig_node;
698 neigh_node->last_seen = jiffies;
701 kref_get(&hardif_neigh->refcount);
702 neigh_node->hardif_neigh = hardif_neigh;
705 kref_init(&neigh_node->refcount);
707 kref_get(&neigh_node->refcount);
708 hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list);
710 batadv_dbg(BATADV_DBG_BATMAN, orig_node->bat_priv,
711 "Creating new neighbor %pM for orig_node %pM on interface %s\n",
712 neigh_addr, orig_node->orig, hard_iface->net_dev->name);
715 spin_unlock_bh(&orig_node->neigh_list_lock);
722 * batadv_neigh_node_get_or_create() - retrieve or create a neigh node object
724 * @hard_iface: the interface where the neighbour is connected to
725 * @neigh_addr: the mac address of the neighbour interface
727 * Return: the neighbour node if found or created or NULL otherwise.
745 * batadv_hardif_neigh_dump() - Dump to netlink the neighbor infos for a
746 * specific outgoing interface
766 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
767 ret = -ENOENT;
772 if (IS_ERR(hard_iface) && PTR_ERR(hard_iface) != -ENONET) {
776 /* => PTR_ERR(hard_iface) == -ENONET
777 * => no hard-iface given, ok
782 if (!bat_priv->algo_ops->neigh.dump) {
783 ret = -EOPNOTSUPP;
787 bat_priv->algo_ops->neigh.dump(msg, cb, bat_priv, hard_iface);
789 ret = msg->len;
802 * batadv_orig_ifinfo_release() - release orig_ifinfo from lists and queue for
813 if (orig_ifinfo->if_outgoing != BATADV_IF_DEFAULT)
814 batadv_hardif_put(orig_ifinfo->if_outgoing);
817 router = rcu_dereference_protected(orig_ifinfo->router, true);
824 * batadv_orig_node_free_rcu() - free the orig_node
837 kfree(orig_node->tt_buff);
842 * batadv_orig_node_release() - release orig_node from lists and queue for
857 spin_lock_bh(&orig_node->neigh_list_lock);
861 &orig_node->neigh_list, list) {
862 hlist_del_rcu(&neigh_node->list);
867 &orig_node->ifinfo_list, list) {
868 hlist_del_rcu(&orig_ifinfo->list);
872 last_candidate = orig_node->last_bonding_candidate;
873 orig_node->last_bonding_candidate = NULL;
874 spin_unlock_bh(&orig_node->neigh_list_lock);
878 spin_lock_bh(&orig_node->vlan_list_lock);
879 hlist_for_each_entry_safe(vlan, node_tmp, &orig_node->vlan_list, list) {
880 hlist_del_rcu(&vlan->list);
883 spin_unlock_bh(&orig_node->vlan_list_lock);
885 call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu);
889 * batadv_originator_free() - Free all originator structures
890 * @bat_priv: the bat priv with all the mesh interface information
894 struct batadv_hashtable *hash = bat_priv->orig_hash;
904 cancel_delayed_work_sync(&bat_priv->orig_work);
906 bat_priv->orig_hash = NULL;
908 for (i = 0; i < hash->size; i++) {
909 head = &hash->table[i];
910 list_lock = &hash->list_locks[i];
915 hlist_del_rcu(&orig_node->hash_entry);
925 * batadv_orig_node_new() - creates a new orig_node
926 * @bat_priv: the bat priv with all the mesh interface information
949 INIT_HLIST_HEAD(&orig_node->neigh_list);
950 INIT_HLIST_HEAD(&orig_node->vlan_list);
951 INIT_HLIST_HEAD(&orig_node->ifinfo_list);
952 spin_lock_init(&orig_node->bcast_seqno_lock);
953 spin_lock_init(&orig_node->neigh_list_lock);
954 spin_lock_init(&orig_node->tt_buff_lock);
955 spin_lock_init(&orig_node->tt_lock);
956 spin_lock_init(&orig_node->vlan_list_lock);
959 kref_init(&orig_node->refcount);
961 orig_node->bat_priv = bat_priv;
962 ether_addr_copy(orig_node->orig, addr);
964 atomic_set(&orig_node->last_ttvn, 0);
965 orig_node->tt_buff = NULL;
966 orig_node->tt_buff_len = 0;
967 orig_node->last_seen = jiffies;
968 reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS);
969 orig_node->bcast_seqno_reset = reset_time;
972 orig_node->mcast_flags = BATADV_MCAST_WANT_NO_RTR4;
973 orig_node->mcast_flags |= BATADV_MCAST_WANT_NO_RTR6;
974 orig_node->mcast_flags |= BATADV_MCAST_HAVE_MC_PTYPE_CAPA;
975 INIT_HLIST_NODE(&orig_node->mcast_want_all_unsnoopables_node);
976 INIT_HLIST_NODE(&orig_node->mcast_want_all_ipv4_node);
977 INIT_HLIST_NODE(&orig_node->mcast_want_all_ipv6_node);
978 spin_lock_init(&orig_node->mcast_handler_lock);
992 INIT_HLIST_HEAD(&orig_node->fragments[i].fragment_list);
993 spin_lock_init(&orig_node->fragments[i].lock);
994 orig_node->fragments[i].size = 0;
1004 * batadv_purge_neigh_ifinfo() - purge obsolete ifinfo entries from neighbor
1005 * @bat_priv: the bat priv with all the mesh interface information
1006 * @neigh: orig node which is to be checked
1016 spin_lock_bh(&neigh->ifinfo_lock);
1020 &neigh->ifinfo_list, list) {
1021 if_outgoing = neigh_ifinfo->if_outgoing;
1023 /* always keep the default interface */
1027 /* don't purge if the interface is not (going) down */
1028 if (if_outgoing->if_status != BATADV_IF_INACTIVE &&
1029 if_outgoing->if_status != BATADV_IF_NOT_IN_USE &&
1030 if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)
1035 neigh->addr, if_outgoing->net_dev->name);
1037 hlist_del_rcu(&neigh_ifinfo->list);
1041 spin_unlock_bh(&neigh->ifinfo_lock);
1045 * batadv_purge_orig_ifinfo() - purge obsolete ifinfo entries from originator
1046 * @bat_priv: the bat priv with all the mesh interface information
1047 * @orig_node: orig node which is to be checked
1060 spin_lock_bh(&orig_node->neigh_list_lock);
1064 &orig_node->ifinfo_list, list) {
1065 if_outgoing = orig_ifinfo->if_outgoing;
1067 /* always keep the default interface */
1071 /* don't purge if the interface is not (going) down */
1072 if (if_outgoing->if_status != BATADV_IF_INACTIVE &&
1073 if_outgoing->if_status != BATADV_IF_NOT_IN_USE &&
1074 if_outgoing->if_status != BATADV_IF_TO_BE_REMOVED)
1079 orig_node->orig, if_outgoing->net_dev->name);
1083 hlist_del_rcu(&orig_ifinfo->list);
1085 if (orig_node->last_bonding_candidate == orig_ifinfo) {
1086 orig_node->last_bonding_candidate = NULL;
1091 spin_unlock_bh(&orig_node->neigh_list_lock);
1097 * batadv_purge_orig_neighbors() - purges neighbors from originator
1098 * @bat_priv: the bat priv with all the mesh interface information
1099 * @orig_node: orig node which is to be checked
1113 spin_lock_bh(&orig_node->neigh_list_lock);
1117 &orig_node->neigh_list, list) {
1118 last_seen = neigh_node->last_seen;
1119 if_incoming = neigh_node->if_incoming;
1122 if_incoming->if_status == BATADV_IF_INACTIVE ||
1123 if_incoming->if_status == BATADV_IF_NOT_IN_USE ||
1124 if_incoming->if_status == BATADV_IF_TO_BE_REMOVED) {
1125 if (if_incoming->if_status == BATADV_IF_INACTIVE ||
1126 if_incoming->if_status == BATADV_IF_NOT_IN_USE ||
1127 if_incoming->if_status == BATADV_IF_TO_BE_REMOVED)
1130 orig_node->orig, neigh_node->addr,
1131 if_incoming->net_dev->name);
1135 orig_node->orig, neigh_node->addr,
1140 hlist_del_rcu(&neigh_node->list);
1144 * deleted, but some interface has been removed.
1150 spin_unlock_bh(&orig_node->neigh_list_lock);
1155 * batadv_find_best_neighbor() - finds the best neighbor after purging
1156 * @bat_priv: the bat priv with all the mesh interface information
1157 * @orig_node: orig node which is to be checked
1158 * @if_outgoing: the interface for which the metric should be compared
1168 struct batadv_algo_ops *bao = bat_priv->algo_ops;
1171 hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) {
1172 if (best && (bao->neigh.cmp(neigh, if_outgoing, best,
1176 if (!kref_get_unless_zero(&neigh->refcount))
1189 * batadv_purge_orig_node() - purges obsolete information from an orig_node
1190 * @bat_priv: the bat priv with all the mesh interface information
1191 * @orig_node: orig node which is to be checked
1206 if (batadv_has_timed_out(orig_node->last_seen,
1210 orig_node->orig,
1211 jiffies_to_msecs(orig_node->last_seen));
1229 netdev_for_each_lower_private_rcu(bat_priv->mesh_iface, hard_iface, iter) {
1230 if (hard_iface->if_status != BATADV_IF_ACTIVE)
1233 if (!kref_get_unless_zero(&hard_iface->refcount))
1251 * batadv_purge_orig_ref() - Purge all outdated originators
1252 * @bat_priv: the bat priv with all the mesh interface information
1256 struct batadv_hashtable *hash = bat_priv->orig_hash;
1267 for (i = 0; i < hash->size; i++) {
1268 head = &hash->table[i];
1271 list_lock = &hash->list_locks[i];
1278 hlist_del_rcu(&orig_node->hash_entry);
1279 batadv_tt_global_del_orig(orig_node->bat_priv,
1280 orig_node, -1,
1304 &bat_priv->orig_work,
1309 * batadv_orig_dump() - Dump to netlink the originator infos for a specific
1310 * outgoing interface
1330 if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
1331 ret = -ENOENT;
1336 if (IS_ERR(hard_iface) && PTR_ERR(hard_iface) != -ENONET) {
1340 /* => PTR_ERR(hard_iface) == -ENONET
1341 * => no hard-iface given, ok
1346 if (!bat_priv->algo_ops->orig.dump) {
1347 ret = -EOPNOTSUPP;
1351 bat_priv->algo_ops->orig.dump(msg, cb, bat_priv, hard_iface);
1353 ret = msg->len;