Skip to content

Commit 10a5af2

Browse files
Jiri Bencdavem330
authored andcommitted
vxlan: simplify metadata_dst usage in vxlan_rcv
Now when the packet is scrubbed early, the metadata_dst can be assigned to the skb as soon as it is allocated. This simplifies the error cleanup path, as the dst will be freed by kfree_skb. It is also not necessary to pass it as a parameter to functions anymore. Signed-off-by: Jiri Benc <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f2d1968 commit 10a5af2

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

drivers/net/vxlan.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,16 +1165,17 @@ static bool vxlan_remcsum(struct vxlanhdr *unparsed,
11651165

11661166
static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
11671167
struct sk_buff *skb, u32 vxflags,
1168-
struct vxlan_metadata *md,
1169-
struct metadata_dst *tun_dst)
1168+
struct vxlan_metadata *md)
11701169
{
11711170
struct vxlanhdr_gbp *gbp = (struct vxlanhdr_gbp *)unparsed;
1171+
struct metadata_dst *tun_dst;
11721172

11731173
if (!(unparsed->vx_flags & VXLAN_HF_GBP))
11741174
goto out;
11751175

11761176
md->gbp = ntohs(gbp->policy_id);
11771177

1178+
tun_dst = (struct metadata_dst *)skb_dst(skb);
11781179
if (tun_dst)
11791180
tun_dst->u.tun_info.key.tun_flags |= TUNNEL_VXLAN_OPT;
11801181

@@ -1250,7 +1251,6 @@ static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
12501251
/* Callback from net/ipv4/udp.c to receive packets */
12511252
static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
12521253
{
1253-
struct metadata_dst *tun_dst = NULL;
12541254
struct pcpu_sw_netstats *stats;
12551255
struct vxlan_dev *vxlan;
12561256
struct vxlan_sock *vs;
@@ -1289,6 +1289,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
12891289

12901290
if (vxlan_collect_metadata(vs)) {
12911291
__be32 vni = vxlan_vni(vxlan_hdr(skb)->vx_vni);
1292+
struct metadata_dst *tun_dst;
12921293

12931294
tun_dst = udp_tun_rx_dst(skb, vxlan_get_sk_family(vs), TUNNEL_KEY,
12941295
vxlan_vni_to_tun_id(vni), sizeof(*md));
@@ -1297,6 +1298,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
12971298
goto drop;
12981299

12991300
md = ip_tunnel_info_opts(&tun_dst->u.tun_info);
1301+
1302+
skb_dst_set(skb, (struct dst_entry *)tun_dst);
13001303
} else {
13011304
memset(md, 0, sizeof(*md));
13021305
}
@@ -1308,7 +1311,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
13081311
if (!vxlan_remcsum(&unparsed, skb, vs->flags))
13091312
goto drop;
13101313
if (vs->flags & VXLAN_F_GBP)
1311-
vxlan_parse_gbp_hdr(&unparsed, skb, vs->flags, md, tun_dst);
1314+
vxlan_parse_gbp_hdr(&unparsed, skb, vs->flags, md);
13121315

13131316
if (unparsed.vx_flags || unparsed.vx_vni) {
13141317
/* If there are any unprocessed flags remaining treat
@@ -1325,11 +1328,6 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
13251328
if (!vxlan_set_mac(vxlan, vs, skb))
13261329
goto drop;
13271330

1328-
if (tun_dst) {
1329-
skb_dst_set(skb, (struct dst_entry *)tun_dst);
1330-
tun_dst = NULL;
1331-
}
1332-
13331331
oiph = skb_network_header(skb);
13341332
skb_reset_network_header(skb);
13351333

@@ -1349,9 +1347,6 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
13491347
return 0;
13501348

13511349
drop:
1352-
if (tun_dst)
1353-
dst_release((struct dst_entry *)tun_dst);
1354-
13551350
/* Consume bad packet */
13561351
kfree_skb(skb);
13571352
return 0;

0 commit comments

Comments
 (0)