@@ -395,7 +395,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
395395 ether_addr_copy (ethhdr -> h_source , mac );
396396 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
397397 "bla_send_claim(): CLAIM %pM on vid %d\n" , mac ,
398- BATADV_PRINT_VID (vid ));
398+ batadv_print_vid (vid ));
399399 break ;
400400 case BATADV_CLAIM_TYPE_UNCLAIM :
401401 /* unclaim frame
@@ -404,7 +404,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
404404 ether_addr_copy (hw_src , mac );
405405 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
406406 "bla_send_claim(): UNCLAIM %pM on vid %d\n" , mac ,
407- BATADV_PRINT_VID (vid ));
407+ batadv_print_vid (vid ));
408408 break ;
409409 case BATADV_CLAIM_TYPE_ANNOUNCE :
410410 /* announcement frame
@@ -413,7 +413,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
413413 ether_addr_copy (hw_src , mac );
414414 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
415415 "bla_send_claim(): ANNOUNCE of %pM on vid %d\n" ,
416- ethhdr -> h_source , BATADV_PRINT_VID (vid ));
416+ ethhdr -> h_source , batadv_print_vid (vid ));
417417 break ;
418418 case BATADV_CLAIM_TYPE_REQUEST :
419419 /* request frame
@@ -425,14 +425,14 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
425425 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
426426 "bla_send_claim(): REQUEST of %pM to %pM on vid %d\n" ,
427427 ethhdr -> h_source , ethhdr -> h_dest ,
428- BATADV_PRINT_VID (vid ));
428+ batadv_print_vid (vid ));
429429 break ;
430430 case BATADV_CLAIM_TYPE_LOOPDETECT :
431431 ether_addr_copy (ethhdr -> h_source , mac );
432432 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
433433 "bla_send_claim(): LOOPDETECT of %pM to %pM on vid %d\n" ,
434434 ethhdr -> h_source , ethhdr -> h_dest ,
435- BATADV_PRINT_VID (vid ));
435+ batadv_print_vid (vid ));
436436
437437 break ;
438438 }
@@ -475,9 +475,9 @@ static void batadv_bla_loopdetect_report(struct work_struct *work)
475475
476476 batadv_info (bat_priv -> soft_iface ,
477477 "Possible loop on VLAN %d detected which can't be handled by BLA - please check your network setup!\n" ,
478- BATADV_PRINT_VID (backbone_gw -> vid ));
478+ batadv_print_vid (backbone_gw -> vid ));
479479 snprintf (vid_str , sizeof (vid_str ), "%d" ,
480- BATADV_PRINT_VID (backbone_gw -> vid ));
480+ batadv_print_vid (backbone_gw -> vid ));
481481 vid_str [sizeof (vid_str ) - 1 ] = 0 ;
482482
483483 batadv_throw_uevent (bat_priv , BATADV_UEV_BLA , BATADV_UEV_LOOPDETECT ,
@@ -510,7 +510,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
510510
511511 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
512512 "bla_get_backbone_gw(): not found (%pM, %d), creating new entry\n" ,
513- orig , BATADV_PRINT_VID (vid ));
513+ orig , batadv_print_vid (vid ));
514514
515515 entry = kzalloc (sizeof (* entry ), GFP_ATOMIC );
516516 if (!entry )
@@ -719,7 +719,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
719719
720720 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
721721 "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n" ,
722- mac , BATADV_PRINT_VID (vid ));
722+ mac , batadv_print_vid (vid ));
723723
724724 kref_get (& claim -> refcount );
725725 hash_added = batadv_hash_add (bat_priv -> bla .claim_hash ,
@@ -739,8 +739,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
739739 goto claim_free_ref ;
740740
741741 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
742- "bla_add_claim(): changing ownership for %pM, vid %d\n" ,
743- mac , BATADV_PRINT_VID (vid ));
742+ "bla_add_claim(): changing ownership for %pM, vid %d to gw %pM \n" ,
743+ mac , batadv_print_vid (vid ), backbone_gw -> orig );
744744
745745 remove_crc = true;
746746 }
@@ -809,7 +809,7 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
809809 return ;
810810
811811 batadv_dbg (BATADV_DBG_BLA , bat_priv , "bla_del_claim(): %pM, vid %d\n" ,
812- mac , BATADV_PRINT_VID (vid ));
812+ mac , batadv_print_vid (vid ));
813813
814814 batadv_hash_remove (bat_priv -> bla .claim_hash , batadv_compare_claim ,
815815 batadv_choose_claim , claim );
@@ -849,7 +849,7 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
849849
850850 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
851851 "handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n" ,
852- BATADV_PRINT_VID (vid ), backbone_gw -> orig , crc );
852+ batadv_print_vid (vid ), backbone_gw -> orig , crc );
853853
854854 spin_lock_bh (& backbone_gw -> crc_lock );
855855 backbone_crc = backbone_gw -> crc ;
@@ -859,7 +859,7 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
859859 batadv_dbg (BATADV_DBG_BLA , backbone_gw -> bat_priv ,
860860 "handle_announce(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n" ,
861861 backbone_gw -> orig ,
862- BATADV_PRINT_VID (backbone_gw -> vid ),
862+ batadv_print_vid (backbone_gw -> vid ),
863863 backbone_crc , crc );
864864
865865 batadv_bla_send_request (backbone_gw );
@@ -904,7 +904,7 @@ static bool batadv_handle_request(struct batadv_priv *bat_priv,
904904
905905 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
906906 "handle_request(): REQUEST vid %d (sent by %pM)...\n" ,
907- BATADV_PRINT_VID (vid ), ethhdr -> h_source );
907+ batadv_print_vid (vid ), ethhdr -> h_source );
908908
909909 batadv_bla_answer_request (bat_priv , primary_if , vid );
910910 return true;
@@ -941,7 +941,7 @@ static bool batadv_handle_unclaim(struct batadv_priv *bat_priv,
941941 /* this must be an UNCLAIM frame */
942942 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
943943 "handle_unclaim(): UNCLAIM %pM on vid %d (sent by %pM)...\n" ,
944- claim_addr , BATADV_PRINT_VID (vid ), backbone_gw -> orig );
944+ claim_addr , batadv_print_vid (vid ), backbone_gw -> orig );
945945
946946 batadv_bla_del_claim (bat_priv , claim_addr , vid );
947947 batadv_backbone_gw_put (backbone_gw );
@@ -1161,7 +1161,7 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,
11611161 if (ret == 1 )
11621162 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
11631163 "bla_process_claim(): received a claim frame from another group. From: %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n" ,
1164- ethhdr -> h_source , BATADV_PRINT_VID (vid ), hw_src ,
1164+ ethhdr -> h_source , batadv_print_vid (vid ), hw_src ,
11651165 hw_dst );
11661166
11671167 if (ret < 2 )
@@ -1197,7 +1197,7 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,
11971197
11981198 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
11991199 "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n" ,
1200- ethhdr -> h_source , BATADV_PRINT_VID (vid ), hw_src , hw_dst );
1200+ ethhdr -> h_source , batadv_print_vid (vid ), hw_src , hw_dst );
12011201 return true;
12021202}
12031203
@@ -1295,10 +1295,13 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,
12951295 goto skip ;
12961296
12971297 batadv_dbg (BATADV_DBG_BLA , bat_priv ,
1298- "bla_purge_claims(): %pM, vid %d, time out\n" ,
1299- claim -> addr , claim -> vid );
1298+ "bla_purge_claims(): timed out.\n" );
13001299
13011300purge_now :
1301+ batadv_dbg (BATADV_DBG_BLA , bat_priv ,
1302+ "bla_purge_claims(): %pM, vid %d\n" ,
1303+ claim -> addr , claim -> vid );
1304+
13021305 batadv_handle_unclaim (bat_priv , primary_if ,
13031306 backbone_gw -> orig ,
13041307 claim -> addr , claim -> vid );
@@ -1846,6 +1849,13 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
18461849 /* possible optimization: race for a claim */
18471850 /* No claim exists yet, claim it for us!
18481851 */
1852+
1853+ batadv_dbg (BATADV_DBG_BLA , bat_priv ,
1854+ "bla_rx(): Unclaimed MAC %pM found. Claim it. Local: %s\n" ,
1855+ ethhdr -> h_source ,
1856+ batadv_is_my_client (bat_priv ,
1857+ ethhdr -> h_source , vid ) ?
1858+ "yes" : "no" );
18491859 batadv_handle_claim (bat_priv , primary_if ,
18501860 primary_if -> net_dev -> dev_addr ,
18511861 ethhdr -> h_source , vid );
@@ -1963,10 +1973,22 @@ bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
19631973 /* if yes, the client has roamed and we have
19641974 * to unclaim it.
19651975 */
1966- batadv_handle_unclaim (bat_priv , primary_if ,
1967- primary_if -> net_dev -> dev_addr ,
1968- ethhdr -> h_source , vid );
1969- goto allow ;
1976+ if (batadv_has_timed_out (claim -> lasttime , 100 )) {
1977+ /* only unclaim if the last claim entry is
1978+ * older than 100 ms to make sure we really
1979+ * have a roaming client here.
1980+ */
1981+ batadv_dbg (BATADV_DBG_BLA , bat_priv , "bla_tx(): Roaming client %pM detected. Unclaim it.\n" ,
1982+ ethhdr -> h_source );
1983+ batadv_handle_unclaim (bat_priv , primary_if ,
1984+ primary_if -> net_dev -> dev_addr ,
1985+ ethhdr -> h_source , vid );
1986+ goto allow ;
1987+ } else {
1988+ batadv_dbg (BATADV_DBG_BLA , bat_priv , "bla_tx(): Race for claim %pM detected. Drop packet.\n" ,
1989+ ethhdr -> h_source );
1990+ goto handled ;
1991+ }
19701992 }
19711993
19721994 /* check if it is a multicast/broadcast frame */
@@ -2042,7 +2064,7 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
20422064 backbone_crc = backbone_gw -> crc ;
20432065 spin_unlock_bh (& backbone_gw -> crc_lock );
20442066 seq_printf (seq , " * %pM on %5d by %pM [%c] (%#.4x)\n" ,
2045- claim -> addr , BATADV_PRINT_VID (claim -> vid ),
2067+ claim -> addr , batadv_print_vid (claim -> vid ),
20462068 backbone_gw -> orig ,
20472069 (is_own ? 'x' : ' ' ),
20482070 backbone_crc );
@@ -2274,7 +2296,7 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
22742296
22752297 seq_printf (seq , " * %pM on %5d %4i.%03is (%#.4x)\n" ,
22762298 backbone_gw -> orig ,
2277- BATADV_PRINT_VID (backbone_gw -> vid ), secs ,
2299+ batadv_print_vid (backbone_gw -> vid ), secs ,
22782300 msecs , backbone_crc );
22792301 }
22802302 rcu_read_unlock ();
@@ -2449,3 +2471,52 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)
24492471
24502472 return ret ;
24512473}
2474+
2475+ #ifdef CONFIG_BATMAN_ADV_DAT
2476+ /**
2477+ * batadv_bla_check_claim - check if address is claimed
2478+ *
2479+ * @bat_priv: the bat priv with all the soft interface information
2480+ * @addr: mac address of which the claim status is checked
2481+ * @vid: the VLAN ID
2482+ *
2483+ * addr is checked if this address is claimed by the local device itself.
2484+ *
2485+ * Return: true if bla is disabled or the mac is claimed by the device,
2486+ * false if the device addr is already claimed by another gateway
2487+ */
2488+ bool batadv_bla_check_claim (struct batadv_priv * bat_priv ,
2489+ u8 * addr , unsigned short vid )
2490+ {
2491+ struct batadv_bla_claim search_claim ;
2492+ struct batadv_bla_claim * claim = NULL ;
2493+ struct batadv_hard_iface * primary_if = NULL ;
2494+ bool ret = true;
2495+
2496+ if (!atomic_read (& bat_priv -> bridge_loop_avoidance ))
2497+ return ret ;
2498+
2499+ primary_if = batadv_primary_if_get_selected (bat_priv );
2500+ if (!primary_if )
2501+ return ret ;
2502+
2503+ /* First look if the mac address is claimed */
2504+ ether_addr_copy (search_claim .addr , addr );
2505+ search_claim .vid = vid ;
2506+
2507+ claim = batadv_claim_hash_find (bat_priv , & search_claim );
2508+
2509+ /* If there is a claim and we are not owner of the claim,
2510+ * return false.
2511+ */
2512+ if (claim ) {
2513+ if (!batadv_compare_eth (claim -> backbone_gw -> orig ,
2514+ primary_if -> net_dev -> dev_addr ))
2515+ ret = false;
2516+ batadv_claim_put (claim );
2517+ }
2518+
2519+ batadv_hardif_put (primary_if );
2520+ return ret ;
2521+ }
2522+ #endif
0 commit comments