Skip to content

Commit a7df487

Browse files
congwangdavem330
authored andcommitted
net_sched: fix tcm_parent in tc filter dump
When we tell kernel to dump filters from root (ffff:ffff), those filters on ingress (ffff:0000) are matched, but their true parents must be dumped as they are. However, kernel dumps just whatever we tell it, that is either ffff:ffff or ffff:0000: $ nl-cls-list --dev=dummy0 --parent=root cls basic dev dummy0 id none parent root prio 49152 protocol ip match-all cls basic dev dummy0 id :1 parent root prio 49152 protocol ip match-all $ nl-cls-list --dev=dummy0 --parent=ffff: cls basic dev dummy0 id none parent ffff: prio 49152 protocol ip match-all cls basic dev dummy0 id :1 parent ffff: prio 49152 protocol ip match-all This is confusing and misleading, more importantly this is a regression since 4.15, so the old behavior must be restored. And, when tc filters are installed on a tc class, the parent should be the classid, rather than the qdisc handle. Commit edf6711 ("net: sched: remove classid and q fields from tcf_proto") removed the classid we save for filters, we can just restore this classid in tcf_block. Steps to reproduce this: ip li set dev dummy0 up tc qd add dev dummy0 ingress tc filter add dev dummy0 parent ffff: protocol arp basic action pass tc filter show dev dummy0 root Before this patch: filter protocol arp pref 49152 basic filter protocol arp pref 49152 basic handle 0x1 action order 1: gact action pass random type none pass val 0 index 1 ref 1 bind 1 After this patch: filter parent ffff: protocol arp pref 49152 basic filter parent ffff: protocol arp pref 49152 basic handle 0x1 action order 1: gact action pass random type none pass val 0 index 1 ref 1 bind 1 Fixes: a10fa20 ("net: sched: propagate q and parent from caller down to tcf_fill_node") Fixes: edf6711 ("net: sched: remove classid and q fields from tcf_proto") Cc: Jamal Hadi Salim <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 071a43e commit a7df487

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

include/net/sch_generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ struct tcf_block {
407407
struct mutex lock;
408408
struct list_head chain_list;
409409
u32 index; /* block index for shared blocks */
410+
u32 classid; /* which class this block belongs to */
410411
refcount_t refcnt;
411412
struct net *net;
412413
struct Qdisc *q;

net/sched/cls_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
20702070
err = PTR_ERR(block);
20712071
goto errout;
20722072
}
2073+
block->classid = parent;
20732074

20742075
chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
20752076
if (chain_index > TC_ACT_EXT_VAL_MASK) {
@@ -2612,12 +2613,10 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
26122613
return skb->len;
26132614

26142615
parent = tcm->tcm_parent;
2615-
if (!parent) {
2616+
if (!parent)
26162617
q = dev->qdisc;
2617-
parent = q->handle;
2618-
} else {
2618+
else
26192619
q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
2620-
}
26212620
if (!q)
26222621
goto out;
26232622
cops = q->ops->cl_ops;
@@ -2633,6 +2632,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
26332632
block = cops->tcf_block(q, cl, NULL);
26342633
if (!block)
26352634
goto out;
2635+
parent = block->classid;
26362636
if (tcf_block_shared(block))
26372637
q = NULL;
26382638
}

0 commit comments

Comments
 (0)