Skip to content

Commit 8953b07

Browse files
jpirkodavem330
authored andcommitted
net: introduce nla_put_bitfield32() helper and use it
Introduce a helper to pass value and selector to. The helper packs them into struct and puts them into netlink message. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent acc086b commit 8953b07

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

‎include/net/netlink.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,21 @@ static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype,
14651465
return nla_put(skb, attrtype, sizeof(*addr), addr);
14661466
}
14671467

1468+
/**
1469+
* nla_put_bitfield32 - Add a bitfield32 netlink attribute to a socket buffer
1470+
* @skb: socket buffer to add attribute to
1471+
* @attrtype: attribute type
1472+
* @value: value carrying bits
1473+
* @selector: selector of valid bits
1474+
*/
1475+
static inline int nla_put_bitfield32(struct sk_buff *skb, int attrtype,
1476+
__u32 value, __u32 selector)
1477+
{
1478+
struct nla_bitfield32 tmp = { value, selector, };
1479+
1480+
return nla_put(skb, attrtype, sizeof(tmp), &tmp);
1481+
}
1482+
14681483
/**
14691484
* nla_get_u32 - return payload of u32 attribute
14701485
* @nla: u32 netlink attribute

‎net/sched/act_api.c‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -789,23 +789,15 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
789789
}
790790
rcu_read_unlock();
791791

792-
if (a->hw_stats != TCA_ACT_HW_STATS_ANY) {
793-
struct nla_bitfield32 hw_stats = {
794-
a->hw_stats,
795-
TCA_ACT_HW_STATS_ANY,
796-
};
797-
798-
if (nla_put(skb, TCA_ACT_HW_STATS, sizeof(hw_stats), &hw_stats))
799-
goto nla_put_failure;
800-
}
801-
802-
if (a->tcfa_flags) {
803-
struct nla_bitfield32 flags = { a->tcfa_flags,
804-
a->tcfa_flags, };
792+
if (a->hw_stats != TCA_ACT_HW_STATS_ANY &&
793+
nla_put_bitfield32(skb, TCA_ACT_HW_STATS,
794+
a->hw_stats, TCA_ACT_HW_STATS_ANY))
795+
goto nla_put_failure;
805796

806-
if (nla_put(skb, TCA_ACT_FLAGS, sizeof(flags), &flags))
807-
goto nla_put_failure;
808-
}
797+
if (a->tcfa_flags &&
798+
nla_put_bitfield32(skb, TCA_ACT_FLAGS,
799+
a->tcfa_flags, a->tcfa_flags))
800+
goto nla_put_failure;
809801

810802
nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
811803
if (nest == NULL)

‎net/sched/sch_red.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,6 @@ static int red_dump_offload_stats(struct Qdisc *sch)
349349
static int red_dump(struct Qdisc *sch, struct sk_buff *skb)
350350
{
351351
struct red_sched_data *q = qdisc_priv(sch);
352-
struct nla_bitfield32 flags_bf = {
353-
.selector = red_supported_flags,
354-
.value = q->flags,
355-
};
356352
struct nlattr *opts = NULL;
357353
struct tc_red_qopt opt = {
358354
.limit = q->limit,
@@ -375,7 +371,8 @@ static int red_dump(struct Qdisc *sch, struct sk_buff *skb)
375371
goto nla_put_failure;
376372
if (nla_put(skb, TCA_RED_PARMS, sizeof(opt), &opt) ||
377373
nla_put_u32(skb, TCA_RED_MAX_P, q->parms.max_P) ||
378-
nla_put(skb, TCA_RED_FLAGS, sizeof(flags_bf), &flags_bf))
374+
nla_put_bitfield32(skb, TCA_RED_FLAGS,
375+
q->flags, red_supported_flags))
379376
goto nla_put_failure;
380377
return nla_nest_end(skb, opts);
381378

0 commit comments

Comments
 (0)