Skip to content

Commit 2a04c7b

Browse files
committed
Merge branch 'vxlan-rx-cleanups'
Jiri Benc says: ==================== vxlan: consolidate rx handling Currently, vxlan_rcv is just called at the end of vxlan_udp_encap_recv, continuing the rx processing where vxlan_udp_encap_recv left it. There's no clear border between those two functions. This patchset moves vxlan_udp_encap_recv and vxlan_rcv into a single function. This also allows to do some simplification in error path. The VXLAN-GPE implementation that will follow up this set can be seen at: https://github.com/jbenc/linux-vxlan/commits/master ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 39661e2 + 10a5af2 commit 2a04c7b

File tree

1 file changed

+64
-67
lines changed

1 file changed

+64
-67
lines changed

drivers/net/vxlan.c

Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,16 +1164,18 @@ static bool vxlan_remcsum(struct vxlanhdr *unparsed,
11641164
}
11651165

11661166
static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
1167-
struct vxlan_metadata *md,
1168-
struct metadata_dst *tun_dst)
1167+
struct sk_buff *skb, u32 vxflags,
1168+
struct vxlan_metadata *md)
11691169
{
11701170
struct vxlanhdr_gbp *gbp = (struct vxlanhdr_gbp *)unparsed;
1171+
struct metadata_dst *tun_dst;
11711172

11721173
if (!(unparsed->vx_flags & VXLAN_HF_GBP))
11731174
goto out;
11741175

11751176
md->gbp = ntohs(gbp->policy_id);
11761177

1178+
tun_dst = (struct metadata_dst *)skb_dst(skb);
11771179
if (tun_dst)
11781180
tun_dst->u.tun_info.key.tun_flags |= TUNNEL_VXLAN_OPT;
11791181

@@ -1183,102 +1185,79 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
11831185
if (gbp->policy_applied)
11841186
md->gbp |= VXLAN_GBP_POLICY_APPLIED;
11851187

1188+
/* In flow-based mode, GBP is carried in dst_metadata */
1189+
if (!(vxflags & VXLAN_F_COLLECT_METADATA))
1190+
skb->mark = md->gbp;
11861191
out:
11871192
unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS;
11881193
}
11891194

1190-
static void vxlan_rcv(struct vxlan_dev *vxlan, struct vxlan_sock *vs,
1191-
struct sk_buff *skb, struct vxlan_metadata *md,
1192-
struct metadata_dst *tun_dst)
1195+
static bool vxlan_set_mac(struct vxlan_dev *vxlan,
1196+
struct vxlan_sock *vs,
1197+
struct sk_buff *skb)
11931198
{
1194-
struct iphdr *oip = NULL;
1195-
struct ipv6hdr *oip6 = NULL;
1196-
struct pcpu_sw_netstats *stats;
11971199
union vxlan_addr saddr;
1198-
int err = 0;
11991200

12001201
skb_reset_mac_header(skb);
12011202
skb->protocol = eth_type_trans(skb, vxlan->dev);
12021203
skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
12031204

12041205
/* Ignore packet loops (and multicast echo) */
12051206
if (ether_addr_equal(eth_hdr(skb)->h_source, vxlan->dev->dev_addr))
1206-
goto drop;
1207+
return false;
12071208

1208-
/* Get data from the outer IP header */
1209+
/* Get address from the outer IP header */
12091210
if (vxlan_get_sk_family(vs) == AF_INET) {
1210-
oip = ip_hdr(skb);
1211-
saddr.sin.sin_addr.s_addr = oip->saddr;
1211+
saddr.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
12121212
saddr.sa.sa_family = AF_INET;
12131213
#if IS_ENABLED(CONFIG_IPV6)
12141214
} else {
1215-
oip6 = ipv6_hdr(skb);
1216-
saddr.sin6.sin6_addr = oip6->saddr;
1215+
saddr.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
12171216
saddr.sa.sa_family = AF_INET6;
12181217
#endif
12191218
}
12201219

1221-
if (tun_dst) {
1222-
skb_dst_set(skb, (struct dst_entry *)tun_dst);
1223-
tun_dst = NULL;
1224-
}
1225-
12261220
if ((vxlan->flags & VXLAN_F_LEARN) &&
12271221
vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source))
1228-
goto drop;
1229-
1230-
skb_reset_network_header(skb);
1231-
/* In flow-based mode, GBP is carried in dst_metadata */
1232-
if (!(vs->flags & VXLAN_F_COLLECT_METADATA))
1233-
skb->mark = md->gbp;
1234-
1235-
if (oip6)
1236-
err = IP6_ECN_decapsulate(oip6, skb);
1237-
if (oip)
1238-
err = IP_ECN_decapsulate(oip, skb);
1239-
1240-
if (unlikely(err)) {
1241-
if (log_ecn_error) {
1242-
if (oip6)
1243-
net_info_ratelimited("non-ECT from %pI6\n",
1244-
&oip6->saddr);
1245-
if (oip)
1246-
net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
1247-
&oip->saddr, oip->tos);
1248-
}
1249-
if (err > 1) {
1250-
++vxlan->dev->stats.rx_frame_errors;
1251-
++vxlan->dev->stats.rx_errors;
1252-
goto drop;
1253-
}
1254-
}
1222+
return false;
12551223

