3333#include <linux/in6.h>
3434#include <linux/ip.h>
3535#include <linux/ipv6.h>
36+ #include <linux/jiffies.h>
3637#include <linux/kernel.h>
3738#include <linux/kref.h>
3839#include <linux/list.h>
4849#include <linux/stddef.h>
4950#include <linux/string.h>
5051#include <linux/types.h>
52+ #include <linux/workqueue.h>
5153#include <net/addrconf.h>
5254#include <net/if_inet6.h>
5355#include <net/ip.h>
6062#include "translation-table.h"
6163#include "tvlv.h"
6264
65+ static void batadv_mcast_mla_update (struct work_struct * work );
66+
67+ /**
68+ * batadv_mcast_start_timer - schedule the multicast periodic worker
69+ * @bat_priv: the bat priv with all the soft interface information
70+ */
71+ static void batadv_mcast_start_timer (struct batadv_priv * bat_priv )
72+ {
73+ queue_delayed_work (batadv_event_workqueue , & bat_priv -> mcast .work ,
74+ msecs_to_jiffies (BATADV_MCAST_WORK_PERIOD ));
75+ }
76+
6377/**
6478 * batadv_mcast_get_bridge - get the bridge on top of the softif if it exists
6579 * @soft_iface: netdev struct of the mesh interface
@@ -255,14 +269,16 @@ static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list)
255269 * translation table except the ones listed in the given mcast_list.
256270 *
257271 * If mcast_list is NULL then all are retracted.
272+ *
273+ * Do not call outside of the mcast worker! (or cancel mcast worker first)
258274 */
259275static void batadv_mcast_mla_tt_retract (struct batadv_priv * bat_priv ,
260276 struct hlist_head * mcast_list )
261277{
262278 struct batadv_hw_addr * mcast_entry ;
263279 struct hlist_node * tmp ;
264280
265- lockdep_assert_held ( & bat_priv -> tt . commit_lock );
281+ WARN_ON ( delayed_work_pending ( & bat_priv -> mcast . work ) );
266282
267283 hlist_for_each_entry_safe (mcast_entry , tmp , & bat_priv -> mcast .mla_list ,
268284 list ) {
@@ -287,14 +303,16 @@ static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
287303 *
288304 * Adds multicast listener announcements from the given mcast_list to the
289305 * translation table if they have not been added yet.
306+ *
307+ * Do not call outside of the mcast worker! (or cancel mcast worker first)
290308 */
291309static void batadv_mcast_mla_tt_add (struct batadv_priv * bat_priv ,
292310 struct hlist_head * mcast_list )
293311{
294312 struct batadv_hw_addr * mcast_entry ;
295313 struct hlist_node * tmp ;
296314
297- lockdep_assert_held ( & bat_priv -> tt . commit_lock );
315+ WARN_ON ( delayed_work_pending ( & bat_priv -> mcast . work ) );
298316
299317 if (!mcast_list )
300318 return ;
@@ -528,13 +546,18 @@ static bool batadv_mcast_mla_tvlv_update(struct batadv_priv *bat_priv)
528546}
529547
530548/**
531- * batadv_mcast_mla_update - update the own MLAs
549+ * __batadv_mcast_mla_update - update the own MLAs
532550 * @bat_priv: the bat priv with all the soft interface information
533551 *
534552 * Updates the own multicast listener announcements in the translation
535553 * table as well as the own, announced multicast tvlv container.
554+ *
555+ * Note that non-conflicting reads and writes to bat_priv->mcast.mla_list
556+ * in batadv_mcast_mla_tt_retract() and batadv_mcast_mla_tt_add() are
557+ * ensured by the non-parallel execution of the worker this function
558+ * belongs to.
536559 */
537- void batadv_mcast_mla_update (struct batadv_priv * bat_priv )
560+ static void __batadv_mcast_mla_update (struct batadv_priv * bat_priv )
538561{
539562 struct net_device * soft_iface = bat_priv -> soft_iface ;
540563 struct hlist_head mcast_list = HLIST_HEAD_INIT ;
@@ -559,6 +582,29 @@ void batadv_mcast_mla_update(struct batadv_priv *bat_priv)
559582 batadv_mcast_mla_list_free (& mcast_list );
560583}
561584
585+ /**
586+ * batadv_mcast_mla_update - update the own MLAs
587+ * @work: kernel work struct
588+ *
589+ * Updates the own multicast listener announcements in the translation
590+ * table as well as the own, announced multicast tvlv container.
591+ *
592+ * In the end, reschedules the work timer.
593+ */
594+ static void batadv_mcast_mla_update (struct work_struct * work )
595+ {
596+ struct delayed_work * delayed_work ;
597+ struct batadv_priv_mcast * priv_mcast ;
598+ struct batadv_priv * bat_priv ;
599+
600+ delayed_work = to_delayed_work (work );
601+ priv_mcast = container_of (delayed_work , struct batadv_priv_mcast , work );
602+ bat_priv = container_of (priv_mcast , struct batadv_priv , mcast );
603+
604+ __batadv_mcast_mla_update (bat_priv );
605+ batadv_mcast_start_timer (bat_priv );
606+ }
607+
562608/**
563609 * batadv_mcast_is_report_ipv4 - check for IGMP reports
564610 * @skb: the ethernet frame destined for the mesh
@@ -1128,6 +1174,9 @@ void batadv_mcast_init(struct batadv_priv *bat_priv)
11281174 batadv_tvlv_handler_register (bat_priv , batadv_mcast_tvlv_ogm_handler ,
11291175 NULL , BATADV_TVLV_MCAST , 2 ,
11301176 BATADV_TVLV_HANDLER_OGM_CIFNOTFND );
1177+
1178+ INIT_DELAYED_WORK (& bat_priv -> mcast .work , batadv_mcast_mla_update );
1179+ batadv_mcast_start_timer (bat_priv );
11311180}
11321181
11331182#ifdef CONFIG_BATMAN_ADV_DEBUGFS
@@ -1239,12 +1288,13 @@ int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset)
12391288 */
12401289void batadv_mcast_free (struct batadv_priv * bat_priv )
12411290{
1291+ cancel_delayed_work_sync (& bat_priv -> mcast .work );
1292+
12421293 batadv_tvlv_container_unregister (bat_priv , BATADV_TVLV_MCAST , 2 );
12431294 batadv_tvlv_handler_unregister (bat_priv , BATADV_TVLV_MCAST , 2 );
12441295
1245- spin_lock_bh ( & bat_priv -> tt . commit_lock );
1296+ /* safely calling outside of worker, as worker was canceled above */
12461297 batadv_mcast_mla_tt_retract (bat_priv , NULL );
1247- spin_unlock_bh (& bat_priv -> tt .commit_lock );
12481298}
12491299
12501300/**
0 commit comments