Skip to content

Commit 7d5509f

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: extend proto ops with 'put' callback
Add optional tp->ops->put() API to be implemented for filter reference counting. This new function is called by cls API to release filter reference for filters returned by tp->ops->change() or tp->ops->get() functions. Implement tfilter_put() helper to call tp->ops->put() only for classifiers that implement it. Signed-off-by: Vlad Buslov <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ec6743a commit 7d5509f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/net/sch_generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ struct tcf_proto_ops {
277277
struct netlink_ext_ack *extack);
278278

279279
void* (*get)(struct tcf_proto*, u32 handle);
280+
void (*put)(struct tcf_proto *tp, void *f);
280281
int (*change)(struct net *net, struct sk_buff *,
281282
struct tcf_proto*, unsigned long,
282283
u32 handle, struct nlattr **,

net/sched/cls_api.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,12 @@ static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
18701870
q, parent, NULL, event, false);
18711871
}
18721872

1873+
static void tfilter_put(struct tcf_proto *tp, void *fh)
1874+
{
1875+
if (tp->ops->put && fh)
1876+
tp->ops->put(tp, fh);
1877+
}
1878+
18731879
static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
18741880
struct netlink_ext_ack *extack)
18751881
{
@@ -2012,6 +2018,7 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
20122018
goto errout;
20132019
}
20142020
} else if (n->nlmsg_flags & NLM_F_EXCL) {
2021+
tfilter_put(tp, fh);
20152022
NL_SET_ERR_MSG(extack, "Filter already exists");
20162023
err = -EEXIST;
20172024
goto errout;
@@ -2026,9 +2033,11 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
20262033
err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
20272034
n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE,
20282035
extack);
2029-
if (err == 0)
2036+
if (err == 0) {
20302037
tfilter_notify(net, skb, n, tp, block, q, parent, fh,
20312038
RTM_NEWTFILTER, false);
2039+
tfilter_put(tp, fh);
2040+
}
20322041

20332042
errout:
20342043
if (err && tp_created)
@@ -2259,6 +2268,7 @@ static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
22592268
NL_SET_ERR_MSG(extack, "Failed to send filter notify message");
22602269
}
22612270

2271+
tfilter_put(tp, fh);
22622272
errout:
22632273
if (chain) {
22642274
if (tp && !IS_ERR(tp))

0 commit comments

Comments
 (0)