]> Pileus Git - ~andy/linux/blobdiff - net/sched/cls_flow.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[~andy/linux] / net / sched / cls_flow.c
index f73542d2cdd0640d3f6ef7900cc44987e1be3544..5b271a18bc3a54199510d8d7c6b8f2844afefcf9 100644 (file)
@@ -65,109 +65,134 @@ static inline u32 addr_fold(void *addr)
        return (a & 0xFFFFFFFF) ^ (BITS_PER_LONG > 32 ? a >> 32 : 0);
 }
 
-static u32 flow_get_src(const struct sk_buff *skb)
+static u32 flow_get_src(struct sk_buff *skb)
 {
        switch (skb->protocol) {
        case htons(ETH_P_IP):
-               return ntohl(ip_hdr(skb)->saddr);
+               if (pskb_network_may_pull(skb, sizeof(struct iphdr)))
+                       return ntohl(ip_hdr(skb)->saddr);
+               break;
        case htons(ETH_P_IPV6):
-               return ntohl(ipv6_hdr(skb)->saddr.s6_addr32[3]);
-       default:
-               return addr_fold(skb->sk);
+               if (pskb_network_may_pull(skb, sizeof(struct ipv6hdr)))
+                       return ntohl(ipv6_hdr(skb)->saddr.s6_addr32[3]);
+               break;
        }
+
+       return addr_fold(skb->sk);
 }
 
-static u32 flow_get_dst(const struct sk_buff *skb)
+static u32 flow_get_dst(struct sk_buff *skb)
 {
        switch (skb->protocol) {
        case htons(ETH_P_IP):
-               return ntohl(ip_hdr(skb)->daddr);
+               if (pskb_network_may_pull(skb, sizeof(struct iphdr)))
+                       return ntohl(ip_hdr(skb)->daddr);
+               break;
        case htons(ETH_P_IPV6):
-               return ntohl(ipv6_hdr(skb)->daddr.s6_addr32[3]);
-       default:
-               return addr_fold(skb_dst(skb)) ^ (__force u16)skb->protocol;
+               if (pskb_network_may_pull(skb, sizeof(struct ipv6hdr)))
+                       return ntohl(ipv6_hdr(skb)->daddr.s6_addr32[3]);
+               break;
        }
+
+       return addr_fold(skb_dst(skb)) ^ (__force u16)skb->protocol;
 }
 
-static u32 flow_get_proto(const struct sk_buff *skb)
+static u32 flow_get_proto(struct sk_buff *skb)
 {
        switch (skb->protocol) {
        case htons(ETH_P_IP):
-               return ip_hdr(skb)->protocol;
+               return pskb_network_may_pull(skb, sizeof(struct iphdr)) ?
+                      ip_hdr(skb)->protocol : 0;
        case htons(ETH_P_IPV6):
-               return ipv6_hdr(skb)->nexthdr;
+               return pskb_network_may_pull(skb, sizeof(struct ipv6hdr)) ?
+                      ipv6_hdr(skb)->nexthdr : 0;
        default:
                return 0;
        }
 }
 
-static int has_ports(u8 protocol)
+static u32 flow_get_proto_src(struct sk_buff *skb)
 {
-       switch (protocol) {
-       case IPPROTO_TCP:
-       case IPPROTO_UDP:
-       case IPPROTO_UDPLITE:
-       case IPPROTO_SCTP:
-       case IPPROTO_DCCP:
-       case IPPROTO_ESP:
-               return 1;
-       default:
-               return 0;
-       }
-}
-
-static u32 flow_get_proto_src(const struct sk_buff *skb)
-{
-       u32 res = 0;
-
        switch (skb->protocol) {
        case htons(ETH_P_IP): {
-               struct iphdr *iph = ip_hdr(skb);
+               struct iphdr *iph;
+               int poff;
 
-               if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
-                   has_ports(iph->protocol))
-                       res = ntohs(*(__be16 *)((void *)iph + iph->ihl * 4));
+               if (!pskb_network_may_pull(skb, sizeof(*iph)))
+                       break;
+               iph = ip_hdr(skb);
+               if (iph->frag_off & htons(IP_MF|IP_OFFSET))
+                       break;
+               poff = proto_ports_offset(iph->protocol);
+               if (poff >= 0 &&
+                   pskb_network_may_pull(skb, iph->ihl * 4 + 2 + poff)) {
+                       iph = ip_hdr(skb);
+                       return ntohs(*(__be16 *)((void *)iph + iph->ihl * 4 +
+                                                poff));
+               }
                break;
        }
        case htons(ETH_P_IPV6): {
-               struct ipv6hdr *iph = ipv6_hdr(skb);
+               struct ipv6hdr *iph;
+               int poff;
 
-               if (has_ports(iph->nexthdr))
-                       res = ntohs(*(__be16 *)&iph[1]);
+               if (!pskb_network_may_pull(skb, sizeof(*iph)))
+                       break;
+               iph = ipv6_hdr(skb);
+               poff = proto_ports_offset(iph->nexthdr);
+               if (poff >= 0 &&
+                   pskb_network_may_pull(skb, sizeof(*iph) + poff + 2)) {
+                       iph = ipv6_hdr(skb);
+                       return ntohs(*(__be16 *)((void *)iph + sizeof(*iph) +
+                                                poff));
+               }
                break;
        }
-       default:
-               res = addr_fold(skb->sk);
        }
 
