Skip to content

Commit 5eecd85

Browse files
amorenozkuba-moo
authored andcommitted
psample: adjust size if rate_as_probability is set
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: 7b1b2b6 ("net: psample: allow using rate as probability") Signed-off-by: Adrian Moreno <[email protected]> Reviewed-by: Aaron Conole <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5eb70db commit 5eecd85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/psample/psample.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ void psample_sample_packet(struct psample_group *group,
393393
nla_total_size_64bit(sizeof(u64)) + /* timestamp */
394394
nla_total_size(sizeof(u16)) + /* protocol */
395395
(md->user_cookie_len ?
396-
nla_total_size(md->user_cookie_len) : 0); /* user cookie */
396+
nla_total_size(md->user_cookie_len) : 0) + /* user cookie */
397+
(md->rate_as_probability ?
398+
nla_total_size(0) : 0); /* rate as probability */
397399

398400
#ifdef CONFIG_INET
399401
tun_info = skb_tunnel_info(skb);
@@ -498,8 +500,9 @@ void psample_sample_packet(struct psample_group *group,
498500
md->user_cookie))
499501
goto error;
500502

501-
if (md->rate_as_probability)
502-
nla_put_flag(nl_skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY);
503+
if (md->rate_as_probability &&
504+
nla_put_flag(nl_skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY))
505+
goto error;
503506

504507
genlmsg_end(nl_skb, data);
505508
genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0,

0 commit comments

Comments
 (0)