Skip to content

Commit 3bd64ca

Browse files
committed
batman-adv: use neigh_node's orig_node only as id
The orig_node member of struct batadv_neigh_node is no longer used in B.A.T.M.A.N. IV. But batadv_neigh_node_create() is still storing it. Only batadv_v_ogm_route_update() uses it to check if we route toward it - not needing the data stored in the batadv_orig_node object itself, but merely a pointer to identify the originator. The field cannot hold a proper reference because that would create a reference cycle, so it must never be dereferenced. Rename it to orig_node_id and mark it __private to make any future attempt to dereference it immediately noticeable. Signed-off-by: Sven Eckelmann <sven@narfation.org>
1 parent 735522e commit 3bd64ca

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

net/batman-adv/bat_v_ogm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static bool batadv_v_ogm_route_update(struct batadv_priv *bat_priv,
719719
* don't route towards it
720720
*/
721721
router = batadv_orig_router_get(orig_node, if_outgoing);
722-
if (router && router->orig_node != orig_node && !orig_neigh_router) {
722+
if (router && ACCESS_PRIVATE(router, orig_node_id) != orig_node && !orig_neigh_router) {
723723
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
724724
"Drop packet: OGM via unknown neighbor!\n");
725725
goto out;

net/batman-adv/originator.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,12 @@ batadv_neigh_node_create(struct batadv_orig_node *orig_node,
693693
kref_get(&hard_iface->refcount);
694694
ether_addr_copy(neigh_node->addr, neigh_addr);
695695
neigh_node->if_incoming = hard_iface;
696-
neigh_node->orig_node = orig_node;
697696
neigh_node->last_seen = jiffies;
698697

698+
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
699+
ACCESS_PRIVATE(neigh_node, orig_node_id) = orig_node;
700+
#endif
701+
699702
/* increment unique neighbor refcount */
700703
kref_get(&hardif_neigh->refcount);
701704
neigh_node->hardif_neigh = hardif_neigh;

net/batman-adv/types.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,15 @@ struct batadv_neigh_node {
663663
/** @list: list node for &batadv_orig_node.neigh_list */
664664
struct hlist_node list;
665665

666-
/** @orig_node: pointer to corresponding orig_node */
667-
struct batadv_orig_node *orig_node;
666+
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
667+
/**
668+
* @orig_node_id: pointer to corresponding orig_node. It must only be used
669+
* to identify the node but must NEVER be dereferenced. The reference counter
670+
* was not increased when this was assigned because it would otherwise create
671+
* a reference cycle.
672+
*/
673+
struct batadv_orig_node *__private orig_node_id;
674+
#endif
668675

669676
/** @addr: the MAC address of the neighboring interface */
670677
u8 addr[ETH_ALEN];

0 commit comments

Comments
 (0)