Skip to content

Commit 5cce04b

Browse files
author
Thomas Graf
committed
datapath: move make_writable helper into common code
note that skb_make_writable already exists in net/netfilter/core.c but does something slightly different. Upstream: e219512 ("net: move make_writable helper into common code") Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Pravin B Shelar <pshelar@nicira.com>
1 parent 17e3889 commit 5cce04b

4 files changed

Lines changed: 33 additions & 25 deletions

File tree

acinclude.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
345345
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [int.skb_zerocopy(],
346346
[OVS_DEFINE([HAVE_SKB_ZEROCOPY])])
347347
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [l4_rxhash])
348+
OVS_GREP_IFELSE([$KSRC/include/linux/skbuff.h], [skb_ensure_writable])
348349
349350
OVS_GREP_IFELSE([$KSRC/include/linux/types.h], [bool],
350351
[OVS_DEFINE([HAVE_BOOL_TYPE])])

datapath/actions.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ static bool is_flow_key_valid(const struct sw_flow_key *key)
122122
return !!key->eth.type;
123123
}
124124

125-
static int make_writable(struct sk_buff *skb, int write_len)
126-
{
127-
if (!pskb_may_pull(skb, write_len))
128-
return -ENOMEM;
129-
130-
if (!skb_cloned(skb) || skb_clone_writable(skb, write_len))
131-
return 0;
132-
133-
return pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
134-
}
135-
136125
static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
137126
const struct ovs_action_push_mpls *mpls)
138127
{
@@ -174,7 +163,7 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
174163
struct ethhdr *hdr;
175164
int err;
176165

177-
err = make_writable(skb, skb->mac_len + MPLS_HLEN);
166+
err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
178167
if (unlikely(err))
179168
return err;
180169

@@ -207,7 +196,7 @@ static int set_mpls(struct sk_buff *skb, struct sw_flow_key *key,
207196
__be32 *stack;
208197
int err;
209198

210-
err = make_writable(skb, skb->mac_len + MPLS_HLEN);
199+
err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
211200
if (unlikely(err))
212201
return err;
213202

@@ -229,7 +218,7 @@ static int __pop_vlan_tci(struct sk_buff *skb, __be16 *current_tci)
229218
struct vlan_hdr *vhdr;
230219
int err;
231220

232-
err = make_writable(skb, VLAN_ETH_HLEN);
221+
err = skb_ensure_writable(skb, VLAN_ETH_HLEN);
233222
if (unlikely(err))
234223
return err;
235224

@@ -313,7 +302,7 @@ static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *key,
313302
const struct ovs_key_ethernet *eth_key)
314303
{
315304
int err;
316-
err = make_writable(skb, ETH_HLEN);
305+
err = skb_ensure_writable(skb, ETH_HLEN);
317306
if (unlikely(err))
318307
return err;
319308

@@ -419,8 +408,8 @@ static int set_ipv4(struct sk_buff *skb, struct sw_flow_key *key,
419408
struct iphdr *nh;
420409
int err;
421410

422-
err = make_writable(skb, skb_network_offset(skb) +
423-
sizeof(struct iphdr));
411+
err = skb_ensure_writable(skb, skb_network_offset(skb) +
412+
sizeof(struct iphdr));
424413
if (unlikely(err))
425414
return err;
426415

@@ -457,8 +446,8 @@ static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *key,
457446
__be32 *saddr;
458447
__be32 *daddr;
459448

460-
err = make_writable(skb, skb_network_offset(skb) +
461-
sizeof(struct ipv6hdr));
449+
err = skb_ensure_writable(skb, skb_network_offset(skb) +
450+
sizeof(struct ipv6hdr));
462451
if (unlikely(err))
463452
return err;
464453

@@ -500,7 +489,7 @@ static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *key,
500489
return 0;
501490
}
502491

503-
/* Must follow make_writable() since that can move the skb data. */
492+
/* Must follow skb_ensure_writable() since that can move the skb data. */
504493
static void set_tp_port(struct sk_buff *skb, __be16 *port,
505494
__be16 new_port, __sum16 *check)
506495
{
@@ -530,8 +519,8 @@ static int set_udp(struct sk_buff *skb, struct sw_flow_key *key,
530519
struct udphdr *uh;
531520
int err;
532521

533-
err = make_writable(skb, skb_transport_offset(skb) +
534-
sizeof(struct udphdr));
522+
err = skb_ensure_writable(skb, skb_transport_offset(skb) +
523+
sizeof(struct udphdr));
535524
if (unlikely(err))
536525
return err;
537526

@@ -555,8 +544,8 @@ static int set_tcp(struct sk_buff *skb, struct sw_flow_key *key,
555544
struct tcphdr *th;
556545
int err;
557546

558-
err = make_writable(skb, skb_transport_offset(skb) +
559-
sizeof(struct tcphdr));
547+
err = skb_ensure_writable(skb, skb_transport_offset(skb) +
548+
sizeof(struct tcphdr));
560549
if (unlikely(err))
561550
return err;
562551

@@ -581,7 +570,7 @@ static int set_sctp(struct sk_buff *skb, struct sw_flow_key *key,
581570
int err;
582571
unsigned int sctphoff = skb_transport_offset(skb);
583572

584-
err = make_writable(skb, sctphoff + sizeof(struct sctphdr));
573+
err = skb_ensure_writable(skb, sctphoff + sizeof(struct sctphdr));
585574
if (unlikely(err))
586575
return err;
587576

datapath/linux/compat/include/linux/skbuff.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,9 @@ static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
324324
}
325325
#endif
326326

327+
#ifndef HAVE_SKB_ENSURE_WRITABLE
328+
#define skb_ensure_writable rpl_skb_ensure_writable
329+
int skb_ensure_writable(struct sk_buff *skb, int write_len);
330+
#endif
331+
327332
#endif

datapath/linux/compat/skbuff-openvswitch.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,16 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)
124124
}
125125
#endif
126126
#endif
127+
128+
#ifndef HAVE_SKB_ENSURE_WRITABLE
129+
int skb_ensure_writable(struct sk_buff *skb, int write_len)
130+
{
131+
if (!pskb_may_pull(skb, write_len))
132+
return -ENOMEM;
133+
134+
if (!skb_cloned(skb) || skb_clone_writable(skb, write_len))
135+
return 0;
136+
137+
return pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
138+
}
139+
#endif

0 commit comments

Comments
 (0)