-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: Introduce psample, a new genetlink channel for packet sampling
Add a general way for kernel modules to sample packets, without being tied to any specific subsystem. This netlink channel can be used by tc, iptables, etc. and allow to standardize packet sampling in the kernel. For every sampled packet, the psample module adds the following metadata fields: PSAMPLE_ATTR_IIFINDEX - the packets input ifindex, if applicable PSAMPLE_ATTR_OIFINDEX - the packet output ifindex, if applicable PSAMPLE_ATTR_ORIGSIZE - the packet's original size, in case it has been truncated during sampling PSAMPLE_ATTR_SAMPLE_GROUP - the packet's sample group, which is set by the user who initiated the sampling. This field allows the user to differentiate between several samplers working simultaneously and filter packets relevant to him PSAMPLE_ATTR_GROUP_SEQ - sequence counter of last sent packet. The sequence is kept for each group PSAMPLE_ATTR_SAMPLE_RATE - the sampling rate used for sampling the packets PSAMPLE_ATTR_DATA - the actual packet bits The sampled packets are sent to the PSAMPLE_NL_MCGRP_SAMPLE multicast group. In addition, add the GET_GROUPS netlink command which allows the user to see the current sample groups, their refcount and sequence number. This command currently supports only netlink dump mode. Signed-off-by: Yotam Gigi <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Reviewed-by: Jamal Hadi Salim <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
- Loading branch information
Showing
9 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9957,6 +9957,13 @@ L: [email protected] | |
S: Maintained | ||
F: drivers/block/ps3vram.c | ||
|
||
PSAMPLE PACKET SAMPLING SUPPORT: | ||
M: Yotam Gigi <[email protected]> | ||
S: Maintained | ||
F: net/psample | ||
F: include/net/psample.h | ||
F: include/uapi/linux/psample.h | ||
|
||
PSTORE FILESYSTEM | ||
M: Anton Vorontsov <[email protected]> | ||
M: Colin Cross <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef __NET_PSAMPLE_H | ||
#define __NET_PSAMPLE_H | ||
|
||
#include <uapi/linux/psample.h> | ||
#include <linux/module.h> | ||
#include <linux/list.h> | ||
|
||
struct psample_group { | ||
struct list_head list; | ||
struct net *net; | ||
u32 group_num; | ||
u32 refcount; | ||
u32 seq; | ||
}; | ||
|
||
struct psample_group *psample_group_get(struct net *net, u32 group_num); | ||
void psample_group_put(struct psample_group *group); | ||
|
||
#if IS_ENABLED(CONFIG_PSAMPLE) | ||
|
||
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, | ||
u32 trunc_size, int in_ifindex, int out_ifindex, | ||
u32 sample_rate); | ||
|
||
#else | ||
|
||
static inline void psample_sample_packet(struct psample_group *group, | ||
struct sk_buff *skb, u32 trunc_size, | ||
int in_ifindex, int out_ifindex, | ||
u32 sample_rate) | ||
{ | ||
} | ||
|
||
#endif | ||
|
||
#endif /* __NET_PSAMPLE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef __UAPI_PSAMPLE_H | ||
#define __UAPI_PSAMPLE_H | ||
|
||
enum { | ||
/* sampled packet metadata */ | ||
PSAMPLE_ATTR_IIFINDEX, | ||
PSAMPLE_ATTR_OIFINDEX, | ||
PSAMPLE_ATTR_ORIGSIZE, | ||
PSAMPLE_ATTR_SAMPLE_GROUP, | ||
PSAMPLE_ATTR_GROUP_SEQ, | ||
PSAMPLE_ATTR_SAMPLE_RATE, | ||
PSAMPLE_ATTR_DATA, | ||
|
||
/* commands attributes */ | ||
PSAMPLE_ATTR_GROUP_REFCOUNT, | ||
|
||
__PSAMPLE_ATTR_MAX | ||
}; | ||
|
||
enum psample_command { | ||
PSAMPLE_CMD_SAMPLE, | ||
PSAMPLE_CMD_GET_GROUP, | ||
PSAMPLE_CMD_NEW_GROUP, | ||
PSAMPLE_CMD_DEL_GROUP, | ||
}; | ||
|
||
/* Can be overridden at runtime by module option */ | ||
#define PSAMPLE_ATTR_MAX (__PSAMPLE_ATTR_MAX - 1) | ||
|
||
#define PSAMPLE_NL_MCGRP_CONFIG_NAME "config" | ||
#define PSAMPLE_NL_MCGRP_SAMPLE_NAME "packets" | ||
#define PSAMPLE_GENL_NAME "psample" | ||
#define PSAMPLE_GENL_VERSION 1 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# psample packet sampling configuration | ||
# | ||
|
||
menuconfig PSAMPLE | ||
depends on NET | ||
tristate "Packet-sampling netlink channel" | ||
default n | ||
help | ||
Say Y here to add support for packet-sampling netlink channel | ||
This netlink channel allows transferring packets alongside some | ||
metadata to userspace. | ||
|
||
To compile this support as a module, choose M here: the module will | ||
be called psample. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# Makefile for the psample netlink channel | ||
# | ||
|
||
obj-$(CONFIG_PSAMPLE) += psample.o |
Oops, something went wrong.