aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6
diff options
context:
space:
mode:
authorstephen hemminger <shemminger@vyatta.com>2012-09-25 07:02:48 -0400
committerDavid S. Miller <davem@davemloft.net>2012-09-27 18:12:37 -0400
commiteccc1bb8d4b4cf68d3c9becb083fa94ada7d495c (patch)
treeb0be7efd0c4a4eed26ffd63863dc372d3b1f2ca0 /net/ipv6
parentb0558ef24a792906914fcad277f3befe2420e618 (diff)
tunnel: drop packet if ECN present with not-ECT
Linux tunnels were written before RFC6040 and therefore never implemented the corner case of ECN getting set in the outer header and the inner header not being ready for it. Section 4.2. Default Tunnel Egress Behaviour. o If the inner ECN field is Not-ECT, the decapsulator MUST NOT propagate any other ECN codepoint onwards. This is because the inner Not-ECT marking is set by transports that rely on dropped packets as an indication of congestion and would not understand or respond to any other ECN codepoint [RFC4774]. Specifically: * If the inner ECN field is Not-ECT and the outer ECN field is CE, the decapsulator MUST drop the packet. * If the inner ECN field is Not-ECT and the outer ECN field is Not-ECT, ECT(0), or ECT(1), the decapsulator MUST forward the outgoing packet with the ECN field cleared to Not-ECT. This patch moves the ECN decap logic out of the individual tunnels into a common place. It also adds logging to allow detecting broken systems that set ECN bits incorrectly when tunneling (or an intermediate router might be changing the header). Overloads rx_frame_error to keep track of ECN related error. Thanks to Chris Wright who caught this while reviewing the new VXLAN tunnel. This code was tested by injecting faulty logic in other end GRE to send incorrectly encapsulated packets. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r--net/ipv6/ip6_gre.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index b987d4db790f..613a16647741 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -56,6 +56,10 @@
56#include <net/ip6_tunnel.h> 56#include <net/ip6_tunnel.h>
57 57
58 58
59static bool log_ecn_error = true;
60module_param(log_ecn_error, bool, 0644);
61MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
62
59#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK) 63#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
60#define IPV6_TCLASS_SHIFT 20 64#define IPV6_TCLASS_SHIFT 20
61 65
@@ -149,7 +153,9 @@ static struct rtnl_link_stats64 *ip6gre_get_stats64(struct net_device *dev,
149 tot->rx_crc_errors = dev->stats.rx_crc_errors; 153 tot->rx_crc_errors = dev->stats.rx_crc_errors;
150 tot->rx_fifo_errors = dev->stats.rx_fifo_errors; 154 tot->rx_fifo_errors = dev->stats.rx_fifo_errors;
151 tot->rx_length_errors = dev->stats.rx_length_errors; 155 tot->rx_length_errors = dev->stats.rx_length_errors;
156 tot->rx_frame_errors = dev->stats.rx_frame_errors;
152 tot->rx_errors = dev->stats.rx_errors; 157 tot->rx_errors = dev->stats.rx_errors;
158
153 tot->tx_fifo_errors = dev->stats.tx_fifo_errors; 159 tot->tx_fifo_errors = dev->stats.tx_fifo_errors;
154 tot->tx_carrier_errors = dev->stats.tx_carrier_errors; 160 tot->tx_carrier_errors = dev->stats.tx_carrier_errors;
155 tot->tx_dropped = dev->stats.tx_dropped; 161 tot->tx_dropped = dev->stats.tx_dropped;
@@ -489,28 +495,6 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
489 t->err_time = jiffies; 495 t->err_time = jiffies;
490} 496}
491 497
492static inline void ip6gre_ecn_decapsulate_ipv4(const struct ip6_tnl *t,
493 const struct ipv6hdr *ipv6h, struct sk_buff *skb)
494{
495 __u8 dsfield = ipv6_get_dsfield(ipv6h) & ~INET_ECN_MASK;
496
497 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
498 ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, dsfield);
499
500 if (INET_ECN_is_ce(dsfield))
501 IP_ECN_set_ce(ip_hdr(skb));
502}
503
504static inline void ip6gre_ecn_decapsulate_ipv6(const struct ip6_tnl *t,
505 const struct ipv6hdr *ipv6h, struct sk_buff *skb)
506{
507 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
508 ipv6_copy_dscp(ipv6_get_dsfield(ipv6h), ipv6_hdr(skb));
509
510 if (INET_ECN_is_ce(ipv6_get_dsfield(ipv6h)))
511 IP6_ECN_set_ce(ipv6_hdr(skb));
512}
513
514static int ip6gre_rcv(struct sk_buff *skb) 498static int ip6gre_rcv(struct sk_buff *skb)
515{ 499{
516 const struct ipv6hdr *ipv6h; 500 const struct ipv6hdr *ipv6h;
@@ -522,6 +506,7 @@ static int ip6gre_rcv(struct sk_buff *skb)
522 struct ip6_tnl *tunnel; 506 struct ip6_tnl *tunnel;
523 int offset = 4; 507 int offset = 4;
524 __be16 gre_proto; 508 __be16 gre_proto;
509 int err;
525 510
526 if (!pskb_may_pull(skb, sizeof(struct in6_addr))) 511 if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
527 goto drop; 512 goto drop;
@@ -625,20 +610,29 @@ static int ip6gre_rcv(struct sk_buff *skb)
625 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN); 610 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
626 } 611 }
627 612
613 __skb_tunnel_rx(skb, tunnel->dev);
614
615 skb_reset_network_header(skb);
616
617 err = IP6_ECN_decapsulate(ipv6h, skb);
618 if (unlikely(err)) {
619 if (log_ecn_error)
620 net_info_ratelimited("non-ECT from %pI6 with dsfield=%#x\n",
621 &ipv6h->saddr,
622 ipv6_get_dsfield(ipv6h));
623 if (err > 1) {
624 ++tunnel->dev->stats.rx_frame_errors;
625 ++tunnel->dev->stats.rx_errors;
626 goto drop;
627 }
628 }
629
628 tstats = this_cpu_ptr(tunnel->dev->tstats); 630 tstats = this_cpu_ptr(tunnel->dev->tstats);
629 u64_stats_update_begin(&tstats->syncp); 631 u64_stats_update_begin(&tstats->syncp);
630 tstats->rx_packets++; 632 tstats->rx_packets++;
631 tstats->rx_bytes += skb->len; 633 tstats->rx_bytes += skb->len;
632 u64_stats_update_end(&tstats->syncp); 634 u64_stats_update_end(&tstats->syncp);
633 635
634 __skb_tunnel_rx(skb, tunnel->dev);
635
636 skb_reset_network_header(skb);
637 if (skb->protocol == htons(ETH_P_IP))
638 ip6gre_ecn_decapsulate_ipv4(tunnel, ipv6h, skb);
639 else if (skb->protocol == htons(ETH_P_IPV6))
640 ip6gre_ecn_decapsulate_ipv6(tunnel, ipv6h, skb);
641
642 netif_rx(skb); 636 netif_rx(skb);
643 637
644 return 0; 638 return 0;