diff mbox series

[4/5] net sched actions: implement get_fill_size routine in act_gact

Message ID 1519929931-1119-5-git-send-email-mrv@mojatatu.com
State Superseded, archived
Delegated to: David Miller
Headers show
Series Fix event generation for actions batch Add/Delete mode | expand

Commit Message

Roman Mashak March 1, 2018, 6:45 p.m. UTC
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
---
 net/sched/act_gact.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Marcelo Ricardo Leitner March 1, 2018, 7:03 p.m. UTC | #1
On Thu, Mar 01, 2018 at 01:45:30PM -0500, Roman Mashak wrote:
> Signed-off-by: Roman Mashak <mrv@mojatatu.com>
> ---
>  net/sched/act_gact.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
> index 7456325..ee775ac 100644
> --- a/net/sched/act_gact.c
> +++ b/net/sched/act_gact.c
> @@ -217,6 +217,22 @@ static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index,
>  	return tcf_idr_search(tn, a, index);
>  }
>  
> +static size_t tcf_gact_get_fill_size(const struct tc_action *act)
> +{
> +#ifdef CONFIG_GACT_PROB
> +	struct tcf_gact *gact = to_gact(act);
> +	int prob_len = 0;
> +
> +	if (gact->tcfg_ptype)
> +		prob_len = nla_total_size(sizeof(struct tc_gact_p));
> +#endif
> +	return	nla_total_size(sizeof(struct tc_gact)) /* TCA_GACT_PARMS */
> +#ifdef CONFIG_GACT_PROB
> +		+ prob_len /* TCA_GACT_PROB */
> +#endif
> +		;
> +}

This is quite bad to the eye. What about:

static size_t tcf_gact_get_fill_size(const struct tc_action *act)
{
	size_t sz = nla_total_size(sizeof(struct tc_gact)); /* TCA_GACT_PARMS */

#ifdef CONFIG_GACT_PROB
	if (to_gact(act)->tcfg_ptype)
		sz += nla_total_size(sizeof(struct tc_gact_p)); /* TCA_GACT_PROB */
#endif

	return sz;
}

Should be the same, bug easier to read.

> +
>  static struct tc_action_ops act_gact_ops = {
>  	.kind		=	"gact",
>  	.type		=	TCA_ACT_GACT,
> @@ -227,6 +243,7 @@ static struct tc_action_ops act_gact_ops = {
>  	.init		=	tcf_gact_init,
>  	.walk		=	tcf_gact_walker,
>  	.lookup		=	tcf_gact_search,
> +	.get_fill_size	=	tcf_gact_get_fill_size,
>  	.size		=	sizeof(struct tcf_gact),
>  };
>  
> -- 
> 2.7.4
>
Roman Mashak March 2, 2018, 3:52 p.m. UTC | #2
Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> writes:

> On Thu, Mar 01, 2018 at 01:45:30PM -0500, Roman Mashak wrote:
>> Signed-off-by: Roman Mashak <mrv@mojatatu.com>
>> ---
>>  net/sched/act_gact.c | 17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>> 
>> diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
>> index 7456325..ee775ac 100644
>> --- a/net/sched/act_gact.c
>> +++ b/net/sched/act_gact.c
>> @@ -217,6 +217,22 @@ static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index,
>>  	return tcf_idr_search(tn, a, index);
>>  }
>>  
>> +static size_t tcf_gact_get_fill_size(const struct tc_action *act)
>> +{
>> +#ifdef CONFIG_GACT_PROB
>> +	struct tcf_gact *gact = to_gact(act);
>> +	int prob_len = 0;
>> +
>> +	if (gact->tcfg_ptype)
>> +		prob_len = nla_total_size(sizeof(struct tc_gact_p));
>> +#endif
>> +	return	nla_total_size(sizeof(struct tc_gact)) /* TCA_GACT_PARMS */
>> +#ifdef CONFIG_GACT_PROB
>> +		+ prob_len /* TCA_GACT_PROB */
>> +#endif
>> +		;
>> +}
>
> This is quite bad to the eye. What about:
>
> static size_t tcf_gact_get_fill_size(const struct tc_action *act)
> {
> 	size_t sz = nla_total_size(sizeof(struct tc_gact)); /* TCA_GACT_PARMS */
>
> #ifdef CONFIG_GACT_PROB
> 	if (to_gact(act)->tcfg_ptype)
> 		sz += nla_total_size(sizeof(struct tc_gact_p)); /* TCA_GACT_PROB */
> #endif
>
> 	return sz;
> }
>
> Should be the same, bug easier to read.

Agree, I will send v2.
diff mbox series

Patch

diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index 7456325..ee775ac 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -217,6 +217,22 @@  static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index,
 	return tcf_idr_search(tn, a, index);
 }
 
+static size_t tcf_gact_get_fill_size(const struct tc_action *act)
+{
+#ifdef CONFIG_GACT_PROB
+	struct tcf_gact *gact = to_gact(act);
+	int prob_len = 0;
+
+	if (gact->tcfg_ptype)
+		prob_len = nla_total_size(sizeof(struct tc_gact_p));
+#endif
+	return	nla_total_size(sizeof(struct tc_gact)) /* TCA_GACT_PARMS */
+#ifdef CONFIG_GACT_PROB
+		+ prob_len /* TCA_GACT_PROB */
+#endif
+		;
+}
+
 static struct tc_action_ops act_gact_ops = {
 	.kind		=	"gact",
 	.type		=	TCA_ACT_GACT,
@@ -227,6 +243,7 @@  static struct tc_action_ops act_gact_ops = {
 	.init		=	tcf_gact_init,
 	.walk		=	tcf_gact_walker,
 	.lookup		=	tcf_gact_search,
+	.get_fill_size	=	tcf_gact_get_fill_size,
 	.size		=	sizeof(struct tcf_gact),
 };