diff mbox series

[net] psample: adjust size if rate_as_probability is set

Message ID 20241217113739.3929300-1-amorenoz@redhat.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net] psample: adjust size if rate_as_probability is set | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-12-17--21-00 (tests: 883)

Commit Message

Adrian Moreno Dec. 17, 2024, 11:37 a.m. UTC
If PSAMPLE_ATTR_SAMPLE_PROBABILITY flag is to be sent, the available
size for the packet data has to be adjusted accordingly.

Also, check the error code returned by nla_put_flag.

Fixes: 7b1b2b60c63f ("net: psample: allow using rate as probability")
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 net/psample/psample.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Aaron Conole Dec. 17, 2024, 1:27 p.m. UTC | #1
Adrian Moreno <amorenoz@redhat.com> writes:

> If PSAMPLE_ATTR_SAMPLE_PROBABILITY flag is to be sent, the available
> size for the packet data has to be adjusted accordingly.
>
> Also, check the error code returned by nla_put_flag.
>
> Fixes: 7b1b2b60c63f ("net: psample: allow using rate as probability")
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---

Reviewed-by: Aaron Conole <aconole@redhat.com>

>  net/psample/psample.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/net/psample/psample.c b/net/psample/psample.c
> index a0ddae8a65f9..25f92ba0840c 100644
> --- a/net/psample/psample.c
> +++ b/net/psample/psample.c
> @@ -393,7 +393,9 @@ void psample_sample_packet(struct psample_group *group,
>  		   nla_total_size_64bit(sizeof(u64)) +	/* timestamp */
>  		   nla_total_size(sizeof(u16)) +	/* protocol */
>  		   (md->user_cookie_len ?
> -		    nla_total_size(md->user_cookie_len) : 0); /* user cookie */
> +		    nla_total_size(md->user_cookie_len) : 0) + /* user cookie */
> +		   (md->rate_as_probability ?
> +		    nla_total_size(0) : 0);	/* rate as probability */
>  
>  #ifdef CONFIG_INET
>  	tun_info = skb_tunnel_info(skb);
> @@ -498,8 +500,9 @@ void psample_sample_packet(struct psample_group *group,
>  		    md->user_cookie))
>  		goto error;
>  
> -	if (md->rate_as_probability)
> -		nla_put_flag(nl_skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY);
> +	if (md->rate_as_probability &&
> +	    nla_put_flag(nl_skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY))
> +		goto error;
>  
>  	genlmsg_end(nl_skb, data);
>  	genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0,
Ido Schimmel Dec. 17, 2024, 2:39 p.m. UTC | #2
On Tue, Dec 17, 2024 at 12:37:39PM +0100, Adrian Moreno wrote:
> If PSAMPLE_ATTR_SAMPLE_PROBABILITY flag is to be sent, the available
> size for the packet data has to be adjusted accordingly.
> 
> Also, check the error code returned by nla_put_flag.
> 
> Fixes: 7b1b2b60c63f ("net: psample: allow using rate as probability")
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
diff mbox series

Patch

diff --git a/net/psample/psample.c b/net/psample/psample.c
index a0ddae8a65f9..25f92ba0840c 100644
--- a/net/psample/psample.c
+++ b/net/psample/psample.c
@@ -393,7 +393,9 @@  void psample_sample_packet(struct psample_group *group,
 		   nla_total_size_64bit(sizeof(u64)) +	/* timestamp */
 		   nla_total_size(sizeof(u16)) +	/* protocol */
 		   (md->user_cookie_len ?
-		    nla_total_size(md->user_cookie_len) : 0); /* user cookie */
+		    nla_total_size(md->user_cookie_len) : 0) + /* user cookie */
+		   (md->rate_as_probability ?
+		    nla_total_size(0) : 0);	/* rate as probability */
 
 #ifdef CONFIG_INET
 	tun_info = skb_tunnel_info(skb);
@@ -498,8 +500,9 @@  void psample_sample_packet(struct psample_group *group,
 		    md->user_cookie))
 		goto error;
 
-	if (md->rate_as_probability)
-		nla_put_flag(nl_skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY);
+	if (md->rate_as_probability &&
+	    nla_put_flag(nl_skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY))
+		goto error;
 
 	genlmsg_end(nl_skb, data);
 	genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0,