Skip to content

Commit 414254e

Browse files
Marek Lindnerordex
authored andcommitted
batman-adv: tvlv - gateway download/upload bandwidth container
Prior to this patch batman-adv read the advertised uplink bandwidth from userspace and compressed this information into a single byte called "gateway class". Now the download & upload bandwidth information is sent as-is. No userspace change is necessary since the sysfs API always allowed to specify a bandwidth. Signed-off-by: Marek Lindner <lindner_marek@yahoo.de> Signed-off-by: Spyros Gasteratos <morfeas3000@gmail.com> Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
1 parent ef26157 commit 414254e

11 files changed

Lines changed: 327 additions & 191 deletions

File tree

‎net/batman-adv/bat_iv_ogm.c‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
135135
batadv_ogm_packet->header.version = BATADV_COMPAT_VERSION;
136136
batadv_ogm_packet->header.ttl = 2;
137137
batadv_ogm_packet->flags = BATADV_NO_FLAGS;
138+
batadv_ogm_packet->reserved = 0;
138139
batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE;
139140
batadv_ogm_packet->tt_num_changes = 0;
140141
batadv_ogm_packet->ttvn = 0;
@@ -690,7 +691,6 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
690691
int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
691692
int vis_server, tt_num_changes = 0;
692693
uint32_t seqno;
693-
uint8_t bandwidth;
694694
uint16_t tvlv_len = 0;
695695

696696
vis_server = atomic_read(&bat_priv->vis_mode);
@@ -719,14 +719,6 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
719719
else
720720
batadv_ogm_packet->flags &= ~BATADV_VIS_SERVER;
721721

722-
if (hard_iface == primary_if &&
723-
atomic_read(&bat_priv->gw_mode) == BATADV_GW_MODE_SERVER) {
724-
bandwidth = (uint8_t)atomic_read(&bat_priv->gw_bandwidth);
725-
batadv_ogm_packet->gw_flags = bandwidth;
726-
} else {
727-
batadv_ogm_packet->gw_flags = BATADV_NO_FLAGS;
728-
}
729-
730722
batadv_iv_ogm_slide_own_bcast_window(hard_iface);
731723
batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
732724
hard_iface->bat_iv.ogm_buff_len, hard_iface, 1,
@@ -861,19 +853,6 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
861853
batadv_ogm_packet->tt_num_changes,
862854
batadv_ogm_packet->ttvn,
863855
ntohs(batadv_ogm_packet->tt_crc));
864-
865-
if (orig_node->gw_flags != batadv_ogm_packet->gw_flags)
866-
batadv_gw_node_update(bat_priv, orig_node,
867-
batadv_ogm_packet->gw_flags);
868-
869-
orig_node->gw_flags = batadv_ogm_packet->gw_flags;
870-
871-
/* restart gateway selection if fast or late switching was enabled */
872-
if ((orig_node->gw_flags) &&
873-
(atomic_read(&bat_priv->gw_mode) == BATADV_GW_MODE_CLIENT) &&
874-
(atomic_read(&bat_priv->gw_sel_class) > 2))
875-
batadv_gw_check_election(bat_priv, orig_node);
876-
877856
goto out;
878857

879858
unlock:

‎net/batman-adv/gateway_client.c‎

Lines changed: 121 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
118118
uint32_t max_gw_factor = 0, tmp_gw_factor = 0;
119119
uint32_t gw_divisor;
120120
uint8_t max_tq = 0;
121-
int down, up;
122121
uint8_t tq_avg;
123122
struct batadv_orig_node *orig_node;
124123

@@ -142,10 +141,9 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
142141

