net: sched: fix skb->protocol use in case of accelerated vlan path
authorJiri Pirko <jiri@resnulli.us>
Tue, 13 Jan 2015 16:13:43 +0000 (17:13 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 13 Jan 2015 22:51:08 +0000 (17:51 -0500)
tc code implicitly considers skb->protocol even in case of accelerated
vlan paths and expects vlan protocol type here. However, on rx path,
if the vlan header was already stripped, skb->protocol contains value
of next header. Similar situation is on tx path.

So for skbs that use skb->vlan_tci for tagging, use skb->vlan_proto instead.

Reported-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/pkt_sched.h
net/sched/act_csum.c
net/sched/cls_flow.c
net/sched/em_ipset.c
net/sched/em_meta.c
net/sched/sch_api.c
net/sched/sch_dsmark.c
net/sched/sch_teql.c

index 27a3383..fe6e7aa 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/jiffies.h>
 #include <linux/ktime.h>
+#include <linux/if_vlan.h>
 #include <net/sch_generic.h>
 
 struct qdisc_walker {
@@ -114,6 +115,17 @@ int tc_classify_compat(struct sk_buff *skb, const struct tcf_proto *tp,
 int tc_classify(struct sk_buff *skb, const struct tcf_proto *tp,
                struct tcf_result *res);
 
+static inline __be16 tc_skb_protocol(const struct sk_buff *skb)
+{
+       /* We need to take extra care in case the skb came via
+        * vlan accelerated path. In that case, use skb->vlan_proto
+        * as the original vlan header was already stripped.
+        */
+       if (vlan_tx_tag_present(skb))
+               return skb->vlan_proto;
+       return skb->protocol;
+}
+
 /* Calculate maximal size of packet seen by hard_start_xmit
    routine of this device.
  */
index edbf40d..4cd5cf1 100644 (file)
@@ -509,7 +509,7 @@ static int tcf_csum(struct sk_buff *skb,
        if (unlikely(action == TC_ACT_SHOT))
                goto drop;
 
-       switch (skb->protocol) {
+       switch (tc_skb_protocol(skb)) {
        case cpu_to_be16(ETH_P_IP):
                if (!tcf_csum_ipv4(skb, update_flags))
                        goto drop;
index 15d68f2..4614103 100644 (file)
@@ -77,7 +77,7 @@ static u32 flow_get_dst(const struct sk_buff *skb, const struct flow_keys *flow)
 {
        if (flow->dst)
                return ntohl(flow->dst);
-       return addr_fold(skb_dst(skb)) ^ (__force u16)skb->protocol;
+       return addr_fold(skb_dst(skb)) ^ (__force u16) tc_skb_protocol(skb);
 }
 
 static u32 flow_get_proto(const struct sk_buff *skb, const struct flow_keys *flow)
@@ -98,7 +98,7 @@ static u32 flow_get_proto_dst(const struct sk_buff *skb, const struct flow_keys
        if (flow->ports)
                return ntohs(flow->port16[1]);
 
-       return addr_fold(skb_dst(skb)) ^ (__force u16)skb->protocol;
+       return addr_fold(skb_dst(skb)) ^ (__force u16) tc_skb_protocol(skb);
 }
 
 static u32 flow_get_iif(const struct sk_buff *skb)
@@ -144,7 +144,7 @@ static u32 flow_get_nfct(const struct sk_buff *skb)
 
 static u32 flow_get_nfct_src(const struct sk_buff *skb, const struct flow_keys *flow)
 {
-       switch (skb->protocol) {
+       switch (tc_skb_protocol(skb)) {
        case htons(ETH_P_IP):
                return ntohl(CTTUPLE(skb, src.u3.ip));
        case htons(ETH_P_IPV6):
@@ -156,7 +156,7 @@ fallback:
 
 static u32 flow_get_nfct_dst(const struct sk_buff *skb, const struct flow_keys *flow)
 {
-       switch (skb->protocol) {
+       switch (tc_skb_protocol(skb)) {
        case htons(ETH_P_IP):
                return ntohl(CTTUPLE(skb, dst.u3.ip));
        case htons(ETH_P_IPV6):
index 5b4a4ef..a3d79c8 100644 (file)
@@ -59,7 +59,7 @@ static int em_ipset_match(struct sk_buff *skb, struct tcf_ematch *em,
        struct net_device *dev, *indev = NULL;
        int ret, network_offset;
 
-       switch (skb->protocol) {
+       switch (tc_skb_protocol(skb)) {
        case htons(ETH_P_IP):
                acpar.family = NFPROTO_IPV4;
                if (!pskb_network_may_pull(skb, sizeof(struct iphdr)))
index c8f8c39..2159981 100644 (file)
@@ -197,7 +197,7 @@ META_COLLECTOR(int_priority)
 META_COLLECTOR(int_protocol)
 {
        /* Let userspace take care of the byte ordering */
-       dst->value = skb->protocol;
+       dst->value = tc_skb_protocol(skb);
 }
 
 META_COLLECTOR(int_pkttype)
Simple merge
Simple merge
Simple merge