Skip to content

Commit a3308d8

Browse files
Paul Blakeydavem330
authored andcommitted
net/sched: cls_flower: Disallow duplicate internal elements
Flower currently allows having the same filter twice with the same priority. Actions (and statistics update) will always execute on the first inserted rule leaving the second rule unused. This patch disallows that. Signed-off-by: Paul Blakey <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a50a05f commit a3308d8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

net/sched/cls_flower.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ static void fl_clear_masked_range(struct fl_flow_key *key,
134134
memset(fl_key_get_start(key, mask), 0, fl_mask_range(mask));
135135
}
136136

137+
static struct cls_fl_filter *fl_lookup(struct cls_fl_head *head,
138+
struct fl_flow_key *mkey)
139+
{
140+
return rhashtable_lookup_fast(&head->ht,
141+
fl_key_get_start(mkey, &head->mask),
142+
head->ht_params);
143+
}
144+
137145
static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp,
138146
struct tcf_result *res)
139147
{
@@ -181,9 +189,7 @@ static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp,
181189

182190
fl_set_masked_key(&skb_mkey, &skb_key, &head->mask);
183191

184-
f = rhashtable_lookup_fast(&head->ht,
185-
fl_key_get_start(&skb_mkey, &head->mask),
186-
head->ht_params);
192+
f = fl_lookup(head, &skb_mkey);
187193
if (f && !tc_skip_sw(f->flags)) {
188194
*res = f->res;
189195
return tcf_exts_exec(skb, &f->exts, res);
@@ -875,6 +881,11 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
875881
goto errout;
876882

877883
if (!tc_skip_sw(fnew->flags)) {
884+
if (!fold && fl_lookup(head, &fnew->mkey)) {
885+
err = -EEXIST;
886+
goto errout;
887+
}
888+
878889
err = rhashtable_insert_fast(&head->ht, &fnew->ht_node,
879890
head->ht_params);
880891
if (err)

0 commit comments

Comments
 (0)