-       return res;
+       return addr_fold(skb->sk);
 }
 
-static u32 flow_get_proto_dst(const struct sk_buff *skb)
+static u32 flow_get_proto_dst(struct sk_buff *skb)
 {
-       u32 res = 0;
-
        switch (skb->protocol) {
        case htons(ETH_P_IP): {
-               struct iphdr *iph = ip_hdr(skb);
+               struct iphdr *iph;
+               int poff;
 
-               if (!(iph->frag_off&htons(IP_MF|IP_OFFSET)) &&
-                   has_ports(iph->protocol))
-                       res = ntohs(*(__be16 *)((void *)iph + iph->ihl * 4 + 2));
+               if (!pskb_network_may_pull(skb, sizeof(*iph)))
+                       break;
+               iph = ip_hdr(skb);
+               if (iph->frag_off & htons(IP_MF|IP_OFFSET))
+                       break;
+               poff = proto_ports_offset(iph->protocol);
+               if (poff >= 0 &&
+                   pskb_network_may_pull(skb, iph->ihl * 4 + 4 + poff)) {
+                       iph = ip_hdr(skb);
+                       return ntohs(*(__be16 *)((void *)iph + iph->ihl * 4 +
+                                                2 + poff));
+               }
                break;
        }
        case htons(ETH_P_IPV6): {
-               struct ipv6hdr *iph = ipv6_hdr(skb);
+               struct ipv6hdr *iph;
+               int poff;
 
-               if (has_ports(iph->nexthdr))
-                       res = ntohs(*(__be16 *)((void *)&iph[1] + 2));
+               if (!pskb_network_may_pull(skb, sizeof(*iph)))
+                       break;
+               iph = ipv6_hdr(skb);
+               poff = proto_ports_offset(iph->nexthdr);
+               if (poff >= 0 &&
+                   pskb_network_may_pull(skb, sizeof(*iph) + poff + 4)) {
+                       iph = ipv6_hdr(skb);
+                       return ntohs(*(__be16 *)((void *)iph + sizeof(*iph) +
+                                                poff + 2));
+               }
                break;
        }
-       default:
-               res = addr_fold(skb_dst(skb)) ^ (__force u16)skb->protocol;
        }
 
-       return res;
+       return addr_fold(skb_dst(skb)) ^ (__force u16)skb->protocol;
 }
 
 static u32 flow_get_iif(const struct sk_buff *skb)
@@ -211,7 +236,7 @@ static u32 flow_get_nfct(const struct sk_buff *skb)
 })
 #endif
 
-static u32 flow_get_nfct_src(const struct sk_buff *skb)
+static u32 flow_get_nfct_src(struct sk_buff *skb)
 {
        switch (skb->protocol) {
        case htons(ETH_P_IP):
@@ -223,7 +248,7 @@ fallback:
        return flow_get_src(skb);
 }
 
-static u32 flow_get_nfct_dst(const struct sk_buff *skb)
+static u32 flow_get_nfct_dst(struct sk_buff *skb)
 {
        switch (skb->protocol) {
        case htons(ETH_P_IP):
@@ -235,14 +260,14 @@ fallback:
        return flow_get_dst(skb);
 }
 
-static u32 flow_get_nfct_proto_src(const struct sk_buff *skb)
+static u32 flow_get_nfct_proto_src(struct sk_buff *skb)
 {
        return ntohs(CTTUPLE(skb, src.u.all));
 fallback:
        return flow_get_proto_src(skb);
 }
 
-static u32 flow_get_nfct_proto_dst(const struct sk_buff *skb)
+static u32 flow_get_nfct_proto_dst(struct sk_buff *skb)
 {
        return ntohs(CTTUPLE(skb, dst.u.all));
 fallback:
@@ -281,7 +306,12 @@ static u32 flow_get_vlan_tag(const struct sk_buff *skb)
        return tag & VLAN_VID_MASK;
 }
 
-static u32 flow_key_get(const struct sk_buff *skb, int key)
+static u32 flow_get_rxhash(struct sk_buff *skb)
+{
+       return skb_get_rxhash(skb);
+}
+
+static u32 flow_key_get(struct sk_buff *skb, int key)
 {
        switch (key) {
        case FLOW_KEY_SRC:
@@ -318,6 +348,8 @@ static u32 flow_key_get(const struct sk_buff *skb, int key)
                return flow_get_skgid(skb);
        case FLOW_KEY_VLAN_TAG:
                return flow_get_vlan_tag(skb);
+       case FLOW_KEY_RXHASH:
+               return flow_get_rxhash(skb);
        default:
                WARN_ON(1);
                return 0;