Skip to content

Commit 0623951

Browse files
committed
Merge branch 'sched-action-events'
Roman Mashak says: ==================== Fix event generation for actions batch Add/Delete mode When adding or deleting a batch of entries, the kernel sends upto TCA_ACT_MAX_PRIO entries in an event to user space. However it does not consider that the action sizes may vary and require different skb sizes. For example : % cat tc-batch.sh TC="sudo /mnt/iproute2.git/tc/tc" $TC actions flush action gact for i in `seq 1 $1`; do cmd="action pass index $i " args=$args$cmd done $TC actions add $args % % ./tc-batch.sh 32 Error: Failed to fill netlink attributes while adding TC action. We have an error talking to the kernel % This patchset introduces new callback in tc_action_ops, which calculates the action size, and passes size to tcf_add_notify()/tcf_del_notify(). The patch fixes act_gact, and the rest of actions will be updated in the follow-up patches. v3: Fixed tcf_action_fill_size() to return shared attrs length when action ->get_fill_size() isn't implemented. v2: Restructured patches to make them bisectable. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 79134e6 + 9c5c9c5 commit 0623951

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

include/net/act_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct tc_action_ops {
9797
const struct tc_action_ops *,
9898
struct netlink_ext_ack *);
9999
void (*stats_update)(struct tc_action *, u64, u32, u64);
100+
size_t (*get_fill_size)(const struct tc_action *act);
100101
struct net_device *(*get_dev)(const struct tc_action *a);
101102
};
102103

@@ -166,7 +167,8 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
166167
int nr_actions, struct tcf_result *res);
167168
int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
168169
struct nlattr *est, char *name, int ovr, int bind,
169-
struct list_head *actions, struct netlink_ext_ack *extack);
170+
struct list_head *actions, size_t *attr_size,
171+
struct netlink_ext_ack *extack);
170172
struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
171173
struct nlattr *nla, struct nlattr *est,
172174
char *name, int ovr, int bind,

net/sched/act_api.c

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,42 @@ int __tcf_idr_release(struct tc_action *p, bool bind, bool strict)
109109
}
110110
EXPORT_SYMBOL(__tcf_idr_release);
111111

112+
static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
113+
{
114+
u32 cookie_len = 0;
115+
116+
if (act->act_cookie)
117+
cookie_len = nla_total_size(act->act_cookie->len);
118+
119+
return nla_total_size(0) /* action number nested */
120+
+ nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */
121+
+ cookie_len /* TCA_ACT_COOKIE */
122+
+ nla_total_size(0) /* TCA_ACT_STATS nested */
123+
/* TCA_STATS_BASIC */
124+
+ nla_total_size_64bit(sizeof(struct gnet_stats_basic))
125+
/* TCA_STATS_QUEUE */
126+
+ nla_total_size_64bit(sizeof(struct gnet_stats_queue))
127+
+ nla_total_size(0) /* TCA_OPTIONS nested */
128+
+ nla_total_size(sizeof(struct tcf_t)); /* TCA_GACT_TM */
129+
}
130+
131+
static size_t tcf_action_full_attrs_size(size_t sz)
132+
{
133+
return NLMSG_HDRLEN /* struct nlmsghdr */
134+
+ sizeof(struct tcamsg)
135+
+ nla_total_size(0) /* TCA_ACT_TAB nested */
136+
+ sz;
137+
}
138+
139+
static size_t tcf_action_fill_size(const struct tc_action *act)
140+
{
141+
size_t sz = tcf_action_shared_attrs_size(act);
142+
143+
if (act->ops->get_fill_size)
144+
return act->ops->get_fill_size(act) + sz;
145+
return sz;
146+
}
147+
112148
static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
113149
struct netlink_callback *cb)
114150
{
@@ -741,10 +777,12 @@ static void cleanup_a(struct list_head *actions, int ovr)
741777

742778
int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
743779
struct nlattr *est, char *name, int ovr, int bind,
744-
struct list_head *actions, struct netlink_ext_ack *extack)
780+
struct list_head *actions, size_t *attr_size,
781+
struct netlink_ext_ack *extack)
745782
{
746783
struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
747784
struct tc_action *act;
785+
size_t sz = 0;
748786
int err;
749787
int i;
750788

@@ -760,11 +798,14 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
760798
goto err;
761799
}
762800
act->order = i;
801+
sz += tcf_action_fill_size(act);
763802
if (ovr)
764803
act->tcfa_refcnt++;
765804
list_add_tail(&act->list, actions);
766805
}
767806

807+
*attr_size = tcf_action_full_attrs_size(sz);
808+
768809
/* Remove the temp refcnt which was necessary to protect against
769810
* destroying an existing action which was being replaced
770811
*/
@@ -994,12 +1035,13 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
9941035

