Skip to content

Commit 3a24a63

Browse files
ordexsimonwunderlich
authored andcommitted
batman-adv: move GW mode and selection class to private data structure
To reduce the field pollution in our main batadv_priv data structure we've already created some substructures so that we could group fields in a convenient manner. However gw_mode and gw_sel_class are still part of the main object. More both fields to the GW private substructure. Signed-off-by: Antonio Quartulli <[email protected]> Signed-off-by: Marek Lindner <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent c149ca7 commit 3a24a63

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

net/batman-adv/gateway_client.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
192192

193193
tq_avg = router_ifinfo->bat_iv.tq_avg;
194194

195-
switch (atomic_read(&bat_priv->gw_sel_class)) {
195+
switch (atomic_read(&bat_priv->gw.sel_class)) {
196196
case 1: /* fast connection */
197197
tmp_gw_factor = tq_avg * tq_avg;
198198
tmp_gw_factor *= gw_node->bandwidth_down;
@@ -255,7 +255,7 @@ void batadv_gw_check_client_stop(struct batadv_priv *bat_priv)
255255
{
256256
struct batadv_gw_node *curr_gw;
257257

258-
if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_CLIENT)
258+
if (atomic_read(&bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT)
259259
return;
260260

261261
curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
@@ -283,7 +283,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv)
283283
struct batadv_neigh_ifinfo *router_ifinfo = NULL;
284284
char gw_addr[18] = { '\0' };
285285

286-
if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_CLIENT)
286+
if (atomic_read(&bat_priv->gw.mode) != BATADV_GW_MODE_CLIENT)
287287
goto out;
288288

289289
curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
@@ -402,8 +402,8 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv,
402402
/* if the routing class is greater than 3 the value tells us how much
403403
* greater the TQ value of the new gateway must be
404404
*/
405-
if ((atomic_read(&bat_priv->gw_sel_class) > 3) &&
406-
(orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw_sel_class)))
405+
if ((atomic_read(&bat_priv->gw.sel_class) > 3) &&
406+
(orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw.sel_class)))
407407
goto out;
408408

409409
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
@@ -820,7 +820,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
820820
if (!gw_node)
821821
goto out;
822822

823-
switch (atomic_read(&bat_priv->gw_mode)) {
823+
switch (atomic_read(&bat_priv->gw.mode)) {
824824
case BATADV_GW_MODE_SERVER:
825825
/* If we are a GW then we are our best GW. We can artificially
826826
* set the tq towards ourself as the maximum value

net/batman-adv/gateway_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv)
144144
u32 down, up;
145145
char gw_mode;
146146

147-
gw_mode = atomic_read(&bat_priv->gw_mode);
147+
gw_mode = atomic_read(&bat_priv->gw.mode);
148148

149149
switch (gw_mode) {
150150
case BATADV_GW_MODE_OFF:
@@ -241,8 +241,8 @@ static void batadv_gw_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
241241

242242
/* restart gateway selection if fast or late switching was enabled */
243243
if ((gateway.bandwidth_down != 0) &&
244-
(atomic_read(&bat_priv->gw_mode) == BATADV_GW_MODE_CLIENT) &&
245-
(atomic_read(&bat_priv->gw_sel_class) > 2))
244+
(atomic_read(&bat_priv->gw.mode) == BATADV_GW_MODE_CLIENT) &&
245+
(atomic_read(&bat_priv->gw.sel_class) > 2))
246246
batadv_gw_check_election(bat_priv, orig);
247247
}
248248

net/batman-adv/soft-interface.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
255255
if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
256256
goto dropped;
257257

