@@ -74,8 +74,8 @@ static int batadv_iv_ogm_iface_enable(struct hard_iface *hard_iface)
7474 batman_ogm_packet -> header .packet_type = BAT_IV_OGM ;
7575 batman_ogm_packet -> header .version = BATADV_COMPAT_VERSION ;
7676 batman_ogm_packet -> header .ttl = 2 ;
77- batman_ogm_packet -> flags = NO_FLAGS ;
78- batman_ogm_packet -> tq = TQ_MAX_VALUE ;
77+ batman_ogm_packet -> flags = BATADV_NO_FLAGS ;
78+ batman_ogm_packet -> tq = BATADV_TQ_MAX_VALUE ;
7979 batman_ogm_packet -> tt_num_changes = 0 ;
8080 batman_ogm_packet -> ttvn = 0 ;
8181
@@ -108,29 +108,37 @@ static void batadv_iv_ogm_primary_iface_set(struct hard_iface *hard_iface)
108108
109109 batman_ogm_packet = (struct batman_ogm_packet * )hard_iface -> packet_buff ;
110110 batman_ogm_packet -> flags = PRIMARIES_FIRST_HOP ;
111- batman_ogm_packet -> header .ttl = TTL ;
111+ batman_ogm_packet -> header .ttl = BATADV_TTL ;
112112}
113113
114114/* when do we schedule our own ogm to be sent */
115115static unsigned long
116116batadv_iv_ogm_emit_send_time (const struct bat_priv * bat_priv )
117117{
118- return jiffies + msecs_to_jiffies (
119- atomic_read (& bat_priv -> orig_interval ) -
120- JITTER + (random32 () % 2 * JITTER ));
118+ unsigned int msecs ;
119+
120+ msecs = atomic_read (& bat_priv -> orig_interval ) - BATADV_JITTER ;
121+ msecs += (random32 () % 2 * BATADV_JITTER );
122+
123+ return jiffies + msecs_to_jiffies (msecs );
121124}
122125
123126/* when do we schedule a ogm packet to be sent */
124127static unsigned long batadv_iv_ogm_fwd_send_time (void )
125128{
126- return jiffies + msecs_to_jiffies (random32 () % (JITTER / 2 ));
129+ return jiffies + msecs_to_jiffies (random32 () % (BATADV_JITTER / 2 ));
127130}
128131
129132/* apply hop penalty for a normal link */
130133static uint8_t batadv_hop_penalty (uint8_t tq , const struct bat_priv * bat_priv )
131134{
132135 int hop_penalty = atomic_read (& bat_priv -> hop_penalty );
133- return (tq * (TQ_MAX_VALUE - hop_penalty )) / (TQ_MAX_VALUE );
136+ int new_tq ;
137+
138+ new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty );
139+ new_tq /= BATADV_TQ_MAX_VALUE ;
140+
141+ return new_tq ;
134142}
135143
136144/* is there another aggregated packet here? */
@@ -143,7 +151,7 @@ static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
143151 next_buff_pos += batadv_tt_len (tt_num_changes );
144152
145153 return (next_buff_pos <= packet_len ) &&
146- (next_buff_pos <= MAX_AGGREGATION_BYTES );
154+ (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES );
147155}
148156
149157/* send a batman ogm to a given interface */
@@ -290,8 +298,11 @@ batadv_iv_ogm_can_aggregate(const struct batman_ogm_packet *new_bat_ogm_packet,
290298 int aggregated_bytes = forw_packet -> packet_len + packet_len ;
291299 struct hard_iface * primary_if = NULL ;
292300 bool res = false;
301+ unsigned long aggregation_end_time ;
293302
294303 batman_ogm_packet = (struct batman_ogm_packet * )forw_packet -> skb -> data ;
304+ aggregation_end_time = send_time ;
305+ aggregation_end_time += msecs_to_jiffies (BATADV_MAX_AGGREGATION_MS );
295306
296307 /* we can aggregate the current packet to this aggregated packet
297308 * if:
@@ -301,9 +312,8 @@ batadv_iv_ogm_can_aggregate(const struct batman_ogm_packet *new_bat_ogm_packet,
301312 * MAX_AGGREGATION_BYTES
302313 */
303314 if (time_before (send_time , forw_packet -> send_time ) &&
304- time_after_eq (send_time + msecs_to_jiffies (MAX_AGGREGATION_MS ),
305- forw_packet -> send_time ) &&
306- (aggregated_bytes <= MAX_AGGREGATION_BYTES )) {
315+ time_after_eq (aggregation_end_time , forw_packet -> send_time ) &&
316+ (aggregated_bytes <= BATADV_MAX_AGGREGATION_BYTES )) {
307317
308318 /* check aggregation compatibility
309319 * -> direct link packets are broadcasted on
@@ -367,6 +377,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
367377 struct bat_priv * bat_priv = netdev_priv (if_incoming -> soft_iface );
368378 struct forw_packet * forw_packet_aggr ;
369379 unsigned char * skb_buff ;
380+ unsigned int skb_size ;
370381
371382 if (!atomic_inc_not_zero (& if_incoming -> refcount ))
372383 return ;
@@ -388,12 +399,12 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
388399 }
389400
390401 if ((atomic_read (& bat_priv -> aggregated_ogms )) &&
391- (packet_len < MAX_AGGREGATION_BYTES ))
392- forw_packet_aggr -> skb = dev_alloc_skb (MAX_AGGREGATION_BYTES +
393- ETH_HLEN );
402+ (packet_len < BATADV_MAX_AGGREGATION_BYTES ))
403+ skb_size = BATADV_MAX_AGGREGATION_BYTES + ETH_HLEN ;
394404 else
395- forw_packet_aggr -> skb = dev_alloc_skb ( packet_len + ETH_HLEN ) ;
405+ skb_size = packet_len + ETH_HLEN ;
396406
407+ forw_packet_aggr -> skb = dev_alloc_skb (skb_size );
397408 if (!forw_packet_aggr -> skb ) {
398409 if (!own_packet )
399410 atomic_inc (& bat_priv -> batman_queue_left );
@@ -411,7 +422,7 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
411422 forw_packet_aggr -> own = own_packet ;
412423 forw_packet_aggr -> if_incoming = if_incoming ;
413424 forw_packet_aggr -> num_packets = 0 ;
414- forw_packet_aggr -> direct_link_flags = NO_FLAGS ;
425+ forw_packet_aggr -> direct_link_flags = BATADV_NO_FLAGS ;
415426 forw_packet_aggr -> send_time = send_time ;
416427
417428 /* save packet direct link flag status */
@@ -466,9 +477,11 @@ static void batadv_iv_ogm_queue_add(struct bat_priv *bat_priv,
466477 struct hlist_node * tmp_node ;
467478 struct batman_ogm_packet * batman_ogm_packet ;
468479 bool direct_link ;
480+ unsigned long max_aggregation_jiffies ;
469481
470482 batman_ogm_packet = (struct batman_ogm_packet * )packet_buff ;
471483 direct_link = batman_ogm_packet -> flags & DIRECTLINK ? 1 : 0 ;
484+ max_aggregation_jiffies = msecs_to_jiffies (BATADV_MAX_AGGREGATION_MS );
472485
473486 /* find position for the packet in the forward queue */
474487 spin_lock_bh (& bat_priv -> forw_bat_list_lock );
@@ -498,9 +511,8 @@ static void batadv_iv_ogm_queue_add(struct bat_priv *bat_priv,
498511 * we hold it back for a while, so that it might be aggregated
499512 * later on
500513 */
501- if ((!own_packet ) &&
502- (atomic_read (& bat_priv -> aggregated_ogms )))
503- send_time += msecs_to_jiffies (MAX_AGGREGATION_MS );
514+ if (!own_packet && atomic_read (& bat_priv -> aggregated_ogms ))
515+ send_time += max_aggregation_jiffies ;
504516
505517 batadv_iv_ogm_aggregate_new (packet_buff , packet_len ,
506518 send_time , direct_link ,
@@ -603,7 +615,7 @@ static void batadv_iv_ogm_schedule(struct hard_iface *hard_iface)
603615 batman_ogm_packet -> gw_flags =
604616 (uint8_t )atomic_read (& bat_priv -> gw_bandwidth );
605617 else
606- batman_ogm_packet -> gw_flags = NO_FLAGS ;
618+ batman_ogm_packet -> gw_flags = BATADV_NO_FLAGS ;
607619
608620 batadv_slide_own_bcast_window (hard_iface );
609621 batadv_iv_ogm_queue_add (bat_priv , hard_iface -> packet_buff ,
@@ -772,8 +784,10 @@ static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
772784 struct neigh_node * neigh_node = NULL , * tmp_neigh_node ;
773785 struct hlist_node * node ;
774786 uint8_t total_count ;
775- uint8_t orig_eq_count , neigh_rq_count , tq_own ;
776- int tq_asym_penalty , ret = 0 ;
787+ uint8_t orig_eq_count , neigh_rq_count , neigh_rq_inv , tq_own ;
788+ unsigned int neigh_rq_inv_cube , neigh_rq_max_cube ;
789+ int tq_asym_penalty , inv_asym_penalty , ret = 0 ;
790+ unsigned int combined_tq ;
777791
778792 /* find corresponding one hop neighbor */
779793 rcu_read_lock ();
@@ -824,32 +838,33 @@ static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
824838 /* if we have too few packets (too less data) we set tq_own to zero
825839 * if we receive too few packets it is not considered bidirectional
826840 */
827- if (( total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM ) ||
828- ( neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM ) )
841+ if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM ||
842+ neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM )
829843 tq_own = 0 ;
830844 else
831845 /* neigh_node->real_packet_count is never zero as we
832846 * only purge old information when getting new
833847 * information
834848 */
835- tq_own = (TQ_MAX_VALUE * total_count ) / neigh_rq_count ;
849+ tq_own = (BATADV_TQ_MAX_VALUE * total_count ) / neigh_rq_count ;
836850
837851 /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
838852 * affect the nearly-symmetric links only a little, but
839853 * punishes asymmetric links more. This will give a value
840854 * between 0 and TQ_MAX_VALUE
841855 */
842- tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE *
843- (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count ) *
844- (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count ) *
845- (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count )) /
846- (TQ_LOCAL_WINDOW_SIZE *
847- TQ_LOCAL_WINDOW_SIZE *
848- TQ_LOCAL_WINDOW_SIZE );
849-
850- batman_ogm_packet -> tq = ((batman_ogm_packet -> tq * tq_own
851- * tq_asym_penalty ) /
852- (TQ_MAX_VALUE * TQ_MAX_VALUE ));
856+ neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count ;
857+ neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv ;
858+ neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE *
859+ BATADV_TQ_LOCAL_WINDOW_SIZE *
860+ BATADV_TQ_LOCAL_WINDOW_SIZE ;
861+ inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube ;
862+ inv_asym_penalty /= neigh_rq_max_cube ;
863+ tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty ;
864+
865+ combined_tq = batman_ogm_packet -> tq * tq_own * tq_asym_penalty ;
866+ combined_tq /= BATADV_TQ_MAX_VALUE * BATADV_TQ_MAX_VALUE ;
867+ batman_ogm_packet -> tq = combined_tq ;
853868
854869 batadv_dbg (DBG_BATMAN , bat_priv ,
855870 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n" ,
@@ -860,7 +875,7 @@ static int batadv_iv_ogm_calc_tq(struct orig_node *orig_node,
860875 /* if link has the minimum required transmission quality
861876 * consider it bidirectional
862877 */
863- if (batman_ogm_packet -> tq >= TQ_TOTAL_BIDRECT_LIMIT )
878+ if (batman_ogm_packet -> tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT )
864879 ret = 1 ;
865880
866881out :
@@ -928,7 +943,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
928943
929944 tmp_neigh_node -> real_packet_count =
930945 bitmap_weight (tmp_neigh_node -> real_bits ,
931- TQ_LOCAL_WINDOW_SIZE );
946+ BATADV_TQ_LOCAL_WINDOW_SIZE );
932947 }
933948 rcu_read_unlock ();
934949
@@ -1050,6 +1065,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
10501065 unsigned long * word ;
10511066 int offset ;
10521067 int32_t bit_pos ;
1068+ int16_t if_num ;
1069+ uint8_t * weight ;
10531070
10541071 orig_neigh_node = batadv_get_orig_node (bat_priv ,
10551072 ethhdr -> h_source );
@@ -1063,15 +1080,17 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
10631080 if (has_directlink_flag &&
10641081 batadv_compare_eth (if_incoming -> net_dev -> dev_addr ,
10651082 batman_ogm_packet -> orig )) {
1066- offset = if_incoming -> if_num * NUM_WORDS ;
1083+ if_num = if_incoming -> if_num ;
1084+ offset = if_num * BATADV_NUM_WORDS ;
10671085
10681086 spin_lock_bh (& orig_neigh_node -> ogm_cnt_lock );
10691087 word = & (orig_neigh_node -> bcast_own [offset ]);
10701088 bit_pos = if_incoming_seqno - 2 ;
10711089 bit_pos -= ntohl (batman_ogm_packet -> seqno );
10721090 batadv_set_bit (word , bit_pos );
1073- orig_neigh_node -> bcast_own_sum [if_incoming -> if_num ] =
1074- bitmap_weight (word , TQ_LOCAL_WINDOW_SIZE );
1091+ weight = & orig_neigh_node -> bcast_own_sum [if_num ];
1092+ * weight = bitmap_weight (word ,
1093+ BATADV_TQ_LOCAL_WINDOW_SIZE );
10751094 spin_unlock_bh (& orig_neigh_node -> ogm_cnt_lock );
10761095 }
10771096
0 commit comments