Commit a03e99d3 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

psample: Encapsulate packet metadata in a struct

Currently, callers of psample_sample_packet() pass three metadata
attributes: Ingress port, egress port and truncated size. Subsequent
patches are going to add more attributes (e.g., egress queue occupancy),
which also need an indication whether they are valid or not.

Encapsulate packet metadata in a struct in order to keep the number of
arguments reasonable.
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c6baf7ee
...@@ -2217,7 +2217,7 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb, ...@@ -2217,7 +2217,7 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
{ {
struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port]; struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
struct mlxsw_sp_port_sample *sample; struct mlxsw_sp_port_sample *sample;
u32 size; struct psample_metadata md = {};
if (unlikely(!mlxsw_sp_port)) { if (unlikely(!mlxsw_sp_port)) {
dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received for non-existent port\n", dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received for non-existent port\n",
...@@ -2229,9 +2229,9 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb, ...@@ -2229,9 +2229,9 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
sample = rcu_dereference(mlxsw_sp_port->sample); sample = rcu_dereference(mlxsw_sp_port->sample);
if (!sample) if (!sample)
goto out_unlock; goto out_unlock;
size = sample->truncate ? sample->trunc_size : skb->len; md.trunc_size = sample->truncate ? sample->trunc_size : skb->len;
psample_sample_packet(sample->psample_group, skb, size, md.in_ifindex = mlxsw_sp_port->dev->ifindex;
mlxsw_sp_port->dev->ifindex, 0, sample->rate); psample_sample_packet(sample->psample_group, skb, sample->rate, &md);
out_unlock: out_unlock:
rcu_read_unlock(); rcu_read_unlock();
out: out:
......
...@@ -14,6 +14,12 @@ struct psample_group { ...@@ -14,6 +14,12 @@ struct psample_group {
struct rcu_head rcu; struct rcu_head rcu;
}; };
struct psample_metadata {
u32 trunc_size;
int in_ifindex;
int out_ifindex;
};
struct psample_group *psample_group_get(struct net *net, u32 group_num); struct psample_group *psample_group_get(struct net *net, u32 group_num);
void psample_group_take(struct psample_group *group); void psample_group_take(struct psample_group *group);
void psample_group_put(struct psample_group *group); void psample_group_put(struct psample_group *group);
...@@ -21,15 +27,13 @@ void psample_group_put(struct psample_group *group); ...@@ -21,15 +27,13 @@ void psample_group_put(struct psample_group *group);
#if IS_ENABLED(CONFIG_PSAMPLE) #if IS_ENABLED(CONFIG_PSAMPLE)
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
u32 trunc_size, int in_ifindex, int out_ifindex, u32 sample_rate, const struct psample_metadata *md);
u32 sample_rate);
#else #else
static inline void psample_sample_packet(struct psample_group *group, static inline void psample_sample_packet(struct psample_group *group,
struct sk_buff *skb, u32 trunc_size, struct sk_buff *skb, u32 sample_rate,
int in_ifindex, int out_ifindex, const struct psample_metadata *md)
u32 sample_rate)
{ {
} }
......
...@@ -356,9 +356,11 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info) ...@@ -356,9 +356,11 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info)
#endif #endif
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
u32 trunc_size, int in_ifindex, int out_ifindex, u32 sample_rate, const struct psample_metadata *md)
u32 sample_rate)
{ {
int out_ifindex = md->out_ifindex;
int in_ifindex = md->in_ifindex;
u32 trunc_size = md->trunc_size;
#ifdef CONFIG_INET #ifdef CONFIG_INET
struct ip_tunnel_info *tun_info; struct ip_tunnel_info *tun_info;
#endif #endif
......
...@@ -158,10 +158,8 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a, ...@@ -158,10 +158,8 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a,
{ {
struct tcf_sample *s = to_sample(a); struct tcf_sample *s = to_sample(a);
struct psample_group *psample_group; struct psample_group *psample_group;
struct psample_metadata md = {};
int retval; int retval;
int size;
int iif;
int oif;
tcf_lastuse_update(&s->tcf_tm); tcf_lastuse_update(&s->tcf_tm);
bstats_cpu_update(this_cpu_ptr(s->common.cpu_bstats), skb); bstats_cpu_update(this_cpu_ptr(s->common.cpu_bstats), skb);
...@@ -172,20 +170,18 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a, ...@@ -172,20 +170,18 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a,
/* randomly sample packets according to rate */ /* randomly sample packets according to rate */
if (psample_group && (prandom_u32() % s->rate == 0)) { if (psample_group && (prandom_u32() % s->rate == 0)) {
if (!skb_at_tc_ingress(skb)) { if (!skb_at_tc_ingress(skb)) {
iif = skb->skb_iif; md.in_ifindex = skb->skb_iif;
oif = skb->dev->ifindex; md.out_ifindex = skb->dev->ifindex;
} else { } else {
iif = skb->dev->ifindex; md.in_ifindex = skb->dev->ifindex;
oif = 0;
} }
/* on ingress, the mac header gets popped, so push it back */ /* on ingress, the mac header gets popped, so push it back */
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev)) if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
skb_push(skb, skb->mac_len); skb_push(skb, skb->mac_len);
size = s->truncate ? s->trunc_size : skb->len; md.trunc_size = s->truncate ? s->trunc_size : skb->len;
psample_sample_packet(psample_group, skb, size, iif, oif, psample_sample_packet(psample_group, skb, s->rate, &md);
s->rate);
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev)) if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
skb_pull(skb, skb->mac_len); skb_pull(skb, skb->mac_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment