Skip to content
This repository was archived by the owner on Dec 27, 2019. It is now read-only.

Commit aca7328

Browse files
committed
device: prepare skb_list_walk_safe for upstreaming
1 parent 9f8ab32 commit aca7328

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
171171
dev_kfree_skb(skb);
172172
skb = segs;
173173
}
174-
do {
175-
next = skb->next;
174+
175+
skb_list_walk_safe(skb, skb, next) {
176176
skb_mark_not_on_list(skb);
177177

178178
skb = skb_share_check(skb, GFP_ATOMIC);
@@ -187,7 +187,7 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
187187
PACKET_CB(skb)->mtu = mtu;
188188

189189
__skb_queue_tail(&packets, skb);
190-
} while ((skb = next) != NULL);
190+
}
191191

192192
spin_lock_bh(&peer->staged_packet_queue.lock);
193193
/* If the queue is getting too big, we start removing the oldest packets

src/device.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ struct wg_device {
6262
int wg_device_init(void);
6363
void wg_device_uninit(void);
6464

65+
/* Later after the dust settles, this can be moved into include/linux/sk_buff.h,
66+
* where virtually all code that deals with GSO segs can benefit, around ~30
67+
* drivers as of writing.
68+
*/
69+
#define skb_list_walk_safe(first, skb, next) \
70+
for (skb = first, next = skb->next; skb; \
71+
skb = next, next = skb ? skb->next : NULL)
72+
6573
#endif /* _WG_DEVICE_H */

src/send.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ void wg_packet_send_keepalive(struct wg_peer *peer)
233233
wg_packet_send_staged_packets(peer);
234234
}
235235

236-
#define skb_walk_null_queue_safe(first, skb, next) \
237-
for (skb = first, next = skb->next; skb; \
238-
skb = next, next = skb ? skb->next : NULL)
239-
240236
static void wg_packet_create_data_done(struct sk_buff *first,
241237
struct wg_peer *peer)
242238
{
@@ -245,7 +241,7 @@ static void wg_packet_create_data_done(struct sk_buff *first,
245241

246242
wg_timers_any_authenticated_packet_traversal(peer);
247243
wg_timers_any_authenticated_packet_sent(peer);
248-
skb_walk_null_queue_safe(first, skb, next) {
244+
skb_list_walk_safe(first, skb, next) {
249245
is_keepalive = skb->len == message_data_len(0);
250246
if (likely(!wg_socket_send_skb_to_peer(peer, skb,
251247
PACKET_CB(skb)->ds) && !is_keepalive))
@@ -295,7 +291,7 @@ void wg_packet_encrypt_worker(struct work_struct *work)
295291
while ((first = ptr_ring_consume_bh(&queue->ring)) != NULL) {
296292
enum packet_state state = PACKET_STATE_CRYPTED;
297293

298-
skb_walk_null_queue_safe(first, skb, next) {
294+
skb_list_walk_safe(first, skb, next) {
299295
if (likely(encrypt_packet(skb,
300296
PACKET_CB(first)->keypair,
301297
&simd_context))) {

0 commit comments

Comments
 (0)