143142
switch (atomic_read(&bat_priv->gw_sel_class)) {
144143
case 1: /* fast connection */
145-
batadv_gw_bandwidth_to_kbit(orig_node->gw_flags,
146-
&down, &up);
147-
148-
tmp_gw_factor = tq_avg * tq_avg * down * 100 * 100;
144+
tmp_gw_factor = tq_avg * tq_avg;
145+
tmp_gw_factor *= gw_node->bandwidth_down;
146+
tmp_gw_factor *= 100 * 100;
149147
tmp_gw_factor /= gw_divisor;
150148

151149
if ((tmp_gw_factor > max_gw_factor) ||
@@ -258,16 +256,22 @@ void batadv_gw_election(struct batadv_priv *bat_priv)
258256
NULL);
259257
} else if ((!curr_gw) && (next_gw)) {
260258
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
261-
"Adding route to gateway %pM (gw_flags: %i, tq: %i)\n",
259+
"Adding route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n",
262260
next_gw->orig_node->orig,
263-
next_gw->orig_node->gw_flags, router->tq_avg);
261+
next_gw->bandwidth_down / 10,
262+
next_gw->bandwidth_down % 10,
263+
next_gw->bandwidth_up / 10,
264+
next_gw->bandwidth_up % 10, router->tq_avg);
264265
batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD,
265266
gw_addr);
266267
} else {
267268
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
268-
"Changing route to gateway %pM (gw_flags: %i, tq: %i)\n",
269+
"Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n",
269270
next_gw->orig_node->orig,
270-
next_gw->orig_node->gw_flags, router->tq_avg);
271+
next_gw->bandwidth_down / 10,
272+
next_gw->bandwidth_down % 10,
273+
next_gw->bandwidth_up / 10,
274+
next_gw->bandwidth_up % 10, router->tq_avg);
271275
batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE,
272276
gw_addr);
273277
}
@@ -337,12 +341,20 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv,
337341
return;
338342
}
339343

344+
/**
345+
* batadv_gw_node_add - add gateway node to list of available gateways
346+
* @bat_priv: the bat priv with all the soft interface information
347+
* @orig_node: originator announcing gateway capabilities
348+
* @gateway: announced bandwidth information
349+
*/
340350
static void batadv_gw_node_add(struct batadv_priv *bat_priv,
341351
struct batadv_orig_node *orig_node,
342-
uint8_t new_gwflags)
352+
struct batadv_tvlv_gateway_data *gateway)
343353
{
344354
struct batadv_gw_node *gw_node;
345-
int down, up;
355+
356+
if (gateway->bandwidth_down == 0)
357+
return;
346358

347359
gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
348360
if (!gw_node)
@@ -356,73 +368,116 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
356368
hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.list);
357369
spin_unlock_bh(&bat_priv->gw.list_lock);
358370

359-
batadv_gw_bandwidth_to_kbit(new_gwflags, &down, &up);
360371
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
361-
"Found new gateway %pM -> gw_class: %i - %i%s/%i%s\n",
362-
orig_node->orig, new_gwflags,
363-
(down > 2048 ? down / 1024 : down),
364-
(down > 2048 ? "MBit" : "KBit"),
365-
(up > 2048 ? up / 1024 : up),
366-
(up > 2048 ? "MBit" : "KBit"));
372+
"Found new gateway %pM -> gw bandwidth: %u.%u/%u.%u MBit\n",
373+
orig_node->orig,
374+
ntohl(gateway->bandwidth_down) / 10,
375+
ntohl(gateway->bandwidth_down) % 10,
376+
ntohl(gateway->bandwidth_up) / 10,
377+
ntohl(gateway->bandwidth_up) % 10);
367378
}
368379

