Skip to content

Commit a03e99d

Browse files
idoschdavem330
authored andcommitted
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: Ido Schimmel <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c6baf7e commit a03e99d

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
22172217
{
22182218
struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
22192219
struct mlxsw_sp_port_sample *sample;
2220-
u32 size;
2220+
struct psample_metadata md = {};
22212221

22222222
if (unlikely(!mlxsw_sp_port)) {
22232223
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,
22292229
sample = rcu_dereference(mlxsw_sp_port->sample);
22302230
if (!sample)
22312231
goto out_unlock;
2232-
size = sample->truncate ? sample->trunc_size : skb->len;
2233-
psample_sample_packet(sample->psample_group, skb, size,
2234-
mlxsw_sp_port->dev->ifindex, 0, sample->rate);
2232+
md.trunc_size = sample->truncate ? sample->trunc_size : skb->len;
2233+
md.in_ifindex = mlxsw_sp_port->dev->ifindex;
2234+
psample_sample_packet(sample->psample_group, skb, sample->rate, &md);
22352235
out_unlock:
22362236
rcu_read_unlock();
22372237
out:

include/net/psample.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@ struct psample_group {
1414
struct rcu_head rcu;
1515
};
1616

17+
struct psample_metadata {
18+
u32 trunc_size;
19+
int in_ifindex;
20+
int out_ifindex;
21+
};
22+
1723
struct psample_group *psample_group_get(struct net *net, u32 group_num);
1824
void psample_group_take(struct psample_group *group);
1925
void psample_group_put(struct psample_group *group);
2026

2127
#if IS_ENABLED(CONFIG_PSAMPLE)
2228

2329
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
24-
u32 trunc_size, int in_ifindex, int out_ifindex,
25-
u32 sample_rate);
30+
u32 sample_rate, const struct psample_metadata *md);
2631

2732
#else
2833

2934
static inline void psample_sample_packet(struct psample_group *group,
30-
struct sk_buff *skb, u32 trunc_size,
31-
int in_ifindex, int out_ifindex,
32-
u32 sample_rate)
35+
struct sk_buff *skb, u32 sample_rate,
36+
const struct psample_metadata *md)
3337
{
3438
}
3539

net/psample/psample.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info)
356356
#endif
357357

358358
void psample_sample_packet(struct psample_group *group, struct sk_buff *skb,
359-
u32 trunc_size, int in_ifindex, int out_ifindex,
360-
u32 sample_rate)
359+
u32 sample_rate, const struct psample_metadata *md)
361360
{
361+
int out_ifindex = md->out_ifindex;
362+
int in_ifindex = md->in_ifindex;
363+
u32 trunc_size = md->trunc_size;
362364
#ifdef CONFIG_INET
363365
struct ip_tunnel_info *tun_info;
364366
#endif

net/sched/act_sample.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,8 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a,
158158
{
159159
struct tcf_sample *s = to_sample(a);
160160
struct psample_group *psample_group;
161+
struct psample_metadata md = {};
161162
int retval;
162-
int size;
163-
int iif;
164-
int oif;
165163

166164
tcf_lastuse_update(&s->tcf_tm);
167165
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,
172170
/* randomly sample packets according to rate */
173171
if (psample_group && (prandom_u32() % s->rate == 0)) {
174172
if (!skb_at_tc_ingress(skb)) {
175-
iif = skb->skb_iif;
176-
oif = skb->dev->ifindex;
173+
md.in_ifindex = skb->skb_iif;
174+
md.out_ifindex = skb->dev->ifindex;
177175
} else {
178-
iif = skb->dev->ifindex;
179-
oif = 0;
176+
md.in_ifindex = skb->dev->ifindex;
180177
}
181178

182179
/* on ingress, the mac header gets popped, so push it back */
183180
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
184181
skb_push(skb, skb->mac_len);
185182

186-
size = s->truncate ? s->trunc_size : skb->len;
187-
psample_sample_packet(psample_group, skb, size, iif, oif,
188-
s->rate);
183+
md.trunc_size = s->truncate ? s->trunc_size : skb->len;
184+
psample_sample_packet(psample_group, skb, s->rate, &md);
189185

190186
if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
191187
skb_pull(skb, skb->mac_len);

0 commit comments

Comments
 (0)