1256-
stats = this_cpu_ptr(vxlan->dev->tstats);
1257-
u64_stats_update_begin(&stats->syncp);
1258-
stats->rx_packets++;
1259-
stats->rx_bytes += skb->len;
1260-
u64_stats_update_end(&stats->syncp);
1224+
return true;
1225+
}
12611226

1262-
gro_cells_receive(&vxlan->gro_cells, skb);
1227+
static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
1228+
struct sk_buff *skb)
1229+
{
1230+
int err = 0;
12631231

1264-
return;
1265-
drop:
1266-
if (tun_dst)
1267-
dst_release((struct dst_entry *)tun_dst);
1232+
if (vxlan_get_sk_family(vs) == AF_INET)
1233+
err = IP_ECN_decapsulate(oiph, skb);
1234+
#if IS_ENABLED(CONFIG_IPV6)
1235+
else
1236+
err = IP6_ECN_decapsulate(oiph, skb);
1237+
#endif
12681238

1269-
/* Consume bad packet */
1270-
kfree_skb(skb);
1239+
if (unlikely(err) && log_ecn_error) {
1240+
if (vxlan_get_sk_family(vs) == AF_INET)
1241+
net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
1242+
&((struct iphdr *)oiph)->saddr,
1243+
((struct iphdr *)oiph)->tos);
1244+
else
1245+
net_info_ratelimited("non-ECT from %pI6\n",
1246+
&((struct ipv6hdr *)oiph)->saddr);
1247+
}
1248+
return err <= 1;
12711249
}
12721250

12731251
/* Callback from net/ipv4/udp.c to receive packets */
1274-
static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
1252+
static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
12751253
{
1276-
struct metadata_dst *tun_dst = NULL;
1254+
struct pcpu_sw_netstats *stats;
12771255
struct vxlan_dev *vxlan;
12781256
struct vxlan_sock *vs;
12791257
struct vxlanhdr unparsed;
12801258
struct vxlan_metadata _md;
12811259
struct vxlan_metadata *md = &_md;
1260+
void *oiph;
12821261

12831262
/* Need Vxlan and inner Ethernet header to be present */
12841263
if (!pskb_may_pull(skb, VXLAN_HLEN))
@@ -1310,6 +1289,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
13101289

13111290
if (vxlan_collect_metadata(vs)) {
13121291
__be32 vni = vxlan_vni(vxlan_hdr(skb)->vx_vni);
1292+
struct metadata_dst *tun_dst;
13131293

13141294
tun_dst = udp_tun_rx_dst(skb, vxlan_get_sk_family(vs), TUNNEL_KEY,
13151295
vxlan_vni_to_tun_id(vni), sizeof(*md));
@@ -1318,6 +1298,8 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
13181298
goto drop;
13191299

13201300
md = ip_tunnel_info_opts(&tun_dst->u.tun_info);
1301+
1302+
skb_dst_set(skb, (struct dst_entry *)tun_dst);
13211303
} else {
13221304
memset(md, 0, sizeof(*md));
13231305
}
@@ -1329,7 +1311,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
13291311
if (!vxlan_remcsum(&unparsed, skb, vs->flags))
13301312
goto drop;
13311313
if (vs->flags & VXLAN_F_GBP)
1332-
vxlan_parse_gbp_hdr(&unparsed, md, tun_dst);
1314+
vxlan_parse_gbp_hdr(&unparsed, skb, vs->flags, md);
13331315

13341316
if (unparsed.vx_flags || unparsed.vx_vni) {
13351317
/* If there are any unprocessed flags remaining treat
@@ -1343,13 +1325,28 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
13431325
goto drop;
13441326
}
13451327

1346-
vxlan_rcv(vxlan, vs, skb, md, tun_dst);
1328+
if (!vxlan_set_mac(vxlan, vs, skb))
1329+
goto drop;
1330+
1331+
oiph = skb_network_header(skb);
1332+
skb_reset_network_header(skb);
1333+
1334+
if (!vxlan_ecn_decapsulate(vs, oiph, skb)) {
1335+
++vxlan->dev->stats.rx_frame_errors;
1336+
++vxlan->dev->stats.rx_errors;
1337+
goto drop;
1338+
}
1339+
1340+
stats = this_cpu_ptr(vxlan->dev->tstats);
1341+
u64_stats_update_begin(&stats->syncp);
1342+
stats->rx_packets++;
1343+
stats->rx_bytes += skb->len;
1344+
u64_stats_update_end(&stats->syncp);
1345+
1346+
gro_cells_receive(&vxlan->gro_cells, skb);
13471347
return 0;
13481348

13491349
drop:
1350-
if (tun_dst)
1351-
dst_release((struct dst_entry *)tun_dst);
1352-
13531350
/* Consume bad packet */
13541351
kfree_skb(skb);
13551352
return 0;
@@ -2648,7 +2645,7 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
26482645
/* Mark socket as an encapsulation socket. */
26492646
tunnel_cfg.sk_user_data = vs;
26502647
tunnel_cfg.encap_type = 1;
2651-
tunnel_cfg.encap_rcv = vxlan_udp_encap_recv;
2648+
tunnel_cfg.encap_rcv = vxlan_rcv;
26522649
tunnel_cfg.encap_destroy = NULL;
26532650

26542651
setup_udp_tunnel_sock(net, sock, &tunnel_cfg);

0 commit comments

Comments
 (0)