258-
gw_mode = atomic_read(&bat_priv->gw_mode);
258+
gw_mode = atomic_read(&bat_priv->gw.mode);
259259
if (is_multicast_ether_addr(ethhdr->h_dest)) {
260260
/* if gw mode is off, broadcast every packet */
261261
if (gw_mode == BATADV_GW_MODE_OFF) {
@@ -815,8 +815,8 @@ static int batadv_softif_init_late(struct net_device *dev)
815815
atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0);
816816
atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
817817
#endif
818-
atomic_set(&bat_priv->gw_mode, BATADV_GW_MODE_OFF);
819-
atomic_set(&bat_priv->gw_sel_class, 20);
818+
atomic_set(&bat_priv->gw.mode, BATADV_GW_MODE_OFF);
819+
atomic_set(&bat_priv->gw.sel_class, 20);
820820
atomic_set(&bat_priv->gw.bandwidth_down, 100);
821821
atomic_set(&bat_priv->gw.bandwidth_up, 20);
822822
atomic_set(&bat_priv->orig_interval, 1000);

net/batman-adv/sysfs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr,
427427
struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
428428
int bytes_written;
429429

430-
switch (atomic_read(&bat_priv->gw_mode)) {
430+
switch (atomic_read(&bat_priv->gw.mode)) {
431431
case BATADV_GW_MODE_CLIENT:
432432
bytes_written = sprintf(buff, "%s\n",
433433
BATADV_GW_MODE_CLIENT_NAME);
@@ -476,10 +476,10 @@ static ssize_t batadv_store_gw_mode(struct kobject *kobj,
476476
return -EINVAL;
477477
}
478478

479-
if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp)
479+
if (atomic_read(&bat_priv->gw.mode) == gw_mode_tmp)
480480
return count;
481481

482-
switch (atomic_read(&bat_priv->gw_mode)) {
482+
switch (atomic_read(&bat_priv->gw.mode)) {
483483
case BATADV_GW_MODE_CLIENT:
484484
curr_gw_mode_str = BATADV_GW_MODE_CLIENT_NAME;
485485
break;
@@ -508,7 +508,7 @@ static ssize_t batadv_store_gw_mode(struct kobject *kobj,
508508
* state
509509
*/
510510
batadv_gw_check_client_stop(bat_priv);
511-
atomic_set(&bat_priv->gw_mode, (unsigned int)gw_mode_tmp);
511+
atomic_set(&bat_priv->gw.mode, (unsigned int)gw_mode_tmp);
512512
batadv_gw_tvlv_container_update(bat_priv);
513513
return count;
514514
}
@@ -624,7 +624,7 @@ BATADV_ATTR_SIF_UINT(orig_interval, orig_interval, S_IRUGO | S_IWUSR,
624624
2 * BATADV_JITTER, INT_MAX, NULL);
625625
BATADV_ATTR_SIF_UINT(hop_penalty, hop_penalty, S_IRUGO | S_IWUSR, 0,
626626
BATADV_TQ_MAX_VALUE, NULL);
627-
BATADV_ATTR_SIF_UINT(gw_sel_class, gw_sel_class, S_IRUGO | S_IWUSR, 1,
627+
BATADV_ATTR_SIF_UINT(gw_sel_class, gw.sel_class, S_IRUGO | S_IWUSR, 1,
628628
BATADV_TQ_MAX_VALUE, batadv_post_gw_reselect);
629629
static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth,
630630
batadv_store_gw_bwidth);

net/batman-adv/types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ struct batadv_priv_debug_log {
707707
* @list: list of available gateway nodes
708708
* @list_lock: lock protecting gw_list & curr_gw
709709
* @curr_gw: pointer to currently selected gateway node
710+
* @mode: gateway operation: off, client or server (see batadv_gw_modes)
711+
* @sel_class: gateway selection class (applies if gw_mode client)
710712
* @bandwidth_down: advertised uplink download bandwidth (if gw_mode server)
711713
* @bandwidth_up: advertised uplink upload bandwidth (if gw_mode server)
712714
* @reselect: bool indicating a gateway re-selection is in progress
@@ -715,6 +717,8 @@ struct batadv_priv_gw {
715717
struct hlist_head list;
716718
spinlock_t list_lock; /* protects gw_list & curr_gw */
717719
struct batadv_gw_node __rcu *curr_gw; /* rcu protected pointer */
720+
atomic_t mode;
721+
atomic_t sel_class;
718722
atomic_t bandwidth_down;
719723
atomic_t bandwidth_up;
720724
atomic_t reselect;
@@ -865,8 +869,6 @@ struct batadv_priv_bat_v {
865869
* enabled
866870
* @multicast_mode: Enable or disable multicast optimizations on this node's
867871
* sender/originating side
868-
* @gw_mode: gateway operation: off, client or server (see batadv_gw_modes)
869-
* @gw_sel_class: gateway selection class (applies if gw_mode client)
870872
* @orig_interval: OGM broadcast interval in milliseconds
871873
* @hop_penalty: penalty which will be applied to an OGM's tq-field on every hop
872874
* @log_level: configured log level (see batadv_dbg_level)
@@ -922,8 +924,6 @@ struct batadv_priv {
922924
#ifdef CONFIG_BATMAN_ADV_MCAST
923925
atomic_t multicast_mode;
924926
#endif
925-
atomic_t gw_mode;
926-
atomic_t gw_sel_class;
927927
atomic_t orig_interval;
928928
atomic_t hop_penalty;
929929
#ifdef CONFIG_BATMAN_ADV_DEBUG

0 commit comments

Comments
 (0)