Skip to content

Commit 1ab016e

Browse files
Jiri Bencdavem330
authored andcommitted
vxlan: move inner L2 header processing to a separate function
This code will be different for VXLAN-GPE, so move it to a separate function. It will also make the rx path less spaghetti-like. Signed-off-by: Jiri Benc <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 64f87d3 commit 1ab016e

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

drivers/net/vxlan.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,46 +1191,63 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
11911191
unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS;
11921192
}
11931193

1194-
static void vxlan_rcv(struct vxlan_dev *vxlan, struct vxlan_sock *vs,
1195-
struct sk_buff *skb, struct vxlan_metadata *md,
1196-
struct metadata_dst *tun_dst)
1194+
static bool vxlan_set_mac(struct vxlan_dev *vxlan,
1195+
struct vxlan_sock *vs,
1196+
struct sk_buff *skb)
11971197
{
1198-
struct iphdr *oip = NULL;
1199-
struct ipv6hdr *oip6 = NULL;
1200-
struct pcpu_sw_netstats *stats;
12011198
union vxlan_addr saddr;
1202-
int err = 0;
12031199

12041200
skb_reset_mac_header(skb);
12051201
skb->protocol = eth_type_trans(skb, vxlan->dev);
12061202
skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
12071203

12081204
/* Ignore packet loops (and multicast echo) */
12091205
if (ether_addr_equal(eth_hdr(skb)->h_source, vxlan->dev->dev_addr))
1210-
goto drop;
1206+
return false;
12111207

12121208
/* Get data from the outer IP header */
12131209
if (vxlan_get_sk_family(vs) == AF_INET) {
1214-
oip = ip_hdr(skb);
1215-
saddr.sin.sin_addr.s_addr = oip->saddr;
1210+
saddr.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
12161211
saddr.sa.sa_family = AF_INET;
12171212
#if IS_ENABLED(CONFIG_IPV6)
12181213
} else {
1219-
oip6 = ipv6_hdr(skb);
1220-
saddr.sin6.sin6_addr = oip6->saddr;
1214+
saddr.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
12211215
saddr.sa.sa_family = AF_INET6;
12221216
#endif
12231217
}
12241218

1219+
if ((vxlan->flags & VXLAN_F_LEARN) &&
1220+
vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source))
1221+
return false;
1222+
1223+
return true;
1224+
}
1225+
1226+
static void vxlan_rcv(struct vxlan_dev *vxlan, struct vxlan_sock *vs,
1227+
struct sk_buff *skb, struct vxlan_metadata *md,
1228+
struct metadata_dst *tun_dst)
1229+
{
1230+
struct iphdr *oip = NULL;
1231+
struct ipv6hdr *oip6 = NULL;
1232+
struct pcpu_sw_netstats *stats;
1233+
int err = 0;
1234+
1235+
if (!vxlan_set_mac(vxlan, vs, skb))
1236+
goto drop;
1237+
1238+
/* Get data from the outer IP header */
1239+
if (vxlan_get_sk_family(vs) == AF_INET)
1240+
oip = ip_hdr(skb);
1241+
#if IS_ENABLED(CONFIG_IPV6)
1242+
else
1243+
oip6 = ipv6_hdr(skb);
1244+
#endif
1245+
12251246
if (tun_dst) {
12261247
skb_dst_set(skb, (struct dst_entry *)tun_dst);
12271248
tun_dst = NULL;
12281249
}
12291250

1230-
if ((vxlan->flags & VXLAN_F_LEARN) &&
1231-
vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source))
1232-
goto drop;
1233-
12341251
skb_reset_network_header(skb);
12351252

12361253
if (oip6)

0 commit comments

Comments
 (0)