Skip to content

Commit 11fca93

Browse files
Eric Dumazetdavem330
authored andcommitted
sch_sfq: use skb_flow_dissect()
Instead of using a custom flow dissector, use skb_flow_dissect() and benefit from tunnelling support. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f07d960 commit 11fca93

1 file changed

Lines changed: 10 additions & 55 deletions

File tree

‎net/sched/sch_sfq.c‎

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
#include <linux/in.h>
1818
#include <linux/errno.h>
1919
#include <linux/init.h>
20-
#include <linux/ipv6.h>
2120
#include <linux/skbuff.h>
2221
#include <linux/jhash.h>
2322
#include <linux/slab.h>
2423
#include <linux/vmalloc.h>
25-
#include <net/ip.h>
2624
#include <net/netlink.h>
2725
#include <net/pkt_sched.h>
26+
#include <net/flow_keys.h>
2827

2928

3029
/* Stochastic Fairness Queuing algorithm.
@@ -137,61 +136,17 @@ static inline struct sfq_head *sfq_dep_head(struct sfq_sched_data *q, sfq_index
137136
return &q->dep[val - SFQ_SLOTS];
138137
}
139138

140-
static unsigned int sfq_fold_hash(struct sfq_sched_data *q, u32 h, u32 h1)
139+
static unsigned int sfq_hash(const struct sfq_sched_data *q,
140+
const struct sk_buff *skb)
141141
{
142-
return jhash_2words(h, h1, q->perturbation) & (q->divisor - 1);
143-
}
144-
145-
static unsigned int sfq_hash(struct sfq_sched_data *q, struct sk_buff *skb)
146-
{
147-
u32 h, h2;
148-
149-
switch (skb->protocol) {
150-
case htons(ETH_P_IP):
151-
{
152-
const struct iphdr *iph;
153-
int poff;
154-
155-
if (!pskb_network_may_pull(skb, sizeof(*iph)))
156-
goto err;
157-
iph = ip_hdr(skb);
158-
h = (__force u32)iph->daddr;
159-
h2 = (__force u32)iph->saddr ^ iph->protocol;
160-
if (ip_is_fragment(iph))
161-
break;
162-
poff = proto_ports_offset(iph->protocol);
163-
if (poff >= 0 &&
164-
pskb_network_may_pull(skb, iph->ihl * 4 + 4 + poff)) {
165-
iph = ip_hdr(skb);
166-
h2 ^= *(u32 *)((void *)iph + iph->ihl * 4 + poff);
167-
}
168-
break;
169-
}
170-
case htons(ETH_P_IPV6):
171-
{
172-
const struct ipv6hdr *iph;
173-
int poff;
174-
175-
if (!pskb_network_may_pull(skb, sizeof(*iph)))
176-
goto err;
177-
iph = ipv6_hdr(skb);
178-
h = (__force u32)iph->daddr.s6_addr32[3];
179-
h2 = (__force u32)iph->saddr.s6_addr32[3] ^ iph->nexthdr;
180-
poff = proto_ports_offset(iph->nexthdr);
181-
if (poff >= 0 &&
182-
pskb_network_may_pull(skb, sizeof(*iph) + 4 + poff)) {
183-
iph = ipv6_hdr(skb);
184-
h2 ^= *(u32 *)((void *)iph + sizeof(*iph) + poff);
185-
}
186-
break;
187-
}
188-
default:
189-
err:
190-
h = (unsigned long)skb_dst(skb) ^ (__force u32)skb->protocol;
191-
h2 = (unsigned long)skb->sk;
192-
}
142+
struct flow_keys keys;
143+
unsigned int hash;
193144

194-
return sfq_fold_hash(q, h, h2);
145+
skb_flow_dissect(skb, &keys);
146+
hash = jhash_3words((__force u32)keys.dst,
147+
(__force u32)keys.src ^ keys.ip_proto,
148+
(__force u32)keys.ports, q->perturbation);
149+
return hash & (q->divisor - 1);
195150
}
196151

197152
static unsigned int sfq_classify(struct sk_buff *skb, struct Qdisc *sch,

0 commit comments

Comments
 (0)