Skip to content

Commit b3a598e

Browse files
committed
Merge tag 'batadv-next-for-davem-20190808' of git://git.open-mesh.org/linux-merge
Simon Wunderlich says: ==================== This feature/cleanup patchset includes the following patches: - bump version strings, by Simon Wunderlich - Replace usage of strlcpy with strscpy, by Sven Eckelmann - Add OGMv2 per-interface queue and aggregations, by Linus Luessing (2 patches) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 13dfb3f + 9cb9a17 commit b3a598e

File tree

7 files changed

+205
-8
lines changed

7 files changed

+205
-8
lines changed

net/batman-adv/bat_v.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
7979

8080
static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface)
8181
{
82+
batadv_v_ogm_iface_disable(hard_iface);
8283
batadv_v_elp_iface_disable(hard_iface);
8384
}
8485

@@ -1081,6 +1082,12 @@ void batadv_v_hardif_init(struct batadv_hard_iface *hard_iface)
10811082
*/
10821083
atomic_set(&hard_iface->bat_v.throughput_override, 0);
10831084
atomic_set(&hard_iface->bat_v.elp_interval, 500);
1085+
1086+
hard_iface->bat_v.aggr_len = 0;
1087+
skb_queue_head_init(&hard_iface->bat_v.aggr_list);
1088+
spin_lock_init(&hard_iface->bat_v.aggr_list_lock);
1089+
INIT_DELAYED_WORK(&hard_iface->bat_v.aggr_wq,
1090+
batadv_v_ogm_aggr_work);
10841091
}
10851092

10861093
/**

net/batman-adv/bat_v_ogm.c

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
#include <linux/kernel.h>
1818
#include <linux/kref.h>
1919
#include <linux/list.h>
20+
#include <linux/lockdep.h>
2021
#include <linux/netdevice.h>
2122
#include <linux/random.h>
2223
#include <linux/rculist.h>
2324
#include <linux/rcupdate.h>
2425
#include <linux/skbuff.h>
2526
#include <linux/slab.h>
27+
#include <linux/spinlock.h>
2628
#include <linux/stddef.h>
2729
#include <linux/string.h>
2830
#include <linux/types.h>
@@ -76,6 +78,20 @@ struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv,
7678
return orig_node;
7779
}
7880

81+
/**
82+
* batadv_v_ogm_start_queue_timer() - restart the OGM aggregation timer
83+
* @hard_iface: the interface to use to send the OGM
84+
*/
85+
static void batadv_v_ogm_start_queue_timer(struct batadv_hard_iface *hard_iface)
86+
{
87+
unsigned int msecs = BATADV_MAX_AGGREGATION_MS * 1000;
88+
89+
/* msecs * [0.9, 1.1] */
90+
msecs += prandom_u32() % (msecs / 5) - (msecs / 10);
91+
queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.aggr_wq,
92+
msecs_to_jiffies(msecs / 1000));
93+
}
94+
7995
/**
8096
* batadv_v_ogm_start_timer() - restart the OGM sending timer
8197
* @bat_priv: the bat priv with all the soft interface information
@@ -115,6 +131,130 @@ static void batadv_v_ogm_send_to_if(struct sk_buff *skb,
115131
batadv_send_broadcast_skb(skb, hard_iface);
116132
}
117133

134+
/**
135+
* batadv_v_ogm_len() - OGMv2 packet length
136+
* @skb: the OGM to check
137+
*
138+
* Return: Length of the given OGMv2 packet, including tvlv length, excluding
139+
* ethernet header length.
140+
*/
141+
static unsigned int batadv_v_ogm_len(struct sk_buff *skb)
142+
{
143+
struct batadv_ogm2_packet *ogm_packet;
144+
145+
ogm_packet = (struct batadv_ogm2_packet *)skb->data;
146+
return BATADV_OGM2_HLEN + ntohs(ogm_packet->tvlv_len);
147+
}
148+
149+
/**
150+
* batadv_v_ogm_queue_left() - check if given OGM still fits aggregation queue
151+
* @skb: the OGM to check
152+
* @hard_iface: the interface to use to send the OGM
153+
*
154+
* Caller needs to hold the hard_iface->bat_v.aggr_list_lock.
155+
*
156+
* Return: True, if the given OGMv2 packet still fits, false otherwise.
157+
*/
158+
static bool batadv_v_ogm_queue_left(struct sk_buff *skb,
159+
struct batadv_hard_iface *hard_iface)
160+
{
161+
unsigned int max = min_t(unsigned int, hard_iface->net_dev->mtu,
162+
BATADV_MAX_AGGREGATION_BYTES);
163+
unsigned int ogm_len = batadv_v_ogm_len(skb);
164+
165+
lockdep_assert_held(&hard_iface->bat_v.aggr_list_lock);
166+
167+
return hard_iface->bat_v.aggr_len + ogm_len <= max;
168+
}
169+
170+
/**
171+
* batadv_v_ogm_aggr_list_free - free all elements in an aggregation queue
172+
* @hard_iface: the interface holding the aggregation queue
173+
*
174+
* Empties the OGMv2 aggregation queue and frees all the skbs it contained.
175+
*
176+
* Caller needs to hold the hard_iface->bat_v.aggr_list_lock.
177+
*/
178+
static void batadv_v_ogm_aggr_list_free(struct batadv_hard_iface *hard_iface)
179+
{
180+
struct sk_buff *skb;
181+
182+
lockdep_assert_held(&hard_iface->bat_v.aggr_list_lock);
183+
184+
while ((skb = skb_dequeue(&hard_iface->bat_v.aggr_list)))
185+
kfree_skb(skb);
186+
187+
hard_iface->bat_v.aggr_len = 0;
188+
}
189+
190+
/**
191+
* batadv_v_ogm_aggr_send() - flush & send aggregation queue
192+
* @hard_iface: the interface with the aggregation queue to flush
193+
*
194+
* Aggregates all OGMv2 packets currently in the aggregation queue into a
195+
* single OGMv2 packet and transmits this aggregate.
196+
*
197+
* The aggregation queue is empty after this call.
198+
*
199+
* Caller needs to hold the hard_iface->bat_v.aggr_list_lock.
200+
*/
201+
static void batadv_v_ogm_aggr_send(struct batadv_hard_iface *hard_iface)
202+
{
203+
unsigned int aggr_len = hard_iface->bat_v.aggr_len;
204+
struct sk_buff *skb_aggr;
205+
unsigned int ogm_len;
206+
struct sk_buff *skb;
207+
208+
lockdep_assert_held(&hard_iface->bat_v.aggr_list_lock);
209+
210+
if (!aggr_len)
211+
return;
212+
213+
skb_aggr = dev_alloc_skb(aggr_len + ETH_HLEN + NET_IP_ALIGN);
214+
if (!skb_aggr) {
215+
batadv_v_ogm_aggr_list_free(hard_iface);
216+
return;
217+
}
218+
219+
skb_reserve(skb_aggr, ETH_HLEN + NET_IP_ALIGN);
220+
skb_reset_network_header(skb_aggr);
221+
222+
while ((skb = skb_dequeue(&hard_iface->bat_v.aggr_list))) {
223+
hard_iface->bat_v.aggr_len -= batadv_v_ogm_len(skb);
224+
225+
ogm_len = batadv_v_ogm_len(skb);
226+
skb_put_data(skb_aggr, skb->data, ogm_len);
227+
228+
consume_skb(skb);
229+
}
230+
231+
batadv_v_ogm_send_to_if(skb_aggr, hard_iface);
232+
}
233+
234+
/**
235+
* batadv_v_ogm_queue_on_if() - queue a batman ogm on a given interface
236+
* @skb: the OGM to queue
237+
* @hard_iface: the interface to queue the OGM on
238+
*/
239+
static void batadv_v_ogm_queue_on_if(struct sk_buff *skb,
240+
struct batadv_hard_iface *hard_iface)
241+
{
242+
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
243+
244+
if (!atomic_read(&bat_priv->aggregated_ogms)) {
245+
batadv_v_ogm_send_to_if(skb, hard_iface);
246+
return;
247+
}
248+
249+
spin_lock_bh(&hard_iface->bat_v.aggr_list_lock);
250+
if (!batadv_v_ogm_queue_left(skb, hard_iface))
251+
batadv_v_ogm_aggr_send(hard_iface);
252+
253+
hard_iface->bat_v.aggr_len += batadv_v_ogm_len(skb);
254+
skb_queue_tail(&hard_iface->bat_v.aggr_list, skb);
255+
spin_unlock_bh(&hard_iface->bat_v.aggr_list_lock);
256+
}
257+
118258
/**
119259
* batadv_v_ogm_send() - periodic worker broadcasting the own OGM
120260
* @work: work queue item
@@ -210,7 +350,7 @@ static void batadv_v_ogm_send(struct work_struct *work)
210350
break;
211351
}
212352

213-
batadv_v_ogm_send_to_if(skb_tmp, hard_iface);
353+
batadv_v_ogm_queue_on_if(skb_tmp, hard_iface);
214354
batadv_hardif_put(hard_iface);
215355
}
216356
rcu_read_unlock();
@@ -223,6 +363,27 @@ static void batadv_v_ogm_send(struct work_struct *work)
223363
return;
224364
}
225365

366+
/**
367+
* batadv_v_ogm_aggr_work() - OGM queue periodic task per interface
368+
* @work: work queue item
369+
*
370+
* Emits aggregated OGM message in regular intervals.
371+
*/
372+
void batadv_v_ogm_aggr_work(struct work_struct *work)
373+
{
374+
struct batadv_hard_iface_bat_v *batv;
375+
struct batadv_hard_iface *hard_iface;
376+
377+
batv = container_of(work, struct batadv_hard_iface_bat_v, aggr_wq.work);
378+
hard_iface = container_of(batv, struct batadv_hard_iface, bat_v);
379+
380+
spin_lock_bh(&hard_iface->bat_v.aggr_list_lock);
381+
batadv_v_ogm_aggr_send(hard_iface);
382+
spin_unlock_bh(&hard_iface->bat_v.aggr_list_lock);
383+
384+
batadv_v_ogm_start_queue_timer(hard_iface);
385+
}
386+
226387
/**
227388
* batadv_v_ogm_iface_enable() - prepare an interface for B.A.T.M.A.N. V
228389
* @hard_iface: the interface to prepare
@@ -235,11 +396,25 @@ int batadv_v_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
235396
{
236397
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
237398

399+
batadv_v_ogm_start_queue_timer(hard_iface);
238400
batadv_v_ogm_start_timer(bat_priv);
239401

240402
return 0;
241403
}
242404

405+
/**
406+
* batadv_v_ogm_iface_disable() - release OGM interface private resources
407+
* @hard_iface: interface for which the resources have to be released
408+
*/
409+
void batadv_v_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
410+
{
411+
cancel_delayed_work_sync(&hard_iface->bat_v.aggr_wq);
412+
413+
spin_lock_bh(&hard_iface->bat_v.aggr_list_lock);
414+
batadv_v_ogm_aggr_list_free(hard_iface);
415+
spin_unlock_bh(&hard_iface->bat_v.aggr_list_lock);
416+
}
417+
243418
/**
244419
* batadv_v_ogm_primary_iface_set() - set a new primary interface
245420
* @primary_iface: the new primary interface
@@ -382,7 +557,7 @@ static void batadv_v_ogm_forward(struct batadv_priv *bat_priv,
382557
if_outgoing->net_dev->name, ntohl(ogm_forward->throughput),
383558
ogm_forward->ttl, if_incoming->net_dev->name);
384559

385-
batadv_v_ogm_send_to_if(skb, if_outgoing);
560+
batadv_v_ogm_queue_on_if(skb, if_outgoing);
386561

387562
out:
388563
if (orig_ifinfo)

net/batman-adv/bat_v_ogm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
#include <linux/skbuff.h>
1313
#include <linux/types.h>
14+
#include <linux/workqueue.h>
1415

1516
int batadv_v_ogm_init(struct batadv_priv *bat_priv);
1617
void batadv_v_ogm_free(struct batadv_priv *bat_priv);
18+
void batadv_v_ogm_aggr_work(struct work_struct *work);
1719
int batadv_v_ogm_iface_enable(struct batadv_hard_iface *hard_iface);
20+
void batadv_v_ogm_iface_disable(struct batadv_hard_iface *hard_iface);
1821
struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv,
1922
const u8 *addr);
2023
void batadv_v_ogm_primary_iface_set(struct batadv_hard_iface *primary_iface);

net/batman-adv/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define BATADV_DRIVER_DEVICE "batman-adv"
1414

1515
#ifndef BATADV_SOURCE_VERSION
16-
#define BATADV_SOURCE_VERSION "2019.3"
16+
#define BATADV_SOURCE_VERSION "2019.4"
1717
#endif
1818

1919
/* B.A.T.M.A.N. parameters */

net/batman-adv/soft-interface.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,10 @@ static const struct net_device_ops batadv_netdev_ops = {
943943
static void batadv_get_drvinfo(struct net_device *dev,
944944
struct ethtool_drvinfo *info)
945945
{
946-
strlcpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
947-
strlcpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
948-
strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
949-
strlcpy(info->bus_info, "batman", sizeof(info->bus_info));
946+
strscpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
947+
strscpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
948+
strscpy(info->fw_version, "N/A", sizeof(info->fw_version));
949+
strscpy(info->bus_info, "batman", sizeof(info->bus_info));
950950
}
951951

952952
/* Inspired by drivers/net/ethernet/dlink/sundance.c:1702

net/batman-adv/sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static ssize_t batadv_store_mesh_iface(struct kobject *kobj,
10701070
dev_hold(net_dev);
10711071
INIT_WORK(&store_work->work, batadv_store_mesh_iface_work);
10721072
store_work->net_dev = net_dev;
1073-
strlcpy(store_work->soft_iface_name, buff,
1073+
strscpy(store_work->soft_iface_name, buff,
10741074
sizeof(store_work->soft_iface_name));
10751075

10761076
queue_work(batadv_event_workqueue, &store_work->work);

net/batman-adv/types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ struct batadv_hard_iface_bat_v {
117117
/** @elp_wq: workqueue used to schedule ELP transmissions */
118118
struct delayed_work elp_wq;
119119

120+
/** @aggr_wq: workqueue used to transmit queued OGM packets */
121+
struct delayed_work aggr_wq;
122+
123+
/** @aggr_list: queue for to be aggregated OGM packets */
124+
struct sk_buff_head aggr_list;
125+
126+
/** @aggr_len: size of the OGM aggregate (excluding ethernet header) */
127+
unsigned int aggr_len;
128+
129+
/** @aggr_list_lock: protects aggr_list */
130+
spinlock_t aggr_list_lock;
131+
120132
/**
121133
* @throughput_override: throughput override to disable link
122134
* auto-detection

0 commit comments

Comments
 (0)