Skip to content

Commit 093b0f3

Browse files
amorenozkuba-moo
authored andcommitted
net: psample: add user cookie
Add a user cookie to the sample metadata so that sample emitters can provide more contextual information to samples. If present, send the user cookie in a new attribute: PSAMPLE_ATTR_USER_COOKIE. Reviewed-by: Michal Kubiak <[email protected]> Acked-by: Eelco Chaudron <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Adrian Moreno <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 064fbc4 commit 093b0f3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

include/net/psample.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ struct psample_metadata {
2525
out_tc_occ_valid:1,
2626
latency_valid:1,
2727
unused:5;
28+
const u8 *user_cookie;
29+
u32 user_cookie_len;
2830
};
2931

3032
struct psample_group *psample_group_get(struct net *net, u32 group_num);

include/uapi/linux/psample.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum {
1919
PSAMPLE_ATTR_LATENCY, /* u64, nanoseconds */
2020
PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */
2121
PSAMPLE_ATTR_PROTO, /* u16 */
22+
PSAMPLE_ATTR_USER_COOKIE, /* binary, user provided data */
2223

2324
__PSAMPLE_ATTR_MAX
2425
};

net/psample/psample.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
386386
nla_total_size(sizeof(u32)) + /* group_num */
387387
nla_total_size(sizeof(u32)) + /* seq */
388388
nla_total_size_64bit(sizeof(u64)) + /* timestamp */
389-
nla_total_size(sizeof(u16)); /* protocol */
389+
nla_total_size(sizeof(u16)) + /* protocol */
390+
(md->user_cookie_len ?
391+
nla_total_size(md->user_cookie_len) : 0); /* user cookie */
390392

391393
#ifdef CONFIG_INET
392394
tun_info = skb_tunnel_info(skb);
@@ -486,6 +488,11 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
486488
}
487489
#endif
488490

491+
if (md->user_cookie && md->user_cookie_len &&
492+
nla_put(nl_skb, PSAMPLE_ATTR_USER_COOKIE, md->user_cookie_len,
493+
md->user_cookie))
494+
goto error;
495+
489496
genlmsg_end(nl_skb, data);
490497
genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0,
491498
PSAMPLE_NL_MCGRP_SAMPLE, GFP_ATOMIC);

0 commit comments

Comments
 (0)