|
| 1 | +From ab65c38369aec72cbaac3e1c9d6731804edfc5b4 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ido Schimmel <idosch@nvidia.com> |
| 3 | +Date: Sun, 14 Mar 2021 14:19:30 +0200 |
| 4 | +Subject: [PATCH 1/3] psample: Encapsulate packet metadata in a struct |
| 5 | + |
| 6 | +Currently, callers of psample_sample_packet() pass three metadata |
| 7 | +attributes: Ingress port, egress port and truncated size. Subsequent |
| 8 | +patches are going to add more attributes (e.g., egress queue occupancy), |
| 9 | +which also need an indication whether they are valid or not. |
| 10 | + |
| 11 | +Encapsulate packet metadata in a struct in order to keep the number of |
| 12 | +arguments reasonable. |
| 13 | + |
| 14 | +Signed-off-by: Ido Schimmel <idosch@nvidia.com> |
| 15 | +Reviewed-by: Jiri Pirko <jiri@nvidia.com> |
| 16 | +Signed-off-by: David S. Miller <davem@davemloft.net> |
| 17 | +--- |
| 18 | + drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 8 ++++---- |
| 19 | + include/net/psample.h | 14 +++++++++----- |
| 20 | + net/psample/psample.c | 6 ++++-- |
| 21 | + net/sched/act_sample.c | 16 ++++++---------- |
| 22 | + 4 files changed, 23 insertions(+), 21 deletions(-) |
| 23 | + |
| 24 | +diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c |
| 25 | +index 1a9978f50..323857943 100644 |
| 26 | +--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c |
| 27 | ++++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c |
| 28 | +@@ -2167,7 +2167,7 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb, |
| 29 | + { |
| 30 | + struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port]; |
| 31 | + struct mlxsw_sp_port_sample *sample; |
| 32 | +- u32 size; |
| 33 | ++ struct psample_metadata md = {}; |
| 34 | + |
| 35 | + if (unlikely(!mlxsw_sp_port)) { |
| 36 | + dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received for non-existent port\n", |
| 37 | +@@ -2179,9 +2179,9 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb, |
| 38 | + sample = rcu_dereference(mlxsw_sp_port->sample); |
| 39 | + if (!sample) |
| 40 | + goto out_unlock; |
| 41 | +- size = sample->truncate ? sample->trunc_size : skb->len; |
| 42 | +- psample_sample_packet(sample->psample_group, skb, size, |
| 43 | +- mlxsw_sp_port->dev->ifindex, 0, sample->rate); |
| 44 | ++ md.trunc_size = sample->truncate ? sample->trunc_size : skb->len; |
| 45 | ++ md.in_ifindex = mlxsw_sp_port->dev->ifindex; |
| 46 | ++ psample_sample_packet(sample->psample_group, skb, sample->rate, &md); |
| 47 | + out_unlock: |
| 48 | + rcu_read_unlock(); |
| 49 | + out: |
| 50 | +diff --git a/include/net/psample.h b/include/net/psample.h |
| 51 | +index 68ae16bb0..ac6dbfb38 100644 |
| 52 | +--- a/include/net/psample.h |
| 53 | ++++ b/include/net/psample.h |
| 54 | +@@ -14,6 +14,12 @@ struct psample_group { |
| 55 | + struct rcu_head rcu; |
| 56 | + }; |
| 57 | + |
| 58 | ++struct psample_metadata { |
| 59 | ++ u32 trunc_size; |
| 60 | ++ int in_ifindex; |
| 61 | ++ int out_ifindex; |
| 62 | ++}; |
| 63 | ++ |
| 64 | + struct psample_group *psample_group_get(struct net *net, u32 group_num); |
| 65 | + void psample_group_take(struct psample_group *group); |
| 66 | + void psample_group_put(struct psample_group *group); |
| 67 | +@@ -21,15 +27,13 @@ void psample_group_put(struct psample_group *group); |
| 68 | + #if IS_ENABLED(CONFIG_PSAMPLE) |
| 69 | + |
| 70 | + void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, |
| 71 | +- u32 trunc_size, int in_ifindex, int out_ifindex, |
| 72 | +- u32 sample_rate); |
| 73 | ++ u32 sample_rate, const struct psample_metadata *md); |
| 74 | + |
| 75 | + #else |
| 76 | + |
| 77 | + static inline void psample_sample_packet(struct psample_group *group, |
| 78 | +- struct sk_buff *skb, u32 trunc_size, |
| 79 | +- int in_ifindex, int out_ifindex, |
| 80 | +- u32 sample_rate) |
| 81 | ++ struct sk_buff *skb, u32 sample_rate, |
| 82 | ++ const struct psample_metadata *md) |
| 83 | + { |
| 84 | + } |
| 85 | + |
| 86 | +diff --git a/net/psample/psample.c b/net/psample/psample.c |
| 87 | +index 482c07f27..065bc887d 100644 |
| 88 | +--- a/net/psample/psample.c |
| 89 | ++++ b/net/psample/psample.c |
| 90 | +@@ -356,9 +356,11 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info) |
| 91 | + #endif |
| 92 | + |
| 93 | + void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, |
| 94 | +- u32 trunc_size, int in_ifindex, int out_ifindex, |
| 95 | +- u32 sample_rate) |
| 96 | ++ u32 sample_rate, const struct psample_metadata *md) |
| 97 | + { |
| 98 | ++ int out_ifindex = md->out_ifindex; |
| 99 | ++ int in_ifindex = md->in_ifindex; |
| 100 | ++ u32 trunc_size = md->trunc_size; |
| 101 | + #ifdef CONFIG_INET |
| 102 | + struct ip_tunnel_info *tun_info; |
| 103 | + #endif |
| 104 | +diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c |
| 105 | +index 3ebf9ede3..2fece01f2 100644 |
| 106 | +--- a/net/sched/act_sample.c |
| 107 | ++++ b/net/sched/act_sample.c |
| 108 | +@@ -158,10 +158,8 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a, |
| 109 | + { |
| 110 | + struct tcf_sample *s = to_sample(a); |
| 111 | + struct psample_group *psample_group; |
| 112 | ++ struct psample_metadata md = {}; |
| 113 | + int retval; |
| 114 | +- int size; |
| 115 | +- int iif; |
| 116 | +- int oif; |
| 117 | + |
| 118 | + tcf_lastuse_update(&s->tcf_tm); |
| 119 | + bstats_cpu_update(this_cpu_ptr(s->common.cpu_bstats), skb); |
| 120 | +@@ -172,20 +170,18 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a, |
| 121 | + /* randomly sample packets according to rate */ |
| 122 | + if (psample_group && (prandom_u32() % s->rate == 0)) { |
| 123 | + if (!skb_at_tc_ingress(skb)) { |
| 124 | +- iif = skb->skb_iif; |
| 125 | +- oif = skb->dev->ifindex; |
| 126 | ++ md.in_ifindex = skb->skb_iif; |
| 127 | ++ md.out_ifindex = skb->dev->ifindex; |
| 128 | + } else { |
| 129 | +- iif = skb->dev->ifindex; |
| 130 | +- oif = 0; |
| 131 | ++ md.in_ifindex = skb->dev->ifindex; |
| 132 | + } |
| 133 | + |
| 134 | + /* on ingress, the mac header gets popped, so push it back */ |
| 135 | + if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev)) |
| 136 | + skb_push(skb, skb->mac_len); |
| 137 | + |
| 138 | +- size = s->truncate ? s->trunc_size : skb->len; |
| 139 | +- psample_sample_packet(psample_group, skb, size, iif, oif, |
| 140 | +- s->rate); |
| 141 | ++ md.trunc_size = s->truncate ? s->trunc_size : skb->len; |
| 142 | ++ psample_sample_packet(psample_group, skb, s->rate, &md); |
| 143 | + |
| 144 | + if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev)) |
| 145 | + skb_pull(skb, skb->mac_len); |
| 146 | +-- |
| 147 | +2.17.1 |
| 148 | + |
0 commit comments