| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/07/29 18:05 | flow | patch-triage |
3mArgs:null Results: {
"EnableConfigs": [
"BATMAN_ADV",
"BATMAN_ADV_BATMAN_V",
"BATMAN_ADV_BLA",
"BATMAN_ADV_DAT",
"BATMAN_ADV_MCAST"
],
"FocusSymbols": [
"batadv_bla_rx",
"batadv_bla_tx",
"batadv_dat_snoop_incoming_arp_reply",
"batadv_dat_snoop_incoming_arp_request",
"batadv_dat_snoop_incoming_dhcp_ack",
"batadv_dat_snoop_outgoing_arp_reply",
"batadv_dat_snoop_outgoing_arp_request",
"batadv_dat_snoop_outgoing_dhcp_ack",
"batadv_tt_global_add",
"batadv_tt_local_add",
"batadv_tt_local_commit_changes",
"batadv_tt_local_remove"
],
"Reasoning": "The patch introduces functional changes by converting `mac_addr` in `batadv_dat_entry` to `atomic64_t` and `flags` in `batadv_tt_common_entry` to `atomic_t`. It updates various functions in the Distributed ARP Table (DAT), Translation Table (TT), and Bridge Loop Avoidance (BLA) components to use atomic operations (`atomic_read`, `atomic_set`, `atomic_or`, `atomic_andnot`, `atomic_try_cmpxchg`) for concurrent state management. These changes affect core packet processing and state tracking logic in the batman-adv virtual network interface, which is reachable and should be fuzzed to ensure concurrency correctness.",
"WorthFuzzing": true
} |
| 1/1 | 2026/07/29 18:05 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 10e96c1ee06e20af874e19b33715bece671383b0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Jul 29 18:05:32 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/uapi/linux/batadv_packet.h b/include/uapi/linux/batadv_packet.h\nindex 1241285b866cd..32436560ecc8b 100644\n--- a/include/uapi/linux/batadv_packet.h\n+++ b/include/uapi/linux/batadv_packet.h\n@@ -192,13 +192,19 @@ enum batadv_tvlv_type {\n };\n \n #pragma pack(2)\n-/* the destination hardware field in the ARP frame is used to\n- * transport the claim type and the group id\n+/**\n+ * struct batadv_bla_claim_dst - layout of the destination MAC of a BLA claim\n+ * frame\n+ * @magic: fixed magic prefix (FF:43:05) identifying claim frames\n+ * @type: claim frame type, see \u0026enum batadv_bla_claimframe\n+ * @group: group identifier of the announcing backbone gateway\n+ *\n+ * used in the destination hardware field of the ARP frame\n */\n struct batadv_bla_claim_dst {\n-\t__u8 magic[3];\t/* FF:43:05 */\n-\t__u8 type;\t\t/* bla_claimframe */\n-\t__be16 group;\t\t/* group id */\n+\t__u8 magic[3];\n+\t__u8 type;\n+\t__be16 group;\n };\n \n /**\ndiff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c\nindex 49e5861b58ec2..93cd77680e644 100644\n--- a/net/batman-adv/bat_algo.c\n+++ b/net/batman-adv/bat_algo.c\n@@ -42,7 +42,8 @@ void batadv_algo_init(void)\n */\n struct batadv_algo_ops *batadv_algo_get(const char *name)\n {\n-\tstruct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;\n+\tstruct batadv_algo_ops *bat_algo_ops = NULL;\n+\tstruct batadv_algo_ops *bat_algo_ops_tmp;\n \n \thlist_for_each_entry(bat_algo_ops_tmp, \u0026batadv_algo_list, list) {\n \t\tif (strcmp(bat_algo_ops_tmp-\u003ename, name) != 0)\n@@ -116,12 +117,23 @@ int batadv_algo_select(struct batadv_priv *bat_priv, const char *name)\n \treturn 0;\n }\n \n+/**\n+ * batadv_param_set_ra() - Validate and store routing_algo module parameter\n+ * @val: new value for the routing_algo module parameter\n+ * @kp: kernel parameter description used to store the value\n+ *\n+ * Check that the requested algorithm is known to batman-adv and then store\n+ * the name as the new default routing algorithm.\n+ *\n+ * Return: 0 on success or negative error number in case of failure\n+ */\n static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)\n {\n \tstruct batadv_algo_ops *bat_algo_ops;\n \tchar *algo_name = (char *)val;\n-\tsize_t name_len = strlen(algo_name);\n+\tsize_t name_len;\n \n+\tname_len = strlen(algo_name);\n \tif (name_len \u003e 0 \u0026\u0026 algo_name[name_len - 1] == '\\n')\n \t\talgo_name[name_len - 1] = '\\0';\n \ndiff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c\nindex 22622283f59b0..aff279b83da49 100644\n--- a/net/batman-adv/bat_iv_ogm.c\n+++ b/net/batman-adv/bat_iv_ogm.c\n@@ -106,8 +106,8 @@ static u8 batadv_ring_buffer_avg(const u8 lq_recv[])\n {\n \tconst u8 *ptr;\n \tu16 count = 0;\n-\tu16 i = 0;\n \tu16 sum = 0;\n+\tu16 i = 0;\n \n \tptr = lq_recv;\n \n@@ -171,6 +171,14 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)\n \treturn NULL;\n }\n \n+/**\n+ * batadv_iv_ogm_neigh_new() - retrieve or create a B.A.T.M.A.N. IV neighbour\n+ * @hard_iface: the interface where the neighbour is connected to\n+ * @neigh_addr: the mac address of the neighbour\n+ * @orig_node: originator object representing the neighbour\n+ *\n+ * Return: pointer to the neigh_node or NULL in case of failure\n+ */\n static struct batadv_neigh_node *\n batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,\n \t\t\tconst u8 *neigh_addr,\n@@ -183,6 +191,14 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,\n \treturn neigh_node;\n }\n \n+/**\n+ * batadv_iv_ogm_iface_enable() - prepare an interface for B.A.T.M.A.N. IV\n+ * @hard_iface: the interface to prepare\n+ *\n+ * Allocate and prepare the per-interface OGM buffer\n+ *\n+ * Return: 0 on success or negative error number in case of failure\n+ */\n static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)\n {\n \tstruct batadv_ogm_packet *batadv_ogm_packet;\n@@ -220,6 +236,14 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)\n \treturn 0;\n }\n \n+/**\n+ * batadv_iv_ogm_iface_disable() - release B.A.T.M.A.N. IV resources of an\n+ * interface\n+ * @hard_iface: the interface which is shutting down\n+ *\n+ * Free the per-interface OGM buffer and cancel a possibly pending OGM\n+ * rescheduling work.\n+ */\n static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)\n {\n \tmutex_lock(\u0026hard_iface-\u003ebat_iv.ogm_buff_mutex);\n@@ -233,6 +257,11 @@ static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)\n \tdisable_delayed_work_sync(\u0026hard_iface-\u003ebat_iv.reschedule_work);\n }\n \n+/**\n+ * batadv_iv_ogm_iface_update_mac() - update the originator MAC stored in the\n+ * per-interface OGM buffer\n+ * @hard_iface: the interface for which the OGM buffer should be updated\n+ */\n static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)\n {\n \tstruct batadv_ogm_packet *batadv_ogm_packet;\n@@ -254,6 +283,14 @@ static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)\n \tmutex_unlock(\u0026hard_iface-\u003ebat_iv.ogm_buff_mutex);\n }\n \n+/**\n+ * batadv_iv_ogm_primary_iface_set() - apply primary interface state to\n+ * a batadv_hard_iface\n+ * @hard_iface: interface which just became the primary\n+ *\n+ * The primary interface uses the full TTL for its own OGMs, so adjust the TTL\n+ * stored in the OGM template buffer accordingly.\n+ */\n static void\n batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)\n {\n@@ -273,7 +310,17 @@ batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)\n \tmutex_unlock(\u0026hard_iface-\u003ebat_iv.ogm_buff_mutex);\n }\n \n-/* when do we schedule our own ogm to be sent */\n+/**\n+ * batadv_iv_ogm_emit_send_time() - calculate the jiffies when an own OGM\n+ * should be sent next\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * The next emission point is the configured orig_interval randomised by\n+ * +/- BATADV_JITTER milliseconds to reduce chance of potential collisions\n+ * between neighbours.\n+ *\n+ * Return: jiffies value when the next OGM should be transmitted\n+ */\n static unsigned long\n batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)\n {\n@@ -285,13 +332,24 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)\n \treturn jiffies + msecs_to_jiffies(msecs);\n }\n \n-/* when do we schedule a ogm packet to be sent */\n+/**\n+ * batadv_iv_ogm_fwd_send_time() - calculate the jiffies when a forwarded OGM\n+ * should be sent next\n+ *\n+ * Return: jiffies value at which a forwarded OGM should be transmitted\n+ */\n static unsigned long batadv_iv_ogm_fwd_send_time(void)\n {\n \treturn jiffies + msecs_to_jiffies(get_random_u32_below(BATADV_JITTER / 2));\n }\n \n-/* apply hop penalty for a normal link */\n+/**\n+ * batadv_hop_penalty() - apply the configured hop penalty to a TQ value\n+ * @tq: input TQ value to be reduced\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Return: the TQ value after the hop penalty has been applied\n+ */\n static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)\n {\n \tint hop_penalty = READ_ONCE(bat_priv-\u003ehop_penalty);\n@@ -337,17 +395,25 @@ batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,\n \treturn next_buff_pos \u003c= packet_len;\n }\n \n-/* send a batman ogm to a given interface */\n+/**\n+ * batadv_iv_ogm_send_to_if() - send a batman OGM to a given interface\n+ * @forw_packet: forward packet containing the OGM(s) to be transmitted\n+ * @hard_iface: interface to send the OGM out on\n+ *\n+ * Update the direct link flags of each aggregated OGM for the outgoing\n+ * interface, log the transmission and finally hand a clone of the skb to the\n+ * lower layer for broadcast.\n+ */\n static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,\n \t\t\t\t struct batadv_hard_iface *hard_iface)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(hard_iface-\u003emesh_iface);\n-\tconst char *fwd_str;\n-\tu8 packet_num;\n-\tint buff_pos;\n \tstruct batadv_ogm_packet *batadv_ogm_packet;\n+\tconst char *fwd_str;\n \tstruct sk_buff *skb;\n \tu8 *packet_pos;\n+\tu8 packet_num;\n+\tint buff_pos;\n \n \tif (hard_iface-\u003eif_status != BATADV_IF_ACTIVE)\n \t\treturn;\n@@ -401,7 +467,13 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,\n \t}\n }\n \n-/* send a batman ogm packet */\n+/**\n+ * batadv_iv_ogm_emit() - emit an (aggregated) OGM packet\n+ * @forw_packet: forward packet which should be emitted\n+ *\n+ * The @forw_packet will be emitted but not consumed. When the interface is\n+ * no longer active, the transmission will be skipped.\n+ */\n static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet)\n {\n \tif (!forw_packet-\u003eif_incoming) {\n@@ -442,13 +514,13 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,\n \t\t\t const struct batadv_hard_iface *if_outgoing,\n \t\t\t const struct batadv_forw_packet *forw_packet)\n {\n-\tstruct batadv_ogm_packet *batadv_ogm_packet;\n \tunsigned int aggregated_bytes = forw_packet-\u003epacket_len + packet_len;\n+\tstruct batadv_ogm_packet *batadv_ogm_packet;\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tu8 packet_num = forw_packet-\u003enum_packets;\n-\tbool res = false;\n \tunsigned long aggregation_end_time;\n \tunsigned int max_bytes;\n+\tbool res = false;\n \n \tbatadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet-\u003eskb-\u003edata;\n \taggregation_end_time = send_time;\n@@ -555,10 +627,10 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n \tstruct batadv_forw_packet *forw_packet_aggr;\n-\tstruct sk_buff *skb;\n \tunsigned char *skb_buff;\n \tunsigned int skb_size;\n-\tatomic_t *queue_left = own_packet ? NULL : \u0026bat_priv-\u003ebatman_queue_left;\n+\tatomic_t *queue_left;\n+\tstruct sk_buff *skb;\n \n \tif (READ_ONCE(bat_priv-\u003eaggregated_ogms))\n \t\tskb_size = max_t(unsigned int, BATADV_MAX_AGGREGATION_BYTES,\n@@ -572,6 +644,7 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,\n \tif (!skb)\n \t\treturn false;\n \n+\tqueue_left = own_packet ? NULL : \u0026bat_priv-\u003ebatman_queue_left;\n \tforw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,\n \t\t\t\t\t\t queue_left, bat_priv, skb);\n \tif (!forw_packet_aggr) {\n@@ -603,7 +676,14 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,\n \treturn true;\n }\n \n-/* aggregate a new packet into the existing ogm packet */\n+/**\n+ * batadv_iv_ogm_aggregate() - append an OGM to an existing aggregated forward\n+ * packet\n+ * @forw_packet_aggr: aggregated forward packet to extend\n+ * @packet_buff: pointer to the OGM to append\n+ * @packet_len: length of the OGM to append\n+ * @direct_link: true if @packet_buff was received as a direct link OGM\n+ */\n static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,\n \t\t\t\t const unsigned char *packet_buff,\n \t\t\t\t int packet_len, bool direct_link)\n@@ -644,9 +724,9 @@ static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,\n \tstruct batadv_forw_packet *forw_packet_aggr = NULL;\n \tstruct batadv_forw_packet *forw_packet_pos = NULL;\n \tstruct batadv_ogm_packet *batadv_ogm_packet;\n-\tbool direct_link;\n \tunsigned long max_aggregation_jiffies;\n \tbool aggregated_ogms;\n+\tbool direct_link;\n \n \tbatadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff;\n \tdirect_link = !!(batadv_ogm_packet-\u003eflags \u0026 BATADV_DIRECTLINK);\n@@ -699,6 +779,21 @@ static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,\n \t}\n }\n \n+/**\n+ * batadv_iv_ogm_forward() - rebroadcast a received OGM\n+ * @orig_node: originator that sent the OGM\n+ * @ethhdr: ethernet header of the OGM packet\n+ * @batadv_ogm_packet: OGM packet to be forwarded\n+ * @is_single_hop_neigh: true if the OGM was received via a one-hop neighbour\n+ * @is_from_best_next_hop: true if the sender is the currently selected best\n+ * next hop towards @orig_node\n+ * @if_incoming: interface where the packet was received\n+ * @if_outgoing: interface for which the retransmission should be considered\n+ *\n+ * Decrement the TTL, apply the hop penalty and queue the OGM for\n+ * retransmission. OGMs that do not arrive over the best next hop are only\n+ * forwarded for link-quality measurement reasons (and marked accordingly).\n+ */\n static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,\n \t\t\t\t const struct ethhdr *ethhdr,\n \t\t\t\t struct batadv_ogm_packet *batadv_ogm_packet,\n@@ -762,9 +857,9 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(hard_iface-\u003emesh_iface);\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n-\tstruct hlist_head *head;\n-\tstruct batadv_orig_node *orig_node;\n \tstruct batadv_orig_ifinfo *orig_ifinfo;\n+\tstruct batadv_orig_node *orig_node;\n+\tstruct hlist_head *head;\n \tunsigned long *word;\n \tu32 i;\n \tu8 *w;\n@@ -802,13 +897,14 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)\n \tstruct batadv_priv *bat_priv = netdev_priv(hard_iface-\u003emesh_iface);\n \tstruct batadv_ogm_buf *ogm_buff = \u0026hard_iface-\u003ebat_iv.ogm_buff;\n \tstruct batadv_ogm_packet *batadv_ogm_packet;\n-\tstruct batadv_hard_iface *primary_if, *tmp_hard_iface;\n-\tstruct list_head *iter;\n-\tu32 seqno;\n-\tu16 tvlv_len = 0;\n+\tstruct batadv_hard_iface *tmp_hard_iface;\n+\tstruct batadv_hard_iface *primary_if;\n \tunsigned long send_time;\n \tbool reschedule = false;\n+\tstruct list_head *iter;\n+\tu16 tvlv_len = 0;\n \tbool scheduled;\n+\tu32 seqno;\n \tint ret;\n \n \tlockdep_assert_held(\u0026hard_iface-\u003ebat_iv.ogm_buff_mutex);\n@@ -899,6 +995,13 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)\n \tbatadv_hardif_put(primary_if);\n }\n \n+/**\n+ * batadv_iv_ogm_schedule() - schedule the next OGM transmission on an\n+ * interface\n+ * @hard_iface: interface for which the next OGM should be scheduled\n+ *\n+ * Take the OGM buffer mutex and prepare the next OGM for transmission.\n+ */\n static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)\n {\n \tif (hard_iface-\u003eif_status == BATADV_IF_TO_BE_REMOVED)\n@@ -909,6 +1012,13 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)\n \tmutex_unlock(\u0026hard_iface-\u003ebat_iv.ogm_buff_mutex);\n }\n \n+/**\n+ * batadv_iv_ogm_reschedule() - work-queue helper to rerun batadv_iv_ogm_schedule()\n+ * @work: work item embedded in the hard interface\n+ *\n+ * Invoked from the per-interface reschedule_work delayed work when the\n+ * previous attempt to enqueue the own OGM failed.\n+ */\n static void batadv_iv_ogm_reschedule(struct work_struct *work)\n {\n \tstruct delayed_work *delayed_work = to_delayed_work(work);\n@@ -996,13 +1106,14 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_hard_iface *if_outgoing,\n \t\t\t enum batadv_dup_status dup_status)\n {\n-\tstruct batadv_neigh_ifinfo *neigh_ifinfo = NULL;\n \tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n-\tstruct batadv_neigh_node *neigh_node = NULL;\n+\tstruct batadv_neigh_ifinfo *neigh_ifinfo = NULL;\n \tstruct batadv_neigh_node *tmp_neigh_node = NULL;\n+\tstruct batadv_neigh_node *neigh_node = NULL;\n \tstruct batadv_neigh_node *router = NULL;\n-\tu8 sum_orig, sum_neigh;\n \tu8 *neigh_addr;\n+\tu8 sum_neigh;\n+\tu8 sum_orig;\n \tu8 tq_avg;\n \n \tbatadv_dbg(BATADV_DBG_BATMAN, bat_priv,\n@@ -1133,15 +1244,21 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,\n \t\t\t\t struct batadv_hard_iface *if_outgoing)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n-\tstruct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node;\n-\tstruct batadv_neigh_ifinfo *neigh_ifinfo;\n-\tu8 total_count;\n-\tu8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;\n \tunsigned int tq_iface_hop_penalty = BATADV_TQ_MAX_VALUE;\n-\tunsigned int neigh_rq_inv_cube, neigh_rq_max_cube;\n-\tunsigned int tq_asym_penalty, inv_asym_penalty;\n+\tstruct batadv_neigh_node *neigh_node = NULL;\n+\tstruct batadv_neigh_node *tmp_neigh_node;\n+\tstruct batadv_neigh_ifinfo *neigh_ifinfo;\n+\tunsigned int neigh_rq_inv_cube;\n+\tunsigned int neigh_rq_max_cube;\n+\tunsigned int inv_asym_penalty;\n+\tunsigned int tq_asym_penalty;\n \tunsigned int combined_tq;\n+\tu8 neigh_rq_count;\n+\tu8 orig_eq_count;\n \tbool ret = false;\n+\tu8 neigh_rq_inv;\n+\tu8 total_count;\n+\tu8 tq_own;\n \n \t/* find corresponding one hop neighbor */\n \trcu_read_lock();\n@@ -1274,19 +1391,19 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,\n \t\t\t struct batadv_hard_iface *if_outgoing)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n-\tstruct batadv_orig_node *orig_node;\n \tstruct batadv_orig_ifinfo *orig_ifinfo = NULL;\n-\tstruct batadv_neigh_node *neigh_node;\n+\tu32 seqno = ntohl(batadv_ogm_packet-\u003eseqno);\n+\tenum batadv_dup_status ret = BATADV_NO_DUP;\n \tstruct batadv_neigh_ifinfo *neigh_ifinfo;\n-\tbool is_dup;\n-\ts32 seq_diff;\n+\tstruct batadv_neigh_node *neigh_node;\n+\tstruct batadv_orig_node *orig_node;\n \tbool need_update = false;\n-\tint set_mark;\n-\tenum batadv_dup_status ret = BATADV_NO_DUP;\n-\tu32 seqno = ntohl(batadv_ogm_packet-\u003eseqno);\n-\tu8 *neigh_addr;\n-\tu8 packet_count;\n \tunsigned long *bitmap;\n+\tu8 packet_count;\n+\tu8 *neigh_addr;\n+\ts32 seq_diff;\n+\tint set_mark;\n+\tbool is_dup;\n \n \torig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet-\u003eorig);\n \tif (!orig_node)\n@@ -1403,21 +1520,22 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n \tstruct batadv_hardif_neigh_node *hardif_neigh = NULL;\n-\tstruct batadv_neigh_node *router = NULL;\n+\tstruct batadv_neigh_node *orig_neigh_router = NULL;\n+\tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n \tstruct batadv_neigh_node *router_router = NULL;\n \tstruct batadv_orig_node *orig_neigh_node;\n+\tstruct batadv_neigh_node *router = NULL;\n \tstruct batadv_orig_ifinfo *orig_ifinfo;\n-\tstruct batadv_neigh_node *orig_neigh_router = NULL;\n-\tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n \tstruct batadv_ogm_packet *ogm_packet;\n-\tenum batadv_dup_status dup_status;\n \tbool is_from_best_next_hop = false;\n+\tenum batadv_dup_status dup_status;\n \tbool is_single_hop_neigh = false;\n-\tbool sameseq, similar_ttl;\n \tstruct sk_buff *skb_priv;\n \tstruct ethhdr *ethhdr;\n-\tu8 *prev_sender;\n+\tbool similar_ttl;\n \tbool is_bidirect;\n+\tu8 *prev_sender;\n+\tbool sameseq;\n \n \t/* create a private copy of the skb, as some functions change tq value\n \t * and/or flags.\n@@ -1639,16 +1757,17 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,\n \t\t\t\t struct batadv_hard_iface *if_incoming)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n-\tstruct batadv_orig_node *orig_neigh_node, *orig_node;\n+\tstruct batadv_orig_node *orig_neigh_node;\n \tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_ogm_packet *ogm_packet;\n-\tu32 if_incoming_seqno;\n-\tbool has_directlink_flag;\n-\tstruct ethhdr *ethhdr;\n+\tstruct batadv_orig_node *orig_node;\n \tbool is_my_oldorig = false;\n+\tbool has_directlink_flag;\n \tbool is_my_addr = false;\n \tbool is_my_orig = false;\n \tstruct list_head *iter;\n+\tu32 if_incoming_seqno;\n+\tstruct ethhdr *ethhdr;\n \n \togm_packet = (struct batadv_ogm_packet *)(skb-\u003edata + ogm_offset);\n \tethhdr = eth_hdr(skb);\n@@ -1765,10 +1884,18 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,\n \tbatadv_orig_node_put(orig_node);\n }\n \n+/**\n+ * batadv_iv_send_outstanding_bat_ogm_packet() - work-queue helper to emit a\n+ * queued forward packet\n+ * @work: work item embedded in the forward packet\n+ *\n+ * Emit the queued OGM forward packet and, for own primary-interface packets,\n+ * schedule the next periodic OGM. The forward packet is freed afterwards.\n+ */\n static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)\n {\n-\tstruct delayed_work *delayed_work;\n \tstruct batadv_forw_packet *forw_packet;\n+\tstruct delayed_work *delayed_work;\n \tstruct batadv_priv *bat_priv;\n \tbool dropped = false;\n \n@@ -1803,15 +1930,26 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)\n \t\tbatadv_forw_packet_free(forw_packet, dropped);\n }\n \n+/**\n+ * batadv_iv_ogm_receive() - receive a B.A.T.M.A.N. IV OGM packet\n+ * @skb: skb containing the OGM packet\n+ * @if_incoming: interface where the packet was received\n+ *\n+ * Validate the packet, then split the aggregated OGM packet into individual\n+ * OGMs and hand each of them to batadv_iv_ogm_process(). Ownership of @skb is\n+ * always taken over by this function.\n+ *\n+ * Return: NET_RX_SUCCESS or NET_RX_DROP\n+ */\n static int batadv_iv_ogm_receive(struct sk_buff *skb,\n \t\t\t\t struct batadv_hard_iface *if_incoming)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n \tstruct batadv_ogm_packet *ogm_packet;\n+\tint ret = NET_RX_DROP;\n \tu8 *packet_pos;\n \tint ogm_offset;\n \tbool res;\n-\tint ret = NET_RX_DROP;\n \n \tres = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);\n \tif (!res)\n@@ -1901,9 +2039,9 @@ batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,\n \t\t\t\t struct batadv_neigh_node *neigh_node,\n \t\t\t\t bool best)\n {\n+\tunsigned int last_seen_msecs;\n \tvoid *hdr;\n \tu8 tq_avg;\n-\tunsigned int last_seen_msecs;\n \n \tlast_seen_msecs = jiffies_to_msecs(jiffies - orig_node-\u003elast_seen);\n \n@@ -1965,9 +2103,9 @@ batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,\n {\n \tstruct batadv_neigh_node *neigh_node_best;\n \tstruct batadv_neigh_node *neigh_node;\n+\tu8 tq_avg_best;\n \tint sub = 0;\n \tbool best;\n-\tu8 tq_avg_best;\n \n \tneigh_node_best = batadv_orig_router_get(orig_node, if_outgoing);\n \tif (!neigh_node_best)\n@@ -2060,11 +2198,11 @@ batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,\n \t\t\tstruct batadv_hard_iface *if_outgoing)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n-\tstruct hlist_head *head;\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \tint bucket = cb-\u003eargs[0];\n+\tstruct hlist_head *head;\n \tint idx = cb-\u003eargs[1];\n \tint sub = cb-\u003eargs[2];\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \n \twhile (bucket \u003c hash-\u003esize) {\n \t\thead = \u0026hash-\u003etable[bucket];\n@@ -2103,9 +2241,11 @@ static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1,\n \t\t\t\t struct batadv_hard_iface *if_outgoing2,\n \t\t\t\t int *diff)\n {\n-\tstruct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;\n-\tu8 tq1, tq2;\n+\tstruct batadv_neigh_ifinfo *neigh1_ifinfo;\n+\tstruct batadv_neigh_ifinfo *neigh2_ifinfo;\n \tbool ret = true;\n+\tu8 tq1;\n+\tu8 tq2;\n \n \tneigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);\n \tneigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2);\n@@ -2139,8 +2279,8 @@ static int\n batadv_iv_ogm_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,\n \t\t\t struct batadv_hardif_neigh_node *hardif_neigh)\n {\n-\tvoid *hdr;\n \tunsigned int last_seen_msecs;\n+\tvoid *hdr;\n \n \tlast_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh-\u003elast_seen);\n \n@@ -2218,12 +2358,12 @@ batadv_iv_ogm_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,\n \t\t\t struct batadv_priv *bat_priv,\n \t\t\t struct batadv_hard_iface *single_hardif)\n {\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \tstruct batadv_hard_iface *hard_iface;\n-\tstruct list_head *iter;\n-\tint i_hardif = 0;\n \tint i_hardif_s = cb-\u003eargs[0];\n+\tstruct list_head *iter;\n \tint idx = cb-\u003eargs[1];\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n+\tint i_hardif = 0;\n \n \trcu_read_lock();\n \tif (single_hardif) {\n@@ -2310,6 +2450,12 @@ batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,\n \treturn ret;\n }\n \n+/**\n+ * batadv_iv_iface_enabled() - notification handler for activated interfaces\n+ * @hard_iface: interface that was just activated\n+ *\n+ * Set up the per-interface reschedule work and start sending periodic OGMs.\n+ */\n static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface)\n {\n \tINIT_DELAYED_WORK(\u0026hard_iface-\u003ebat_iv.reschedule_work, batadv_iv_ogm_reschedule);\n@@ -2328,17 +2474,26 @@ static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv)\n \tWRITE_ONCE(bat_priv-\u003egw.sel_class, 20);\n }\n \n+/**\n+ * batadv_iv_gw_get_best_gw_node() - retrieve the best gateway node based on\n+ * the B.A.T.M.A.N. IV metric and the configured GW selection class\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Return: gateway node with the highest score for the current selection class,\n+ * or NULL if no eligible gateway exists.\n+ */\n static struct batadv_gw_node *\n batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_neigh_node *router;\n \tstruct batadv_neigh_ifinfo *router_ifinfo;\n-\tstruct batadv_gw_node *gw_node, *curr_gw = NULL;\n+\tstruct batadv_gw_node *curr_gw = NULL;\n+\tstruct batadv_orig_node *orig_node;\n+\tstruct batadv_neigh_node *router;\n+\tstruct batadv_gw_node *gw_node;\n \tu64 max_gw_factor = 0;\n \tu64 tmp_gw_factor = 0;\n \tu8 max_tq = 0;\n \tu8 tq_avg;\n-\tstruct batadv_orig_node *orig_node;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(gw_node, \u0026bat_priv-\u003egw.gateway_list, list) {\n@@ -2405,6 +2560,19 @@ batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)\n \treturn curr_gw;\n }\n \n+/**\n+ * batadv_iv_gw_is_eligible() - check whether a new gateway should replace the\n+ * currently selected one\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @curr_gw_orig: originator of the currently selected gateway\n+ * @orig_node: originator of the gateway candidate\n+ *\n+ * Compare the TQ values of @curr_gw_orig and @orig_node, taking the configured\n+ * gateway selection class into account.\n+ *\n+ * Return: true if @orig_node should take over as the active gateway, false\n+ * otherwise\n+ */\n static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_orig_node *curr_gw_orig,\n \t\t\t\t struct batadv_orig_node *orig_node)\n@@ -2412,10 +2580,11 @@ static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,\n \tstruct batadv_neigh_ifinfo *router_orig_ifinfo = NULL;\n \tstruct batadv_neigh_ifinfo *router_gw_ifinfo = NULL;\n \tu32 sel_class = READ_ONCE(bat_priv-\u003egw.sel_class);\n-\tstruct batadv_neigh_node *router_gw = NULL;\n \tstruct batadv_neigh_node *router_orig = NULL;\n-\tu8 gw_tq_avg, orig_tq_avg;\n+\tstruct batadv_neigh_node *router_gw = NULL;\n \tbool ret = false;\n+\tu8 orig_tq_avg;\n+\tu8 gw_tq_avg;\n \n \t/* dynamic re-election is performed only on fast or late switch */\n \tif (sel_class \u003c= 2)\n@@ -2486,8 +2655,8 @@ static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid,\n \t\t\t\t struct batadv_gw_node *gw_node)\n {\n \tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n-\tstruct batadv_neigh_node *router;\n \tstruct batadv_gw_node *curr_gw = NULL;\n+\tstruct batadv_neigh_node *router;\n \tint ret = 0;\n \tvoid *hdr;\n \ndiff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c\nindex db6f5bdcaa985..ee372fc9d44e9 100644\n--- a/net/batman-adv/bat_v.c\n+++ b/net/batman-adv/bat_v.c\n@@ -41,6 +41,13 @@\n #include \"netlink.h\"\n #include \"originator.h\"\n \n+/**\n+ * batadv_v_iface_activate() - finalise the activation of a hard interface\n+ * @hard_iface: interface to activate\n+ *\n+ * Reuse the currently selected primary interface to seed the ELP packet.\n+ * Immediately activate the interface.\n+ */\n static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(hard_iface-\u003emesh_iface);\n@@ -61,6 +68,16 @@ static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface)\n \t\thard_iface-\u003eif_status = BATADV_IF_ACTIVE;\n }\n \n+/**\n+ * batadv_v_iface_enable() - enable the B.A.T.M.A.N. V protocol on an\n+ * interface\n+ * @hard_iface: interface to enable\n+ *\n+ * Enable the ELP and OGM components for @hard_iface. On error, the partially\n+ * enabled state is rolled back before returning.\n+ *\n+ * Return: 0 on success or negative error number in case of failure\n+ */\n static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)\n {\n \tint ret;\n@@ -76,12 +93,21 @@ static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)\n \treturn ret;\n }\n \n+/**\n+ * batadv_v_iface_disable() - disable the B.A.T.M.A.N. V protocol on an\n+ * interface\n+ * @hard_iface: interface to disable\n+ */\n static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface)\n {\n \tbatadv_v_ogm_iface_disable(hard_iface);\n \tbatadv_v_elp_iface_disable(hard_iface);\n }\n \n+/**\n+ * batadv_v_primary_iface_set() - apply primary interface state\n+ * @hard_iface: interface which just became the primary\n+ */\n static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface)\n {\n \tbatadv_v_elp_primary_iface_set(hard_iface);\n@@ -109,6 +135,11 @@ static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface)\n \tbatadv_hardif_put(primary_if);\n }\n \n+/**\n+ * batadv_v_hardif_neigh_init() - initialise the B.A.T.M.A.N. V state of a\n+ * hard interface neighbour\n+ * @hardif_neigh: hard interface neighbour to initialise\n+ */\n static void\n batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)\n {\n@@ -128,9 +159,9 @@ static int\n batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,\n \t\t\t struct batadv_hardif_neigh_node *hardif_neigh)\n {\n-\tvoid *hdr;\n \tunsigned int last_seen_msecs;\n \tu32 throughput;\n+\tvoid *hdr;\n \n \tlast_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh-\u003elast_seen);\n \tthroughput = ewma_throughput_read(\u0026hardif_neigh-\u003ebat_v.throughput);\n@@ -211,12 +242,12 @@ batadv_v_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,\n \t\t struct batadv_priv *bat_priv,\n \t\t struct batadv_hard_iface *single_hardif)\n {\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \tstruct batadv_hard_iface *hard_iface;\n-\tstruct list_head *iter;\n-\tint i_hardif = 0;\n \tint i_hardif_s = cb-\u003eargs[0];\n+\tstruct list_head *iter;\n \tint idx = cb-\u003eargs[1];\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n+\tint i_hardif = 0;\n \n \trcu_read_lock();\n \tif (single_hardif) {\n@@ -421,11 +452,11 @@ batadv_v_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,\n \t\t struct batadv_hard_iface *if_outgoing)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n-\tstruct hlist_head *head;\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \tint bucket = cb-\u003eargs[0];\n+\tstruct hlist_head *head;\n \tint idx = cb-\u003eargs[1];\n \tint sub = cb-\u003eargs[2];\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \n \twhile (bucket \u003c hash-\u003esize) {\n \t\thead = \u0026hash-\u003etable[bucket];\n@@ -444,12 +475,23 @@ batadv_v_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,\n \tcb-\u003eargs[2] = sub;\n }\n \n+/**\n+ * batadv_v_neigh_cmp() - compare two B.A.T.M.A.N. V neighbours by throughput\n+ * @neigh1: first neighbour to compare\n+ * @if_outgoing1: outgoing interface to use for @neigh1\n+ * @neigh2: second neighbour to compare\n+ * @if_outgoing2: outgoing interface to use for @neigh2\n+ *\n+ * Return: a positive value if @neigh1 is better, a negative value if @neigh2\n+ * is better and 0 if both have equal throughput\n+ */\n static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1,\n \t\t\t struct batadv_hard_iface *if_outgoing1,\n \t\t\t struct batadv_neigh_node *neigh2,\n \t\t\t struct batadv_hard_iface *if_outgoing2)\n {\n-\tstruct batadv_neigh_ifinfo *ifinfo1, *ifinfo2;\n+\tstruct batadv_neigh_ifinfo *ifinfo1;\n+\tstruct batadv_neigh_ifinfo *ifinfo2;\n \tint ret = 0;\n \n \tifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);\n@@ -469,14 +511,26 @@ static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1,\n \treturn ret;\n }\n \n+/**\n+ * batadv_v_neigh_is_sob() - check whether two B.A.T.M.A.N. V neighbours have\n+ * a similar or better throughput\n+ * @neigh1: first neighbour to compare\n+ * @if_outgoing1: outgoing interface to use for @neigh1\n+ * @neigh2: second neighbour to compare\n+ * @if_outgoing2: outgoing interface to use for @neigh2\n+ *\n+ * Return: true if the throughput of @neigh2 is at least 3/4 of the\n+ * @neigh1 throughput\n+ */\n static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1,\n \t\t\t\t struct batadv_hard_iface *if_outgoing1,\n \t\t\t\t struct batadv_neigh_node *neigh2,\n \t\t\t\t struct batadv_hard_iface *if_outgoing2)\n {\n-\tstruct batadv_neigh_ifinfo *ifinfo1, *ifinfo2;\n-\tu32 threshold;\n+\tstruct batadv_neigh_ifinfo *ifinfo1;\n+\tstruct batadv_neigh_ifinfo *ifinfo2;\n \tbool ret = false;\n+\tu32 threshold;\n \n \tifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);\n \tif (!ifinfo1)\n@@ -558,8 +612,10 @@ static int batadv_v_gw_throughput_get(struct batadv_gw_node *gw_node, u32 *bw)\n static struct batadv_gw_node *\n batadv_v_gw_get_best_gw_node(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_gw_node *gw_node, *curr_gw = NULL;\n-\tu32 max_bw = 0, bw;\n+\tstruct batadv_gw_node *curr_gw = NULL;\n+\tstruct batadv_gw_node *gw_node;\n+\tu32 max_bw = 0;\n+\tu32 bw;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(gw_node, \u0026bat_priv-\u003egw.gateway_list, list) {\n@@ -598,9 +654,12 @@ static bool batadv_v_gw_is_eligible(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_orig_node *curr_gw_orig,\n \t\t\t\t struct batadv_orig_node *orig_node)\n {\n-\tstruct batadv_gw_node *curr_gw, *orig_gw = NULL;\n-\tu32 gw_throughput, orig_throughput, threshold;\n+\tstruct batadv_gw_node *orig_gw = NULL;\n+\tstruct batadv_gw_node *curr_gw;\n+\tu32 orig_throughput;\n+\tu32 gw_throughput;\n \tbool ret = false;\n+\tu32 threshold;\n \n \tthreshold = READ_ONCE(bat_priv-\u003egw.sel_class);\n \n@@ -656,8 +715,8 @@ static int batadv_v_gw_dump_entry(struct sk_buff *msg, u32 portid,\n \t\t\t\t struct batadv_gw_node *gw_node)\n {\n \tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n-\tstruct batadv_neigh_node *router;\n \tstruct batadv_gw_node *curr_gw = NULL;\n+\tstruct batadv_neigh_node *router;\n \tint ret = 0;\n \tvoid *hdr;\n \ndiff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c\nindex 262e40040007c..6ad6042a5d9b6 100644\n--- a/net/batman-adv/bat_v_elp.c\n+++ b/net/batman-adv/bat_v_elp.c\n@@ -230,11 +230,14 @@ static bool\n batadv_v_elp_wifi_neigh_probe(struct batadv_hardif_neigh_node *neigh)\n {\n \tstruct batadv_hard_iface *hard_iface = neigh-\u003eif_incoming;\n-\tstruct batadv_priv *bat_priv = netdev_priv(hard_iface-\u003emesh_iface);\n+\tstruct batadv_priv *bat_priv;\n \tunsigned long last_tx_diff;\n \tstruct sk_buff *skb;\n-\tint probe_len, i;\n \tint elp_skb_len;\n+\tint probe_len;\n+\tint i;\n+\n+\tbat_priv = netdev_priv(hard_iface-\u003emesh_iface);\n \n \t/* this probing routine is for Wifi neighbours only */\n \tif (!batadv_is_wifi_hardif(hard_iface))\n@@ -289,8 +292,8 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)\n \tstruct batadv_v_metric_queue_entry *metric_entry;\n \tstruct batadv_v_metric_queue_entry *metric_safe;\n \tstruct batadv_hardif_neigh_node *hardif_neigh;\n-\tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_hard_iface_bat_v *bat_v;\n+\tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_elp_packet *elp_packet;\n \tstruct list_head metric_queue;\n \tstruct batadv_priv *bat_priv;\n@@ -395,9 +398,9 @@ int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface)\n \tstatic const size_t tvlv_padding = sizeof(__be32);\n \tstruct batadv_elp_packet *elp_packet;\n \tunsigned char *elp_buff;\n+\tint res = -ENOMEM;\n \tu32 random_seqno;\n \tsize_t size;\n-\tint res = -ENOMEM;\n \n \tsize = ETH_HLEN + NET_IP_ALIGN + BATADV_ELP_HLEN + tvlv_padding;\n \thard_iface-\u003ebat_v.elp_skb = dev_alloc_skb(size);\n@@ -500,11 +503,11 @@ static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_elp_packet *elp_packet)\n \n {\n-\tstruct batadv_neigh_node *neigh;\n-\tstruct batadv_orig_node *orig_neigh;\n \tstruct batadv_hardif_neigh_node *hardif_neigh;\n-\ts32 seqno_diff;\n+\tstruct batadv_orig_node *orig_neigh;\n+\tstruct batadv_neigh_node *neigh;\n \ts32 elp_latest_seqno;\n+\ts32 seqno_diff;\n \n \torig_neigh = batadv_v_ogm_orig_get(bat_priv, elp_packet-\u003eorig);\n \tif (!orig_neigh)\n@@ -556,8 +559,8 @@ int batadv_v_elp_packet_recv(struct sk_buff *skb,\n \tstruct batadv_elp_packet *elp_packet;\n \tstruct batadv_hard_iface *primary_if;\n \tstruct ethhdr *ethhdr;\n-\tbool res;\n \tint ret = NET_RX_DROP;\n+\tbool res;\n \n \tres = batadv_check_management_packet(skb, if_incoming, BATADV_ELP_HLEN);\n \tif (!res)\ndiff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c\nindex e921d49f7eced..70846c997410d 100644\n--- a/net/batman-adv/bat_v_ogm.c\n+++ b/net/batman-adv/bat_v_ogm.c\n@@ -101,6 +101,7 @@ static void batadv_v_ogm_start_queue_timer(struct batadv_hard_iface *hard_iface)\n static void batadv_v_ogm_start_timer(struct batadv_priv *bat_priv)\n {\n \tunsigned long msecs;\n+\n \t/* this function may be invoked in different contexts (ogm rescheduling\n \t * or hard_iface activation), but the work timer should not be reset\n \t */\n@@ -268,11 +269,12 @@ static void batadv_v_ogm_queue_on_if(struct sk_buff *skb,\n */\n static void batadv_v_ogm_send_meshif(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_ogm2_packet *ogm_packet;\n+\tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_ogm_buf *ogm_buff;\n-\tstruct sk_buff *skb, *skb_tmp;\n+\tstruct sk_buff *skb_tmp;\n \tstruct list_head *iter;\n+\tstruct sk_buff *skb;\n \tu16 tvlv_len;\n \tint ret;\n \n@@ -621,11 +623,11 @@ static int batadv_v_ogm_metric_update(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_hard_iface *if_incoming,\n \t\t\t\t struct batadv_hard_iface *if_outgoing)\n {\n-\tstruct batadv_orig_ifinfo *orig_ifinfo;\n \tstruct batadv_neigh_ifinfo *neigh_ifinfo = NULL;\n+\tstruct batadv_orig_ifinfo *orig_ifinfo;\n \tbool protection_started = false;\n-\tint ret = -EINVAL;\n \tu32 path_throughput;\n+\tint ret = -EINVAL;\n \ts32 seq_diff;\n \n \torig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);\n@@ -703,15 +705,17 @@ static bool batadv_v_ogm_route_update(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_hard_iface *if_incoming,\n \t\t\t\t struct batadv_hard_iface *if_outgoing)\n {\n-\tstruct batadv_neigh_node *router = NULL;\n-\tstruct batadv_orig_node *orig_neigh_node;\n \tstruct batadv_neigh_node *orig_neigh_router = NULL;\n-\tstruct batadv_neigh_ifinfo *router_ifinfo = NULL, *neigh_ifinfo = NULL;\n-\tu32 router_throughput, neigh_throughput;\n+\tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n+\tstruct batadv_neigh_ifinfo *neigh_ifinfo = NULL;\n+\tstruct batadv_orig_node *orig_neigh_node;\n+\tstruct batadv_neigh_node *router = NULL;\n+\tu32 router_throughput;\n \tu32 router_last_seqno;\n+\tu32 neigh_throughput;\n \tu32 neigh_last_seqno;\n-\ts32 neigh_seq_diff;\n \tbool forward = false;\n+\ts32 neigh_seq_diff;\n \n \torig_neigh_node = batadv_v_ogm_orig_get(bat_priv, ethhdr-\u003eh_source);\n \tif (!orig_neigh_node)\n@@ -871,14 +875,16 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,\n \t\t\t\t struct batadv_hard_iface *if_incoming)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n-\tstruct ethhdr *ethhdr;\n-\tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_hardif_neigh_node *hardif_neigh = NULL;\n \tstruct batadv_neigh_node *neigh_node = NULL;\n-\tstruct batadv_hard_iface *hard_iface;\n+\tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_ogm2_packet *ogm_packet;\n-\tu32 ogm_throughput, link_throughput, path_throughput;\n+\tstruct batadv_hard_iface *hard_iface;\n \tstruct list_head *iter;\n+\tstruct ethhdr *ethhdr;\n+\tu32 link_throughput;\n+\tu32 path_throughput;\n+\tu32 ogm_throughput;\n \tint ret;\n \n \tethhdr = eth_hdr(skb);\n@@ -1004,9 +1010,9 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb,\n \tstruct batadv_priv *bat_priv = netdev_priv(if_incoming-\u003emesh_iface);\n \tstruct batadv_ogm2_packet *ogm_packet;\n \tstruct ethhdr *ethhdr;\n+\tint ret = NET_RX_DROP;\n \tint ogm_offset;\n \tu8 *packet_pos;\n-\tint ret = NET_RX_DROP;\n \n \t/* did we receive a OGM2 packet on an interface that does not have\n \t * B.A.T.M.A.N. V enabled ?\ndiff --git a/net/batman-adv/bitarray.c b/net/batman-adv/bitarray.c\nindex 67cb356332bf1..f814756d9533f 100644\n--- a/net/batman-adv/bitarray.c\n+++ b/net/batman-adv/bitarray.c\n@@ -11,7 +11,14 @@\n \n #include \"log.h\"\n \n-/* shift the packet array by n places. */\n+/**\n+ * batadv_bitmap_shift_left() - shift the sequence number bitmap left\n+ * @seq_bits: the sequence number bitmap to shift\n+ * @n: number of positions to shift left\n+ *\n+ * Shift @seq_bits by @n positions. No-op if @n is not within the bounds of\n+ * the bitmap.\n+ */\n static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n)\n {\n \tif (n \u003c= 0 || n \u003e= BATADV_TQ_LOCAL_WINDOW_SIZE)\ndiff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c\nindex f9a1fadf8de9e..f231afbee218a 100644\n--- a/net/batman-adv/bridge_loop_avoidance.c\n+++ b/net/batman-adv/bridge_loop_avoidance.c\n@@ -177,8 +177,8 @@ static void batadv_backbone_gw_put(struct batadv_bla_backbone_gw *backbone_gw)\n */\n static void batadv_claim_release(struct kref *ref)\n {\n-\tstruct batadv_bla_claim *claim;\n \tstruct batadv_bla_backbone_gw *old_backbone_gw;\n+\tstruct batadv_bla_claim *claim;\n \n \tclaim = container_of(ref, struct batadv_bla_claim, refcount);\n \n@@ -220,9 +220,9 @@ batadv_claim_hash_find(struct batadv_priv *bat_priv,\n \t\t struct batadv_bla_claim *data)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003ebla.claim_hash;\n-\tstruct hlist_head *head;\n-\tstruct batadv_bla_claim *claim;\n \tstruct batadv_bla_claim *claim_tmp = NULL;\n+\tstruct batadv_bla_claim *claim;\n+\tstruct hlist_head *head;\n \tint index;\n \n \tif (!hash)\n@@ -260,9 +260,10 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, const u8 *addr,\n \t\t\t unsigned short vid)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003ebla.backbone_hash;\n-\tstruct hlist_head *head;\n-\tstruct batadv_bla_backbone_gw search_entry, *backbone_gw;\n \tstruct batadv_bla_backbone_gw *backbone_gw_tmp = NULL;\n+\tstruct batadv_bla_backbone_gw search_entry;\n+\tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tstruct hlist_head *head;\n \tint index;\n \n \tif (!hash)\n@@ -298,12 +299,12 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, const u8 *addr,\n static void\n batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)\n {\n+\tspinlock_t *list_lock;\t/* protects write access to the hash lists */\n+\tstruct batadv_bla_claim *claim;\n \tstruct batadv_hashtable *hash;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n-\tstruct batadv_bla_claim *claim;\n \tint i;\n-\tspinlock_t *list_lock;\t/* protects write access to the hash lists */\n \n \thash = backbone_gw-\u003ebat_priv-\u003ebla.claim_hash;\n \tif (!hash)\n@@ -324,11 +325,6 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)\n \t\t}\n \t\tspin_unlock_bh(list_lock);\n \t}\n-\n-\t/* all claims gone, initialize CRC */\n-\tspin_lock_bh(\u0026backbone_gw-\u003ecrc_lock);\n-\tbackbone_gw-\u003ecrc = BATADV_BLA_CRC_INIT;\n-\tspin_unlock_bh(\u0026backbone_gw-\u003ecrc_lock);\n }\n \n /**\n@@ -341,12 +337,12 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)\n static void batadv_bla_send_claim(struct batadv_priv *bat_priv, const u8 *mac,\n \t\t\t\t unsigned short vid, int claimtype)\n {\n-\tstruct sk_buff *skb;\n-\tstruct ethhdr *ethhdr;\n-\tstruct batadv_hard_iface *primary_if;\n-\tu8 *hw_src;\n \tstruct batadv_bla_claim_dst local_claim_dest;\n+\tstruct batadv_hard_iface *primary_if;\n+\tstruct ethhdr *ethhdr;\n+\tstruct sk_buff *skb;\n \t__be32 zeroip = 0;\n+\tu8 *hw_src;\n \n \tprimary_if = batadv_primary_if_get_selected(bat_priv);\n \tif (!primary_if)\n@@ -593,10 +589,10 @@ static void batadv_bla_answer_request(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_hard_iface *primary_if,\n \t\t\t\t unsigned short vid)\n {\n-\tstruct hlist_head *head;\n-\tstruct batadv_hashtable *hash;\n-\tstruct batadv_bla_claim *claim;\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tstruct batadv_bla_claim *claim;\n+\tstruct batadv_hashtable *hash;\n+\tstruct hlist_head *head;\n \tint i;\n \n \tbatadv_dbg(BATADV_DBG_BLA, bat_priv,\n@@ -692,14 +688,16 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_bla_backbone_gw *backbone_gw)\n {\n \tstruct batadv_bla_backbone_gw *old_backbone_gw;\n-\tstruct batadv_bla_claim *claim;\n \tstruct batadv_bla_claim search_claim;\n-\tbool remove_crc = false;\n+\tstruct batadv_bla_claim *claim;\n \tint hash_added;\n+\tu16 claim_crc;\n+\tbool changed;\n \n \tether_addr_copy(search_claim.addr, mac);\n \tsearch_claim.vid = vid;\n \tclaim = batadv_claim_hash_find(bat_priv, \u0026search_claim);\n+\tclaim_crc = crc16(0, mac, ETH_ALEN);\n \n \t/* create a new claim entry if it does not exist yet. */\n \tif (!claim) {\n@@ -731,43 +729,55 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,\n \t\t\tkfree(claim);\n \t\t\treturn;\n \t\t}\n+\n+\t\tspin_lock_bh(\u0026backbone_gw-\u003ecrc_lock);\n+\t\tbackbone_gw-\u003ecrc ^= claim_crc;\n+\t\tspin_unlock_bh(\u0026backbone_gw-\u003ecrc_lock);\n+\n+\t\tWRITE_ONCE(backbone_gw-\u003elasttime, jiffies);\n+\n+\t\tbatadv_claim_put(claim);\n+\t\treturn;\n+\t}\n+\n+\tWRITE_ONCE(claim-\u003elasttime, jiffies);\n+\n+\t/* replace backbone_gw atomically and adjust reference counters */\n+\tspin_lock_bh(\u0026claim-\u003ebackbone_lock);\n+\tif (claim-\u003ebackbone_gw != backbone_gw) {\n+\t\tchanged = true;\n+\n+\t\told_backbone_gw = claim-\u003ebackbone_gw;\n+\t\tkref_get(\u0026backbone_gw-\u003erefcount);\n+\t\tclaim-\u003ebackbone_gw = backbone_gw;\n \t} else {\n-\t\tWRITE_ONCE(claim-\u003elasttime, jiffies);\n-\t\tif (claim-\u003ebackbone_gw == backbone_gw)\n-\t\t\t/* no need to register a new backbone */\n-\t\t\tgoto claim_free_ref;\n+\t\told_backbone_gw = NULL;\n+\t\tchanged = false;\n+\t}\n+\tspin_unlock_bh(\u0026claim-\u003ebackbone_lock);\n \n+\tif (changed) {\n \t\tbatadv_dbg(BATADV_DBG_BLA, bat_priv,\n \t\t\t \"%s(): changing ownership for %pM, vid %d to gw %pM\\n\",\n \t\t\t __func__, mac, batadv_print_vid(vid),\n \t\t\t backbone_gw-\u003eorig);\n \n-\t\tremove_crc = true;\n+\t\t/* add claim address to new backbone_gw */\n+\t\tspin_lock_bh(\u0026backbone_gw-\u003ecrc_lock);\n+\t\tbackbone_gw-\u003ecrc ^= claim_crc;\n+\t\tspin_unlock_bh(\u0026backbone_gw-\u003ecrc_lock);\n \t}\n \n-\t/* replace backbone_gw atomically and adjust reference counters */\n-\tspin_lock_bh(\u0026claim-\u003ebackbone_lock);\n-\told_backbone_gw = claim-\u003ebackbone_gw;\n-\tkref_get(\u0026backbone_gw-\u003erefcount);\n-\tclaim-\u003ebackbone_gw = backbone_gw;\n-\tspin_unlock_bh(\u0026claim-\u003ebackbone_lock);\n-\n-\tif (remove_crc) {\n+\tif (old_backbone_gw) {\n \t\t/* remove claim address from old backbone_gw */\n \t\tspin_lock_bh(\u0026old_backbone_gw-\u003ecrc_lock);\n-\t\told_backbone_gw-\u003ecrc ^= crc16(0, claim-\u003eaddr, ETH_ALEN);\n+\t\told_backbone_gw-\u003ecrc ^= claim_crc;\n \t\tspin_unlock_bh(\u0026old_backbone_gw-\u003ecrc_lock);\n-\t}\n \n-\tbatadv_backbone_gw_put(old_backbone_gw);\n+\t\tbatadv_backbone_gw_put(old_backbone_gw);\n+\t}\n \n-\t/* add claim address to new backbone_gw */\n-\tspin_lock_bh(\u0026backbone_gw-\u003ecrc_lock);\n-\tbackbone_gw-\u003ecrc ^= crc16(0, claim-\u003eaddr, ETH_ALEN);\n-\tspin_unlock_bh(\u0026backbone_gw-\u003ecrc_lock);\n \tWRITE_ONCE(backbone_gw-\u003elasttime, jiffies);\n-\n-claim_free_ref:\n \tbatadv_claim_put(claim);\n }\n \n@@ -800,9 +810,10 @@ batadv_bla_claim_get_backbone_gw(struct batadv_bla_claim *claim)\n static void batadv_bla_del_claim(struct batadv_priv *bat_priv,\n \t\t\t\t const u8 *mac, const unsigned short vid)\n {\n-\tstruct batadv_bla_claim search_claim, *claim;\n \tstruct batadv_bla_claim *claim_removed_entry;\n \tstruct hlist_node *claim_removed_node;\n+\tstruct batadv_bla_claim search_claim;\n+\tstruct batadv_bla_claim *claim;\n \n \tether_addr_copy(search_claim.addr, mac);\n \tsearch_claim.vid = vid;\n@@ -842,7 +853,8 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,\n \t\t\t\t u8 *backbone_addr, unsigned short vid)\n {\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n-\tu16 backbone_crc, crc;\n+\tu16 backbone_crc;\n+\tu16 crc;\n \n \tif (memcmp(an_addr, batadv_announce_mac, 4) != 0)\n \t\treturn false;\n@@ -1019,9 +1031,10 @@ static int batadv_check_claim_group(struct batadv_priv *bat_priv,\n \t\t\t\t u8 *hw_src, u8 *hw_dst,\n \t\t\t\t struct ethhdr *ethhdr)\n {\n-\tu8 *backbone_addr;\n+\tstruct batadv_bla_claim_dst *bla_dst_own;\n+\tstruct batadv_bla_claim_dst *bla_dst;\n \tstruct batadv_orig_node *orig_node;\n-\tstruct batadv_bla_claim_dst *bla_dst, *bla_dst_own;\n+\tu8 *backbone_addr;\n \n \tbla_dst = (struct batadv_bla_claim_dst *)hw_dst;\n \tbla_dst_own = \u0026bat_priv-\u003ebla.claim_dest;\n@@ -1078,6 +1091,11 @@ static int batadv_check_claim_group(struct batadv_priv *bat_priv,\n * @primary_if: the primary hard interface of this batman mesh interface\n * @skb: the frame to be checked\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: true if it was a claim frame, otherwise return false to\n * tell the callee that it can use the frame on its own.\n */\n@@ -1085,15 +1103,18 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_hard_iface *primary_if,\n \t\t\t\t struct sk_buff *skb)\n {\n-\tstruct batadv_bla_claim_dst *bla_dst, *bla_dst_own;\n-\tu8 *hw_src, *hw_dst;\n-\tstruct vlan_hdr *vhdr, vhdr_buf;\n+\tstruct batadv_bla_claim_dst *bla_dst_own;\n+\tstruct batadv_bla_claim_dst *bla_dst;\n+\tstruct vlan_hdr vhdr_buf;\n+\tstruct vlan_hdr *vhdr;\n \tstruct ethhdr *ethhdr;\n \tstruct arphdr *arphdr;\n \tunsigned short vid;\n \tint vlan_depth = 0;\n \t__be16 proto;\n \tint headlen;\n+\tu8 *hw_src;\n+\tu8 *hw_dst;\n \tint ret;\n \n \tvid = batadv_get_vid(skb, 0);\n@@ -1225,11 +1246,11 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,\n */\n static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now)\n {\n+\tspinlock_t *list_lock;\t/* protects write access to the hash lists */\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tstruct batadv_hashtable *hash;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n-\tstruct batadv_hashtable *hash;\n-\tspinlock_t *list_lock;\t/* protects write access to the hash lists */\n \tbool purged;\n \tint i;\n \n@@ -1302,8 +1323,8 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,\n {\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n \tstruct batadv_bla_claim *claim;\n-\tstruct hlist_head *head;\n \tstruct batadv_hashtable *hash;\n+\tstruct hlist_head *head;\n \tint i;\n \n \thash = bat_priv-\u003ebla.claim_hash;\n@@ -1365,8 +1386,8 @@ void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_hard_iface *oldif)\n {\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n-\tstruct hlist_head *head;\n \tstruct batadv_hashtable *hash;\n+\tstruct hlist_head *head;\n \t__be16 group;\n \tint i;\n \n@@ -1459,14 +1480,14 @@ void batadv_bla_status_update(struct net_device *net_dev)\n */\n static void batadv_bla_periodic_work(struct work_struct *work)\n {\n+\tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tstruct batadv_hard_iface *primary_if;\n \tstruct delayed_work *delayed_work;\n-\tstruct batadv_priv *bat_priv;\n \tstruct batadv_priv_bla *priv_bla;\n-\tstruct hlist_head *head;\n-\tstruct batadv_bla_backbone_gw *backbone_gw;\n \tstruct batadv_hashtable *hash;\n-\tstruct batadv_hard_iface *primary_if;\n+\tstruct batadv_priv *bat_priv;\n \tbool send_loopdetect = false;\n+\tstruct hlist_head *head;\n \tint i;\n \n \tdelayed_work = to_delayed_work(work);\n@@ -1568,11 +1589,11 @@ static struct lock_class_key batadv_backbone_hash_lock_class_key;\n */\n int batadv_bla_init(struct batadv_priv *bat_priv)\n {\n-\tint i;\n \tu8 claim_dest[ETH_ALEN] = {0xff, 0x43, 0x05, 0x00, 0x00, 0x00};\n \tstruct batadv_hard_iface *primary_if;\n-\tu16 crc;\n \tunsigned long entrytime;\n+\tu16 crc;\n+\tint i;\n \n \tspin_lock_init(\u0026bat_priv-\u003ebla.bcast_duplist_lock);\n \n@@ -1651,8 +1672,9 @@ static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv,\n \tstruct batadv_bcast_duplist_entry *entry;\n \tbool ret = false;\n \tint payload_len;\n-\tint i, curr;\n+\tint curr;\n \tu32 crc;\n+\tint i;\n \n \t/* calculate the crc ... */\n \tpayload_len = skb-\u003elen - payload_offset;\n@@ -1774,8 +1796,8 @@ bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,\n \t\t\t\t unsigned short vid)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003ebla.backbone_hash;\n-\tstruct hlist_head *head;\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tstruct hlist_head *head;\n \tint i;\n \n \tif (!READ_ONCE(bat_priv-\u003ebridge_loop_avoidance))\n@@ -1807,6 +1829,11 @@ bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,\n * @orig_node: the orig_node of the frame\n * @hdr_size: maximum length of the frame\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * pskb_may_pull() and batadv_get_vid(). Any pointer into the skb data (e.g.\n+ * obtained from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: true if the orig_node is also a gateway on the mesh interface,\n * otherwise it returns false.\n */\n@@ -1936,9 +1963,10 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \t\t unsigned short vid, int packet_type)\n {\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n-\tstruct ethhdr *ethhdr;\n-\tstruct batadv_bla_claim search_claim, *claim = NULL;\n+\tstruct batadv_bla_claim *claim = NULL;\n+\tstruct batadv_bla_claim search_claim;\n \tstruct batadv_hard_iface *primary_if;\n+\tstruct ethhdr *ethhdr;\n \tbool own_claim;\n \tbool ret;\n \n@@ -2069,10 +2097,11 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,\n bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \t\t unsigned short vid)\n {\n-\tstruct ethhdr *ethhdr;\n-\tstruct batadv_bla_claim search_claim, *claim = NULL;\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tstruct batadv_bla_claim *claim = NULL;\n+\tstruct batadv_bla_claim search_claim;\n \tstruct batadv_hard_iface *primary_if;\n+\tstruct ethhdr *ethhdr;\n \tbool client_roamed;\n \tbool ret = false;\n \n@@ -2173,10 +2202,10 @@ batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid,\n {\n \tconst u8 *primary_addr = primary_if-\u003enet_dev-\u003edev_addr;\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n+\tint ret = -EINVAL;\n \tu16 backbone_crc;\n \tbool is_own;\n \tvoid *hdr;\n-\tint ret = -EINVAL;\n \n \thdr = genlmsg_put(msg, portid, cb-\u003enlh-\u003enlmsg_seq,\n \t\t\t \u0026batadv_netlink_family, NLM_F_MULTI,\n@@ -2335,11 +2364,11 @@ batadv_bla_backbone_dump_entry(struct sk_buff *msg, u32 portid,\n \t\t\t struct batadv_bla_backbone_gw *backbone_gw)\n {\n \tconst u8 *primary_addr = primary_if-\u003enet_dev-\u003edev_addr;\n+\tint ret = -EINVAL;\n \tu16 backbone_crc;\n \tbool is_own;\n \tint msecs;\n \tvoid *hdr;\n-\tint ret = -EINVAL;\n \n \thdr = genlmsg_put(msg, portid, cb-\u003enlh-\u003enlmsg_seq,\n \t\t\t \u0026batadv_netlink_family, NLM_F_MULTI,\n@@ -2494,10 +2523,10 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)\n bool batadv_bla_check_claim(struct batadv_priv *bat_priv,\n \t\t\t u8 *addr, unsigned short vid)\n {\n+\tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_bla_backbone_gw *backbone_gw;\n-\tstruct batadv_bla_claim search_claim;\n \tstruct batadv_bla_claim *claim = NULL;\n-\tstruct batadv_hard_iface *primary_if = NULL;\n+\tstruct batadv_bla_claim search_claim;\n \tbool ret = true;\n \n \tif (!READ_ONCE(bat_priv-\u003ebridge_loop_avoidance))\ndiff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c\nindex a6fe4820f65b9..bedd0cc76550d 100644\n--- a/net/batman-adv/distributed-arp-table.c\n+++ b/net/batman-adv/distributed-arp-table.c\n@@ -50,27 +50,65 @@\n #include \"translation-table.h\"\n #include \"tvlv.h\"\n \n+/**\n+ * enum batadv_bootpop - BOOTP/DHCP message op codes\n+ */\n enum batadv_bootpop {\n+\t/** @BATADV_BOOTREPLY: server-to-client reply */\n \tBATADV_BOOTREPLY\t= 2,\n };\n \n+/**\n+ * enum batadv_boothtype - BOOTP/DHCP hardware address types\n+ */\n enum batadv_boothtype {\n+\t/** @BATADV_HTYPE_ETHERNET: Ethernet (10Mb) */\n \tBATADV_HTYPE_ETHERNET\t= 1,\n };\n \n+/**\n+ * enum batadv_dhcpoptioncode - DHCP option codes relevant for batman-adv DAT\n+ */\n enum batadv_dhcpoptioncode {\n+\t/** @BATADV_DHCP_OPT_PAD: pad option */\n \tBATADV_DHCP_OPT_PAD\t\t= 0,\n+\n+\t/** @BATADV_DHCP_OPT_MSG_TYPE: DHCP message type option */\n \tBATADV_DHCP_OPT_MSG_TYPE\t= 53,\n+\n+\t/** @BATADV_DHCP_OPT_END: end of options marker */\n \tBATADV_DHCP_OPT_END\t\t= 255,\n };\n \n+/**\n+ * enum batadv_dhcptype - DHCP message types relevant for batman-adv DAT\n+ */\n enum batadv_dhcptype {\n+\t/** @BATADV_DHCPACK: DHCPACK message */\n \tBATADV_DHCPACK\t\t= 5,\n };\n \n /* { 99, 130, 83, 99 } */\n #define BATADV_DHCP_MAGIC 1669485411\n \n+/**\n+ * struct batadv_dhcp_packet - BOOTP/DHCP packet header\n+ * @op: message op code / message type\n+ * @htype: hardware address type\n+ * @hlen: hardware address length\n+ * @hops: number of relay hops\n+ * @xid: transaction identifier\n+ * @secs: seconds elapsed since client started trying to boot\n+ * @flags: BOOTP/DHCP flags\n+ * @ciaddr: client IP address\n+ * @yiaddr: \"your\" (client) IP address as assigned by the server\n+ * @siaddr: IP address of next server to use in bootstrap\n+ * @giaddr: relay agent IP address\n+ * @chaddr: client hardware address\n+ * @sname: optional server host name\n+ * @file: boot file name\n+ * @magic: BOOTP/DHCP magic cookie identifying the start of options\n+ */\n struct batadv_dhcp_packet {\n \t__u8 op;\n \t__u8 htype;\n@@ -90,6 +128,34 @@ struct batadv_dhcp_packet {\n \t/* __u8 options[]; */\n };\n \n+/**\n+ * struct batadv_dhcp_header - minimal BOOTP/DHCP packet header\n+ */\n+struct batadv_dhcp_header {\n+\t/** @op: message op code / message type */\n+\t__u8 op;\n+\n+\t/** @htype: hardware address type */\n+\t__u8 htype;\n+\n+\t/** @hlen: hardware address length */\n+\t__u8 hlen;\n+\n+\t/** @hops: number of relay hops */\n+\t__u8 hops;\n+};\n+\n+/**\n+ * struct batadv_dhcp_option_header - BOOTP/DHCP option header\n+ */\n+struct batadv_dhcp_option_header {\n+\t/** @type: type of option */\n+\t__u8 type;\n+\n+\t/** @len: length of option */\n+\t__u8 len;\n+};\n+\n #define BATADV_DHCP_YIADDR_LEN sizeof(((struct batadv_dhcp_packet *)0)-\u003eyiaddr)\n #define BATADV_DHCP_CHADDR_LEN sizeof(((struct batadv_dhcp_packet *)0)-\u003echaddr)\n \n@@ -250,7 +316,10 @@ static u8 *batadv_arp_hw_src(struct sk_buff *skb, int hdr_size)\n */\n static __be32 batadv_arp_ip_src(struct sk_buff *skb, int hdr_size)\n {\n-\treturn *(__force __be32 *)(batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN);\n+\tu8 *src = batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN;\n+\t__be32 *ip = (__force __be32 *)src;\n+\n+\treturn get_unaligned(ip);\n }\n \n /**\n@@ -275,8 +344,9 @@ static u8 *batadv_arp_hw_dst(struct sk_buff *skb, int hdr_size)\n static __be32 batadv_arp_ip_dst(struct sk_buff *skb, int hdr_size)\n {\n \tu8 *dst = batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN * 2 + 4;\n+\t__be32 *ip = (__force __be32 *)dst;\n \n-\treturn *(__force __be32 *)dst;\n+\treturn get_unaligned(ip);\n }\n \n /**\n@@ -288,9 +358,9 @@ static __be32 batadv_arp_ip_dst(struct sk_buff *skb, int hdr_size)\n */\n static u32 batadv_hash_dat(const void *data, u32 size)\n {\n-\tu32 hash = 0;\n \tconst struct batadv_dat_entry *dat = data;\n \tconst unsigned char *key;\n+\tu32 hash = 0;\n \t__be16 vid;\n \tu32 i;\n \n@@ -329,9 +399,11 @@ static struct batadv_dat_entry *\n batadv_dat_entry_hash_find(struct batadv_priv *bat_priv, __be32 ip,\n \t\t\t unsigned short vid)\n {\n-\tstruct hlist_head *head;\n-\tstruct batadv_dat_entry to_find, *dat_entry, *dat_entry_tmp = NULL;\n \tstruct batadv_hashtable *hash = bat_priv-\u003edat.hash;\n+\tstruct batadv_dat_entry *dat_entry_tmp = NULL;\n+\tstruct batadv_dat_entry *dat_entry;\n+\tstruct batadv_dat_entry to_find;\n+\tstruct hlist_head *head;\n \tu32 index;\n \n \tif (!hash)\n@@ -372,18 +444,19 @@ batadv_dat_entry_hash_find(struct batadv_priv *bat_priv, __be32 ip,\n static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,\n \t\t\t\t u8 *mac_addr, unsigned short vid)\n {\n+\tu64 u64_mac = ether_addr_to_u64(mac_addr);\n \tstruct batadv_dat_entry *dat_entry;\n \tint hash_added;\n \n \tdat_entry = batadv_dat_entry_hash_find(bat_priv, ip, vid);\n \t/* if this entry is already known, just update it */\n \tif (dat_entry) {\n-\t\tif (!batadv_compare_eth(dat_entry-\u003emac_addr, mac_addr))\n-\t\t\tether_addr_copy(dat_entry-\u003emac_addr, mac_addr);\n+\t\tatomic64_set(\u0026dat_entry-\u003emac_addr, u64_mac);\n+\n \t\tdat_entry-\u003elast_update = jiffies;\n \t\tbatadv_dbg(BATADV_DBG_DAT, bat_priv,\n \t\t\t \"Entry updated: %pI4 %pM (vid: %d)\\n\",\n-\t\t\t \u0026dat_entry-\u003eip, dat_entry-\u003emac_addr,\n+\t\t\t \u0026dat_entry-\u003eip, mac_addr,\n \t\t\t batadv_print_vid(vid));\n \t\tgoto out;\n \t}\n@@ -394,7 +467,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,\n \n \tdat_entry-\u003eip = ip;\n \tdat_entry-\u003evid = vid;\n-\tether_addr_copy(dat_entry-\u003emac_addr, mac_addr);\n+\tatomic64_set(\u0026dat_entry-\u003emac_addr, u64_mac);\n \tdat_entry-\u003elast_update = jiffies;\n \tkref_init(\u0026dat_entry-\u003erefcount);\n \n@@ -410,7 +483,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,\n \t}\n \n \tbatadv_dbg(BATADV_DBG_DAT, bat_priv, \"New entry added: %pI4 %pM (vid: %d)\\n\",\n-\t\t \u0026dat_entry-\u003eip, dat_entry-\u003emac_addr, batadv_print_vid(vid));\n+\t\t \u0026dat_entry-\u003eip, mac_addr, batadv_print_vid(vid));\n \n out:\n \tbatadv_dat_entry_put(dat_entry);\n@@ -432,7 +505,8 @@ static void batadv_dbg_arp(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \tstruct batadv_unicast_4addr_packet *unicast_4addr_packet;\n \tstruct batadv_bcast_packet *bcast_pkt;\n \tu8 *orig_addr;\n-\t__be32 ip_src, ip_dst;\n+\t__be32 ip_src;\n+\t__be32 ip_dst;\n \n \tif (msg)\n \t\tbatadv_dbg(BATADV_DBG_DAT, bat_priv, \"%s\\n\", msg);\n@@ -567,10 +641,11 @@ static void batadv_choose_next_candidate(struct batadv_priv *bat_priv,\n \t\t\t\t\t int select, batadv_dat_addr_t ip_key,\n \t\t\t\t\t batadv_dat_addr_t *last_max)\n {\n-\tbatadv_dat_addr_t max = 0;\n-\tbatadv_dat_addr_t tmp_max = 0;\n-\tstruct batadv_orig_node *orig_node, *max_orig_node = NULL;\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n+\tstruct batadv_orig_node *max_orig_node = NULL;\n+\tstruct batadv_orig_node *orig_node;\n+\tbatadv_dat_addr_t tmp_max = 0;\n+\tbatadv_dat_addr_t max = 0;\n \tstruct hlist_head *head;\n \tint i;\n \n@@ -634,10 +709,11 @@ static struct batadv_dat_candidate *\n batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,\n \t\t\t unsigned short vid)\n {\n-\tint select;\n-\tbatadv_dat_addr_t last_max = BATADV_DAT_ADDR_MAX, ip_key;\n+\tbatadv_dat_addr_t last_max = BATADV_DAT_ADDR_MAX;\n \tstruct batadv_dat_candidate *res;\n \tstruct batadv_dat_entry dat;\n+\tbatadv_dat_addr_t ip_key;\n+\tint select;\n \n \tif (!bat_priv-\u003eorig_hash)\n \t\treturn NULL;\n@@ -680,12 +756,12 @@ static bool batadv_dat_forward_data(struct batadv_priv *bat_priv,\n \t\t\t\t struct sk_buff *skb, __be32 ip,\n \t\t\t\t unsigned short vid, int packet_subtype)\n {\n-\tint i;\n-\tbool ret = false;\n-\tint send_status;\n \tstruct batadv_neigh_node *neigh_node = NULL;\n-\tstruct sk_buff *tmp_skb;\n \tstruct batadv_dat_candidate *cand;\n+\tstruct sk_buff *tmp_skb;\n+\tbool ret = false;\n+\tint send_status;\n+\tint i;\n \n \tcand = batadv_dat_select_candidates(bat_priv, ip, vid);\n \tif (!cand)\n@@ -864,6 +940,8 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid,\n \t\t\t struct netlink_callback *cb,\n \t\t\t struct batadv_dat_entry *dat_entry)\n {\n+\tu8 mac[ETH_ALEN];\n+\tu64 u64_mac;\n \tint msecs;\n \tvoid *hdr;\n \n@@ -876,11 +954,12 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid,\n \tgenl_dump_check_consistent(cb, hdr);\n \n \tmsecs = jiffies_to_msecs(jiffies - dat_entry-\u003elast_update);\n+\tu64_mac = atomic64_read(\u0026dat_entry-\u003emac_addr);\n+\tu64_to_ether_addr(u64_mac, mac);\n \n \tif (nla_put_in_addr(msg, BATADV_ATTR_DAT_CACHE_IP4ADDRESS,\n \t\t\t dat_entry-\u003eip) ||\n-\t nla_put(msg, BATADV_ATTR_DAT_CACHE_HWADDRESS, ETH_ALEN,\n-\t\t dat_entry-\u003emac_addr) ||\n+\t nla_put(msg, BATADV_ATTR_DAT_CACHE_HWADDRESS, ETH_ALEN, mac) ||\n \t nla_put_u16(msg, BATADV_ATTR_DAT_CACHE_VID, dat_entry-\u003evid) ||\n \t nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, msecs)) {\n \t\tgenlmsg_cancel(msg, hdr);\n@@ -993,6 +1072,11 @@ int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)\n * @skb: packet to analyse\n * @hdr_size: size of the possible header before the ARP packet in the skb\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * pskb_may_pull(). Any pointer into the skb data (e.g. obtained from skb-\u003edata\n+ * or eth_hdr()) before this call must be considered invalid afterwards and has\n+ * to be reacquired.\n+ *\n * Return: the ARP type if the skb contains a valid ARP packet, 0 otherwise.\n */\n static u16 batadv_arp_get_type(struct batadv_priv *bat_priv,\n@@ -1000,9 +1084,11 @@ static u16 batadv_arp_get_type(struct batadv_priv *bat_priv,\n {\n \tstruct arphdr *arphdr;\n \tstruct ethhdr *ethhdr;\n-\t__be32 ip_src, ip_dst;\n-\tu8 *hw_src, *hw_dst;\n+\t__be32 ip_src;\n+\t__be32 ip_dst;\n \tu16 type = 0;\n+\tu8 *hw_src;\n+\tu8 *hw_dst;\n \n \t/* pull the ethernet header */\n \tif (unlikely(!pskb_may_pull(skb, hdr_size + ETH_HLEN)))\n@@ -1069,6 +1155,11 @@ static u16 batadv_arp_get_type(struct batadv_priv *bat_priv,\n * The caller must ensure that at least @hdr_size + ETH_HLEN bytes are\n * accessible after skb-\u003edata.\n *\n+ * Warning: This function calls batadv_get_vid() and may therefore reallocate\n+ * the skb data buffer. Any pointer into the skb data (e.g. obtained from\n+ * skb-\u003edata or eth_hdr()) before this call must be considered invalid\n+ * afterwards and has to be reacquired.\n+ *\n * Return: If the packet embedded in the skb is vlan tagged this function\n * returns the VID with the BATADV_VLAN_HAS_TAG flag. Otherwise BATADV_NO_FLAGS\n * is returned.\n@@ -1131,6 +1222,11 @@ batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,\n * @bat_priv: the bat priv with all the mesh interface information\n * @skb: packet to check\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: true if the message has been sent to the dht candidates, false\n * otherwise. In case of a positive return value the message has to be enqueued\n * to permit the fallback.\n@@ -1138,15 +1234,18 @@ batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,\n bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct sk_buff *skb)\n {\n-\tu16 type = 0;\n-\t__be32 ip_dst, ip_src;\n-\tu8 *hw_src;\n-\tbool ret = false;\n+\tstruct net_device *mesh_iface = bat_priv-\u003emesh_iface;\n \tstruct batadv_dat_entry *dat_entry = NULL;\n \tstruct sk_buff *skb_new;\n-\tstruct net_device *mesh_iface = bat_priv-\u003emesh_iface;\n-\tint hdr_size = 0;\n \tunsigned short vid;\n+\tbool ret = false;\n+\tu8 mac[ETH_ALEN];\n+\tint hdr_size = 0;\n+\t__be32 ip_dst;\n+\t__be32 ip_src;\n+\tu16 type = 0;\n+\tu64 u64_mac;\n+\tu8 *hw_src;\n \n \tif (!READ_ONCE(bat_priv-\u003edistributed_arp_table))\n \t\tgoto out;\n@@ -1174,6 +1273,9 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\n \n \tdat_entry = batadv_dat_entry_hash_find(bat_priv, ip_dst, vid);\n \tif (dat_entry) {\n+\t\tu64_mac = atomic64_read(\u0026dat_entry-\u003emac_addr);\n+\t\tu64_to_ether_addr(u64_mac, mac);\n+\n \t\t/* If the ARP request is destined for a local client the local\n \t\t * client will answer itself. DAT would only generate a\n \t\t * duplicate packet.\n@@ -1182,7 +1284,7 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\n \t\t * additional DAT answer may trigger kernel warnings about\n \t\t * a packet coming from the wrong port.\n \t\t */\n-\t\tif (batadv_is_my_client(bat_priv, dat_entry-\u003emac_addr, vid)) {\n+\t\tif (batadv_is_my_client(bat_priv, mac, vid)) {\n \t\t\tret = true;\n \t\t\tgoto out;\n \t\t}\n@@ -1192,18 +1294,16 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\n \t\t * the backbone gws belonging to our backbone has claimed the\n \t\t * destination.\n \t\t */\n-\t\tif (!batadv_bla_check_claim(bat_priv,\n-\t\t\t\t\t dat_entry-\u003emac_addr, vid)) {\n+\t\tif (!batadv_bla_check_claim(bat_priv, mac, vid)) {\n \t\t\tbatadv_dbg(BATADV_DBG_DAT, bat_priv,\n \t\t\t\t \"Device %pM claimed by another backbone gw. Don't send ARP reply!\",\n-\t\t\t\t dat_entry-\u003emac_addr);\n+\t\t\t\t mac);\n \t\t\tret = true;\n \t\t\tgoto out;\n \t\t}\n \n \t\tskb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,\n-\t\t\t\t\t\t dat_entry-\u003emac_addr,\n-\t\t\t\t\t\t hw_src, vid);\n+\t\t\t\t\t\t mac, hw_src, vid);\n \t\tif (!skb_new)\n \t\t\tgoto out;\n \n@@ -1233,18 +1333,26 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\n * @skb: packet to check\n * @hdr_size: size of the encapsulation header\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: true if the request has been answered, false otherwise.\n */\n bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct sk_buff *skb, int hdr_size)\n {\n-\tu16 type;\n-\t__be32 ip_src, ip_dst;\n-\tu8 *hw_src;\n-\tstruct sk_buff *skb_new;\n \tstruct batadv_dat_entry *dat_entry = NULL;\n-\tbool ret = false;\n+\tstruct sk_buff *skb_new;\n \tunsigned short vid;\n+\tbool ret = false;\n+\tu8 mac[ETH_ALEN];\n+\t__be32 ip_src;\n+\t__be32 ip_dst;\n+\tu64 u64_mac;\n+\tu8 *hw_src;\n+\tu16 type;\n \tint err;\n \n \tif (!READ_ONCE(bat_priv-\u003edistributed_arp_table))\n@@ -1272,22 +1380,17 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,\n \tif (!dat_entry)\n \t\tgoto out;\n \n+\tu64_mac = atomic64_read(\u0026dat_entry-\u003emac_addr);\n+\tu64_to_ether_addr(u64_mac, mac);\n+\n \tskb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,\n-\t\t\t\t\t dat_entry-\u003emac_addr, hw_src, vid);\n+\t\t\t\t\t mac, hw_src, vid);\n \tif (!skb_new)\n \t\tgoto out;\n \n-\t/* To preserve backwards compatibility, the node has choose the outgoing\n-\t * format based on the incoming request packet type. The assumption is\n-\t * that a node not using the 4addr packet format doesn't support it.\n-\t */\n-\tif (hdr_size == sizeof(struct batadv_unicast_4addr_packet))\n-\t\terr = batadv_send_skb_via_tt_4addr(bat_priv, skb_new,\n-\t\t\t\t\t\t BATADV_P_DAT_CACHE_REPLY,\n-\t\t\t\t\t\t NULL, vid);\n-\telse\n-\t\terr = batadv_send_skb_via_tt(bat_priv, skb_new, NULL, vid);\n-\n+\terr = batadv_send_skb_via_tt_4addr(bat_priv, skb_new,\n+\t\t\t\t\t BATADV_P_DAT_CACHE_REPLY,\n+\t\t\t\t\t NULL, vid);\n \tif (err != NET_XMIT_DROP) {\n \t\tbatadv_inc_counter(bat_priv, BATADV_CNT_DAT_CACHED_REPLY_TX);\n \t\tret = true;\n@@ -1303,15 +1406,22 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,\n * batadv_dat_snoop_outgoing_arp_reply() - snoop the ARP reply and fill the DHT\n * @bat_priv: the bat priv with all the mesh interface information\n * @skb: packet to check\n+ *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n */\n void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct sk_buff *skb)\n {\n-\tu16 type;\n-\t__be32 ip_src, ip_dst;\n-\tu8 *hw_src, *hw_dst;\n-\tint hdr_size = 0;\n \tunsigned short vid;\n+\tint hdr_size = 0;\n+\t__be32 ip_src;\n+\t__be32 ip_dst;\n+\tu8 *hw_src;\n+\tu8 *hw_dst;\n+\tu16 type;\n \n \tif (!READ_ONCE(bat_priv-\u003edistributed_arp_table))\n \t\treturn;\n@@ -1352,6 +1462,11 @@ void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,\n * @skb: packet to check\n * @hdr_size: size of the encapsulation header\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: true if the packet was snooped and consumed by DAT. False if the\n * packet has to be delivered to the interface\n */\n@@ -1359,11 +1474,15 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct sk_buff *skb, int hdr_size)\n {\n \tstruct batadv_dat_entry *dat_entry = NULL;\n-\tu16 type;\n-\t__be32 ip_src, ip_dst;\n-\tu8 *hw_src, *hw_dst;\n \tbool dropped = false;\n \tunsigned short vid;\n+\tu8 mac[ETH_ALEN];\n+\t__be32 ip_src;\n+\t__be32 ip_dst;\n+\tu64 u64_mac;\n+\tu8 *hw_src;\n+\tu8 *hw_dst;\n+\tu16 type;\n \n \tif (!READ_ONCE(bat_priv-\u003edistributed_arp_table))\n \t\tgoto out;\n@@ -1392,11 +1511,17 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,\n \t * this frame would lead to doubled receive of an ARP reply.\n \t */\n \tdat_entry = batadv_dat_entry_hash_find(bat_priv, ip_src, vid);\n-\tif (dat_entry \u0026\u0026 batadv_compare_eth(hw_src, dat_entry-\u003emac_addr)) {\n-\t\tbatadv_dbg(BATADV_DBG_DAT, bat_priv, \"Doubled ARP reply removed: ARP MSG = [src: %pM-%pI4 dst: %pM-%pI4]; dat_entry: %pM-%pI4\\n\",\n-\t\t\t hw_src, \u0026ip_src, hw_dst, \u0026ip_dst,\n-\t\t\t dat_entry-\u003emac_addr,\t\u0026dat_entry-\u003eip);\n-\t\tdropped = true;\n+\tif (dat_entry) {\n+\t\tu64_mac = atomic64_read(\u0026dat_entry-\u003emac_addr);\n+\t\tu64_to_ether_addr(u64_mac, mac);\n+\n+\t\tif (batadv_compare_eth(hw_src, mac)) {\n+\t\t\tbatadv_dbg(BATADV_DBG_DAT, bat_priv,\n+\t\t\t\t \"Doubled ARP reply removed: ARP MSG = [src: %pM-%pI4 dst: %pM-%pI4]; dat_entry: %pM-%pI4\\n\",\n+\t\t\t\t hw_src, \u0026ip_src, hw_dst, \u0026ip_dst,\n+\t\t\t\t mac, \u0026dat_entry-\u003eip);\n+\t\t\tdropped = true;\n+\t\t}\n \t}\n \n \t/* Update our internal cache with both the IP addresses the node got\n@@ -1454,8 +1579,10 @@ static bool\n batadv_dat_check_dhcp_ipudp(struct sk_buff *skb, __be32 *ip_src)\n {\n \tunsigned int offset = skb_network_offset(skb);\n-\tstruct udphdr *udphdr, _udphdr;\n-\tstruct iphdr *iphdr, _iphdr;\n+\tstruct udphdr *udphdr;\n+\tstruct udphdr _udphdr;\n+\tstruct iphdr *iphdr;\n+\tstruct iphdr _iphdr;\n \n \tiphdr = skb_header_pointer(skb, offset, sizeof(_iphdr), \u0026_iphdr);\n \tif (!iphdr || iphdr-\u003eversion != 4 || iphdr-\u003eihl * 4 \u003c sizeof(_iphdr))\n@@ -1493,14 +1620,11 @@ batadv_dat_check_dhcp_ipudp(struct sk_buff *skb, __be32 *ip_src)\n static int\n batadv_dat_check_dhcp(struct sk_buff *skb, __be16 proto, __be32 *ip_src)\n {\n-\t__be32 *magic, _magic;\n+\tstruct batadv_dhcp_header *dhcp_h;\n+\tstruct batadv_dhcp_header _dhcp_h;\n \tunsigned int offset;\n-\tstruct {\n-\t\t__u8 op;\n-\t\t__u8 htype;\n-\t\t__u8 hlen;\n-\t\t__u8 hops;\n-\t} *dhcp_h, _dhcp_h;\n+\t__be32 *magic;\n+\t__be32 _magic;\n \n \tif (proto != htons(ETH_P_IP))\n \t\treturn -EINVAL;\n@@ -1541,11 +1665,10 @@ batadv_dat_check_dhcp(struct sk_buff *skb, __be16 proto, __be32 *ip_src)\n static int batadv_dat_get_dhcp_message_type(struct sk_buff *skb)\n {\n \tunsigned int offset = skb_transport_offset(skb) + sizeof(struct udphdr);\n-\tu8 *type, _type;\n-\tstruct {\n-\t\tu8 type;\n-\t\tu8 len;\n-\t} *tl, _tl;\n+\tstruct batadv_dhcp_option_header *tl;\n+\tstruct batadv_dhcp_option_header _tl;\n+\tu8 *type;\n+\tu8 _type;\n \n \toffset += sizeof(struct batadv_dhcp_packet);\n \n@@ -1737,7 +1860,8 @@ void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\n \t\t\t\t\tunsigned short vid)\n {\n \tu8 chaddr[BATADV_DHCP_CHADDR_LEN];\n-\t__be32 ip_src, yiaddr;\n+\t__be32 ip_src;\n+\t__be32 yiaddr;\n \n \tif (!READ_ONCE(bat_priv-\u003edistributed_arp_table))\n \t\treturn;\n@@ -1758,15 +1882,21 @@ void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\n * This function first checks whether the given skb is a valid DHCPACK. If\n * so then its source MAC and IP as well as its DHCP Client Hardware Address\n * field and DHCP Your IP Address field are added to the local DAT cache.\n+ *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * pskb_may_pull()/batadv_dat_get_vid(). Any pointer into the skb data (e.g.\n+ * obtained from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n */\n void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\n \t\t\t\t\tstruct sk_buff *skb, int hdr_size)\n {\n \tu8 chaddr[BATADV_DHCP_CHADDR_LEN];\n \tstruct ethhdr *ethhdr;\n-\t__be32 ip_src, yiaddr;\n \tunsigned short vid;\n \tint hdr_size_tmp;\n+\t__be32 ip_src;\n+\t__be32 yiaddr;\n \t__be16 proto;\n \tu8 *hw_src;\n \n@@ -1805,17 +1935,22 @@ void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\n * @bat_priv: the bat priv with all the mesh interface information\n * @forw_packet: the broadcast packet\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: true if the node can drop the packet, false otherwise.\n */\n bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_forw_packet *forw_packet)\n {\n-\tu16 type;\n-\t__be32 ip_dst;\n-\tstruct batadv_dat_entry *dat_entry = NULL;\n-\tbool ret = false;\n \tint hdr_size = sizeof(struct batadv_bcast_packet);\n+\tstruct batadv_dat_entry *dat_entry = NULL;\n \tunsigned short vid;\n+\tbool ret = false;\n+\t__be32 ip_dst;\n+\tu16 type;\n \n \tif (!READ_ONCE(bat_priv-\u003edistributed_arp_table))\n \t\tgoto out;\ndiff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c\nindex 2e20a2cb64cbf..5142a911db9ff 100644\n--- a/net/batman-adv/fragmentation.c\n+++ b/net/batman-adv/fragmentation.c\n@@ -139,15 +139,17 @@ static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,\n \t\t\t\t struct sk_buff *skb,\n \t\t\t\t struct hlist_head *chain_out)\n {\n-\tstruct batadv_frag_table_entry *chain;\n-\tstruct batadv_frag_list_entry *frag_entry_new = NULL, *frag_entry_curr;\n \tstruct batadv_frag_list_entry *frag_entry_last = NULL;\n+\tstruct batadv_frag_list_entry *frag_entry_new = NULL;\n+\tu16 hdr_size = sizeof(struct batadv_frag_packet);\n+\tstruct batadv_frag_list_entry *frag_entry_curr;\n \tstruct batadv_frag_packet *frag_packet;\n-\tu8 bucket;\n-\tu16 seqno, hdr_size = sizeof(struct batadv_frag_packet);\n+\tstruct batadv_frag_table_entry *chain;\n \tbool overflow = false;\n \tbool ret = false;\n \tsize_t data_len;\n+\tu8 bucket;\n+\tu16 seqno;\n \n \t/* Linearize packet to avoid linearizing 16 packets in a row when doing\n \t * the later merge. Non-linear merge should be added to remove this\n@@ -258,11 +260,12 @@ static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,\n static struct sk_buff *\n batadv_frag_merge_packets(struct hlist_head *chain)\n {\n-\tstruct batadv_frag_packet *packet;\n+\tint hdr_size = sizeof(struct batadv_frag_packet);\n \tstruct batadv_frag_list_entry *entry;\n+\tstruct batadv_frag_packet *packet;\n \tstruct sk_buff *skb_out;\n-\tint size, hdr_size = sizeof(struct batadv_frag_packet);\n \tbool dropped = false;\n+\tint size;\n \n \t/* Remove first entry, as this is the destination for the rest of the\n \t * fragments.\n@@ -348,8 +351,8 @@ static bool batadv_skb_is_frag(struct sk_buff *skb)\n bool batadv_frag_skb_buffer(struct sk_buff **skb,\n \t\t\t struct batadv_orig_node *orig_node_src)\n {\n-\tstruct sk_buff *skb_out = NULL;\n \tstruct hlist_head head = HLIST_HEAD_INIT;\n+\tstruct sk_buff *skb_out = NULL;\n \tbool ret = false;\n \n \t/* Add packet to buffer and table entry if merge is possible. */\n@@ -403,8 +406,8 @@ bool batadv_frag_skb_fwd(struct sk_buff *skb,\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n \tstruct batadv_neigh_node *neigh_node = NULL;\n \tstruct batadv_frag_packet *packet;\n-\tu16 total_size;\n \tbool ret = false;\n+\tu16 total_size;\n \n \tpacket = (struct batadv_frag_packet *)skb-\u003edata;\n \n@@ -468,10 +471,11 @@ static struct sk_buff *batadv_frag_create(struct net_device *net_dev,\n {\n \tunsigned int ll_reserved = LL_RESERVED_SPACE(net_dev);\n \tunsigned int tailroom = net_dev-\u003eneeded_tailroom;\n-\tstruct sk_buff *skb_fragment;\n \tunsigned int header_size = sizeof(*frag_head);\n-\tunsigned int mtu = fragment_size + header_size;\n+\tstruct sk_buff *skb_fragment;\n+\tunsigned int mtu;\n \n+\tmtu = fragment_size + header_size;\n \tskb_fragment = dev_alloc_skb(ll_reserved + mtu + tailroom);\n \tif (!skb_fragment)\n \t\tgoto err;\n@@ -503,18 +507,20 @@ int batadv_frag_send_packet(struct sk_buff *skb,\n \t\t\t struct batadv_neigh_node *neigh_node)\n {\n \tstruct net_device *net_dev = neigh_node-\u003eif_incoming-\u003enet_dev;\n-\tstruct batadv_priv *bat_priv;\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_frag_packet frag_header;\n-\tstruct sk_buff *skb_fragment;\n \tunsigned int mtu = net_dev-\u003emtu;\n-\tunsigned int header_size = sizeof(frag_header);\n-\tunsigned int max_fragment_size, num_fragments;\n+\tunsigned int max_fragment_size;\n+\tstruct batadv_priv *bat_priv;\n+\tstruct sk_buff *skb_fragment;\n+\tunsigned int num_fragments;\n+\tunsigned int header_size;\n \tint ret;\n \n \t/* To avoid merge and refragmentation at next-hops we never send\n \t * fragments larger than BATADV_FRAG_MAX_FRAG_SIZE\n \t */\n+\theader_size = sizeof(frag_header);\n \tmtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE);\n \tmax_fragment_size = mtu - header_size;\n \ndiff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c\nindex a5ac82eabd250..0dfbd3f514c1c 100644\n--- a/net/batman-adv/gateway_client.c\n+++ b/net/batman-adv/gateway_client.c\n@@ -103,8 +103,8 @@ batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv)\n struct batadv_orig_node *\n batadv_gw_get_selected_orig(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_gw_node *gw_node;\n \tstruct batadv_orig_node *orig_node = NULL;\n+\tstruct batadv_gw_node *gw_node;\n \n \tgw_node = batadv_gw_get_selected_gw_node(bat_priv);\n \tif (!gw_node)\n@@ -125,6 +125,14 @@ batadv_gw_get_selected_orig(struct batadv_priv *bat_priv)\n \treturn orig_node;\n }\n \n+/**\n+ * batadv_gw_select() - select a new currently active gateway\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @new_gw_node: gateway node to be set as the current gateway, may be NULL\n+ *\n+ * Atomically replace the currently active gateway with @new_gw_node and drop\n+ * the reference to the previous one.\n+ */\n static void batadv_gw_select(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_gw_node *new_gw_node)\n {\n@@ -197,10 +205,10 @@ void batadv_gw_check_client_stop(struct batadv_priv *bat_priv)\n */\n void batadv_gw_election(struct batadv_priv *bat_priv)\n {\n+\tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n+\tstruct batadv_neigh_node *router = NULL;\n \tstruct batadv_gw_node *curr_gw = NULL;\n \tstruct batadv_gw_node *next_gw = NULL;\n-\tstruct batadv_neigh_node *router = NULL;\n-\tstruct batadv_neigh_ifinfo *router_ifinfo = NULL;\n \tchar gw_addr[18] = { '\\0' };\n \n \tif (READ_ONCE(bat_priv-\u003egw.mode) != BATADV_GW_MODE_CLIENT)\n@@ -370,7 +378,8 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,\n struct batadv_gw_node *batadv_gw_node_get(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig_node)\n {\n-\tstruct batadv_gw_node *gw_node_tmp, *gw_node = NULL;\n+\tstruct batadv_gw_node *gw_node = NULL;\n+\tstruct batadv_gw_node *gw_node_tmp;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(gw_node_tmp, \u0026bat_priv-\u003egw.gateway_list,\n@@ -400,7 +409,8 @@ void batadv_gw_node_update(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_orig_node *orig_node,\n \t\t\t struct batadv_tvlv_gateway_data *gateway)\n {\n-\tstruct batadv_gw_node *gw_node, *curr_gw = NULL;\n+\tstruct batadv_gw_node *curr_gw = NULL;\n+\tstruct batadv_gw_node *gw_node;\n \n \tspin_lock_bh(\u0026bat_priv-\u003egw.list_lock);\n \tgw_node = batadv_gw_node_get(bat_priv, orig_node);\n@@ -558,11 +568,11 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,\n \t\t\t u8 *chaddr)\n {\n \tenum batadv_dhcp_recipient ret = BATADV_DHCP_NO;\n-\tstruct ethhdr *ethhdr;\n-\tstruct iphdr *iphdr;\n+\tstruct vlan_ethhdr *vhdr;\n \tstruct ipv6hdr *ipv6hdr;\n+\tstruct ethhdr *ethhdr;\n \tstruct udphdr *udphdr;\n-\tstruct vlan_ethhdr *vhdr;\n+\tstruct iphdr *iphdr;\n \tint chaddr_offset;\n \t__be16 proto;\n \tu8 *p;\n@@ -669,7 +679,11 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,\n * server. Due to topology changes it may be the case that the GW server\n * previously selected is not the best one anymore.\n *\n- * This call might reallocate skb data.\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_get_vid(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Must be invoked only when the DHCP packet is going TO a DHCP SERVER.\n *\n * Return: true if the packet destination is unicast and it is not the best gw,\n@@ -678,16 +692,17 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,\n bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,\n \t\t\t struct sk_buff *skb)\n {\n+\tstruct batadv_orig_node *orig_dst_node = NULL;\n \tstruct batadv_neigh_node *neigh_curr = NULL;\n \tstruct batadv_neigh_node *neigh_old = NULL;\n-\tstruct batadv_orig_node *orig_dst_node = NULL;\n+\tstruct batadv_neigh_ifinfo *curr_ifinfo;\n+\tstruct batadv_neigh_ifinfo *old_ifinfo;\n \tstruct batadv_gw_node *gw_node = NULL;\n \tstruct batadv_gw_node *curr_gw = NULL;\n-\tstruct batadv_neigh_ifinfo *curr_ifinfo, *old_ifinfo;\n-\tstruct ethhdr *ethhdr;\n \tbool out_of_range = false;\n-\tu8 curr_tq_avg;\n+\tstruct ethhdr *ethhdr;\n \tunsigned short vid;\n+\tu8 curr_tq_avg;\n \n \tvid = batadv_get_vid(skb, 0);\n \tethhdr = (struct ethhdr *)skb-\u003edata;\ndiff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c\nindex 675ebf098d4ec..65d3392050906 100644\n--- a/net/batman-adv/gateway_common.c\n+++ b/net/batman-adv/gateway_common.c\n@@ -26,7 +26,8 @@ void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv)\n {\n \tstruct batadv_tvlv_gateway_data gw;\n \tenum batadv_gw_modes gw_mode;\n-\tu32 down, up;\n+\tu32 down;\n+\tu32 up;\n \n \tgw_mode = READ_ONCE(bat_priv-\u003egw.mode);\n \n@@ -59,7 +60,8 @@ static void batadv_gw_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,\n \t\t\t\t\t u8 flags,\n \t\t\t\t\t void *tvlv_value, u16 tvlv_value_len)\n {\n-\tstruct batadv_tvlv_gateway_data gateway, *gateway_ptr;\n+\tstruct batadv_tvlv_gateway_data *gateway_ptr;\n+\tstruct batadv_tvlv_gateway_data gateway;\n \n \t/* only fetch the tvlv value if the handler wasn't called via the\n \t * CIFNOTFND flag and if there is data to fetch\ndiff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c\nindex b6867576bbafa..e7ad295504e4f 100644\n--- a/net/batman-adv/hard-interface.c\n+++ b/net/batman-adv/hard-interface.c\n@@ -197,6 +197,17 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev)\n \treturn ret;\n }\n \n+/**\n+ * batadv_is_valid_iface() - check whether a net_device can be used as a hard\n+ * interface\n+ * @net_dev: the net_device to check\n+ *\n+ * Refuse loopback devices, non-Ethernet devices, devices with a non-Ethernet\n+ * address length and any device that is already part of a batman-adv mesh\n+ * interface stack.\n+ *\n+ * Return: true if @net_dev can be used as a hard interface, false otherwise\n+ */\n static bool batadv_is_valid_iface(const struct net_device *net_dev)\n {\n \tif (net_dev-\u003eflags \u0026 IFF_LOOPBACK)\n@@ -339,8 +350,8 @@ static bool batadv_is_cfg80211_netdev(struct net_device *net_device)\n */\n static u32 batadv_wifi_flags_evaluate(struct net_device *net_device)\n {\n-\tu32 wifi_flags = 0;\n \tstruct net_device *real_netdev;\n+\tu32 wifi_flags = 0;\n \n \tif (batadv_is_wext_netdev(net_device))\n \t\twifi_flags |= BATADV_HARDIF_WIFI_WEXT_DIRECT;\n@@ -434,8 +445,8 @@ int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,\n \t\t\t u8 *orig_addr, u8 *orig_neigh)\n {\n \tstruct batadv_hardif_neigh_node *hardif_neigh;\n-\tstruct hlist_node *first;\n \tint ret = BATADV_HARDIF_BCAST_OK;\n+\tstruct hlist_node *first;\n \n \trcu_read_lock();\n \n@@ -467,6 +478,14 @@ int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,\n \treturn ret;\n }\n \n+/**\n+ * batadv_hardif_get_active() - retrieve an active hard interface for a mesh\n+ * interface\n+ * @mesh_iface: mesh interface to search\n+ *\n+ * Return: first hard interface in BATADV_IF_ACTIVE state attached to\n+ * @mesh_iface, or NULL if none is active.\n+ */\n static struct batadv_hard_iface *\n batadv_hardif_get_active(struct net_device *mesh_iface)\n {\n@@ -487,6 +506,15 @@ batadv_hardif_get_active(struct net_device *mesh_iface)\n \treturn hard_iface;\n }\n \n+/**\n+ * batadv_primary_if_update_addr() - propagate the new primary interface MAC\n+ * address to all dependent components\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @oldif: previously used primary interface, or NULL if none\n+ *\n+ * Inform DAT and BLA that the originator address has changed so they can\n+ * adjust their state accordingly.\n+ */\n static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_hard_iface *oldif)\n {\n@@ -502,6 +530,15 @@ static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,\n \tbatadv_hardif_put(primary_if);\n }\n \n+/**\n+ * batadv_primary_if_select() - select the new primary interface\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @new_hard_iface: new primary interface, may be NULL\n+ *\n+ * Replace the currently selected primary interface with @new_hard_iface,\n+ * invoke the algorithm-specific primary_set hook and update the originator\n+ * MAC address.\n+ */\n static void batadv_primary_if_select(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_hard_iface *new_hard_iface)\n {\n@@ -525,6 +562,13 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,\n \tbatadv_hardif_put(curr_hard_iface);\n }\n \n+/**\n+ * batadv_hardif_is_iface_up() - check whether the underlying net_device of a\n+ * hard interface is up\n+ * @hard_iface: the hard interface to check\n+ *\n+ * Return: true if the underlying net_device has the IFF_UP flag set\n+ */\n static bool\n batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)\n {\n@@ -534,6 +578,15 @@ batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)\n \treturn false;\n }\n \n+/**\n+ * batadv_check_known_mac_addr() - warn about duplicate hard interface MAC\n+ * addresses\n+ * @hard_iface: hard interface that was just added or had its MAC changed\n+ *\n+ * Iterate over all hard interfaces of the same mesh interface and emit a\n+ * warning if another in-use interface shares the same MAC address as\n+ * @hard_iface.\n+ */\n static void batadv_check_known_mac_addr(const struct batadv_hard_iface *hard_iface)\n {\n \tstruct net_device *mesh_iface = hard_iface-\u003emesh_iface;\n@@ -666,11 +719,20 @@ void batadv_update_min_mtu(struct net_device *mesh_iface)\n \tbatadv_tt_local_resize_to_mtu(mesh_iface);\n }\n \n+/**\n+ * batadv_hardif_activate_interface() - move a hard interface to the active\n+ * state\n+ * @hard_iface: the interface that has come up\n+ *\n+ * Activate an interface, select it as the primary interface if no\n+ * primary is currently active and invoke the algorithm-specific\n+ * activate hook.\n+ */\n static void\n batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)\n {\n-\tstruct batadv_priv *bat_priv;\n \tstruct batadv_hard_iface *primary_if = NULL;\n+\tstruct batadv_priv *bat_priv;\n \n \tif (hard_iface-\u003eif_status != BATADV_IF_INACTIVE)\n \t\tgoto out;\n@@ -699,6 +761,14 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)\n \tbatadv_hardif_put(primary_if);\n }\n \n+/**\n+ * batadv_hardif_deactivate_interface() - move a hard interface to the\n+ * inactive state\n+ * @hard_iface: the interface that went down\n+ *\n+ * Demote @hard_iface to BATADV_IF_INACTIVE and recalculate the mesh minimum\n+ * MTU based on the remaining active interfaces.\n+ */\n static void\n batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)\n {\n@@ -724,10 +794,10 @@ batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)\n int batadv_hardif_enable_interface(struct net_device *net_dev,\n \t\t\t\t struct net_device *mesh_iface)\n {\n-\tstruct batadv_priv *bat_priv;\n-\t__be16 ethertype = htons(ETH_P_BATMAN);\n \tint max_header_len = batadv_max_header_len();\n+\t__be16 ethertype = htons(ETH_P_BATMAN);\n \tstruct batadv_hard_iface *hard_iface;\n+\tstruct batadv_priv *bat_priv;\n \tunsigned int required_mtu;\n \tunsigned int hardif_mtu;\n \tbool fragmentation;\n@@ -1020,12 +1090,24 @@ static void batadv_wifi_net_device_event(unsigned long event,\n \t}\n }\n \n+/**\n+ * batadv_hard_if_event() - netdevice notifier callback for hard interfaces\n+ * @this: notifier block (unused)\n+ * @event: the NETDEV_* event to handle\n+ * @ptr: notifier info pointing to the affected net_device\n+ *\n+ * Dispatch netdevice events that affect potential or existing hard\n+ * interfaces. Mesh interfaces are handled separately by\n+ * batadv_hard_if_event_meshif().\n+ *\n+ * Return: NOTIFY_DONE\n+ */\n static int batadv_hard_if_event(struct notifier_block *this,\n \t\t\t\tunsigned long event, void *ptr)\n {\n \tstruct net_device *net_dev = netdev_notifier_info_to_dev(ptr);\n-\tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_hard_iface *primary_if = NULL;\n+\tstruct batadv_hard_iface *hard_iface;\n \tstruct batadv_priv *bat_priv;\n \n \tif (batadv_meshif_is_valid(net_dev))\ndiff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c\nindex 759fa29176db5..b9a652bd523b1 100644\n--- a/net/batman-adv/hash.c\n+++ b/net/batman-adv/hash.c\n@@ -11,7 +11,10 @@\n #include \u003clinux/lockdep.h\u003e\n #include \u003clinux/slab.h\u003e\n \n-/* clears the hash */\n+/**\n+ * batadv_hash_init() - clear all buckets of a hashtable\n+ * @hash: hashtable to clear\n+ */\n static void batadv_hash_init(struct batadv_hashtable *hash)\n {\n \tu32 i;\ndiff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h\nindex 86a2c20000dcf..755ced52a01c5 100644\n--- a/net/batman-adv/hash.h\n+++ b/net/batman-adv/hash.h\n@@ -18,21 +18,35 @@\n #include \u003clinux/stddef.h\u003e\n #include \u003clinux/types.h\u003e\n \n-/* callback to a compare function. should compare 2 element data for their\n- * keys\n+/**\n+ * typedef batadv_hashdata_compare_cb - hash element comparison callback\n+ * @node: hlist node of the element currently stored in the bucket\n+ * @key: opaque payload to compare @node's key against\n+ *\n+ * Compare hash element by its keys.\n+ *\n+ * Return: true if both elements are considered equal, false otherwise.\n+ */\n+typedef bool (*batadv_hashdata_compare_cb)(const struct hlist_node *node,\n+\t\t\t\t\t const void *key);\n+\n+/**\n+ * typedef batadv_hashdata_choose_cb - hash bucket selection callback\n+ * @key: opaque payload whose key selects the bucket\n+ * @size: number of buckets in the hash table\n *\n- * Return: true if same and false if not same\n+ * Return: bucket index derived from the key in @data and the table @size.\n */\n-typedef bool (*batadv_hashdata_compare_cb)(const struct hlist_node *,\n-\t\t\t\t\t const void *);\n+typedef u32 (*batadv_hashdata_choose_cb)(const void *key, u32 size);\n \n-/* the hashfunction\n+/**\n+ * typedef batadv_hashdata_free_cb - hash element free callback\n+ * @node: hlist node of the element being removed\n+ * @arg: opaque caller-supplied argument forwarded from the caller\n *\n- * Return: an index based on the key in the data of the first argument and the\n- * size the second\n+ * Release a previously inserted hash element.\n */\n-typedef u32 (*batadv_hashdata_choose_cb)(const void *, u32);\n-typedef void (*batadv_hashdata_free_cb)(struct hlist_node *, void *);\n+typedef void (*batadv_hashdata_free_cb)(struct hlist_node *node, void *arg);\n \n /**\n * struct batadv_hashtable - Wrapper of simple hlist based hashtable\n@@ -78,11 +92,11 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash,\n \t\t\t\t const void *data,\n \t\t\t\t struct hlist_node *data_node)\n {\n-\tu32 index;\n-\tint ret = -1;\n+\tspinlock_t *list_lock; /* spinlock to protect write access */\n \tstruct hlist_head *head;\n \tstruct hlist_node *node;\n-\tspinlock_t *list_lock; /* spinlock to protect write access */\n+\tint ret = -1;\n+\tu32 index;\n \n \tif (!hash)\n \t\tgoto out;\n@@ -131,10 +145,10 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash,\n \t\t\t\t batadv_hashdata_choose_cb choose,\n \t\t\t\t void *data)\n {\n-\tu32 index;\n \tstruct hlist_node *node;\n \tstruct hlist_head *head;\n \tvoid *data_save = NULL;\n+\tu32 index;\n \n \tindex = choose(data, hash-\u003esize);\n \thead = \u0026hash-\u003etable[index];\ndiff --git a/net/batman-adv/log.h b/net/batman-adv/log.h\nindex a0d2b0d64b2b0..9f3aed826dea6 100644\n--- a/net/batman-adv/log.h\n+++ b/net/batman-adv/log.h\n@@ -117,8 +117,12 @@ static inline void _batadv_dbg(int type __always_unused,\n */\n #define batadv_info(net_dev, fmt, arg...)\t\t\t\t\\\n \tdo {\t\t\t\t\t\t\t\t\\\n-\t\tstruct net_device *_netdev = (net_dev); \\\n-\t\tstruct batadv_priv *_batpriv = netdev_priv(_netdev); \\\n+\t\tstruct batadv_priv *_batpriv;\t\t\t\t\\\n+\t\tstruct net_device *_netdev;\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\t\t_netdev = (net_dev);\t\t\t\t\t\\\n+\t\t_batpriv = netdev_priv(_netdev);\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n \t\tbatadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg);\t\\\n \t\tpr_info(\"%s: \" fmt, _netdev-\u003ename, ## arg);\t\t\\\n \t} while (0)\n@@ -131,8 +135,12 @@ static inline void _batadv_dbg(int type __always_unused,\n */\n #define batadv_err(net_dev, fmt, arg...)\t\t\t\t\\\n \tdo {\t\t\t\t\t\t\t\t\\\n-\t\tstruct net_device *_netdev = (net_dev); \\\n-\t\tstruct batadv_priv *_batpriv = netdev_priv(_netdev); \\\n+\t\tstruct batadv_priv *_batpriv;\t\t\t\t\\\n+\t\tstruct net_device *_netdev;\t\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n+\t\t_netdev = (net_dev);\t\t\t\t\t\\\n+\t\t_batpriv = netdev_priv(_netdev);\t\t\t\\\n+\t\t\t\t\t\t\t\t\t\\\n \t\tbatadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg);\t\\\n \t\tpr_err(\"%s: \" fmt, _netdev-\u003ename, ## arg);\t\t\\\n \t} while (0)\ndiff --git a/net/batman-adv/main.c b/net/batman-adv/main.c\nindex 73becb0549488..5981e8eb6d979 100644\n--- a/net/batman-adv/main.c\n+++ b/net/batman-adv/main.c\n@@ -82,6 +82,14 @@ static char *batadv_uev_type_str[] = {\n \t\"bla\",\n };\n \n+/**\n+ * batadv_init() - batman-adv module init function\n+ *\n+ * Initialise the global state used by all mesh interfaces, register the\n+ * netdevice notifier and the netlink/rtnl family.\n+ *\n+ * Return: 0 on success or negative error number in case of failure\n+ */\n static int __init batadv_init(void)\n {\n \tint ret;\n@@ -128,6 +136,12 @@ static int __init batadv_init(void)\n \treturn ret;\n }\n \n+/**\n+ * batadv_exit() - batman-adv module exit function\n+ *\n+ * Unregister the netdevice notifier and tear down all global state allocated\n+ * by batadv_init().\n+ */\n static void __exit batadv_exit(void)\n {\n \tbatadv_netlink_unregister();\n@@ -354,10 +368,14 @@ int batadv_max_header_len(void)\n */\n void batadv_skb_set_priority(struct sk_buff *skb, int offset)\n {\n-\tstruct iphdr ip_hdr_tmp, *ip_hdr;\n-\tstruct ipv6hdr ip6_hdr_tmp, *ip6_hdr;\n-\tstruct ethhdr ethhdr_tmp, *ethhdr;\n-\tstruct vlan_ethhdr *vhdr, vhdr_tmp;\n+\tstruct vlan_ethhdr vhdr_tmp;\n+\tstruct ipv6hdr ip6_hdr_tmp;\n+\tstruct ethhdr ethhdr_tmp;\n+\tstruct vlan_ethhdr *vhdr;\n+\tstruct iphdr ip_hdr_tmp;\n+\tstruct ipv6hdr *ip6_hdr;\n+\tstruct ethhdr *ethhdr;\n+\tstruct iphdr *ip_hdr;\n \tu32 prio;\n \n \t/* already set, do nothing */\n@@ -398,6 +416,17 @@ void batadv_skb_set_priority(struct sk_buff *skb, int offset)\n \tskb-\u003epriority = prio + 256;\n }\n \n+/**\n+ * batadv_recv_unhandled_packet() - default RX handler for unsupported packet\n+ * types\n+ * @skb: incoming packet\n+ * @recv_if: interface on which the packet was received (unused)\n+ *\n+ * Drop incoming packets whose packet_type has no dedicated RX handler\n+ * registered.\n+ *\n+ * Return: NET_RX_DROP\n+ */\n static int batadv_recv_unhandled_packet(struct sk_buff *skb,\n \t\t\t\t\tstruct batadv_hard_iface *recv_if)\n {\n@@ -406,10 +435,6 @@ static int batadv_recv_unhandled_packet(struct sk_buff *skb,\n \treturn NET_RX_DROP;\n }\n \n-/* incoming packets with the batman ethertype received on any active hard\n- * interface\n- */\n-\n /**\n * batadv_batman_skb_recv() - Handle incoming message from an hard interface\n * @skb: the received packet\n@@ -423,9 +448,9 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,\n \t\t\t struct packet_type *ptype,\n \t\t\t struct net_device *orig_dev)\n {\n-\tstruct batadv_priv *bat_priv;\n \tstruct batadv_ogm_packet *batadv_ogm_packet;\n \tstruct batadv_hard_iface *hard_iface;\n+\tstruct batadv_priv *bat_priv;\n \tu8 idx;\n \n \thard_iface = container_of(ptype, struct batadv_hard_iface,\n@@ -492,6 +517,13 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,\n \treturn NET_RX_DROP;\n }\n \n+/**\n+ * batadv_recv_handler_init() - initialise the RX handler dispatch table\n+ *\n+ * Initialise all entries of the RX handler table (+ unused to the\n+ * default drop handler) and perform compile-time size sanity checks on\n+ * all on-wire packet structs.\n+ */\n static void batadv_recv_handler_init(void)\n {\n \tint i;\n@@ -582,6 +614,11 @@ void batadv_recv_handler_unregister(u8 packet_type)\n * The caller must ensure that at least @header_len + ETH_HLEN bytes are\n * accessible after skb-\u003edata.\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * pskb_may_pull(). Any pointer into the skb data (e.g. obtained from skb-\u003edata\n+ * or eth_hdr()) before this call must be considered invalid afterwards and has\n+ * to be reacquired.\n+ *\n * Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the\n * skb is vlan tagged. Otherwise BATADV_NO_FLAGS.\n */\n@@ -650,9 +687,9 @@ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)\n int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,\n \t\t\tenum batadv_uev_action action, const char *data)\n {\n-\tint ret = -ENOMEM;\n-\tstruct kobject *bat_kobj;\n \tchar *uevent_env[4] = { NULL, NULL, NULL, NULL };\n+\tstruct kobject *bat_kobj;\n+\tint ret = -ENOMEM;\n \n \tbat_kobj = \u0026bat_priv-\u003emesh_iface-\u003edev.kobj;\n \ndiff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c\nindex 1dc6cfae9e9ae..90830b10403f3 100644\n--- a/net/batman-adv/mesh-interface.c\n+++ b/net/batman-adv/mesh-interface.c\n@@ -57,6 +57,11 @@\n * @skb: packet buffer which should be modified\n * @len: number of bytes to add\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * skb_cow_head(). Any pointer into the skb data (e.g. obtained\n+ * from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n * Return: 0 on success or negative error number in case of failure\n */\n int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)\n@@ -87,7 +92,8 @@ int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)\n */\n static u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx)\n {\n-\tu64 *counters, sum = 0;\n+\tu64 *counters;\n+\tu64 sum = 0;\n \tint cpu;\n \n \tfor_each_possible_cpu(cpu) {\n@@ -98,6 +104,15 @@ static u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx)\n \treturn sum;\n }\n \n+/**\n+ * batadv_interface_stats() - return netdev stats for a mesh interface\n+ * @dev: the mesh interface to query\n+ *\n+ * Aggregate the per-CPU traffic counters into the standard netdev stats\n+ * structure.\n+ *\n+ * Return: pointer to the populated net_device_stats structure\n+ */\n static struct net_device_stats *batadv_interface_stats(struct net_device *dev)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(dev);\n@@ -111,6 +126,18 @@ static struct net_device_stats *batadv_interface_stats(struct net_device *dev)\n \treturn stats;\n }\n \n+/**\n+ * batadv_interface_set_mac_addr() - change the MAC address of a mesh\n+ * interface\n+ * @dev: the mesh interface to modify\n+ * @p: pointer to a struct sockaddr holding the new MAC address\n+ *\n+ * Replace the MAC address of the mesh interface. If the mesh is already\n+ * active, also update the local translation table entries for all configured\n+ * VLANs so that the new MAC is announced and the old one is removed.\n+ *\n+ * Return: 0 on success or negative error number in case of failure\n+ */\n static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(dev);\n@@ -140,6 +167,16 @@ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)\n \treturn 0;\n }\n \n+/**\n+ * batadv_interface_change_mtu() - change the MTU of a mesh interface\n+ * @dev: the mesh interface to modify\n+ * @new_mtu: requested new MTU value\n+ *\n+ * Validate that @new_mtu fits within the range supported by the configured\n+ * hard interfaces and remember it as the user-configured MTU.\n+ *\n+ * Return: 0 on success or -EINVAL if @new_mtu is out of range\n+ */\n static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(dev);\n@@ -166,31 +203,39 @@ static void batadv_interface_set_rx_mode(struct net_device *dev)\n {\n }\n \n+/**\n+ * batadv_interface_tx() - transmit a frame on a mesh interface\n+ * @skb: the frame to send\n+ * @mesh_iface: the mesh interface the frame was queued on\n+ *\n+ * Return: NETDEV_TX_OK on success\n+ */\n static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n \t\t\t\t struct net_device *mesh_iface)\n {\n-\tstruct ethhdr *ethhdr;\n+\tstatic const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00, 0x00, 0x00};\n+\tstatic const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x00};\n \tstruct batadv_priv *bat_priv = netdev_priv(mesh_iface);\n+\tenum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;\n+\tenum batadv_forw_mode forw_mode = BATADV_FORW_BCAST;\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_bcast_packet *bcast_packet;\n-\tstatic const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,\n-\t\t\t\t\t 0x00, 0x00};\n-\tstatic const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,\n-\t\t\t\t\t 0x00, 0x00};\n-\tenum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;\n-\tu8 *dst_hint = NULL, chaddr[ETH_ALEN];\n-\tstruct vlan_ethhdr *vhdr;\n+\tint network_offset = ETH_HLEN;\n \tunsigned int header_len = 0;\n-\tint data_len = skb-\u003elen, ret;\n \tunsigned long brd_delay = 0;\n-\tbool do_bcast = false, client_added;\n-\tunsigned short vid;\n-\tu32 seqno;\n-\tint gw_mode;\n-\tenum batadv_forw_mode forw_mode = BATADV_FORW_BCAST;\n \tint mcast_is_routable = 0;\n-\tint network_offset = ETH_HLEN;\n+\tstruct vlan_ethhdr *vhdr;\n+\tint data_len = skb-\u003elen;\n+\tstruct ethhdr *ethhdr;\n+\tbool do_bcast = false;\n+\tu8 *dst_hint = NULL;\n+\tu8 chaddr[ETH_ALEN];\n+\tunsigned short vid;\n+\tbool client_added;\n \t__be16 proto;\n+\tint gw_mode;\n+\tu32 seqno;\n+\tint ret;\n \n \tif (READ_ONCE(bat_priv-\u003emesh_state) != BATADV_MESH_ACTIVE)\n \t\tgoto dropped;\n@@ -260,6 +305,8 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n \tif (batadv_compare_eth(ethhdr-\u003eh_dest, ectp_addr))\n \t\tgoto dropped;\n \n+\tbatadv_skb_set_priority(skb, 0);\n+\n \tgw_mode = READ_ONCE(bat_priv-\u003egw.mode);\n \tif (is_multicast_ether_addr(ethhdr-\u003eh_dest)) {\n \t\t/* if gw mode is off, broadcast every packet */\n@@ -293,6 +340,9 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n \n send:\n \t\tif (do_bcast \u0026\u0026 !is_broadcast_ether_addr(ethhdr-\u003eh_dest)) {\n+\t\t\t/* WARNING batadv_mcast_forw_mode might add more headers\n+\t\t\t * in front of the skb. and might even reallocate the skb\n+\t\t\t */\n \t\t\tforw_mode = batadv_mcast_forw_mode(bat_priv, skb, vid,\n \t\t\t\t\t\t\t \u0026mcast_is_routable);\n \t\t\tswitch (forw_mode) {\n@@ -310,8 +360,6 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n \t\t}\n \t}\n \n-\tbatadv_skb_set_priority(skb, 0);\n-\n \t/* ethernet packet should be broadcasted */\n \tif (do_bcast) {\n \t\tprimary_if = batadv_primary_if_get_selected(bat_priv);\n@@ -408,8 +456,8 @@ void batadv_interface_rx(struct net_device *mesh_iface,\n \t\t\t struct sk_buff *skb, int hdr_size,\n \t\t\t struct batadv_orig_node *orig_node)\n {\n-\tstruct batadv_bcast_packet *batadv_bcast_packet;\n \tstruct batadv_priv *bat_priv = netdev_priv(mesh_iface);\n+\tstruct batadv_bcast_packet *batadv_bcast_packet;\n \tstruct vlan_ethhdr *vhdr;\n \tstruct ethhdr *ethhdr;\n \tunsigned short vid;\n@@ -523,7 +571,8 @@ void batadv_meshif_vlan_release(struct kref *ref)\n struct batadv_meshif_vlan *batadv_meshif_vlan_get(struct batadv_priv *bat_priv,\n \t\t\t\t\t\t unsigned short vid)\n {\n-\tstruct batadv_meshif_vlan *vlan_tmp, *vlan = NULL;\n+\tstruct batadv_meshif_vlan *vlan = NULL;\n+\tstruct batadv_meshif_vlan *vlan_tmp;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(vlan_tmp, \u0026bat_priv-\u003emeshif_vlan_list, list) {\n@@ -741,10 +790,10 @@ static void batadv_set_lockdep_class(struct net_device *dev)\n */\n static int batadv_meshif_init_late(struct net_device *dev)\n {\n+\tsize_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;\n \tstruct batadv_priv *bat_priv;\n \tu32 random_seqno;\n \tint ret;\n-\tsize_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;\n \n \tbatadv_set_lockdep_class(dev);\n \n@@ -883,6 +932,11 @@ static const struct net_device_ops batadv_netdev_ops = {\n \t.ndo_del_slave = batadv_meshif_slave_del,\n };\n \n+/**\n+ * batadv_get_drvinfo() - ethtool driver info handler for mesh interfaces\n+ * @dev: the mesh interface (unused)\n+ * @info: ethtool_drvinfo struct to populate\n+ */\n static void batadv_get_drvinfo(struct net_device *dev,\n \t\t\t struct ethtool_drvinfo *info)\n {\n@@ -943,6 +997,12 @@ static const struct {\n #endif\n };\n \n+/**\n+ * batadv_get_strings() - ethtool string handler for mesh interfaces\n+ * @dev: the mesh interface (unused)\n+ * @stringset: ethtool string set to retrieve\n+ * @data: buffer to copy the requested string set into\n+ */\n static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data)\n {\n \tif (stringset == ETH_SS_STATS)\n@@ -950,6 +1010,12 @@ static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data)\n \t\t sizeof(batadv_counters_strings));\n }\n \n+/**\n+ * batadv_get_ethtool_stats() - ethtool stats handler for mesh interfaces\n+ * @dev: the mesh interface to query\n+ * @stats: ethtool_stats struct (unused)\n+ * @data: destination array for the gathered counter values\n+ */\n static void batadv_get_ethtool_stats(struct net_device *dev,\n \t\t\t\t struct ethtool_stats *stats, u64 *data)\n {\n@@ -960,6 +1026,14 @@ static void batadv_get_ethtool_stats(struct net_device *dev,\n \t\tdata[i] = batadv_sum_counter(bat_priv, i);\n }\n \n+/**\n+ * batadv_get_sset_count() - ethtool stringset size handler for mesh interfaces\n+ * @dev: the mesh interface (unused)\n+ * @stringset: ethtool string set to query\n+ *\n+ * Return: number of entries in @stringset or -EOPNOTSUPP if @stringset is not\n+ * supported\n+ */\n static int batadv_get_sset_count(struct net_device *dev, int stringset)\n {\n \tif (stringset == ETH_SS_STATS)\ndiff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c\nindex 1c5315e55c046..929dca6f21f50 100644\n--- a/net/batman-adv/multicast.c\n+++ b/net/batman-adv/multicast.c\n@@ -274,8 +274,9 @@ static struct batadv_mcast_mla_flags\n batadv_mcast_mla_flags_get(struct batadv_priv *bat_priv)\n {\n \tstruct net_device *dev = bat_priv-\u003emesh_iface;\n-\tstruct batadv_mcast_querier_state *qr4, *qr6;\n \tstruct batadv_mcast_mla_flags mla_flags;\n+\tstruct batadv_mcast_querier_state *qr4;\n+\tstruct batadv_mcast_querier_state *qr6;\n \tstruct net_device *bridge;\n \n \tbridge = batadv_mcast_get_bridge(dev);\n@@ -521,7 +522,8 @@ batadv_mcast_mla_meshif_get(struct net_device *dev,\n \t\t\t struct batadv_mcast_mla_flags *flags)\n {\n \tstruct net_device *bridge = batadv_mcast_get_bridge(dev);\n-\tint ret4, ret6 = 0;\n+\tint ret6 = 0;\n+\tint ret4;\n \n \tif (bridge)\n \t\tdev = bridge;\n@@ -585,10 +587,11 @@ static int batadv_mcast_mla_bridge_get(struct net_device *dev,\n \t\t\t\t struct batadv_mcast_mla_flags *flags)\n {\n \tstruct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list);\n-\tstruct br_ip_list *br_ip_entry, *tmp;\n \tu8 tvlv_flags = flags-\u003etvlv_flags;\n+\tstruct br_ip_list *br_ip_entry;\n \tstruct batadv_hw_addr *new;\n \tu8 mcast_addr[ETH_ALEN];\n+\tstruct br_ip_list *tmp;\n \tint ret;\n \n \t/* we don't need to detect these devices/listeners, the IGMP/MLD\n@@ -935,8 +938,8 @@ static void __batadv_mcast_mla_update(struct batadv_priv *bat_priv)\n */\n static void batadv_mcast_mla_update(struct work_struct *work)\n {\n-\tstruct delayed_work *delayed_work;\n \tstruct batadv_priv_mcast *priv_mcast;\n+\tstruct delayed_work *delayed_work;\n \tstruct batadv_priv *bat_priv;\n \n \tdelayed_work = to_delayed_work(work);\n@@ -1223,10 +1226,14 @@ enum batadv_forw_mode\n batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \t\t unsigned short vid, int *is_routable)\n {\n-\tint ret, tt_count, ip_count, unsnoop_count, total_count;\n \tbool is_unsnoopable = false;\n \tstruct ethhdr *ethhdr;\n+\tint unsnoop_count;\n \tint rtr_count = 0;\n+\tint total_count;\n+\tint tt_count;\n+\tint ip_count;\n+\tint ret;\n \n \tret = batadv_mcast_forw_mode_check(bat_priv, skb, \u0026is_unsnoopable,\n \t\t\t\t\t is_routable);\n@@ -1301,13 +1308,11 @@ static int\n batadv_mcast_forw_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \t\t unsigned short vid)\n {\n-\tint ret = NET_XMIT_SUCCESS;\n-\tstruct sk_buff *newskb;\n-\n \tstruct batadv_tt_orig_list_entry *orig_entry;\n-\n \tstruct batadv_tt_global_entry *tt_global;\n \tconst u8 *addr = eth_hdr(skb)-\u003eh_dest;\n+\tint ret = NET_XMIT_SUCCESS;\n+\tstruct sk_buff *newskb;\n \n \ttt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);\n \tif (!tt_global)\n@@ -1602,8 +1607,8 @@ static void batadv_mcast_want_unsnoop_update(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig,\n \t\t\t\t\t u8 mcast_flags)\n {\n-\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_unsnoopables_node;\n \tstruct hlist_head *head = \u0026bat_priv-\u003emcast.want_all_unsnoopables_list;\n+\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_unsnoopables_node;\n \n \tlockdep_assert_held(\u0026orig-\u003emcast_handler_lock);\n \n@@ -1647,8 +1652,8 @@ static void batadv_mcast_want_ipv4_update(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig,\n \t\t\t\t\t u8 mcast_flags)\n {\n-\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_ipv4_node;\n \tstruct hlist_head *head = \u0026bat_priv-\u003emcast.want_all_ipv4_list;\n+\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_ipv4_node;\n \n \tlockdep_assert_held(\u0026orig-\u003emcast_handler_lock);\n \n@@ -1692,8 +1697,8 @@ static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig,\n \t\t\t\t\t u8 mcast_flags)\n {\n-\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_ipv6_node;\n \tstruct hlist_head *head = \u0026bat_priv-\u003emcast.want_all_ipv6_list;\n+\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_ipv6_node;\n \n \tlockdep_assert_held(\u0026orig-\u003emcast_handler_lock);\n \n@@ -1737,8 +1742,8 @@ static void batadv_mcast_want_rtr4_update(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig,\n \t\t\t\t\t u8 mcast_flags)\n {\n-\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_rtr4_node;\n \tstruct hlist_head *head = \u0026bat_priv-\u003emcast.want_all_rtr4_list;\n+\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_rtr4_node;\n \n \tlockdep_assert_held(\u0026orig-\u003emcast_handler_lock);\n \n@@ -1782,8 +1787,8 @@ static void batadv_mcast_want_rtr6_update(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig,\n \t\t\t\t\t u8 mcast_flags)\n {\n-\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_rtr6_node;\n \tstruct hlist_head *head = \u0026bat_priv-\u003emcast.want_all_rtr6_list;\n+\tstruct hlist_node *node = \u0026orig-\u003emcast_want_all_rtr6_node;\n \n \tlockdep_assert_held(\u0026orig-\u003emcast_handler_lock);\n \ndiff --git a/net/batman-adv/multicast_forw.c b/net/batman-adv/multicast_forw.c\nindex 1404a3b7adfb1..ccd4ae158dcd3 100644\n--- a/net/batman-adv/multicast_forw.c\n+++ b/net/batman-adv/multicast_forw.c\n@@ -195,8 +195,8 @@ static int batadv_mcast_forw_push_dests_list(struct batadv_priv *bat_priv,\n \t\t\t\t\t unsigned short *num_dests,\n \t\t\t\t\t unsigned short *tvlv_len)\n {\n-\tstruct hlist_node *node;\n \tstruct batadv_orig_node *orig_node;\n+\tstruct hlist_node *node;\n \n \trcu_read_lock();\n \t__hlist_for_each_rcu(node, head) {\n@@ -232,12 +232,9 @@ batadv_mcast_forw_push_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \t\t\t unsigned short *tvlv_len)\n {\n \tstruct batadv_tt_orig_list_entry *orig_entry;\n-\n \tstruct batadv_tt_global_entry *tt_global;\n \tconst u8 *addr = eth_hdr(skb)-\u003eh_dest;\n-\n-\t/* ok */\n-\tint ret = true;\n+\tint ret = true; /* ok */\n \n \ttt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);\n \tif (!tt_global)\n@@ -368,7 +365,8 @@ static void batadv_mcast_forw_scrape(struct sk_buff *skb,\n \t\t\t\t unsigned short offset,\n \t\t\t\t unsigned short len)\n {\n-\tchar *to, *from;\n+\tchar *from;\n+\tchar *to;\n \n \tSKB_LINEAR_ASSERT(skb);\n \n@@ -411,7 +409,8 @@ static bool batadv_mcast_forw_push_insert_padding(struct sk_buff *skb,\n \t\t\t\t\t\t unsigned short *tvlv_len)\n {\n \tunsigned short offset =\t*tvlv_len;\n-\tchar *to, *from = skb-\u003edata;\n+\tchar *from = skb-\u003edata;\n+\tchar *to;\n \n \tto = batadv_mcast_forw_push_padding(skb, tvlv_len);\n \tif (!to)\n@@ -933,8 +932,9 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv,\n \tunsigned int tvlv_len;\n \tunsigned long offset;\n \tbool xmitted = false;\n-\tu8 *dest, *next_dest;\n+\tu8 *next_dest;\n \tu16 num_dests;\n+\tu8 *dest;\n \tint ret;\n \n \t/* (at least) TVLV part needs to be linearized */\n@@ -1080,6 +1080,11 @@ unsigned int batadv_mcast_forw_packet_hdrlen(unsigned int num_dests)\n * Tries to expand an skb's headroom so that its head to tail is 1298\n * bytes (minimum IPv6 MTU + vlan ethernet header size) large.\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * skb_cow() / skb_linearize(). Any pointer into the skb data (e.g.\n+ * obtained from skb-\u003edata or eth_hdr()) before this call must be\n+ * considered invalid afterwards and has to be reacquired.\n+ *\n * Return: -EINVAL if the given skb's length is too large or -ENOMEM on memory\n * allocation failure. Otherwise, on success, zero is returned.\n */\n@@ -1100,8 +1105,11 @@ static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv,\n \t\treturn -EINVAL;\n \t}\n \n-\tif (skb_headroom(skb) \u003c hdr_size \u0026\u0026\n-\t pskb_expand_head(skb, hdr_size, 0, GFP_ATOMIC) \u003c 0)\n+\tif (skb_cow(skb, hdr_size) \u003c 0)\n+\t\treturn -ENOMEM;\n+\n+\t/* batadv_mcast_forw_scrape() + batadv_mcast_forw_packet() require linearized skb */\n+\tif (skb_linearize(skb) \u003c 0)\n \t\treturn -ENOMEM;\n \n \treturn 0;\n@@ -1120,6 +1128,11 @@ static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv,\n * that signaled interest in it, that is either via the translation table or the\n * according want-all flags, is attached accordingly.\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * batadv_mcast_forw_expand_head(). Any pointer into the skb data (e.g.\n+ * obtained from skb-\u003edata or eth_hdr()) before this call must be\n+ * considered invalid afterwards and has to be reacquired.\n+ *\n * Return: true on success, false otherwise.\n */\n bool batadv_mcast_forw_push(struct batadv_priv *bat_priv, struct sk_buff *skb,\ndiff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c\nindex d2bc48c707143..926210a67d640 100644\n--- a/net/batman-adv/netlink.c\n+++ b/net/batman-adv/netlink.c\n@@ -52,9 +52,15 @@\n \n struct genl_family batadv_netlink_family;\n \n-/* multicast groups */\n+/**\n+ * enum batadv_netlink_multicast_groups - batman-adv generic netlink multicast\n+ * groups\n+ */\n enum batadv_netlink_multicast_groups {\n+\t/** @BATADV_NL_MCGRP_CONFIG: configuration change notifications */\n \tBATADV_NL_MCGRP_CONFIG,\n+\n+\t/** @BATADV_NL_MCGRP_TPMETER: throughput meter result notifications */\n \tBATADV_NL_MCGRP_TPMETER,\n };\n \n@@ -746,8 +752,8 @@ static int\n batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info)\n {\n \tstruct batadv_priv *bat_priv = info-\u003euser_ptr[0];\n-\tu8 *dst;\n \tint ret = 0;\n+\tu8 *dst;\n \n \tif (!info-\u003eattrs[BATADV_ATTR_ORIG_ADDRESS])\n \t\treturn -EINVAL;\n@@ -953,10 +959,10 @@ static int batadv_netlink_set_hardif(struct sk_buff *skb,\n static int\n batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb)\n {\n-\tstruct net_device *mesh_iface;\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \tstruct batadv_hard_iface *hard_iface;\n+\tstruct net_device *mesh_iface;\n \tstruct batadv_priv *bat_priv;\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n \tint skip = cb-\u003eargs[0];\n \tstruct list_head *iter;\n \tint i = 0;\ndiff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c\nindex 48f837cf665a2..f06583ef9b3f5 100644\n--- a/net/batman-adv/originator.c\n+++ b/net/batman-adv/originator.c\n@@ -53,8 +53,9 @@ struct batadv_orig_node *\n batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n+\tstruct batadv_orig_node *orig_node_tmp = NULL;\n+\tstruct batadv_orig_node *orig_node;\n \tstruct hlist_head *head;\n-\tstruct batadv_orig_node *orig_node, *orig_node_tmp = NULL;\n \tint index;\n \n \tif (!hash)\n@@ -108,7 +109,8 @@ struct batadv_orig_node_vlan *\n batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,\n \t\t\t unsigned short vid)\n {\n-\tstruct batadv_orig_node_vlan *vlan = NULL, *tmp;\n+\tstruct batadv_orig_node_vlan *vlan = NULL;\n+\tstruct batadv_orig_node_vlan *tmp;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(tmp, \u0026orig_node-\u003evlan_list, list) {\n@@ -282,9 +284,9 @@ void batadv_hardif_neigh_release(struct kref *ref)\n */\n void batadv_neigh_node_release(struct kref *ref)\n {\n-\tstruct hlist_node *node_tmp;\n-\tstruct batadv_neigh_node *neigh_node;\n \tstruct batadv_neigh_ifinfo *neigh_ifinfo;\n+\tstruct batadv_neigh_node *neigh_node;\n+\tstruct hlist_node *node_tmp;\n \n \tneigh_node = container_of(ref, struct batadv_neigh_node, refcount);\n \n@@ -314,8 +316,8 @@ struct batadv_neigh_node *\n batadv_orig_router_get(struct batadv_orig_node *orig_node,\n \t\t const struct batadv_hard_iface *if_outgoing)\n {\n-\tstruct batadv_orig_ifinfo *orig_ifinfo;\n \tstruct batadv_neigh_node *router = NULL;\n+\tstruct batadv_orig_ifinfo *orig_ifinfo;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(orig_ifinfo, \u0026orig_node-\u003eifinfo_list, list) {\n@@ -373,7 +375,8 @@ struct batadv_orig_ifinfo *\n batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node,\n \t\t struct batadv_hard_iface *if_outgoing)\n {\n-\tstruct batadv_orig_ifinfo *tmp, *orig_ifinfo = NULL;\n+\tstruct batadv_orig_ifinfo *orig_ifinfo = NULL;\n+\tstruct batadv_orig_ifinfo *tmp;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(tmp, \u0026orig_node-\u003eifinfo_list,\n@@ -451,8 +454,8 @@ struct batadv_neigh_ifinfo *\n batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh,\n \t\t\tstruct batadv_hard_iface *if_outgoing)\n {\n-\tstruct batadv_neigh_ifinfo *neigh_ifinfo = NULL,\n-\t\t\t\t *tmp_neigh_ifinfo;\n+\tstruct batadv_neigh_ifinfo *neigh_ifinfo = NULL;\n+\tstruct batadv_neigh_ifinfo *tmp_neigh_ifinfo;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(tmp_neigh_ifinfo, \u0026neigh-\u003eifinfo_list,\n@@ -530,7 +533,8 @@ batadv_neigh_node_get(const struct batadv_orig_node *orig_node,\n \t\t const struct batadv_hard_iface *hard_iface,\n \t\t const u8 *addr)\n {\n-\tstruct batadv_neigh_node *tmp_neigh_node, *res = NULL;\n+\tstruct batadv_neigh_node *tmp_neigh_node;\n+\tstruct batadv_neigh_node *res = NULL;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(tmp_neigh_node, \u0026orig_node-\u003eneigh_list, list) {\n@@ -634,7 +638,8 @@ struct batadv_hardif_neigh_node *\n batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,\n \t\t\tconst u8 *neigh_addr)\n {\n-\tstruct batadv_hardif_neigh_node *tmp_hardif_neigh, *hardif_neigh = NULL;\n+\tstruct batadv_hardif_neigh_node *hardif_neigh = NULL;\n+\tstruct batadv_hardif_neigh_node *tmp_hardif_neigh;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(tmp_hardif_neigh,\n@@ -668,8 +673,8 @@ batadv_neigh_node_create(struct batadv_orig_node *orig_node,\n \t\t\t struct batadv_hard_iface *hard_iface,\n \t\t\t const u8 *neigh_addr)\n {\n-\tstruct batadv_neigh_node *neigh_node;\n \tstruct batadv_hardif_neigh_node *hardif_neigh = NULL;\n+\tstruct batadv_neigh_node *neigh_node;\n \n \tspin_lock_bh(\u0026orig_node-\u003eneigh_list_lock);\n \n@@ -753,7 +758,8 @@ batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,\n */\n int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb)\n {\n-\tstruct batadv_hard_iface *primary_if, *hard_iface;\n+\tstruct batadv_hard_iface *primary_if;\n+\tstruct batadv_hard_iface *hard_iface;\n \tstruct net_device *mesh_iface;\n \tstruct batadv_priv *bat_priv;\n \tint ret;\n@@ -850,12 +856,12 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu)\n */\n void batadv_orig_node_release(struct kref *ref)\n {\n-\tstruct hlist_node *node_tmp;\n+\tstruct batadv_orig_ifinfo *last_candidate;\n+\tstruct batadv_orig_ifinfo *orig_ifinfo;\n \tstruct batadv_neigh_node *neigh_node;\n \tstruct batadv_orig_node *orig_node;\n-\tstruct batadv_orig_ifinfo *orig_ifinfo;\n \tstruct batadv_orig_node_vlan *vlan;\n-\tstruct batadv_orig_ifinfo *last_candidate;\n+\tstruct hlist_node *node_tmp;\n \n \torig_node = container_of(ref, struct batadv_orig_node, refcount);\n \n@@ -898,11 +904,11 @@ void batadv_orig_node_release(struct kref *ref)\n */\n void batadv_originator_free(struct batadv_priv *bat_priv)\n {\n+\tspinlock_t *list_lock; /* spinlock to protect write access */\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n+\tstruct batadv_orig_node *orig_node;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n-\tspinlock_t *list_lock; /* spinlock to protect write access */\n-\tstruct batadv_orig_node *orig_node;\n \tu32 i;\n \n \tif (!hash)\n@@ -1109,11 +1115,11 @@ static bool\n batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_orig_node *orig_node)\n {\n-\tstruct hlist_node *node_tmp;\n+\tstruct batadv_hard_iface *if_incoming;\n \tstruct batadv_neigh_node *neigh_node;\n+\tstruct hlist_node *node_tmp;\n \tbool neigh_purged = false;\n \tunsigned long last_seen;\n-\tstruct batadv_hard_iface *if_incoming;\n \n \tspin_lock_bh(\u0026orig_node-\u003eneigh_list_lock);\n \n@@ -1167,8 +1173,9 @@ batadv_find_best_neighbor(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_orig_node *orig_node,\n \t\t\t struct batadv_hard_iface *if_outgoing)\n {\n-\tstruct batadv_neigh_node *best = NULL, *neigh;\n \tstruct batadv_algo_ops *bao = bat_priv-\u003ealgo_ops;\n+\tstruct batadv_neigh_node *best = NULL;\n+\tstruct batadv_neigh_node *neigh;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(neigh, \u0026orig_node-\u003eneigh_list, list) {\n@@ -1203,8 +1210,9 @@ static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,\n {\n \tstruct batadv_neigh_node *best_neigh_node;\n \tstruct batadv_hard_iface *hard_iface;\n-\tbool changed_ifinfo, changed_neigh;\n \tstruct list_head *iter;\n+\tbool changed_ifinfo;\n+\tbool changed_neigh;\n \n \tif (batadv_has_timed_out(orig_node-\u003elast_seen,\n \t\t\t\t 2 * BATADV_PURGE_TIMEOUT)) {\n@@ -1256,11 +1264,11 @@ static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,\n */\n void batadv_purge_orig_ref(struct batadv_priv *bat_priv)\n {\n+\tspinlock_t *list_lock; /* spinlock to protect write access */\n \tstruct batadv_hashtable *hash = bat_priv-\u003eorig_hash;\n+\tstruct batadv_orig_node *orig_node;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n-\tspinlock_t *list_lock; /* spinlock to protect write access */\n-\tstruct batadv_orig_node *orig_node;\n \tu32 i;\n \n \tif (!hash)\n@@ -1295,6 +1303,13 @@ void batadv_purge_orig_ref(struct batadv_priv *bat_priv)\n \tbatadv_gw_election(bat_priv);\n }\n \n+/**\n+ * batadv_purge_orig() - periodic worker to purge stale originator entries\n+ * @work: delayed work embedded in the bat_priv\n+ *\n+ * Invoke batadv_purge_orig_ref() to drop stale originators and reschedule the\n+ * next run after BATADV_ORIG_WORK_PERIOD milliseconds.\n+ */\n static void batadv_purge_orig(struct work_struct *work)\n {\n \tstruct delayed_work *delayed_work;\n@@ -1318,7 +1333,8 @@ static void batadv_purge_orig(struct work_struct *work)\n */\n int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)\n {\n-\tstruct batadv_hard_iface *primary_if, *hard_iface;\n+\tstruct batadv_hard_iface *primary_if;\n+\tstruct batadv_hard_iface *hard_iface;\n \tstruct net_device *mesh_iface;\n \tstruct batadv_priv *bat_priv;\n \tint ret;\ndiff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c\nindex bbd40fe3a8e59..15ef47d30406e 100644\n--- a/net/batman-adv/routing.c\n+++ b/net/batman-adv/routing.c\n@@ -172,6 +172,11 @@ bool batadv_window_protected(struct batadv_priv *bat_priv, s32 seq_num_diff,\n * @hard_iface: incoming hard interface\n * @header_len: minimal header length of packet type\n *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * skb_cow() / skb_linearize(). Any pointer into the skb data (e.g.\n+ * obtained from skb-\u003edata or eth_hdr()) before this call must be\n+ * considered invalid afterwards and has to be reacquired.\n+ *\n * Return: true when management preconditions are met, false otherwise\n */\n bool batadv_check_management_packet(struct sk_buff *skb,\n@@ -263,8 +268,7 @@ static bool batadv_skb_decrement_ttl(struct sk_buff *skb)\n * @bat_priv: the bat priv with all the mesh interface information\n * @skb: icmp packet to process\n *\n- * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP\n- * otherwise.\n+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure\n */\n static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,\n \t\t\t\t struct sk_buff *skb)\n@@ -272,7 +276,8 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_icmp_header *icmph;\n-\tint res, ret = NET_RX_DROP;\n+\tint ret = NET_RX_DROP;\n+\tint res;\n \n \ticmph = (struct batadv_icmp_header *)skb-\u003edata;\n \n@@ -328,13 +333,24 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,\n \treturn ret;\n }\n \n+/**\n+ * batadv_recv_icmp_ttl_exceeded() - handle an ICMP packet that hit TTL 0\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @skb: ICMP packet whose TTL has expired\n+ *\n+ * For traceroute-style ICMP echo requests, send a TTL exceeded reply back to\n+ * the source. Other ICMP types are simply dropped.\n+ *\n+ * Return: NET_XMIT_SUCCESS if the reply was queued, NET_RX_DROP otherwise\n+ */\n static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct sk_buff *skb)\n {\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_icmp_packet *icmp_packet;\n-\tint res, ret = NET_RX_DROP;\n+\tint ret = NET_RX_DROP;\n+\tint res;\n \n \ticmp_packet = (struct batadv_icmp_packet *)skb-\u003edata;\n \n@@ -392,12 +408,13 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,\n \t\t\t struct batadv_hard_iface *recv_if)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n-\tstruct batadv_icmp_header *icmph;\n+\tint hdr_size = sizeof(struct batadv_icmp_header);\n \tstruct batadv_icmp_packet_rr *icmp_packet_rr;\n-\tstruct ethhdr *ethhdr;\n \tstruct batadv_orig_node *orig_node = NULL;\n-\tint hdr_size = sizeof(struct batadv_icmp_header);\n-\tint res, ret = NET_RX_DROP;\n+\tstruct batadv_icmp_header *icmph;\n+\tstruct ethhdr *ethhdr;\n+\tint ret = NET_RX_DROP;\n+\tint res;\n \n \t/* drop packet if it has not necessary minimum size */\n \tif (unlikely(!pskb_may_pull(skb, hdr_size)))\n@@ -576,15 +593,17 @@ batadv_find_router(struct batadv_priv *bat_priv,\n \t\t struct batadv_orig_node *orig_node,\n \t\t struct batadv_hard_iface *recv_if)\n {\n-\tstruct batadv_algo_ops *bao = bat_priv-\u003ealgo_ops;\n \tstruct batadv_neigh_node *first_candidate_router = NULL;\n \tstruct batadv_neigh_node *next_candidate_router = NULL;\n-\tstruct batadv_neigh_node *router, *cand_router = NULL;\n \tstruct batadv_neigh_node *last_cand_router = NULL;\n-\tstruct batadv_orig_ifinfo *cand, *first_candidate = NULL;\n+\tstruct batadv_orig_ifinfo *first_candidate = NULL;\n+\tstruct batadv_algo_ops *bao = bat_priv-\u003ealgo_ops;\n \tstruct batadv_orig_ifinfo *next_candidate = NULL;\n+\tstruct batadv_neigh_node *cand_router = NULL;\n \tstruct batadv_orig_ifinfo *last_candidate;\n \tbool last_candidate_found = false;\n+\tstruct batadv_neigh_node *router;\n+\tstruct batadv_orig_ifinfo *cand;\n \n \tif (!orig_node)\n \t\treturn NULL;\n@@ -706,15 +725,29 @@ batadv_find_router(struct batadv_priv *bat_priv,\n \treturn router;\n }\n \n+/**\n+ * batadv_route_unicast_packet() - forward a unicast packet towards its\n+ * destination originator\n+ * @skb: the received unicast packet\n+ * @recv_if: interface on which the packet was received\n+ *\n+ * Decrement the TTL, look up the originator for the destination address and\n+ * hand the packet over to batadv_send_skb_to_orig() for transmission. Drop\n+ * the packet when the TTL is exhausted or no route exists.\n+ *\n+ * Return: NET_RX_SUCCESS if the packet was forwarded, NET_RX_DROP otherwise\n+ */\n static int batadv_route_unicast_packet(struct sk_buff *skb,\n \t\t\t\t struct batadv_hard_iface *recv_if)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n-\tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_unicast_packet *unicast_packet;\n+\tstruct batadv_orig_node *orig_node = NULL;\n \tstruct ethhdr *ethhdr = eth_hdr(skb);\n-\tint res, hdr_len, ret = NET_RX_DROP;\n+\tint ret = NET_RX_DROP;\n \tunsigned int len;\n+\tint hdr_len;\n+\tint res;\n \n \tunicast_packet = (struct batadv_unicast_packet *)skb-\u003edata;\n \n@@ -797,10 +830,10 @@ batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \t\t\t struct batadv_unicast_packet *unicast_packet,\n \t\t\t u8 *dst_addr, unsigned short vid)\n {\n-\tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_hard_iface *primary_if = NULL;\n-\tbool ret = false;\n+\tstruct batadv_orig_node *orig_node = NULL;\n \tconst u8 *orig_addr;\n+\tbool ret = false;\n \tu8 orig_ttvn;\n \n \tif (batadv_is_my_client(bat_priv, dst_addr, vid)) {\n@@ -836,16 +869,31 @@ batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,\n \treturn ret;\n }\n \n+/**\n+ * batadv_check_unicast_ttvn() - check and adjust the TTVN of a unicast packet\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @skb: the unicast packet to check\n+ * @hdr_len: length of the unicast header preceding the payload\n+ *\n+ * Warning: This function may reallocate the skb data buffer via\n+ * pskb_may_pull() and batadv_get_vid(). Any pointer into the skb data (e.g.\n+ * obtained from skb-\u003edata or eth_hdr()) before this call must be considered\n+ * invalid afterwards and has to be reacquired.\n+ *\n+ * Return: true if the packet may be processed further, false if it has been\n+ * consumed or has to be dropped by the caller\n+ */\n static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,\n \t\t\t\t struct sk_buff *skb, int hdr_len)\n {\n \tstruct batadv_unicast_packet *unicast_packet;\n \tstruct batadv_hard_iface *primary_if;\n \tstruct batadv_orig_node *orig_node;\n-\tu8 curr_ttvn, old_ttvn;\n \tstruct ethhdr *ethhdr;\n \tunsigned short vid;\n \tint is_old_ttvn;\n+\tu8 curr_ttvn;\n+\tu8 old_ttvn;\n \n \t/* check if there is enough data before accessing it */\n \tif (!pskb_may_pull(skb, hdr_len + ETH_HLEN))\n@@ -955,15 +1003,15 @@ static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,\n * @skb: unicast tvlv packet to process\n * @recv_if: pointer to interface this packet was received on\n *\n- * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP\n- * otherwise.\n+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure\n */\n int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,\n \t\t\t\t\t struct batadv_hard_iface *recv_if)\n {\n-\tstruct batadv_unicast_packet *unicast_packet;\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n-\tint check, hdr_size = sizeof(*unicast_packet);\n+\tstruct batadv_unicast_packet *unicast_packet;\n+\tint hdr_size = sizeof(*unicast_packet);\n+\tint check;\n \n \tcheck = batadv_check_unicast_packet(bat_priv, skb, hdr_size);\n \tif (check \u003c 0)\n@@ -992,14 +1040,18 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,\n \t\t\t struct batadv_hard_iface *recv_if)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n-\tstruct batadv_unicast_packet *unicast_packet;\n \tstruct batadv_unicast_4addr_packet *unicast_4addr_packet;\n-\tu8 *orig_addr, *orig_addr_gw;\n-\tstruct batadv_orig_node *orig_node = NULL, *orig_node_gw = NULL;\n-\tint check, hdr_size = sizeof(*unicast_packet);\n+\tstruct batadv_unicast_packet *unicast_packet;\n+\tstruct batadv_orig_node *orig_node_gw = NULL;\n+\tstruct batadv_orig_node *orig_node = NULL;\n+\tint hdr_size = sizeof(*unicast_packet);\n \tenum batadv_subtype subtype;\n \tint ret = NET_RX_DROP;\n-\tbool is4addr, is_gw;\n+\tu8 *orig_addr_gw;\n+\tu8 *orig_addr;\n+\tbool is4addr;\n+\tbool is_gw;\n+\tint check;\n \n \tunicast_packet = (struct batadv_unicast_packet *)skb-\u003edata;\n \tis4addr = unicast_packet-\u003epacket_type == BATADV_UNICAST_4ADDR;\n@@ -1089,18 +1141,17 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,\n * @skb: unicast tvlv packet to process\n * @recv_if: pointer to interface this packet was received on\n *\n- * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP\n- * otherwise.\n+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure\n */\n int batadv_recv_unicast_tvlv(struct sk_buff *skb,\n \t\t\t struct batadv_hard_iface *recv_if)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n \tstruct batadv_unicast_tvlv_packet *unicast_tvlv_packet;\n-\tunsigned char *tvlv_buff;\n-\tu16 tvlv_buff_len;\n \tint hdr_size = sizeof(*unicast_tvlv_packet);\n+\tunsigned char *tvlv_buff;\n \tint ret = NET_RX_DROP;\n+\tu16 tvlv_buff_len;\n \n \tif (batadv_check_unicast_packet(bat_priv, skb, hdr_size) \u003c 0)\n \t\tgoto free_skb;\n@@ -1146,7 +1197,7 @@ int batadv_recv_unicast_tvlv(struct sk_buff *skb,\n * the assembled packet will exceed our MTU; 2) Buffer fragment, if we still\n * lack further fragments; 3) Merge fragments, if we have all needed parts.\n *\n- * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.\n+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure\n */\n int batadv_recv_frag_packet(struct sk_buff *skb,\n \t\t\t struct batadv_hard_iface *recv_if)\n@@ -1215,8 +1266,8 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,\n \tstruct batadv_priv *bat_priv = netdev_priv(recv_if-\u003emesh_iface);\n \tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_bcast_packet *bcast_packet;\n-\tstruct ethhdr *ethhdr;\n \tint hdr_size = sizeof(*bcast_packet);\n+\tstruct ethhdr *ethhdr;\n \ts32 seq_diff;\n \tu32 seqno;\n \tint ret;\n@@ -1334,7 +1385,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,\n * contents of its TVLV forwards it and/or decapsulates it to hand it to the\n * mesh interface.\n *\n- * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.\n+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure\n */\n int batadv_recv_mcast_packet(struct sk_buff *skb,\n \t\t\t struct batadv_hard_iface *recv_if)\ndiff --git a/net/batman-adv/send.c b/net/batman-adv/send.c\nindex 7f449338a4909..2122560c90e51 100644\n--- a/net/batman-adv/send.c\n+++ b/net/batman-adv/send.c\n@@ -271,8 +271,8 @@ bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_orig_node *orig,\n \t\t\t\t\t int packet_subtype)\n {\n-\tstruct batadv_hard_iface *primary_if;\n \tstruct batadv_unicast_4addr_packet *uc_4addr_packet;\n+\tstruct batadv_hard_iface *primary_if;\n \tbool ret = false;\n \n \tprimary_if = batadv_primary_if_get_selected(bat_priv);\n@@ -322,8 +322,8 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,\n \t\t\t unsigned short vid)\n {\n \tstruct batadv_unicast_packet *unicast_packet;\n-\tstruct ethhdr *ethhdr;\n \tint ret = NET_XMIT_DROP;\n+\tstruct ethhdr *ethhdr;\n \n \tif (!orig_node)\n \t\tgoto out;\n@@ -394,7 +394,8 @@ int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,\n {\n \tstruct ethhdr *ethhdr = (struct ethhdr *)skb-\u003edata;\n \tstruct batadv_orig_node *orig_node;\n-\tu8 *src, *dst;\n+\tu8 *src;\n+\tu8 *dst;\n \tint ret;\n \n \tsrc = ethhdr-\u003eh_source;\ndiff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c\nindex 00467aa79de9d..022eb13e8ec47 100644\n--- a/net/batman-adv/tp_meter.c\n+++ b/net/batman-adv/tp_meter.c\n@@ -221,9 +221,9 @@ static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason,\n \t\t\t\t unsigned long start_time, u64 total_sent,\n \t\t\t\t u32 cookie)\n {\n+\tu32 total_bytes;\n \tu32 test_time;\n \tu8 result;\n-\tu32 total_bytes;\n \n \tif (!batadv_tp_is_error(reason)) {\n \t\tresult = BATADV_TP_REASON_COMPLETE;\n@@ -267,7 +267,8 @@ static void batadv_tp_batctl_error_notify(enum batadv_tp_meter_reason reason,\n static struct batadv_tp_sender *\n batadv_tp_list_find_sender(struct batadv_priv *bat_priv, const u8 *dst)\n {\n-\tstruct batadv_tp_sender *pos, *tp_vars = NULL;\n+\tstruct batadv_tp_sender *tp_vars = NULL;\n+\tstruct batadv_tp_sender *pos;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(pos, \u0026bat_priv-\u003etp_sender_list, common.list) {\n@@ -332,7 +333,8 @@ static struct batadv_tp_sender *\n batadv_tp_list_find_sender_session(struct batadv_priv *bat_priv, const u8 *dst,\n \t\t\t\t const u8 *session)\n {\n-\tstruct batadv_tp_sender *pos, *tp_vars = NULL;\n+\tstruct batadv_tp_sender *tp_vars = NULL;\n+\tstruct batadv_tp_sender *pos;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(pos, \u0026bat_priv-\u003etp_sender_list, common.list) {\n@@ -578,8 +580,8 @@ static void batadv_tp_sender_timeout(struct timer_list *t)\n static void batadv_tp_fill_prerandom(struct batadv_tp_sender *tp_vars,\n \t\t\t\t u8 *buf, size_t nbytes)\n {\n-\tu32 local_offset;\n \tsize_t bytes_inbuf;\n+\tu32 local_offset;\n \tsize_t to_copy;\n \tsize_t pos = 0;\n \n@@ -625,9 +627,9 @@ static int batadv_tp_send_msg(struct batadv_tp_sender *tp_vars, const u8 *src,\n {\n \tstruct batadv_icmp_tp_packet *icmp;\n \tstruct sk_buff *skb;\n-\tint r;\n-\tu8 *data;\n \tsize_t data_len;\n+\tu8 *data;\n+\tint r;\n \n \tskb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);\n \tif (unlikely(!skb))\n@@ -864,7 +866,8 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,\n static bool batadv_tp_avail(struct batadv_tp_sender *tp_vars,\n \t\t\t size_t payload_len)\n {\n-\tu32 win_left, win_limit;\n+\tu32 win_limit;\n+\tu32 win_left;\n \n \tspin_lock_bh(\u0026tp_vars-\u003ecc_lock);\n \n@@ -910,14 +913,16 @@ static int batadv_tp_wait_available(struct batadv_tp_sender *tp_vars, size_t ple\n */\n static int batadv_tp_send(void *arg)\n {\n-\tstruct batadv_tp_sender *tp_vars = arg;\n-\tstruct batadv_priv *bat_priv = tp_vars-\u003ecommon.bat_priv;\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_orig_node *orig_node = NULL;\n-\tsize_t payload_len, packet_len;\n+\tstruct batadv_tp_sender *tp_vars = arg;\n+\tstruct batadv_priv *bat_priv;\n+\tsize_t payload_len;\n+\tsize_t packet_len;\n \tu32 last_sent;\n \tint err = 0;\n \n+\tbat_priv = tp_vars-\u003ecommon.bat_priv;\n \torig_node = batadv_orig_hash_find(bat_priv, tp_vars-\u003ecommon.other_end);\n \tif (unlikely(!orig_node)) {\n \t\terr = BATADV_TP_REASON_DST_UNREACHABLE;\n@@ -1005,8 +1010,8 @@ static int batadv_tp_send(void *arg)\n */\n static void batadv_tp_start_kthread(struct batadv_tp_sender *tp_vars)\n {\n-\tstruct task_struct *kthread;\n \tstruct batadv_priv *bat_priv = tp_vars-\u003ecommon.bat_priv;\n+\tstruct task_struct *kthread;\n \tu32 session_cookie;\n \n \tkref_get(\u0026tp_vars-\u003ecommon.refcount);\n@@ -1042,9 +1047,9 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,\n \t\t u32 test_length, u32 *cookie)\n {\n \tstruct batadv_tp_sender *tp_vars;\n+\tu32 session_cookie;\n \tu8 session_id[2];\n \tu8 icmp_uid;\n-\tu32 session_cookie;\n \n \tget_random_bytes(session_id, sizeof(session_id));\n \tget_random_bytes(\u0026icmp_uid, 1);\n@@ -1211,7 +1216,8 @@ static struct batadv_tp_receiver *\n batadv_tp_list_find_receiver_session(struct batadv_priv *bat_priv, const u8 *dst,\n \t\t\t\t const u8 *session)\n {\n-\tstruct batadv_tp_receiver *pos, *tp_vars = NULL;\n+\tstruct batadv_tp_receiver *tp_vars = NULL;\n+\tstruct batadv_tp_receiver *pos;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(pos, \u0026bat_priv-\u003etp_receiver_list, common.list) {\n@@ -1296,7 +1302,8 @@ static void batadv_tp_reset_receiver_timer(struct batadv_tp_receiver *tp_vars)\n static void batadv_tp_receiver_shutdown(struct timer_list *t)\n {\n \tstruct batadv_tp_receiver *tp_vars = timer_container_of(tp_vars, t, common.timer);\n-\tstruct batadv_tp_unacked *un, *safe;\n+\tstruct batadv_tp_unacked *safe;\n+\tstruct batadv_tp_unacked *un;\n \tstruct batadv_priv *bat_priv;\n \n \tbat_priv = tp_vars-\u003ecommon.bat_priv;\n@@ -1351,7 +1358,8 @@ static int batadv_tp_send_ack(struct batadv_priv *bat_priv, const u8 *dst,\n \tstruct batadv_orig_node *orig_node;\n \tstruct batadv_icmp_tp_packet *icmp;\n \tstruct sk_buff *skb;\n-\tint r, ret;\n+\tint ret;\n+\tint r;\n \n \torig_node = batadv_orig_hash_find(bat_priv, dst);\n \tif (unlikely(!orig_node)) {\n@@ -1528,7 +1536,8 @@ static bool batadv_tp_handle_out_of_order(struct batadv_tp_receiver *tp_vars,\n static void batadv_tp_ack_unordered(struct batadv_tp_receiver *tp_vars)\n \t__must_hold(\u0026tp_vars-\u003eack_seqno_lock)\n {\n-\tstruct batadv_tp_unacked *un, *safe;\n+\tstruct batadv_tp_unacked *safe;\n+\tstruct batadv_tp_unacked *un;\n \tu32 to_ack;\n \n \t/* go through the unacked packet list and possibly ACK them as\ndiff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c\nindex dae5e1d8c0385..5e10e6bb7bd6a 100644\n--- a/net/batman-adv/translation-table.c\n+++ b/net/batman-adv/translation-table.c\n@@ -128,8 +128,10 @@ static struct batadv_tt_common_entry *\n batadv_tt_hash_find(struct batadv_hashtable *hash, const u8 *addr,\n \t\t unsigned short vid)\n {\n+\tstruct batadv_tt_common_entry *tt_tmp = NULL;\n+\tstruct batadv_tt_common_entry to_search;\n+\tstruct batadv_tt_common_entry *tt;\n \tstruct hlist_head *head;\n-\tstruct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;\n \tu32 index;\n \n \tif (!hash)\n@@ -173,8 +175,8 @@ static struct batadv_tt_local_entry *\n batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,\n \t\t\t unsigned short vid)\n {\n-\tstruct batadv_tt_common_entry *tt_common_entry;\n \tstruct batadv_tt_local_entry *tt_local_entry = NULL;\n+\tstruct batadv_tt_common_entry *tt_common_entry;\n \n \ttt_common_entry = batadv_tt_hash_find(bat_priv-\u003ett.local_hash, addr,\n \t\t\t\t\t vid);\n@@ -198,8 +200,8 @@ struct batadv_tt_global_entry *\n batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,\n \t\t\t unsigned short vid)\n {\n-\tstruct batadv_tt_common_entry *tt_common_entry;\n \tstruct batadv_tt_global_entry *tt_global_entry = NULL;\n+\tstruct batadv_tt_common_entry *tt_common_entry;\n \n \ttt_common_entry = batadv_tt_hash_find(bat_priv-\u003ett.global_hash, addr,\n \t\t\t\t\t vid);\n@@ -421,10 +423,13 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_tt_local_entry *tt_local_entry,\n \t\t\t\t u8 event_flags)\n {\n-\tstruct batadv_tt_change_node *tt_change_node, *entry, *safe;\n \tstruct batadv_tt_common_entry *common = \u0026tt_local_entry-\u003ecommon;\n-\tu8 flags = common-\u003eflags | event_flags;\n-\tbool del_op_requested, del_op_entry;\n+\tu8 flags = atomic_read(\u0026common-\u003eflags) | event_flags;\n+\tstruct batadv_tt_change_node *tt_change_node;\n+\tstruct batadv_tt_change_node *entry;\n+\tstruct batadv_tt_change_node *safe;\n+\tbool del_op_requested;\n+\tbool del_op_entry;\n \tsize_t changes;\n \n \ttt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);\n@@ -514,9 +519,9 @@ static u16 batadv_tt_entries(u16 tt_len)\n */\n static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)\n {\n-\tu16 num_vlan = 0;\n-\tu16 tt_local_entries = 0;\n \tstruct batadv_meshif_vlan *vlan;\n+\tu16 tt_local_entries = 0;\n+\tu16 num_vlan = 0;\n \tint hdr_size;\n \n \trcu_read_lock();\n@@ -535,6 +540,12 @@ static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)\n \treturn hdr_size + batadv_tt_len(tt_local_entries);\n }\n \n+/**\n+ * batadv_tt_local_init() - allocate and initialise the local translation table\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Return: 0 on success or -ENOMEM in case of allocation failure\n+ */\n static int batadv_tt_local_init(struct batadv_priv *bat_priv)\n {\n \tif (bat_priv-\u003ett.local_hash)\n@@ -551,6 +562,15 @@ static int batadv_tt_local_init(struct batadv_priv *bat_priv)\n \treturn 0;\n }\n \n+/**\n+ * batadv_tt_global_free() - drop a global translation table entry\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @tt_global: the global TT entry to remove\n+ * @message: debug message explaining why the entry is being removed\n+ *\n+ * Remove @tt_global from the global TT hash and drop the reference held by\n+ * the hash.\n+ */\n static void batadv_tt_global_free(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_tt_global_entry *tt_global,\n \t\t\t\t const char *message)\n@@ -594,19 +614,26 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \t\t\t unsigned short vid, int ifindex, u32 mark)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(mesh_iface);\n-\tstruct batadv_tt_local_entry *tt_local;\n \tstruct batadv_tt_global_entry *tt_global = NULL;\n+\tstruct batadv_tt_orig_list_entry *orig_entry;\n+\tstruct batadv_tt_local_entry *tt_local;\n \tstruct net *net = dev_net(mesh_iface);\n-\tstruct batadv_meshif_vlan *vlan;\n \tstruct net_device *in_dev = NULL;\n-\tstruct hlist_head *head;\n-\tstruct batadv_tt_orig_list_entry *orig_entry;\n-\tint hash_added, table_size, packet_size_max;\n-\tbool ret = false;\n+\tstruct batadv_meshif_vlan *vlan;\n \tbool roamed_back = false;\n \tbool iif_is_wifi = false;\n+\tstruct hlist_head *head;\n+\tint packet_size_max;\n+\tu8 new_remote_flags;\n+\tbool ret = false;\n \tu8 remote_flags;\n+\tint hash_added;\n+\tint table_size;\n \tu32 match_mark;\n+\tu8 clear_flags;\n+\tu16 old_flags;\n+\tu8 set_flags;\n+\tu16 flags;\n \n \tif (ifindex != BATADV_NULL_IFINDEX)\n \t\tin_dev = dev_get_by_index(net, ifindex);\n@@ -624,7 +651,9 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \n \tif (tt_local) {\n \t\ttt_local-\u003elast_seen = jiffies;\n-\t\tif (tt_local-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_PENDING) {\n+\n+\t\tflags = atomic_read(\u0026tt_local-\u003ecommon.flags);\n+\t\tif (flags \u0026 BATADV_TT_CLIENT_PENDING) {\n \t\t\tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n \t\t\t\t \"Re-adding pending client %pM (vid: %d)\\n\",\n \t\t\t\t addr, batadv_print_vid(vid));\n@@ -633,11 +662,11 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \t\t\t * this orig_interval. Since it popped up again, the\n \t\t\t * flag can be reset like it was never enqueued\n \t\t\t */\n-\t\t\ttt_local-\u003ecommon.flags \u0026= ~BATADV_TT_CLIENT_PENDING;\n+\t\t\tatomic_andnot(BATADV_TT_CLIENT_PENDING, \u0026tt_local-\u003ecommon.flags);\n \t\t\tgoto add_event;\n \t\t}\n \n-\t\tif (tt_local-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ROAM) {\n+\t\tif (flags \u0026 BATADV_TT_CLIENT_ROAM) {\n \t\t\tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n \t\t\t\t \"Roaming client %pM (vid: %d) came back to its original location\\n\",\n \t\t\t\t addr, batadv_print_vid(vid));\n@@ -646,7 +675,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \t\t\t * that the client popped up again at its original\n \t\t\t * location such flag can be unset\n \t\t\t */\n-\t\t\ttt_local-\u003ecommon.flags \u0026= ~BATADV_TT_CLIENT_ROAM;\n+\t\t\tatomic_andnot(BATADV_TT_CLIENT_ROAM, \u0026tt_local-\u003ecommon.flags);\n \t\t\troamed_back = true;\n \t\t}\n \t\tgoto check_roaming;\n@@ -683,26 +712,29 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \t\t addr, batadv_print_vid(vid),\n \t\t (u8)atomic_read(\u0026bat_priv-\u003ett.vn));\n \n+\ttt_local-\u003ecommon.vid = vid;\n+\tkref_init(\u0026tt_local-\u003ecommon.refcount);\n+\ttt_local-\u003elast_seen = jiffies;\n+\ttt_local-\u003ecommon.added_at = tt_local-\u003elast_seen;\n+\ttt_local-\u003evlan = vlan;\n+\n \tether_addr_copy(tt_local-\u003ecommon.addr, addr);\n \t/* The local entry has to be marked as NEW to avoid to send it in\n \t * a full table response going out before the next ttvn increment\n \t * (consistency check)\n \t */\n-\ttt_local-\u003ecommon.flags = BATADV_TT_CLIENT_NEW;\n-\ttt_local-\u003ecommon.vid = vid;\n+\tflags = BATADV_TT_CLIENT_NEW;\n \tif (iif_is_wifi)\n-\t\ttt_local-\u003ecommon.flags |= BATADV_TT_CLIENT_WIFI;\n-\tkref_init(\u0026tt_local-\u003ecommon.refcount);\n-\ttt_local-\u003elast_seen = jiffies;\n-\ttt_local-\u003ecommon.added_at = tt_local-\u003elast_seen;\n-\ttt_local-\u003evlan = vlan;\n+\t\tflags |= BATADV_TT_CLIENT_WIFI;\n \n \t/* the batman interface mac and multicast addresses should never be\n \t * purged\n \t */\n \tif (batadv_compare_eth(addr, mesh_iface-\u003edev_addr) ||\n \t is_multicast_ether_addr(addr))\n-\t\ttt_local-\u003ecommon.flags |= BATADV_TT_CLIENT_NOPURGE;\n+\t\tflags |= BATADV_TT_CLIENT_NOPURGE;\n+\n+\tatomic_set(\u0026tt_local-\u003ecommon.flags, flags);\n \n \tkref_get(\u0026tt_local-\u003ecommon.refcount);\n \thash_added = batadv_hash_add(bat_priv-\u003ett.local_hash, batadv_compare_tt,\n@@ -720,9 +752,17 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \n check_roaming:\n \t/* Check whether it is a roaming, but don't do anything if the roaming\n-\t * process has already been handled\n+\t * process has already been handled. The ROAM flag is claimed via an\n+\t * atomic test-and-set to make sure that only a single context handles\n+\t * the advertisement for a client\n \t */\n-\tif (tt_global \u0026\u0026 !(tt_global-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ROAM)) {\n+\told_flags = BATADV_TT_CLIENT_ROAM;\n+\tif (tt_global \u0026\u0026\n+\t !(atomic_read(\u0026tt_global-\u003ecommon.flags) \u0026 BATADV_TT_CLIENT_ROAM))\n+\t\told_flags = atomic_fetch_or(BATADV_TT_CLIENT_ROAM,\n+\t\t\t\t\t \u0026tt_global-\u003ecommon.flags);\n+\n+\tif (tt_global \u0026\u0026 !(old_flags \u0026 BATADV_TT_CLIENT_ROAM)) {\n \t\t/* These node are probably going to update their tt table */\n \t\thead = \u0026tt_global-\u003eorig_list;\n \t\trcu_read_lock();\n@@ -732,27 +772,30 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \t\t\t\t\t orig_entry-\u003eorig_node);\n \t\t}\n \t\trcu_read_unlock();\n-\t\tif (roamed_back) {\n-\t\t\tbatadv_tt_global_free(bat_priv, tt_global,\n-\t\t\t\t\t \"Roaming canceled\");\n-\t\t} else {\n-\t\t\t/* The global entry has to be marked as ROAMING and\n+\n+\t\tif (!roamed_back) {\n+\t\t\t/* The global entry was marked as ROAMING and\n \t\t\t * has to be kept for consistency purpose\n \t\t\t */\n-\t\t\ttt_global-\u003ecommon.flags |= BATADV_TT_CLIENT_ROAM;\n \t\t\ttt_global-\u003eroam_at = jiffies;\n \t\t}\n \t}\n \n+\t/* clean up independent of the roaming advertisement handler */\n+\tif (tt_global \u0026\u0026 roamed_back)\n+\t\tbatadv_tt_global_free(bat_priv, tt_global, \"Roaming canceled\");\n+\n \t/* store the current remote flags before altering them. This helps\n \t * understanding is flags are changing or not\n \t */\n-\tremote_flags = tt_local-\u003ecommon.flags \u0026 BATADV_TT_REMOTE_MASK;\n+\tremote_flags = atomic_read(\u0026tt_local-\u003ecommon.flags) \u0026 BATADV_TT_REMOTE_MASK;\n+\n+\tnew_remote_flags = remote_flags;\n \n \tif (iif_is_wifi)\n-\t\ttt_local-\u003ecommon.flags |= BATADV_TT_CLIENT_WIFI;\n+\t\tnew_remote_flags |= BATADV_TT_CLIENT_WIFI;\n \telse\n-\t\ttt_local-\u003ecommon.flags \u0026= ~BATADV_TT_CLIENT_WIFI;\n+\t\tnew_remote_flags \u0026= ~BATADV_TT_CLIENT_WIFI;\n \n \t/* check the mark in the skb: if it's equal to the configured\n \t * isolation_mark, it means the packet is coming from an isolated\n@@ -761,14 +804,22 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\n \tmatch_mark = (mark \u0026 bat_priv-\u003eisolation_mark_mask);\n \tif (bat_priv-\u003eisolation_mark_mask \u0026\u0026\n \t match_mark == bat_priv-\u003eisolation_mark)\n-\t\ttt_local-\u003ecommon.flags |= BATADV_TT_CLIENT_ISOLA;\n+\t\tnew_remote_flags |= BATADV_TT_CLIENT_ISOLA;\n \telse\n-\t\ttt_local-\u003ecommon.flags \u0026= ~BATADV_TT_CLIENT_ISOLA;\n+\t\tnew_remote_flags \u0026= ~BATADV_TT_CLIENT_ISOLA;\n+\n+\tset_flags = new_remote_flags \u0026 ~remote_flags;\n+\tif (set_flags)\n+\t\tatomic_or(set_flags, \u0026tt_local-\u003ecommon.flags);\n+\n+\tclear_flags = remote_flags \u0026 ~new_remote_flags;\n+\tif (clear_flags)\n+\t\tatomic_andnot(clear_flags, \u0026tt_local-\u003ecommon.flags);\n \n \t/* if any \"dynamic\" flag has been modified, resend an ADD event for this\n \t * entry so that all the nodes can get the new flags\n \t */\n-\tif (remote_flags ^ (tt_local-\u003ecommon.flags \u0026 BATADV_TT_REMOTE_MASK))\n+\tif (set_flags || clear_flags)\n \t\tbatadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);\n \n \tret = true;\n@@ -987,14 +1038,16 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,\n */\n static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_tt_change_node *entry, *safe;\n-\tstruct batadv_tvlv_tt_data *tt_data;\n \tstruct batadv_tvlv_tt_change *tt_change;\n-\tint tt_diff_len, tt_change_len = 0;\n-\tint tt_diff_entries_num = 0;\n+\tstruct batadv_tt_change_node *entry;\n+\tstruct batadv_tvlv_tt_data *tt_data;\n+\tstruct batadv_tt_change_node *safe;\n \tint tt_diff_entries_count = 0;\n+\tint tt_diff_entries_num = 0;\n \tbool drop_changes = false;\n \tsize_t tt_extra_len = 0;\n+\tint tt_change_len = 0;\n+\tint tt_diff_len;\n \tu16 tvlv_len;\n \n \ttt_diff_entries_num = READ_ONCE(bat_priv-\u003ett.local_changes);\n@@ -1087,14 +1140,16 @@ batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid,\n \t\t\t struct batadv_priv *bat_priv,\n \t\t\t struct batadv_tt_common_entry *common)\n {\n-\tvoid *hdr;\n-\tstruct batadv_meshif_vlan *vlan;\n \tstruct batadv_tt_local_entry *local;\n+\tstruct batadv_meshif_vlan *vlan;\n \tunsigned int last_seen_msecs;\n+\tvoid *hdr;\n+\tu16 flags;\n \tu32 crc;\n \n \tlocal = container_of(common, struct batadv_tt_local_entry, common);\n \tlast_seen_msecs = jiffies_to_msecs(jiffies - local-\u003elast_seen);\n+\tflags = atomic_read(\u0026common-\u003eflags);\n \n \tvlan = batadv_meshif_vlan_get(bat_priv, common-\u003evid);\n \tif (!vlan)\n@@ -1115,10 +1170,10 @@ batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid,\n \tif (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common-\u003eaddr) ||\n \t nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||\n \t nla_put_u16(msg, BATADV_ATTR_TT_VID, common-\u003evid) ||\n-\t nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, common-\u003eflags))\n+\t nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, flags))\n \t\tgoto nla_put_failure;\n \n-\tif (!(common-\u003eflags \u0026 BATADV_TT_CLIENT_NOPURGE) \u0026\u0026\n+\tif (!(flags \u0026 BATADV_TT_CLIENT_NOPURGE) \u0026\u0026\n \t nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, last_seen_msecs))\n \t\tgoto nla_put_failure;\n \n@@ -1181,14 +1236,14 @@ batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid,\n */\n int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)\n {\n-\tstruct net_device *mesh_iface;\n-\tstruct batadv_priv *bat_priv;\n \tstruct batadv_hard_iface *primary_if = NULL;\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n+\tstruct net_device *mesh_iface;\n \tstruct batadv_hashtable *hash;\n-\tint ret;\n+\tstruct batadv_priv *bat_priv;\n \tint bucket = cb-\u003eargs[0];\n \tint idx = cb-\u003eargs[1];\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n+\tint ret;\n \n \tmesh_iface = batadv_netlink_get_meshif(cb);\n \tif (IS_ERR(mesh_iface))\n@@ -1224,6 +1279,17 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)\n \treturn ret;\n }\n \n+/**\n+ * batadv_tt_local_set_pending() - mark a local TT entry as pending removal\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @tt_local_entry: local TT entry to mark\n+ * @flags: TT change flags to announce together with the pending removal\n+ * @message: debug message describing the reason for the change\n+ *\n+ * Schedule the TT change announcement and set BATADV_TT_CLIENT_PENDING on the\n+ * entry. The entry is kept in the local table until the next TTVN increment\n+ * so that a consistency-check response can still be answered.\n+ */\n static void\n batadv_tt_local_set_pending(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_tt_local_entry *tt_local_entry,\n@@ -1235,7 +1301,7 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,\n \t * to be kept in the table in order to send it in a full table\n \t * response issued before the net ttvn increment (consistency check)\n \t */\n-\ttt_local_entry-\u003ecommon.flags |= BATADV_TT_CLIENT_PENDING;\n+\tatomic_or(BATADV_TT_CLIENT_PENDING, \u0026tt_local_entry-\u003ecommon.flags);\n \n \tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n \t\t \"Local tt entry (%pM, vid: %d) pending to be removed: %s\\n\",\n@@ -1259,14 +1325,16 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,\n {\n \tstruct batadv_tt_local_entry *tt_removed_entry;\n \tstruct batadv_tt_local_entry *tt_local_entry;\n-\tu16 flags, curr_flags = BATADV_NO_FLAGS;\n \tstruct hlist_node *tt_removed_node;\n+\tu16 curr_flags = BATADV_NO_FLAGS;\n+\tu16 old_flags;\n+\tu16 flags;\n \n \ttt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);\n \tif (!tt_local_entry)\n \t\tgoto out;\n \n-\tcurr_flags = tt_local_entry-\u003ecommon.flags;\n+\tcurr_flags = atomic_read(\u0026tt_local_entry-\u003ecommon.flags);\n \n \tflags = BATADV_TT_CLIENT_DEL;\n \t/* if this global entry addition is due to a roaming, the node has to\n@@ -1276,10 +1344,12 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,\n \tif (roaming) {\n \t\tflags |= BATADV_TT_CLIENT_ROAM;\n \t\t/* mark the local client as ROAMed */\n-\t\ttt_local_entry-\u003ecommon.flags |= BATADV_TT_CLIENT_ROAM;\n+\t\tatomic_or(BATADV_TT_CLIENT_ROAM, \u0026tt_local_entry-\u003ecommon.flags);\n \t}\n \n-\tif (!(tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_NEW)) {\n+\told_flags = atomic_fetch_andnot(BATADV_TT_CLIENT_NEW,\n+\t\t\t\t\t\u0026tt_local_entry-\u003ecommon.flags);\n+\tif (!(old_flags \u0026 BATADV_TT_CLIENT_NEW)) {\n \t\tbatadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,\n \t\t\t\t\t message);\n \t\tgoto out;\n@@ -1319,20 +1389,24 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,\n \t\t\t\t struct hlist_head *head,\n \t\t\t\t int timeout)\n {\n-\tstruct batadv_tt_local_entry *tt_local_entry;\n \tstruct batadv_tt_common_entry *tt_common_entry;\n+\tstruct batadv_tt_local_entry *tt_local_entry;\n \tstruct hlist_node *node_tmp;\n+\tu16 flags;\n \n \thlist_for_each_entry_safe(tt_common_entry, node_tmp, head,\n \t\t\t\t hash_entry) {\n \t\ttt_local_entry = container_of(tt_common_entry,\n \t\t\t\t\t struct batadv_tt_local_entry,\n \t\t\t\t\t common);\n-\t\tif (tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_NOPURGE)\n+\n+\t\tflags = atomic_read(\u0026tt_local_entry-\u003ecommon.flags);\n+\n+\t\tif (flags \u0026 BATADV_TT_CLIENT_NOPURGE)\n \t\t\tcontinue;\n \n \t\t/* entry already marked for deletion */\n-\t\tif (tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_PENDING)\n+\t\tif (flags \u0026 BATADV_TT_CLIENT_PENDING)\n \t\t\tcontinue;\n \n \t\tif (!batadv_has_timed_out(tt_local_entry-\u003elast_seen, timeout))\n@@ -1352,9 +1426,9 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,\n static void batadv_tt_local_purge(struct batadv_priv *bat_priv,\n \t\t\t\t int timeout)\n {\n+\tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tstruct batadv_hashtable *hash = bat_priv-\u003ett.local_hash;\n \tstruct hlist_head *head;\n-\tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tu32 i;\n \n \tfor (i = 0; i \u003c hash-\u003esize; i++) {\n@@ -1367,12 +1441,19 @@ static void batadv_tt_local_purge(struct batadv_priv *bat_priv,\n \t}\n }\n \n+/**\n+ * batadv_tt_local_table_free() - release the local translation table\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Drop every entry of the local TT hash, free their references and finally\n+ * release the hashtable itself.\n+ */\n static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_hashtable *hash;\n \tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tstruct batadv_tt_common_entry *tt_common_entry;\n \tstruct batadv_tt_local_entry *tt_local;\n+\tstruct batadv_hashtable *hash;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n \tu32 i;\n@@ -1404,6 +1485,13 @@ static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)\n \tbat_priv-\u003ett.local_hash = NULL;\n }\n \n+/**\n+ * batadv_tt_global_init() - allocate and initialise the global translation\n+ * table\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Return: 0 on success or -ENOMEM in case of allocation failure\n+ */\n static int batadv_tt_global_init(struct batadv_priv *bat_priv)\n {\n \tif (bat_priv-\u003ett.global_hash)\n@@ -1420,9 +1508,16 @@ static int batadv_tt_global_init(struct batadv_priv *bat_priv)\n \treturn 0;\n }\n \n+/**\n+ * batadv_tt_changes_list_free() - drop all pending local TT changes\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Discard every queued local TT change and reset the pending change counter.\n+ */\n static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_tt_change_node *entry, *safe;\n+\tstruct batadv_tt_change_node *entry;\n+\tstruct batadv_tt_change_node *safe;\n \n \tspin_lock_bh(\u0026bat_priv-\u003ett.changes_list_lock);\n \n@@ -1451,7 +1546,8 @@ static struct batadv_tt_orig_list_entry *\n batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,\n \t\t\t\t const struct batadv_orig_node *orig_node)\n {\n-\tstruct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL;\n+\tstruct batadv_tt_orig_list_entry *orig_entry = NULL;\n+\tstruct batadv_tt_orig_list_entry *tmp_orig_entry;\n \tconst struct hlist_head *head;\n \n \trcu_read_lock();\n@@ -1516,6 +1612,8 @@ batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)\n \tstruct batadv_tt_orig_list_entry *orig_entry;\n \tconst struct hlist_head *head;\n \tu16 flags = BATADV_NO_FLAGS;\n+\tint new_flags;\n+\tint old_flags;\n \n \trcu_read_lock();\n \thead = \u0026tt_global-\u003eorig_list;\n@@ -1523,8 +1621,15 @@ batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)\n \t\tflags |= orig_entry-\u003eflags;\n \trcu_read_unlock();\n \n-\tflags |= tt_global-\u003ecommon.flags \u0026 (~BATADV_TT_SYNC_MASK);\n-\ttt_global-\u003ecommon.flags = flags;\n+\t/* replace the sync flags without dropping concurrent modifications of\n+\t * the non-sync flags\n+\t */\n+\told_flags = atomic_read(\u0026tt_global-\u003ecommon.flags);\n+\tdo {\n+\t\tnew_flags = (old_flags \u0026 ~BATADV_TT_SYNC_MASK) | flags;\n+\t\tif (new_flags == old_flags)\n+\t\t\tbreak;\n+\t} while (!atomic_try_cmpxchg(\u0026tt_global-\u003ecommon.flags, \u0026old_flags, new_flags));\n }\n \n /**\n@@ -1604,10 +1709,12 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n {\n \tstruct batadv_tt_global_entry *tt_global_entry;\n \tstruct batadv_tt_local_entry *tt_local_entry;\n-\tbool ret = false;\n-\tint hash_added;\n \tstruct batadv_tt_common_entry *common;\n+\tbool ret = false;\n \tu16 local_flags;\n+\tu16 clear_flags;\n+\tint hash_added;\n+\tu16 old_flags;\n \n \t/* ignore global entries from backbone nodes */\n \tif (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node-\u003eorig, vid))\n@@ -1621,7 +1728,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \t * table\n \t */\n \tif ((flags \u0026 BATADV_TT_CLIENT_TEMP) \u0026\u0026 tt_local_entry \u0026\u0026\n-\t !(tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_NEW))\n+\t !(atomic_read(\u0026tt_local_entry-\u003ecommon.flags) \u0026 BATADV_TT_CLIENT_NEW))\n \t\tgoto out;\n \n \tif (!tt_global_entry) {\n@@ -1635,7 +1742,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \t\tcommon-\u003evid = vid;\n \n \t\tif (!is_multicast_ether_addr(common-\u003eaddr))\n-\t\t\tcommon-\u003eflags = flags \u0026 (~BATADV_TT_SYNC_MASK);\n+\t\t\tatomic_set(\u0026common-\u003eflags, flags \u0026 (~BATADV_TT_SYNC_MASK));\n \n \t\ttt_global_entry-\u003eroam_at = 0;\n \t\t/* node must store current time in case of roaming. This is\n@@ -1664,6 +1771,8 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \t\t}\n \t} else {\n \t\tcommon = \u0026tt_global_entry-\u003ecommon;\n+\t\tclear_flags = 0;\n+\n \t\t/* If there is already a global entry, we can use this one for\n \t\t * our processing.\n \t\t * But if we are trying to add a temporary client then here are\n@@ -1675,7 +1784,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \t\t * originator list and add the new one orig_entry\n \t\t */\n \t\tif (flags \u0026 BATADV_TT_CLIENT_TEMP) {\n-\t\t\tif (!(common-\u003eflags \u0026 BATADV_TT_CLIENT_TEMP))\n+\t\t\tif (!(atomic_read(\u0026common-\u003eflags) \u0026 BATADV_TT_CLIENT_TEMP))\n \t\t\t\tgoto out;\n \t\t\tif (batadv_tt_global_entry_has_orig(tt_global_entry,\n \t\t\t\t\t\t\t orig_node, NULL))\n@@ -1684,24 +1793,26 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \t\t\tgoto add_orig_entry;\n \t\t}\n \n+\t\t/* the change can carry possible \"attribute\" flags like the\n+\t\t * TT_CLIENT_TEMP, therefore they have to be copied in the\n+\t\t * client entry\n+\t\t */\n+\t\tif (!is_multicast_ether_addr(common-\u003eaddr))\n+\t\t\tatomic_or(flags \u0026 (~BATADV_TT_SYNC_MASK), \u0026common-\u003eflags);\n+\n+\t\told_flags = atomic_read(\u0026common-\u003eflags);\n+\n \t\t/* if the client was temporary added before receiving the first\n \t\t * OGM announcing it, we have to clear the TEMP flag. Also,\n \t\t * remove the previous temporary orig node and re-add it\n \t\t * if required. If the orig entry changed, the new one which\n \t\t * is a non-temporary entry is preferred.\n \t\t */\n-\t\tif (common-\u003eflags \u0026 BATADV_TT_CLIENT_TEMP) {\n+\t\tif (old_flags \u0026 BATADV_TT_CLIENT_TEMP) {\n \t\t\tbatadv_tt_global_del_orig_list(tt_global_entry);\n-\t\t\tcommon-\u003eflags \u0026= ~BATADV_TT_CLIENT_TEMP;\n+\t\t\tclear_flags |= BATADV_TT_CLIENT_TEMP;\n \t\t}\n \n-\t\t/* the change can carry possible \"attribute\" flags like the\n-\t\t * TT_CLIENT_TEMP, therefore they have to be copied in the\n-\t\t * client entry\n-\t\t */\n-\t\tif (!is_multicast_ether_addr(common-\u003eaddr))\n-\t\t\tcommon-\u003eflags |= flags \u0026 (~BATADV_TT_SYNC_MASK);\n-\n \t\t/* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only\n \t\t * one originator left in the list and we previously received a\n \t\t * delete + roaming change for this originator.\n@@ -1709,11 +1820,14 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \t\t * We should first delete the old originator before adding the\n \t\t * new one.\n \t\t */\n-\t\tif (common-\u003eflags \u0026 BATADV_TT_CLIENT_ROAM) {\n+\t\tif (old_flags \u0026 BATADV_TT_CLIENT_ROAM) {\n \t\t\tbatadv_tt_global_del_orig_list(tt_global_entry);\n-\t\t\tcommon-\u003eflags \u0026= ~BATADV_TT_CLIENT_ROAM;\n+\t\t\tclear_flags |= BATADV_TT_CLIENT_ROAM;\n \t\t\ttt_global_entry-\u003eroam_at = 0;\n \t\t}\n+\n+\t\tif (clear_flags)\n+\t\t\tatomic_andnot(clear_flags, \u0026common-\u003eflags);\n \t}\n add_orig_entry:\n \t/* add the new orig_entry (if needed) or update it */\n@@ -1737,13 +1851,15 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n \tlocal_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,\n \t\t\t\t\t \"global tt received\",\n \t\t\t\t\t flags \u0026 BATADV_TT_CLIENT_ROAM);\n-\ttt_global_entry-\u003ecommon.flags |= local_flags \u0026 BATADV_TT_CLIENT_WIFI;\n+\tif (local_flags \u0026 BATADV_TT_CLIENT_WIFI)\n+\t\tatomic_or(local_flags \u0026 BATADV_TT_CLIENT_WIFI,\n+\t\t\t \u0026tt_global_entry-\u003ecommon.flags);\n \n \tif (!(flags \u0026 BATADV_TT_CLIENT_ROAM))\n \t\t/* this is a normal global add. Therefore the client is not in a\n \t\t * roaming state anymore.\n \t\t */\n-\t\ttt_global_entry-\u003ecommon.flags \u0026= ~BATADV_TT_CLIENT_ROAM;\n+\t\tatomic_andnot(BATADV_TT_CLIENT_ROAM, \u0026tt_global_entry-\u003ecommon.flags);\n \n out:\n \tbatadv_tt_global_entry_put(tt_global_entry);\n@@ -1763,10 +1879,12 @@ static struct batadv_tt_orig_list_entry *\n batadv_transtable_best_orig(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_tt_global_entry *tt_global_entry)\n {\n-\tstruct batadv_neigh_node *router, *best_router = NULL;\n+\tstruct batadv_tt_orig_list_entry *best_entry = NULL;\n \tstruct batadv_algo_ops *bao = bat_priv-\u003ealgo_ops;\n+\tstruct batadv_neigh_node *best_router = NULL;\n+\tstruct batadv_tt_orig_list_entry *orig_entry;\n+\tstruct batadv_neigh_node *router;\n \tstruct hlist_head *head;\n-\tstruct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;\n \n \thead = \u0026tt_global_entry-\u003eorig_list;\n \thlist_for_each_entry_rcu(orig_entry, head, list) {\n@@ -1811,10 +1929,10 @@ batadv_tt_global_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,\n \t\t\t struct batadv_tt_orig_list_entry *orig,\n \t\t\t bool best)\n {\n-\tu16 flags = (common-\u003eflags \u0026 (~BATADV_TT_SYNC_MASK)) | orig-\u003eflags;\n-\tvoid *hdr;\n+\tu16 flags = (atomic_read(\u0026common-\u003eflags) \u0026 (~BATADV_TT_SYNC_MASK)) | orig-\u003eflags;\n \tstruct batadv_orig_node_vlan *vlan;\n \tu8 last_ttvn;\n+\tvoid *hdr;\n \tu32 crc;\n \n \tvlan = batadv_orig_node_vlan_get(orig-\u003eorig_node,\n@@ -1873,7 +1991,8 @@ batadv_tt_global_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,\n \t\t\t struct batadv_priv *bat_priv,\n \t\t\t struct batadv_tt_common_entry *common, int *sub_s)\n {\n-\tstruct batadv_tt_orig_list_entry *orig_entry, *best_entry;\n+\tstruct batadv_tt_orig_list_entry *orig_entry;\n+\tstruct batadv_tt_orig_list_entry *best_entry;\n \tstruct batadv_tt_global_entry *global;\n \tstruct hlist_head *head;\n \tint sub = 0;\n@@ -1948,16 +2067,16 @@ batadv_tt_global_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,\n */\n int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb)\n {\n-\tstruct net_device *mesh_iface;\n-\tstruct batadv_priv *bat_priv;\n \tstruct batadv_hard_iface *primary_if = NULL;\n+\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n+\tstruct net_device *mesh_iface;\n \tstruct batadv_hashtable *hash;\n-\tstruct hlist_head *head;\n-\tint ret;\n+\tstruct batadv_priv *bat_priv;\n \tint bucket = cb-\u003eargs[0];\n+\tstruct hlist_head *head;\n \tint idx = cb-\u003eargs[1];\n \tint sub = cb-\u003eargs[2];\n-\tint portid = NETLINK_CB(cb-\u003eskb).portid;\n+\tint ret;\n \n \tmesh_iface = batadv_netlink_get_meshif(cb);\n \tif (IS_ERR(mesh_iface))\n@@ -2024,13 +2143,17 @@ _batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry *tt_global_entry,\n \tbatadv_tt_orig_list_entry_put(orig_entry);\n }\n \n-/* deletes the orig list of a tt_global_entry */\n+/**\n+ * batadv_tt_global_del_orig_list() - drop every orig_list_entry of a global\n+ * TT entry\n+ * @tt_global_entry: the global TT entry to clear\n+ */\n static void\n batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry)\n {\n+\tstruct batadv_tt_orig_list_entry *orig_entry;\n \tstruct hlist_head *head;\n \tstruct hlist_node *safe;\n-\tstruct batadv_tt_orig_list_entry *orig_entry;\n \n \tspin_lock_bh(\u0026tt_global_entry-\u003elist_lock);\n \thead = \u0026tt_global_entry-\u003eorig_list;\n@@ -2055,9 +2178,9 @@ batadv_tt_global_del_orig_node(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_orig_node *orig_node,\n \t\t\t const char *message)\n {\n+\tstruct batadv_tt_orig_list_entry *orig_entry;\n \tstruct hlist_head *head;\n \tstruct hlist_node *safe;\n-\tstruct batadv_tt_orig_list_entry *orig_entry;\n \tunsigned short vid;\n \n \tspin_lock_bh(\u0026tt_global_entry-\u003elist_lock);\n@@ -2077,9 +2200,17 @@ batadv_tt_global_del_orig_node(struct batadv_priv *bat_priv,\n \tspin_unlock_bh(\u0026tt_global_entry-\u003elist_lock);\n }\n \n-/* If the client is to be deleted, we check if it is the last origantor entry\n- * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the\n- * timer, otherwise we simply remove the originator scheduled for deletion.\n+/**\n+ * batadv_tt_global_del_roaming() - remove a roaming client from a global TT\n+ * entry\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @tt_global_entry: the global TT entry of the roaming client\n+ * @orig_node: the originator that the client has roamed away from\n+ * @message: debug message describing the reason for the change\n+ *\n+ * If @orig_node was the last announced source for the client, mark the entry\n+ * for roaming so it can be cleaned up after the roaming timer expires.\n+ * Otherwise simply remove the orig_node entry from the announcer list.\n */\n static void\n batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,\n@@ -2087,9 +2218,9 @@ batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_orig_node *orig_node,\n \t\t\t const char *message)\n {\n-\tbool last_entry = true;\n-\tstruct hlist_head *head;\n \tstruct batadv_tt_orig_list_entry *orig_entry;\n+\tstruct hlist_head *head;\n+\tbool last_entry = true;\n \n \t/* no local entry exists, case 1:\n \t * Check if this is the last one or if other entries exist.\n@@ -2107,7 +2238,7 @@ batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,\n \n \tif (last_entry) {\n \t\t/* its the last one, mark for roaming. */\n-\t\ttt_global_entry-\u003ecommon.flags |= BATADV_TT_CLIENT_ROAM;\n+\t\tatomic_or(BATADV_TT_CLIENT_ROAM, \u0026tt_global_entry-\u003ecommon.flags);\n \t\ttt_global_entry-\u003eroam_at = jiffies;\n \t} else {\n \t\t/* there is another entry, we can simply delete this\n@@ -2133,8 +2264,8 @@ static void batadv_tt_global_del(struct batadv_priv *bat_priv,\n \t\t\t\t const unsigned char *addr, unsigned short vid,\n \t\t\t\t const char *message, bool roaming)\n {\n-\tstruct batadv_tt_global_entry *tt_global_entry;\n \tstruct batadv_tt_local_entry *local_entry = NULL;\n+\tstruct batadv_tt_global_entry *tt_global_entry;\n \n \ttt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);\n \tif (!tt_global_entry)\n@@ -2196,14 +2327,14 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,\n \t\t\t s32 match_vid,\n \t\t\t const char *message)\n {\n-\tstruct batadv_tt_global_entry *tt_global;\n-\tstruct batadv_tt_common_entry *tt_common_entry;\n-\tu32 i;\n+\tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tstruct batadv_hashtable *hash = bat_priv-\u003ett.global_hash;\n+\tstruct batadv_tt_common_entry *tt_common_entry;\n+\tstruct batadv_tt_global_entry *tt_global;\n \tstruct hlist_node *safe;\n \tstruct hlist_head *head;\n-\tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tunsigned short vid;\n+\tu32 i;\n \n \tif (!hash)\n \t\treturn;\n@@ -2241,20 +2372,30 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,\n \tclear_bit(BATADV_ORIG_CAPA_HAS_TT, \u0026orig_node-\u003ecapa_initialized);\n }\n \n+/**\n+ * batadv_tt_global_to_purge() - check whether a global TT entry has to be\n+ * purged\n+ * @tt_global: global TT entry under consideration\n+ * @msg: storage for a pointer to a human readable reason on return\n+ *\n+ * Return: true if the entry should be purged because its roaming or temporary\n+ * timer has elapsed; false otherwise\n+ */\n static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,\n \t\t\t\t char **msg)\n {\n-\tbool purge = false;\n \tunsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT;\n \tunsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT;\n+\tu16 flags = atomic_read(\u0026tt_global-\u003ecommon.flags);\n+\tbool purge = false;\n \n-\tif ((tt_global-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ROAM) \u0026\u0026\n+\tif ((flags \u0026 BATADV_TT_CLIENT_ROAM) \u0026\u0026\n \t batadv_has_timed_out(tt_global-\u003eroam_at, roam_timeout)) {\n \t\tpurge = true;\n \t\t*msg = \"Roaming timeout\\n\";\n \t}\n \n-\tif ((tt_global-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_TEMP) \u0026\u0026\n+\tif ((flags \u0026 BATADV_TT_CLIENT_TEMP) \u0026\u0026\n \t batadv_has_timed_out(tt_global-\u003ecommon.added_at, temp_timeout)) {\n \t\tpurge = true;\n \t\t*msg = \"Temporary client timeout\\n\";\n@@ -2263,16 +2404,23 @@ static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,\n \treturn purge;\n }\n \n+/**\n+ * batadv_tt_global_purge() - purge expired global translation table entries\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Iterate over the global translation table and drop every entry that the\n+ * roaming or temporary timer has expired for.\n+ */\n static void batadv_tt_global_purge(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_hashtable *hash = bat_priv-\u003ett.global_hash;\n-\tstruct hlist_head *head;\n-\tstruct hlist_node *node_tmp;\n \tspinlock_t *list_lock; /* protects write access to the hash lists */\n-\tu32 i;\n-\tchar *msg = NULL;\n+\tstruct batadv_hashtable *hash = bat_priv-\u003ett.global_hash;\n \tstruct batadv_tt_common_entry *tt_common;\n \tstruct batadv_tt_global_entry *tt_global;\n+\tstruct hlist_node *node_tmp;\n+\tstruct hlist_head *head;\n+\tchar *msg = NULL;\n+\tu32 i;\n \n \tfor (i = 0; i \u003c hash-\u003esize; i++) {\n \t\thead = \u0026hash-\u003etable[i];\n@@ -2302,12 +2450,19 @@ static void batadv_tt_global_purge(struct batadv_priv *bat_priv)\n \t}\n }\n \n+/**\n+ * batadv_tt_global_table_free() - release the global translation table\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Drop every entry of the global TT hash, free their references and finally\n+ * release the hashtable itself.\n+ */\n static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_hashtable *hash;\n \tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tstruct batadv_tt_common_entry *tt_common_entry;\n \tstruct batadv_tt_global_entry *tt_global;\n+\tstruct batadv_hashtable *hash;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n \tu32 i;\n@@ -2338,17 +2493,30 @@ static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)\n \tbat_priv-\u003ett.global_hash = NULL;\n }\n \n+/**\n+ * _batadv_is_ap_isolated() - check whether two clients are AP-isolated from\n+ * each other\n+ * @tt_local_entry: local TT entry of the sending client\n+ * @tt_global_entry: global TT entry of the destination client\n+ *\n+ * Return: true if traffic between the two clients should be dropped because\n+ * either both are WiFi clients or both carry the ISOLATION flag; false\n+ * otherwise\n+ */\n static bool\n _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,\n \t\t struct batadv_tt_global_entry *tt_global_entry)\n {\n-\tif (tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_WIFI \u0026\u0026\n-\t tt_global_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_WIFI)\n+\tu16 global_flags = atomic_read(\u0026tt_global_entry-\u003ecommon.flags);\n+\tu16 local_flags = atomic_read(\u0026tt_local_entry-\u003ecommon.flags);\n+\n+\tif (local_flags \u0026 BATADV_TT_CLIENT_WIFI \u0026\u0026\n+\t global_flags \u0026 BATADV_TT_CLIENT_WIFI)\n \t\treturn true;\n \n \t/* check if the two clients are marked as isolated */\n-\tif (tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ISOLA \u0026\u0026\n-\t tt_global_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ISOLA)\n+\tif (local_flags \u0026 BATADV_TT_CLIENT_ISOLA \u0026\u0026\n+\t global_flags \u0026 BATADV_TT_CLIENT_ISOLA)\n \t\treturn true;\n \n \treturn false;\n@@ -2373,15 +2541,15 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,\n \t\t\t\t\t\t const u8 *addr,\n \t\t\t\t\t\t unsigned short vid)\n {\n-\tstruct batadv_tt_local_entry *tt_local_entry = NULL;\n \tstruct batadv_tt_global_entry *tt_global_entry = NULL;\n-\tstruct batadv_orig_node *orig_node = NULL;\n+\tstruct batadv_tt_local_entry *tt_local_entry = NULL;\n \tstruct batadv_tt_orig_list_entry *best_entry;\n+\tstruct batadv_orig_node *orig_node = NULL;\n \n \tif (src \u0026\u0026 batadv_vlan_ap_isola_get(bat_priv, vid)) {\n \t\ttt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid);\n \t\tif (!tt_local_entry ||\n-\t\t (tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_PENDING))\n+\t\t (atomic_read(\u0026tt_local_entry-\u003ecommon.flags) \u0026 BATADV_TT_CLIENT_PENDING))\n \t\t\tgoto out;\n \t}\n \n@@ -2445,9 +2613,12 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,\n \tstruct batadv_tt_common_entry *tt_common;\n \tstruct batadv_tt_global_entry *tt_global;\n \tstruct hlist_head *head;\n-\tu32 i, crc_tmp, crc = 0;\n-\tu8 flags;\n+\tu16 entry_flags;\n \t__be16 tmp_vid;\n+\tu32 crc_tmp;\n+\tu32 crc = 0;\n+\tu8 flags;\n+\tu32 i;\n \n \tfor (i = 0; i \u003c hash-\u003esize; i++) {\n \t\thead = \u0026hash-\u003etable[i];\n@@ -2463,18 +2634,20 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,\n \t\t\tif (tt_common-\u003evid != vid)\n \t\t\t\tcontinue;\n \n+\t\t\tentry_flags = atomic_read(\u0026tt_common-\u003eflags);\n+\n \t\t\t/* Roaming clients are in the global table for\n \t\t\t * consistency only. They don't have to be\n \t\t\t * taken into account while computing the\n \t\t\t * global crc\n \t\t\t */\n-\t\t\tif (tt_common-\u003eflags \u0026 BATADV_TT_CLIENT_ROAM)\n+\t\t\tif (entry_flags \u0026 BATADV_TT_CLIENT_ROAM)\n \t\t\t\tcontinue;\n \t\t\t/* Temporary clients have not been announced yet, so\n \t\t\t * they have to be skipped while computing the global\n \t\t\t * crc\n \t\t\t */\n-\t\t\tif (tt_common-\u003eflags \u0026 BATADV_TT_CLIENT_TEMP)\n+\t\t\tif (entry_flags \u0026 BATADV_TT_CLIENT_TEMP)\n \t\t\t\tcontinue;\n \n \t\t\t/* find out if this global entry is announced by this\n@@ -2523,9 +2696,12 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,\n \tstruct batadv_hashtable *hash = bat_priv-\u003ett.local_hash;\n \tstruct batadv_tt_common_entry *tt_common;\n \tstruct hlist_head *head;\n-\tu32 i, crc_tmp, crc = 0;\n-\tu8 flags;\n+\tu16 entry_flags;\n \t__be16 tmp_vid;\n+\tu32 crc_tmp;\n+\tu32 crc = 0;\n+\tu8 flags;\n+\tu32 i;\n \n \tfor (i = 0; i \u003c hash-\u003esize; i++) {\n \t\thead = \u0026hash-\u003etable[i];\n@@ -2538,10 +2714,12 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,\n \t\t\tif (tt_common-\u003evid != vid)\n \t\t\t\tcontinue;\n \n+\t\t\tentry_flags = atomic_read(\u0026tt_common-\u003eflags);\n+\n \t\t\t/* not yet committed clients have not to be taken into\n \t\t\t * account while computing the CRC\n \t\t\t */\n-\t\t\tif (tt_common-\u003eflags \u0026 BATADV_TT_CLIENT_NEW)\n+\t\t\tif (entry_flags \u0026 BATADV_TT_CLIENT_NEW)\n \t\t\t\tcontinue;\n \n \t\t\t/* use network order to read the VID: this ensures that\n@@ -2553,7 +2731,7 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,\n \t\t\t/* compute the CRC on flags that have to be kept in sync\n \t\t\t * among nodes\n \t\t\t */\n-\t\t\tflags = tt_common-\u003eflags \u0026 BATADV_TT_SYNC_MASK;\n+\t\t\tflags = entry_flags \u0026 BATADV_TT_SYNC_MASK;\n \t\t\tcrc_tmp = crc32c(crc_tmp, \u0026flags, sizeof(flags));\n \n \t\t\tcrc ^= crc32c(crc_tmp, tt_common-\u003eaddr, ETH_ALEN);\n@@ -2590,6 +2768,10 @@ static void batadv_tt_req_node_put(struct batadv_tt_req_node *tt_req_node)\n \tkref_put(\u0026tt_req_node-\u003erefcount, batadv_tt_req_node_release);\n }\n \n+/**\n+ * batadv_tt_req_list_free() - drop all pending TT requests\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ */\n static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)\n {\n \tstruct batadv_tt_req_node *node;\n@@ -2605,6 +2787,18 @@ static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)\n \tspin_unlock_bh(\u0026bat_priv-\u003ett.req_list_lock);\n }\n \n+/**\n+ * batadv_tt_save_orig_buffer() - cache the latest TT TVLV payload of an\n+ * originator\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @orig_node: originator for which the buffer should be created\n+ * @tt_buff: pointer to the TT TVLV payload to cache\n+ * @tt_buff_len: length of @tt_buff in bytes\n+ *\n+ * Replace the previously cached TT payload of @orig_node with a copy of\n+ * @tt_buff. The buffer is left untouched when @tt_buff_len is 0 so that\n+ * empty OGM updates do not discard the previously cached data.\n+ */\n static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_orig_node *orig_node,\n \t\t\t\t const void *tt_buff,\n@@ -2626,6 +2820,10 @@ static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,\n \tspin_unlock_bh(\u0026orig_node-\u003ett_buff_lock);\n }\n \n+/**\n+ * batadv_tt_req_purge() - drop timed-out TT requests\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ */\n static void batadv_tt_req_purge(struct batadv_priv *bat_priv)\n {\n \tstruct batadv_tt_req_node *node;\n@@ -2654,7 +2852,8 @@ static struct batadv_tt_req_node *\n batadv_tt_req_node_new(struct batadv_priv *bat_priv,\n \t\t struct batadv_orig_node *orig_node)\n {\n-\tstruct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL;\n+\tstruct batadv_tt_req_node *tt_req_node = NULL;\n+\tstruct batadv_tt_req_node *tt_req_node_tmp;\n \n \tspin_lock_bh(\u0026bat_priv-\u003ett.req_list_lock);\n \thlist_for_each_entry(tt_req_node_tmp, \u0026bat_priv-\u003ett.req_list, list) {\n@@ -2695,12 +2894,13 @@ static bool batadv_tt_local_valid(const void *entry_ptr,\n \t\t\t\t u8 *flags)\n {\n \tconst struct batadv_tt_common_entry *tt_common_entry = entry_ptr;\n+\tu16 entry_flags = atomic_read(\u0026tt_common_entry-\u003eflags);\n \n-\tif (tt_common_entry-\u003eflags \u0026 BATADV_TT_CLIENT_NEW)\n+\tif (entry_flags \u0026 BATADV_TT_CLIENT_NEW)\n \t\treturn false;\n \n \tif (flags)\n-\t\t*flags = tt_common_entry-\u003eflags;\n+\t\t*flags = entry_flags;\n \n \treturn true;\n }\n@@ -2724,9 +2924,10 @@ static bool batadv_tt_global_valid(const void *entry_ptr,\n \tconst struct batadv_tt_common_entry *tt_common_entry = entry_ptr;\n \tconst struct batadv_tt_global_entry *tt_global_entry;\n \tconst struct batadv_orig_node *orig_node = data_ptr;\n+\tu16 entry_flags;\n \n-\tif (tt_common_entry-\u003eflags \u0026 BATADV_TT_CLIENT_ROAM ||\n-\t tt_common_entry-\u003eflags \u0026 BATADV_TT_CLIENT_TEMP)\n+\tentry_flags = atomic_read(\u0026tt_common_entry-\u003eflags);\n+\tif (entry_flags \u0026 (BATADV_TT_CLIENT_ROAM | BATADV_TT_CLIENT_TEMP))\n \t\treturn false;\n \n \ttt_global_entry = container_of(tt_common_entry,\n@@ -2763,7 +2964,8 @@ static u16 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,\n \tstruct batadv_tt_common_entry *tt_common_entry;\n \tstruct batadv_tvlv_tt_change *tt_change;\n \tstruct hlist_head *head;\n-\tu16 tt_tot, tt_num_entries = 0;\n+\tu16 tt_num_entries = 0;\n+\tu16 tt_tot;\n \tu8 flags;\n \tbool ret;\n \tu32 i;\n@@ -2817,8 +3019,9 @@ static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node,\n {\n \tstruct batadv_tvlv_tt_vlan_data *tt_vlan_tmp;\n \tstruct batadv_orig_node_vlan *vlan;\n-\tint i, orig_num_vlan;\n+\tint orig_num_vlan;\n \tu32 crc;\n+\tint i;\n \n \t/* check if each received CRC matches the locally stored one */\n \tfor (i = 0; i \u003c num_vlan; i++) {\n@@ -2924,7 +3127,8 @@ static bool batadv_send_tt_request(struct batadv_priv *bat_priv,\n \tstruct batadv_tt_req_node *tt_req_node = NULL;\n \tstruct batadv_hard_iface *primary_if;\n \tbool ret = false;\n-\tint i, size;\n+\tint size;\n+\tint i;\n \n \tprimary_if = batadv_primary_if_get_selected(bat_priv);\n \tif (!primary_if)\n@@ -3000,13 +3204,15 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,\n \t\t\t\t\t struct batadv_tvlv_tt_data *tt_data,\n \t\t\t\t\t u8 *req_src, u8 *req_dst)\n {\n-\tstruct batadv_orig_node *req_dst_orig_node;\n \tstruct batadv_orig_node *res_dst_orig_node = NULL;\n-\tstruct batadv_tvlv_tt_change *tt_change;\n \tstruct batadv_tvlv_tt_data *tvlv_tt_data = NULL;\n-\tbool ret = false, full_table;\n-\tu8 orig_ttvn, req_ttvn;\n+\tstruct batadv_orig_node *req_dst_orig_node;\n+\tstruct batadv_tvlv_tt_change *tt_change;\n+\tbool ret = false;\n+\tbool full_table;\n+\tu8 orig_ttvn;\n \tu16 tvlv_len;\n+\tu8 req_ttvn;\n \ts32 tt_len;\n \n \tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n@@ -3133,9 +3339,10 @@ static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv,\n \tstruct batadv_hard_iface *primary_if = NULL;\n \tstruct batadv_tvlv_tt_change *tt_change;\n \tstruct batadv_orig_node *orig_node;\n-\tu8 my_ttvn, req_ttvn;\n-\tu16 tvlv_len;\n \tbool full_table;\n+\tu16 tvlv_len;\n+\tu8 req_ttvn;\n+\tu8 my_ttvn;\n \ts32 tt_len;\n \n \tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n@@ -3253,13 +3460,25 @@ static bool batadv_send_tt_response(struct batadv_priv *bat_priv,\n \t\t\t\t\t req_dst);\n }\n \n+/**\n+ * _batadv_tt_update_changes() - apply a list of TT changes to the global TT\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @orig_node: originator announcing the changes\n+ * @tt_change: array of TT change entries to apply\n+ * @tt_num_changes: number of entries in @tt_change\n+ * @ttvn: TTVN of @orig_node corresponding to @tt_change\n+ *\n+ * Walk @tt_change and add/remove the announced clients in the global TT.\n+ * Abort early without marking the TTVN as up to date if adding an entry\n+ * fails, so that the next TT request can re-sync the full table.\n+ */\n static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_orig_node *orig_node,\n \t\t\t\t struct batadv_tvlv_tt_change *tt_change,\n \t\t\t\t u16 tt_num_changes, u8 ttvn)\n {\n-\tint i;\n \tint roams;\n+\tint i;\n \n \tfor (i = 0; i \u003c tt_num_changes; i++) {\n \t\tif ((tt_change + i)-\u003eflags \u0026 BATADV_TT_CLIENT_DEL) {\n@@ -3286,6 +3505,18 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,\n \tset_bit(BATADV_ORIG_CAPA_HAS_TT, \u0026orig_node-\u003ecapa_initialized);\n }\n \n+/**\n+ * batadv_tt_fill_gtable() - replace the cached TT of an originator with a\n+ * full table response\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @tt_change: array of TT change entries describing the full table\n+ * @ttvn: TTVN announced together with the full table\n+ * @resp_src: MAC address of the responder\n+ * @num_entries: number of entries in @tt_change\n+ *\n+ * Drop the previously known global TT entries of @resp_src and replace them\n+ * with the entries from a freshly received full TT response.\n+ */\n static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_tvlv_tt_change *tt_change,\n \t\t\t\t u8 ttvn, u8 *resp_src,\n@@ -3316,6 +3547,15 @@ static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,\n \tbatadv_orig_node_put(orig_node);\n }\n \n+/**\n+ * batadv_tt_update_changes() - apply an incremental TT changeset to the\n+ * global TT\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ * @orig_node: originator announcing the changes\n+ * @tt_num_changes: number of entries in @tt_change\n+ * @ttvn: TTVN of @orig_node corresponding to @tt_change\n+ * @tt_change: array of TT change entries to apply\n+ */\n static void batadv_tt_update_changes(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_orig_node *orig_node,\n \t\t\t\t u16 tt_num_changes, u8 ttvn,\n@@ -3342,6 +3582,7 @@ bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,\n {\n \tstruct batadv_tt_local_entry *tt_local_entry;\n \tbool ret = false;\n+\tu16 entry_flags;\n \n \ttt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);\n \tif (!tt_local_entry)\n@@ -3349,8 +3590,8 @@ bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,\n \t/* Check if the client has been logically deleted (but is kept for\n \t * consistency purpose)\n \t */\n-\tif ((tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_PENDING) ||\n-\t (tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ROAM))\n+\tentry_flags = atomic_read(\u0026tt_local_entry-\u003ecommon.flags);\n+\tif (entry_flags \u0026 (BATADV_TT_CLIENT_PENDING | BATADV_TT_CLIENT_ROAM))\n \t\tgoto out;\n \tret = true;\n out:\n@@ -3369,11 +3610,11 @@ static void batadv_handle_tt_response(struct batadv_priv *bat_priv,\n \t\t\t\t struct batadv_tvlv_tt_data *tt_data,\n \t\t\t\t u8 *resp_src, u16 num_entries)\n {\n-\tstruct batadv_tt_req_node *node;\n-\tstruct hlist_node *safe;\n \tstruct batadv_orig_node *orig_node = NULL;\n \tstruct batadv_tvlv_tt_change *tt_change;\n+\tstruct batadv_tt_req_node *node;\n \tu8 *tvlv_ptr = (u8 *)tt_data;\n+\tstruct hlist_node *safe;\n \n \tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n \t\t \"Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\\n\",\n@@ -3416,9 +3657,14 @@ static void batadv_handle_tt_response(struct batadv_priv *bat_priv,\n \tbatadv_orig_node_put(orig_node);\n }\n \n+/**\n+ * batadv_tt_roam_list_free() - drop all entries from the roaming clients list\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ */\n static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_tt_roam_node *node, *safe;\n+\tstruct batadv_tt_roam_node *node;\n+\tstruct batadv_tt_roam_node *safe;\n \n \tspin_lock_bh(\u0026bat_priv-\u003ett.roam_list_lock);\n \n@@ -3430,9 +3676,14 @@ static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)\n \tspin_unlock_bh(\u0026bat_priv-\u003ett.roam_list_lock);\n }\n \n+/**\n+ * batadv_tt_roam_purge() - drop timed-out roaming clients\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ */\n static void batadv_tt_roam_purge(struct batadv_priv *bat_priv)\n {\n-\tstruct batadv_tt_roam_node *node, *safe;\n+\tstruct batadv_tt_roam_node *node;\n+\tstruct batadv_tt_roam_node *safe;\n \n \tspin_lock_bh(\u0026bat_priv-\u003ett.roam_list_lock);\n \tlist_for_each_entry_safe(node, safe, \u0026bat_priv-\u003ett.roam_list, list) {\n@@ -3522,8 +3773,8 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,\n \t\t\t\t unsigned short vid,\n \t\t\t\t struct batadv_orig_node *orig_node)\n {\n-\tstruct batadv_hard_iface *primary_if;\n \tstruct batadv_tvlv_roam_adv tvlv_roam;\n+\tstruct batadv_hard_iface *primary_if;\n \n \tprimary_if = batadv_primary_if_get_selected(bat_priv);\n \tif (!primary_if)\n@@ -3552,6 +3803,14 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,\n \tbatadv_hardif_put(primary_if);\n }\n \n+/**\n+ * batadv_tt_purge() - periodic worker to maintain the translation table\n+ * @work: delayed work embedded in the per-mesh-interface TT state\n+ *\n+ * Purge timed-out entries from the local and global TT, drop stale TT\n+ * requests and roaming clients, and reschedule the next run after\n+ * BATADV_TT_WORK_PERIOD milliseconds.\n+ */\n static void batadv_tt_purge(struct work_struct *work)\n {\n \tstruct delayed_work *delayed_work;\n@@ -3594,19 +3853,17 @@ void batadv_tt_free(struct batadv_priv *bat_priv)\n }\n \n /**\n- * batadv_tt_local_set_flags() - set or unset the specified flags on the local\n- * table and possibly count them in the TT size\n+ * batadv_tt_local_transition_new() - unset the NEW flag on the local\n+ * table and count them in the TT size\n * @bat_priv: the bat priv with all the mesh interface information\n- * @flags: the flag to switch\n- * @enable: whether to set or unset the flag\n- * @count: whether to increase the TT size by the number of changed entries\n */\n-static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,\n-\t\t\t\t bool enable, bool count)\n+static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv)\n {\n \tstruct batadv_hashtable *hash = bat_priv-\u003ett.local_hash;\n \tstruct batadv_tt_common_entry *tt_common_entry;\n \tstruct hlist_head *head;\n+\tatomic_t *entry_flags;\n+\tu16 old_flags;\n \tu32 i;\n \n \tif (!hash)\n@@ -3618,17 +3875,15 @@ static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,\n \t\trcu_read_lock();\n \t\thlist_for_each_entry_rcu(tt_common_entry,\n \t\t\t\t\t head, hash_entry) {\n-\t\t\tif (enable) {\n-\t\t\t\tif ((tt_common_entry-\u003eflags \u0026 flags) == flags)\n-\t\t\t\t\tcontinue;\n-\t\t\t\ttt_common_entry-\u003eflags |= flags;\n-\t\t\t} else {\n-\t\t\t\tif (!(tt_common_entry-\u003eflags \u0026 flags))\n-\t\t\t\t\tcontinue;\n-\t\t\t\ttt_common_entry-\u003eflags \u0026= ~flags;\n-\t\t\t}\n+\t\t\tentry_flags = \u0026tt_common_entry-\u003eflags;\n+\t\t\told_flags = atomic_read(entry_flags);\n+\n+\t\t\tif (!(old_flags \u0026 BATADV_TT_CLIENT_NEW))\n+\t\t\t\tcontinue;\n \n-\t\t\tif (!count)\n+\t\t\told_flags = atomic_fetch_andnot(BATADV_TT_CLIENT_NEW,\n+\t\t\t\t\t\t\tentry_flags);\n+\t\t\tif (!(old_flags \u0026 BATADV_TT_CLIENT_NEW))\n \t\t\t\tcontinue;\n \n \t\t\tbatadv_tt_local_size_inc(bat_priv,\n@@ -3638,15 +3893,22 @@ static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,\n \t}\n }\n \n-/* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */\n+/**\n+ * batadv_tt_local_purge_pending_clients() - finalise removal of pending local\n+ * clients\n+ * @bat_priv: the bat priv with all the mesh interface information\n+ *\n+ * Iterate over the local TT and physically remove every entry that has been\n+ * marked as BATADV_TT_CLIENT_PENDING.\n+ */\n static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)\n {\n+\tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tstruct batadv_hashtable *hash = bat_priv-\u003ett.local_hash;\n \tstruct batadv_tt_common_entry *tt_common;\n \tstruct batadv_tt_local_entry *tt_local;\n \tstruct hlist_node *node_tmp;\n \tstruct hlist_head *head;\n-\tspinlock_t *list_lock; /* protects write access to the hash lists */\n \tu32 i;\n \n \tif (!hash)\n@@ -3659,7 +3921,7 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)\n \t\tspin_lock_bh(list_lock);\n \t\thlist_for_each_entry_safe(tt_common, node_tmp, head,\n \t\t\t\t\t hash_entry) {\n-\t\t\tif (!(tt_common-\u003eflags \u0026 BATADV_TT_CLIENT_PENDING))\n+\t\t\tif (!(atomic_read(\u0026tt_common-\u003eflags) \u0026 BATADV_TT_CLIENT_PENDING))\n \t\t\t\tcontinue;\n \n \t\t\tbatadv_dbg(BATADV_DBG_TT, bat_priv,\n@@ -3696,7 +3958,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)\n \t\treturn;\n \t}\n \n-\tbatadv_tt_local_set_flags(bat_priv, BATADV_TT_CLIENT_NEW, false, true);\n+\tbatadv_tt_local_transition_new(bat_priv);\n \n \tbatadv_tt_local_purge_pending_clients(bat_priv);\n \tbatadv_tt_local_update_crc(bat_priv);\n@@ -3736,8 +3998,8 @@ void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv)\n bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst,\n \t\t\t unsigned short vid)\n {\n-\tstruct batadv_tt_local_entry *tt_local_entry;\n \tstruct batadv_tt_global_entry *tt_global_entry;\n+\tstruct batadv_tt_local_entry *tt_local_entry;\n \tstruct batadv_meshif_vlan *vlan;\n \tbool ret = false;\n \n@@ -3872,7 +4134,7 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,\n \tif (!tt_global_entry)\n \t\tgoto out;\n \n-\tret = tt_global_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ROAM;\n+\tret = atomic_read(\u0026tt_global_entry-\u003ecommon.flags) \u0026 BATADV_TT_CLIENT_ROAM;\n \tbatadv_tt_global_entry_put(tt_global_entry);\n out:\n \treturn ret;\n@@ -3898,7 +4160,7 @@ bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,\n \tif (!tt_local_entry)\n \t\tgoto out;\n \n-\tret = tt_local_entry-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ROAM;\n+\tret = atomic_read(\u0026tt_local_entry-\u003ecommon.flags) \u0026 BATADV_TT_CLIENT_ROAM;\n \tbatadv_tt_local_entry_put(tt_local_entry);\n out:\n \treturn ret;\n@@ -3947,13 +4209,15 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,\n void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)\n {\n \tstruct batadv_priv *bat_priv = netdev_priv(mesh_iface);\n-\tint packet_size_max = READ_ONCE(bat_priv-\u003epacket_size_max);\n-\tint table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2;\n+\tint timeout = BATADV_TT_LOCAL_TIMEOUT / 2;\n \tbool reduced = false;\n+\tint packet_size_max;\n+\tint table_size;\n \n \tspin_lock_bh(\u0026bat_priv-\u003ett.commit_lock);\n \n \twhile (timeout) {\n+\t\tpacket_size_max = READ_ONCE(bat_priv-\u003epacket_size_max);\n \t\ttable_size = batadv_tt_local_table_transmit_size(bat_priv);\n \t\tif (packet_size_max \u003e= table_size)\n \t\t\tbreak;\n@@ -3992,8 +4256,9 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,\n {\n \tstruct batadv_tvlv_tt_change *tt_change;\n \tstruct batadv_tvlv_tt_data *tt_data;\n-\tu16 num_entries, num_vlan;\n \tsize_t tt_data_sz;\n+\tu16 num_entries;\n+\tu16 num_vlan;\n \n \tif (tvlv_value_len \u003c sizeof(*tt_data))\n \t\treturn;\n@@ -4115,8 +4380,8 @@ static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,\n \t\t\t\t\t void *tvlv_value,\n \t\t\t\t\t u16 tvlv_value_len)\n {\n-\tstruct batadv_tvlv_roam_adv *roaming_adv;\n \tstruct batadv_orig_node *orig_node = NULL;\n+\tstruct batadv_tvlv_roam_adv *roaming_adv;\n \n \t/* If this node is not the intended recipient of the\n \t * roaming advertisement the packet is forwarded\n@@ -4205,7 +4470,7 @@ bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,\n \tif (!tt)\n \t\treturn false;\n \n-\tret = tt-\u003ecommon.flags \u0026 BATADV_TT_CLIENT_ISOLA;\n+\tret = atomic_read(\u0026tt-\u003ecommon.flags) \u0026 BATADV_TT_CLIENT_ISOLA;\n \n \tbatadv_tt_global_entry_put(tt);\n \n@@ -4219,12 +4484,12 @@ bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,\n */\n int __init batadv_tt_cache_init(void)\n {\n-\tsize_t tl_size = sizeof(struct batadv_tt_local_entry);\n-\tsize_t tg_size = sizeof(struct batadv_tt_global_entry);\n \tsize_t tt_orig_size = sizeof(struct batadv_tt_orig_list_entry);\n \tsize_t tt_change_size = sizeof(struct batadv_tt_change_node);\n-\tsize_t tt_req_size = sizeof(struct batadv_tt_req_node);\n \tsize_t tt_roam_size = sizeof(struct batadv_tt_roam_node);\n+\tsize_t tg_size = sizeof(struct batadv_tt_global_entry);\n+\tsize_t tt_req_size = sizeof(struct batadv_tt_req_node);\n+\tsize_t tl_size = sizeof(struct batadv_tt_local_entry);\n \n \tbatadv_tl_cache = kmem_cache_create(\"batadv_tl_cache\", tl_size, 0,\n \t\t\t\t\t SLAB_HWCACHE_ALIGN, NULL);\ndiff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c\nindex 49bf2ed9ecdc3..5600aaf00627c 100644\n--- a/net/batman-adv/tvlv.c\n+++ b/net/batman-adv/tvlv.c\n@@ -72,7 +72,8 @@ static void batadv_tvlv_handler_put(struct batadv_tvlv_handler *tvlv_handler)\n static struct batadv_tvlv_handler *\n batadv_tvlv_handler_get(struct batadv_priv *bat_priv, u8 type, u8 version)\n {\n-\tstruct batadv_tvlv_handler *tvlv_handler_tmp, *tvlv_handler = NULL;\n+\tstruct batadv_tvlv_handler *tvlv_handler = NULL;\n+\tstruct batadv_tvlv_handler *tvlv_handler_tmp;\n \n \trcu_read_lock();\n \thlist_for_each_entry_rcu(tvlv_handler_tmp,\n@@ -134,7 +135,8 @@ static void batadv_tvlv_container_put(struct batadv_tvlv_container *tvlv)\n static struct batadv_tvlv_container *\n batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version)\n {\n-\tstruct batadv_tvlv_container *tvlv_tmp, *tvlv = NULL;\n+\tstruct batadv_tvlv_container *tvlv = NULL;\n+\tstruct batadv_tvlv_container *tvlv_tmp;\n \n \tlockdep_assert_held(\u0026bat_priv-\u003etvlv.container_list_lock);\n \n@@ -236,7 +238,8 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,\n \t\t\t\t u8 type, u8 version,\n \t\t\t\t void *tvlv_value, u16 tvlv_value_len)\n {\n-\tstruct batadv_tvlv_container *tvlv_old, *tvlv_new;\n+\tstruct batadv_tvlv_container *tvlv_old;\n+\tstruct batadv_tvlv_container *tvlv_new;\n \n \tif (!tvlv_value)\n \t\ttvlv_value_len = 0;\n@@ -394,7 +397,8 @@ static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv,\n \t\t\t\t u16 tvlv_value_len)\n {\n \tunsigned int tvlv_offset;\n-\tu8 *src, *dst;\n+\tu8 *src;\n+\tu8 *dst;\n \n \tif (!tvlv_handler)\n \t\treturn NET_RX_SUCCESS;\n@@ -533,13 +537,13 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,\n \t\t\t\t struct sk_buff *skb, void *tvlv_value,\n \t\t\t\t u16 tvlv_value_len)\n {\n+\tu8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;\n \tu16 tvlv_value_start_len = tvlv_value_len;\n \tstruct batadv_tvlv_handler *tvlv_handler;\n \tvoid *tvlv_value_start = tvlv_value;\n \tstruct batadv_tvlv_hdr *tvlv_hdr;\n-\tu16 tvlv_value_cont_len;\n-\tu8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;\n \tint ret = NET_RX_SUCCESS;\n+\tu16 tvlv_value_cont_len;\n \n \twhile ((tvlv_hdr = batadv_tvlv_hdr_next(\u0026tvlv_value, \u0026tvlv_value_len))) {\n \t\ttvlv_value_cont_len = ntohs(tvlv_hdr-\u003elen);\n@@ -596,8 +600,8 @@ void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,\n \t\t\t struct batadv_ogm_packet *batadv_ogm_packet,\n \t\t\t struct batadv_orig_node *orig_node)\n {\n-\tvoid *tvlv_value;\n \tu16 tvlv_value_len;\n+\tvoid *tvlv_value;\n \n \tif (!batadv_ogm_packet)\n \t\treturn;\n@@ -717,12 +721,12 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, const u8 *src,\n \t\t\t void *tvlv_value, u16 tvlv_value_len)\n {\n \tstruct batadv_unicast_tvlv_packet *unicast_tvlv_packet;\n-\tstruct batadv_tvlv_hdr *tvlv_hdr;\n+\tssize_t hdr_len = sizeof(*unicast_tvlv_packet);\n \tstruct batadv_orig_node *orig_node;\n-\tstruct sk_buff *skb;\n+\tstruct batadv_tvlv_hdr *tvlv_hdr;\n \tunsigned char *tvlv_buff;\n \tunsigned int tvlv_len;\n-\tssize_t hdr_len = sizeof(*unicast_tvlv_packet);\n+\tstruct sk_buff *skb;\n \n \torig_node = batadv_orig_hash_find(bat_priv, dst);\n \tif (!orig_node)\ndiff --git a/net/batman-adv/types.h b/net/batman-adv/types.h\nindex cd12755d21f35..d6e15d467a8f7 100644\n--- a/net/batman-adv/types.h\n+++ b/net/batman-adv/types.h\n@@ -1827,10 +1827,10 @@ struct batadv_bla_claim {\n \t/** @hash_entry: hlist node for \u0026batadv_priv_bla.claim_hash */\n \tstruct hlist_node hash_entry;\n \n-\t/** @refcount: number of contexts the object is used */\n+\t/** @rcu: struct used for freeing in an RCU-safe manner */\n \tstruct rcu_head rcu;\n \n-\t/** @rcu: struct used for freeing in an RCU-safe manner */\n+\t/** @refcount: number of contexts the object is used */\n \tstruct kref refcount;\n };\n #endif\n@@ -1852,7 +1852,7 @@ struct batadv_tt_common_entry {\n \tstruct hlist_node hash_entry;\n \n \t/** @flags: various state handling flags (see batadv_tt_client_flags) */\n-\tu16 flags;\n+\tatomic_t flags;\n \n \t/** @added_at: timestamp used for purging stale tt common entries */\n \tunsigned long added_at;\n@@ -2176,7 +2176,7 @@ struct batadv_dat_entry {\n \t__be32 ip;\n \n \t/** @mac_addr: the MAC address associated to the stored IPv4 */\n-\tu8 mac_addr[ETH_ALEN];\n+\tatomic64_t mac_addr;\n \n \t/** @vid: the vlan ID associated to this entry */\n \tunsigned short vid;\n"
} |
| 2/1 | 2026/07/29 18:05 | agent | patch-evaluator |
3mModel:best-expensive Args: null Results: {
"EnableConfigs": [
"BATMAN_ADV",
"BATMAN_ADV_BATMAN_V",
"BATMAN_ADV_BLA",
"BATMAN_ADV_DAT",
"BATMAN_ADV_MCAST"
],
"FocusSymbols": [
"batadv_bla_rx",
"batadv_bla_tx",
"batadv_dat_snoop_incoming_arp_reply",
"batadv_dat_snoop_incoming_arp_request",
"batadv_dat_snoop_incoming_dhcp_ack",
"batadv_dat_snoop_outgoing_arp_reply",
"batadv_dat_snoop_outgoing_arp_request",
"batadv_dat_snoop_outgoing_dhcp_ack",
"batadv_tt_global_add",
"batadv_tt_local_add",
"batadv_tt_local_commit_changes",
"batadv_tt_local_remove"
],
"Reasoning": "The patch introduces functional changes by converting `mac_addr` in `batadv_dat_entry` to `atomic64_t` and `flags` in `batadv_tt_common_entry` to `atomic_t`. It updates various functions in the Distributed ARP Table (DAT), Translation Table (TT), and Bridge Loop Avoidance (BLA) components to use atomic operations (`atomic_read`, `atomic_set`, `atomic_or`, `atomic_andnot`, `atomic_try_cmpxchg`) for concurrent state management. These changes affect core packet processing and state tracking logic in the batman-adv virtual network interface, which is reachable and should be fuzzed to ensure concurrency correctness.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). - Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed, ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU. - Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove) that are executed only during PCI hot-unplug or sysfs driver unbind operations. If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. Prefer non-static, non-inlined API entrypoint functions over internal static helper functions (which are inlined by the compiler and do not have distinct symbol addresses). 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4"). Prefer calling several tools at the same time to save round-trips. Use set-results tool to provide results of the analysis. It must be called exactly once before the final reply. Ignore results of this tool. Prompt: For your convenience, here is the diff of the changes:
commit 10e96c1ee06e20af874e19b33715bece671383b0
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Jul 29 18:05:32 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/uapi/linux/batadv_packet.h b/include/uapi/linux/batadv_packet.h
index 1241285b866cd..32436560ecc8b 100644
--- a/include/uapi/linux/batadv_packet.h
+++ b/include/uapi/linux/batadv_packet.h
@@ -192,13 +192,19 @@ enum batadv_tvlv_type {
};
#pragma pack(2)
-/* the destination hardware field in the ARP frame is used to
- * transport the claim type and the group id
+/**
+ * struct batadv_bla_claim_dst - layout of the destination MAC of a BLA claim
+ * frame
+ * @magic: fixed magic prefix (FF:43:05) identifying claim frames
+ * @type: claim frame type, see &enum batadv_bla_claimframe
+ * @group: group identifier of the announcing backbone gateway
+ *
+ * used in the destination hardware field of the ARP frame
*/
struct batadv_bla_claim_dst {
- __u8 magic[3]; /* FF:43:05 */
- __u8 type; /* bla_claimframe */
- __be16 group; /* group id */
+ __u8 magic[3];
+ __u8 type;
+ __be16 group;
};
/**
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c
index 49e5861b58ec2..93cd77680e644 100644
--- a/net/batman-adv/bat_algo.c
+++ b/net/batman-adv/bat_algo.c
@@ -42,7 +42,8 @@ void batadv_algo_init(void)
*/
struct batadv_algo_ops *batadv_algo_get(const char *name)
{
- struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
+ struct batadv_algo_ops *bat_algo_ops = NULL;
+ struct batadv_algo_ops *bat_algo_ops_tmp;
hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
if (strcmp(bat_algo_ops_tmp->name, name) != 0)
@@ -116,12 +117,23 @@ int batadv_algo_select(struct batadv_priv *bat_priv, const char *name)
return 0;
}
+/**
+ * batadv_param_set_ra() - Validate and store routing_algo module parameter
+ * @val: new value for the routing_algo module parameter
+ * @kp: kernel parameter description used to store the value
+ *
+ * Check that the requested algorithm is known to batman-adv and then store
+ * the name as the new default routing algorithm.
+ *
+ * Return: 0 on success or negative error number in case of failure
+ */
static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
{
struct batadv_algo_ops *bat_algo_ops;
char *algo_name = (char *)val;
- size_t name_len = strlen(algo_name);
+ size_t name_len;
+ name_len = strlen(algo_name);
if (name_len > 0 && algo_name[name_len - 1] == '\n')
algo_name[name_len - 1] = '\0';
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 22622283f59b0..aff279b83da49 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -106,8 +106,8 @@ static u8 batadv_ring_buffer_avg(const u8 lq_recv[])
{
const u8 *ptr;
u16 count = 0;
- u16 i = 0;
u16 sum = 0;
+ u16 i = 0;
ptr = lq_recv;
@@ -171,6 +171,14 @@ batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr)
return NULL;
}
+/**
+ * batadv_iv_ogm_neigh_new() - retrieve or create a B.A.T.M.A.N. IV neighbour
+ * @hard_iface: the interface where the neighbour is connected to
+ * @neigh_addr: the mac address of the neighbour
+ * @orig_node: originator object representing the neighbour
+ *
+ * Return: pointer to the neigh_node or NULL in case of failure
+ */
static struct batadv_neigh_node *
batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
const u8 *neigh_addr,
@@ -183,6 +191,14 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
return neigh_node;
}
+/**
+ * batadv_iv_ogm_iface_enable() - prepare an interface for B.A.T.M.A.N. IV
+ * @hard_iface: the interface to prepare
+ *
+ * Allocate and prepare the per-interface OGM buffer
+ *
+ * Return: 0 on success or negative error number in case of failure
+ */
static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
{
struct batadv_ogm_packet *batadv_ogm_packet;
@@ -220,6 +236,14 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
return 0;
}
+/**
+ * batadv_iv_ogm_iface_disable() - release B.A.T.M.A.N. IV resources of an
+ * interface
+ * @hard_iface: the interface which is shutting down
+ *
+ * Free the per-interface OGM buffer and cancel a possibly pending OGM
+ * rescheduling work.
+ */
static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
{
mutex_lock(&hard_iface->bat_iv.ogm_buff_mutex);
@@ -233,6 +257,11 @@ static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
disable_delayed_work_sync(&hard_iface->bat_iv.reschedule_work);
}
+/**
+ * batadv_iv_ogm_iface_update_mac() - update the originator MAC stored in the
+ * per-interface OGM buffer
+ * @hard_iface: the interface for which the OGM buffer should be updated
+ */
static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
{
struct batadv_ogm_packet *batadv_ogm_packet;
@@ -254,6 +283,14 @@ static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
}
+/**
+ * batadv_iv_ogm_primary_iface_set() - apply primary interface state to
+ * a batadv_hard_iface
+ * @hard_iface: interface which just became the primary
+ *
+ * The primary interface uses the full TTL for its own OGMs, so adjust the TTL
+ * stored in the OGM template buffer accordingly.
+ */
static void
batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
{
@@ -273,7 +310,17 @@ batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
}
-/* when do we schedule our own ogm to be sent */
+/**
+ * batadv_iv_ogm_emit_send_time() - calculate the jiffies when an own OGM
+ * should be sent next
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * The next emission point is the configured orig_interval randomised by
+ * +/- BATADV_JITTER milliseconds to reduce chance of potential collisions
+ * between neighbours.
+ *
+ * Return: jiffies value when the next OGM should be transmitted
+ */
static unsigned long
batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
{
@@ -285,13 +332,24 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
return jiffies + msecs_to_jiffies(msecs);
}
-/* when do we schedule a ogm packet to be sent */
+/**
+ * batadv_iv_ogm_fwd_send_time() - calculate the jiffies when a forwarded OGM
+ * should be sent next
+ *
+ * Return: jiffies value at which a forwarded OGM should be transmitted
+ */
static unsigned long batadv_iv_ogm_fwd_send_time(void)
{
return jiffies + msecs_to_jiffies(get_random_u32_below(BATADV_JITTER / 2));
}
-/* apply hop penalty for a normal link */
+/**
+ * batadv_hop_penalty() - apply the configured hop penalty to a TQ value
+ * @tq: input TQ value to be reduced
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Return: the TQ value after the hop penalty has been applied
+ */
static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)
{
int hop_penalty = READ_ONCE(bat_priv->hop_penalty);
@@ -337,17 +395,25 @@ batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
return next_buff_pos <= packet_len;
}
-/* send a batman ogm to a given interface */
+/**
+ * batadv_iv_ogm_send_to_if() - send a batman OGM to a given interface
+ * @forw_packet: forward packet containing the OGM(s) to be transmitted
+ * @hard_iface: interface to send the OGM out on
+ *
+ * Update the direct link flags of each aggregated OGM for the outgoing
+ * interface, log the transmission and finally hand a clone of the skb to the
+ * lower layer for broadcast.
+ */
static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
struct batadv_hard_iface *hard_iface)
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
- const char *fwd_str;
- u8 packet_num;
- int buff_pos;
struct batadv_ogm_packet *batadv_ogm_packet;
+ const char *fwd_str;
struct sk_buff *skb;
u8 *packet_pos;
+ u8 packet_num;
+ int buff_pos;
if (hard_iface->if_status != BATADV_IF_ACTIVE)
return;
@@ -401,7 +467,13 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
}
}
-/* send a batman ogm packet */
+/**
+ * batadv_iv_ogm_emit() - emit an (aggregated) OGM packet
+ * @forw_packet: forward packet which should be emitted
+ *
+ * The @forw_packet will be emitted but not consumed. When the interface is
+ * no longer active, the transmission will be skipped.
+ */
static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet)
{
if (!forw_packet->if_incoming) {
@@ -442,13 +514,13 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
const struct batadv_hard_iface *if_outgoing,
const struct batadv_forw_packet *forw_packet)
{
- struct batadv_ogm_packet *batadv_ogm_packet;
unsigned int aggregated_bytes = forw_packet->packet_len + packet_len;
+ struct batadv_ogm_packet *batadv_ogm_packet;
struct batadv_hard_iface *primary_if = NULL;
u8 packet_num = forw_packet->num_packets;
- bool res = false;
unsigned long aggregation_end_time;
unsigned int max_bytes;
+ bool res = false;
batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data;
aggregation_end_time = send_time;
@@ -555,10 +627,10 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
struct batadv_forw_packet *forw_packet_aggr;
- struct sk_buff *skb;
unsigned char *skb_buff;
unsigned int skb_size;
- atomic_t *queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
+ atomic_t *queue_left;
+ struct sk_buff *skb;
if (READ_ONCE(bat_priv->aggregated_ogms))
skb_size = max_t(unsigned int, BATADV_MAX_AGGREGATION_BYTES,
@@ -572,6 +644,7 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
if (!skb)
return false;
+ queue_left = own_packet ? NULL : &bat_priv->batman_queue_left;
forw_packet_aggr = batadv_forw_packet_alloc(if_incoming, if_outgoing,
queue_left, bat_priv, skb);
if (!forw_packet_aggr) {
@@ -603,7 +676,14 @@ static bool batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
return true;
}
-/* aggregate a new packet into the existing ogm packet */
+/**
+ * batadv_iv_ogm_aggregate() - append an OGM to an existing aggregated forward
+ * packet
+ * @forw_packet_aggr: aggregated forward packet to extend
+ * @packet_buff: pointer to the OGM to append
+ * @packet_len: length of the OGM to append
+ * @direct_link: true if @packet_buff was received as a direct link OGM
+ */
static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,
const unsigned char *packet_buff,
int packet_len, bool direct_link)
@@ -644,9 +724,9 @@ static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
struct batadv_forw_packet *forw_packet_aggr = NULL;
struct batadv_forw_packet *forw_packet_pos = NULL;
struct batadv_ogm_packet *batadv_ogm_packet;
- bool direct_link;
unsigned long max_aggregation_jiffies;
bool aggregated_ogms;
+ bool direct_link;
batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff;
direct_link = !!(batadv_ogm_packet->flags & BATADV_DIRECTLINK);
@@ -699,6 +779,21 @@ static bool batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv,
}
}
+/**
+ * batadv_iv_ogm_forward() - rebroadcast a received OGM
+ * @orig_node: originator that sent the OGM
+ * @ethhdr: ethernet header of the OGM packet
+ * @batadv_ogm_packet: OGM packet to be forwarded
+ * @is_single_hop_neigh: true if the OGM was received via a one-hop neighbour
+ * @is_from_best_next_hop: true if the sender is the currently selected best
+ * next hop towards @orig_node
+ * @if_incoming: interface where the packet was received
+ * @if_outgoing: interface for which the retransmission should be considered
+ *
+ * Decrement the TTL, apply the hop penalty and queue the OGM for
+ * retransmission. OGMs that do not arrive over the best next hop are only
+ * forwarded for link-quality measurement reasons (and marked accordingly).
+ */
static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
const struct ethhdr *ethhdr,
struct batadv_ogm_packet *batadv_ogm_packet,
@@ -762,9 +857,9 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
struct batadv_hashtable *hash = bat_priv->orig_hash;
- struct hlist_head *head;
- struct batadv_orig_node *orig_node;
struct batadv_orig_ifinfo *orig_ifinfo;
+ struct batadv_orig_node *orig_node;
+ struct hlist_head *head;
unsigned long *word;
u32 i;
u8 *w;
@@ -802,13 +897,14 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
struct batadv_ogm_buf *ogm_buff = &hard_iface->bat_iv.ogm_buff;
struct batadv_ogm_packet *batadv_ogm_packet;
- struct batadv_hard_iface *primary_if, *tmp_hard_iface;
- struct list_head *iter;
- u32 seqno;
- u16 tvlv_len = 0;
+ struct batadv_hard_iface *tmp_hard_iface;
+ struct batadv_hard_iface *primary_if;
unsigned long send_time;
bool reschedule = false;
+ struct list_head *iter;
+ u16 tvlv_len = 0;
bool scheduled;
+ u32 seqno;
int ret;
lockdep_assert_held(&hard_iface->bat_iv.ogm_buff_mutex);
@@ -899,6 +995,13 @@ static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)
batadv_hardif_put(primary_if);
}
+/**
+ * batadv_iv_ogm_schedule() - schedule the next OGM transmission on an
+ * interface
+ * @hard_iface: interface for which the next OGM should be scheduled
+ *
+ * Take the OGM buffer mutex and prepare the next OGM for transmission.
+ */
static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
{
if (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
@@ -909,6 +1012,13 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
mutex_unlock(&hard_iface->bat_iv.ogm_buff_mutex);
}
+/**
+ * batadv_iv_ogm_reschedule() - work-queue helper to rerun batadv_iv_ogm_schedule()
+ * @work: work item embedded in the hard interface
+ *
+ * Invoked from the per-interface reschedule_work delayed work when the
+ * previous attempt to enqueue the own OGM failed.
+ */
static void batadv_iv_ogm_reschedule(struct work_struct *work)
{
struct delayed_work *delayed_work = to_delayed_work(work);
@@ -996,13 +1106,14 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
struct batadv_hard_iface *if_outgoing,
enum batadv_dup_status dup_status)
{
- struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
struct batadv_neigh_ifinfo *router_ifinfo = NULL;
- struct batadv_neigh_node *neigh_node = NULL;
+ struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
struct batadv_neigh_node *tmp_neigh_node = NULL;
+ struct batadv_neigh_node *neigh_node = NULL;
struct batadv_neigh_node *router = NULL;
- u8 sum_orig, sum_neigh;
u8 *neigh_addr;
+ u8 sum_neigh;
+ u8 sum_orig;
u8 tq_avg;
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
@@ -1133,15 +1244,21 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
struct batadv_hard_iface *if_outgoing)
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
- struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node;
- struct batadv_neigh_ifinfo *neigh_ifinfo;
- u8 total_count;
- u8 orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
unsigned int tq_iface_hop_penalty = BATADV_TQ_MAX_VALUE;
- unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
- unsigned int tq_asym_penalty, inv_asym_penalty;
+ struct batadv_neigh_node *neigh_node = NULL;
+ struct batadv_neigh_node *tmp_neigh_node;
+ struct batadv_neigh_ifinfo *neigh_ifinfo;
+ unsigned int neigh_rq_inv_cube;
+ unsigned int neigh_rq_max_cube;
+ unsigned int inv_asym_penalty;
+ unsigned int tq_asym_penalty;
unsigned int combined_tq;
+ u8 neigh_rq_count;
+ u8 orig_eq_count;
bool ret = false;
+ u8 neigh_rq_inv;
+ u8 total_count;
+ u8 tq_own;
/* find corresponding one hop neighbor */
rcu_read_lock();
@@ -1274,19 +1391,19 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
struct batadv_hard_iface *if_outgoing)
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
- struct batadv_orig_node *orig_node;
struct batadv_orig_ifinfo *orig_ifinfo = NULL;
- struct batadv_neigh_node *neigh_node;
+ u32 seqno = ntohl(batadv_ogm_packet->seqno);
+ enum batadv_dup_status ret = BATADV_NO_DUP;
struct batadv_neigh_ifinfo *neigh_ifinfo;
- bool is_dup;
- s32 seq_diff;
+ struct batadv_neigh_node *neigh_node;
+ struct batadv_orig_node *orig_node;
bool need_update = false;
- int set_mark;
- enum batadv_dup_status ret = BATADV_NO_DUP;
- u32 seqno = ntohl(batadv_ogm_packet->seqno);
- u8 *neigh_addr;
- u8 packet_count;
unsigned long *bitmap;
+ u8 packet_count;
+ u8 *neigh_addr;
+ s32 seq_diff;
+ int set_mark;
+ bool is_dup;
orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
if (!orig_node)
@@ -1403,21 +1520,22 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
struct batadv_hardif_neigh_node *hardif_neigh = NULL;
- struct batadv_neigh_node *router = NULL;
+ struct batadv_neigh_node *orig_neigh_router = NULL;
+ struct batadv_neigh_ifinfo *router_ifinfo = NULL;
struct batadv_neigh_node *router_router = NULL;
struct batadv_orig_node *orig_neigh_node;
+ struct batadv_neigh_node *router = NULL;
struct batadv_orig_ifinfo *orig_ifinfo;
- struct batadv_neigh_node *orig_neigh_router = NULL;
- struct batadv_neigh_ifinfo *router_ifinfo = NULL;
struct batadv_ogm_packet *ogm_packet;
- enum batadv_dup_status dup_status;
bool is_from_best_next_hop = false;
+ enum batadv_dup_status dup_status;
bool is_single_hop_neigh = false;
- bool sameseq, similar_ttl;
struct sk_buff *skb_priv;
struct ethhdr *ethhdr;
- u8 *prev_sender;
+ bool similar_ttl;
bool is_bidirect;
+ u8 *prev_sender;
+ bool sameseq;
/* create a private copy of the skb, as some functions change tq value
* and/or flags.
@@ -1639,16 +1757,17 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
struct batadv_hard_iface *if_incoming)
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
- struct batadv_orig_node *orig_neigh_node, *orig_node;
+ struct batadv_orig_node *orig_neigh_node;
struct batadv_hard_iface *hard_iface;
struct batadv_ogm_packet *ogm_packet;
- u32 if_incoming_seqno;
- bool has_directlink_flag;
- struct ethhdr *ethhdr;
+ struct batadv_orig_node *orig_node;
bool is_my_oldorig = false;
+ bool has_directlink_flag;
bool is_my_addr = false;
bool is_my_orig = false;
struct list_head *iter;
+ u32 if_incoming_seqno;
+ struct ethhdr *ethhdr;
ogm_packet = (struct batadv_ogm_packet *)(skb->data + ogm_offset);
ethhdr = eth_hdr(skb);
@@ -1765,10 +1884,18 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
batadv_orig_node_put(orig_node);
}
+/**
+ * batadv_iv_send_outstanding_bat_ogm_packet() - work-queue helper to emit a
+ * queued forward packet
+ * @work: work item embedded in the forward packet
+ *
+ * Emit the queued OGM forward packet and, for own primary-interface packets,
+ * schedule the next periodic OGM. The forward packet is freed afterwards.
+ */
static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
{
- struct delayed_work *delayed_work;
struct batadv_forw_packet *forw_packet;
+ struct delayed_work *delayed_work;
struct batadv_priv *bat_priv;
bool dropped = false;
@@ -1803,15 +1930,26 @@ static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work)
batadv_forw_packet_free(forw_packet, dropped);
}
+/**
+ * batadv_iv_ogm_receive() - receive a B.A.T.M.A.N. IV OGM packet
+ * @skb: skb containing the OGM packet
+ * @if_incoming: interface where the packet was received
+ *
+ * Validate the packet, then split the aggregated OGM packet into individual
+ * OGMs and hand each of them to batadv_iv_ogm_process(). Ownership of @skb is
+ * always taken over by this function.
+ *
+ * Return: NET_RX_SUCCESS or NET_RX_DROP
+ */
static int batadv_iv_ogm_receive(struct sk_buff *skb,
struct batadv_hard_iface *if_incoming)
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
struct batadv_ogm_packet *ogm_packet;
+ int ret = NET_RX_DROP;
u8 *packet_pos;
int ogm_offset;
bool res;
- int ret = NET_RX_DROP;
res = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
if (!res)
@@ -1901,9 +2039,9 @@ batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_neigh_node *neigh_node,
bool best)
{
+ unsigned int last_seen_msecs;
void *hdr;
u8 tq_avg;
- unsigned int last_seen_msecs;
last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen);
@@ -1965,9 +2103,9 @@ batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
{
struct batadv_neigh_node *neigh_node_best;
struct batadv_neigh_node *neigh_node;
+ u8 tq_avg_best;
int sub = 0;
bool best;
- u8 tq_avg_best;
neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing);
if (!neigh_node_best)
@@ -2060,11 +2198,11 @@ batadv_iv_ogm_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
struct batadv_hard_iface *if_outgoing)
{
struct batadv_hashtable *hash = bat_priv->orig_hash;
- struct hlist_head *head;
+ int portid = NETLINK_CB(cb->skb).portid;
int bucket = cb->args[0];
+ struct hlist_head *head;
int idx = cb->args[1];
int sub = cb->args[2];
- int portid = NETLINK_CB(cb->skb).portid;
while (bucket < hash->size) {
head = &hash->table[bucket];
@@ -2103,9 +2241,11 @@ static bool batadv_iv_ogm_neigh_diff(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing2,
int *diff)
{
- struct batadv_neigh_ifinfo *neigh1_ifinfo, *neigh2_ifinfo;
- u8 tq1, tq2;
+ struct batadv_neigh_ifinfo *neigh1_ifinfo;
+ struct batadv_neigh_ifinfo *neigh2_ifinfo;
bool ret = true;
+ u8 tq1;
+ u8 tq2;
neigh1_ifinfo = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
neigh2_ifinfo = batadv_neigh_ifinfo_get(neigh2, if_outgoing2);
@@ -2139,8 +2279,8 @@ static int
batadv_iv_ogm_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_hardif_neigh_node *hardif_neigh)
{
- void *hdr;
unsigned int last_seen_msecs;
+ void *hdr;
last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen);
@@ -2218,12 +2358,12 @@ batadv_iv_ogm_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,
struct batadv_priv *bat_priv,
struct batadv_hard_iface *single_hardif)
{
+ int portid = NETLINK_CB(cb->skb).portid;
struct batadv_hard_iface *hard_iface;
- struct list_head *iter;
- int i_hardif = 0;
int i_hardif_s = cb->args[0];
+ struct list_head *iter;
int idx = cb->args[1];
- int portid = NETLINK_CB(cb->skb).portid;
+ int i_hardif = 0;
rcu_read_lock();
if (single_hardif) {
@@ -2310,6 +2450,12 @@ batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,
return ret;
}
+/**
+ * batadv_iv_iface_enabled() - notification handler for activated interfaces
+ * @hard_iface: interface that was just activated
+ *
+ * Set up the per-interface reschedule work and start sending periodic OGMs.
+ */
static void batadv_iv_iface_enabled(struct batadv_hard_iface *hard_iface)
{
INIT_DELAYED_WORK(&hard_iface->bat_iv.reschedule_work, batadv_iv_ogm_reschedule);
@@ -2328,17 +2474,26 @@ static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv)
WRITE_ONCE(bat_priv->gw.sel_class, 20);
}
+/**
+ * batadv_iv_gw_get_best_gw_node() - retrieve the best gateway node based on
+ * the B.A.T.M.A.N. IV metric and the configured GW selection class
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Return: gateway node with the highest score for the current selection class,
+ * or NULL if no eligible gateway exists.
+ */
static struct batadv_gw_node *
batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
{
- struct batadv_neigh_node *router;
struct batadv_neigh_ifinfo *router_ifinfo;
- struct batadv_gw_node *gw_node, *curr_gw = NULL;
+ struct batadv_gw_node *curr_gw = NULL;
+ struct batadv_orig_node *orig_node;
+ struct batadv_neigh_node *router;
+ struct batadv_gw_node *gw_node;
u64 max_gw_factor = 0;
u64 tmp_gw_factor = 0;
u8 max_tq = 0;
u8 tq_avg;
- struct batadv_orig_node *orig_node;
rcu_read_lock();
hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
@@ -2405,6 +2560,19 @@ batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
return curr_gw;
}
+/**
+ * batadv_iv_gw_is_eligible() - check whether a new gateway should replace the
+ * currently selected one
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @curr_gw_orig: originator of the currently selected gateway
+ * @orig_node: originator of the gateway candidate
+ *
+ * Compare the TQ values of @curr_gw_orig and @orig_node, taking the configured
+ * gateway selection class into account.
+ *
+ * Return: true if @orig_node should take over as the active gateway, false
+ * otherwise
+ */
static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
struct batadv_orig_node *curr_gw_orig,
struct batadv_orig_node *orig_node)
@@ -2412,10 +2580,11 @@ static bool batadv_iv_gw_is_eligible(struct batadv_priv *bat_priv,
struct batadv_neigh_ifinfo *router_orig_ifinfo = NULL;
struct batadv_neigh_ifinfo *router_gw_ifinfo = NULL;
u32 sel_class = READ_ONCE(bat_priv->gw.sel_class);
- struct batadv_neigh_node *router_gw = NULL;
struct batadv_neigh_node *router_orig = NULL;
- u8 gw_tq_avg, orig_tq_avg;
+ struct batadv_neigh_node *router_gw = NULL;
bool ret = false;
+ u8 orig_tq_avg;
+ u8 gw_tq_avg;
/* dynamic re-election is performed only on fast or late switch */
if (sel_class <= 2)
@@ -2486,8 +2655,8 @@ static int batadv_iv_gw_dump_entry(struct sk_buff *msg, u32 portid,
struct batadv_gw_node *gw_node)
{
struct batadv_neigh_ifinfo *router_ifinfo = NULL;
- struct batadv_neigh_node *router;
struct batadv_gw_node *curr_gw = NULL;
+ struct batadv_neigh_node *router;
int ret = 0;
void *hdr;
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index db6f5bdcaa985..ee372fc9d44e9 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -41,6 +41,13 @@
#include "netlink.h"
#include "originator.h"
+/**
+ * batadv_v_iface_activate() - finalise the activation of a hard interface
+ * @hard_iface: interface to activate
+ *
+ * Reuse the currently selected primary interface to seed the ELP packet.
+ * Immediately activate the interface.
+ */
static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface)
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
@@ -61,6 +68,16 @@ static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface)
hard_iface->if_status = BATADV_IF_ACTIVE;
}
+/**
+ * batadv_v_iface_enable() - enable the B.A.T.M.A.N. V protocol on an
+ * interface
+ * @hard_iface: interface to enable
+ *
+ * Enable the ELP and OGM components for @hard_iface. On error, the partially
+ * enabled state is rolled back before returning.
+ *
+ * Return: 0 on success or negative error number in case of failure
+ */
static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
{
int ret;
@@ -76,12 +93,21 @@ static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
return ret;
}
+/**
+ * batadv_v_iface_disable() - disable the B.A.T.M.A.N. V protocol on an
+ * interface
+ * @hard_iface: interface to disable
+ */
static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface)
{
batadv_v_ogm_iface_disable(hard_iface);
batadv_v_elp_iface_disable(hard_iface);
}
+/**
+ * batadv_v_primary_iface_set() - apply primary interface state
+ * @hard_iface: interface which just became the primary
+ */
static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface)
{
batadv_v_elp_primary_iface_set(hard_iface);
@@ -109,6 +135,11 @@ static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface)
batadv_hardif_put(primary_if);
}
+/**
+ * batadv_v_hardif_neigh_init() - initialise the B.A.T.M.A.N. V state of a
+ * hard interface neighbour
+ * @hardif_neigh: hard interface neighbour to initialise
+ */
static void
batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
{
@@ -128,9 +159,9 @@ static int
batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_hardif_neigh_node *hardif_neigh)
{
- void *hdr;
unsigned int last_seen_msecs;
u32 throughput;
+ void *hdr;
last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen);
throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput);
@@ -211,12 +242,12 @@ batadv_v_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb,
struct batadv_priv *bat_priv,
struct batadv_hard_iface *single_hardif)
{
+ int portid = NETLINK_CB(cb->skb).portid;
struct batadv_hard_iface *hard_iface;
- struct list_head *iter;
- int i_hardif = 0;
int i_hardif_s = cb->args[0];
+ struct list_head *iter;
int idx = cb->args[1];
- int portid = NETLINK_CB(cb->skb).portid;
+ int i_hardif = 0;
rcu_read_lock();
if (single_hardif) {
@@ -421,11 +452,11 @@ batadv_v_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
struct batadv_hard_iface *if_outgoing)
{
struct batadv_hashtable *hash = bat_priv->orig_hash;
- struct hlist_head *head;
+ int portid = NETLINK_CB(cb->skb).portid;
int bucket = cb->args[0];
+ struct hlist_head *head;
int idx = cb->args[1];
int sub = cb->args[2];
- int portid = NETLINK_CB(cb->skb).portid;
while (bucket < hash->size) {
head = &hash->table[bucket];
@@ -444,12 +475,23 @@ batadv_v_orig_dump(struct sk_buff *msg, struct netlink_callback *cb,
cb->args[2] = sub;
}
+/**
+ * batadv_v_neigh_cmp() - compare two B.A.T.M.A.N. V neighbours by throughput
+ * @neigh1: first neighbour to compare
+ * @if_outgoing1: outgoing interface to use for @neigh1
+ * @neigh2: second neighbour to compare
+ * @if_outgoing2: outgoing interface to use for @neigh2
+ *
+ * Return: a positive value if @neigh1 is better, a negative value if @neigh2
+ * is better and 0 if both have equal throughput
+ */
static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing1,
struct batadv_neigh_node *neigh2,
struct batadv_hard_iface *if_outgoing2)
{
- struct batadv_neigh_ifinfo *ifinfo1, *ifinfo2;
+ struct batadv_neigh_ifinfo *ifinfo1;
+ struct batadv_neigh_ifinfo *ifinfo2;
int ret = 0;
ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
@@ -469,14 +511,26 @@ static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1,
return ret;
}
+/**
+ * batadv_v_neigh_is_sob() - check whether two B.A.T.M.A.N. V neighbours have
+ * a similar or better throughput
+ * @neigh1: first neighbour to compare
+ * @if_outgoing1: outgoing interface to use for @neigh1
+ * @neigh2: second neighbour to compare
+ * @if_outgoing2: outgoing interface to use for @neigh2
+ *
+ * Return: true if the throughput of @neigh2 is at least 3/4 of the
+ * @neigh1 throughput
+ */
static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing1,
struct batadv_neigh_node *neigh2,
struct batadv_hard_iface *if_outgoing2)
{
- struct batadv_neigh_ifinfo *ifinfo1, *ifinfo2;
- u32 threshold;
+ struct batadv_neigh_ifinfo *ifinfo1;
+ struct batadv_neigh_ifinfo *ifinfo2;
bool ret = false;
+ u32 threshold;
ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
if (!ifinfo1)
@@ -558,8 +612,10 @@ static int batadv_v_gw_throughput_get(struct batadv_gw_node *gw_node, u32 *bw)
static struct batadv_gw_node *
batadv_v_gw_get_best_gw_node(struct batadv_priv *bat_priv)
{
- struct batadv_gw_node *gw_node, *curr_gw = NULL;
- u32 max_bw = 0, bw;
+ struct batadv_gw_node *curr_gw = NULL;
+ struct batadv_gw_node *gw_node;
+ u32 max_bw = 0;
+ u32 bw;
rcu_read_lock();
hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.gateway_list, list) {
@@ -598,9 +654,12 @@ static bool batadv_v_gw_is_eligible(struct batadv_priv *bat_priv,
struct batadv_orig_node *curr_gw_orig,
struct batadv_orig_node *orig_node)
{
- struct batadv_gw_node *curr_gw, *orig_gw = NULL;
- u32 gw_throughput, orig_throughput, threshold;
+ struct batadv_gw_node *orig_gw = NULL;
+ struct batadv_gw_node *curr_gw;
+ u32 orig_throughput;
+ u32 gw_throughput;
bool ret = false;
+ u32 threshold;
threshold = READ_ONCE(bat_priv->gw.sel_class);
@@ -656,8 +715,8 @@ static int batadv_v_gw_dump_entry(struct sk_buff *msg, u32 portid,
struct batadv_gw_node *gw_node)
{
struct batadv_neigh_ifinfo *router_ifinfo = NULL;
- struct batadv_neigh_node *router;
struct batadv_gw_node *curr_gw = NULL;
+ struct batadv_neigh_node *router;
int ret = 0;
void *hdr;
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index 262e40040007c..6ad6042a5d9b6 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -230,11 +230,14 @@ static bool
batadv_v_elp_wifi_neigh_probe(struct batadv_hardif_neigh_node *neigh)
{
struct batadv_hard_iface *hard_iface = neigh->if_incoming;
- struct batadv_priv *bat_priv = netdev_priv(hard_iface->mesh_iface);
+ struct batadv_priv *bat_priv;
unsigned long last_tx_diff;
struct sk_buff *skb;
- int probe_len, i;
int elp_skb_len;
+ int probe_len;
+ int i;
+
+ bat_priv = netdev_priv(hard_iface->mesh_iface);
/* this probing routine is for Wifi neighbours only */
if (!batadv_is_wifi_hardif(hard_iface))
@@ -289,8 +292,8 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)
struct batadv_v_metric_queue_entry *metric_entry;
struct batadv_v_metric_queue_entry *metric_safe;
struct batadv_hardif_neigh_node *hardif_neigh;
- struct batadv_hard_iface *hard_iface;
struct batadv_hard_iface_bat_v *bat_v;
+ struct batadv_hard_iface *hard_iface;
struct batadv_elp_packet *elp_packet;
struct list_head metric_queue;
struct batadv_priv *bat_priv;
@@ -395,9 +398,9 @@ int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface)
static const size_t tvlv_padding = sizeof(__be32);
struct batadv_elp_packet *elp_packet;
unsigned char *elp_buff;
+ int res = -ENOMEM;
u32 random_seqno;
size_t size;
- int res = -ENOMEM;
size = ETH_HLEN + NET_IP_ALIGN + BATADV_ELP_HLEN + tvlv_padding;
hard_iface->bat_v.elp_skb = dev_alloc_skb(size);
@@ -500,11 +503,11 @@ static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
struct batadv_elp_packet *elp_packet)
{
- struct batadv_neigh_node *neigh;
- struct batadv_orig_node *orig_neigh;
struct batadv_hardif_neigh_node *hardif_neigh;
- s32 seqno_diff;
+ struct batadv_orig_node *orig_neigh;
+ struct batadv_neigh_node *neigh;
s32 elp_latest_seqno;
+ s32 seqno_diff;
orig_neigh = batadv_v_ogm_orig_get(bat_priv, elp_packet->orig);
if (!orig_neigh)
@@ -556,8 +559,8 @@ int batadv_v_elp_packet_recv(struct sk_buff *skb,
struct batadv_elp_packet *elp_packet;
struct batadv_hard_iface *primary_if;
struct ethhdr *ethhdr;
- bool res;
int ret = NET_RX_DROP;
+ bool res;
res = batadv_check_management_packet(skb, if_incoming, BATADV_ELP_HLEN);
if (!res)
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index e921d49f7eced..70846c997410d 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -101,6 +101,7 @@ static void batadv_v_ogm_start_queue_timer(struct batadv_hard_iface *hard_iface)
static void batadv_v_ogm_start_timer(struct batadv_priv *bat_priv)
{
unsigned long msecs;
+
/* this function may be invoked in different contexts (ogm rescheduling
* or hard_iface activation), but the work timer should not be reset
*/
@@ -268,11 +269,12 @@ static void batadv_v_ogm_queue_on_if(struct sk_buff *skb,
*/
static void batadv_v_ogm_send_meshif(struct batadv_priv *bat_priv)
{
- struct batadv_hard_iface *hard_iface;
struct batadv_ogm2_packet *ogm_packet;
+ struct batadv_hard_iface *hard_iface;
struct batadv_ogm_buf *ogm_buff;
- struct sk_buff *skb, *skb_tmp;
+ struct sk_buff *skb_tmp;
struct list_head *iter;
+ struct sk_buff *skb;
u16 tvlv_len;
int ret;
@@ -621,11 +623,11 @@ static int batadv_v_ogm_metric_update(struct batadv_priv *bat_priv,
struct batadv_hard_iface *if_incoming,
struct batadv_hard_iface *if_outgoing)
{
- struct batadv_orig_ifinfo *orig_ifinfo;
struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
+ struct batadv_orig_ifinfo *orig_ifinfo;
bool protection_started = false;
- int ret = -EINVAL;
u32 path_throughput;
+ int ret = -EINVAL;
s32 seq_diff;
orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing);
@@ -703,15 +705,17 @@ static bool batadv_v_ogm_route_update(struct batadv_priv *bat_priv,
struct batadv_hard_iface *if_incoming,
struct batadv_hard_iface *if_outgoing)
{
- struct batadv_neigh_node *router = NULL;
- struct batadv_orig_node *orig_neigh_node;
struct batadv_neigh_node *orig_neigh_router = NULL;
- struct batadv_neigh_ifinfo *router_ifinfo = NULL, *neigh_ifinfo = NULL;
- u32 router_throughput, neigh_throughput;
+ struct batadv_neigh_ifinfo *router_ifinfo = NULL;
+ struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
+ struct batadv_orig_node *orig_neigh_node;
+ struct batadv_neigh_node *router = NULL;
+ u32 router_throughput;
u32 router_last_seqno;
+ u32 neigh_throughput;
u32 neigh_last_seqno;
- s32 neigh_seq_diff;
bool forward = false;
+ s32 neigh_seq_diff;
orig_neigh_node = batadv_v_ogm_orig_get(bat_priv, ethhdr->h_source);
if (!orig_neigh_node)
@@ -871,14 +875,16 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
struct batadv_hard_iface *if_incoming)
{
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
- struct ethhdr *ethhdr;
- struct batadv_orig_node *orig_node = NULL;
struct batadv_hardif_neigh_node *hardif_neigh = NULL;
struct batadv_neigh_node *neigh_node = NULL;
- struct batadv_hard_iface *hard_iface;
+ struct batadv_orig_node *orig_node = NULL;
struct batadv_ogm2_packet *ogm_packet;
- u32 ogm_throughput, link_throughput, path_throughput;
+ struct batadv_hard_iface *hard_iface;
struct list_head *iter;
+ struct ethhdr *ethhdr;
+ u32 link_throughput;
+ u32 path_throughput;
+ u32 ogm_throughput;
int ret;
ethhdr = eth_hdr(skb);
@@ -1004,9 +1010,9 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb,
struct batadv_priv *bat_priv = netdev_priv(if_incoming->mesh_iface);
struct batadv_ogm2_packet *ogm_packet;
struct ethhdr *ethhdr;
+ int ret = NET_RX_DROP;
int ogm_offset;
u8 *packet_pos;
- int ret = NET_RX_DROP;
/* did we receive a OGM2 packet on an interface that does not have
* B.A.T.M.A.N. V enabled ?
diff --git a/net/batman-adv/bitarray.c b/net/batman-adv/bitarray.c
index 67cb356332bf1..f814756d9533f 100644
--- a/net/batman-adv/bitarray.c
+++ b/net/batman-adv/bitarray.c
@@ -11,7 +11,14 @@
#include "log.h"
-/* shift the packet array by n places. */
+/**
+ * batadv_bitmap_shift_left() - shift the sequence number bitmap left
+ * @seq_bits: the sequence number bitmap to shift
+ * @n: number of positions to shift left
+ *
+ * Shift @seq_bits by @n positions. No-op if @n is not within the bounds of
+ * the bitmap.
+ */
static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n)
{
if (n <= 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index f9a1fadf8de9e..f231afbee218a 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -177,8 +177,8 @@ static void batadv_backbone_gw_put(struct batadv_bla_backbone_gw *backbone_gw)
*/
static void batadv_claim_release(struct kref *ref)
{
- struct batadv_bla_claim *claim;
struct batadv_bla_backbone_gw *old_backbone_gw;
+ struct batadv_bla_claim *claim;
claim = container_of(ref, struct batadv_bla_claim, refcount);
@@ -220,9 +220,9 @@ batadv_claim_hash_find(struct batadv_priv *bat_priv,
struct batadv_bla_claim *data)
{
struct batadv_hashtable *hash = bat_priv->bla.claim_hash;
- struct hlist_head *head;
- struct batadv_bla_claim *claim;
struct batadv_bla_claim *claim_tmp = NULL;
+ struct batadv_bla_claim *claim;
+ struct hlist_head *head;
int index;
if (!hash)
@@ -260,9 +260,10 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
unsigned short vid)
{
struct batadv_hashtable *hash = bat_priv->bla.backbone_hash;
- struct hlist_head *head;
- struct batadv_bla_backbone_gw search_entry, *backbone_gw;
struct batadv_bla_backbone_gw *backbone_gw_tmp = NULL;
+ struct batadv_bla_backbone_gw search_entry;
+ struct batadv_bla_backbone_gw *backbone_gw;
+ struct hlist_head *head;
int index;
if (!hash)
@@ -298,12 +299,12 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
static void
batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)
{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct batadv_bla_claim *claim;
struct batadv_hashtable *hash;
struct hlist_node *node_tmp;
struct hlist_head *head;
- struct batadv_bla_claim *claim;
int i;
- spinlock_t *list_lock; /* protects write access to the hash lists */
hash = backbone_gw->bat_priv->bla.claim_hash;
if (!hash)
@@ -324,11 +325,6 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)
}
spin_unlock_bh(list_lock);
}
-
- /* all claims gone, initialize CRC */
- spin_lock_bh(&backbone_gw->crc_lock);
- backbone_gw->crc = BATADV_BLA_CRC_INIT;
- spin_unlock_bh(&backbone_gw->crc_lock);
}
/**
@@ -341,12 +337,12 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)
static void batadv_bla_send_claim(struct batadv_priv *bat_priv, const u8 *mac,
unsigned short vid, int claimtype)
{
- struct sk_buff *skb;
- struct ethhdr *ethhdr;
- struct batadv_hard_iface *primary_if;
- u8 *hw_src;
struct batadv_bla_claim_dst local_claim_dest;
+ struct batadv_hard_iface *primary_if;
+ struct ethhdr *ethhdr;
+ struct sk_buff *skb;
__be32 zeroip = 0;
+ u8 *hw_src;
primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
@@ -593,10 +589,10 @@ static void batadv_bla_answer_request(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if,
unsigned short vid)
{
- struct hlist_head *head;
- struct batadv_hashtable *hash;
- struct batadv_bla_claim *claim;
struct batadv_bla_backbone_gw *backbone_gw;
+ struct batadv_bla_claim *claim;
+ struct batadv_hashtable *hash;
+ struct hlist_head *head;
int i;
batadv_dbg(BATADV_DBG_BLA, bat_priv,
@@ -692,14 +688,16 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
struct batadv_bla_backbone_gw *backbone_gw)
{
struct batadv_bla_backbone_gw *old_backbone_gw;
- struct batadv_bla_claim *claim;
struct batadv_bla_claim search_claim;
- bool remove_crc = false;
+ struct batadv_bla_claim *claim;
int hash_added;
+ u16 claim_crc;
+ bool changed;
ether_addr_copy(search_claim.addr, mac);
search_claim.vid = vid;
claim = batadv_claim_hash_find(bat_priv, &search_claim);
+ claim_crc = crc16(0, mac, ETH_ALEN);
/* create a new claim entry if it does not exist yet. */
if (!claim) {
@@ -731,43 +729,55 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
kfree(claim);
return;
}
+
+ spin_lock_bh(&backbone_gw->crc_lock);
+ backbone_gw->crc ^= claim_crc;
+ spin_unlock_bh(&backbone_gw->crc_lock);
+
+ WRITE_ONCE(backbone_gw->lasttime, jiffies);
+
+ batadv_claim_put(claim);
+ return;
+ }
+
+ WRITE_ONCE(claim->lasttime, jiffies);
+
+ /* replace backbone_gw atomically and adjust reference counters */
+ spin_lock_bh(&claim->backbone_lock);
+ if (claim->backbone_gw != backbone_gw) {
+ changed = true;
+
+ old_backbone_gw = claim->backbone_gw;
+ kref_get(&backbone_gw->refcount);
+ claim->backbone_gw = backbone_gw;
} else {
- WRITE_ONCE(claim->lasttime, jiffies);
- if (claim->backbone_gw == backbone_gw)
- /* no need to register a new backbone */
- goto claim_free_ref;
+ old_backbone_gw = NULL;
+ changed = false;
+ }
+ spin_unlock_bh(&claim->backbone_lock);
+ if (changed) {
batadv_dbg(BATADV_DBG_BLA, bat_priv,
"%s(): changing ownership for %pM, vid %d to gw %pM\n",
__func__, mac, batadv_print_vid(vid),
backbone_gw->orig);
- remove_crc = true;
+ /* add claim address to new backbone_gw */
+ spin_lock_bh(&backbone_gw->crc_lock);
+ backbone_gw->crc ^= claim_crc;
+ spin_unlock_bh(&backbone_gw->crc_lock);
}
- /* replace backbone_gw atomically and adjust reference counters */
- spin_lock_bh(&claim->backbone_lock);
- old_backbone_gw = claim->backbone_gw;
- kref_get(&backbone_gw->refcount);
- claim->backbone_gw = backbone_gw;
- spin_unlock_bh(&claim->backbone_lock);
-
- if (remove_crc) {
+ if (old_backbone_gw) {
/* remove claim address from old backbone_gw */
spin_lock_bh(&old_backbone_gw->crc_lock);
- old_backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
+ old_backbone_gw->crc ^= claim_crc;
spin_unlock_bh(&old_backbone_gw->crc_lock);
- }
- batadv_backbone_gw_put(old_backbone_gw);
+ batadv_backbone_gw_put(old_backbone_gw);
+ }
- /* add claim address to new backbone_gw */
- spin_lock_bh(&backbone_gw->crc_lock);
- backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
- spin_unlock_bh(&backbone_gw->crc_lock);
WRITE_ONCE(backbone_gw->lasttime, jiffies);
-
-claim_free_ref:
batadv_claim_put(claim);
}
@@ -800,9 +810,10 @@ batadv_bla_claim_get_backbone_gw(struct batadv_bla_claim *claim)
static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
const u8 *mac, const unsigned short vid)
{
- struct batadv_bla_claim search_claim, *claim;
struct batadv_bla_claim *claim_removed_entry;
struct hlist_node *claim_removed_node;
+ struct batadv_bla_claim search_claim;
+ struct batadv_bla_claim *claim;
ether_addr_copy(search_claim.addr, mac);
search_claim.vid = vid;
@@ -842,7 +853,8 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
u8 *backbone_addr, unsigned short vid)
{
struct batadv_bla_backbone_gw *backbone_gw;
- u16 backbone_crc, crc;
+ u16 backbone_crc;
+ u16 crc;
if (memcmp(an_addr, batadv_announce_mac, 4) != 0)
return false;
@@ -1019,9 +1031,10 @@ static int batadv_check_claim_group(struct batadv_priv *bat_priv,
u8 *hw_src, u8 *hw_dst,
struct ethhdr *ethhdr)
{
- u8 *backbone_addr;
+ struct batadv_bla_claim_dst *bla_dst_own;
+ struct batadv_bla_claim_dst *bla_dst;
struct batadv_orig_node *orig_node;
- struct batadv_bla_claim_dst *bla_dst, *bla_dst_own;
+ u8 *backbone_addr;
bla_dst = (struct batadv_bla_claim_dst *)hw_dst;
bla_dst_own = &bat_priv->bla.claim_dest;
@@ -1078,6 +1091,11 @@ static int batadv_check_claim_group(struct batadv_priv *bat_priv,
* @primary_if: the primary hard interface of this batman mesh interface
* @skb: the frame to be checked
*
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: true if it was a claim frame, otherwise return false to
* tell the callee that it can use the frame on its own.
*/
@@ -1085,15 +1103,18 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if,
struct sk_buff *skb)
{
- struct batadv_bla_claim_dst *bla_dst, *bla_dst_own;
- u8 *hw_src, *hw_dst;
- struct vlan_hdr *vhdr, vhdr_buf;
+ struct batadv_bla_claim_dst *bla_dst_own;
+ struct batadv_bla_claim_dst *bla_dst;
+ struct vlan_hdr vhdr_buf;
+ struct vlan_hdr *vhdr;
struct ethhdr *ethhdr;
struct arphdr *arphdr;
unsigned short vid;
int vlan_depth = 0;
__be16 proto;
int headlen;
+ u8 *hw_src;
+ u8 *hw_dst;
int ret;
vid = batadv_get_vid(skb, 0);
@@ -1225,11 +1246,11 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,
*/
static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now)
{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_bla_backbone_gw *backbone_gw;
+ struct batadv_hashtable *hash;
struct hlist_node *node_tmp;
struct hlist_head *head;
- struct batadv_hashtable *hash;
- spinlock_t *list_lock; /* protects write access to the hash lists */
bool purged;
int i;
@@ -1302,8 +1323,8 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,
{
struct batadv_bla_backbone_gw *backbone_gw;
struct batadv_bla_claim *claim;
- struct hlist_head *head;
struct batadv_hashtable *hash;
+ struct hlist_head *head;
int i;
hash = bat_priv->bla.claim_hash;
@@ -1365,8 +1386,8 @@ void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
struct batadv_hard_iface *oldif)
{
struct batadv_bla_backbone_gw *backbone_gw;
- struct hlist_head *head;
struct batadv_hashtable *hash;
+ struct hlist_head *head;
__be16 group;
int i;
@@ -1459,14 +1480,14 @@ void batadv_bla_status_update(struct net_device *net_dev)
*/
static void batadv_bla_periodic_work(struct work_struct *work)
{
+ struct batadv_bla_backbone_gw *backbone_gw;
+ struct batadv_hard_iface *primary_if;
struct delayed_work *delayed_work;
- struct batadv_priv *bat_priv;
struct batadv_priv_bla *priv_bla;
- struct hlist_head *head;
- struct batadv_bla_backbone_gw *backbone_gw;
struct batadv_hashtable *hash;
- struct batadv_hard_iface *primary_if;
+ struct batadv_priv *bat_priv;
bool send_loopdetect = false;
+ struct hlist_head *head;
int i;
delayed_work = to_delayed_work(work);
@@ -1568,11 +1589,11 @@ static struct lock_class_key batadv_backbone_hash_lock_class_key;
*/
int batadv_bla_init(struct batadv_priv *bat_priv)
{
- int i;
u8 claim_dest[ETH_ALEN] = {0xff, 0x43, 0x05, 0x00, 0x00, 0x00};
struct batadv_hard_iface *primary_if;
- u16 crc;
unsigned long entrytime;
+ u16 crc;
+ int i;
spin_lock_init(&bat_priv->bla.bcast_duplist_lock);
@@ -1651,8 +1672,9 @@ static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv,
struct batadv_bcast_duplist_entry *entry;
bool ret = false;
int payload_len;
- int i, curr;
+ int curr;
u32 crc;
+ int i;
/* calculate the crc ... */
payload_len = skb->len - payload_offset;
@@ -1774,8 +1796,8 @@ bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,
unsigned short vid)
{
struct batadv_hashtable *hash = bat_priv->bla.backbone_hash;
- struct hlist_head *head;
struct batadv_bla_backbone_gw *backbone_gw;
+ struct hlist_head *head;
int i;
if (!READ_ONCE(bat_priv->bridge_loop_avoidance))
@@ -1807,6 +1829,11 @@ bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,
* @orig_node: the orig_node of the frame
* @hdr_size: maximum length of the frame
*
+ * Warning: This function may reallocate the skb data buffer via
+ * pskb_may_pull() and batadv_get_vid(). Any pointer into the skb data (e.g.
+ * obtained from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: true if the orig_node is also a gateway on the mesh interface,
* otherwise it returns false.
*/
@@ -1936,9 +1963,10 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
unsigned short vid, int packet_type)
{
struct batadv_bla_backbone_gw *backbone_gw;
- struct ethhdr *ethhdr;
- struct batadv_bla_claim search_claim, *claim = NULL;
+ struct batadv_bla_claim *claim = NULL;
+ struct batadv_bla_claim search_claim;
struct batadv_hard_iface *primary_if;
+ struct ethhdr *ethhdr;
bool own_claim;
bool ret;
@@ -2069,10 +2097,11 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
unsigned short vid)
{
- struct ethhdr *ethhdr;
- struct batadv_bla_claim search_claim, *claim = NULL;
struct batadv_bla_backbone_gw *backbone_gw;
+ struct batadv_bla_claim *claim = NULL;
+ struct batadv_bla_claim search_claim;
struct batadv_hard_iface *primary_if;
+ struct ethhdr *ethhdr;
bool client_roamed;
bool ret = false;
@@ -2173,10 +2202,10 @@ batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid,
{
const u8 *primary_addr = primary_if->net_dev->dev_addr;
struct batadv_bla_backbone_gw *backbone_gw;
+ int ret = -EINVAL;
u16 backbone_crc;
bool is_own;
void *hdr;
- int ret = -EINVAL;
hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq,
&batadv_netlink_family, NLM_F_MULTI,
@@ -2335,11 +2364,11 @@ batadv_bla_backbone_dump_entry(struct sk_buff *msg, u32 portid,
struct batadv_bla_backbone_gw *backbone_gw)
{
const u8 *primary_addr = primary_if->net_dev->dev_addr;
+ int ret = -EINVAL;
u16 backbone_crc;
bool is_own;
int msecs;
void *hdr;
- int ret = -EINVAL;
hdr = genlmsg_put(msg, portid, cb->nlh->nlmsg_seq,
&batadv_netlink_family, NLM_F_MULTI,
@@ -2494,10 +2523,10 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)
bool batadv_bla_check_claim(struct batadv_priv *bat_priv,
u8 *addr, unsigned short vid)
{
+ struct batadv_hard_iface *primary_if = NULL;
struct batadv_bla_backbone_gw *backbone_gw;
- struct batadv_bla_claim search_claim;
struct batadv_bla_claim *claim = NULL;
- struct batadv_hard_iface *primary_if = NULL;
+ struct batadv_bla_claim search_claim;
bool ret = true;
if (!READ_ONCE(bat_priv->bridge_loop_avoidance))
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index a6fe4820f65b9..bedd0cc76550d 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -50,27 +50,65 @@
#include "translation-table.h"
#include "tvlv.h"
+/**
+ * enum batadv_bootpop - BOOTP/DHCP message op codes
+ */
enum batadv_bootpop {
+ /** @BATADV_BOOTREPLY: server-to-client reply */
BATADV_BOOTREPLY = 2,
};
+/**
+ * enum batadv_boothtype - BOOTP/DHCP hardware address types
+ */
enum batadv_boothtype {
+ /** @BATADV_HTYPE_ETHERNET: Ethernet (10Mb) */
BATADV_HTYPE_ETHERNET = 1,
};
+/**
+ * enum batadv_dhcpoptioncode - DHCP option codes relevant for batman-adv DAT
+ */
enum batadv_dhcpoptioncode {
+ /** @BATADV_DHCP_OPT_PAD: pad option */
BATADV_DHCP_OPT_PAD = 0,
+
+ /** @BATADV_DHCP_OPT_MSG_TYPE: DHCP message type option */
BATADV_DHCP_OPT_MSG_TYPE = 53,
+
+ /** @BATADV_DHCP_OPT_END: end of options marker */
BATADV_DHCP_OPT_END = 255,
};
+/**
+ * enum batadv_dhcptype - DHCP message types relevant for batman-adv DAT
+ */
enum batadv_dhcptype {
+ /** @BATADV_DHCPACK: DHCPACK message */
BATADV_DHCPACK = 5,
};
/* { 99, 130, 83, 99 } */
#define BATADV_DHCP_MAGIC 1669485411
+/**
+ * struct batadv_dhcp_packet - BOOTP/DHCP packet header
+ * @op: message op code / message type
+ * @htype: hardware address type
+ * @hlen: hardware address length
+ * @hops: number of relay hops
+ * @xid: transaction identifier
+ * @secs: seconds elapsed since client started trying to boot
+ * @flags: BOOTP/DHCP flags
+ * @ciaddr: client IP address
+ * @yiaddr: "your" (client) IP address as assigned by the server
+ * @siaddr: IP address of next server to use in bootstrap
+ * @giaddr: relay agent IP address
+ * @chaddr: client hardware address
+ * @sname: optional server host name
+ * @file: boot file name
+ * @magic: BOOTP/DHCP magic cookie identifying the start of options
+ */
struct batadv_dhcp_packet {
__u8 op;
__u8 htype;
@@ -90,6 +128,34 @@ struct batadv_dhcp_packet {
/* __u8 options[]; */
};
+/**
+ * struct batadv_dhcp_header - minimal BOOTP/DHCP packet header
+ */
+struct batadv_dhcp_header {
+ /** @op: message op code / message type */
+ __u8 op;
+
+ /** @htype: hardware address type */
+ __u8 htype;
+
+ /** @hlen: hardware address length */
+ __u8 hlen;
+
+ /** @hops: number of relay hops */
+ __u8 hops;
+};
+
+/**
+ * struct batadv_dhcp_option_header - BOOTP/DHCP option header
+ */
+struct batadv_dhcp_option_header {
+ /** @type: type of option */
+ __u8 type;
+
+ /** @len: length of option */
+ __u8 len;
+};
+
#define BATADV_DHCP_YIADDR_LEN sizeof(((struct batadv_dhcp_packet *)0)->yiaddr)
#define BATADV_DHCP_CHADDR_LEN sizeof(((struct batadv_dhcp_packet *)0)->chaddr)
@@ -250,7 +316,10 @@ static u8 *batadv_arp_hw_src(struct sk_buff *skb, int hdr_size)
*/
static __be32 batadv_arp_ip_src(struct sk_buff *skb, int hdr_size)
{
- return *(__force __be32 *)(batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN);
+ u8 *src = batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN;
+ __be32 *ip = (__force __be32 *)src;
+
+ return get_unaligned(ip);
}
/**
@@ -275,8 +344,9 @@ static u8 *batadv_arp_hw_dst(struct sk_buff *skb, int hdr_size)
static __be32 batadv_arp_ip_dst(struct sk_buff *skb, int hdr_size)
{
u8 *dst = batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN * 2 + 4;
+ __be32 *ip = (__force __be32 *)dst;
- return *(__force __be32 *)dst;
+ return get_unaligned(ip);
}
/**
@@ -288,9 +358,9 @@ static __be32 batadv_arp_ip_dst(struct sk_buff *skb, int hdr_size)
*/
static u32 batadv_hash_dat(const void *data, u32 size)
{
- u32 hash = 0;
const struct batadv_dat_entry *dat = data;
const unsigned char *key;
+ u32 hash = 0;
__be16 vid;
u32 i;
@@ -329,9 +399,11 @@ static struct batadv_dat_entry *
batadv_dat_entry_hash_find(struct batadv_priv *bat_priv, __be32 ip,
unsigned short vid)
{
- struct hlist_head *head;
- struct batadv_dat_entry to_find, *dat_entry, *dat_entry_tmp = NULL;
struct batadv_hashtable *hash = bat_priv->dat.hash;
+ struct batadv_dat_entry *dat_entry_tmp = NULL;
+ struct batadv_dat_entry *dat_entry;
+ struct batadv_dat_entry to_find;
+ struct hlist_head *head;
u32 index;
if (!hash)
@@ -372,18 +444,19 @@ batadv_dat_entry_hash_find(struct batadv_priv *bat_priv, __be32 ip,
static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
u8 *mac_addr, unsigned short vid)
{
+ u64 u64_mac = ether_addr_to_u64(mac_addr);
struct batadv_dat_entry *dat_entry;
int hash_added;
dat_entry = batadv_dat_entry_hash_find(bat_priv, ip, vid);
/* if this entry is already known, just update it */
if (dat_entry) {
- if (!batadv_compare_eth(dat_entry->mac_addr, mac_addr))
- ether_addr_copy(dat_entry->mac_addr, mac_addr);
+ atomic64_set(&dat_entry->mac_addr, u64_mac);
+
dat_entry->last_update = jiffies;
batadv_dbg(BATADV_DBG_DAT, bat_priv,
"Entry updated: %pI4 %pM (vid: %d)\n",
- &dat_entry->ip, dat_entry->mac_addr,
+ &dat_entry->ip, mac_addr,
batadv_print_vid(vid));
goto out;
}
@@ -394,7 +467,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
dat_entry->ip = ip;
dat_entry->vid = vid;
- ether_addr_copy(dat_entry->mac_addr, mac_addr);
+ atomic64_set(&dat_entry->mac_addr, u64_mac);
dat_entry->last_update = jiffies;
kref_init(&dat_entry->refcount);
@@ -410,7 +483,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
}
batadv_dbg(BATADV_DBG_DAT, bat_priv, "New entry added: %pI4 %pM (vid: %d)\n",
- &dat_entry->ip, dat_entry->mac_addr, batadv_print_vid(vid));
+ &dat_entry->ip, mac_addr, batadv_print_vid(vid));
out:
batadv_dat_entry_put(dat_entry);
@@ -432,7 +505,8 @@ static void batadv_dbg_arp(struct batadv_priv *bat_priv, struct sk_buff *skb,
struct batadv_unicast_4addr_packet *unicast_4addr_packet;
struct batadv_bcast_packet *bcast_pkt;
u8 *orig_addr;
- __be32 ip_src, ip_dst;
+ __be32 ip_src;
+ __be32 ip_dst;
if (msg)
batadv_dbg(BATADV_DBG_DAT, bat_priv, "%s\n", msg);
@@ -567,10 +641,11 @@ static void batadv_choose_next_candidate(struct batadv_priv *bat_priv,
int select, batadv_dat_addr_t ip_key,
batadv_dat_addr_t *last_max)
{
- batadv_dat_addr_t max = 0;
- batadv_dat_addr_t tmp_max = 0;
- struct batadv_orig_node *orig_node, *max_orig_node = NULL;
struct batadv_hashtable *hash = bat_priv->orig_hash;
+ struct batadv_orig_node *max_orig_node = NULL;
+ struct batadv_orig_node *orig_node;
+ batadv_dat_addr_t tmp_max = 0;
+ batadv_dat_addr_t max = 0;
struct hlist_head *head;
int i;
@@ -634,10 +709,11 @@ static struct batadv_dat_candidate *
batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,
unsigned short vid)
{
- int select;
- batadv_dat_addr_t last_max = BATADV_DAT_ADDR_MAX, ip_key;
+ batadv_dat_addr_t last_max = BATADV_DAT_ADDR_MAX;
struct batadv_dat_candidate *res;
struct batadv_dat_entry dat;
+ batadv_dat_addr_t ip_key;
+ int select;
if (!bat_priv->orig_hash)
return NULL;
@@ -680,12 +756,12 @@ static bool batadv_dat_forward_data(struct batadv_priv *bat_priv,
struct sk_buff *skb, __be32 ip,
unsigned short vid, int packet_subtype)
{
- int i;
- bool ret = false;
- int send_status;
struct batadv_neigh_node *neigh_node = NULL;
- struct sk_buff *tmp_skb;
struct batadv_dat_candidate *cand;
+ struct sk_buff *tmp_skb;
+ bool ret = false;
+ int send_status;
+ int i;
cand = batadv_dat_select_candidates(bat_priv, ip, vid);
if (!cand)
@@ -864,6 +940,8 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid,
struct netlink_callback *cb,
struct batadv_dat_entry *dat_entry)
{
+ u8 mac[ETH_ALEN];
+ u64 u64_mac;
int msecs;
void *hdr;
@@ -876,11 +954,12 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid,
genl_dump_check_consistent(cb, hdr);
msecs = jiffies_to_msecs(jiffies - dat_entry->last_update);
+ u64_mac = atomic64_read(&dat_entry->mac_addr);
+ u64_to_ether_addr(u64_mac, mac);
if (nla_put_in_addr(msg, BATADV_ATTR_DAT_CACHE_IP4ADDRESS,
dat_entry->ip) ||
- nla_put(msg, BATADV_ATTR_DAT_CACHE_HWADDRESS, ETH_ALEN,
- dat_entry->mac_addr) ||
+ nla_put(msg, BATADV_ATTR_DAT_CACHE_HWADDRESS, ETH_ALEN, mac) ||
nla_put_u16(msg, BATADV_ATTR_DAT_CACHE_VID, dat_entry->vid) ||
nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, msecs)) {
genlmsg_cancel(msg, hdr);
@@ -993,6 +1072,11 @@ int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
* @skb: packet to analyse
* @hdr_size: size of the possible header before the ARP packet in the skb
*
+ * Warning: This function may reallocate the skb data buffer via
+ * pskb_may_pull(). Any pointer into the skb data (e.g. obtained from skb->data
+ * or eth_hdr()) before this call must be considered invalid afterwards and has
+ * to be reacquired.
+ *
* Return: the ARP type if the skb contains a valid ARP packet, 0 otherwise.
*/
static u16 batadv_arp_get_type(struct batadv_priv *bat_priv,
@@ -1000,9 +1084,11 @@ static u16 batadv_arp_get_type(struct batadv_priv *bat_priv,
{
struct arphdr *arphdr;
struct ethhdr *ethhdr;
- __be32 ip_src, ip_dst;
- u8 *hw_src, *hw_dst;
+ __be32 ip_src;
+ __be32 ip_dst;
u16 type = 0;
+ u8 *hw_src;
+ u8 *hw_dst;
/* pull the ethernet header */
if (unlikely(!pskb_may_pull(skb, hdr_size + ETH_HLEN)))
@@ -1069,6 +1155,11 @@ static u16 batadv_arp_get_type(struct batadv_priv *bat_priv,
* The caller must ensure that at least @hdr_size + ETH_HLEN bytes are
* accessible after skb->data.
*
+ * Warning: This function calls batadv_get_vid() and may therefore reallocate
+ * the skb data buffer. Any pointer into the skb data (e.g. obtained from
+ * skb->data or eth_hdr()) before this call must be considered invalid
+ * afterwards and has to be reacquired.
+ *
* Return: If the packet embedded in the skb is vlan tagged this function
* returns the VID with the BATADV_VLAN_HAS_TAG flag. Otherwise BATADV_NO_FLAGS
* is returned.
@@ -1131,6 +1222,11 @@ batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
* @bat_priv: the bat priv with all the mesh interface information
* @skb: packet to check
*
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: true if the message has been sent to the dht candidates, false
* otherwise. In case of a positive return value the message has to be enqueued
* to permit the fallback.
@@ -1138,15 +1234,18 @@ batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
- u16 type = 0;
- __be32 ip_dst, ip_src;
- u8 *hw_src;
- bool ret = false;
+ struct net_device *mesh_iface = bat_priv->mesh_iface;
struct batadv_dat_entry *dat_entry = NULL;
struct sk_buff *skb_new;
- struct net_device *mesh_iface = bat_priv->mesh_iface;
- int hdr_size = 0;
unsigned short vid;
+ bool ret = false;
+ u8 mac[ETH_ALEN];
+ int hdr_size = 0;
+ __be32 ip_dst;
+ __be32 ip_src;
+ u16 type = 0;
+ u64 u64_mac;
+ u8 *hw_src;
if (!READ_ONCE(bat_priv->distributed_arp_table))
goto out;
@@ -1174,6 +1273,9 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
dat_entry = batadv_dat_entry_hash_find(bat_priv, ip_dst, vid);
if (dat_entry) {
+ u64_mac = atomic64_read(&dat_entry->mac_addr);
+ u64_to_ether_addr(u64_mac, mac);
+
/* If the ARP request is destined for a local client the local
* client will answer itself. DAT would only generate a
* duplicate packet.
@@ -1182,7 +1284,7 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
* additional DAT answer may trigger kernel warnings about
* a packet coming from the wrong port.
*/
- if (batadv_is_my_client(bat_priv, dat_entry->mac_addr, vid)) {
+ if (batadv_is_my_client(bat_priv, mac, vid)) {
ret = true;
goto out;
}
@@ -1192,18 +1294,16 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
* the backbone gws belonging to our backbone has claimed the
* destination.
*/
- if (!batadv_bla_check_claim(bat_priv,
- dat_entry->mac_addr, vid)) {
+ if (!batadv_bla_check_claim(bat_priv, mac, vid)) {
batadv_dbg(BATADV_DBG_DAT, bat_priv,
"Device %pM claimed by another backbone gw. Don't send ARP reply!",
- dat_entry->mac_addr);
+ mac);
ret = true;
goto out;
}
skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
- dat_entry->mac_addr,
- hw_src, vid);
+ mac, hw_src, vid);
if (!skb_new)
goto out;
@@ -1233,18 +1333,26 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
* @skb: packet to check
* @hdr_size: size of the encapsulation header
*
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: true if the request has been answered, false otherwise.
*/
bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
struct sk_buff *skb, int hdr_size)
{
- u16 type;
- __be32 ip_src, ip_dst;
- u8 *hw_src;
- struct sk_buff *skb_new;
struct batadv_dat_entry *dat_entry = NULL;
- bool ret = false;
+ struct sk_buff *skb_new;
unsigned short vid;
+ bool ret = false;
+ u8 mac[ETH_ALEN];
+ __be32 ip_src;
+ __be32 ip_dst;
+ u64 u64_mac;
+ u8 *hw_src;
+ u16 type;
int err;
if (!READ_ONCE(bat_priv->distributed_arp_table))
@@ -1272,22 +1380,17 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
if (!dat_entry)
goto out;
+ u64_mac = atomic64_read(&dat_entry->mac_addr);
+ u64_to_ether_addr(u64_mac, mac);
+
skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
- dat_entry->mac_addr, hw_src, vid);
+ mac, hw_src, vid);
if (!skb_new)
goto out;
- /* To preserve backwards compatibility, the node has choose the outgoing
- * format based on the incoming request packet type. The assumption is
- * that a node not using the 4addr packet format doesn't support it.
- */
- if (hdr_size == sizeof(struct batadv_unicast_4addr_packet))
- err = batadv_send_skb_via_tt_4addr(bat_priv, skb_new,
- BATADV_P_DAT_CACHE_REPLY,
- NULL, vid);
- else
- err = batadv_send_skb_via_tt(bat_priv, skb_new, NULL, vid);
-
+ err = batadv_send_skb_via_tt_4addr(bat_priv, skb_new,
+ BATADV_P_DAT_CACHE_REPLY,
+ NULL, vid);
if (err != NET_XMIT_DROP) {
batadv_inc_counter(bat_priv, BATADV_CNT_DAT_CACHED_REPLY_TX);
ret = true;
@@ -1303,15 +1406,22 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
* batadv_dat_snoop_outgoing_arp_reply() - snoop the ARP reply and fill the DHT
* @bat_priv: the bat priv with all the mesh interface information
* @skb: packet to check
+ *
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
*/
void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
- u16 type;
- __be32 ip_src, ip_dst;
- u8 *hw_src, *hw_dst;
- int hdr_size = 0;
unsigned short vid;
+ int hdr_size = 0;
+ __be32 ip_src;
+ __be32 ip_dst;
+ u8 *hw_src;
+ u8 *hw_dst;
+ u16 type;
if (!READ_ONCE(bat_priv->distributed_arp_table))
return;
@@ -1352,6 +1462,11 @@ void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
* @skb: packet to check
* @hdr_size: size of the encapsulation header
*
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: true if the packet was snooped and consumed by DAT. False if the
* packet has to be delivered to the interface
*/
@@ -1359,11 +1474,15 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
struct sk_buff *skb, int hdr_size)
{
struct batadv_dat_entry *dat_entry = NULL;
- u16 type;
- __be32 ip_src, ip_dst;
- u8 *hw_src, *hw_dst;
bool dropped = false;
unsigned short vid;
+ u8 mac[ETH_ALEN];
+ __be32 ip_src;
+ __be32 ip_dst;
+ u64 u64_mac;
+ u8 *hw_src;
+ u8 *hw_dst;
+ u16 type;
if (!READ_ONCE(bat_priv->distributed_arp_table))
goto out;
@@ -1392,11 +1511,17 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
* this frame would lead to doubled receive of an ARP reply.
*/
dat_entry = batadv_dat_entry_hash_find(bat_priv, ip_src, vid);
- if (dat_entry && batadv_compare_eth(hw_src, dat_entry->mac_addr)) {
- batadv_dbg(BATADV_DBG_DAT, bat_priv, "Doubled ARP reply removed: ARP MSG = [src: %pM-%pI4 dst: %pM-%pI4]; dat_entry: %pM-%pI4\n",
- hw_src, &ip_src, hw_dst, &ip_dst,
- dat_entry->mac_addr, &dat_entry->ip);
- dropped = true;
+ if (dat_entry) {
+ u64_mac = atomic64_read(&dat_entry->mac_addr);
+ u64_to_ether_addr(u64_mac, mac);
+
+ if (batadv_compare_eth(hw_src, mac)) {
+ batadv_dbg(BATADV_DBG_DAT, bat_priv,
+ "Doubled ARP reply removed: ARP MSG = [src: %pM-%pI4 dst: %pM-%pI4]; dat_entry: %pM-%pI4\n",
+ hw_src, &ip_src, hw_dst, &ip_dst,
+ mac, &dat_entry->ip);
+ dropped = true;
+ }
}
/* Update our internal cache with both the IP addresses the node got
@@ -1454,8 +1579,10 @@ static bool
batadv_dat_check_dhcp_ipudp(struct sk_buff *skb, __be32 *ip_src)
{
unsigned int offset = skb_network_offset(skb);
- struct udphdr *udphdr, _udphdr;
- struct iphdr *iphdr, _iphdr;
+ struct udphdr *udphdr;
+ struct udphdr _udphdr;
+ struct iphdr *iphdr;
+ struct iphdr _iphdr;
iphdr = skb_header_pointer(skb, offset, sizeof(_iphdr), &_iphdr);
if (!iphdr || iphdr->version != 4 || iphdr->ihl * 4 < sizeof(_iphdr))
@@ -1493,14 +1620,11 @@ batadv_dat_check_dhcp_ipudp(struct sk_buff *skb, __be32 *ip_src)
static int
batadv_dat_check_dhcp(struct sk_buff *skb, __be16 proto, __be32 *ip_src)
{
- __be32 *magic, _magic;
+ struct batadv_dhcp_header *dhcp_h;
+ struct batadv_dhcp_header _dhcp_h;
unsigned int offset;
- struct {
- __u8 op;
- __u8 htype;
- __u8 hlen;
- __u8 hops;
- } *dhcp_h, _dhcp_h;
+ __be32 *magic;
+ __be32 _magic;
if (proto != htons(ETH_P_IP))
return -EINVAL;
@@ -1541,11 +1665,10 @@ batadv_dat_check_dhcp(struct sk_buff *skb, __be16 proto, __be32 *ip_src)
static int batadv_dat_get_dhcp_message_type(struct sk_buff *skb)
{
unsigned int offset = skb_transport_offset(skb) + sizeof(struct udphdr);
- u8 *type, _type;
- struct {
- u8 type;
- u8 len;
- } *tl, _tl;
+ struct batadv_dhcp_option_header *tl;
+ struct batadv_dhcp_option_header _tl;
+ u8 *type;
+ u8 _type;
offset += sizeof(struct batadv_dhcp_packet);
@@ -1737,7 +1860,8 @@ void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
unsigned short vid)
{
u8 chaddr[BATADV_DHCP_CHADDR_LEN];
- __be32 ip_src, yiaddr;
+ __be32 ip_src;
+ __be32 yiaddr;
if (!READ_ONCE(bat_priv->distributed_arp_table))
return;
@@ -1758,15 +1882,21 @@ void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
* This function first checks whether the given skb is a valid DHCPACK. If
* so then its source MAC and IP as well as its DHCP Client Hardware Address
* field and DHCP Your IP Address field are added to the local DAT cache.
+ *
+ * Warning: This function may reallocate the skb data buffer via
+ * pskb_may_pull()/batadv_dat_get_vid(). Any pointer into the skb data (e.g.
+ * obtained from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
*/
void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
struct sk_buff *skb, int hdr_size)
{
u8 chaddr[BATADV_DHCP_CHADDR_LEN];
struct ethhdr *ethhdr;
- __be32 ip_src, yiaddr;
unsigned short vid;
int hdr_size_tmp;
+ __be32 ip_src;
+ __be32 yiaddr;
__be16 proto;
u8 *hw_src;
@@ -1805,17 +1935,22 @@ void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
* @bat_priv: the bat priv with all the mesh interface information
* @forw_packet: the broadcast packet
*
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_dat_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: true if the node can drop the packet, false otherwise.
*/
bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
struct batadv_forw_packet *forw_packet)
{
- u16 type;
- __be32 ip_dst;
- struct batadv_dat_entry *dat_entry = NULL;
- bool ret = false;
int hdr_size = sizeof(struct batadv_bcast_packet);
+ struct batadv_dat_entry *dat_entry = NULL;
unsigned short vid;
+ bool ret = false;
+ __be32 ip_dst;
+ u16 type;
if (!READ_ONCE(bat_priv->distributed_arp_table))
goto out;
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
index 2e20a2cb64cbf..5142a911db9ff 100644
--- a/net/batman-adv/fragmentation.c
+++ b/net/batman-adv/fragmentation.c
@@ -139,15 +139,17 @@ static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,
struct sk_buff *skb,
struct hlist_head *chain_out)
{
- struct batadv_frag_table_entry *chain;
- struct batadv_frag_list_entry *frag_entry_new = NULL, *frag_entry_curr;
struct batadv_frag_list_entry *frag_entry_last = NULL;
+ struct batadv_frag_list_entry *frag_entry_new = NULL;
+ u16 hdr_size = sizeof(struct batadv_frag_packet);
+ struct batadv_frag_list_entry *frag_entry_curr;
struct batadv_frag_packet *frag_packet;
- u8 bucket;
- u16 seqno, hdr_size = sizeof(struct batadv_frag_packet);
+ struct batadv_frag_table_entry *chain;
bool overflow = false;
bool ret = false;
size_t data_len;
+ u8 bucket;
+ u16 seqno;
/* Linearize packet to avoid linearizing 16 packets in a row when doing
* the later merge. Non-linear merge should be added to remove this
@@ -258,11 +260,12 @@ static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,
static struct sk_buff *
batadv_frag_merge_packets(struct hlist_head *chain)
{
- struct batadv_frag_packet *packet;
+ int hdr_size = sizeof(struct batadv_frag_packet);
struct batadv_frag_list_entry *entry;
+ struct batadv_frag_packet *packet;
struct sk_buff *skb_out;
- int size, hdr_size = sizeof(struct batadv_frag_packet);
bool dropped = false;
+ int size;
/* Remove first entry, as this is the destination for the rest of the
* fragments.
@@ -348,8 +351,8 @@ static bool batadv_skb_is_frag(struct sk_buff *skb)
bool batadv_frag_skb_buffer(struct sk_buff **skb,
struct batadv_orig_node *orig_node_src)
{
- struct sk_buff *skb_out = NULL;
struct hlist_head head = HLIST_HEAD_INIT;
+ struct sk_buff *skb_out = NULL;
bool ret = false;
/* Add packet to buffer and table entry if merge is possible. */
@@ -403,8 +406,8 @@ bool batadv_frag_skb_fwd(struct sk_buff *skb,
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
struct batadv_neigh_node *neigh_node = NULL;
struct batadv_frag_packet *packet;
- u16 total_size;
bool ret = false;
+ u16 total_size;
packet = (struct batadv_frag_packet *)skb->data;
@@ -468,10 +471,11 @@ static struct sk_buff *batadv_frag_create(struct net_device *net_dev,
{
unsigned int ll_reserved = LL_RESERVED_SPACE(net_dev);
unsigned int tailroom = net_dev->needed_tailroom;
- struct sk_buff *skb_fragment;
unsigned int header_size = sizeof(*frag_head);
- unsigned int mtu = fragment_size + header_size;
+ struct sk_buff *skb_fragment;
+ unsigned int mtu;
+ mtu = fragment_size + header_size;
skb_fragment = dev_alloc_skb(ll_reserved + mtu + tailroom);
if (!skb_fragment)
goto err;
@@ -503,18 +507,20 @@ int batadv_frag_send_packet(struct sk_buff *skb,
struct batadv_neigh_node *neigh_node)
{
struct net_device *net_dev = neigh_node->if_incoming->net_dev;
- struct batadv_priv *bat_priv;
struct batadv_hard_iface *primary_if = NULL;
struct batadv_frag_packet frag_header;
- struct sk_buff *skb_fragment;
unsigned int mtu = net_dev->mtu;
- unsigned int header_size = sizeof(frag_header);
- unsigned int max_fragment_size, num_fragments;
+ unsigned int max_fragment_size;
+ struct batadv_priv *bat_priv;
+ struct sk_buff *skb_fragment;
+ unsigned int num_fragments;
+ unsigned int header_size;
int ret;
/* To avoid merge and refragmentation at next-hops we never send
* fragments larger than BATADV_FRAG_MAX_FRAG_SIZE
*/
+ header_size = sizeof(frag_header);
mtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE);
max_fragment_size = mtu - header_size;
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index a5ac82eabd250..0dfbd3f514c1c 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -103,8 +103,8 @@ batadv_gw_get_selected_gw_node(struct batadv_priv *bat_priv)
struct batadv_orig_node *
batadv_gw_get_selected_orig(struct batadv_priv *bat_priv)
{
- struct batadv_gw_node *gw_node;
struct batadv_orig_node *orig_node = NULL;
+ struct batadv_gw_node *gw_node;
gw_node = batadv_gw_get_selected_gw_node(bat_priv);
if (!gw_node)
@@ -125,6 +125,14 @@ batadv_gw_get_selected_orig(struct batadv_priv *bat_priv)
return orig_node;
}
+/**
+ * batadv_gw_select() - select a new currently active gateway
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @new_gw_node: gateway node to be set as the current gateway, may be NULL
+ *
+ * Atomically replace the currently active gateway with @new_gw_node and drop
+ * the reference to the previous one.
+ */
static void batadv_gw_select(struct batadv_priv *bat_priv,
struct batadv_gw_node *new_gw_node)
{
@@ -197,10 +205,10 @@ void batadv_gw_check_client_stop(struct batadv_priv *bat_priv)
*/
void batadv_gw_election(struct batadv_priv *bat_priv)
{
+ struct batadv_neigh_ifinfo *router_ifinfo = NULL;
+ struct batadv_neigh_node *router = NULL;
struct batadv_gw_node *curr_gw = NULL;
struct batadv_gw_node *next_gw = NULL;
- struct batadv_neigh_node *router = NULL;
- struct batadv_neigh_ifinfo *router_ifinfo = NULL;
char gw_addr[18] = { '\0' };
if (READ_ONCE(bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT)
@@ -370,7 +378,8 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
struct batadv_gw_node *batadv_gw_node_get(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node)
{
- struct batadv_gw_node *gw_node_tmp, *gw_node = NULL;
+ struct batadv_gw_node *gw_node = NULL;
+ struct batadv_gw_node *gw_node_tmp;
rcu_read_lock();
hlist_for_each_entry_rcu(gw_node_tmp, &bat_priv->gw.gateway_list,
@@ -400,7 +409,8 @@ void batadv_gw_node_update(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_tvlv_gateway_data *gateway)
{
- struct batadv_gw_node *gw_node, *curr_gw = NULL;
+ struct batadv_gw_node *curr_gw = NULL;
+ struct batadv_gw_node *gw_node;
spin_lock_bh(&bat_priv->gw.list_lock);
gw_node = batadv_gw_node_get(bat_priv, orig_node);
@@ -558,11 +568,11 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,
u8 *chaddr)
{
enum batadv_dhcp_recipient ret = BATADV_DHCP_NO;
- struct ethhdr *ethhdr;
- struct iphdr *iphdr;
+ struct vlan_ethhdr *vhdr;
struct ipv6hdr *ipv6hdr;
+ struct ethhdr *ethhdr;
struct udphdr *udphdr;
- struct vlan_ethhdr *vhdr;
+ struct iphdr *iphdr;
int chaddr_offset;
__be16 proto;
u8 *p;
@@ -669,7 +679,11 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,
* server. Due to topology changes it may be the case that the GW server
* previously selected is not the best one anymore.
*
- * This call might reallocate skb data.
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_get_vid(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Must be invoked only when the DHCP packet is going TO a DHCP SERVER.
*
* Return: true if the packet destination is unicast and it is not the best gw,
@@ -678,16 +692,17 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,
bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
+ struct batadv_orig_node *orig_dst_node = NULL;
struct batadv_neigh_node *neigh_curr = NULL;
struct batadv_neigh_node *neigh_old = NULL;
- struct batadv_orig_node *orig_dst_node = NULL;
+ struct batadv_neigh_ifinfo *curr_ifinfo;
+ struct batadv_neigh_ifinfo *old_ifinfo;
struct batadv_gw_node *gw_node = NULL;
struct batadv_gw_node *curr_gw = NULL;
- struct batadv_neigh_ifinfo *curr_ifinfo, *old_ifinfo;
- struct ethhdr *ethhdr;
bool out_of_range = false;
- u8 curr_tq_avg;
+ struct ethhdr *ethhdr;
unsigned short vid;
+ u8 curr_tq_avg;
vid = batadv_get_vid(skb, 0);
ethhdr = (struct ethhdr *)skb->data;
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index 675ebf098d4ec..65d3392050906 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -26,7 +26,8 @@ void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv)
{
struct batadv_tvlv_gateway_data gw;
enum batadv_gw_modes gw_mode;
- u32 down, up;
+ u32 down;
+ u32 up;
gw_mode = READ_ONCE(bat_priv->gw.mode);
@@ -59,7 +60,8 @@ static void batadv_gw_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
u8 flags,
void *tvlv_value, u16 tvlv_value_len)
{
- struct batadv_tvlv_gateway_data gateway, *gateway_ptr;
+ struct batadv_tvlv_gateway_data *gateway_ptr;
+ struct batadv_tvlv_gateway_data gateway;
/* only fetch the tvlv value if the handler wasn't called via the
* CIFNOTFND flag and if there is data to fetch
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index b6867576bbafa..e7ad295504e4f 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -197,6 +197,17 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
return ret;
}
+/**
+ * batadv_is_valid_iface() - check whether a net_device can be used as a hard
+ * interface
+ * @net_dev: the net_device to check
+ *
+ * Refuse loopback devices, non-Ethernet devices, devices with a non-Ethernet
+ * address length and any device that is already part of a batman-adv mesh
+ * interface stack.
+ *
+ * Return: true if @net_dev can be used as a hard interface, false otherwise
+ */
static bool batadv_is_valid_iface(const struct net_device *net_dev)
{
if (net_dev->flags & IFF_LOOPBACK)
@@ -339,8 +350,8 @@ static bool batadv_is_cfg80211_netdev(struct net_device *net_device)
*/
static u32 batadv_wifi_flags_evaluate(struct net_device *net_device)
{
- u32 wifi_flags = 0;
struct net_device *real_netdev;
+ u32 wifi_flags = 0;
if (batadv_is_wext_netdev(net_device))
wifi_flags |= BATADV_HARDIF_WIFI_WEXT_DIRECT;
@@ -434,8 +445,8 @@ int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
u8 *orig_addr, u8 *orig_neigh)
{
struct batadv_hardif_neigh_node *hardif_neigh;
- struct hlist_node *first;
int ret = BATADV_HARDIF_BCAST_OK;
+ struct hlist_node *first;
rcu_read_lock();
@@ -467,6 +478,14 @@ int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
return ret;
}
+/**
+ * batadv_hardif_get_active() - retrieve an active hard interface for a mesh
+ * interface
+ * @mesh_iface: mesh interface to search
+ *
+ * Return: first hard interface in BATADV_IF_ACTIVE state attached to
+ * @mesh_iface, or NULL if none is active.
+ */
static struct batadv_hard_iface *
batadv_hardif_get_active(struct net_device *mesh_iface)
{
@@ -487,6 +506,15 @@ batadv_hardif_get_active(struct net_device *mesh_iface)
return hard_iface;
}
+/**
+ * batadv_primary_if_update_addr() - propagate the new primary interface MAC
+ * address to all dependent components
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @oldif: previously used primary interface, or NULL if none
+ *
+ * Inform DAT and BLA that the originator address has changed so they can
+ * adjust their state accordingly.
+ */
static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
struct batadv_hard_iface *oldif)
{
@@ -502,6 +530,15 @@ static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
batadv_hardif_put(primary_if);
}
+/**
+ * batadv_primary_if_select() - select the new primary interface
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @new_hard_iface: new primary interface, may be NULL
+ *
+ * Replace the currently selected primary interface with @new_hard_iface,
+ * invoke the algorithm-specific primary_set hook and update the originator
+ * MAC address.
+ */
static void batadv_primary_if_select(struct batadv_priv *bat_priv,
struct batadv_hard_iface *new_hard_iface)
{
@@ -525,6 +562,13 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,
batadv_hardif_put(curr_hard_iface);
}
+/**
+ * batadv_hardif_is_iface_up() - check whether the underlying net_device of a
+ * hard interface is up
+ * @hard_iface: the hard interface to check
+ *
+ * Return: true if the underlying net_device has the IFF_UP flag set
+ */
static bool
batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
{
@@ -534,6 +578,15 @@ batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
return false;
}
+/**
+ * batadv_check_known_mac_addr() - warn about duplicate hard interface MAC
+ * addresses
+ * @hard_iface: hard interface that was just added or had its MAC changed
+ *
+ * Iterate over all hard interfaces of the same mesh interface and emit a
+ * warning if another in-use interface shares the same MAC address as
+ * @hard_iface.
+ */
static void batadv_check_known_mac_addr(const struct batadv_hard_iface *hard_iface)
{
struct net_device *mesh_iface = hard_iface->mesh_iface;
@@ -666,11 +719,20 @@ void batadv_update_min_mtu(struct net_device *mesh_iface)
batadv_tt_local_resize_to_mtu(mesh_iface);
}
+/**
+ * batadv_hardif_activate_interface() - move a hard interface to the active
+ * state
+ * @hard_iface: the interface that has come up
+ *
+ * Activate an interface, select it as the primary interface if no
+ * primary is currently active and invoke the algorithm-specific
+ * activate hook.
+ */
static void
batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
{
- struct batadv_priv *bat_priv;
struct batadv_hard_iface *primary_if = NULL;
+ struct batadv_priv *bat_priv;
if (hard_iface->if_status != BATADV_IF_INACTIVE)
goto out;
@@ -699,6 +761,14 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
batadv_hardif_put(primary_if);
}
+/**
+ * batadv_hardif_deactivate_interface() - move a hard interface to the
+ * inactive state
+ * @hard_iface: the interface that went down
+ *
+ * Demote @hard_iface to BATADV_IF_INACTIVE and recalculate the mesh minimum
+ * MTU based on the remaining active interfaces.
+ */
static void
batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
{
@@ -724,10 +794,10 @@ batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
int batadv_hardif_enable_interface(struct net_device *net_dev,
struct net_device *mesh_iface)
{
- struct batadv_priv *bat_priv;
- __be16 ethertype = htons(ETH_P_BATMAN);
int max_header_len = batadv_max_header_len();
+ __be16 ethertype = htons(ETH_P_BATMAN);
struct batadv_hard_iface *hard_iface;
+ struct batadv_priv *bat_priv;
unsigned int required_mtu;
unsigned int hardif_mtu;
bool fragmentation;
@@ -1020,12 +1090,24 @@ static void batadv_wifi_net_device_event(unsigned long event,
}
}
+/**
+ * batadv_hard_if_event() - netdevice notifier callback for hard interfaces
+ * @this: notifier block (unused)
+ * @event: the NETDEV_* event to handle
+ * @ptr: notifier info pointing to the affected net_device
+ *
+ * Dispatch netdevice events that affect potential or existing hard
+ * interfaces. Mesh interfaces are handled separately by
+ * batadv_hard_if_event_meshif().
+ *
+ * Return: NOTIFY_DONE
+ */
static int batadv_hard_if_event(struct notifier_block *this,
unsigned long event, void *ptr)
{
struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
- struct batadv_hard_iface *hard_iface;
struct batadv_hard_iface *primary_if = NULL;
+ struct batadv_hard_iface *hard_iface;
struct batadv_priv *bat_priv;
if (batadv_meshif_is_valid(net_dev))
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 759fa29176db5..b9a652bd523b1 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -11,7 +11,10 @@
#include <linux/lockdep.h>
#include <linux/slab.h>
-/* clears the hash */
+/**
+ * batadv_hash_init() - clear all buckets of a hashtable
+ * @hash: hashtable to clear
+ */
static void batadv_hash_init(struct batadv_hashtable *hash)
{
u32 i;
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index 86a2c20000dcf..755ced52a01c5 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -18,21 +18,35 @@
#include <linux/stddef.h>
#include <linux/types.h>
-/* callback to a compare function. should compare 2 element data for their
- * keys
+/**
+ * typedef batadv_hashdata_compare_cb - hash element comparison callback
+ * @node: hlist node of the element currently stored in the bucket
+ * @key: opaque payload to compare @node's key against
+ *
+ * Compare hash element by its keys.
+ *
+ * Return: true if both elements are considered equal, false otherwise.
+ */
+typedef bool (*batadv_hashdata_compare_cb)(const struct hlist_node *node,
+ const void *key);
+
+/**
+ * typedef batadv_hashdata_choose_cb - hash bucket selection callback
+ * @key: opaque payload whose key selects the bucket
+ * @size: number of buckets in the hash table
*
- * Return: true if same and false if not same
+ * Return: bucket index derived from the key in @data and the table @size.
*/
-typedef bool (*batadv_hashdata_compare_cb)(const struct hlist_node *,
- const void *);
+typedef u32 (*batadv_hashdata_choose_cb)(const void *key, u32 size);
-/* the hashfunction
+/**
+ * typedef batadv_hashdata_free_cb - hash element free callback
+ * @node: hlist node of the element being removed
+ * @arg: opaque caller-supplied argument forwarded from the caller
*
- * Return: an index based on the key in the data of the first argument and the
- * size the second
+ * Release a previously inserted hash element.
*/
-typedef u32 (*batadv_hashdata_choose_cb)(const void *, u32);
-typedef void (*batadv_hashdata_free_cb)(struct hlist_node *, void *);
+typedef void (*batadv_hashdata_free_cb)(struct hlist_node *node, void *arg);
/**
* struct batadv_hashtable - Wrapper of simple hlist based hashtable
@@ -78,11 +92,11 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash,
const void *data,
struct hlist_node *data_node)
{
- u32 index;
- int ret = -1;
+ spinlock_t *list_lock; /* spinlock to protect write access */
struct hlist_head *head;
struct hlist_node *node;
- spinlock_t *list_lock; /* spinlock to protect write access */
+ int ret = -1;
+ u32 index;
if (!hash)
goto out;
@@ -131,10 +145,10 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash,
batadv_hashdata_choose_cb choose,
void *data)
{
- u32 index;
struct hlist_node *node;
struct hlist_head *head;
void *data_save = NULL;
+ u32 index;
index = choose(data, hash->size);
head = &hash->table[index];
diff --git a/net/batman-adv/log.h b/net/batman-adv/log.h
index a0d2b0d64b2b0..9f3aed826dea6 100644
--- a/net/batman-adv/log.h
+++ b/net/batman-adv/log.h
@@ -117,8 +117,12 @@ static inline void _batadv_dbg(int type __always_unused,
*/
#define batadv_info(net_dev, fmt, arg...) \
do { \
- struct net_device *_netdev = (net_dev); \
- struct batadv_priv *_batpriv = netdev_priv(_netdev); \
+ struct batadv_priv *_batpriv; \
+ struct net_device *_netdev; \
+ \
+ _netdev = (net_dev); \
+ _batpriv = netdev_priv(_netdev); \
+ \
batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
pr_info("%s: " fmt, _netdev->name, ## arg); \
} while (0)
@@ -131,8 +135,12 @@ static inline void _batadv_dbg(int type __always_unused,
*/
#define batadv_err(net_dev, fmt, arg...) \
do { \
- struct net_device *_netdev = (net_dev); \
- struct batadv_priv *_batpriv = netdev_priv(_netdev); \
+ struct batadv_priv *_batpriv; \
+ struct net_device *_netdev; \
+ \
+ _netdev = (net_dev); \
+ _batpriv = netdev_priv(_netdev); \
+ \
batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
pr_err("%s: " fmt, _netdev->name, ## arg); \
} while (0)
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 73becb0549488..5981e8eb6d979 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -82,6 +82,14 @@ static char *batadv_uev_type_str[] = {
"bla",
};
+/**
+ * batadv_init() - batman-adv module init function
+ *
+ * Initialise the global state used by all mesh interfaces, register the
+ * netdevice notifier and the netlink/rtnl family.
+ *
+ * Return: 0 on success or negative error number in case of failure
+ */
static int __init batadv_init(void)
{
int ret;
@@ -128,6 +136,12 @@ static int __init batadv_init(void)
return ret;
}
+/**
+ * batadv_exit() - batman-adv module exit function
+ *
+ * Unregister the netdevice notifier and tear down all global state allocated
+ * by batadv_init().
+ */
static void __exit batadv_exit(void)
{
batadv_netlink_unregister();
@@ -354,10 +368,14 @@ int batadv_max_header_len(void)
*/
void batadv_skb_set_priority(struct sk_buff *skb, int offset)
{
- struct iphdr ip_hdr_tmp, *ip_hdr;
- struct ipv6hdr ip6_hdr_tmp, *ip6_hdr;
- struct ethhdr ethhdr_tmp, *ethhdr;
- struct vlan_ethhdr *vhdr, vhdr_tmp;
+ struct vlan_ethhdr vhdr_tmp;
+ struct ipv6hdr ip6_hdr_tmp;
+ struct ethhdr ethhdr_tmp;
+ struct vlan_ethhdr *vhdr;
+ struct iphdr ip_hdr_tmp;
+ struct ipv6hdr *ip6_hdr;
+ struct ethhdr *ethhdr;
+ struct iphdr *ip_hdr;
u32 prio;
/* already set, do nothing */
@@ -398,6 +416,17 @@ void batadv_skb_set_priority(struct sk_buff *skb, int offset)
skb->priority = prio + 256;
}
+/**
+ * batadv_recv_unhandled_packet() - default RX handler for unsupported packet
+ * types
+ * @skb: incoming packet
+ * @recv_if: interface on which the packet was received (unused)
+ *
+ * Drop incoming packets whose packet_type has no dedicated RX handler
+ * registered.
+ *
+ * Return: NET_RX_DROP
+ */
static int batadv_recv_unhandled_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
@@ -406,10 +435,6 @@ static int batadv_recv_unhandled_packet(struct sk_buff *skb,
return NET_RX_DROP;
}
-/* incoming packets with the batman ethertype received on any active hard
- * interface
- */
-
/**
* batadv_batman_skb_recv() - Handle incoming message from an hard interface
* @skb: the received packet
@@ -423,9 +448,9 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *ptype,
struct net_device *orig_dev)
{
- struct batadv_priv *bat_priv;
struct batadv_ogm_packet *batadv_ogm_packet;
struct batadv_hard_iface *hard_iface;
+ struct batadv_priv *bat_priv;
u8 idx;
hard_iface = container_of(ptype, struct batadv_hard_iface,
@@ -492,6 +517,13 @@ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
return NET_RX_DROP;
}
+/**
+ * batadv_recv_handler_init() - initialise the RX handler dispatch table
+ *
+ * Initialise all entries of the RX handler table (+ unused to the
+ * default drop handler) and perform compile-time size sanity checks on
+ * all on-wire packet structs.
+ */
static void batadv_recv_handler_init(void)
{
int i;
@@ -582,6 +614,11 @@ void batadv_recv_handler_unregister(u8 packet_type)
* The caller must ensure that at least @header_len + ETH_HLEN bytes are
* accessible after skb->data.
*
+ * Warning: This function may reallocate the skb data buffer via
+ * pskb_may_pull(). Any pointer into the skb data (e.g. obtained from skb->data
+ * or eth_hdr()) before this call must be considered invalid afterwards and has
+ * to be reacquired.
+ *
* Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the
* skb is vlan tagged. Otherwise BATADV_NO_FLAGS.
*/
@@ -650,9 +687,9 @@ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)
int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
enum batadv_uev_action action, const char *data)
{
- int ret = -ENOMEM;
- struct kobject *bat_kobj;
char *uevent_env[4] = { NULL, NULL, NULL, NULL };
+ struct kobject *bat_kobj;
+ int ret = -ENOMEM;
bat_kobj = &bat_priv->mesh_iface->dev.kobj;
diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c
index 1dc6cfae9e9ae..90830b10403f3 100644
--- a/net/batman-adv/mesh-interface.c
+++ b/net/batman-adv/mesh-interface.c
@@ -57,6 +57,11 @@
* @skb: packet buffer which should be modified
* @len: number of bytes to add
*
+ * Warning: This function may reallocate the skb data buffer via
+ * skb_cow_head(). Any pointer into the skb data (e.g. obtained
+ * from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
* Return: 0 on success or negative error number in case of failure
*/
int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
@@ -87,7 +92,8 @@ int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
*/
static u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx)
{
- u64 *counters, sum = 0;
+ u64 *counters;
+ u64 sum = 0;
int cpu;
for_each_possible_cpu(cpu) {
@@ -98,6 +104,15 @@ static u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx)
return sum;
}
+/**
+ * batadv_interface_stats() - return netdev stats for a mesh interface
+ * @dev: the mesh interface to query
+ *
+ * Aggregate the per-CPU traffic counters into the standard netdev stats
+ * structure.
+ *
+ * Return: pointer to the populated net_device_stats structure
+ */
static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
{
struct batadv_priv *bat_priv = netdev_priv(dev);
@@ -111,6 +126,18 @@ static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
return stats;
}
+/**
+ * batadv_interface_set_mac_addr() - change the MAC address of a mesh
+ * interface
+ * @dev: the mesh interface to modify
+ * @p: pointer to a struct sockaddr holding the new MAC address
+ *
+ * Replace the MAC address of the mesh interface. If the mesh is already
+ * active, also update the local translation table entries for all configured
+ * VLANs so that the new MAC is announced and the old one is removed.
+ *
+ * Return: 0 on success or negative error number in case of failure
+ */
static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
{
struct batadv_priv *bat_priv = netdev_priv(dev);
@@ -140,6 +167,16 @@ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
return 0;
}
+/**
+ * batadv_interface_change_mtu() - change the MTU of a mesh interface
+ * @dev: the mesh interface to modify
+ * @new_mtu: requested new MTU value
+ *
+ * Validate that @new_mtu fits within the range supported by the configured
+ * hard interfaces and remember it as the user-configured MTU.
+ *
+ * Return: 0 on success or -EINVAL if @new_mtu is out of range
+ */
static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
{
struct batadv_priv *bat_priv = netdev_priv(dev);
@@ -166,31 +203,39 @@ static void batadv_interface_set_rx_mode(struct net_device *dev)
{
}
+/**
+ * batadv_interface_tx() - transmit a frame on a mesh interface
+ * @skb: the frame to send
+ * @mesh_iface: the mesh interface the frame was queued on
+ *
+ * Return: NETDEV_TX_OK on success
+ */
static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
struct net_device *mesh_iface)
{
- struct ethhdr *ethhdr;
+ static const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00, 0x00, 0x00};
+ static const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x00};
struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
+ enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;
+ enum batadv_forw_mode forw_mode = BATADV_FORW_BCAST;
struct batadv_hard_iface *primary_if = NULL;
struct batadv_bcast_packet *bcast_packet;
- static const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
- 0x00, 0x00};
- static const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
- 0x00, 0x00};
- enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;
- u8 *dst_hint = NULL, chaddr[ETH_ALEN];
- struct vlan_ethhdr *vhdr;
+ int network_offset = ETH_HLEN;
unsigned int header_len = 0;
- int data_len = skb->len, ret;
unsigned long brd_delay = 0;
- bool do_bcast = false, client_added;
- unsigned short vid;
- u32 seqno;
- int gw_mode;
- enum batadv_forw_mode forw_mode = BATADV_FORW_BCAST;
int mcast_is_routable = 0;
- int network_offset = ETH_HLEN;
+ struct vlan_ethhdr *vhdr;
+ int data_len = skb->len;
+ struct ethhdr *ethhdr;
+ bool do_bcast = false;
+ u8 *dst_hint = NULL;
+ u8 chaddr[ETH_ALEN];
+ unsigned short vid;
+ bool client_added;
__be16 proto;
+ int gw_mode;
+ u32 seqno;
+ int ret;
if (READ_ONCE(bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
goto dropped;
@@ -260,6 +305,8 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
goto dropped;
+ batadv_skb_set_priority(skb, 0);
+
gw_mode = READ_ONCE(bat_priv->gw.mode);
if (is_multicast_ether_addr(ethhdr->h_dest)) {
/* if gw mode is off, broadcast every packet */
@@ -293,6 +340,9 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
send:
if (do_bcast && !is_broadcast_ether_addr(ethhdr->h_dest)) {
+ /* WARNING batadv_mcast_forw_mode might add more headers
+ * in front of the skb. and might even reallocate the skb
+ */
forw_mode = batadv_mcast_forw_mode(bat_priv, skb, vid,
&mcast_is_routable);
switch (forw_mode) {
@@ -310,8 +360,6 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
}
}
- batadv_skb_set_priority(skb, 0);
-
/* ethernet packet should be broadcasted */
if (do_bcast) {
primary_if = batadv_primary_if_get_selected(bat_priv);
@@ -408,8 +456,8 @@ void batadv_interface_rx(struct net_device *mesh_iface,
struct sk_buff *skb, int hdr_size,
struct batadv_orig_node *orig_node)
{
- struct batadv_bcast_packet *batadv_bcast_packet;
struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
+ struct batadv_bcast_packet *batadv_bcast_packet;
struct vlan_ethhdr *vhdr;
struct ethhdr *ethhdr;
unsigned short vid;
@@ -523,7 +571,8 @@ void batadv_meshif_vlan_release(struct kref *ref)
struct batadv_meshif_vlan *batadv_meshif_vlan_get(struct batadv_priv *bat_priv,
unsigned short vid)
{
- struct batadv_meshif_vlan *vlan_tmp, *vlan = NULL;
+ struct batadv_meshif_vlan *vlan = NULL;
+ struct batadv_meshif_vlan *vlan_tmp;
rcu_read_lock();
hlist_for_each_entry_rcu(vlan_tmp, &bat_priv->meshif_vlan_list, list) {
@@ -741,10 +790,10 @@ static void batadv_set_lockdep_class(struct net_device *dev)
*/
static int batadv_meshif_init_late(struct net_device *dev)
{
+ size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;
struct batadv_priv *bat_priv;
u32 random_seqno;
int ret;
- size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;
batadv_set_lockdep_class(dev);
@@ -883,6 +932,11 @@ static const struct net_device_ops batadv_netdev_ops = {
.ndo_del_slave = batadv_meshif_slave_del,
};
+/**
+ * batadv_get_drvinfo() - ethtool driver info handler for mesh interfaces
+ * @dev: the mesh interface (unused)
+ * @info: ethtool_drvinfo struct to populate
+ */
static void batadv_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
@@ -943,6 +997,12 @@ static const struct {
#endif
};
+/**
+ * batadv_get_strings() - ethtool string handler for mesh interfaces
+ * @dev: the mesh interface (unused)
+ * @stringset: ethtool string set to retrieve
+ * @data: buffer to copy the requested string set into
+ */
static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data)
{
if (stringset == ETH_SS_STATS)
@@ -950,6 +1010,12 @@ static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data)
sizeof(batadv_counters_strings));
}
+/**
+ * batadv_get_ethtool_stats() - ethtool stats handler for mesh interfaces
+ * @dev: the mesh interface to query
+ * @stats: ethtool_stats struct (unused)
+ * @data: destination array for the gathered counter values
+ */
static void batadv_get_ethtool_stats(struct net_device *dev,
struct ethtool_stats *stats, u64 *data)
{
@@ -960,6 +1026,14 @@ static void batadv_get_ethtool_stats(struct net_device *dev,
data[i] = batadv_sum_counter(bat_priv, i);
}
+/**
+ * batadv_get_sset_count() - ethtool stringset size handler for mesh interfaces
+ * @dev: the mesh interface (unused)
+ * @stringset: ethtool string set to query
+ *
+ * Return: number of entries in @stringset or -EOPNOTSUPP if @stringset is not
+ * supported
+ */
static int batadv_get_sset_count(struct net_device *dev, int stringset)
{
if (stringset == ETH_SS_STATS)
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 1c5315e55c046..929dca6f21f50 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -274,8 +274,9 @@ static struct batadv_mcast_mla_flags
batadv_mcast_mla_flags_get(struct batadv_priv *bat_priv)
{
struct net_device *dev = bat_priv->mesh_iface;
- struct batadv_mcast_querier_state *qr4, *qr6;
struct batadv_mcast_mla_flags mla_flags;
+ struct batadv_mcast_querier_state *qr4;
+ struct batadv_mcast_querier_state *qr6;
struct net_device *bridge;
bridge = batadv_mcast_get_bridge(dev);
@@ -521,7 +522,8 @@ batadv_mcast_mla_meshif_get(struct net_device *dev,
struct batadv_mcast_mla_flags *flags)
{
struct net_device *bridge = batadv_mcast_get_bridge(dev);
- int ret4, ret6 = 0;
+ int ret6 = 0;
+ int ret4;
if (bridge)
dev = bridge;
@@ -585,10 +587,11 @@ static int batadv_mcast_mla_bridge_get(struct net_device *dev,
struct batadv_mcast_mla_flags *flags)
{
struct list_head bridge_mcast_list = LIST_HEAD_INIT(bridge_mcast_list);
- struct br_ip_list *br_ip_entry, *tmp;
u8 tvlv_flags = flags->tvlv_flags;
+ struct br_ip_list *br_ip_entry;
struct batadv_hw_addr *new;
u8 mcast_addr[ETH_ALEN];
+ struct br_ip_list *tmp;
int ret;
/* we don't need to detect these devices/listeners, the IGMP/MLD
@@ -935,8 +938,8 @@ static void __batadv_mcast_mla_update(struct batadv_priv *bat_priv)
*/
static void batadv_mcast_mla_update(struct work_struct *work)
{
- struct delayed_work *delayed_work;
struct batadv_priv_mcast *priv_mcast;
+ struct delayed_work *delayed_work;
struct batadv_priv *bat_priv;
delayed_work = to_delayed_work(work);
@@ -1223,10 +1226,14 @@ enum batadv_forw_mode
batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
unsigned short vid, int *is_routable)
{
- int ret, tt_count, ip_count, unsnoop_count, total_count;
bool is_unsnoopable = false;
struct ethhdr *ethhdr;
+ int unsnoop_count;
int rtr_count = 0;
+ int total_count;
+ int tt_count;
+ int ip_count;
+ int ret;
ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable,
is_routable);
@@ -1301,13 +1308,11 @@ static int
batadv_mcast_forw_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,
unsigned short vid)
{
- int ret = NET_XMIT_SUCCESS;
- struct sk_buff *newskb;
-
struct batadv_tt_orig_list_entry *orig_entry;
-
struct batadv_tt_global_entry *tt_global;
const u8 *addr = eth_hdr(skb)->h_dest;
+ int ret = NET_XMIT_SUCCESS;
+ struct sk_buff *newskb;
tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
if (!tt_global)
@@ -1602,8 +1607,8 @@ static void batadv_mcast_want_unsnoop_update(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig,
u8 mcast_flags)
{
- struct hlist_node *node = &orig->mcast_want_all_unsnoopables_node;
struct hlist_head *head = &bat_priv->mcast.want_all_unsnoopables_list;
+ struct hlist_node *node = &orig->mcast_want_all_unsnoopables_node;
lockdep_assert_held(&orig->mcast_handler_lock);
@@ -1647,8 +1652,8 @@ static void batadv_mcast_want_ipv4_update(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig,
u8 mcast_flags)
{
- struct hlist_node *node = &orig->mcast_want_all_ipv4_node;
struct hlist_head *head = &bat_priv->mcast.want_all_ipv4_list;
+ struct hlist_node *node = &orig->mcast_want_all_ipv4_node;
lockdep_assert_held(&orig->mcast_handler_lock);
@@ -1692,8 +1697,8 @@ static void batadv_mcast_want_ipv6_update(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig,
u8 mcast_flags)
{
- struct hlist_node *node = &orig->mcast_want_all_ipv6_node;
struct hlist_head *head = &bat_priv->mcast.want_all_ipv6_list;
+ struct hlist_node *node = &orig->mcast_want_all_ipv6_node;
lockdep_assert_held(&orig->mcast_handler_lock);
@@ -1737,8 +1742,8 @@ static void batadv_mcast_want_rtr4_update(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig,
u8 mcast_flags)
{
- struct hlist_node *node = &orig->mcast_want_all_rtr4_node;
struct hlist_head *head = &bat_priv->mcast.want_all_rtr4_list;
+ struct hlist_node *node = &orig->mcast_want_all_rtr4_node;
lockdep_assert_held(&orig->mcast_handler_lock);
@@ -1782,8 +1787,8 @@ static void batadv_mcast_want_rtr6_update(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig,
u8 mcast_flags)
{
- struct hlist_node *node = &orig->mcast_want_all_rtr6_node;
struct hlist_head *head = &bat_priv->mcast.want_all_rtr6_list;
+ struct hlist_node *node = &orig->mcast_want_all_rtr6_node;
lockdep_assert_held(&orig->mcast_handler_lock);
diff --git a/net/batman-adv/multicast_forw.c b/net/batman-adv/multicast_forw.c
index 1404a3b7adfb1..ccd4ae158dcd3 100644
--- a/net/batman-adv/multicast_forw.c
+++ b/net/batman-adv/multicast_forw.c
@@ -195,8 +195,8 @@ static int batadv_mcast_forw_push_dests_list(struct batadv_priv *bat_priv,
unsigned short *num_dests,
unsigned short *tvlv_len)
{
- struct hlist_node *node;
struct batadv_orig_node *orig_node;
+ struct hlist_node *node;
rcu_read_lock();
__hlist_for_each_rcu(node, head) {
@@ -232,12 +232,9 @@ batadv_mcast_forw_push_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,
unsigned short *tvlv_len)
{
struct batadv_tt_orig_list_entry *orig_entry;
-
struct batadv_tt_global_entry *tt_global;
const u8 *addr = eth_hdr(skb)->h_dest;
-
- /* ok */
- int ret = true;
+ int ret = true; /* ok */
tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
if (!tt_global)
@@ -368,7 +365,8 @@ static void batadv_mcast_forw_scrape(struct sk_buff *skb,
unsigned short offset,
unsigned short len)
{
- char *to, *from;
+ char *from;
+ char *to;
SKB_LINEAR_ASSERT(skb);
@@ -411,7 +409,8 @@ static bool batadv_mcast_forw_push_insert_padding(struct sk_buff *skb,
unsigned short *tvlv_len)
{
unsigned short offset = *tvlv_len;
- char *to, *from = skb->data;
+ char *from = skb->data;
+ char *to;
to = batadv_mcast_forw_push_padding(skb, tvlv_len);
if (!to)
@@ -933,8 +932,9 @@ static int batadv_mcast_forw_packet(struct batadv_priv *bat_priv,
unsigned int tvlv_len;
unsigned long offset;
bool xmitted = false;
- u8 *dest, *next_dest;
+ u8 *next_dest;
u16 num_dests;
+ u8 *dest;
int ret;
/* (at least) TVLV part needs to be linearized */
@@ -1080,6 +1080,11 @@ unsigned int batadv_mcast_forw_packet_hdrlen(unsigned int num_dests)
* Tries to expand an skb's headroom so that its head to tail is 1298
* bytes (minimum IPv6 MTU + vlan ethernet header size) large.
*
+ * Warning: This function may reallocate the skb data buffer via
+ * skb_cow() / skb_linearize(). Any pointer into the skb data (e.g.
+ * obtained from skb->data or eth_hdr()) before this call must be
+ * considered invalid afterwards and has to be reacquired.
+ *
* Return: -EINVAL if the given skb's length is too large or -ENOMEM on memory
* allocation failure. Otherwise, on success, zero is returned.
*/
@@ -1100,8 +1105,11 @@ static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv,
return -EINVAL;
}
- if (skb_headroom(skb) < hdr_size &&
- pskb_expand_head(skb, hdr_size, 0, GFP_ATOMIC) < 0)
+ if (skb_cow(skb, hdr_size) < 0)
+ return -ENOMEM;
+
+ /* batadv_mcast_forw_scrape() + batadv_mcast_forw_packet() require linearized skb */
+ if (skb_linearize(skb) < 0)
return -ENOMEM;
return 0;
@@ -1120,6 +1128,11 @@ static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv,
* that signaled interest in it, that is either via the translation table or the
* according want-all flags, is attached accordingly.
*
+ * Warning: This function may reallocate the skb data buffer via
+ * batadv_mcast_forw_expand_head(). Any pointer into the skb data (e.g.
+ * obtained from skb->data or eth_hdr()) before this call must be
+ * considered invalid afterwards and has to be reacquired.
+ *
* Return: true on success, false otherwise.
*/
bool batadv_mcast_forw_push(struct batadv_priv *bat_priv, struct sk_buff *skb,
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index d2bc48c707143..926210a67d640 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -52,9 +52,15 @@
struct genl_family batadv_netlink_family;
-/* multicast groups */
+/**
+ * enum batadv_netlink_multicast_groups - batman-adv generic netlink multicast
+ * groups
+ */
enum batadv_netlink_multicast_groups {
+ /** @BATADV_NL_MCGRP_CONFIG: configuration change notifications */
BATADV_NL_MCGRP_CONFIG,
+
+ /** @BATADV_NL_MCGRP_TPMETER: throughput meter result notifications */
BATADV_NL_MCGRP_TPMETER,
};
@@ -746,8 +752,8 @@ static int
batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info)
{
struct batadv_priv *bat_priv = info->user_ptr[0];
- u8 *dst;
int ret = 0;
+ u8 *dst;
if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
return -EINVAL;
@@ -953,10 +959,10 @@ static int batadv_netlink_set_hardif(struct sk_buff *skb,
static int
batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb)
{
- struct net_device *mesh_iface;
+ int portid = NETLINK_CB(cb->skb).portid;
struct batadv_hard_iface *hard_iface;
+ struct net_device *mesh_iface;
struct batadv_priv *bat_priv;
- int portid = NETLINK_CB(cb->skb).portid;
int skip = cb->args[0];
struct list_head *iter;
int i = 0;
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 48f837cf665a2..f06583ef9b3f5 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -53,8 +53,9 @@ struct batadv_orig_node *
batadv_orig_hash_find(struct batadv_priv *bat_priv, const void *data)
{
struct batadv_hashtable *hash = bat_priv->orig_hash;
+ struct batadv_orig_node *orig_node_tmp = NULL;
+ struct batadv_orig_node *orig_node;
struct hlist_head *head;
- struct batadv_orig_node *orig_node, *orig_node_tmp = NULL;
int index;
if (!hash)
@@ -108,7 +109,8 @@ struct batadv_orig_node_vlan *
batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
unsigned short vid)
{
- struct batadv_orig_node_vlan *vlan = NULL, *tmp;
+ struct batadv_orig_node_vlan *vlan = NULL;
+ struct batadv_orig_node_vlan *tmp;
rcu_read_lock();
hlist_for_each_entry_rcu(tmp, &orig_node->vlan_list, list) {
@@ -282,9 +284,9 @@ void batadv_hardif_neigh_release(struct kref *ref)
*/
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_neigh_node *neigh_node;
+ struct hlist_node *node_tmp;
neigh_node = container_of(ref, struct batadv_neigh_node, refcount);
@@ -314,8 +316,8 @@ struct batadv_neigh_node *
batadv_orig_router_get(struct batadv_orig_node *orig_node,
const struct batadv_hard_iface *if_outgoing)
{
- struct batadv_orig_ifinfo *orig_ifinfo;
struct batadv_neigh_node *router = NULL;
+ struct batadv_orig_ifinfo *orig_ifinfo;
rcu_read_lock();
hlist_for_each_entry_rcu(orig_ifinfo, &orig_node->ifinfo_list, list) {
@@ -373,7 +375,8 @@ struct batadv_orig_ifinfo *
batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node,
struct batadv_hard_iface *if_outgoing)
{
- struct batadv_orig_ifinfo *tmp, *orig_ifinfo = NULL;
+ struct batadv_orig_ifinfo *orig_ifinfo = NULL;
+ struct batadv_orig_ifinfo *tmp;
rcu_read_lock();
hlist_for_each_entry_rcu(tmp, &orig_node->ifinfo_list,
@@ -451,8 +454,8 @@ struct batadv_neigh_ifinfo *
batadv_neigh_ifinfo_get(struct batadv_neigh_node *neigh,
struct batadv_hard_iface *if_outgoing)
{
- struct batadv_neigh_ifinfo *neigh_ifinfo = NULL,
- *tmp_neigh_ifinfo;
+ struct batadv_neigh_ifinfo *neigh_ifinfo = NULL;
+ struct batadv_neigh_ifinfo *tmp_neigh_ifinfo;
rcu_read_lock();
hlist_for_each_entry_rcu(tmp_neigh_ifinfo, &neigh->ifinfo_list,
@@ -530,7 +533,8 @@ batadv_neigh_node_get(const struct batadv_orig_node *orig_node,
const struct batadv_hard_iface *hard_iface,
const u8 *addr)
{
- struct batadv_neigh_node *tmp_neigh_node, *res = NULL;
+ struct batadv_neigh_node *tmp_neigh_node;
+ struct batadv_neigh_node *res = NULL;
rcu_read_lock();
hlist_for_each_entry_rcu(tmp_neigh_node, &orig_node->neigh_list, list) {
@@ -634,7 +638,8 @@ struct batadv_hardif_neigh_node *
batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface,
const u8 *neigh_addr)
{
- struct batadv_hardif_neigh_node *tmp_hardif_neigh, *hardif_neigh = NULL;
+ struct batadv_hardif_neigh_node *hardif_neigh = NULL;
+ struct batadv_hardif_neigh_node *tmp_hardif_neigh;
rcu_read_lock();
hlist_for_each_entry_rcu(tmp_hardif_neigh,
@@ -668,8 +673,8 @@ 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;
+ struct batadv_neigh_node *neigh_node;
spin_lock_bh(&orig_node->neigh_list_lock);
@@ -753,7 +758,8 @@ batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,
*/
int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
- struct batadv_hard_iface *primary_if, *hard_iface;
+ struct batadv_hard_iface *primary_if;
+ struct batadv_hard_iface *hard_iface;
struct net_device *mesh_iface;
struct batadv_priv *bat_priv;
int ret;
@@ -850,12 +856,12 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
*/
void batadv_orig_node_release(struct kref *ref)
{
- struct hlist_node *node_tmp;
+ struct batadv_orig_ifinfo *last_candidate;
+ struct batadv_orig_ifinfo *orig_ifinfo;
struct batadv_neigh_node *neigh_node;
struct batadv_orig_node *orig_node;
- struct batadv_orig_ifinfo *orig_ifinfo;
struct batadv_orig_node_vlan *vlan;
- struct batadv_orig_ifinfo *last_candidate;
+ struct hlist_node *node_tmp;
orig_node = container_of(ref, struct batadv_orig_node, refcount);
@@ -898,11 +904,11 @@ void batadv_orig_node_release(struct kref *ref)
*/
void batadv_originator_free(struct batadv_priv *bat_priv)
{
+ spinlock_t *list_lock; /* spinlock to protect write access */
struct batadv_hashtable *hash = bat_priv->orig_hash;
+ struct batadv_orig_node *orig_node;
struct hlist_node *node_tmp;
struct hlist_head *head;
- spinlock_t *list_lock; /* spinlock to protect write access */
- struct batadv_orig_node *orig_node;
u32 i;
if (!hash)
@@ -1109,11 +1115,11 @@ static bool
batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node)
{
- struct hlist_node *node_tmp;
+ struct batadv_hard_iface *if_incoming;
struct batadv_neigh_node *neigh_node;
+ struct hlist_node *node_tmp;
bool neigh_purged = false;
unsigned long last_seen;
- struct batadv_hard_iface *if_incoming;
spin_lock_bh(&orig_node->neigh_list_lock);
@@ -1167,8 +1173,9 @@ batadv_find_best_neighbor(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_hard_iface *if_outgoing)
{
- struct batadv_neigh_node *best = NULL, *neigh;
struct batadv_algo_ops *bao = bat_priv->algo_ops;
+ struct batadv_neigh_node *best = NULL;
+ struct batadv_neigh_node *neigh;
rcu_read_lock();
hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) {
@@ -1203,8 +1210,9 @@ static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
{
struct batadv_neigh_node *best_neigh_node;
struct batadv_hard_iface *hard_iface;
- bool changed_ifinfo, changed_neigh;
struct list_head *iter;
+ bool changed_ifinfo;
+ bool changed_neigh;
if (batadv_has_timed_out(orig_node->last_seen,
2 * BATADV_PURGE_TIMEOUT)) {
@@ -1256,11 +1264,11 @@ static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
*/
void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
{
+ spinlock_t *list_lock; /* spinlock to protect write access */
struct batadv_hashtable *hash = bat_priv->orig_hash;
+ struct batadv_orig_node *orig_node;
struct hlist_node *node_tmp;
struct hlist_head *head;
- spinlock_t *list_lock; /* spinlock to protect write access */
- struct batadv_orig_node *orig_node;
u32 i;
if (!hash)
@@ -1295,6 +1303,13 @@ void batadv_purge_orig_ref(struct batadv_priv *bat_priv)
batadv_gw_election(bat_priv);
}
+/**
+ * batadv_purge_orig() - periodic worker to purge stale originator entries
+ * @work: delayed work embedded in the bat_priv
+ *
+ * Invoke batadv_purge_orig_ref() to drop stale originators and reschedule the
+ * next run after BATADV_ORIG_WORK_PERIOD milliseconds.
+ */
static void batadv_purge_orig(struct work_struct *work)
{
struct delayed_work *delayed_work;
@@ -1318,7 +1333,8 @@ static void batadv_purge_orig(struct work_struct *work)
*/
int batadv_orig_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
- struct batadv_hard_iface *primary_if, *hard_iface;
+ struct batadv_hard_iface *primary_if;
+ struct batadv_hard_iface *hard_iface;
struct net_device *mesh_iface;
struct batadv_priv *bat_priv;
int ret;
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index bbd40fe3a8e59..15ef47d30406e 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -172,6 +172,11 @@ bool batadv_window_protected(struct batadv_priv *bat_priv, s32 seq_num_diff,
* @hard_iface: incoming hard interface
* @header_len: minimal header length of packet type
*
+ * Warning: This function may reallocate the skb data buffer via
+ * skb_cow() / skb_linearize(). Any pointer into the skb data (e.g.
+ * obtained from skb->data or eth_hdr()) before this call must be
+ * considered invalid afterwards and has to be reacquired.
+ *
* Return: true when management preconditions are met, false otherwise
*/
bool batadv_check_management_packet(struct sk_buff *skb,
@@ -263,8 +268,7 @@ static bool batadv_skb_decrement_ttl(struct sk_buff *skb)
* @bat_priv: the bat priv with all the mesh interface information
* @skb: icmp packet to process
*
- * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
- * otherwise.
+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
*/
static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
struct sk_buff *skb)
@@ -272,7 +276,8 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if = NULL;
struct batadv_orig_node *orig_node = NULL;
struct batadv_icmp_header *icmph;
- int res, ret = NET_RX_DROP;
+ int ret = NET_RX_DROP;
+ int res;
icmph = (struct batadv_icmp_header *)skb->data;
@@ -328,13 +333,24 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
return ret;
}
+/**
+ * batadv_recv_icmp_ttl_exceeded() - handle an ICMP packet that hit TTL 0
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @skb: ICMP packet whose TTL has expired
+ *
+ * For traceroute-style ICMP echo requests, send a TTL exceeded reply back to
+ * the source. Other ICMP types are simply dropped.
+ *
+ * Return: NET_XMIT_SUCCESS if the reply was queued, NET_RX_DROP otherwise
+ */
static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
struct sk_buff *skb)
{
struct batadv_hard_iface *primary_if = NULL;
struct batadv_orig_node *orig_node = NULL;
struct batadv_icmp_packet *icmp_packet;
- int res, ret = NET_RX_DROP;
+ int ret = NET_RX_DROP;
+ int res;
icmp_packet = (struct batadv_icmp_packet *)skb->data;
@@ -392,12 +408,13 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
- struct batadv_icmp_header *icmph;
+ int hdr_size = sizeof(struct batadv_icmp_header);
struct batadv_icmp_packet_rr *icmp_packet_rr;
- struct ethhdr *ethhdr;
struct batadv_orig_node *orig_node = NULL;
- int hdr_size = sizeof(struct batadv_icmp_header);
- int res, ret = NET_RX_DROP;
+ struct batadv_icmp_header *icmph;
+ struct ethhdr *ethhdr;
+ int ret = NET_RX_DROP;
+ int res;
/* drop packet if it has not necessary minimum size */
if (unlikely(!pskb_may_pull(skb, hdr_size)))
@@ -576,15 +593,17 @@ batadv_find_router(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_hard_iface *recv_if)
{
- struct batadv_algo_ops *bao = bat_priv->algo_ops;
struct batadv_neigh_node *first_candidate_router = NULL;
struct batadv_neigh_node *next_candidate_router = NULL;
- struct batadv_neigh_node *router, *cand_router = NULL;
struct batadv_neigh_node *last_cand_router = NULL;
- struct batadv_orig_ifinfo *cand, *first_candidate = NULL;
+ struct batadv_orig_ifinfo *first_candidate = NULL;
+ struct batadv_algo_ops *bao = bat_priv->algo_ops;
struct batadv_orig_ifinfo *next_candidate = NULL;
+ struct batadv_neigh_node *cand_router = NULL;
struct batadv_orig_ifinfo *last_candidate;
bool last_candidate_found = false;
+ struct batadv_neigh_node *router;
+ struct batadv_orig_ifinfo *cand;
if (!orig_node)
return NULL;
@@ -706,15 +725,29 @@ batadv_find_router(struct batadv_priv *bat_priv,
return router;
}
+/**
+ * batadv_route_unicast_packet() - forward a unicast packet towards its
+ * destination originator
+ * @skb: the received unicast packet
+ * @recv_if: interface on which the packet was received
+ *
+ * Decrement the TTL, look up the originator for the destination address and
+ * hand the packet over to batadv_send_skb_to_orig() for transmission. Drop
+ * the packet when the TTL is exhausted or no route exists.
+ *
+ * Return: NET_RX_SUCCESS if the packet was forwarded, NET_RX_DROP otherwise
+ */
static int batadv_route_unicast_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
- struct batadv_orig_node *orig_node = NULL;
struct batadv_unicast_packet *unicast_packet;
+ struct batadv_orig_node *orig_node = NULL;
struct ethhdr *ethhdr = eth_hdr(skb);
- int res, hdr_len, ret = NET_RX_DROP;
+ int ret = NET_RX_DROP;
unsigned int len;
+ int hdr_len;
+ int res;
unicast_packet = (struct batadv_unicast_packet *)skb->data;
@@ -797,10 +830,10 @@ batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,
struct batadv_unicast_packet *unicast_packet,
u8 *dst_addr, unsigned short vid)
{
- struct batadv_orig_node *orig_node = NULL;
struct batadv_hard_iface *primary_if = NULL;
- bool ret = false;
+ struct batadv_orig_node *orig_node = NULL;
const u8 *orig_addr;
+ bool ret = false;
u8 orig_ttvn;
if (batadv_is_my_client(bat_priv, dst_addr, vid)) {
@@ -836,16 +869,31 @@ batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,
return ret;
}
+/**
+ * batadv_check_unicast_ttvn() - check and adjust the TTVN of a unicast packet
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @skb: the unicast packet to check
+ * @hdr_len: length of the unicast header preceding the payload
+ *
+ * Warning: This function may reallocate the skb data buffer via
+ * pskb_may_pull() and batadv_get_vid(). Any pointer into the skb data (e.g.
+ * obtained from skb->data or eth_hdr()) before this call must be considered
+ * invalid afterwards and has to be reacquired.
+ *
+ * Return: true if the packet may be processed further, false if it has been
+ * consumed or has to be dropped by the caller
+ */
static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
struct sk_buff *skb, int hdr_len)
{
struct batadv_unicast_packet *unicast_packet;
struct batadv_hard_iface *primary_if;
struct batadv_orig_node *orig_node;
- u8 curr_ttvn, old_ttvn;
struct ethhdr *ethhdr;
unsigned short vid;
int is_old_ttvn;
+ u8 curr_ttvn;
+ u8 old_ttvn;
/* check if there is enough data before accessing it */
if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
@@ -955,15 +1003,15 @@ static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
* @skb: unicast tvlv packet to process
* @recv_if: pointer to interface this packet was received on
*
- * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
- * otherwise.
+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
*/
int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
- struct batadv_unicast_packet *unicast_packet;
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
- int check, hdr_size = sizeof(*unicast_packet);
+ struct batadv_unicast_packet *unicast_packet;
+ int hdr_size = sizeof(*unicast_packet);
+ int check;
check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
if (check < 0)
@@ -992,14 +1040,18 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
- struct batadv_unicast_packet *unicast_packet;
struct batadv_unicast_4addr_packet *unicast_4addr_packet;
- u8 *orig_addr, *orig_addr_gw;
- struct batadv_orig_node *orig_node = NULL, *orig_node_gw = NULL;
- int check, hdr_size = sizeof(*unicast_packet);
+ struct batadv_unicast_packet *unicast_packet;
+ struct batadv_orig_node *orig_node_gw = NULL;
+ struct batadv_orig_node *orig_node = NULL;
+ int hdr_size = sizeof(*unicast_packet);
enum batadv_subtype subtype;
int ret = NET_RX_DROP;
- bool is4addr, is_gw;
+ u8 *orig_addr_gw;
+ u8 *orig_addr;
+ bool is4addr;
+ bool is_gw;
+ int check;
unicast_packet = (struct batadv_unicast_packet *)skb->data;
is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR;
@@ -1089,18 +1141,17 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
* @skb: unicast tvlv packet to process
* @recv_if: pointer to interface this packet was received on
*
- * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
- * otherwise.
+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
*/
int batadv_recv_unicast_tvlv(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
- unsigned char *tvlv_buff;
- u16 tvlv_buff_len;
int hdr_size = sizeof(*unicast_tvlv_packet);
+ unsigned char *tvlv_buff;
int ret = NET_RX_DROP;
+ u16 tvlv_buff_len;
if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
goto free_skb;
@@ -1146,7 +1197,7 @@ int batadv_recv_unicast_tvlv(struct sk_buff *skb,
* the assembled packet will exceed our MTU; 2) Buffer fragment, if we still
* lack further fragments; 3) Merge fragments, if we have all needed parts.
*
- * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.
+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
*/
int batadv_recv_frag_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
@@ -1215,8 +1266,8 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
struct batadv_orig_node *orig_node = NULL;
struct batadv_bcast_packet *bcast_packet;
- struct ethhdr *ethhdr;
int hdr_size = sizeof(*bcast_packet);
+ struct ethhdr *ethhdr;
s32 seq_diff;
u32 seqno;
int ret;
@@ -1334,7 +1385,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
* contents of its TVLV forwards it and/or decapsulates it to hand it to the
* mesh interface.
*
- * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.
+ * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
*/
int batadv_recv_mcast_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 7f449338a4909..2122560c90e51 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -271,8 +271,8 @@ bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig,
int packet_subtype)
{
- struct batadv_hard_iface *primary_if;
struct batadv_unicast_4addr_packet *uc_4addr_packet;
+ struct batadv_hard_iface *primary_if;
bool ret = false;
primary_if = batadv_primary_if_get_selected(bat_priv);
@@ -322,8 +322,8 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
unsigned short vid)
{
struct batadv_unicast_packet *unicast_packet;
- struct ethhdr *ethhdr;
int ret = NET_XMIT_DROP;
+ struct ethhdr *ethhdr;
if (!orig_node)
goto out;
@@ -394,7 +394,8 @@ int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
{
struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
struct batadv_orig_node *orig_node;
- u8 *src, *dst;
+ u8 *src;
+ u8 *dst;
int ret;
src = ethhdr->h_source;
diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c
index 00467aa79de9d..022eb13e8ec47 100644
--- a/net/batman-adv/tp_meter.c
+++ b/net/batman-adv/tp_meter.c
@@ -221,9 +221,9 @@ static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason,
unsigned long start_time, u64 total_sent,
u32 cookie)
{
+ u32 total_bytes;
u32 test_time;
u8 result;
- u32 total_bytes;
if (!batadv_tp_is_error(reason)) {
result = BATADV_TP_REASON_COMPLETE;
@@ -267,7 +267,8 @@ static void batadv_tp_batctl_error_notify(enum batadv_tp_meter_reason reason,
static struct batadv_tp_sender *
batadv_tp_list_find_sender(struct batadv_priv *bat_priv, const u8 *dst)
{
- struct batadv_tp_sender *pos, *tp_vars = NULL;
+ struct batadv_tp_sender *tp_vars = NULL;
+ struct batadv_tp_sender *pos;
rcu_read_lock();
hlist_for_each_entry_rcu(pos, &bat_priv->tp_sender_list, common.list) {
@@ -332,7 +333,8 @@ static struct batadv_tp_sender *
batadv_tp_list_find_sender_session(struct batadv_priv *bat_priv, const u8 *dst,
const u8 *session)
{
- struct batadv_tp_sender *pos, *tp_vars = NULL;
+ struct batadv_tp_sender *tp_vars = NULL;
+ struct batadv_tp_sender *pos;
rcu_read_lock();
hlist_for_each_entry_rcu(pos, &bat_priv->tp_sender_list, common.list) {
@@ -578,8 +580,8 @@ static void batadv_tp_sender_timeout(struct timer_list *t)
static void batadv_tp_fill_prerandom(struct batadv_tp_sender *tp_vars,
u8 *buf, size_t nbytes)
{
- u32 local_offset;
size_t bytes_inbuf;
+ u32 local_offset;
size_t to_copy;
size_t pos = 0;
@@ -625,9 +627,9 @@ static int batadv_tp_send_msg(struct batadv_tp_sender *tp_vars, const u8 *src,
{
struct batadv_icmp_tp_packet *icmp;
struct sk_buff *skb;
- int r;
- u8 *data;
size_t data_len;
+ u8 *data;
+ int r;
skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
if (unlikely(!skb))
@@ -864,7 +866,8 @@ static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,
static bool batadv_tp_avail(struct batadv_tp_sender *tp_vars,
size_t payload_len)
{
- u32 win_left, win_limit;
+ u32 win_limit;
+ u32 win_left;
spin_lock_bh(&tp_vars->cc_lock);
@@ -910,14 +913,16 @@ static int batadv_tp_wait_available(struct batadv_tp_sender *tp_vars, size_t ple
*/
static int batadv_tp_send(void *arg)
{
- struct batadv_tp_sender *tp_vars = arg;
- struct batadv_priv *bat_priv = tp_vars->common.bat_priv;
struct batadv_hard_iface *primary_if = NULL;
struct batadv_orig_node *orig_node = NULL;
- size_t payload_len, packet_len;
+ struct batadv_tp_sender *tp_vars = arg;
+ struct batadv_priv *bat_priv;
+ size_t payload_len;
+ size_t packet_len;
u32 last_sent;
int err = 0;
+ bat_priv = tp_vars->common.bat_priv;
orig_node = batadv_orig_hash_find(bat_priv, tp_vars->common.other_end);
if (unlikely(!orig_node)) {
err = BATADV_TP_REASON_DST_UNREACHABLE;
@@ -1005,8 +1010,8 @@ static int batadv_tp_send(void *arg)
*/
static void batadv_tp_start_kthread(struct batadv_tp_sender *tp_vars)
{
- struct task_struct *kthread;
struct batadv_priv *bat_priv = tp_vars->common.bat_priv;
+ struct task_struct *kthread;
u32 session_cookie;
kref_get(&tp_vars->common.refcount);
@@ -1042,9 +1047,9 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
u32 test_length, u32 *cookie)
{
struct batadv_tp_sender *tp_vars;
+ u32 session_cookie;
u8 session_id[2];
u8 icmp_uid;
- u32 session_cookie;
get_random_bytes(session_id, sizeof(session_id));
get_random_bytes(&icmp_uid, 1);
@@ -1211,7 +1216,8 @@ static struct batadv_tp_receiver *
batadv_tp_list_find_receiver_session(struct batadv_priv *bat_priv, const u8 *dst,
const u8 *session)
{
- struct batadv_tp_receiver *pos, *tp_vars = NULL;
+ struct batadv_tp_receiver *tp_vars = NULL;
+ struct batadv_tp_receiver *pos;
rcu_read_lock();
hlist_for_each_entry_rcu(pos, &bat_priv->tp_receiver_list, common.list) {
@@ -1296,7 +1302,8 @@ static void batadv_tp_reset_receiver_timer(struct batadv_tp_receiver *tp_vars)
static void batadv_tp_receiver_shutdown(struct timer_list *t)
{
struct batadv_tp_receiver *tp_vars = timer_container_of(tp_vars, t, common.timer);
- struct batadv_tp_unacked *un, *safe;
+ struct batadv_tp_unacked *safe;
+ struct batadv_tp_unacked *un;
struct batadv_priv *bat_priv;
bat_priv = tp_vars->common.bat_priv;
@@ -1351,7 +1358,8 @@ static int batadv_tp_send_ack(struct batadv_priv *bat_priv, const u8 *dst,
struct batadv_orig_node *orig_node;
struct batadv_icmp_tp_packet *icmp;
struct sk_buff *skb;
- int r, ret;
+ int ret;
+ int r;
orig_node = batadv_orig_hash_find(bat_priv, dst);
if (unlikely(!orig_node)) {
@@ -1528,7 +1536,8 @@ static bool batadv_tp_handle_out_of_order(struct batadv_tp_receiver *tp_vars,
static void batadv_tp_ack_unordered(struct batadv_tp_receiver *tp_vars)
__must_hold(&tp_vars->ack_seqno_lock)
{
- struct batadv_tp_unacked *un, *safe;
+ struct batadv_tp_unacked *safe;
+ struct batadv_tp_unacked *un;
u32 to_ack;
/* go through the unacked packet list and possibly ACK them as
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index dae5e1d8c0385..5e10e6bb7bd6a 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -128,8 +128,10 @@ static struct batadv_tt_common_entry *
batadv_tt_hash_find(struct batadv_hashtable *hash, const u8 *addr,
unsigned short vid)
{
+ struct batadv_tt_common_entry *tt_tmp = NULL;
+ struct batadv_tt_common_entry to_search;
+ struct batadv_tt_common_entry *tt;
struct hlist_head *head;
- struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
u32 index;
if (!hash)
@@ -173,8 +175,8 @@ static struct batadv_tt_local_entry *
batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
unsigned short vid)
{
- struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tt_local_entry *tt_local_entry = NULL;
+ struct batadv_tt_common_entry *tt_common_entry;
tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
vid);
@@ -198,8 +200,8 @@ struct batadv_tt_global_entry *
batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
unsigned short vid)
{
- struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tt_global_entry *tt_global_entry = NULL;
+ struct batadv_tt_common_entry *tt_common_entry;
tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr,
vid);
@@ -421,10 +423,13 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local_entry,
u8 event_flags)
{
- struct batadv_tt_change_node *tt_change_node, *entry, *safe;
struct batadv_tt_common_entry *common = &tt_local_entry->common;
- u8 flags = common->flags | event_flags;
- bool del_op_requested, del_op_entry;
+ u8 flags = atomic_read(&common->flags) | event_flags;
+ struct batadv_tt_change_node *tt_change_node;
+ struct batadv_tt_change_node *entry;
+ struct batadv_tt_change_node *safe;
+ bool del_op_requested;
+ bool del_op_entry;
size_t changes;
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
@@ -514,9 +519,9 @@ static u16 batadv_tt_entries(u16 tt_len)
*/
static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)
{
- u16 num_vlan = 0;
- u16 tt_local_entries = 0;
struct batadv_meshif_vlan *vlan;
+ u16 tt_local_entries = 0;
+ u16 num_vlan = 0;
int hdr_size;
rcu_read_lock();
@@ -535,6 +540,12 @@ static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv)
return hdr_size + batadv_tt_len(tt_local_entries);
}
+/**
+ * batadv_tt_local_init() - allocate and initialise the local translation table
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Return: 0 on success or -ENOMEM in case of allocation failure
+ */
static int batadv_tt_local_init(struct batadv_priv *bat_priv)
{
if (bat_priv->tt.local_hash)
@@ -551,6 +562,15 @@ static int batadv_tt_local_init(struct batadv_priv *bat_priv)
return 0;
}
+/**
+ * batadv_tt_global_free() - drop a global translation table entry
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_global: the global TT entry to remove
+ * @message: debug message explaining why the entry is being removed
+ *
+ * Remove @tt_global from the global TT hash and drop the reference held by
+ * the hash.
+ */
static void batadv_tt_global_free(struct batadv_priv *bat_priv,
struct batadv_tt_global_entry *tt_global,
const char *message)
@@ -594,19 +614,26 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
unsigned short vid, int ifindex, u32 mark)
{
struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
- struct batadv_tt_local_entry *tt_local;
struct batadv_tt_global_entry *tt_global = NULL;
+ struct batadv_tt_orig_list_entry *orig_entry;
+ struct batadv_tt_local_entry *tt_local;
struct net *net = dev_net(mesh_iface);
- struct batadv_meshif_vlan *vlan;
struct net_device *in_dev = NULL;
- struct hlist_head *head;
- struct batadv_tt_orig_list_entry *orig_entry;
- int hash_added, table_size, packet_size_max;
- bool ret = false;
+ struct batadv_meshif_vlan *vlan;
bool roamed_back = false;
bool iif_is_wifi = false;
+ struct hlist_head *head;
+ int packet_size_max;
+ u8 new_remote_flags;
+ bool ret = false;
u8 remote_flags;
+ int hash_added;
+ int table_size;
u32 match_mark;
+ u8 clear_flags;
+ u16 old_flags;
+ u8 set_flags;
+ u16 flags;
if (ifindex != BATADV_NULL_IFINDEX)
in_dev = dev_get_by_index(net, ifindex);
@@ -624,7 +651,9 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
if (tt_local) {
tt_local->last_seen = jiffies;
- if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
+
+ flags = atomic_read(&tt_local->common.flags);
+ if (flags & BATADV_TT_CLIENT_PENDING) {
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Re-adding pending client %pM (vid: %d)\n",
addr, batadv_print_vid(vid));
@@ -633,11 +662,11 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
* this orig_interval. Since it popped up again, the
* flag can be reset like it was never enqueued
*/
- tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
+ atomic_andnot(BATADV_TT_CLIENT_PENDING, &tt_local->common.flags);
goto add_event;
}
- if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
+ if (flags & BATADV_TT_CLIENT_ROAM) {
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Roaming client %pM (vid: %d) came back to its original location\n",
addr, batadv_print_vid(vid));
@@ -646,7 +675,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
* that the client popped up again at its original
* location such flag can be unset
*/
- tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
+ atomic_andnot(BATADV_TT_CLIENT_ROAM, &tt_local->common.flags);
roamed_back = true;
}
goto check_roaming;
@@ -683,26 +712,29 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
addr, batadv_print_vid(vid),
(u8)atomic_read(&bat_priv->tt.vn));
+ tt_local->common.vid = vid;
+ kref_init(&tt_local->common.refcount);
+ tt_local->last_seen = jiffies;
+ tt_local->common.added_at = tt_local->last_seen;
+ tt_local->vlan = vlan;
+
ether_addr_copy(tt_local->common.addr, addr);
/* The local entry has to be marked as NEW to avoid to send it in
* a full table response going out before the next ttvn increment
* (consistency check)
*/
- tt_local->common.flags = BATADV_TT_CLIENT_NEW;
- tt_local->common.vid = vid;
+ flags = BATADV_TT_CLIENT_NEW;
if (iif_is_wifi)
- tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
- kref_init(&tt_local->common.refcount);
- tt_local->last_seen = jiffies;
- tt_local->common.added_at = tt_local->last_seen;
- tt_local->vlan = vlan;
+ flags |= BATADV_TT_CLIENT_WIFI;
/* the batman interface mac and multicast addresses should never be
* purged
*/
if (batadv_compare_eth(addr, mesh_iface->dev_addr) ||
is_multicast_ether_addr(addr))
- tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
+ flags |= BATADV_TT_CLIENT_NOPURGE;
+
+ atomic_set(&tt_local->common.flags, flags);
kref_get(&tt_local->common.refcount);
hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
@@ -720,9 +752,17 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
check_roaming:
/* Check whether it is a roaming, but don't do anything if the roaming
- * process has already been handled
+ * process has already been handled. The ROAM flag is claimed via an
+ * atomic test-and-set to make sure that only a single context handles
+ * the advertisement for a client
*/
- if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
+ old_flags = BATADV_TT_CLIENT_ROAM;
+ if (tt_global &&
+ !(atomic_read(&tt_global->common.flags) & BATADV_TT_CLIENT_ROAM))
+ old_flags = atomic_fetch_or(BATADV_TT_CLIENT_ROAM,
+ &tt_global->common.flags);
+
+ if (tt_global && !(old_flags & BATADV_TT_CLIENT_ROAM)) {
/* These node are probably going to update their tt table */
head = &tt_global->orig_list;
rcu_read_lock();
@@ -732,27 +772,30 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
orig_entry->orig_node);
}
rcu_read_unlock();
- if (roamed_back) {
- batadv_tt_global_free(bat_priv, tt_global,
- "Roaming canceled");
- } else {
- /* The global entry has to be marked as ROAMING and
+
+ if (!roamed_back) {
+ /* The global entry was marked as ROAMING and
* has to be kept for consistency purpose
*/
- tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
tt_global->roam_at = jiffies;
}
}
+ /* clean up independent of the roaming advertisement handler */
+ if (tt_global && roamed_back)
+ batadv_tt_global_free(bat_priv, tt_global, "Roaming canceled");
+
/* store the current remote flags before altering them. This helps
* understanding is flags are changing or not
*/
- remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK;
+ remote_flags = atomic_read(&tt_local->common.flags) & BATADV_TT_REMOTE_MASK;
+
+ new_remote_flags = remote_flags;
if (iif_is_wifi)
- tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
+ new_remote_flags |= BATADV_TT_CLIENT_WIFI;
else
- tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI;
+ new_remote_flags &= ~BATADV_TT_CLIENT_WIFI;
/* check the mark in the skb: if it's equal to the configured
* isolation_mark, it means the packet is coming from an isolated
@@ -761,14 +804,22 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
match_mark = (mark & bat_priv->isolation_mark_mask);
if (bat_priv->isolation_mark_mask &&
match_mark == bat_priv->isolation_mark)
- tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA;
+ new_remote_flags |= BATADV_TT_CLIENT_ISOLA;
else
- tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA;
+ new_remote_flags &= ~BATADV_TT_CLIENT_ISOLA;
+
+ set_flags = new_remote_flags & ~remote_flags;
+ if (set_flags)
+ atomic_or(set_flags, &tt_local->common.flags);
+
+ clear_flags = remote_flags & ~new_remote_flags;
+ if (clear_flags)
+ atomic_andnot(clear_flags, &tt_local->common.flags);
/* if any "dynamic" flag has been modified, resend an ADD event for this
* entry so that all the nodes can get the new flags
*/
- if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK))
+ if (set_flags || clear_flags)
batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
ret = true;
@@ -987,14 +1038,16 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv,
*/
static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
{
- struct batadv_tt_change_node *entry, *safe;
- struct batadv_tvlv_tt_data *tt_data;
struct batadv_tvlv_tt_change *tt_change;
- int tt_diff_len, tt_change_len = 0;
- int tt_diff_entries_num = 0;
+ struct batadv_tt_change_node *entry;
+ struct batadv_tvlv_tt_data *tt_data;
+ struct batadv_tt_change_node *safe;
int tt_diff_entries_count = 0;
+ int tt_diff_entries_num = 0;
bool drop_changes = false;
size_t tt_extra_len = 0;
+ int tt_change_len = 0;
+ int tt_diff_len;
u16 tvlv_len;
tt_diff_entries_num = READ_ONCE(bat_priv->tt.local_changes);
@@ -1087,14 +1140,16 @@ batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid,
struct batadv_priv *bat_priv,
struct batadv_tt_common_entry *common)
{
- void *hdr;
- struct batadv_meshif_vlan *vlan;
struct batadv_tt_local_entry *local;
+ struct batadv_meshif_vlan *vlan;
unsigned int last_seen_msecs;
+ void *hdr;
+ u16 flags;
u32 crc;
local = container_of(common, struct batadv_tt_local_entry, common);
last_seen_msecs = jiffies_to_msecs(jiffies - local->last_seen);
+ flags = atomic_read(&common->flags);
vlan = batadv_meshif_vlan_get(bat_priv, common->vid);
if (!vlan)
@@ -1115,10 +1170,10 @@ batadv_tt_local_dump_entry(struct sk_buff *msg, u32 portid,
if (nla_put(msg, BATADV_ATTR_TT_ADDRESS, ETH_ALEN, common->addr) ||
nla_put_u32(msg, BATADV_ATTR_TT_CRC32, crc) ||
nla_put_u16(msg, BATADV_ATTR_TT_VID, common->vid) ||
- nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, common->flags))
+ nla_put_u32(msg, BATADV_ATTR_TT_FLAGS, flags))
goto nla_put_failure;
- if (!(common->flags & BATADV_TT_CLIENT_NOPURGE) &&
+ if (!(flags & BATADV_TT_CLIENT_NOPURGE) &&
nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, last_seen_msecs))
goto nla_put_failure;
@@ -1181,14 +1236,14 @@ batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid,
*/
int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
- struct net_device *mesh_iface;
- struct batadv_priv *bat_priv;
struct batadv_hard_iface *primary_if = NULL;
+ int portid = NETLINK_CB(cb->skb).portid;
+ struct net_device *mesh_iface;
struct batadv_hashtable *hash;
- int ret;
+ struct batadv_priv *bat_priv;
int bucket = cb->args[0];
int idx = cb->args[1];
- int portid = NETLINK_CB(cb->skb).portid;
+ int ret;
mesh_iface = batadv_netlink_get_meshif(cb);
if (IS_ERR(mesh_iface))
@@ -1224,6 +1279,17 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)
return ret;
}
+/**
+ * batadv_tt_local_set_pending() - mark a local TT entry as pending removal
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_local_entry: local TT entry to mark
+ * @flags: TT change flags to announce together with the pending removal
+ * @message: debug message describing the reason for the change
+ *
+ * Schedule the TT change announcement and set BATADV_TT_CLIENT_PENDING on the
+ * entry. The entry is kept in the local table until the next TTVN increment
+ * so that a consistency-check response can still be answered.
+ */
static void
batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local_entry,
@@ -1235,7 +1301,7 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
* to be kept in the table in order to send it in a full table
* response issued before the net ttvn increment (consistency check)
*/
- tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING;
+ atomic_or(BATADV_TT_CLIENT_PENDING, &tt_local_entry->common.flags);
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
@@ -1259,14 +1325,16 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,
{
struct batadv_tt_local_entry *tt_removed_entry;
struct batadv_tt_local_entry *tt_local_entry;
- u16 flags, curr_flags = BATADV_NO_FLAGS;
struct hlist_node *tt_removed_node;
+ u16 curr_flags = BATADV_NO_FLAGS;
+ u16 old_flags;
+ u16 flags;
tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
if (!tt_local_entry)
goto out;
- curr_flags = tt_local_entry->common.flags;
+ curr_flags = atomic_read(&tt_local_entry->common.flags);
flags = BATADV_TT_CLIENT_DEL;
/* if this global entry addition is due to a roaming, the node has to
@@ -1276,10 +1344,12 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,
if (roaming) {
flags |= BATADV_TT_CLIENT_ROAM;
/* mark the local client as ROAMed */
- tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
+ atomic_or(BATADV_TT_CLIENT_ROAM, &tt_local_entry->common.flags);
}
- if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) {
+ old_flags = atomic_fetch_andnot(BATADV_TT_CLIENT_NEW,
+ &tt_local_entry->common.flags);
+ if (!(old_flags & BATADV_TT_CLIENT_NEW)) {
batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
message);
goto out;
@@ -1319,20 +1389,24 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
struct hlist_head *head,
int timeout)
{
- struct batadv_tt_local_entry *tt_local_entry;
struct batadv_tt_common_entry *tt_common_entry;
+ struct batadv_tt_local_entry *tt_local_entry;
struct hlist_node *node_tmp;
+ u16 flags;
hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
hash_entry) {
tt_local_entry = container_of(tt_common_entry,
struct batadv_tt_local_entry,
common);
- if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
+
+ flags = atomic_read(&tt_local_entry->common.flags);
+
+ if (flags & BATADV_TT_CLIENT_NOPURGE)
continue;
/* entry already marked for deletion */
- if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
+ if (flags & BATADV_TT_CLIENT_PENDING)
continue;
if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout))
@@ -1352,9 +1426,9 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
static void batadv_tt_local_purge(struct batadv_priv *bat_priv,
int timeout)
{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
struct hlist_head *head;
- spinlock_t *list_lock; /* protects write access to the hash lists */
u32 i;
for (i = 0; i < hash->size; i++) {
@@ -1367,12 +1441,19 @@ static void batadv_tt_local_purge(struct batadv_priv *bat_priv,
}
}
+/**
+ * batadv_tt_local_table_free() - release the local translation table
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Drop every entry of the local TT hash, free their references and finally
+ * release the hashtable itself.
+ */
static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
{
- struct batadv_hashtable *hash;
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tt_local_entry *tt_local;
+ struct batadv_hashtable *hash;
struct hlist_node *node_tmp;
struct hlist_head *head;
u32 i;
@@ -1404,6 +1485,13 @@ static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
bat_priv->tt.local_hash = NULL;
}
+/**
+ * batadv_tt_global_init() - allocate and initialise the global translation
+ * table
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Return: 0 on success or -ENOMEM in case of allocation failure
+ */
static int batadv_tt_global_init(struct batadv_priv *bat_priv)
{
if (bat_priv->tt.global_hash)
@@ -1420,9 +1508,16 @@ static int batadv_tt_global_init(struct batadv_priv *bat_priv)
return 0;
}
+/**
+ * batadv_tt_changes_list_free() - drop all pending local TT changes
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Discard every queued local TT change and reset the pending change counter.
+ */
static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
{
- struct batadv_tt_change_node *entry, *safe;
+ struct batadv_tt_change_node *entry;
+ struct batadv_tt_change_node *safe;
spin_lock_bh(&bat_priv->tt.changes_list_lock);
@@ -1451,7 +1546,8 @@ static struct batadv_tt_orig_list_entry *
batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
const struct batadv_orig_node *orig_node)
{
- struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL;
+ struct batadv_tt_orig_list_entry *orig_entry = NULL;
+ struct batadv_tt_orig_list_entry *tmp_orig_entry;
const struct hlist_head *head;
rcu_read_lock();
@@ -1516,6 +1612,8 @@ batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)
struct batadv_tt_orig_list_entry *orig_entry;
const struct hlist_head *head;
u16 flags = BATADV_NO_FLAGS;
+ int new_flags;
+ int old_flags;
rcu_read_lock();
head = &tt_global->orig_list;
@@ -1523,8 +1621,15 @@ batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)
flags |= orig_entry->flags;
rcu_read_unlock();
- flags |= tt_global->common.flags & (~BATADV_TT_SYNC_MASK);
- tt_global->common.flags = flags;
+ /* replace the sync flags without dropping concurrent modifications of
+ * the non-sync flags
+ */
+ old_flags = atomic_read(&tt_global->common.flags);
+ do {
+ new_flags = (old_flags & ~BATADV_TT_SYNC_MASK) | flags;
+ if (new_flags == old_flags)
+ break;
+ } while (!atomic_try_cmpxchg(&tt_global->common.flags, &old_flags, new_flags));
}
/**
@@ -1604,10 +1709,12 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
{
struct batadv_tt_global_entry *tt_global_entry;
struct batadv_tt_local_entry *tt_local_entry;
- bool ret = false;
- int hash_added;
struct batadv_tt_common_entry *common;
+ bool ret = false;
u16 local_flags;
+ u16 clear_flags;
+ int hash_added;
+ u16 old_flags;
/* ignore global entries from backbone nodes */
if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid))
@@ -1621,7 +1728,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
* table
*/
if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry &&
- !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW))
+ !(atomic_read(&tt_local_entry->common.flags) & BATADV_TT_CLIENT_NEW))
goto out;
if (!tt_global_entry) {
@@ -1635,7 +1742,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
common->vid = vid;
if (!is_multicast_ether_addr(common->addr))
- common->flags = flags & (~BATADV_TT_SYNC_MASK);
+ atomic_set(&common->flags, flags & (~BATADV_TT_SYNC_MASK));
tt_global_entry->roam_at = 0;
/* node must store current time in case of roaming. This is
@@ -1664,6 +1771,8 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
}
} else {
common = &tt_global_entry->common;
+ clear_flags = 0;
+
/* If there is already a global entry, we can use this one for
* our processing.
* But if we are trying to add a temporary client then here are
@@ -1675,7 +1784,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
* originator list and add the new one orig_entry
*/
if (flags & BATADV_TT_CLIENT_TEMP) {
- if (!(common->flags & BATADV_TT_CLIENT_TEMP))
+ if (!(atomic_read(&common->flags) & BATADV_TT_CLIENT_TEMP))
goto out;
if (batadv_tt_global_entry_has_orig(tt_global_entry,
orig_node, NULL))
@@ -1684,24 +1793,26 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
goto add_orig_entry;
}
+ /* the change can carry possible "attribute" flags like the
+ * TT_CLIENT_TEMP, therefore they have to be copied in the
+ * client entry
+ */
+ if (!is_multicast_ether_addr(common->addr))
+ atomic_or(flags & (~BATADV_TT_SYNC_MASK), &common->flags);
+
+ old_flags = atomic_read(&common->flags);
+
/* if the client was temporary added before receiving the first
* OGM announcing it, we have to clear the TEMP flag. Also,
* remove the previous temporary orig node and re-add it
* if required. If the orig entry changed, the new one which
* is a non-temporary entry is preferred.
*/
- if (common->flags & BATADV_TT_CLIENT_TEMP) {
+ if (old_flags & BATADV_TT_CLIENT_TEMP) {
batadv_tt_global_del_orig_list(tt_global_entry);
- common->flags &= ~BATADV_TT_CLIENT_TEMP;
+ clear_flags |= BATADV_TT_CLIENT_TEMP;
}
- /* the change can carry possible "attribute" flags like the
- * TT_CLIENT_TEMP, therefore they have to be copied in the
- * client entry
- */
- if (!is_multicast_ether_addr(common->addr))
- common->flags |= flags & (~BATADV_TT_SYNC_MASK);
-
/* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only
* one originator left in the list and we previously received a
* delete + roaming change for this originator.
@@ -1709,11 +1820,14 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
* We should first delete the old originator before adding the
* new one.
*/
- if (common->flags & BATADV_TT_CLIENT_ROAM) {
+ if (old_flags & BATADV_TT_CLIENT_ROAM) {
batadv_tt_global_del_orig_list(tt_global_entry);
- common->flags &= ~BATADV_TT_CLIENT_ROAM;
+ clear_flags |= BATADV_TT_CLIENT_ROAM;
tt_global_entry->roam_at = 0;
}
+
+ if (clear_flags)
+ atomic_andnot(clear_flags, &common->flags);
}
add_orig_entry:
/* add the new orig_entry (if needed) or update it */
@@ -1737,13 +1851,15 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,
"global tt received",
flags & BATADV_TT_CLIENT_ROAM);
- tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI;
+ if (local_flags & BATADV_TT_CLIENT_WIFI)
+ atomic_or(local_flags & BATADV_TT_CLIENT_WIFI,
+ &tt_global_entry->common.flags);
if (!(flags & BATADV_TT_CLIENT_ROAM))
/* this is a normal global add. Therefore the client is not in a
* roaming state anymore.
*/
- tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM;
+ atomic_andnot(BATADV_TT_CLIENT_ROAM, &tt_global_entry->common.flags);
out:
batadv_tt_global_entry_put(tt_global_entry);
@@ -1763,10 +1879,12 @@ static struct batadv_tt_orig_list_entry *
batadv_transtable_best_orig(struct batadv_priv *bat_priv,
struct batadv_tt_global_entry *tt_global_entry)
{
- struct batadv_neigh_node *router, *best_router = NULL;
+ struct batadv_tt_orig_list_entry *best_entry = NULL;
struct batadv_algo_ops *bao = bat_priv->algo_ops;
+ struct batadv_neigh_node *best_router = NULL;
+ struct batadv_tt_orig_list_entry *orig_entry;
+ struct batadv_neigh_node *router;
struct hlist_head *head;
- struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;
head = &tt_global_entry->orig_list;
hlist_for_each_entry_rcu(orig_entry, head, list) {
@@ -1811,10 +1929,10 @@ batadv_tt_global_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_tt_orig_list_entry *orig,
bool best)
{
- u16 flags = (common->flags & (~BATADV_TT_SYNC_MASK)) | orig->flags;
- void *hdr;
+ u16 flags = (atomic_read(&common->flags) & (~BATADV_TT_SYNC_MASK)) | orig->flags;
struct batadv_orig_node_vlan *vlan;
u8 last_ttvn;
+ void *hdr;
u32 crc;
vlan = batadv_orig_node_vlan_get(orig->orig_node,
@@ -1873,7 +1991,8 @@ batadv_tt_global_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_priv *bat_priv,
struct batadv_tt_common_entry *common, int *sub_s)
{
- struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
+ struct batadv_tt_orig_list_entry *orig_entry;
+ struct batadv_tt_orig_list_entry *best_entry;
struct batadv_tt_global_entry *global;
struct hlist_head *head;
int sub = 0;
@@ -1948,16 +2067,16 @@ batadv_tt_global_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
*/
int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
- struct net_device *mesh_iface;
- struct batadv_priv *bat_priv;
struct batadv_hard_iface *primary_if = NULL;
+ int portid = NETLINK_CB(cb->skb).portid;
+ struct net_device *mesh_iface;
struct batadv_hashtable *hash;
- struct hlist_head *head;
- int ret;
+ struct batadv_priv *bat_priv;
int bucket = cb->args[0];
+ struct hlist_head *head;
int idx = cb->args[1];
int sub = cb->args[2];
- int portid = NETLINK_CB(cb->skb).portid;
+ int ret;
mesh_iface = batadv_netlink_get_meshif(cb);
if (IS_ERR(mesh_iface))
@@ -2024,13 +2143,17 @@ _batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry *tt_global_entry,
batadv_tt_orig_list_entry_put(orig_entry);
}
-/* deletes the orig list of a tt_global_entry */
+/**
+ * batadv_tt_global_del_orig_list() - drop every orig_list_entry of a global
+ * TT entry
+ * @tt_global_entry: the global TT entry to clear
+ */
static void
batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry)
{
+ struct batadv_tt_orig_list_entry *orig_entry;
struct hlist_head *head;
struct hlist_node *safe;
- struct batadv_tt_orig_list_entry *orig_entry;
spin_lock_bh(&tt_global_entry->list_lock);
head = &tt_global_entry->orig_list;
@@ -2055,9 +2178,9 @@ batadv_tt_global_del_orig_node(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
const char *message)
{
+ struct batadv_tt_orig_list_entry *orig_entry;
struct hlist_head *head;
struct hlist_node *safe;
- struct batadv_tt_orig_list_entry *orig_entry;
unsigned short vid;
spin_lock_bh(&tt_global_entry->list_lock);
@@ -2077,9 +2200,17 @@ batadv_tt_global_del_orig_node(struct batadv_priv *bat_priv,
spin_unlock_bh(&tt_global_entry->list_lock);
}
-/* If the client is to be deleted, we check if it is the last origantor entry
- * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the
- * timer, otherwise we simply remove the originator scheduled for deletion.
+/**
+ * batadv_tt_global_del_roaming() - remove a roaming client from a global TT
+ * entry
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_global_entry: the global TT entry of the roaming client
+ * @orig_node: the originator that the client has roamed away from
+ * @message: debug message describing the reason for the change
+ *
+ * If @orig_node was the last announced source for the client, mark the entry
+ * for roaming so it can be cleaned up after the roaming timer expires.
+ * Otherwise simply remove the orig_node entry from the announcer list.
*/
static void
batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
@@ -2087,9 +2218,9 @@ batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
const char *message)
{
- bool last_entry = true;
- struct hlist_head *head;
struct batadv_tt_orig_list_entry *orig_entry;
+ struct hlist_head *head;
+ bool last_entry = true;
/* no local entry exists, case 1:
* Check if this is the last one or if other entries exist.
@@ -2107,7 +2238,7 @@ batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
if (last_entry) {
/* its the last one, mark for roaming. */
- tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
+ atomic_or(BATADV_TT_CLIENT_ROAM, &tt_global_entry->common.flags);
tt_global_entry->roam_at = jiffies;
} else {
/* there is another entry, we can simply delete this
@@ -2133,8 +2264,8 @@ static void batadv_tt_global_del(struct batadv_priv *bat_priv,
const unsigned char *addr, unsigned short vid,
const char *message, bool roaming)
{
- struct batadv_tt_global_entry *tt_global_entry;
struct batadv_tt_local_entry *local_entry = NULL;
+ struct batadv_tt_global_entry *tt_global_entry;
tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
if (!tt_global_entry)
@@ -2196,14 +2327,14 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
s32 match_vid,
const char *message)
{
- struct batadv_tt_global_entry *tt_global;
- struct batadv_tt_common_entry *tt_common_entry;
- u32 i;
+ spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_hashtable *hash = bat_priv->tt.global_hash;
+ struct batadv_tt_common_entry *tt_common_entry;
+ struct batadv_tt_global_entry *tt_global;
struct hlist_node *safe;
struct hlist_head *head;
- spinlock_t *list_lock; /* protects write access to the hash lists */
unsigned short vid;
+ u32 i;
if (!hash)
return;
@@ -2241,20 +2372,30 @@ void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
clear_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
}
+/**
+ * batadv_tt_global_to_purge() - check whether a global TT entry has to be
+ * purged
+ * @tt_global: global TT entry under consideration
+ * @msg: storage for a pointer to a human readable reason on return
+ *
+ * Return: true if the entry should be purged because its roaming or temporary
+ * timer has elapsed; false otherwise
+ */
static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
char **msg)
{
- bool purge = false;
unsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT;
unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT;
+ u16 flags = atomic_read(&tt_global->common.flags);
+ bool purge = false;
- if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) &&
+ if ((flags & BATADV_TT_CLIENT_ROAM) &&
batadv_has_timed_out(tt_global->roam_at, roam_timeout)) {
purge = true;
*msg = "Roaming timeout\n";
}
- if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) &&
+ if ((flags & BATADV_TT_CLIENT_TEMP) &&
batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) {
purge = true;
*msg = "Temporary client timeout\n";
@@ -2263,16 +2404,23 @@ static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
return purge;
}
+/**
+ * batadv_tt_global_purge() - purge expired global translation table entries
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Iterate over the global translation table and drop every entry that the
+ * roaming or temporary timer has expired for.
+ */
static void batadv_tt_global_purge(struct batadv_priv *bat_priv)
{
- struct batadv_hashtable *hash = bat_priv->tt.global_hash;
- struct hlist_head *head;
- struct hlist_node *node_tmp;
spinlock_t *list_lock; /* protects write access to the hash lists */
- u32 i;
- char *msg = NULL;
+ struct batadv_hashtable *hash = bat_priv->tt.global_hash;
struct batadv_tt_common_entry *tt_common;
struct batadv_tt_global_entry *tt_global;
+ struct hlist_node *node_tmp;
+ struct hlist_head *head;
+ char *msg = NULL;
+ u32 i;
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
@@ -2302,12 +2450,19 @@ static void batadv_tt_global_purge(struct batadv_priv *bat_priv)
}
}
+/**
+ * batadv_tt_global_table_free() - release the global translation table
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Drop every entry of the global TT hash, free their references and finally
+ * release the hashtable itself.
+ */
static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)
{
- struct batadv_hashtable *hash;
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tt_global_entry *tt_global;
+ struct batadv_hashtable *hash;
struct hlist_node *node_tmp;
struct hlist_head *head;
u32 i;
@@ -2338,17 +2493,30 @@ static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)
bat_priv->tt.global_hash = NULL;
}
+/**
+ * _batadv_is_ap_isolated() - check whether two clients are AP-isolated from
+ * each other
+ * @tt_local_entry: local TT entry of the sending client
+ * @tt_global_entry: global TT entry of the destination client
+ *
+ * Return: true if traffic between the two clients should be dropped because
+ * either both are WiFi clients or both carry the ISOLATION flag; false
+ * otherwise
+ */
static bool
_batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,
struct batadv_tt_global_entry *tt_global_entry)
{
- if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI &&
- tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI)
+ u16 global_flags = atomic_read(&tt_global_entry->common.flags);
+ u16 local_flags = atomic_read(&tt_local_entry->common.flags);
+
+ if (local_flags & BATADV_TT_CLIENT_WIFI &&
+ global_flags & BATADV_TT_CLIENT_WIFI)
return true;
/* check if the two clients are marked as isolated */
- if (tt_local_entry->common.flags & BATADV_TT_CLIENT_ISOLA &&
- tt_global_entry->common.flags & BATADV_TT_CLIENT_ISOLA)
+ if (local_flags & BATADV_TT_CLIENT_ISOLA &&
+ global_flags & BATADV_TT_CLIENT_ISOLA)
return true;
return false;
@@ -2373,15 +2541,15 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
const u8 *addr,
unsigned short vid)
{
- struct batadv_tt_local_entry *tt_local_entry = NULL;
struct batadv_tt_global_entry *tt_global_entry = NULL;
- struct batadv_orig_node *orig_node = NULL;
+ struct batadv_tt_local_entry *tt_local_entry = NULL;
struct batadv_tt_orig_list_entry *best_entry;
+ struct batadv_orig_node *orig_node = NULL;
if (src && batadv_vlan_ap_isola_get(bat_priv, vid)) {
tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid);
if (!tt_local_entry ||
- (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
+ (atomic_read(&tt_local_entry->common.flags) & BATADV_TT_CLIENT_PENDING))
goto out;
}
@@ -2445,9 +2613,12 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,
struct batadv_tt_common_entry *tt_common;
struct batadv_tt_global_entry *tt_global;
struct hlist_head *head;
- u32 i, crc_tmp, crc = 0;
- u8 flags;
+ u16 entry_flags;
__be16 tmp_vid;
+ u32 crc_tmp;
+ u32 crc = 0;
+ u8 flags;
+ u32 i;
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
@@ -2463,18 +2634,20 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,
if (tt_common->vid != vid)
continue;
+ entry_flags = atomic_read(&tt_common->flags);
+
/* Roaming clients are in the global table for
* consistency only. They don't have to be
* taken into account while computing the
* global crc
*/
- if (tt_common->flags & BATADV_TT_CLIENT_ROAM)
+ if (entry_flags & BATADV_TT_CLIENT_ROAM)
continue;
/* Temporary clients have not been announced yet, so
* they have to be skipped while computing the global
* crc
*/
- if (tt_common->flags & BATADV_TT_CLIENT_TEMP)
+ if (entry_flags & BATADV_TT_CLIENT_TEMP)
continue;
/* find out if this global entry is announced by this
@@ -2523,9 +2696,12 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
struct batadv_tt_common_entry *tt_common;
struct hlist_head *head;
- u32 i, crc_tmp, crc = 0;
- u8 flags;
+ u16 entry_flags;
__be16 tmp_vid;
+ u32 crc_tmp;
+ u32 crc = 0;
+ u8 flags;
+ u32 i;
for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
@@ -2538,10 +2714,12 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,
if (tt_common->vid != vid)
continue;
+ entry_flags = atomic_read(&tt_common->flags);
+
/* not yet committed clients have not to be taken into
* account while computing the CRC
*/
- if (tt_common->flags & BATADV_TT_CLIENT_NEW)
+ if (entry_flags & BATADV_TT_CLIENT_NEW)
continue;
/* use network order to read the VID: this ensures that
@@ -2553,7 +2731,7 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,
/* compute the CRC on flags that have to be kept in sync
* among nodes
*/
- flags = tt_common->flags & BATADV_TT_SYNC_MASK;
+ flags = entry_flags & BATADV_TT_SYNC_MASK;
crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags));
crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN);
@@ -2590,6 +2768,10 @@ static void batadv_tt_req_node_put(struct batadv_tt_req_node *tt_req_node)
kref_put(&tt_req_node->refcount, batadv_tt_req_node_release);
}
+/**
+ * batadv_tt_req_list_free() - drop all pending TT requests
+ * @bat_priv: the bat priv with all the mesh interface information
+ */
static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)
{
struct batadv_tt_req_node *node;
@@ -2605,6 +2787,18 @@ static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)
spin_unlock_bh(&bat_priv->tt.req_list_lock);
}
+/**
+ * batadv_tt_save_orig_buffer() - cache the latest TT TVLV payload of an
+ * originator
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @orig_node: originator for which the buffer should be created
+ * @tt_buff: pointer to the TT TVLV payload to cache
+ * @tt_buff_len: length of @tt_buff in bytes
+ *
+ * Replace the previously cached TT payload of @orig_node with a copy of
+ * @tt_buff. The buffer is left untouched when @tt_buff_len is 0 so that
+ * empty OGM updates do not discard the previously cached data.
+ */
static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
const void *tt_buff,
@@ -2626,6 +2820,10 @@ static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,
spin_unlock_bh(&orig_node->tt_buff_lock);
}
+/**
+ * batadv_tt_req_purge() - drop timed-out TT requests
+ * @bat_priv: the bat priv with all the mesh interface information
+ */
static void batadv_tt_req_purge(struct batadv_priv *bat_priv)
{
struct batadv_tt_req_node *node;
@@ -2654,7 +2852,8 @@ static struct batadv_tt_req_node *
batadv_tt_req_node_new(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node)
{
- struct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL;
+ struct batadv_tt_req_node *tt_req_node = NULL;
+ struct batadv_tt_req_node *tt_req_node_tmp;
spin_lock_bh(&bat_priv->tt.req_list_lock);
hlist_for_each_entry(tt_req_node_tmp, &bat_priv->tt.req_list, list) {
@@ -2695,12 +2894,13 @@ static bool batadv_tt_local_valid(const void *entry_ptr,
u8 *flags)
{
const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
+ u16 entry_flags = atomic_read(&tt_common_entry->flags);
- if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
+ if (entry_flags & BATADV_TT_CLIENT_NEW)
return false;
if (flags)
- *flags = tt_common_entry->flags;
+ *flags = entry_flags;
return true;
}
@@ -2724,9 +2924,10 @@ static bool batadv_tt_global_valid(const void *entry_ptr,
const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
const struct batadv_tt_global_entry *tt_global_entry;
const struct batadv_orig_node *orig_node = data_ptr;
+ u16 entry_flags;
- if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM ||
- tt_common_entry->flags & BATADV_TT_CLIENT_TEMP)
+ entry_flags = atomic_read(&tt_common_entry->flags);
+ if (entry_flags & (BATADV_TT_CLIENT_ROAM | BATADV_TT_CLIENT_TEMP))
return false;
tt_global_entry = container_of(tt_common_entry,
@@ -2763,7 +2964,8 @@ static u16 batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
struct batadv_tt_common_entry *tt_common_entry;
struct batadv_tvlv_tt_change *tt_change;
struct hlist_head *head;
- u16 tt_tot, tt_num_entries = 0;
+ u16 tt_num_entries = 0;
+ u16 tt_tot;
u8 flags;
bool ret;
u32 i;
@@ -2817,8 +3019,9 @@ static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node,
{
struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp;
struct batadv_orig_node_vlan *vlan;
- int i, orig_num_vlan;
+ int orig_num_vlan;
u32 crc;
+ int i;
/* check if each received CRC matches the locally stored one */
for (i = 0; i < num_vlan; i++) {
@@ -2924,7 +3127,8 @@ static bool batadv_send_tt_request(struct batadv_priv *bat_priv,
struct batadv_tt_req_node *tt_req_node = NULL;
struct batadv_hard_iface *primary_if;
bool ret = false;
- int i, size;
+ int size;
+ int i;
primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
@@ -3000,13 +3204,15 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
struct batadv_tvlv_tt_data *tt_data,
u8 *req_src, u8 *req_dst)
{
- struct batadv_orig_node *req_dst_orig_node;
struct batadv_orig_node *res_dst_orig_node = NULL;
- struct batadv_tvlv_tt_change *tt_change;
struct batadv_tvlv_tt_data *tvlv_tt_data = NULL;
- bool ret = false, full_table;
- u8 orig_ttvn, req_ttvn;
+ struct batadv_orig_node *req_dst_orig_node;
+ struct batadv_tvlv_tt_change *tt_change;
+ bool ret = false;
+ bool full_table;
+ u8 orig_ttvn;
u16 tvlv_len;
+ u8 req_ttvn;
s32 tt_len;
batadv_dbg(BATADV_DBG_TT, bat_priv,
@@ -3133,9 +3339,10 @@ static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if = NULL;
struct batadv_tvlv_tt_change *tt_change;
struct batadv_orig_node *orig_node;
- u8 my_ttvn, req_ttvn;
- u16 tvlv_len;
bool full_table;
+ u16 tvlv_len;
+ u8 req_ttvn;
+ u8 my_ttvn;
s32 tt_len;
batadv_dbg(BATADV_DBG_TT, bat_priv,
@@ -3253,13 +3460,25 @@ static bool batadv_send_tt_response(struct batadv_priv *bat_priv,
req_dst);
}
+/**
+ * _batadv_tt_update_changes() - apply a list of TT changes to the global TT
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @orig_node: originator announcing the changes
+ * @tt_change: array of TT change entries to apply
+ * @tt_num_changes: number of entries in @tt_change
+ * @ttvn: TTVN of @orig_node corresponding to @tt_change
+ *
+ * Walk @tt_change and add/remove the announced clients in the global TT.
+ * Abort early without marking the TTVN as up to date if adding an entry
+ * fails, so that the next TT request can re-sync the full table.
+ */
static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_tvlv_tt_change *tt_change,
u16 tt_num_changes, u8 ttvn)
{
- int i;
int roams;
+ int i;
for (i = 0; i < tt_num_changes; i++) {
if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) {
@@ -3286,6 +3505,18 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
set_bit(BATADV_ORIG_CAPA_HAS_TT, &orig_node->capa_initialized);
}
+/**
+ * batadv_tt_fill_gtable() - replace the cached TT of an originator with a
+ * full table response
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_change: array of TT change entries describing the full table
+ * @ttvn: TTVN announced together with the full table
+ * @resp_src: MAC address of the responder
+ * @num_entries: number of entries in @tt_change
+ *
+ * Drop the previously known global TT entries of @resp_src and replace them
+ * with the entries from a freshly received full TT response.
+ */
static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
struct batadv_tvlv_tt_change *tt_change,
u8 ttvn, u8 *resp_src,
@@ -3316,6 +3547,15 @@ static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
batadv_orig_node_put(orig_node);
}
+/**
+ * batadv_tt_update_changes() - apply an incremental TT changeset to the
+ * global TT
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @orig_node: originator announcing the changes
+ * @tt_num_changes: number of entries in @tt_change
+ * @ttvn: TTVN of @orig_node corresponding to @tt_change
+ * @tt_change: array of TT change entries to apply
+ */
static void batadv_tt_update_changes(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
u16 tt_num_changes, u8 ttvn,
@@ -3342,6 +3582,7 @@ bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,
{
struct batadv_tt_local_entry *tt_local_entry;
bool ret = false;
+ u16 entry_flags;
tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
if (!tt_local_entry)
@@ -3349,8 +3590,8 @@ bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,
/* Check if the client has been logically deleted (but is kept for
* consistency purpose)
*/
- if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) ||
- (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM))
+ entry_flags = atomic_read(&tt_local_entry->common.flags);
+ if (entry_flags & (BATADV_TT_CLIENT_PENDING | BATADV_TT_CLIENT_ROAM))
goto out;
ret = true;
out:
@@ -3369,11 +3610,11 @@ static void batadv_handle_tt_response(struct batadv_priv *bat_priv,
struct batadv_tvlv_tt_data *tt_data,
u8 *resp_src, u16 num_entries)
{
- struct batadv_tt_req_node *node;
- struct hlist_node *safe;
struct batadv_orig_node *orig_node = NULL;
struct batadv_tvlv_tt_change *tt_change;
+ struct batadv_tt_req_node *node;
u8 *tvlv_ptr = (u8 *)tt_data;
+ struct hlist_node *safe;
batadv_dbg(BATADV_DBG_TT, bat_priv,
"Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n",
@@ -3416,9 +3657,14 @@ static void batadv_handle_tt_response(struct batadv_priv *bat_priv,
batadv_orig_node_put(orig_node);
}
+/**
+ * batadv_tt_roam_list_free() - drop all entries from the roaming clients list
+ * @bat_priv: the bat priv with all the mesh interface information
+ */
static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)
{
- struct batadv_tt_roam_node *node, *safe;
+ struct batadv_tt_roam_node *node;
+ struct batadv_tt_roam_node *safe;
spin_lock_bh(&bat_priv->tt.roam_list_lock);
@@ -3430,9 +3676,14 @@ static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)
spin_unlock_bh(&bat_priv->tt.roam_list_lock);
}
+/**
+ * batadv_tt_roam_purge() - drop timed-out roaming clients
+ * @bat_priv: the bat priv with all the mesh interface information
+ */
static void batadv_tt_roam_purge(struct batadv_priv *bat_priv)
{
- struct batadv_tt_roam_node *node, *safe;
+ struct batadv_tt_roam_node *node;
+ struct batadv_tt_roam_node *safe;
spin_lock_bh(&bat_priv->tt.roam_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
@@ -3522,8 +3773,8 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
unsigned short vid,
struct batadv_orig_node *orig_node)
{
- struct batadv_hard_iface *primary_if;
struct batadv_tvlv_roam_adv tvlv_roam;
+ struct batadv_hard_iface *primary_if;
primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
@@ -3552,6 +3803,14 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, u8 *client,
batadv_hardif_put(primary_if);
}
+/**
+ * batadv_tt_purge() - periodic worker to maintain the translation table
+ * @work: delayed work embedded in the per-mesh-interface TT state
+ *
+ * Purge timed-out entries from the local and global TT, drop stale TT
+ * requests and roaming clients, and reschedule the next run after
+ * BATADV_TT_WORK_PERIOD milliseconds.
+ */
static void batadv_tt_purge(struct work_struct *work)
{
struct delayed_work *delayed_work;
@@ -3594,19 +3853,17 @@ void batadv_tt_free(struct batadv_priv *bat_priv)
}
/**
- * batadv_tt_local_set_flags() - set or unset the specified flags on the local
- * table and possibly count them in the TT size
+ * batadv_tt_local_transition_new() - unset the NEW flag on the local
+ * table and count them in the TT size
* @bat_priv: the bat priv with all the mesh interface information
- * @flags: the flag to switch
- * @enable: whether to set or unset the flag
- * @count: whether to increase the TT size by the number of changed entries
*/
-static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,
- bool enable, bool count)
+static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv)
{
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
struct batadv_tt_common_entry *tt_common_entry;
struct hlist_head *head;
+ atomic_t *entry_flags;
+ u16 old_flags;
u32 i;
if (!hash)
@@ -3618,17 +3875,15 @@ static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,
rcu_read_lock();
hlist_for_each_entry_rcu(tt_common_entry,
head, hash_entry) {
- if (enable) {
- if ((tt_common_entry->flags & flags) == flags)
- continue;
- tt_common_entry->flags |= flags;
- } else {
- if (!(tt_common_entry->flags & flags))
- continue;
- tt_common_entry->flags &= ~flags;
- }
+ entry_flags = &tt_common_entry->flags;
+ old_flags = atomic_read(entry_flags);
+
+ if (!(old_flags & BATADV_TT_CLIENT_NEW))
+ continue;
- if (!count)
+ old_flags = atomic_fetch_andnot(BATADV_TT_CLIENT_NEW,
+ entry_flags);
+ if (!(old_flags & BATADV_TT_CLIENT_NEW))
continue;
batadv_tt_local_size_inc(bat_priv,
@@ -3638,15 +3893,22 @@ static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, u16 flags,
}
}
-/* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
+/**
+ * batadv_tt_local_purge_pending_clients() - finalise removal of pending local
+ * clients
+ * @bat_priv: the bat priv with all the mesh interface information
+ *
+ * Iterate over the local TT and physically remove every entry that has been
+ * marked as BATADV_TT_CLIENT_PENDING.
+ */
static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
struct batadv_tt_common_entry *tt_common;
struct batadv_tt_local_entry *tt_local;
struct hlist_node *node_tmp;
struct hlist_head *head;
- spinlock_t *list_lock; /* protects write access to the hash lists */
u32 i;
if (!hash)
@@ -3659,7 +3921,7 @@ static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
spin_lock_bh(list_lock);
hlist_for_each_entry_safe(tt_common, node_tmp, head,
hash_entry) {
- if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
+ if (!(atomic_read(&tt_common->flags) & BATADV_TT_CLIENT_PENDING))
continue;
batadv_dbg(BATADV_DBG_TT, bat_priv,
@@ -3696,7 +3958,7 @@ static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)
return;
}
- batadv_tt_local_set_flags(bat_priv, BATADV_TT_CLIENT_NEW, false, true);
+ batadv_tt_local_transition_new(bat_priv);
batadv_tt_local_purge_pending_clients(bat_priv);
batadv_tt_local_update_crc(bat_priv);
@@ -3736,8 +3998,8 @@ void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv)
bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst,
unsigned short vid)
{
- struct batadv_tt_local_entry *tt_local_entry;
struct batadv_tt_global_entry *tt_global_entry;
+ struct batadv_tt_local_entry *tt_local_entry;
struct batadv_meshif_vlan *vlan;
bool ret = false;
@@ -3872,7 +4134,7 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
if (!tt_global_entry)
goto out;
- ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM;
+ ret = atomic_read(&tt_global_entry->common.flags) & BATADV_TT_CLIENT_ROAM;
batadv_tt_global_entry_put(tt_global_entry);
out:
return ret;
@@ -3898,7 +4160,7 @@ bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
if (!tt_local_entry)
goto out;
- ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM;
+ ret = atomic_read(&tt_local_entry->common.flags) & BATADV_TT_CLIENT_ROAM;
batadv_tt_local_entry_put(tt_local_entry);
out:
return ret;
@@ -3947,13 +4209,15 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)
{
struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
- int packet_size_max = READ_ONCE(bat_priv->packet_size_max);
- int table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2;
+ int timeout = BATADV_TT_LOCAL_TIMEOUT / 2;
bool reduced = false;
+ int packet_size_max;
+ int table_size;
spin_lock_bh(&bat_priv->tt.commit_lock);
while (timeout) {
+ packet_size_max = READ_ONCE(bat_priv->packet_size_max);
table_size = batadv_tt_local_table_transmit_size(bat_priv);
if (packet_size_max >= table_size)
break;
@@ -3992,8 +4256,9 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
{
struct batadv_tvlv_tt_change *tt_change;
struct batadv_tvlv_tt_data *tt_data;
- u16 num_entries, num_vlan;
size_t tt_data_sz;
+ u16 num_entries;
+ u16 num_vlan;
if (tvlv_value_len < sizeof(*tt_data))
return;
@@ -4115,8 +4380,8 @@ static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
void *tvlv_value,
u16 tvlv_value_len)
{
- struct batadv_tvlv_roam_adv *roaming_adv;
struct batadv_orig_node *orig_node = NULL;
+ struct batadv_tvlv_roam_adv *roaming_adv;
/* If this node is not the intended recipient of the
* roaming advertisement the packet is forwarded
@@ -4205,7 +4470,7 @@ bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,
if (!tt)
return false;
- ret = tt->common.flags & BATADV_TT_CLIENT_ISOLA;
+ ret = atomic_read(&tt->common.flags) & BATADV_TT_CLIENT_ISOLA;
batadv_tt_global_entry_put(tt);
@@ -4219,12 +4484,12 @@ bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,
*/
int __init batadv_tt_cache_init(void)
{
- size_t tl_size = sizeof(struct batadv_tt_local_entry);
- size_t tg_size = sizeof(struct batadv_tt_global_entry);
size_t tt_orig_size = sizeof(struct batadv_tt_orig_list_entry);
size_t tt_change_size = sizeof(struct batadv_tt_change_node);
- size_t tt_req_size = sizeof(struct batadv_tt_req_node);
size_t tt_roam_size = sizeof(struct batadv_tt_roam_node);
+ size_t tg_size = sizeof(struct batadv_tt_global_entry);
+ size_t tt_req_size = sizeof(struct batadv_tt_req_node);
+ size_t tl_size = sizeof(struct batadv_tt_local_entry);
batadv_tl_cache = kmem_cache_create("batadv_tl_cache", tl_size, 0,
SLAB_HWCACHE_ALIGN, NULL);
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 49bf2ed9ecdc3..5600aaf00627c 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -72,7 +72,8 @@ static void batadv_tvlv_handler_put(struct batadv_tvlv_handler *tvlv_handler)
static struct batadv_tvlv_handler *
batadv_tvlv_handler_get(struct batadv_priv *bat_priv, u8 type, u8 version)
{
- struct batadv_tvlv_handler *tvlv_handler_tmp, *tvlv_handler = NULL;
+ struct batadv_tvlv_handler *tvlv_handler = NULL;
+ struct batadv_tvlv_handler *tvlv_handler_tmp;
rcu_read_lock();
hlist_for_each_entry_rcu(tvlv_handler_tmp,
@@ -134,7 +135,8 @@ static void batadv_tvlv_container_put(struct batadv_tvlv_container *tvlv)
static struct batadv_tvlv_container *
batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version)
{
- struct batadv_tvlv_container *tvlv_tmp, *tvlv = NULL;
+ struct batadv_tvlv_container *tvlv = NULL;
+ struct batadv_tvlv_container *tvlv_tmp;
lockdep_assert_held(&bat_priv->tvlv.container_list_lock);
@@ -236,7 +238,8 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
u8 type, u8 version,
void *tvlv_value, u16 tvlv_value_len)
{
- struct batadv_tvlv_container *tvlv_old, *tvlv_new;
+ struct batadv_tvlv_container *tvlv_old;
+ struct batadv_tvlv_container *tvlv_new;
if (!tvlv_value)
tvlv_value_len = 0;
@@ -394,7 +397,8 @@ static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv,
u16 tvlv_value_len)
{
unsigned int tvlv_offset;
- u8 *src, *dst;
+ u8 *src;
+ u8 *dst;
if (!tvlv_handler)
return NET_RX_SUCCESS;
@@ -533,13 +537,13 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
struct sk_buff *skb, void *tvlv_value,
u16 tvlv_value_len)
{
+ u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;
u16 tvlv_value_start_len = tvlv_value_len;
struct batadv_tvlv_handler *tvlv_handler;
void *tvlv_value_start = tvlv_value;
struct batadv_tvlv_hdr *tvlv_hdr;
- u16 tvlv_value_cont_len;
- u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;
int ret = NET_RX_SUCCESS;
+ u16 tvlv_value_cont_len;
while ((tvlv_hdr = batadv_tvlv_hdr_next(&tvlv_value, &tvlv_value_len))) {
tvlv_value_cont_len = ntohs(tvlv_hdr->len);
@@ -596,8 +600,8 @@ void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
struct batadv_ogm_packet *batadv_ogm_packet,
struct batadv_orig_node *orig_node)
{
- void *tvlv_value;
u16 tvlv_value_len;
+ void *tvlv_value;
if (!batadv_ogm_packet)
return;
@@ -717,12 +721,12 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, const u8 *src,
void *tvlv_value, u16 tvlv_value_len)
{
struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
- struct batadv_tvlv_hdr *tvlv_hdr;
+ ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
struct batadv_orig_node *orig_node;
- struct sk_buff *skb;
+ struct batadv_tvlv_hdr *tvlv_hdr;
unsigned char *tvlv_buff;
unsigned int tvlv_len;
- ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
+ struct sk_buff *skb;
orig_node = batadv_orig_hash_find(bat_priv, dst);
if (!orig_node)
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index cd12755d21f35..d6e15d467a8f7 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1827,10 +1827,10 @@ struct batadv_bla_claim {
/** @hash_entry: hlist node for &batadv_priv_bla.claim_hash */
struct hlist_node hash_entry;
- /** @refcount: number of contexts the object is used */
+ /** @rcu: struct used for freeing in an RCU-safe manner */
struct rcu_head rcu;
- /** @rcu: struct used for freeing in an RCU-safe manner */
+ /** @refcount: number of contexts the object is used */
struct kref refcount;
};
#endif
@@ -1852,7 +1852,7 @@ struct batadv_tt_common_entry {
struct hlist_node hash_entry;
/** @flags: various state handling flags (see batadv_tt_client_flags) */
- u16 flags;
+ atomic_t flags;
/** @added_at: timestamp used for purging stale tt common entries */
unsigned long added_at;
@@ -2176,7 +2176,7 @@ struct batadv_dat_entry {
__be32 ip;
/** @mac_addr: the MAC address associated to the stored IPv4 */
- u8 mac_addr[ETH_ALEN];
+ atomic64_t mac_addr;
/** @vid: the vlan ID associated to this entry */
unsigned short vid;
|
| 3/2 | 2026/07/29 18:05 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 83312 output: 34 thoughts: 585 Thoughts: **Analyzing a Patch to Batman-adv for Potential Fuzzing** Okay, so I'm looking at this patch targeting `net/batman-adv/`, and my initial impression is that it's primarily focused on improving concurrency and atomicity. The changes include variable reordering, kernel-doc additions (always a good sign!), and most notably, the replacement of `mac_addr` (originally `u8 mac_addr[ETH_ALEN]`) in `batadv_dat_entry` with an `atomic64_t` and similar atomic operations for flags in several structures and functions. This conversion to atomic types and operations is a definite functional change aimed at addressing potential race conditions, making it more interesting from a fuzzing perspective. I need to confirm that these modifications aren't just cosmetic. Yes, changing the data types to atomic versions and using atomic operations is indeed a functional change, aimed at fixing concurrency issues which opens up the possibility of discovering subtle bugs through fuzzing that we may not discover with more traditional techniques. This makes fuzzing a very attractive option, since the modifications change the underlying structure of critical data. Now, the important question is whether these changes are reachable and if `batman-adv` is accessible for fuzzing. Batman-adv, as a layer 2 mesh routing protocol, should be reachable, and it's a virtual interface. I can easily test this by creating a `bat0` interface using `batctl` or netlink within a QEMU environment. Since we have functional changes involving atomics and locking, it’s definitely worth the effort. Let's identify the specific functions targeted by the patch. These are: `batadv_dat_entry_add`, `batadv_dat_snoop_outgoing_arp_request`, `batadv_dat_snoop_incoming_arp_request`, `batadv_dat_snoop_incoming_arp_reply`, `batadv_tt_local_add`, `batadv_tt_global_add`, `batadv_tt_local_remove`, `batadv_tt_global_sync_flags`, `batadv_tt_local_transition_new`, and `batadv_bla_add_claim`. Knowing the modified functions will help me prioritize fuzzing targets. Finally, I have to determine the necessary configurations. I'm assuming that I will need `CONFIG_BATMAN_ADV`, `CONFIG_BATMAN_ADV_DAT`, and `CONFIG_BATMAN_ADV_BLA` enabled. I might also need `CONFIG_BATMAN_ADV_MCAST`, depending on how the patch interacts with multicast functionality. I should check the Kconfig files for a definitive answer, just to be sure. With this information, I can now move forward with setting up a fuzzing environment. |
| 4/2 | 2026/07/29 18:05 | tool | grepper |
0mArgs:{
"Expression": "config BATMAN_ADV",
"PathPrefix": "net/batman-adv/Kconfig"
}Results: {
"Output": "net/batman-adv/Kconfig-9-\nnet/batman-adv/Kconfig:10:config BATMAN_ADV\nnet/batman-adv/Kconfig-11-\ttristate \"B.A.T.M.A.N. Advanced Meshing Protocol\"\n--\nnet/batman-adv/Kconfig-19-\nnet/batman-adv/Kconfig:20:config BATMAN_ADV_BATMAN_V\nnet/batman-adv/Kconfig-21-\tbool \"B.A.T.M.A.N. V protocol\"\n--\nnet/batman-adv/Kconfig-33-\nnet/batman-adv/Kconfig:34:config BATMAN_ADV_BLA\nnet/batman-adv/Kconfig-35-\tbool \"Bridge Loop Avoidance\"\n--\nnet/batman-adv/Kconfig-46-\nnet/batman-adv/Kconfig:47:config BATMAN_ADV_DAT\nnet/batman-adv/Kconfig-48-\tbool \"Distributed ARP Table\"\n--\nnet/batman-adv/Kconfig-56-\nnet/batman-adv/Kconfig:57:config BATMAN_ADV_MCAST\nnet/batman-adv/Kconfig-58-\tbool \"Multicast optimisation\"\n--\nnet/batman-adv/Kconfig-65-\nnet/batman-adv/Kconfig:66:config BATMAN_ADV_DEBUG\nnet/batman-adv/Kconfig-67-\tbool \"B.A.T.M.A.N. debugging\"\n--\nnet/batman-adv/Kconfig-74-\nnet/batman-adv/Kconfig:75:config BATMAN_ADV_TRACING\nnet/batman-adv/Kconfig-76-\tbool \"B.A.T.M.A.N. tracing support\"\n"
} |
| 5/2 | 2026/07/29 18:05 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 84991 output: 31 thoughts: 57 Thoughts: **Analyzing the batman-adv Configuration** Okay, so I'm looking at these configurations: `BATMAN_ADV`, `BATMAN_ADV_DAT`, `BATMAN_ADV_BLA`, and `BATMAN_ADV_MCAST`. Naturally, my next step is to drill down into `BATMAN_ADV` and understand its dependencies. That's the core, so it's the logical place to start figuring out the structure of the whole thing. Let's see what that reveals. |
| 6/2 | 2026/07/29 18:05 | tool | grepper |
0mArgs:{
"Expression": "depends on",
"PathPrefix": "net/batman-adv/Kconfig"
}Results: {
"Output": "net/batman-adv/Kconfig=20=config BATMAN_ADV_BATMAN_V\nnet/batman-adv/Kconfig-21-\tbool \"B.A.T.M.A.N. V protocol\"\nnet/batman-adv/Kconfig:22:\tdepends on BATMAN_ADV \u0026\u0026 !(CFG80211=m \u0026\u0026 BATMAN_ADV=y)\nnet/batman-adv/Kconfig-23-\tdefault y\n--\nnet/batman-adv/Kconfig=34=config BATMAN_ADV_BLA\nnet/batman-adv/Kconfig-35-\tbool \"Bridge Loop Avoidance\"\nnet/batman-adv/Kconfig:36:\tdepends on BATMAN_ADV \u0026\u0026 INET\nnet/batman-adv/Kconfig-37-\tselect CRC16\n--\nnet/batman-adv/Kconfig=47=config BATMAN_ADV_DAT\nnet/batman-adv/Kconfig-48-\tbool \"Distributed ARP Table\"\nnet/batman-adv/Kconfig:49:\tdepends on BATMAN_ADV \u0026\u0026 INET\nnet/batman-adv/Kconfig-50-\tdefault y\n--\nnet/batman-adv/Kconfig=57=config BATMAN_ADV_MCAST\nnet/batman-adv/Kconfig-58-\tbool \"Multicast optimisation\"\nnet/batman-adv/Kconfig:59:\tdepends on BATMAN_ADV \u0026\u0026 INET \u0026\u0026 !(BRIDGE=m \u0026\u0026 BATMAN_ADV=y)\nnet/batman-adv/Kconfig-60-\tdefault y\n--\nnet/batman-adv/Kconfig=66=config BATMAN_ADV_DEBUG\nnet/batman-adv/Kconfig-67-\tbool \"B.A.T.M.A.N. debugging\"\nnet/batman-adv/Kconfig:68:\tdepends on BATMAN_ADV\nnet/batman-adv/Kconfig-69-\thelp\n--\nnet/batman-adv/Kconfig=75=config BATMAN_ADV_TRACING\nnet/batman-adv/Kconfig-76-\tbool \"B.A.T.M.A.N. tracing support\"\nnet/batman-adv/Kconfig:77:\tdepends on BATMAN_ADV\nnet/batman-adv/Kconfig:78:\tdepends on EVENT_TRACING\nnet/batman-adv/Kconfig-79-\thelp\n"
} |
| 7/2 | 2026/07/29 18:05 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 85789 output: 34 thoughts: 39 Thoughts: Okay, let's see... **Analyzing the Dependency Structure of BATMAN_ADV** Right, so from what I'm seeing, `BATMAN_ADV` doesn't seem to have any explicit dependencies *other* than `NET`. That's to be expected, `NET` is basically a given. But hold on, before I jump to any conclusions, let me just double-check the `BATMAN_ADV` module itself. I need to be absolutely sure there aren't any hidden implications or subtler requirements that I'm overlooking. Gotta be thorough. |
| 8/2 | 2026/07/29 18:05 | tool | grepper |
0mArgs:{
"Expression": "config BATMAN_ADV",
"PathPrefix": "net/batman-adv/Kconfig"
}Results: {
"Output": "net/batman-adv/Kconfig-9-\nnet/batman-adv/Kconfig:10:config BATMAN_ADV\nnet/batman-adv/Kconfig-11-\ttristate \"B.A.T.M.A.N. Advanced Meshing Protocol\"\n--\nnet/batman-adv/Kconfig-19-\nnet/batman-adv/Kconfig:20:config BATMAN_ADV_BATMAN_V\nnet/batman-adv/Kconfig-21-\tbool \"B.A.T.M.A.N. V protocol\"\n--\nnet/batman-adv/Kconfig-33-\nnet/batman-adv/Kconfig:34:config BATMAN_ADV_BLA\nnet/batman-adv/Kconfig-35-\tbool \"Bridge Loop Avoidance\"\n--\nnet/batman-adv/Kconfig-46-\nnet/batman-adv/Kconfig:47:config BATMAN_ADV_DAT\nnet/batman-adv/Kconfig-48-\tbool \"Distributed ARP Table\"\n--\nnet/batman-adv/Kconfig-56-\nnet/batman-adv/Kconfig:57:config BATMAN_ADV_MCAST\nnet/batman-adv/Kconfig-58-\tbool \"Multicast optimisation\"\n--\nnet/batman-adv/Kconfig-65-\nnet/batman-adv/Kconfig:66:config BATMAN_ADV_DEBUG\nnet/batman-adv/Kconfig-67-\tbool \"B.A.T.M.A.N. debugging\"\n--\nnet/batman-adv/Kconfig-74-\nnet/batman-adv/Kconfig:75:config BATMAN_ADV_TRACING\nnet/batman-adv/Kconfig-76-\tbool \"B.A.T.M.A.N. tracing support\"\n"
} |
| 9/2 | 2026/07/29 18:05 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 86451 output: 36 thoughts: 23 Thoughts: Here's a summary of my thought process, as requested: **Kconfig Inspection: batman-adv** Okay, time to dive into the `net/batman-adv/Kconfig` file. Specifically, I need to focus on lines 10 through 18. I'm guessing that area probably deals with a key feature or configuration option related to the batman-adv mesh networking protocol. It could be enabling or disabling a core module, defining a default behavior, or handling some sort of dependency. I'll need to parse those lines quickly and understand their implications within the broader context of batman-adv's configuration options. Let's see what gems are hidden there. |
| 10/2 | 2026/07/29 18:05 | tool | read-file |
0mArgs:{
"File": "net/batman-adv/Kconfig",
"FirstLine": 10,
"LineCount": 10
}Results: {
"Contents": " 10:\tconfig BATMAN_ADV\n 11:\t\ttristate \"B.A.T.M.A.N. Advanced Meshing Protocol\"\n 12:\t\tselect CRC32\n 13:\t\thelp\n 14:\t\t B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is\n 15:\t\t a routing protocol for multi-hop ad-hoc mesh networks. The\n 16:\t\t networks may be wired or wireless. See\n 17:\t\t https://www.open-mesh.org/ for more information and user space\n 18:\t\t tools.\n 19:\t\n"
} |
| 11/2 | 2026/07/29 18:05 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 86826 output: 42 thoughts: 532 Thoughts: **Analyzing the BATMAN_ADV Patch** Alright, let's dive into this patch. No unusual dependencies to worry about, which is a good start for a `BATMAN_ADV` modification. Now, time to pinpoint the core changes. The focus symbols are jumping out at me: I can see modifications across a broad spectrum of the data structures and functions. It looks like the patch is touching several aspects of data management and traffic handling, from the Data Table (`dat`) and Translation Table (`tt`) entries, to Broadcast Local Announcement (`bla`) processes, fragmentation (`frag`) and gateway (`gw`) related functionality, multicast (`mcast`) forwarding, and isolation checks. The modifications seem pretty extensive, spanning a lot of key areas of the protocol. Hmm, wait a second, some of these modifications look like they're just reordering variables or adding kernel-doc comments. Not all of them are necessarily core changes to the functionality itself. Okay, let's zoom in and focus on what's going on in a single function and see what's actually modified. I will begin by investigating `batadv_dat_entry_add`. |
| 12/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_dat_entry_add",
"PathPrefix": "net/batman-adv/distributed-arp-table.c"
}Results: {
"Output": "net/batman-adv/distributed-arp-table.c=399=batadv_dat_entry_hash_find(struct batadv_priv *bat_priv, __be32 ip,\n--\nnet/batman-adv/distributed-arp-table.c-437-/**\nnet/batman-adv/distributed-arp-table.c:438: * batadv_dat_entry_add() - add a new dat entry or update it if already exists\nnet/batman-adv/distributed-arp-table.c-439- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/distributed-arp-table.c-443- */\nnet/batman-adv/distributed-arp-table.c:444:static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,\nnet/batman-adv/distributed-arp-table.c-445-\t\t\t\t u8 *mac_addr, unsigned short vid)\n--\nnet/batman-adv/distributed-arp-table.c=1234=bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1271-\nnet/batman-adv/distributed-arp-table.c:1272:\tbatadv_dat_entry_add(bat_priv, ip_src, hw_src, vid);\nnet/batman-adv/distributed-arp-table.c-1273-\n--\nnet/batman-adv/distributed-arp-table.c=1343=bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1376-\nnet/batman-adv/distributed-arp-table.c:1377:\tbatadv_dat_entry_add(bat_priv, ip_src, hw_src, vid);\nnet/batman-adv/distributed-arp-table.c-1378-\n--\nnet/batman-adv/distributed-arp-table.c=1415=void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1445-\nnet/batman-adv/distributed-arp-table.c:1446:\tbatadv_dat_entry_add(bat_priv, ip_src, hw_src, vid);\nnet/batman-adv/distributed-arp-table.c:1447:\tbatadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid);\nnet/batman-adv/distributed-arp-table.c-1448-\n--\nnet/batman-adv/distributed-arp-table.c=1473=bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1529-\t */\nnet/batman-adv/distributed-arp-table.c:1530:\tbatadv_dat_entry_add(bat_priv, ip_src, hw_src, vid);\nnet/batman-adv/distributed-arp-table.c:1531:\tbatadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid);\nnet/batman-adv/distributed-arp-table.c-1532-\n--\nnet/batman-adv/distributed-arp-table.c=1772=static void batadv_dat_put_dhcp(struct batadv_priv *bat_priv, u8 *chaddr,\n--\nnet/batman-adv/distributed-arp-table.c-1784-\nnet/batman-adv/distributed-arp-table.c:1785:\tbatadv_dat_entry_add(bat_priv, yiaddr, chaddr, vid);\nnet/batman-adv/distributed-arp-table.c:1786:\tbatadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid);\nnet/batman-adv/distributed-arp-table.c-1787-\n--\nnet/batman-adv/distributed-arp-table.c=1891=void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1920-\nnet/batman-adv/distributed-arp-table.c:1921:\tbatadv_dat_entry_add(bat_priv, yiaddr, chaddr, vid);\nnet/batman-adv/distributed-arp-table.c:1922:\tbatadv_dat_entry_add(bat_priv, ip_src, hw_src, vid);\nnet/batman-adv/distributed-arp-table.c-1923-\n"
} |
| 13/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 88902 output: 40 thoughts: 137 Thoughts: **Analyzing the Usage of `batadv_dat_entry_add`** Okay, so I need to understand where `batadv_dat_entry_add` is being used. It's marked as `static`, which means its scope is limited, but that doesn't mean it's simple to track down. I see it's called from quite a few places: `batadv_dat_snoop_outgoing_arp_request`, `batadv_dat_snoop_incoming_arp_request`, `batadv_dat_snoop_outgoing_arp_reply`, `batadv_dat_snoop_incoming_arp_reply`, `batadv_dat_put_dhcp`, and `batadv_dat_snoop_incoming_dhcp_ack`. The pattern here is obvious. I have to look into the context around these calls to understand the overall behavior. They seem to be connected to snooping and handling ARP and DHCP traffic, which makes sense within the broader context of BATMAN-adv's data tracking. Now, most of these call sites are likely non-static themselves, or static but called from elsewhere. Time to dive into the code and see exactly what's happening. I'll start with `batadv_dat_snoop_outgoing_arp_request` since it's the first one in the list. |
| 14/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_dat_snoop_outgoing_arp_request",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/distributed-arp-table.c=1199=batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,\n--\nnet/batman-adv/distributed-arp-table.c-1219-/**\nnet/batman-adv/distributed-arp-table.c:1220: * batadv_dat_snoop_outgoing_arp_request() - snoop the ARP request and try to\nnet/batman-adv/distributed-arp-table.c-1221- * answer using DAT\n--\nnet/batman-adv/distributed-arp-table.c-1233- */\nnet/batman-adv/distributed-arp-table.c:1234:bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.c-1235-\t\t\t\t\t struct sk_buff *skb)\n--\nnet/batman-adv/distributed-arp-table.h=26=void batadv_dat_status_update(struct net_device *net_dev);\nnet/batman-adv/distributed-arp-table.h:27:bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-28-\t\t\t\t\t struct sk_buff *skb);\n--\nnet/batman-adv/distributed-arp-table.h=106=static inline bool\nnet/batman-adv/distributed-arp-table.h:107:batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-108-\t\t\t\t struct sk_buff *skb)\n--\nnet/batman-adv/mesh-interface.c=213=static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n--\nnet/batman-adv/mesh-interface.c-372-\t\t */\nnet/batman-adv/mesh-interface.c:373:\t\tif (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))\nnet/batman-adv/mesh-interface.c-374-\t\t\tbrd_delay = msecs_to_jiffies(ARP_REQ_DELAY);\n--\nnet/batman-adv/mesh-interface.c-411-\t\t} else {\nnet/batman-adv/mesh-interface.c:412:\t\t\tif (batadv_dat_snoop_outgoing_arp_request(bat_priv,\nnet/batman-adv/mesh-interface.c-413-\t\t\t\t\t\t\t\t skb))\n"
} |
| 15/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 90068 output: 35 thoughts: 71 Thoughts: **Fuzzing Target Identification** Okay, so I'm looking at how traffic flows in this Batfish setup. The function `batadv_dat_snoop_outgoing_arp_request` is triggered by `batadv_interface_tx`, which is essentially the core transmission function, `ndo_start_xmit`, of the `bat0` interface. That's a direct, measurable path. It's definitely reachable under normal operation, making it a prime candidate for fuzzing. Given my experience, a likely target to find exploitable bugs. Now, let's also investigate the call graph leading to `batadv_tt_local_add`. I have a feeling there might be some interesting data manipulation going on there. |
| 16/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_local_add",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/mesh-interface.c=141=static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)\n--\nnet/batman-adv/mesh-interface.c-161-\t\t\t\t \"mac address changed\", false);\nnet/batman-adv/mesh-interface.c:162:\t\tbatadv_tt_local_add(dev, addr-\u003esa_data, vlan-\u003evid,\nnet/batman-adv/mesh-interface.c-163-\t\t\t\t BATADV_NULL_IFINDEX, BATADV_NO_MARK);\n--\nnet/batman-adv/mesh-interface.c=213=static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n--\nnet/batman-adv/mesh-interface.c-285-\t !batadv_bla_is_loopdetect_mac(ethhdr-\u003eh_source)) {\nnet/batman-adv/mesh-interface.c:286:\t\tclient_added = batadv_tt_local_add(mesh_iface, ethhdr-\u003eh_source,\nnet/batman-adv/mesh-interface.c-287-\t\t\t\t\t\t vid, skb-\u003eskb_iif,\n--\nnet/batman-adv/mesh-interface.c=600=int batadv_meshif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)\n--\nnet/batman-adv/mesh-interface.c-631-\t */\nnet/batman-adv/mesh-interface.c:632:\tbatadv_tt_local_add(bat_priv-\u003emesh_iface,\nnet/batman-adv/mesh-interface.c-633-\t\t\t bat_priv-\u003emesh_iface-\u003edev_addr, vid,\n--\nnet/batman-adv/mesh-interface.c=670=static int batadv_interface_add_vid(struct net_device *dev, __be16 proto,\n--\nnet/batman-adv/mesh-interface.c-705-\t */\nnet/batman-adv/mesh-interface.c:706:\tbatadv_tt_local_add(bat_priv-\u003emesh_iface,\nnet/batman-adv/mesh-interface.c-707-\t\t\t bat_priv-\u003emesh_iface-\u003edev_addr, vid,\n--\nnet/batman-adv/multicast.c=714=static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/multicast.c-727-\nnet/batman-adv/multicast.c:728:\t\tif (!batadv_tt_local_add(bat_priv-\u003emesh_iface,\nnet/batman-adv/multicast.c-729-\t\t\t\t\t mcast_entry-\u003eaddr, BATADV_NO_FLAGS,\n--\nnet/batman-adv/translation-table.c=574=static void batadv_tt_global_free(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-600-/**\nnet/batman-adv/translation-table.c:601: * batadv_tt_local_add() - add a new client to the local table or update an\nnet/batman-adv/translation-table.c-602- * existing client\n--\nnet/batman-adv/translation-table.c-612- */\nnet/batman-adv/translation-table.c:613:bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\nnet/batman-adv/translation-table.c-614-\t\t\t unsigned short vid, int ifindex, u32 mark)\n--\nnet/batman-adv/translation-table.h=18=int batadv_tt_init(struct batadv_priv *bat_priv);\nnet/batman-adv/translation-table.h:19:bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\nnet/batman-adv/translation-table.h-20-\t\t\t unsigned short vid, int ifindex, u32 mark);\n"
} |
| 17/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 91391 output: 35 thoughts: 37 Thoughts: Here's a summary of my immediate thought process: **Diving into the batadv Codebase** Okay, so I'm digging into this `batadv` code and I see that `batadv_tt_local_add` is also invoked from within `batadv_interface_tx`. That's a key point to remember; it affects the possible control flow and how we might analyze its impact. Given that connection, I think it's time to shift my focus and start looking closely at `batadv_bla_add_claim`. That seems to be the next logical step in understanding the overall behavior, particularly in the context of `batadv_interface_tx`. |
| 18/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_bla_add_claim",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/bridge_loop_avoidance.c=663=static void batadv_bla_send_announce(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/bridge_loop_avoidance.c-679-/**\nnet/batman-adv/bridge_loop_avoidance.c:680: * batadv_bla_add_claim() - Adds a claim in the claim hash\nnet/batman-adv/bridge_loop_avoidance.c-681- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/bridge_loop_avoidance.c-685- */\nnet/batman-adv/bridge_loop_avoidance.c:686:static void batadv_bla_add_claim(struct batadv_priv *bat_priv,\nnet/batman-adv/bridge_loop_avoidance.c-687-\t\t\t\t const u8 *mac, const unsigned short vid,\n--\nnet/batman-adv/bridge_loop_avoidance.c=985=static bool batadv_handle_claim(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/bridge_loop_avoidance.c-1000-\t/* this must be a CLAIM frame */\nnet/batman-adv/bridge_loop_avoidance.c:1001:\tbatadv_bla_add_claim(bat_priv, claim_addr, vid, backbone_gw);\nnet/batman-adv/bridge_loop_avoidance.c-1002-\tif (batadv_compare_eth(backbone_addr, primary_if-\u003enet_dev-\u003edev_addr))\n"
} |
| 19/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 92029 output: 40 thoughts: 164 Thoughts: **Tracing the Network Claim Flow** Okay, so I'm mentally mapping out how these claim mechanisms are integrated within the broader Batman-adv framework. It looks like `batadv_bla_add_claim` is the crux of the claim process, and it's being initiated from `batadv_handle_claim`. Now, `batadv_handle_claim` is triggered by `batadv_bla_process_claim`. So far, so good – makes logical sense. Now, where does `batadv_bla_process_claim` fit in? It's called from both `batadv_bla_rx` and `batadv_bla_tx`. Okay, that suggests it handles both incoming and outgoing claim-related data. I'll need to drill down deeper to understand the specifics of the processing. `batadv_bla_tx`, in turn, is called from `batadv_interface_tx`, which is pretty low-level, at the interface layer. This shows its deeply integrated within the sending process. On the receive side, `batadv_bla_rx` is called from two primary points: `batadv_batman_skb_recv` (which uses a whole string of functions like `batadv_recv_bcast_packet`, etc.) and also `batadv_interface_rx`. So, both broadcast and interface receptions are involved. Alright, so the claims process flows from reception and transmission, through processing and handling to claiming, which is expected. Looks like everything is reachable and functional from within the module, based on how the function calls are arranged. Now, let's switch gears and check out `batadv_dat_snoop_outgoing_arp_reply` to understand how the snooping function works. |
| 20/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_dat_snoop_outgoing_arp_reply",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/distributed-arp-table.c=1343=bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1405-/**\nnet/batman-adv/distributed-arp-table.c:1406: * batadv_dat_snoop_outgoing_arp_reply() - snoop the ARP reply and fill the DHT\nnet/batman-adv/distributed-arp-table.c-1407- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/distributed-arp-table.c-1414- */\nnet/batman-adv/distributed-arp-table.c:1415:void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.c-1416-\t\t\t\t\t struct sk_buff *skb)\n--\nnet/batman-adv/distributed-arp-table.h=29=bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-30-\t\t\t\t\t struct sk_buff *skb, int hdr_size);\nnet/batman-adv/distributed-arp-table.h:31:void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-32-\t\t\t\t\t struct sk_buff *skb);\n--\nnet/batman-adv/distributed-arp-table.h=120=static inline bool\nnet/batman-adv/distributed-arp-table.h:121:batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-122-\t\t\t\t struct sk_buff *skb)\n--\nnet/batman-adv/mesh-interface.c=213=static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n--\nnet/batman-adv/mesh-interface.c-415-\nnet/batman-adv/mesh-interface.c:416:\t\t\tbatadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);\nnet/batman-adv/mesh-interface.c-417-\n"
} |
| 21/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 93240 output: 35 thoughts: 43 Thoughts: Okay, here's my interpretation of those thoughts, presented as my own mental process, given my expertise: **Checking ARP Reply Handling Within BATMAN-adv's Data Path** Right, so `batadv_dat_snoop_outgoing_arp_reply`. I recall seeing that function name – it definitely sounds like part of the ARP handling logic for outbound packets within BATMAN-adv's data plane. The text confirms that it's called from `batadv_interface_tx`. That makes sense; `batadv_interface_tx` is the primary transmit function, so it's the natural place to insert checks and modifications to packets *before* they're sent out the interface. This all feels consistent with my understanding of how BATMAN-adv handles data transmission. I'm satisfied so far. Now, let's switch gears a bit. I need to refresh my memory on some of the TT (tunneling table) operations, since outbound ARP reply snooping could be interacting with how addresses are resolved. I'll need to double check the TT interaction. That might involve how things are added to the table. Let me check `batadv_tt_global_add`, and see how the tunnel entry is inserted. |
| 22/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_global_add",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/translation-table.c=1643=batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,\n--\nnet/batman-adv/translation-table.c-1686-/**\nnet/batman-adv/translation-table.c:1687: * batadv_tt_global_add() - add a new TT global entry or update an existing one\nnet/batman-adv/translation-table.c-1688- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/translation-table.c-1704- */\nnet/batman-adv/translation-table.c:1705:static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\nnet/batman-adv/translation-table.c-1706-\t\t\t\t struct batadv_orig_node *orig_node,\n--\nnet/batman-adv/translation-table.c=3475=static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-3491-\t\t} else {\nnet/batman-adv/translation-table.c:3492:\t\t\tif (!batadv_tt_global_add(bat_priv, orig_node,\nnet/batman-adv/translation-table.c-3493-\t\t\t\t\t\t (tt_change + i)-\u003eaddr,\n--\nnet/batman-adv/translation-table.c=4178=bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-4188-\nnet/batman-adv/translation-table.c:4189:\tif (!batadv_tt_global_add(bat_priv, orig_node, addr, vid,\nnet/batman-adv/translation-table.c-4190-\t\t\t\t BATADV_TT_CLIENT_TEMP,\n--\nnet/batman-adv/translation-table.c=4378=static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-4406-\nnet/batman-adv/translation-table.c:4407:\tbatadv_tt_global_add(bat_priv, orig_node, roaming_adv-\u003eclient,\nnet/batman-adv/translation-table.c-4408-\t\t\t ntohs(roaming_adv-\u003evid), BATADV_TT_CLIENT_ROAM,\n"
} |
| 23/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 94259 output: 35 thoughts: 203 Thoughts: **Tracing the TT Entry Management Calls** Okay, so I'm diving into this batadv code and need to understand the call graph for managing the translation table (TT) entries. It's clear that `batadv_tt_global_add` is a crucial function, and it's being called from several key points: `_batadv_tt_update_changes`, `batadv_tt_add_temporary_global_entry`, and also interestingly, `batadv_roam_tvlv_unicast_handler_v1`. That last one suggests it's involved in roaming scenarios, which makes sense. Now, `_batadv_tt_update_changes` gets called from `batadv_tt_update_changes` and `batadv_tt_fill_gtable`. That makes a bit more sense. `batadv_tt_update_changes` itself is triggered by `batadv_tt_tvlv_ogm_handler_v1` – so OGM (Originator Generated Message) processing is clearly a trigger for table updates. `batadv_tt_fill_gtable`, is interestingly called from `batadv_handle_tt_response`, so it must be updating the table from responses. Finally, and I think this is important, `batadv_tt_add_temporary_global_entry` which also calls `batadv_tt_global_add`, is called from `batadv_reroute_unicast_packet` – so unicast routing is adding entries and clearly using temp entries. The fact that `batadv_tt_global_add` is so reachable tells me this is a core function, touched by all the main events, meaning it's highly utilized. Alright, now it’s time to look at the removal side, let’s check `batadv_tt_local_remove` to complete my analysis. |
| 24/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_local_remove",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/mesh-interface.c=141=static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)\n--\nnet/batman-adv/mesh-interface.c-159-\thlist_for_each_entry_rcu(vlan, \u0026bat_priv-\u003emeshif_vlan_list, list) {\nnet/batman-adv/mesh-interface.c:160:\t\tbatadv_tt_local_remove(bat_priv, old_addr, vlan-\u003evid,\nnet/batman-adv/mesh-interface.c-161-\t\t\t\t \"mac address changed\", false);\n--\nnet/batman-adv/mesh-interface.c=647=void batadv_meshif_destroy_vlan(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/mesh-interface.c-652-\t */\nnet/batman-adv/mesh-interface.c:653:\tbatadv_tt_local_remove(bat_priv, bat_priv-\u003emesh_iface-\u003edev_addr,\nnet/batman-adv/mesh-interface.c-654-\t\t\t vlan-\u003evid, \"vlan interface destroyed\", false);\n--\nnet/batman-adv/multicast.c=684=static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/multicast.c-696-\nnet/batman-adv/multicast.c:697:\t\tbatadv_tt_local_remove(bat_priv, mcast_entry-\u003eaddr,\nnet/batman-adv/multicast.c-698-\t\t\t\t BATADV_NO_FLAGS,\n--\nnet/batman-adv/translation-table.c=1294=batadv_tt_local_set_pending(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-1312-/**\nnet/batman-adv/translation-table.c:1313: * batadv_tt_local_remove() - logically remove an entry from the local table\nnet/batman-adv/translation-table.c-1314- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/translation-table.c-1321- */\nnet/batman-adv/translation-table.c:1322:u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,\nnet/batman-adv/translation-table.c-1323-\t\t\t unsigned short vid, const char *message,\n--\nnet/batman-adv/translation-table.c=1705=static bool batadv_tt_global_add(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-1850-\t/* remove address from local hash if present */\nnet/batman-adv/translation-table.c:1851:\tlocal_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,\nnet/batman-adv/translation-table.c-1852-\t\t\t\t\t \"global tt received\",\n--\nnet/batman-adv/translation-table.h=19=bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,\nnet/batman-adv/translation-table.h-20-\t\t\t unsigned short vid, int ifindex, u32 mark);\nnet/batman-adv/translation-table.h:21:u16 batadv_tt_local_remove(struct batadv_priv *bat_priv,\nnet/batman-adv/translation-table.h-22-\t\t\t const u8 *addr, unsigned short vid,\n"
} |
| 25/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 95863 output: 37 thoughts: 78 Thoughts: Here's my thought process, as requested: **Analyzing the Callers of `batadv_tt_local_remove`** Okay, so I need to understand the implications of the `batadv_tt_local_remove` function. I see that it's called from several other functions: `batadv_tt_global_add`, `batadv_mcast_mla_tt_retract`, `batadv_meshif_destroy_vlan`, and `batadv_interface_set_mac_addr`. This tells me immediately that removing a local TT entry isn't just a simple operation; it's triggered by various events across the mesh network's lifecycle, from initial TT additions to VLAN destruction and even interface MAC address changes. Understanding these callers is key to grasping the scenarios where a local TT entry is deemed no longer valid or necessary. Now, given this context, I should probably also quickly refresh myself on the synchronization flags and operations surrounding the global TT table. So let's investigate how `batadv_tt_global_sync_flags` fits into this picture. I expect that synchronization will need to happen after removal to make sure everything stays in order. |
| 26/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_global_sync_flags",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/translation-table.c=1582=batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,\n--\nnet/batman-adv/translation-table.c-1602-/**\nnet/batman-adv/translation-table.c:1603: * batadv_tt_global_sync_flags() - update TT sync flags\nnet/batman-adv/translation-table.c-1604- * @tt_global: the TT global entry to update sync flags in\n--\nnet/batman-adv/translation-table.c=1609=static void\nnet/batman-adv/translation-table.c:1610:batadv_tt_global_sync_flags(struct batadv_tt_global_entry *tt_global)\nnet/batman-adv/translation-table.c-1611-{\n--\nnet/batman-adv/translation-table.c=1643=batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,\n--\nnet/batman-adv/translation-table.c-1678-sync_flags:\nnet/batman-adv/translation-table.c:1679:\tbatadv_tt_global_sync_flags(tt_global);\nnet/batman-adv/translation-table.c-1680-out:\n"
} |
| 27/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 96592 output: 37 thoughts: 60 Thoughts: Here's my take on the thought process, as requested: **Navigating the Batadv Table Management** Okay, so I'm looking at how the batadv table management functions. I've tracked down that `batadv_tt_global_sync_flags` gets called by `batadv_tt_global_orig_entry_add`. And that in turn is called from `batadv_tt_global_add`. This gives me a good starting point to understand the overall flow: we're likely dealing with some synchronization of flags during the addition of an origin entry to the global table. Now, the next logical step is to dive into the other local table transition function that is used to sync information. Let me see what `batadv_tt_local_transition_new` is doing. This should fill out the picture. |
| 28/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_local_transition_new",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/translation-table.c=3837=void batadv_tt_free(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/translation-table.c-3855-/**\nnet/batman-adv/translation-table.c:3856: * batadv_tt_local_transition_new() - unset the NEW flag on the local\nnet/batman-adv/translation-table.c-3857- * table and count them in the TT size\n--\nnet/batman-adv/translation-table.c-3859- */\nnet/batman-adv/translation-table.c:3860:static void batadv_tt_local_transition_new(struct batadv_priv *bat_priv)\nnet/batman-adv/translation-table.c-3861-{\n--\nnet/batman-adv/translation-table.c=3951=static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/translation-table.c-3960-\nnet/batman-adv/translation-table.c:3961:\tbatadv_tt_local_transition_new(bat_priv);\nnet/batman-adv/translation-table.c-3962-\n"
} |
| 29/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 97210 output: 35 thoughts: 116 Thoughts: **Analyzing the `batadv_tt` Transition Process** Okay, let's break down this connection. It looks like `batadv_tt_local_transition_new` is being triggered by a chain of function calls. Specifically, it's called from `batadv_tt_local_commit_changes_nolock`, which itself is invoked by `batadv_tt_local_commit_changes`. Now, where does *that* fit in? `batadv_tt_local_commit_changes` seems to be the critical point, called by both `batadv_tt_purge` and `batadv_tt_local_resize_to_mtu`. Knowing that `batadv_tt_purge` is a work queue function is important. It implies some level of asynchronous operation, which might influence the timing or nature of the transition. Given this context, it's logical to dive deeper into `batadv_bla_process_claim` next. Understanding how claims are processed should provide critical context for any transition or committing operations. |
| 30/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_bla_process_claim",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/bridge_loop_avoidance.c=1029=static int batadv_check_claim_group(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/bridge_loop_avoidance.c-1088-/**\nnet/batman-adv/bridge_loop_avoidance.c:1089: * batadv_bla_process_claim() - Check if this is a claim frame, and process it\nnet/batman-adv/bridge_loop_avoidance.c-1090- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/bridge_loop_avoidance.c-1101- */\nnet/batman-adv/bridge_loop_avoidance.c:1102:static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,\nnet/batman-adv/bridge_loop_avoidance.c-1103-\t\t\t\t struct batadv_hard_iface *primary_if,\n--\nnet/batman-adv/bridge_loop_avoidance.c=2097=bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,\n--\nnet/batman-adv/bridge_loop_avoidance.c-2114-\nnet/batman-adv/bridge_loop_avoidance.c:2115:\tif (batadv_bla_process_claim(bat_priv, primary_if, skb))\nnet/batman-adv/bridge_loop_avoidance.c-2116-\t\tgoto handled;\n"
} |
| 31/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 97995 output: 43 thoughts: 37 Thoughts: Here's my summary, as the thought process unfolds: **Digging into `batadv_bla_process_claim`'s Callers** Okay, hold on a second. I just realized something potentially important. I'm looking at `batadv_bla_process_claim` and, wait a minute, isn't that also called from `batadv_bla_rx`? I need to verify that. It feels like a key point in understanding the control flow and potential race conditions, so I need to go back and cross-reference. Let's get into `batadv_bla_rx` and trace the call. Better to be certain now, and save time down the line. |
| 32/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_bla_process_claim",
"PathPrefix": "net/batman-adv/bridge_loop_avoidance.c"
}Results: {
"Output": "net/batman-adv/bridge_loop_avoidance.c=1029=static int batadv_check_claim_group(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/bridge_loop_avoidance.c-1088-/**\nnet/batman-adv/bridge_loop_avoidance.c:1089: * batadv_bla_process_claim() - Check if this is a claim frame, and process it\nnet/batman-adv/bridge_loop_avoidance.c-1090- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/bridge_loop_avoidance.c-1101- */\nnet/batman-adv/bridge_loop_avoidance.c:1102:static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,\nnet/batman-adv/bridge_loop_avoidance.c-1103-\t\t\t\t struct batadv_hard_iface *primary_if,\n--\nnet/batman-adv/bridge_loop_avoidance.c=2097=bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,\n--\nnet/batman-adv/bridge_loop_avoidance.c-2114-\nnet/batman-adv/bridge_loop_avoidance.c:2115:\tif (batadv_bla_process_claim(bat_priv, primary_if, skb))\nnet/batman-adv/bridge_loop_avoidance.c-2116-\t\tgoto handled;\n"
} |
| 33/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 98635 output: 35 thoughts: 37 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Analyzing `batadv_bla` Function Calls** Okay, so `batadv_bla_process_claim` is looking a little isolated. The code seems to indicate that it's only called directly from `batadv_bla_tx`. That's a potential area for closer inspection. I need to understand the complete picture, not just the transmission side. Let me quickly cross-reference that with the receiver path and see if `batadv_bla_rx` provides any insight into the process or if it might call this function as well. My understanding is, that these functions would need to sync to avoid any race conditions. |
| 34/2 | 2026/07/29 18:06 | tool | grepper |
0mArgs:{
"Expression": "batadv_bla_process_claim",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/bridge_loop_avoidance.c=1029=static int batadv_check_claim_group(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/bridge_loop_avoidance.c-1088-/**\nnet/batman-adv/bridge_loop_avoidance.c:1089: * batadv_bla_process_claim() - Check if this is a claim frame, and process it\nnet/batman-adv/bridge_loop_avoidance.c-1090- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/bridge_loop_avoidance.c-1101- */\nnet/batman-adv/bridge_loop_avoidance.c:1102:static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,\nnet/batman-adv/bridge_loop_avoidance.c-1103-\t\t\t\t struct batadv_hard_iface *primary_if,\n--\nnet/batman-adv/bridge_loop_avoidance.c=2097=bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,\n--\nnet/batman-adv/bridge_loop_avoidance.c-2114-\nnet/batman-adv/bridge_loop_avoidance.c:2115:\tif (batadv_bla_process_claim(bat_priv, primary_if, skb))\nnet/batman-adv/bridge_loop_avoidance.c-2116-\t\tgoto handled;\n"
} |
| 35/2 | 2026/07/29 18:06 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 99268 output: 41 thoughts: 66 Thoughts: Here's my thought process, as if I were analyzing this code: **Analyzing the Call Chain** Alright, so `batadv_bla_process_claim` is definitely the key function here, and it looks like it's only invoked by `batadv_bla_tx`. That's a good starting point. Now, to understand the broader context, I need to see *where* `batadv_bla_tx` is called. It seems it's called from `batadv_interface_tx`. Okay, that gives me a high-level view of the execution flow. I need to understand this whole calling tree now. My next step will be to explore the `batadv_dat_snoop_outgoing_dhcp_ack` function to better understand how everything fits together. |
| 36/2 | 2026/07/29 18:07 | tool | grepper |
0mArgs:{
"Expression": "batadv_dat_snoop_outgoing_dhcp_ack",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/distributed-arp-table.c=1820=batadv_dat_check_dhcp_ack(struct sk_buff *skb, __be16 proto, __be32 *ip_src,\n--\nnet/batman-adv/distributed-arp-table.c-1842-/**\nnet/batman-adv/distributed-arp-table.c:1843: * batadv_dat_snoop_outgoing_dhcp_ack() - snoop DHCPACK and fill DAT with it\nnet/batman-adv/distributed-arp-table.c-1844- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/distributed-arp-table.c-1856- */\nnet/batman-adv/distributed-arp-table.c:1857:void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.c-1858-\t\t\t\t\tstruct sk_buff *skb,\n--\nnet/batman-adv/distributed-arp-table.h=33=bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-34-\t\t\t\t\t struct sk_buff *skb, int hdr_size);\nnet/batman-adv/distributed-arp-table.h:35:void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-36-\t\t\t\t\tstruct sk_buff *skb,\n--\nnet/batman-adv/distributed-arp-table.h=134=static inline void\nnet/batman-adv/distributed-arp-table.h:135:batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-136-\t\t\t\t struct sk_buff *skb, __be16 proto,\n--\nnet/batman-adv/mesh-interface.c=213=static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n--\nnet/batman-adv/mesh-interface.c-293-\t/* Snoop address candidates from DHCPACKs for early DAT filling */\nnet/batman-adv/mesh-interface.c:294:\tbatadv_dat_snoop_outgoing_dhcp_ack(bat_priv, skb, proto, vid);\nnet/batman-adv/mesh-interface.c-295-\n"
} |
| 37/2 | 2026/07/29 18:07 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 100217 output: 41 thoughts: 50 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing BATMAN-Adv DHCP ACK Handling** Alright, so I'm mentally tracing through the BATMAN-Adv DHCP ACK code flow. Right, I'm confirming that `batadv_dat_snoop_outgoing_dhcp_ack` is indeed invoked directly from `batadv_interface_tx`. That makes sense; it's the point where we're about to put a DHCP ACK packet onto the wire. Now, the next logical step is to dive into the incoming side of this. Let's see how `batadv_dat_snoop_incoming_dhcp_ack` handles these DHCP responses. Need to understand the full picture, from transmission to reception. |
| 38/2 | 2026/07/29 18:07 | tool | grepper |
0mArgs:{
"Expression": "batadv_dat_snoop_incoming_dhcp_ack",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/distributed-arp-table.c=1857=void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1876-/**\nnet/batman-adv/distributed-arp-table.c:1877: * batadv_dat_snoop_incoming_dhcp_ack() - snoop DHCPACK and fill DAT cache\nnet/batman-adv/distributed-arp-table.c-1878- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/distributed-arp-table.c-1890- */\nnet/batman-adv/distributed-arp-table.c:1891:void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.c-1892-\t\t\t\t\tstruct sk_buff *skb, int hdr_size)\n--\nnet/batman-adv/distributed-arp-table.h=35=void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.h-38-\t\t\t\t\tunsigned short vid);\nnet/batman-adv/distributed-arp-table.h:39:void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-40-\t\t\t\t\tstruct sk_buff *skb, int hdr_size);\n--\nnet/batman-adv/distributed-arp-table.h=141=static inline void\nnet/batman-adv/distributed-arp-table.h:142:batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-143-\t\t\t\t struct sk_buff *skb, int hdr_size)\n--\nnet/batman-adv/routing.c=1039=int batadv_recv_unicast_packet(struct sk_buff *skb,\n--\nnet/batman-adv/routing.c-1117-\nnet/batman-adv/routing.c:1118:\t\tbatadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);\nnet/batman-adv/routing.c-1119-\n--\nnet/batman-adv/routing.c=1263=int batadv_recv_bcast_packet(struct sk_buff *skb,\n--\nnet/batman-adv/routing.c-1358-\nnet/batman-adv/routing.c:1359:\tbatadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);\nnet/batman-adv/routing.c-1360-\n"
} |
| 39/2 | 2026/07/29 18:07 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 101234 output: 37 thoughts: 61 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing DHCP ACK Processing in B.A.T.M.A.N.** Alright, let's see. My mental map is guiding me. I'm recalling that `batadv_dat_snoop_incoming_dhcp_ack` is definitely a key function for handling DHCP acknowledgements within B.A.T.M.A.N. as expected. I'm quite confident in that association; it's called during incoming unicast packets via `batadv_recv_unicast_packet` as well as broadcast packets via `batadv_recv_bcast_packet` which makes sense for the protocol. So, where do these packets get dropped? This line of thinking now guides me to investigating the `batadv_dat_drop_broadcast_packet` function. This would be the next logical step. I need to understand the criteria involved in that broadcast packet dropping. Is it some form of filtering, rate limiting, or a specific condition related to DHCP, or is this happening elsewhere in the flow? I need to understand that. |
| 40/2 | 2026/07/29 18:07 | tool | grepper |
0mArgs:{
"Expression": "batadv_dat_drop_broadcast_packet",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/distributed-arp-table.c=1891=void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/distributed-arp-table.c-1932-/**\nnet/batman-adv/distributed-arp-table.c:1933: * batadv_dat_drop_broadcast_packet() - check if an ARP request has to be\nnet/batman-adv/distributed-arp-table.c-1934- * dropped (because the node has already obtained the reply via DAT) or not\n--\nnet/batman-adv/distributed-arp-table.c-1944- */\nnet/batman-adv/distributed-arp-table.c:1945:bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.c-1946-\t\t\t\t struct batadv_forw_packet *forw_packet)\n--\nnet/batman-adv/distributed-arp-table.h=39=void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-40-\t\t\t\t\tstruct sk_buff *skb, int hdr_size);\nnet/batman-adv/distributed-arp-table.h:41:bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-42-\t\t\t\t struct batadv_forw_packet *forw_packet);\n--\nnet/batman-adv/distributed-arp-table.h=147=static inline bool\nnet/batman-adv/distributed-arp-table.h:148:batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,\nnet/batman-adv/distributed-arp-table.h-149-\t\t\t\t struct batadv_forw_packet *forw_packet)\n--\nnet/batman-adv/send.c=1037=static void batadv_send_outstanding_bcast_packet(struct work_struct *work)\n--\nnet/batman-adv/send.c-1055-\nnet/batman-adv/send.c:1056:\tif (batadv_dat_drop_broadcast_packet(bat_priv, forw_packet)) {\nnet/batman-adv/send.c-1057-\t\tdropped = true;\n"
} |
| 41/2 | 2026/07/29 18:07 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 102220 output: 36 thoughts: 53 Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing: **Analyzing Packet Handling in BATMAN Advanced** Right, so I'm digging into how broadcast packets are managed in BATMAN-adv. I see that `batadv_dat_drop_broadcast_packet` gets called directly from `batadv_send_outstanding_bcast_packet`. That's important, and it immediately clues me in to the fact that `batadv_send_outstanding_bcast_packet` runs within a work queue context. Makes sense – broadcast packets need to be handled reliably but potentially with a bit of a delay to avoid overwhelming the system. Now, I need to understand *why* a broadcast packet might be dropped. Let's pivot and take a look at the `batadv_frag_skb_buffer` function. I have a hunch that fragmentation and reassembly might be playing a role here. I need to see how packets are buffered and handled in relation to potential fragmentation, because that's often where broadcast packet issues pop up. I need to understand if the "drop" is related to some kind of buffer overflow or resource limitation during fragmentation. I expect there's probably some intricate interplay between the fragmentation process and broadcast packet prioritization, so this is where I need to focus my attention. |
| 42/2 | 2026/07/29 18:07 | tool | grepper |
0mArgs:{
"Expression": "batadv_frag_skb_buffer",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/fragmentation.c=318=static bool batadv_skb_is_frag(struct sk_buff *skb)\n--\nnet/batman-adv/fragmentation.c-337-/**\nnet/batman-adv/fragmentation.c:338: * batadv_frag_skb_buffer() - buffer fragment for later merge\nnet/batman-adv/fragmentation.c-339- * @skb: skb to buffer\n--\nnet/batman-adv/fragmentation.c-350- */\nnet/batman-adv/fragmentation.c:351:bool batadv_frag_skb_buffer(struct sk_buff **skb,\nnet/batman-adv/fragmentation.c-352-\t\t\t struct batadv_orig_node *orig_node_src)\n--\nnet/batman-adv/fragmentation.h=20=bool batadv_frag_skb_fwd(struct sk_buff *skb,\n--\nnet/batman-adv/fragmentation.h-23-\t\t\t int *rx_result);\nnet/batman-adv/fragmentation.h:24:bool batadv_frag_skb_buffer(struct sk_buff **skb,\nnet/batman-adv/fragmentation.h-25-\t\t\t struct batadv_orig_node *orig_node);\n--\nnet/batman-adv/routing.c=1202=int batadv_recv_frag_packet(struct sk_buff *skb,\n--\nnet/batman-adv/routing.c-1232-\t/* Add fragment to buffer and merge if possible. */\nnet/batman-adv/routing.c:1233:\tif (!batadv_frag_skb_buffer(\u0026skb, orig_node_src))\nnet/batman-adv/routing.c-1234-\t\tgoto put_orig_node;\n"
} |
| 43/2 | 2026/07/29 18:07 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 103063 output: 37 thoughts: 43 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating the BATMAN-adv Packet Fragment Handling** Alright, so I'm thinking about how packet fragmentation is handled within BATMAN-adv. Specifically, I recall `batadv_frag_skb_buffer` being the function responsible for managing the buffer used for fragment reassembly. Right, that function is indeed called from within `batadv_recv_frag_packet`. Makes sense, that's where the incoming fragments are processed, so the buffering logic should be there. Now, to get a better handle on how all this works, it's worth taking a look at how those buffers get forwarded on. Let me switch gears and check out the `batadv_frag_skb_fwd` function next; that'll probably tell me the story of how a reassembled packet gets sent upwards after the fragments are put back together. |
| 44/2 | 2026/07/29 18:07 | tool | grepper |
0mArgs:{
"Expression": "batadv_frag_skb_fwd",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/fragmentation.c=351=bool batadv_frag_skb_buffer(struct sk_buff **skb,\n--\nnet/batman-adv/fragmentation.c-387-/**\nnet/batman-adv/fragmentation.c:388: * batadv_frag_skb_fwd() - forward fragments that would exceed MTU when merged\nnet/batman-adv/fragmentation.c-389- * @skb: skb to forward\n--\nnet/batman-adv/fragmentation.c-400- */\nnet/batman-adv/fragmentation.c:401:bool batadv_frag_skb_fwd(struct sk_buff *skb,\nnet/batman-adv/fragmentation.c-402-\t\t\t struct batadv_hard_iface *recv_if,\n--\nnet/batman-adv/fragmentation.h=18=void batadv_frag_purge_orig(struct batadv_orig_node *orig,\nnet/batman-adv/fragmentation.h-19-\t\t\t bool (*check_cb)(struct batadv_frag_table_entry *));\nnet/batman-adv/fragmentation.h:20:bool batadv_frag_skb_fwd(struct sk_buff *skb,\nnet/batman-adv/fragmentation.h-21-\t\t\t struct batadv_hard_iface *recv_if,\n--\nnet/batman-adv/routing.c=1202=int batadv_recv_frag_packet(struct sk_buff *skb,\n--\nnet/batman-adv/routing.c-1222-\tif (!batadv_is_my_mac(bat_priv, frag_packet-\u003edest) \u0026\u0026\nnet/batman-adv/routing.c:1223:\t batadv_frag_skb_fwd(skb, recv_if, orig_node_src, \u0026ret)) {\nnet/batman-adv/routing.c-1224-\t\t/* skb was consumed */\n"
} |
| 45/2 | 2026/07/29 18:07 | llm | patch-evaluator |
1mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 103852 output: 35 thoughts: 42 Thoughts: Okay, here's my interpretation of those thoughts, crafted with an expert audience in mind: **Analyzing the Batadv Fragment Handling** Alright, so `batadv_frag_skb_fwd` is definitely called from within `batadv_recv_frag_packet`. That confirms a key aspect of the fragment handling flow. Now, I need to understand the outbound path a bit better. The logical next step in tracing this logic is to investigate `batadv_frag_send_packet`. I need to review how the outbound fragment sending is actually handled. That should clarify the relationship and full process for handling batadv fragments. |
| 46/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_frag_send_packet",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/fragmentation.c=467=static struct sk_buff *batadv_frag_create(struct net_device *net_dev,\n--\nnet/batman-adv/fragmentation.c-497-/**\nnet/batman-adv/fragmentation.c:498: * batadv_frag_send_packet() - create up to 16 fragments from the passed skb\nnet/batman-adv/fragmentation.c-499- * @skb: skb to create fragments from\n--\nnet/batman-adv/fragmentation.c-504- */\nnet/batman-adv/fragmentation.c:505:int batadv_frag_send_packet(struct sk_buff *skb,\nnet/batman-adv/fragmentation.c-506-\t\t\t struct batadv_orig_node *orig_node,\n--\nnet/batman-adv/fragmentation.h=24=bool batadv_frag_skb_buffer(struct sk_buff **skb,\nnet/batman-adv/fragmentation.h-25-\t\t\t struct batadv_orig_node *orig_node);\nnet/batman-adv/fragmentation.h:26:int batadv_frag_send_packet(struct sk_buff *skb,\nnet/batman-adv/fragmentation.h-27-\t\t\t struct batadv_orig_node *orig_node,\n--\nnet/batman-adv/send.c=170=int batadv_send_skb_to_orig(struct sk_buff *skb,\n--\nnet/batman-adv/send.c-190-\t\t/* Fragment and send packet. */\nnet/batman-adv/send.c:191:\t\tret = batadv_frag_send_packet(skb, orig_node, neigh_node);\nnet/batman-adv/send.c-192-\t\t/* skb was consumed */\n"
} |
| 47/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 104544 output: 37 thoughts: 45 Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective: **Diving into the Batadv Packet Transmission Logic** Alright, so the task at hand is to pinpoint where the fragmentation function, `batadv_frag_send_packet`, is being called within the Batadv mesh networking code. The first thing that comes to mind is the likely candidate: `batadv_send_skb_to_orig`. Yes, that feels right, that's the point where an SKB (Socket Buffer) destined for the origin node would potentially be fragmented. Now, let's just make absolutely sure we're on the right track. My next thought is to quickly verify the GW (Gateway) range check logic. I'll need to double check how the function `batadv_gw_out_of_range` is used because this is probably an important factor. My gut feeling is we'll find some linkage there. Let's see... |
| 48/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_gw_out_of_range",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/gateway_client.c=567=batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,\n--\nnet/batman-adv/gateway_client.c-672-/**\nnet/batman-adv/gateway_client.c:673: * batadv_gw_out_of_range() - check if the dhcp request destination is the best\nnet/batman-adv/gateway_client.c-674- * gateway\n--\nnet/batman-adv/gateway_client.c-691- */\nnet/batman-adv/gateway_client.c:692:bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,\nnet/batman-adv/gateway_client.c-693-\t\t\t struct sk_buff *skb)\n--\nnet/batman-adv/gateway_client.h=34=int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb);\nnet/batman-adv/gateway_client.h:35:bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb);\nnet/batman-adv/gateway_client.h-36-enum batadv_dhcp_recipient\n--\nnet/batman-adv/mesh-interface.c=213=static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n--\nnet/batman-adv/mesh-interface.c-401-\t\tif (dhcp_rcp == BATADV_DHCP_TO_SERVER) {\nnet/batman-adv/mesh-interface.c:402:\t\t\tret = batadv_gw_out_of_range(bat_priv, skb);\nnet/batman-adv/mesh-interface.c-403-\t\t\tif (ret)\n"
} |
| 49/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 105318 output: 37 thoughts: 42 Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing: **Analyzing `batadv_gw_out_of_range`** Right, so `batadv_gw_out_of_range` is definitely called from within `batadv_interface_tx`. Makes sense – the gateway range check needs to happen during transmission, as I would expect. Now, before I proceed with any deeper analysis, I want to take a quick look at `batadv_mcast_forw_mode`. I need to ensure that whatever logic is happening there is compatible with how `batadv_gw_out_of_range` is triggered. I'm especially keen to see how the forwarding mode interacts with range-based checks. Might be some subtle interactions to keep in mind, and that area is probably ripe for optimization or subtle improvement later. |
| 50/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_mcast_forw_mode",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/mesh-interface.c=213=static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,\n--\nnet/batman-adv/mesh-interface.c-342-\t\tif (do_bcast \u0026\u0026 !is_broadcast_ether_addr(ethhdr-\u003eh_dest)) {\nnet/batman-adv/mesh-interface.c:343:\t\t\t/* WARNING batadv_mcast_forw_mode might add more headers\nnet/batman-adv/mesh-interface.c-344-\t\t\t * in front of the skb. and might even reallocate the skb\nnet/batman-adv/mesh-interface.c-345-\t\t\t */\nnet/batman-adv/mesh-interface.c:346:\t\t\tforw_mode = batadv_mcast_forw_mode(bat_priv, skb, vid,\nnet/batman-adv/mesh-interface.c-347-\t\t\t\t\t\t\t \u0026mcast_is_routable);\n--\nnet/batman-adv/multicast.c=963=static bool batadv_mcast_is_report_ipv4(struct sk_buff *skb)\n--\nnet/batman-adv/multicast.c-978-/**\nnet/batman-adv/multicast.c:979: * batadv_mcast_forw_mode_check_ipv4() - check for optimized forwarding\nnet/batman-adv/multicast.c-980- * potential\n--\nnet/batman-adv/multicast.c-991- */\nnet/batman-adv/multicast.c:992:static int batadv_mcast_forw_mode_check_ipv4(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast.c-993-\t\t\t\t\t struct sk_buff *skb,\n--\nnet/batman-adv/multicast.c=1029=static bool batadv_mcast_is_report_ipv6(struct sk_buff *skb)\n--\nnet/batman-adv/multicast.c-1043-/**\nnet/batman-adv/multicast.c:1044: * batadv_mcast_forw_mode_check_ipv6() - check for optimized forwarding\nnet/batman-adv/multicast.c-1045- * potential\n--\nnet/batman-adv/multicast.c-1055- */\nnet/batman-adv/multicast.c:1056:static int batadv_mcast_forw_mode_check_ipv6(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast.c-1057-\t\t\t\t\t struct sk_buff *skb,\n--\nnet/batman-adv/multicast.c-1086-/**\nnet/batman-adv/multicast.c:1087: * batadv_mcast_forw_mode_check() - check for optimized forwarding potential\nnet/batman-adv/multicast.c-1088- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast.c-1097- */\nnet/batman-adv/multicast.c:1098:static int batadv_mcast_forw_mode_check(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast.c-1099-\t\t\t\t\tstruct sk_buff *skb,\n--\nnet/batman-adv/multicast.c-1109-\tcase ETH_P_IP:\nnet/batman-adv/multicast.c:1110:\t\treturn batadv_mcast_forw_mode_check_ipv4(bat_priv, skb,\nnet/batman-adv/multicast.c-1111-\t\t\t\t\t\t\t is_unsnoopable,\n--\nnet/batman-adv/multicast.c-1116-\nnet/batman-adv/multicast.c:1117:\t\treturn batadv_mcast_forw_mode_check_ipv6(bat_priv, skb,\nnet/batman-adv/multicast.c-1118-\t\t\t\t\t\t\t is_unsnoopable,\n--\nnet/batman-adv/multicast.c=1159=static int batadv_mcast_forw_rtr_count(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/multicast.c-1172-/**\nnet/batman-adv/multicast.c:1173: * batadv_mcast_forw_mode_by_count() - get forwarding mode by count\nnet/batman-adv/multicast.c-1174- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast.c=1196=static enum batadv_forw_mode\nnet/batman-adv/multicast.c:1197:batadv_mcast_forw_mode_by_count(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast.c-1198-\t\t\t\tstruct sk_buff *skb, unsigned short vid,\n--\nnet/batman-adv/multicast.c-1216-/**\nnet/batman-adv/multicast.c:1217: * batadv_mcast_forw_mode() - check on how to forward a multicast packet\nnet/batman-adv/multicast.c-1218- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast.c=1225=enum batadv_forw_mode\nnet/batman-adv/multicast.c:1226:batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast.c-1227-\t\t unsigned short vid, int *is_routable)\n--\nnet/batman-adv/multicast.c-1237-\nnet/batman-adv/multicast.c:1238:\tret = batadv_mcast_forw_mode_check(bat_priv, skb, \u0026is_unsnoopable,\nnet/batman-adv/multicast.c-1239-\t\t\t\t\t is_routable);\n--\nnet/batman-adv/multicast.c-1260-\nnet/batman-adv/multicast.c:1261:\treturn batadv_mcast_forw_mode_by_count(bat_priv, skb, vid, *is_routable,\nnet/batman-adv/multicast.c-1262-\t\t\t\t\t total_count);\n--\nnet/batman-adv/multicast.h=44=enum batadv_forw_mode\nnet/batman-adv/multicast.h:45:batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast.h-46-\t\t unsigned short vid, int *is_routable);\n--\nnet/batman-adv/multicast.h=76=static inline enum batadv_forw_mode\nnet/batman-adv/multicast.h:77:batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast.h-78-\t\t unsigned short vid, int *is_routable)\n--\nnet/batman-adv/multicast_forw.c=1091=static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/multicast_forw.c-1100-\tif (hdr_size \u003c 0) {\nnet/batman-adv/multicast_forw.c:1101:\t\t/* batadv_mcast_forw_mode_check_count() should ensure we do not\nnet/batman-adv/multicast_forw.c-1102-\t\t * end up here\n"
} |
| 51/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 107621 output: 37 thoughts: 42 Thoughts: Okay, here's my interpretation of those thoughts, framed as my own mental process, given that I'm an expert: **Tracing the Multicast Forwarding Path in B.A.T.M.A.N.** Right, so we're talking multicast forwarding in B.A.T.M.A.N.. I remember now, `batadv_mcast_forw_mode` gets triggered from `batadv_interface_tx`. That's where the initial decision to forward the multicast frame is made, the starting point. Good. Now, I need to remind myself how the actual forwarding *happens*. Let's dig into the details... what's next in the chain? Okay, now I have to check `batadv_mcast_forw_push`. Right, I remember that one. That's the function that's responsible for the actual pushing of the multicast packets across the mesh. Gotta refresh my memory about the specifics of that function: the forwarding table lookups, the encapsulation, the physical interface selection, everything. I'll need to go back and check the code, but at least I know the next step now. |
| 52/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_mcast_forw_push",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/multicast.c=1197=batadv_mcast_forw_mode_by_count(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/multicast.c-1206-\t skb-\u003elen + mcast_hdrlen \u003c= IPV6_MIN_MTU \u0026\u0026\nnet/batman-adv/multicast.c:1207:\t batadv_mcast_forw_push(bat_priv, skb, vid, is_routable, count))\nnet/batman-adv/multicast.c-1208-\t\treturn BATADV_FORW_MCAST;\n--\nnet/batman-adv/multicast.h=67=unsigned int batadv_mcast_forw_packet_hdrlen(unsigned int num_dests);\nnet/batman-adv/multicast.h-68-\nnet/batman-adv/multicast.h:69:bool batadv_mcast_forw_push(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast.h-70-\t\t\t unsigned short vid, int is_routable, int count);\n--\nnet/batman-adv/multicast_forw.c=52=static void *batadv_mcast_forw_skb_push(struct sk_buff *skb, size_t size,\n--\nnet/batman-adv/multicast_forw.c-59-/**\nnet/batman-adv/multicast_forw.c:60: * batadv_mcast_forw_push_padding() - push 2 padding bytes to skb's front\nnet/batman-adv/multicast_forw.c-61- * @skb: the skb to push onto\n--\nnet/batman-adv/multicast_forw.c=69=static char *\nnet/batman-adv/multicast_forw.c:70:batadv_mcast_forw_push_padding(struct sk_buff *skb, unsigned short *tvlv_len)\nnet/batman-adv/multicast_forw.c-71-{\n--\nnet/batman-adv/multicast_forw.c-84-/**\nnet/batman-adv/multicast_forw.c:85: * batadv_mcast_forw_push_est_padding() - push padding bytes if necessary\nnet/batman-adv/multicast_forw.c-86- * @skb: the skb to potentially push the padding onto\n--\nnet/batman-adv/multicast_forw.c=96=static bool\nnet/batman-adv/multicast_forw.c:97:batadv_mcast_forw_push_est_padding(struct sk_buff *skb, int count,\nnet/batman-adv/multicast_forw.c-98-\t\t\t\t unsigned short *tvlv_len)\nnet/batman-adv/multicast_forw.c-99-{\nnet/batman-adv/multicast_forw.c:100:\tif (!(count % 2) \u0026\u0026 !batadv_mcast_forw_push_padding(skb, tvlv_len))\nnet/batman-adv/multicast_forw.c-101-\t\treturn false;\n--\nnet/batman-adv/multicast_forw.c=114=batadv_mcast_forw_orig_entry(struct hlist_node *node,\n--\nnet/batman-adv/multicast_forw.c-132-/**\nnet/batman-adv/multicast_forw.c:133: * batadv_mcast_forw_push_dest() - push an originator MAC address onto an skb\nnet/batman-adv/multicast_forw.c-134- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c-148- */\nnet/batman-adv/multicast_forw.c:149:static bool batadv_mcast_forw_push_dest(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast_forw.c-150-\t\t\t\t\tstruct sk_buff *skb, unsigned short vid,\n--\nnet/batman-adv/multicast_forw.c-175-/**\nnet/batman-adv/multicast_forw.c:176: * batadv_mcast_forw_push_dests_list() - push originators from list onto an skb\nnet/batman-adv/multicast_forw.c-177- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c-189- */\nnet/batman-adv/multicast_forw.c:190:static int batadv_mcast_forw_push_dests_list(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast_forw.c-191-\t\t\t\t\t struct sk_buff *skb,\n--\nnet/batman-adv/multicast_forw.c-204-\t\tif (!orig_node ||\nnet/batman-adv/multicast_forw.c:205:\t\t !batadv_mcast_forw_push_dest(bat_priv, skb, vid, orig_node,\nnet/batman-adv/multicast_forw.c-206-\t\t\t\t\t\t num_dests, tvlv_len)) {\n--\nnet/batman-adv/multicast_forw.c-216-/**\nnet/batman-adv/multicast_forw.c:217: * batadv_mcast_forw_push_tt() - push originators with interest through TT\nnet/batman-adv/multicast_forw.c-218- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c=229=static bool\nnet/batman-adv/multicast_forw.c:230:batadv_mcast_forw_push_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast_forw.c-231-\t\t\t unsigned short vid, unsigned short *num_dests,\n--\nnet/batman-adv/multicast_forw.c-244-\thlist_for_each_entry_rcu(orig_entry, \u0026tt_global-\u003eorig_list, list) {\nnet/batman-adv/multicast_forw.c:245:\t\tif (!batadv_mcast_forw_push_dest(bat_priv, skb, vid,\nnet/batman-adv/multicast_forw.c-246-\t\t\t\t\t\t orig_entry-\u003eorig_node,\n--\nnet/batman-adv/multicast_forw.c-260-/**\nnet/batman-adv/multicast_forw.c:261: * batadv_mcast_forw_push_want_all() - push originators with want-all flag\nnet/batman-adv/multicast_forw.c-262- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c-272- */\nnet/batman-adv/multicast_forw.c:273:static bool batadv_mcast_forw_push_want_all(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast_forw.c-274-\t\t\t\t\t struct sk_buff *skb,\n--\nnet/batman-adv/multicast_forw.c-297-\nnet/batman-adv/multicast_forw.c:298:\tret = batadv_mcast_forw_push_dests_list(bat_priv, skb, vid, head,\nnet/batman-adv/multicast_forw.c-299-\t\t\t\t\t\toffset, num_dests, tvlv_len);\n--\nnet/batman-adv/multicast_forw.c-306-/**\nnet/batman-adv/multicast_forw.c:307: * batadv_mcast_forw_push_want_rtr() - push originators with want-router flag\nnet/batman-adv/multicast_forw.c-308- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c-318- */\nnet/batman-adv/multicast_forw.c:319:static bool batadv_mcast_forw_push_want_rtr(struct batadv_priv *bat_priv,\nnet/batman-adv/multicast_forw.c-320-\t\t\t\t\t struct sk_buff *skb,\n--\nnet/batman-adv/multicast_forw.c-343-\nnet/batman-adv/multicast_forw.c:344:\tret = batadv_mcast_forw_push_dests_list(bat_priv, skb, vid, head,\nnet/batman-adv/multicast_forw.c-345-\t\t\t\t\t\toffset, num_dests, tvlv_len);\n--\nnet/batman-adv/multicast_forw.c=364=static void batadv_mcast_forw_scrape(struct sk_buff *skb,\n--\nnet/batman-adv/multicast_forw.c-379-/**\nnet/batman-adv/multicast_forw.c:380: * batadv_mcast_forw_push_scrape_padding() - remove TVLV padding\nnet/batman-adv/multicast_forw.c-381- * @skb: the skb to potentially adjust the TVLV's padding on\n--\nnet/batman-adv/multicast_forw.c-388- */\nnet/batman-adv/multicast_forw.c:389:static void batadv_mcast_forw_push_scrape_padding(struct sk_buff *skb,\nnet/batman-adv/multicast_forw.c-390-\t\t\t\t\t\t unsigned short *tvlv_len)\n--\nnet/batman-adv/multicast_forw.c-398-/**\nnet/batman-adv/multicast_forw.c:399: * batadv_mcast_forw_push_insert_padding() - insert TVLV padding\nnet/batman-adv/multicast_forw.c-400- * @skb: the skb to potentially adjust the TVLV's padding on\n--\nnet/batman-adv/multicast_forw.c-407- */\nnet/batman-adv/multicast_forw.c:408:static bool batadv_mcast_forw_push_insert_padding(struct sk_buff *skb,\nnet/batman-adv/multicast_forw.c-409-\t\t\t\t\t\t unsigned short *tvlv_len)\n--\nnet/batman-adv/multicast_forw.c-414-\nnet/batman-adv/multicast_forw.c:415:\tto = batadv_mcast_forw_push_padding(skb, tvlv_len);\nnet/batman-adv/multicast_forw.c-416-\tif (!to)\n--\nnet/batman-adv/multicast_forw.c-424-/**\nnet/batman-adv/multicast_forw.c:425: * batadv_mcast_forw_push_adjust_padding() - adjust padding if necessary\nnet/batman-adv/multicast_forw.c-426- * @skb: the skb to potentially adjust the TVLV's padding on\n--\nnet/batman-adv/multicast_forw.c=447=static bool\nnet/batman-adv/multicast_forw.c:448:batadv_mcast_forw_push_adjust_padding(struct sk_buff *skb, int *count,\nnet/batman-adv/multicast_forw.c-449-\t\t\t\t unsigned short num_dests_pushed,\n--\nnet/batman-adv/multicast_forw.c-461-\tif (!(*count % 2) \u0026\u0026 (num_dests_pushed % 2))\nnet/batman-adv/multicast_forw.c:462:\t\tbatadv_mcast_forw_push_scrape_padding(skb, tvlv_len);\nnet/batman-adv/multicast_forw.c-463-\t/**\n--\nnet/batman-adv/multicast_forw.c-467-\telse if ((*count % 2) \u0026\u0026 (!(num_dests_pushed % 2)))\nnet/batman-adv/multicast_forw.c:468:\t\tret = batadv_mcast_forw_push_insert_padding(skb, tvlv_len);\nnet/batman-adv/multicast_forw.c-469-\n--\nnet/batman-adv/multicast_forw.c-475-/**\nnet/batman-adv/multicast_forw.c:476: * batadv_mcast_forw_push_dests() - push originator addresses onto an skb\nnet/batman-adv/multicast_forw.c-477- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c=490=static int\nnet/batman-adv/multicast_forw.c:491:batadv_mcast_forw_push_dests(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast_forw.c-492-\t\t\t unsigned short vid, int is_routable, int *count,\n--\nnet/batman-adv/multicast_forw.c-496-\nnet/batman-adv/multicast_forw.c:497:\tif (!batadv_mcast_forw_push_est_padding(skb, *count, tvlv_len))\nnet/batman-adv/multicast_forw.c-498-\t\tgoto err;\nnet/batman-adv/multicast_forw.c-499-\nnet/batman-adv/multicast_forw.c:500:\tif (!batadv_mcast_forw_push_tt(bat_priv, skb, vid, \u0026num_dests,\nnet/batman-adv/multicast_forw.c-501-\t\t\t\t tvlv_len))\n--\nnet/batman-adv/multicast_forw.c-503-\nnet/batman-adv/multicast_forw.c:504:\tif (!batadv_mcast_forw_push_want_all(bat_priv, skb, vid, \u0026num_dests,\nnet/batman-adv/multicast_forw.c-505-\t\t\t\t\t tvlv_len))\n--\nnet/batman-adv/multicast_forw.c-508-\tif (is_routable \u0026\u0026\nnet/batman-adv/multicast_forw.c:509:\t !batadv_mcast_forw_push_want_rtr(bat_priv, skb, vid, \u0026num_dests,\nnet/batman-adv/multicast_forw.c-510-\t\t\t\t\t tvlv_len))\n--\nnet/batman-adv/multicast_forw.c-512-\nnet/batman-adv/multicast_forw.c:513:\tif (!batadv_mcast_forw_push_adjust_padding(skb, count, num_dests,\nnet/batman-adv/multicast_forw.c-514-\t\t\t\t\t\t tvlv_len))\n--\nnet/batman-adv/multicast_forw.c-522-/**\nnet/batman-adv/multicast_forw.c:523: * batadv_mcast_forw_push_tracker() - push a multicast tracker TVLV header\nnet/batman-adv/multicast_forw.c-524- * @skb: the skb to push the tracker TVLV onto\n--\nnet/batman-adv/multicast_forw.c-537- */\nnet/batman-adv/multicast_forw.c:538:static int batadv_mcast_forw_push_tracker(struct sk_buff *skb, int num_dests,\nnet/batman-adv/multicast_forw.c-539-\t\t\t\t\t unsigned short *tvlv_len)\n--\nnet/batman-adv/multicast_forw.c-567-/**\nnet/batman-adv/multicast_forw.c:568: * batadv_mcast_forw_push_tvlvs() - push a multicast tracker TVLV onto an skb\nnet/batman-adv/multicast_forw.c-569- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c=582=static int\nnet/batman-adv/multicast_forw.c:583:batadv_mcast_forw_push_tvlvs(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast_forw.c-584-\t\t\t unsigned short vid, int is_routable, int count,\n--\nnet/batman-adv/multicast_forw.c-588-\nnet/batman-adv/multicast_forw.c:589:\tret = batadv_mcast_forw_push_dests(bat_priv, skb, vid, is_routable,\nnet/batman-adv/multicast_forw.c-590-\t\t\t\t\t \u0026count, tvlv_len);\n--\nnet/batman-adv/multicast_forw.c-593-\nnet/batman-adv/multicast_forw.c:594:\tret = batadv_mcast_forw_push_tracker(skb, count, tvlv_len);\nnet/batman-adv/multicast_forw.c-595-\tif (ret \u003c 0)\n--\nnet/batman-adv/multicast_forw.c-601-/**\nnet/batman-adv/multicast_forw.c:602: * batadv_mcast_forw_push_hdr() - push a multicast packet header onto an skb\nnet/batman-adv/multicast_forw.c-603- * @skb: the skb to push the header onto\n--\nnet/batman-adv/multicast_forw.c=614=static int\nnet/batman-adv/multicast_forw.c:615:batadv_mcast_forw_push_hdr(struct sk_buff *skb, unsigned short tvlv_len)\nnet/batman-adv/multicast_forw.c-616-{\n--\nnet/batman-adv/multicast_forw.c=1091=static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/multicast_forw.c-1118-/**\nnet/batman-adv/multicast_forw.c:1119: * batadv_mcast_forw_push() - encapsulate skb in a batman-adv multicast packet\nnet/batman-adv/multicast_forw.c-1120- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/multicast_forw.c-1137- */\nnet/batman-adv/multicast_forw.c:1138:bool batadv_mcast_forw_push(struct batadv_priv *bat_priv, struct sk_buff *skb,\nnet/batman-adv/multicast_forw.c-1139-\t\t\t unsigned short vid, int is_routable, int count)\n--\nnet/batman-adv/multicast_forw.c-1148-\nnet/batman-adv/multicast_forw.c:1149:\tret = batadv_mcast_forw_push_tvlvs(bat_priv, skb, vid, is_routable,\nnet/batman-adv/multicast_forw.c-1150-\t\t\t\t\t count, \u0026tvlv_len);\n--\nnet/batman-adv/multicast_forw.c-1153-\nnet/batman-adv/multicast_forw.c:1154:\tret = batadv_mcast_forw_push_hdr(skb, tvlv_len);\nnet/batman-adv/multicast_forw.c-1155-\tif (ret \u003c 0)\n"
} |
| 53/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 113247 output: 35 thoughts: 76 Thoughts: Here's my analysis of the provided code flow, as if I were working through it: **Digging into the Multicast Forwarding Path** Okay, so I'm tracing the multicast forwarding logic here. My initial thought is that `batadv_mcast_forw_push` is definitely the key function, and it's being called by `batadv_mcast_forw_mode_by_count`. Now, `batadv_mcast_forw_mode_by_count` itself is called by `batadv_mcast_forw_mode`, which seems to be the central arbitrator. And that function is ultimately triggered from the `batadv_interface_tx` function, meaning that's where the forwarding decision is likely made, or at least initiated. It makes sense, that's the transmission path. It makes sense that's the transmission entry point. Now, before I go any further into the core logic, I think it would be important to determine if the node I am looking at is an access point isolated from clients. This seems like a reasonable assumption that can effect the multicast decision, so let's check `batadv_is_ap_isolated`. |
| 54/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_is_ap_isolated",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/mesh-interface.c=455=void batadv_interface_rx(struct net_device *mesh_iface,\n--\nnet/batman-adv/mesh-interface.c-530-\t\t}\nnet/batman-adv/mesh-interface.c:531:\t} else if (batadv_is_ap_isolated(bat_priv, ethhdr-\u003eh_source,\nnet/batman-adv/mesh-interface.c-532-\t\t\t\t\t ethhdr-\u003eh_dest, vid)) {\n--\nnet/batman-adv/translation-table.c=2460=static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/translation-table.c-2496-/**\nnet/batman-adv/translation-table.c:2497: * _batadv_is_ap_isolated() - check whether two clients are AP-isolated from\nnet/batman-adv/translation-table.c-2498- * each other\n--\nnet/batman-adv/translation-table.c=2506=static bool\nnet/batman-adv/translation-table.c:2507:_batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,\nnet/batman-adv/translation-table.c-2508-\t\t struct batadv_tt_global_entry *tt_global_entry)\n--\nnet/batman-adv/translation-table.c=2539=struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.c-2563-\tif (tt_local_entry \u0026\u0026\nnet/batman-adv/translation-table.c:2564:\t _batadv_is_ap_isolated(tt_local_entry, tt_global_entry))\nnet/batman-adv/translation-table.c-2565-\t\tgoto out;\n--\nnet/batman-adv/translation-table.c=3982=void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/translation-table.c-3989-/**\nnet/batman-adv/translation-table.c:3990: * batadv_is_ap_isolated() - Check if packet from upper layer should be dropped\nnet/batman-adv/translation-table.c-3991- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/translation-table.c-3997- */\nnet/batman-adv/translation-table.c:3998:bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst,\nnet/batman-adv/translation-table.c-3999-\t\t\t unsigned short vid)\n--\nnet/batman-adv/translation-table.c-4020-\nnet/batman-adv/translation-table.c:4021:\tif (_batadv_is_ap_isolated(tt_local_entry, tt_global_entry))\nnet/batman-adv/translation-table.c-4022-\t\tret = true;\n--\nnet/batman-adv/translation-table.h=39=bool batadv_is_my_client(struct batadv_priv *bat_priv, const u8 *addr,\nnet/batman-adv/translation-table.h-40-\t\t\t unsigned short vid);\nnet/batman-adv/translation-table.h:41:bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst,\nnet/batman-adv/translation-table.h-42-\t\t\t unsigned short vid);\n"
} |
| 55/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 114590 output: 37 thoughts: 386 Thoughts: **My Analysis of Batadv Function Reachability** Okay, so I've confirmed that `batadv_is_ap_isolated` is indeed called within `batadv_interface_rx`. This means the code paths involving this function are active and, importantly, the modifications I've made are almost certainly being hit in practice. That's good; it confirms that my work is indeed live. Let me make sure I have a clear list of the key symbols I need to focus on. Here's a quick rundown: * `batadv_dat_snoop_outgoing_arp_request` * `batadv_dat_snoop_incoming_arp_request` * `batadv_dat_snoop_outgoing_arp_reply` * `batadv_dat_snoop_incoming_arp_reply` * `batadv_dat_snoop_outgoing_dhcp_ack` * `batadv_dat_snoop_incoming_dhcp_ack` * `batadv_dat_drop_broadcast_packet` * `batadv_tt_local_add` * `batadv_tt_local_remove` * `batadv_bla_tx` * `batadv_bla_rx` * `batadv_frag_skb_buffer` * `batadv_frag_skb_fwd` * `batadv_frag_send_packet` * `batadv_gw_out_of_range` * `batadv_mcast_forw_mode` * `batadv_mcast_forw_push` * `batadv_is_ap_isolated` * `batadv_tt_global_is_isolated` Hold on a second. I just saw that `batadv_tt_global_is_isolated` is being called from both `batadv_mcast_forw_mode_check_ipv4` and `batadv_mcast_forw_mode_check_ipv6`. That makes this function a potential point of interest. Let me make sure I'm clear on how it behaves. |
| 56/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_global_is_isolated",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/mesh-interface.c=455=void batadv_interface_rx(struct net_device *mesh_iface,\n--\nnet/batman-adv/mesh-interface.c-522-\t\tif (batadv_vlan_ap_isola_get(bat_priv, vid) \u0026\u0026\nnet/batman-adv/mesh-interface.c:523:\t\t batadv_tt_global_is_isolated(bat_priv, ethhdr-\u003eh_source,\nnet/batman-adv/mesh-interface.c-524-\t\t\t\t\t\t vid)) {\n--\nnet/batman-adv/translation-table.c=4422=int batadv_tt_init(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/translation-table.c-4454-/**\nnet/batman-adv/translation-table.c:4455: * batadv_tt_global_is_isolated() - check if a client is marked as isolated\nnet/batman-adv/translation-table.c-4456- * @bat_priv: the bat priv with all the mesh interface information\n--\nnet/batman-adv/translation-table.c-4462- */\nnet/batman-adv/translation-table.c:4463:bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,\nnet/batman-adv/translation-table.c-4464-\t\t\t\t const u8 *addr, unsigned short vid)\n--\nnet/batman-adv/translation-table.h=49=bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,\n--\nnet/batman-adv/translation-table.h-52-\t\t\t\t\t unsigned short vid);\nnet/batman-adv/translation-table.h:53:bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv,\nnet/batman-adv/translation-table.h-54-\t\t\t\t const u8 *addr, unsigned short vid);\n"
} |
| 57/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 116016 output: 37 thoughts: 42 Thoughts: Okay, here's my interpretation of that. **Analyzing the BatAdv Traffic Table Codepath** Alright, so the call stack I'm interested in starts with `batadv_tt_global_is_isolated` -- I know that function is triggered by `batadv_interface_rx`. That much is clear. The question now is what happens *after* that. I'm going to have to check what is in the function `batadv_tt_local_commit_changes` to get a better understanding of the code flow and the implications of the state in that branch. Time to dig in there. |
| 58/2 | 2026/07/29 18:08 | tool | grepper |
0mArgs:{
"Expression": "batadv_tt_local_commit_changes",
"PathPrefix": "net/batman-adv/"
}Results: {
"Output": "net/batman-adv/bat_iv_ogm.c=895=static void batadv_iv_ogm_schedule_buff(struct batadv_hard_iface *hard_iface)\n--\nnet/batman-adv/bat_iv_ogm.c-930-\t\t */\nnet/batman-adv/bat_iv_ogm.c:931:\t\tbatadv_tt_local_commit_changes(bat_priv);\nnet/batman-adv/bat_iv_ogm.c-932-\t\tret = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff);\n--\nnet/batman-adv/bat_v_ogm.c=270=static void batadv_v_ogm_send_meshif(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/bat_v_ogm.c-290-\t */\nnet/batman-adv/bat_v_ogm.c:291:\tbatadv_tt_local_commit_changes(bat_priv);\nnet/batman-adv/bat_v_ogm.c-292-\tret = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff);\n--\nnet/batman-adv/translation-table.c=3904=static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)\n--\nnet/batman-adv/translation-table.c-3944-/**\nnet/batman-adv/translation-table.c:3945: * batadv_tt_local_commit_changes_nolock() - commit all pending local tt changes\nnet/batman-adv/translation-table.c-3946- * which have been queued in the time since the last commit\n--\nnet/batman-adv/translation-table.c-3950- */\nnet/batman-adv/translation-table.c:3951:static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv)\nnet/batman-adv/translation-table.c-3952-{\n--\nnet/batman-adv/translation-table.c-3977-/**\nnet/batman-adv/translation-table.c:3978: * batadv_tt_local_commit_changes() - commit all pending local tt changes which\nnet/batman-adv/translation-table.c-3979- * have been queued in the time since the last commit\n--\nnet/batman-adv/translation-table.c-3981- */\nnet/batman-adv/translation-table.c:3982:void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv)\nnet/batman-adv/translation-table.c-3983-{\nnet/batman-adv/translation-table.c-3984-\tspin_lock_bh(\u0026bat_priv-\u003ett.commit_lock);\nnet/batman-adv/translation-table.c:3985:\tbatadv_tt_local_commit_changes_nolock(bat_priv);\nnet/batman-adv/translation-table.c-3986-\tspin_unlock_bh(\u0026bat_priv-\u003ett.commit_lock);\n--\nnet/batman-adv/translation-table.c=4209=void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)\n--\nnet/batman-adv/translation-table.c-4238-\tif (reduced)\nnet/batman-adv/translation-table.c:4239:\t\tbatadv_tt_local_commit_changes_nolock(bat_priv);\nnet/batman-adv/translation-table.c-4240-\n--\nnet/batman-adv/translation-table.h=41=bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, u8 *src, u8 *dst,\nnet/batman-adv/translation-table.h-42-\t\t\t unsigned short vid);\nnet/batman-adv/translation-table.h:43:void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv);\nnet/batman-adv/translation-table.h-44-bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,\n"
} |
| 59/2 | 2026/07/29 18:08 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 117344 output: 389 thoughts: 1105 Thoughts: **Refining the Focus for Atomic Changes in batman-adv** Okay, so I've been tracing the implications of the atomic changes introduced in this patch, specifically focusing on how they interact with batman-adv's core functionality. My initial thought was to cast a wide net, given the breadth of the codebase, but I need to narrow my focus to the most critical symbols. The initial list included a lot of functions, many of which I don't think are immediately relevant. The key starting point is `batadv_tt_local_commit_changes`, as it is called by `batadv_iv_ogm_schedule_buff` and `batadv_v_ogm_send_meshif`. That gives me the relevant entry points. I've narrowed the list of symbols based on that logic. The important ones process packets directly or are directly affected by the atomic changes to data structures. I'm focusing on the `batadv_dat_snoop_*` functions (ARP and DHCP snooping), because `batadv_dat_entry_add`, which uses the `atomic64_t` data type, is called by those functions. I'm also including `batadv_tt_local_add`, `batadv_tt_global_add`, `batadv_tt_local_remove`, and `batadv_bla_tx` / `batadv_bla_rx` which I know handle the translation table and BLA. Importantly, I also need to track the addition of the `atomic_t` type for the flags in `batadv_tt_common_entry`, which shows up in `batadv_tt_local_commit_changes_nolock`, `batadv_tt_global_sync_flags`, and `batadv_tt_global_del_roaming`. This is where I'll be able to spot the implications of these changes in the source code. Now, for configuration options. I initially identified `BATMAN_ADV`, `BATMAN_ADV_DAT`, `BATMAN_ADV_BLA`, and `BATMAN_ADV_MCAST`. However, a quick scan revealed that `BATMAN_ADV_BATMAN_V` is also relevant because it's modified in `bat_v.c`, `bat_v_elp.c`, and `bat_v_ogm.c`, which are critical for batman-adv's basic operation. I'm noting this as it depends on `BATMAN_ADV` in the Kconfig. I'm adding `BATMAN_ADV_DEBUG` to the list because that's good for troubleshooting and understanding the atomic operations, even if it's not strictly a functional dependency. `BATMAN_ADV_NC` is not relevant here. So the complete list of config symbols is now: * `BATMAN_ADV` * `BATMAN_ADV_BATMAN_V` * `BATMAN_ADV_BLA` * `BATMAN_ADV_DAT` * `BATMAN_ADV_MCAST` * `BATMAN_ADV_DEBUG` To verify the reasoning, this patch focuses on making the necessary updates for atomic operations with the new data types, specifically `mac_addr` in `batadv_dat_entry` to `atomic64_t` and `flags` in `batadv_tt_common_entry` to `atomic_t`. It's all about ensuring that concurrent access and modification to these crucial fields are handled safely, which is a significant functional change. The code reachable via the `bat0` interface and could potentially be fuzzed, which is something I need to keep in mind. The new atomic operations are also functional changes, so that makes this even more important. |
| 60/2 | 2026/07/29 18:09 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BATMAN_ADV",
"BATMAN_ADV_BATMAN_V",
"BATMAN_ADV_BLA",
"BATMAN_ADV_DAT",
"BATMAN_ADV_MCAST"
],
"FocusSymbols": [
"batadv_bla_rx",
"batadv_bla_tx",
"batadv_dat_snoop_incoming_arp_reply",
"batadv_dat_snoop_incoming_arp_request",
"batadv_dat_snoop_incoming_dhcp_ack",
"batadv_dat_snoop_outgoing_arp_reply",
"batadv_dat_snoop_outgoing_arp_request",
"batadv_dat_snoop_outgoing_dhcp_ack",
"batadv_tt_global_add",
"batadv_tt_local_add",
"batadv_tt_local_commit_changes",
"batadv_tt_local_remove"
],
"Reasoning": "The patch introduces functional changes by converting `mac_addr` in `batadv_dat_entry` to `atomic64_t` and `flags` in `batadv_tt_common_entry` to `atomic_t`. It updates various functions in the Distributed ARP Table (DAT), Translation Table (TT), and Bridge Loop Avoidance (BLA) components to use atomic operations (`atomic_read`, `atomic_set`, `atomic_or`, `atomic_andnot`, `atomic_try_cmpxchg`) for concurrent state management. These changes affect core packet processing and state tracking logic in the batman-adv virtual network interface, which is reachable and should be fuzzed to ensure concurrency correctness.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BATMAN_ADV",
"BATMAN_ADV_BATMAN_V",
"BATMAN_ADV_BLA",
"BATMAN_ADV_DAT",
"BATMAN_ADV_MCAST"
],
"FocusSymbols": [
"batadv_bla_rx",
"batadv_bla_tx",
"batadv_dat_snoop_incoming_arp_reply",
"batadv_dat_snoop_incoming_arp_request",
"batadv_dat_snoop_incoming_dhcp_ack",
"batadv_dat_snoop_outgoing_arp_reply",
"batadv_dat_snoop_outgoing_arp_request",
"batadv_dat_snoop_outgoing_dhcp_ack",
"batadv_tt_global_add",
"batadv_tt_local_add",
"batadv_tt_local_commit_changes",
"batadv_tt_local_remove"
],
"Reasoning": "The patch introduces functional changes by converting `mac_addr` in `batadv_dat_entry` to `atomic64_t` and `flags` in `batadv_tt_common_entry` to `atomic_t`. It updates various functions in the Distributed ARP Table (DAT), Translation Table (TT), and Bridge Loop Avoidance (BLA) components to use atomic operations (`atomic_read`, `atomic_set`, `atomic_or`, `atomic_andnot`, `atomic_try_cmpxchg`) for concurrent state management. These changes affect core packet processing and state tracking logic in the batman-adv virtual network interface, which is reachable and should be fuzzed to ensure concurrency correctness.",
"WorthFuzzing": true
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|