369-
void batadv_gw_node_update(struct batadv_priv *bat_priv,
370-
struct batadv_orig_node *orig_node,
371-
uint8_t new_gwflags)
380+
/**
381+
* batadv_gw_node_get - retrieve gateway node from list of available gateways
382+
* @bat_priv: the bat priv with all the soft interface information
383+
* @orig_node: originator announcing gateway capabilities
384+
*
385+
* Returns gateway node if found or NULL otherwise.
386+
*/
387+
static struct batadv_gw_node *
388+
batadv_gw_node_get(struct batadv_priv *bat_priv,
389+
struct batadv_orig_node *orig_node)
372390
{
373-
struct batadv_gw_node *gw_node, *curr_gw;
374-
375-
/* Note: We don't need a NULL check here, since curr_gw never gets
376-
* dereferenced. If curr_gw is NULL we also should not exit as we may
377-
* have this gateway in our list (duplication check!) even though we
378-
* have no currently selected gateway.
379-
*/
380-
curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
391+
struct batadv_gw_node *gw_node_tmp, *gw_node = NULL;
381392

382393
rcu_read_lock();
383-
hlist_for_each_entry_rcu(gw_node, &bat_priv->gw.list, list) {
384-
if (gw_node->orig_node != orig_node)
394+
hlist_for_each_entry_rcu(gw_node_tmp, &bat_priv->gw.list, list) {
395+
if (gw_node_tmp->orig_node != orig_node)
385396
continue;
386397

387-
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
388-
"Gateway class of originator %pM changed from %i to %i\n",
389-
orig_node->orig, gw_node->orig_node->gw_flags,
390-
new_gwflags);
398+
if (gw_node_tmp->deleted)
399+
continue;
391400

392-
gw_node->deleted = 0;
401+
if (!atomic_inc_not_zero(&gw_node_tmp->refcount))
402+
continue;
393403

394-
if (new_gwflags == BATADV_NO_FLAGS) {
395-
gw_node->deleted = jiffies;
396-
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
397-
"Gateway %pM removed from gateway list\n",
398-
orig_node->orig);
404+
gw_node = gw_node_tmp;
405+
break;
406+
}
407+
rcu_read_unlock();
399408

400-
if (gw_node == curr_gw)
401-
goto deselect;
402-
}
409+
return gw_node;
410+
}
403411

404-
goto unlock;
412+
/**
413+
* batadv_gw_node_update - update list of available gateways with changed
414+
* bandwidth information
415+
* @bat_priv: the bat priv with all the soft interface information
416+
* @orig_node: originator announcing gateway capabilities
417+
* @gateway: announced bandwidth information
418+
*/
419+
void batadv_gw_node_update(struct batadv_priv *bat_priv,
420+
struct batadv_orig_node *orig_node,
421+
struct batadv_tvlv_gateway_data *gateway)
422+
{
423+
struct batadv_gw_node *gw_node, *curr_gw = NULL;
424+
425+
gw_node = batadv_gw_node_get(bat_priv, orig_node);
426+
if (!gw_node) {
427+
batadv_gw_node_add(bat_priv, orig_node, gateway);
428+
goto out;
405429
}
406430

407-
if (new_gwflags == BATADV_NO_FLAGS)
408-
goto unlock;
431+
if ((gw_node->bandwidth_down == ntohl(gateway->bandwidth_down)) &&
432+
(gw_node->bandwidth_up == ntohl(gateway->bandwidth_up)))
433+
goto out;
409434

410-
batadv_gw_node_add(bat_priv, orig_node, new_gwflags);
411-
goto unlock;
435+
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
436+
"Gateway bandwidth of originator %pM changed from %u.%u/%u.%u MBit to %u.%u/%u.%u MBit\n",
437+
orig_node->orig,
438+
gw_node->bandwidth_down / 10,
439+
gw_node->bandwidth_down % 10,
440+
gw_node->bandwidth_up / 10,
441+
gw_node->bandwidth_up % 10,
442+
ntohl(gateway->bandwidth_down) / 10,
443+
ntohl(gateway->bandwidth_down) % 10,
444+
ntohl(gateway->bandwidth_up) / 10,
445+
ntohl(gateway->bandwidth_up) % 10);
446+
447+
gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
448+
gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
449+
450+
gw_node->deleted = 0;
451+
if (ntohl(gateway->bandwidth_down) == 0) {
452+
gw_node->deleted = jiffies;
453+
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
454+
"Gateway %pM removed from gateway list\n",
455+
orig_node->orig);
412456

413-
deselect:
414-
batadv_gw_deselect(bat_priv);
415-
unlock:
416-
rcu_read_unlock();
457+
/* Note: We don't need a NULL check here, since curr_gw never
458+
* gets dereferenced.
459+
*/
460+
curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
461+
if (gw_node == curr_gw)
462+
batadv_gw_deselect(bat_priv);
463+
}
417464

465+
out:
418466
if (curr_gw)
419467
batadv_gw_node_free_ref(curr_gw);
468+
if (gw_node)
469+
batadv_gw_node_free_ref(gw_node);
420470
}
421471

