Skip to content

Commit 2081fd3

Browse files
Asbjørn Sloth Tønnesendavem330
authored andcommitted
net: sched: cls_api: add filter counter
Maintain a count of filters per block. Counter updates are protected by cb_lock, which is also used to protect the offload counters. Signed-off-by: Asbjørn Sloth Tønnesen <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f631ef3 commit 2081fd3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/net/sch_generic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ struct tcf_proto {
422422
*/
423423
spinlock_t lock;
424424
bool deleting;
425+
bool counted;
425426
refcount_t refcnt;
426427
struct rcu_head rcu;
427428
struct hlist_node destroy_ht_node;
@@ -471,6 +472,7 @@ struct tcf_block {
471472
struct flow_block flow_block;
472473
struct list_head owner_list;
473474
bool keep_dst;
475+
atomic_t filtercnt; /* Number of filters */
474476
atomic_t skipswcnt; /* Number of skip_sw filters */
475477
atomic_t offloadcnt; /* Number of oddloaded filters */
476478
unsigned int nooffloaddevcnt; /* Number of devs unable to do offload */

net/sched/cls_api.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,30 @@ static void tcf_proto_get(struct tcf_proto *tp)
410410
refcount_inc(&tp->refcnt);
411411
}
412412

413+
static void tcf_block_filter_cnt_update(struct tcf_block *block, bool *counted, bool add)
414+
{
415+
lockdep_assert_not_held(&block->cb_lock);
416+
417+
down_write(&block->cb_lock);
418+
if (*counted != add) {
419+
if (add) {
420+
atomic_inc(&block->filtercnt);
421+
*counted = true;
422+
} else {
423+
atomic_dec(&block->filtercnt);
424+
*counted = false;
425+
}
426+
}
427+
up_write(&block->cb_lock);
428+
}
429+
413430
static void tcf_chain_put(struct tcf_chain *chain);
414431

415432
static void tcf_proto_destroy(struct tcf_proto *tp, bool rtnl_held,
416433
bool sig_destroy, struct netlink_ext_ack *extack)
417434
{
418435
tp->ops->destroy(tp, rtnl_held, extack);
436+
tcf_block_filter_cnt_update(tp->chain->block, &tp->counted, false);
419437
if (sig_destroy)
420438
tcf_proto_signal_destroyed(tp->chain, tp);
421439
tcf_chain_put(tp->chain);
@@ -2364,6 +2382,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
23642382
err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
23652383
flags, extack);
23662384
if (err == 0) {
2385+
tcf_block_filter_cnt_update(block, &tp->counted, true);
23672386
tfilter_notify(net, skb, n, tp, block, q, parent, fh,
23682387
RTM_NEWTFILTER, false, rtnl_held, extack);
23692388
tfilter_put(tp, fh);

0 commit comments

Comments
 (0)