psample: Encapsulate packet metadata in a struct
[sfrench/cifs-2.6.git] / net / sched / act_sample.c
index 3ebf9ede3cf10cccc825305faec1a15b810fd120..6a0c16e4351d717384af50b68abc860d5ef1ee77 100644 (file)
@@ -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 psample_group *psample_group;
+       struct psample_metadata md = {};
        int retval;
-       int size;
-       int iif;
-       int oif;
 
        tcf_lastuse_update(&s->tcf_tm);
        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,
        /* randomly sample packets according to rate */
        if (psample_group && (prandom_u32() % s->rate == 0)) {
                if (!skb_at_tc_ingress(skb)) {
-                       iif = skb->skb_iif;
-                       oif = skb->dev->ifindex;
+                       md.in_ifindex = skb->skb_iif;
+                       md.out_ifindex = skb->dev->ifindex;
                } else {
-                       iif = skb->dev->ifindex;
-                       oif = 0;
+                       md.in_ifindex = skb->dev->ifindex;
                }
 
                /* on ingress, the mac header gets popped, so push it back */
                if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
                        skb_push(skb, skb->mac_len);
 
-               size = s->truncate ? s->trunc_size : skb->len;
-               psample_sample_packet(psample_group, skb, size, iif, oif,
-                                     s->rate);
+               md.trunc_size = s->truncate ? s->trunc_size : skb->len;
+               psample_sample_packet(psample_group, skb, s->rate, &md);
 
                if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
                        skb_pull(skb, skb->mac_len);
@@ -194,6 +190,16 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a,
        return retval;
 }
 
+static void tcf_sample_stats_update(struct tc_action *a, u64 bytes, u64 packets,
+                                   u64 drops, u64 lastuse, bool hw)
+{
+       struct tcf_sample *s = to_sample(a);
+       struct tcf_t *tm = &s->tcf_tm;
+
+       tcf_action_update_stats(a, bytes, packets, drops, hw);
+       tm->lastuse = max_t(u64, tm->lastuse, lastuse);
+}
+
 static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a,
                           int bind, int ref)
 {
@@ -280,6 +286,7 @@ static struct tc_action_ops act_sample_ops = {
        .id       = TCA_ID_SAMPLE,
        .owner    = THIS_MODULE,
        .act      = tcf_sample_act,
+       .stats_update = tcf_sample_stats_update,
        .dump     = tcf_sample_dump,
        .init     = tcf_sample_init,
        .cleanup  = tcf_sample_cleanup,