422472
void batadv_gw_node_delete(struct batadv_priv *bat_priv,
423473
struct batadv_orig_node *orig_node)
424474
{
425-
batadv_gw_node_update(bat_priv, orig_node, 0);
475+
struct batadv_tvlv_gateway_data gateway;
476+
477+
gateway.bandwidth_down = 0;
478+
gateway.bandwidth_up = 0;
479+
480+
batadv_gw_node_update(bat_priv, orig_node, &gateway);
426481
}
427482

428483
void batadv_gw_node_purge(struct batadv_priv *bat_priv)
@@ -467,26 +522,23 @@ static int batadv_write_buffer_text(struct batadv_priv *bat_priv,
467522
{
468523
struct batadv_gw_node *curr_gw;
469524
struct batadv_neigh_node *router;
470-
int down, up, ret = -1;
471-
472-
batadv_gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags, &down, &up);
525+
int ret = -1;
473526

474527
router = batadv_orig_node_get_router(gw_node->orig_node);
475528
if (!router)
476529
goto out;
477530

478531
curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
479532

480-
ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %3i - %i%s/%i%s\n",
533+
ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n",
481534
(curr_gw == gw_node ? "=>" : " "),
482535
gw_node->orig_node->orig,
483536
router->tq_avg, router->addr,
484537
router->if_incoming->net_dev->name,
485-
gw_node->orig_node->gw_flags,
486-
(down > 2048 ? down / 1024 : down),
487-
(down > 2048 ? "MBit" : "KBit"),
488-
(up > 2048 ? up / 1024 : up),
489-
(up > 2048 ? "MBit" : "KBit"));
538+
gw_node->bandwidth_down / 10,
539+
gw_node->bandwidth_down % 10,
540+
gw_node->bandwidth_up / 10,
541+
gw_node->bandwidth_up % 10);
490542

491543
batadv_neigh_node_free_ref(router);
492544
if (curr_gw)
@@ -508,7 +560,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
508560
goto out;
509561

510562
seq_printf(seq,
511-
" %-12s (%s/%i) %17s [%10s]: gw_class ... [B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
563+
" %-12s (%s/%i) %17s [%10s]: advertised uplink bandwidth ... [B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
512564
"Gateway", "#", BATADV_TQ_MAX_VALUE, "Nexthop", "outgoingIF",
513565
BATADV_SOURCE_VERSION, primary_if->net_dev->name,
514566
primary_if->net_dev->dev_addr, net_dev->name);
@@ -675,7 +727,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
675727
{
676728
struct batadv_neigh_node *neigh_curr = NULL, *neigh_old = NULL;
677729
struct batadv_orig_node *orig_dst_node = NULL;
678-
struct batadv_gw_node *curr_gw = NULL;
730+
struct batadv_gw_node *gw_node = NULL, *curr_gw = NULL;
679731
struct ethhdr *ethhdr;
680732
bool ret, out_of_range = false;
681733
unsigned int header_len = 0;
@@ -691,7 +743,8 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
691743
if (!orig_dst_node)
692744
goto out;
693745

694-
if (!orig_dst_node->gw_flags)
746+
gw_node = batadv_gw_node_get(bat_priv, orig_dst_node);
747+
if (!gw_node->bandwidth_down == 0)
695748
goto out;
696749

697750
ret = batadv_is_type_dhcprequest(skb, header_len);
@@ -742,6 +795,8 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
742795
batadv_orig_node_free_ref(orig_dst_node);
743796
if (curr_gw)
744797
batadv_gw_node_free_ref(curr_gw);
798+
if (gw_node)
799+
batadv_gw_node_free_ref(gw_node);
745800
if (neigh_old)
746801
batadv_neigh_node_free_ref(neigh_old);
747802
if (neigh_curr)

‎net/batman-adv/gateway_client.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv,
2929
struct batadv_orig_node *orig_node);
3030
void batadv_gw_node_update(struct batadv_priv *bat_priv,
3131
struct batadv_orig_node *orig_node,
32-
uint8_t new_gwflags);
32+
struct batadv_tvlv_gateway_data *gateway);
3333
void batadv_gw_node_delete(struct batadv_priv *bat_priv,
3434
struct batadv_orig_node *orig_node);
3535
void batadv_gw_node_purge(struct batadv_priv *bat_priv);

0 commit comments

Comments
 (0)