Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* net/sched/sch_atm.c - ATM VC selection "queueing discipline" */
0003 
0004 /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
0005 
0006 #include <linux/module.h>
0007 #include <linux/slab.h>
0008 #include <linux/init.h>
0009 #include <linux/interrupt.h>
0010 #include <linux/string.h>
0011 #include <linux/errno.h>
0012 #include <linux/skbuff.h>
0013 #include <linux/atmdev.h>
0014 #include <linux/atmclip.h>
0015 #include <linux/rtnetlink.h>
0016 #include <linux/file.h>     /* for fput */
0017 #include <net/netlink.h>
0018 #include <net/pkt_sched.h>
0019 #include <net/pkt_cls.h>
0020 
0021 /*
0022  * The ATM queuing discipline provides a framework for invoking classifiers
0023  * (aka "filters"), which in turn select classes of this queuing discipline.
0024  * Each class maps the flow(s) it is handling to a given VC. Multiple classes
0025  * may share the same VC.
0026  *
0027  * When creating a class, VCs are specified by passing the number of the open
0028  * socket descriptor by which the calling process references the VC. The kernel
0029  * keeps the VC open at least until all classes using it are removed.
0030  *
0031  * In this file, most functions are named atm_tc_* to avoid confusion with all
0032  * the atm_* in net/atm. This naming convention differs from what's used in the
0033  * rest of net/sched.
0034  *
0035  * Known bugs:
0036  *  - sometimes messes up the IP stack
0037  *  - any manipulations besides the few operations described in the README, are
0038  *    untested and likely to crash the system
0039  *  - should lock the flow while there is data in the queue (?)
0040  */
0041 
0042 #define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
0043 
0044 struct atm_flow_data {
0045     struct Qdisc_class_common common;
0046     struct Qdisc        *q; /* FIFO, TBF, etc. */
0047     struct tcf_proto __rcu  *filter_list;
0048     struct tcf_block    *block;
0049     struct atm_vcc      *vcc;   /* VCC; NULL if VCC is closed */
0050     void            (*old_pop)(struct atm_vcc *vcc,
0051                        struct sk_buff *skb); /* chaining */
0052     struct atm_qdisc_data   *parent;    /* parent qdisc */
0053     struct socket       *sock;      /* for closing */
0054     int         ref;        /* reference count */
0055     struct gnet_stats_basic_sync    bstats;
0056     struct gnet_stats_queue qstats;
0057     struct list_head    list;
0058     struct atm_flow_data    *excess;    /* flow for excess traffic;
0059                            NULL to set CLP instead */
0060     int         hdr_len;
0061     unsigned char       hdr[];      /* header data; MUST BE LAST */
0062 };
0063 
0064 struct atm_qdisc_data {
0065     struct atm_flow_data    link;       /* unclassified skbs go here */
0066     struct list_head    flows;      /* NB: "link" is also on this
0067                            list */
0068     struct tasklet_struct   task;       /* dequeue tasklet */
0069 };
0070 
0071 /* ------------------------- Class/flow operations ------------------------- */
0072 
0073 static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid)
0074 {
0075     struct atm_qdisc_data *p = qdisc_priv(sch);
0076     struct atm_flow_data *flow;
0077 
0078     list_for_each_entry(flow, &p->flows, list) {
0079         if (flow->common.classid == classid)
0080             return flow;
0081     }
0082     return NULL;
0083 }
0084 
0085 static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
0086             struct Qdisc *new, struct Qdisc **old,
0087             struct netlink_ext_ack *extack)
0088 {
0089     struct atm_qdisc_data *p = qdisc_priv(sch);
0090     struct atm_flow_data *flow = (struct atm_flow_data *)arg;
0091 
0092     pr_debug("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
0093         sch, p, flow, new, old);
0094     if (list_empty(&flow->list))
0095         return -EINVAL;
0096     if (!new)
0097         new = &noop_qdisc;
0098     *old = flow->q;
0099     flow->q = new;
0100     if (*old)
0101         qdisc_reset(*old);
0102     return 0;
0103 }
0104 
0105 static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl)
0106 {
0107     struct atm_flow_data *flow = (struct atm_flow_data *)cl;
0108 
0109     pr_debug("atm_tc_leaf(sch %p,flow %p)\n", sch, flow);
0110     return flow ? flow->q : NULL;
0111 }
0112 
0113 static unsigned long atm_tc_find(struct Qdisc *sch, u32 classid)
0114 {
0115     struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
0116     struct atm_flow_data *flow;
0117 
0118     pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, p, classid);
0119     flow = lookup_flow(sch, classid);
0120     pr_debug("%s: flow %p\n", __func__, flow);
0121     return (unsigned long)flow;
0122 }
0123 
0124 static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
0125                     unsigned long parent, u32 classid)
0126 {
0127     struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
0128     struct atm_flow_data *flow;
0129 
0130     pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, p, classid);
0131     flow = lookup_flow(sch, classid);
0132     if (flow)
0133         flow->ref++;
0134     pr_debug("%s: flow %p\n", __func__, flow);
0135     return (unsigned long)flow;
0136 }
0137 
0138 /*
0139  * atm_tc_put handles all destructions, including the ones that are explicitly
0140  * requested (atm_tc_destroy, etc.). The assumption here is that we never drop
0141  * anything that still seems to be in use.
0142  */
0143 static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
0144 {
0145     struct atm_qdisc_data *p = qdisc_priv(sch);
0146     struct atm_flow_data *flow = (struct atm_flow_data *)cl;
0147 
0148     pr_debug("atm_tc_put(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
0149     if (--flow->ref)
0150         return;
0151     pr_debug("atm_tc_put: destroying\n");
0152     list_del_init(&flow->list);
0153     pr_debug("atm_tc_put: qdisc %p\n", flow->q);
0154     qdisc_put(flow->q);
0155     tcf_block_put(flow->block);
0156     if (flow->sock) {
0157         pr_debug("atm_tc_put: f_count %ld\n",
0158             file_count(flow->sock->file));
0159         flow->vcc->pop = flow->old_pop;
0160         sockfd_put(flow->sock);
0161     }
0162     if (flow->excess)
0163         atm_tc_put(sch, (unsigned long)flow->excess);
0164     if (flow != &p->link)
0165         kfree(flow);
0166     /*
0167      * If flow == &p->link, the qdisc no longer works at this point and
0168      * needs to be removed. (By the caller of atm_tc_put.)
0169      */
0170 }
0171 
0172 static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
0173 {
0174     struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
0175 
0176     pr_debug("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n", vcc, skb, p);
0177     VCC2FLOW(vcc)->old_pop(vcc, skb);
0178     tasklet_schedule(&p->task);
0179 }
0180 
0181 static const u8 llc_oui_ip[] = {
0182     0xaa,           /* DSAP: non-ISO */
0183     0xaa,           /* SSAP: non-ISO */
0184     0x03,           /* Ctrl: Unnumbered Information Command PDU */
0185     0x00,           /* OUI: EtherType */
0186     0x00, 0x00,
0187     0x08, 0x00
0188 };              /* Ethertype IP (0800) */
0189 
0190 static const struct nla_policy atm_policy[TCA_ATM_MAX + 1] = {
0191     [TCA_ATM_FD]        = { .type = NLA_U32 },
0192     [TCA_ATM_EXCESS]    = { .type = NLA_U32 },
0193 };
0194 
0195 static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
0196              struct nlattr **tca, unsigned long *arg,
0197              struct netlink_ext_ack *extack)
0198 {
0199     struct atm_qdisc_data *p = qdisc_priv(sch);
0200     struct atm_flow_data *flow = (struct atm_flow_data *)*arg;
0201     struct atm_flow_data *excess = NULL;
0202     struct nlattr *opt = tca[TCA_OPTIONS];
0203     struct nlattr *tb[TCA_ATM_MAX + 1];
0204     struct socket *sock;
0205     int fd, error, hdr_len;
0206     void *hdr;
0207 
0208     pr_debug("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
0209         "flow %p,opt %p)\n", sch, p, classid, parent, flow, opt);
0210     /*
0211      * The concept of parents doesn't apply for this qdisc.
0212      */
0213     if (parent && parent != TC_H_ROOT && parent != sch->handle)
0214         return -EINVAL;
0215     /*
0216      * ATM classes cannot be changed. In order to change properties of the
0217      * ATM connection, that socket needs to be modified directly (via the
0218      * native ATM API. In order to send a flow to a different VC, the old
0219      * class needs to be removed and a new one added. (This may be changed
0220      * later.)
0221      */
0222     if (flow)
0223         return -EBUSY;
0224     if (opt == NULL)
0225         return -EINVAL;
0226 
0227     error = nla_parse_nested_deprecated(tb, TCA_ATM_MAX, opt, atm_policy,
0228                         NULL);
0229     if (error < 0)
0230         return error;
0231 
0232     if (!tb[TCA_ATM_FD])
0233         return -EINVAL;
0234     fd = nla_get_u32(tb[TCA_ATM_FD]);
0235     pr_debug("atm_tc_change: fd %d\n", fd);
0236     if (tb[TCA_ATM_HDR]) {
0237         hdr_len = nla_len(tb[TCA_ATM_HDR]);
0238         hdr = nla_data(tb[TCA_ATM_HDR]);
0239     } else {
0240         hdr_len = RFC1483LLC_LEN;
0241         hdr = NULL; /* default LLC/SNAP for IP */
0242     }
0243     if (!tb[TCA_ATM_EXCESS])
0244         excess = NULL;
0245     else {
0246         excess = (struct atm_flow_data *)
0247             atm_tc_find(sch, nla_get_u32(tb[TCA_ATM_EXCESS]));
0248         if (!excess)
0249             return -ENOENT;
0250     }
0251     pr_debug("atm_tc_change: type %d, payload %d, hdr_len %d\n",
0252          opt->nla_type, nla_len(opt), hdr_len);
0253     sock = sockfd_lookup(fd, &error);
0254     if (!sock)
0255         return error;   /* f_count++ */
0256     pr_debug("atm_tc_change: f_count %ld\n", file_count(sock->file));
0257     if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
0258         error = -EPROTOTYPE;
0259         goto err_out;
0260     }
0261     /* @@@ should check if the socket is really operational or we'll crash
0262        on vcc->send */
0263     if (classid) {
0264         if (TC_H_MAJ(classid ^ sch->handle)) {
0265             pr_debug("atm_tc_change: classid mismatch\n");
0266             error = -EINVAL;
0267             goto err_out;
0268         }
0269     } else {
0270         int i;
0271         unsigned long cl;
0272 
0273         for (i = 1; i < 0x8000; i++) {
0274             classid = TC_H_MAKE(sch->handle, 0x8000 | i);
0275             cl = atm_tc_find(sch, classid);
0276             if (!cl)
0277                 break;
0278         }
0279     }
0280     pr_debug("atm_tc_change: new id %x\n", classid);
0281     flow = kzalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL);
0282     pr_debug("atm_tc_change: flow %p\n", flow);
0283     if (!flow) {
0284         error = -ENOBUFS;
0285         goto err_out;
0286     }
0287 
0288     error = tcf_block_get(&flow->block, &flow->filter_list, sch,
0289                   extack);
0290     if (error) {
0291         kfree(flow);
0292         goto err_out;
0293     }
0294 
0295     flow->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, classid,
0296                     extack);
0297     if (!flow->q)
0298         flow->q = &noop_qdisc;
0299     pr_debug("atm_tc_change: qdisc %p\n", flow->q);
0300     flow->sock = sock;
0301     flow->vcc = ATM_SD(sock);   /* speedup */
0302     flow->vcc->user_back = flow;
0303     pr_debug("atm_tc_change: vcc %p\n", flow->vcc);
0304     flow->old_pop = flow->vcc->pop;
0305     flow->parent = p;
0306     flow->vcc->pop = sch_atm_pop;
0307     flow->common.classid = classid;
0308     flow->ref = 1;
0309     flow->excess = excess;
0310     list_add(&flow->list, &p->link.list);
0311     flow->hdr_len = hdr_len;
0312     if (hdr)
0313         memcpy(flow->hdr, hdr, hdr_len);
0314     else
0315         memcpy(flow->hdr, llc_oui_ip, sizeof(llc_oui_ip));
0316     *arg = (unsigned long)flow;
0317     return 0;
0318 err_out:
0319     sockfd_put(sock);
0320     return error;
0321 }
0322 
0323 static int atm_tc_delete(struct Qdisc *sch, unsigned long arg,
0324              struct netlink_ext_ack *extack)
0325 {
0326     struct atm_qdisc_data *p = qdisc_priv(sch);
0327     struct atm_flow_data *flow = (struct atm_flow_data *)arg;
0328 
0329     pr_debug("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
0330     if (list_empty(&flow->list))
0331         return -EINVAL;
0332     if (rcu_access_pointer(flow->filter_list) || flow == &p->link)
0333         return -EBUSY;
0334     /*
0335      * Reference count must be 2: one for "keepalive" (set at class
0336      * creation), and one for the reference held when calling delete.
0337      */
0338     if (flow->ref < 2) {
0339         pr_err("atm_tc_delete: flow->ref == %d\n", flow->ref);
0340         return -EINVAL;
0341     }
0342     if (flow->ref > 2)
0343         return -EBUSY;  /* catch references via excess, etc. */
0344     atm_tc_put(sch, arg);
0345     return 0;
0346 }
0347 
0348 static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
0349 {
0350     struct atm_qdisc_data *p = qdisc_priv(sch);
0351     struct atm_flow_data *flow;
0352 
0353     pr_debug("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
0354     if (walker->stop)
0355         return;
0356     list_for_each_entry(flow, &p->flows, list) {
0357         if (walker->count >= walker->skip &&
0358             walker->fn(sch, (unsigned long)flow, walker) < 0) {
0359             walker->stop = 1;
0360             break;
0361         }
0362         walker->count++;
0363     }
0364 }
0365 
0366 static struct tcf_block *atm_tc_tcf_block(struct Qdisc *sch, unsigned long cl,
0367                       struct netlink_ext_ack *extack)
0368 {
0369     struct atm_qdisc_data *p = qdisc_priv(sch);
0370     struct atm_flow_data *flow = (struct atm_flow_data *)cl;
0371 
0372     pr_debug("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
0373     return flow ? flow->block : p->link.block;
0374 }
0375 
0376 /* --------------------------- Qdisc operations ---------------------------- */
0377 
0378 static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
0379               struct sk_buff **to_free)
0380 {
0381     struct atm_qdisc_data *p = qdisc_priv(sch);
0382     struct atm_flow_data *flow;
0383     struct tcf_result res;
0384     int result;
0385     int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
0386 
0387     pr_debug("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
0388     result = TC_ACT_OK; /* be nice to gcc */
0389     flow = NULL;
0390     if (TC_H_MAJ(skb->priority) != sch->handle ||
0391         !(flow = (struct atm_flow_data *)atm_tc_find(sch, skb->priority))) {
0392         struct tcf_proto *fl;
0393 
0394         list_for_each_entry(flow, &p->flows, list) {
0395             fl = rcu_dereference_bh(flow->filter_list);
0396             if (fl) {
0397                 result = tcf_classify(skb, NULL, fl, &res, true);
0398                 if (result < 0)
0399                     continue;
0400                 flow = (struct atm_flow_data *)res.class;
0401                 if (!flow)
0402                     flow = lookup_flow(sch, res.classid);
0403                 goto done;
0404             }
0405         }
0406         flow = NULL;
0407 done:
0408         ;
0409     }
0410     if (!flow) {
0411         flow = &p->link;
0412     } else {
0413         if (flow->vcc)
0414             ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
0415         /*@@@ looks good ... but it's not supposed to work :-) */
0416 #ifdef CONFIG_NET_CLS_ACT
0417         switch (result) {
0418         case TC_ACT_QUEUED:
0419         case TC_ACT_STOLEN:
0420         case TC_ACT_TRAP:
0421             __qdisc_drop(skb, to_free);
0422             return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
0423         case TC_ACT_SHOT:
0424             __qdisc_drop(skb, to_free);
0425             goto drop;
0426         case TC_ACT_RECLASSIFY:
0427             if (flow->excess)
0428                 flow = flow->excess;
0429             else
0430                 ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP;
0431             break;
0432         }
0433 #endif
0434     }
0435 
0436     ret = qdisc_enqueue(skb, flow->q, to_free);
0437     if (ret != NET_XMIT_SUCCESS) {
0438 drop: __maybe_unused
0439         if (net_xmit_drop_count(ret)) {
0440             qdisc_qstats_drop(sch);
0441             if (flow)
0442                 flow->qstats.drops++;
0443         }
0444         return ret;
0445     }
0446     /*
0447      * Okay, this may seem weird. We pretend we've dropped the packet if
0448      * it goes via ATM. The reason for this is that the outer qdisc
0449      * expects to be able to q->dequeue the packet later on if we return
0450      * success at this place. Also, sch->q.qdisc needs to reflect whether
0451      * there is a packet egligible for dequeuing or not. Note that the
0452      * statistics of the outer qdisc are necessarily wrong because of all
0453      * this. There's currently no correct solution for this.
0454      */
0455     if (flow == &p->link) {
0456         sch->q.qlen++;
0457         return NET_XMIT_SUCCESS;
0458     }
0459     tasklet_schedule(&p->task);
0460     return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
0461 }
0462 
0463 /*
0464  * Dequeue packets and send them over ATM. Note that we quite deliberately
0465  * avoid checking net_device's flow control here, simply because sch_atm
0466  * uses its own channels, which have nothing to do with any CLIP/LANE/or
0467  * non-ATM interfaces.
0468  */
0469 
0470 static void sch_atm_dequeue(struct tasklet_struct *t)
0471 {
0472     struct atm_qdisc_data *p = from_tasklet(p, t, task);
0473     struct Qdisc *sch = qdisc_from_priv(p);
0474     struct atm_flow_data *flow;
0475     struct sk_buff *skb;
0476 
0477     pr_debug("sch_atm_dequeue(sch %p,[qdisc %p])\n", sch, p);
0478     list_for_each_entry(flow, &p->flows, list) {
0479         if (flow == &p->link)
0480             continue;
0481         /*
0482          * If traffic is properly shaped, this won't generate nasty
0483          * little bursts. Otherwise, it may ... (but that's okay)
0484          */
0485         while ((skb = flow->q->ops->peek(flow->q))) {
0486             if (!atm_may_send(flow->vcc, skb->truesize))
0487                 break;
0488 
0489             skb = qdisc_dequeue_peeked(flow->q);
0490             if (unlikely(!skb))
0491                 break;
0492 
0493             qdisc_bstats_update(sch, skb);
0494             bstats_update(&flow->bstats, skb);
0495             pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
0496             /* remove any LL header somebody else has attached */
0497             skb_pull(skb, skb_network_offset(skb));
0498             if (skb_headroom(skb) < flow->hdr_len) {
0499                 struct sk_buff *new;
0500 
0501                 new = skb_realloc_headroom(skb, flow->hdr_len);
0502                 dev_kfree_skb(skb);
0503                 if (!new)
0504                     continue;
0505                 skb = new;
0506             }
0507             pr_debug("sch_atm_dequeue: ip %p, data %p\n",
0508                  skb_network_header(skb), skb->data);
0509             ATM_SKB(skb)->vcc = flow->vcc;
0510             memcpy(skb_push(skb, flow->hdr_len), flow->hdr,
0511                    flow->hdr_len);
0512             refcount_add(skb->truesize,
0513                    &sk_atm(flow->vcc)->sk_wmem_alloc);
0514             /* atm.atm_options are already set by atm_tc_enqueue */
0515             flow->vcc->send(flow->vcc, skb);
0516         }
0517     }
0518 }
0519 
0520 static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
0521 {
0522     struct atm_qdisc_data *p = qdisc_priv(sch);
0523     struct sk_buff *skb;
0524 
0525     pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
0526     tasklet_schedule(&p->task);
0527     skb = qdisc_dequeue_peeked(p->link.q);
0528     if (skb)
0529         sch->q.qlen--;
0530     return skb;
0531 }
0532 
0533 static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
0534 {
0535     struct atm_qdisc_data *p = qdisc_priv(sch);
0536 
0537     pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
0538 
0539     return p->link.q->ops->peek(p->link.q);
0540 }
0541 
0542 static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt,
0543                struct netlink_ext_ack *extack)
0544 {
0545     struct atm_qdisc_data *p = qdisc_priv(sch);
0546     int err;
0547 
0548     pr_debug("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
0549     INIT_LIST_HEAD(&p->flows);
0550     INIT_LIST_HEAD(&p->link.list);
0551     gnet_stats_basic_sync_init(&p->link.bstats);
0552     list_add(&p->link.list, &p->flows);
0553     p->link.q = qdisc_create_dflt(sch->dev_queue,
0554                       &pfifo_qdisc_ops, sch->handle, extack);
0555     if (!p->link.q)
0556         p->link.q = &noop_qdisc;
0557     pr_debug("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
0558     p->link.vcc = NULL;
0559     p->link.sock = NULL;
0560     p->link.common.classid = sch->handle;
0561     p->link.ref = 1;
0562 
0563     err = tcf_block_get(&p->link.block, &p->link.filter_list, sch,
0564                 extack);
0565     if (err)
0566         return err;
0567 
0568     tasklet_setup(&p->task, sch_atm_dequeue);
0569     return 0;
0570 }
0571 
0572 static void atm_tc_reset(struct Qdisc *sch)
0573 {
0574     struct atm_qdisc_data *p = qdisc_priv(sch);
0575     struct atm_flow_data *flow;
0576 
0577     pr_debug("atm_tc_reset(sch %p,[qdisc %p])\n", sch, p);
0578     list_for_each_entry(flow, &p->flows, list)
0579         qdisc_reset(flow->q);
0580     sch->q.qlen = 0;
0581 }
0582 
0583 static void atm_tc_destroy(struct Qdisc *sch)
0584 {
0585     struct atm_qdisc_data *p = qdisc_priv(sch);
0586     struct atm_flow_data *flow, *tmp;
0587 
0588     pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
0589     list_for_each_entry(flow, &p->flows, list) {
0590         tcf_block_put(flow->block);
0591         flow->block = NULL;
0592     }
0593 
0594     list_for_each_entry_safe(flow, tmp, &p->flows, list) {
0595         if (flow->ref > 1)
0596             pr_err("atm_destroy: %p->ref = %d\n", flow, flow->ref);
0597         atm_tc_put(sch, (unsigned long)flow);
0598     }
0599     tasklet_kill(&p->task);
0600 }
0601 
0602 static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
0603                  struct sk_buff *skb, struct tcmsg *tcm)
0604 {
0605     struct atm_qdisc_data *p = qdisc_priv(sch);
0606     struct atm_flow_data *flow = (struct atm_flow_data *)cl;
0607     struct nlattr *nest;
0608 
0609     pr_debug("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
0610         sch, p, flow, skb, tcm);
0611     if (list_empty(&flow->list))
0612         return -EINVAL;
0613     tcm->tcm_handle = flow->common.classid;
0614     tcm->tcm_info = flow->q->handle;
0615 
0616     nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
0617     if (nest == NULL)
0618         goto nla_put_failure;
0619 
0620     if (nla_put(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr))
0621         goto nla_put_failure;
0622     if (flow->vcc) {
0623         struct sockaddr_atmpvc pvc;
0624         int state;
0625 
0626         memset(&pvc, 0, sizeof(pvc));
0627         pvc.sap_family = AF_ATMPVC;
0628         pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
0629         pvc.sap_addr.vpi = flow->vcc->vpi;
0630         pvc.sap_addr.vci = flow->vcc->vci;
0631         if (nla_put(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc))
0632             goto nla_put_failure;
0633         state = ATM_VF2VS(flow->vcc->flags);
0634         if (nla_put_u32(skb, TCA_ATM_STATE, state))
0635             goto nla_put_failure;
0636     }
0637     if (flow->excess) {
0638         if (nla_put_u32(skb, TCA_ATM_EXCESS, flow->common.classid))
0639             goto nla_put_failure;
0640     } else {
0641         if (nla_put_u32(skb, TCA_ATM_EXCESS, 0))
0642             goto nla_put_failure;
0643     }
0644     return nla_nest_end(skb, nest);
0645 
0646 nla_put_failure:
0647     nla_nest_cancel(skb, nest);
0648     return -1;
0649 }
0650 static int
0651 atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
0652             struct gnet_dump *d)
0653 {
0654     struct atm_flow_data *flow = (struct atm_flow_data *)arg;
0655 
0656     if (gnet_stats_copy_basic(d, NULL, &flow->bstats, true) < 0 ||
0657         gnet_stats_copy_queue(d, NULL, &flow->qstats, flow->q->q.qlen) < 0)
0658         return -1;
0659 
0660     return 0;
0661 }
0662 
0663 static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
0664 {
0665     return 0;
0666 }
0667 
0668 static const struct Qdisc_class_ops atm_class_ops = {
0669     .graft      = atm_tc_graft,
0670     .leaf       = atm_tc_leaf,
0671     .find       = atm_tc_find,
0672     .change     = atm_tc_change,
0673     .delete     = atm_tc_delete,
0674     .walk       = atm_tc_walk,
0675     .tcf_block  = atm_tc_tcf_block,
0676     .bind_tcf   = atm_tc_bind_filter,
0677     .unbind_tcf = atm_tc_put,
0678     .dump       = atm_tc_dump_class,
0679     .dump_stats = atm_tc_dump_class_stats,
0680 };
0681 
0682 static struct Qdisc_ops atm_qdisc_ops __read_mostly = {
0683     .cl_ops     = &atm_class_ops,
0684     .id     = "atm",
0685     .priv_size  = sizeof(struct atm_qdisc_data),
0686     .enqueue    = atm_tc_enqueue,
0687     .dequeue    = atm_tc_dequeue,
0688     .peek       = atm_tc_peek,
0689     .init       = atm_tc_init,
0690     .reset      = atm_tc_reset,
0691     .destroy    = atm_tc_destroy,
0692     .dump       = atm_tc_dump,
0693     .owner      = THIS_MODULE,
0694 };
0695 
0696 static int __init atm_init(void)
0697 {
0698     return register_qdisc(&atm_qdisc_ops);
0699 }
0700 
0701 static void __exit atm_exit(void)
0702 {
0703     unregister_qdisc(&atm_qdisc_ops);
0704 }
0705 
0706 module_init(atm_init)
0707 module_exit(atm_exit)
0708 MODULE_LICENSE("GPL");