From: Roman Mashak <mrv@mojatatu.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, kernel@mojatatu.com, jhs@mojatatu.com,
xiyou.wangcong@gmail.com, jiri@resnulli.us,
Roman Mashak <mrv@mojatatu.com>
Subject: [PATCH v2 net-next 3/4] net sched actions: calculate add/delete event message size
Date: Tue, 6 Mar 2018 16:55:23 -0500 [thread overview]
Message-ID: <1520373324-17433-4-git-send-email-mrv@mojatatu.com> (raw)
In-Reply-To: <1520373324-17433-1-git-send-email-mrv@mojatatu.com>
Introduce routines to calculate size of the shared tc netlink attributes
and the full message size including netlink header and tc service header.
Update add/delete action logic to have the size for event messages,
the size is passed to tcf_add_notify() and tcf_del_notify() where the
notification message is being allocated and constructed.
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
---
net/sched/act_api.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 3de0e06..8809e48 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -109,6 +109,41 @@ int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
}
EXPORT_SYMBOL(__tcf_idr_release);
+static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
+{
+ u32 cookie_len = 0;
+
+ if (act->act_cookie)
+ cookie_len = nla_total_size(act->act_cookie->len);
+
+ return nla_total_size(0) /* action number nested */
+ + nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */
+ + cookie_len /* TCA_ACT_COOKIE */
+ + nla_total_size(0) /* TCA_ACT_STATS nested */
+ /* TCA_STATS_BASIC */
+ + nla_total_size_64bit(sizeof(struct gnet_stats_basic))
+ /* TCA_STATS_QUEUE */
+ + nla_total_size_64bit(sizeof(struct gnet_stats_queue))
+ + nla_total_size(0) /* TCA_OPTIONS nested */
+ + nla_total_size(sizeof(struct tcf_t)); /* TCA_GACT_TM */
+}
+
+static size_t tcf_action_full_attrs_size(size_t sz)
+{
+ return NLMSG_HDRLEN /* struct nlmsghdr */
+ + sizeof(struct tcamsg)
+ + nla_total_size(0) /* TCA_ACT_TAB nested */
+ + sz;
+}
+
+static size_t tcf_action_fill_size(const struct tc_action *act)
+{
+ if (act->ops->get_fill_size)
+ return act->ops->get_fill_size(act) +
+ tcf_action_shared_attrs_size(act);
+ return 0;
+}
+
static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
struct netlink_callback *cb)
{
@@ -746,6 +781,7 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
{
struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
struct tc_action *act;
+ size_t sz = 0;
int err;
int i;
@@ -761,11 +797,14 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
goto err;
}
act->order = i;
+ sz += tcf_action_fill_size(act);
if (ovr)
act->tcfa_refcnt++;
list_add_tail(&act->list, actions);
}
+ *attr_size = tcf_action_full_attrs_size(sz);
+
/* Remove the temp refcnt which was necessary to protect against
* destroying an existing action which was being replaced
*/
@@ -1056,9 +1095,12 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
goto err;
}
act->order = i;
+ attr_size += tcf_action_fill_size(act);
list_add_tail(&act->list, &actions);
}
+ attr_size = tcf_action_full_attrs_size(attr_size);
+
if (event == RTM_GETACTION)
ret = tcf_get_notify(net, portid, n, &actions, event, extack);
else { /* delete */
--
2.7.4
next prev parent reply other threads:[~2018-03-06 21:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 21:55 [PATCH v2 net-next 0/4] Fix event generation for actions batch Add/Delete mode Roman Mashak
2018-03-06 21:55 ` [PATCH v2 net-next 1/4] net sched actions: update Add/Delete action API with new argument Roman Mashak
2018-03-06 21:55 ` [PATCH v2 net-next 2/4] net sched actions: add new tc_action_ops callback Roman Mashak
2018-03-06 21:55 ` Roman Mashak [this message]
2018-03-07 19:55 ` [PATCH v2 net-next 3/4] net sched actions: calculate add/delete event message size David Miller
2018-03-07 20:43 ` Roman Mashak
2018-03-06 21:55 ` [PATCH v2 net-next 4/4] net sched actions: implement get_fill_size routine in act_gact Roman Mashak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1520373324-17433-4-git-send-email-mrv@mojatatu.com \
--to=mrv@mojatatu.com \
--cc=davem@davemloft.net \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kernel@mojatatu.com \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).