Skip to content

Commit 760c680

Browse files
Jiri Bencdavem330
authored andcommitted
vxlan: move ECN decapsulation to a separate function
It simplifies the vxlan_rcv function. Signed-off-by: Jiri Benc <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1ab016e commit 760c680

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

drivers/net/vxlan.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,
12051205
if (ether_addr_equal(eth_hdr(skb)->h_source, vxlan->dev->dev_addr))
12061206
return false;
12071207

1208-
/* Get data from the outer IP header */
1208+
/* Get address from the outer IP header */
12091209
if (vxlan_get_sk_family(vs) == AF_INET) {
12101210
saddr.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
12111211
saddr.sa.sa_family = AF_INET;
@@ -1223,52 +1223,52 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,
12231223
return true;
12241224
}
12251225

1226+
static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
1227+
struct sk_buff *skb)
1228+
{
1229+
int err = 0;
1230+
1231+
if (vxlan_get_sk_family(vs) == AF_INET)
1232+
err = IP_ECN_decapsulate(oiph, skb);
1233+
#if IS_ENABLED(CONFIG_IPV6)
1234+
else
1235+
err = IP6_ECN_decapsulate(oiph, skb);
1236+
#endif
1237+
1238+
if (unlikely(err) && log_ecn_error) {
1239+
if (vxlan_get_sk_family(vs) == AF_INET)
1240+
net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
1241+
&((struct iphdr *)oiph)->saddr,
1242+
((struct iphdr *)oiph)->tos);
1243+
else
1244+
net_info_ratelimited("non-ECT from %pI6\n",
1245+
&((struct ipv6hdr *)oiph)->saddr);
1246+
}
1247+
return err <= 1;
1248+
}
1249+
12261250
static void vxlan_rcv(struct vxlan_dev *vxlan, struct vxlan_sock *vs,
12271251
struct sk_buff *skb, struct vxlan_metadata *md,
12281252
struct metadata_dst *tun_dst)
12291253
{
1230-
struct iphdr *oip = NULL;
1231-
struct ipv6hdr *oip6 = NULL;
12321254
struct pcpu_sw_netstats *stats;
1233-
int err = 0;
1255+
void *oiph;
12341256

12351257
if (!vxlan_set_mac(vxlan, vs, skb))
12361258
goto drop;
12371259

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-
12461260
if (tun_dst) {
12471261
skb_dst_set(skb, (struct dst_entry *)tun_dst);
12481262
tun_dst = NULL;
12491263
}
12501264

1265+
oiph = skb_network_header(skb);
12511266
skb_reset_network_header(skb);
12521267

1253-
if (oip6)
1254-
err = IP6_ECN_decapsulate(oip6, skb);
1255-
if (oip)
1256-
err = IP_ECN_decapsulate(oip, skb);
1257-
1258-
if (unlikely(err)) {
1259-
if (log_ecn_error) {
1260-
if (oip6)
1261-
net_info_ratelimited("non-ECT from %pI6\n",
1262-
&oip6->saddr);
1263-
if (oip)
1264-
net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
1265-
&oip->saddr, oip->tos);
1266-
}
1267-
if (err > 1) {
1268-
++vxlan->dev->stats.rx_frame_errors;
1269-
++vxlan->dev->stats.rx_errors;
1270-
goto drop;
1271-
}
1268+
if (!vxlan_ecn_decapsulate(vs, oiph, skb)) {
1269+
++vxlan->dev->stats.rx_frame_errors;
1270+
++vxlan->dev->stats.rx_errors;
1271+
goto drop;
12721272
}
12731273

12741274
stats = this_cpu_ptr(vxlan->dev->tstats);

0 commit comments

Comments
 (0)