9951036
static int
9961037
tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
997-
u32 portid, struct netlink_ext_ack *extack)
1038+
u32 portid, size_t attr_size, struct netlink_ext_ack *extack)
9981039
{
9991040
int ret;
10001041
struct sk_buff *skb;
10011042

1002-
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1043+
skb = alloc_skb(attr_size <= NLMSG_GOODSIZE ? NLMSG_GOODSIZE : attr_size,
1044+
GFP_KERNEL);
10031045
if (!skb)
10041046
return -ENOBUFS;
10051047

@@ -1032,6 +1074,7 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
10321074
int i, ret;
10331075
struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
10341076
struct tc_action *act;
1077+
size_t attr_size = 0;
10351078
LIST_HEAD(actions);
10361079

10371080
ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack);
@@ -1053,13 +1096,16 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
10531096
goto err;
10541097
}
10551098
act->order = i;
1099+
attr_size += tcf_action_fill_size(act);
10561100
list_add_tail(&act->list, &actions);
10571101
}
10581102

1103+
attr_size = tcf_action_full_attrs_size(attr_size);
1104+
10591105
if (event == RTM_GETACTION)
10601106
ret = tcf_get_notify(net, portid, n, &actions, event, extack);
10611107
else { /* delete */
1062-
ret = tcf_del_notify(net, n, &actions, portid, extack);
1108+
ret = tcf_del_notify(net, n, &actions, portid, attr_size, extack);
10631109
if (ret)
10641110
goto err;
10651111
return ret;
@@ -1072,12 +1118,13 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
10721118

10731119
static int
10741120
tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
1075-
u32 portid, struct netlink_ext_ack *extack)
1121+
u32 portid, size_t attr_size, struct netlink_ext_ack *extack)
10761122
{
10771123
struct sk_buff *skb;
10781124
int err = 0;
10791125

1080-
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1126+
skb = alloc_skb(attr_size <= NLMSG_GOODSIZE ? NLMSG_GOODSIZE : attr_size,
1127+
GFP_KERNEL);
10811128
if (!skb)
10821129
return -ENOBUFS;
10831130

@@ -1099,15 +1146,16 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
10991146
struct nlmsghdr *n, u32 portid, int ovr,
11001147
struct netlink_ext_ack *extack)
11011148
{
1149+
size_t attr_size = 0;
11021150
int ret = 0;
11031151
LIST_HEAD(actions);
11041152

11051153
ret = tcf_action_init(net, NULL, nla, NULL, NULL, ovr, 0, &actions,
1106-
extack);
1154+
&attr_size, extack);
11071155
if (ret)
11081156
return ret;
11091157

1110-
return tcf_add_notify(net, n, &actions, portid, extack);
1158+
return tcf_add_notify(net, n, &actions, portid, attr_size, extack);
11111159
}
11121160

11131161
static u32 tcaa_root_flags_allowed = TCA_FLAG_LARGE_DUMP_ON;

net/sched/act_gact.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,19 @@ static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index,
217217
return tcf_idr_search(tn, a, index);
218218
}
219219

220+
static size_t tcf_gact_get_fill_size(const struct tc_action *act)
221+
{
222+
size_t sz = nla_total_size(sizeof(struct tc_gact)); /* TCA_GACT_PARMS */
223+
224+
#ifdef CONFIG_GACT_PROB
225+
if (to_gact(act)->tcfg_ptype)
226+
/* TCA_GACT_PROB */
227+
sz += nla_total_size(sizeof(struct tc_gact_p));
228+
#endif
229+
230+
return sz;
231+
}
232+
220233
static struct tc_action_ops act_gact_ops = {
221234
.kind = "gact",
222235
.type = TCA_ACT_GACT,
@@ -227,6 +240,7 @@ static struct tc_action_ops act_gact_ops = {
227240
.init = tcf_gact_init,
228241
.walk = tcf_gact_walker,
229242
.lookup = tcf_gact_search,
243+
.get_fill_size = tcf_gact_get_fill_size,
230244
.size = sizeof(struct tcf_gact),
231245
};
232246

net/sched/cls_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
14331433
#ifdef CONFIG_NET_CLS_ACT
14341434
{
14351435
struct tc_action *act;
1436+
size_t attr_size = 0;
14361437

14371438
if (exts->police && tb[exts->police]) {
14381439
act = tcf_action_init_1(net, tp, tb[exts->police],
@@ -1450,7 +1451,7 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
14501451

14511452
err = tcf_action_init(net, tp, tb[exts->action],
14521453
rate_tlv, NULL, ovr, TCA_ACT_BIND,
1453-
&actions, extack);
1454+
&actions, &attr_size, extack);
14541455
if (err)
14551456
return err;
14561457
list_for_each_entry(act, &actions, list)

0 commit comments

Comments
 (0)