Commit b0188d4d authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[NET_SCHED]: sch_atm: Lindent

Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f13ec93f
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* Written 1998-2000 by Werner Almesberger, EPFL ICA */ /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/string.h> #include <linux/string.h>
...@@ -11,12 +10,11 @@ ...@@ -11,12 +10,11 @@
#include <linux/atmdev.h> #include <linux/atmdev.h>
#include <linux/atmclip.h> #include <linux/atmclip.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/file.h> /* for fput */ #include <linux/file.h> /* for fput */
#include <net/netlink.h> #include <net/netlink.h>
#include <net/pkt_sched.h> #include <net/pkt_sched.h>
extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
#if 0 /* control */ #if 0 /* control */
#define DPRINTK(format,args...) printk(KERN_DEBUG format,##args) #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
...@@ -30,7 +28,6 @@ extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */ ...@@ -30,7 +28,6 @@ extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
#define D2PRINTK(format,args...) #define D2PRINTK(format,args...)
#endif #endif
/* /*
* The ATM queuing discipline provides a framework for invoking classifiers * The ATM queuing discipline provides a framework for invoking classifiers
* (aka "filters"), which in turn select classes of this queuing discipline. * (aka "filters"), which in turn select classes of this queuing discipline.
...@@ -52,16 +49,15 @@ extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */ ...@@ -52,16 +49,15 @@ extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
* - should lock the flow while there is data in the queue (?) * - should lock the flow while there is data in the queue (?)
*/ */
#define PRIV(sch) qdisc_priv(sch) #define PRIV(sch) qdisc_priv(sch)
#define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back)) #define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
struct atm_flow_data { struct atm_flow_data {
struct Qdisc *q; /* FIFO, TBF, etc. */ struct Qdisc *q; /* FIFO, TBF, etc. */
struct tcf_proto *filter_list; struct tcf_proto *filter_list;
struct atm_vcc *vcc; /* VCC; NULL if VCC is closed */ struct atm_vcc *vcc; /* VCC; NULL if VCC is closed */
void (*old_pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* chaining */ void (*old_pop)(struct atm_vcc *vcc,
struct sk_buff * skb); /* chaining */
struct atm_qdisc_data *parent; /* parent qdisc */ struct atm_qdisc_data *parent; /* parent qdisc */
struct socket *sock; /* for closing */ struct socket *sock; /* for closing */
u32 classid; /* x:y type ID */ u32 classid; /* x:y type ID */
...@@ -82,76 +78,74 @@ struct atm_qdisc_data { ...@@ -82,76 +78,74 @@ struct atm_qdisc_data {
struct tasklet_struct task; /* requeue tasklet */ struct tasklet_struct task; /* requeue tasklet */
}; };
/* ------------------------- Class/flow operations ------------------------- */ /* ------------------------- Class/flow operations ------------------------- */
static int find_flow(struct atm_qdisc_data *qdisc, struct atm_flow_data *flow)
static int find_flow(struct atm_qdisc_data *qdisc,struct atm_flow_data *flow)
{ {
struct atm_flow_data *walk; struct atm_flow_data *walk;
DPRINTK("find_flow(qdisc %p,flow %p)\n",qdisc,flow); DPRINTK("find_flow(qdisc %p,flow %p)\n", qdisc, flow);
for (walk = qdisc->flows; walk; walk = walk->next) for (walk = qdisc->flows; walk; walk = walk->next)
if (walk == flow) return 1; if (walk == flow)
return 1;
DPRINTK("find_flow: not found\n"); DPRINTK("find_flow: not found\n");
return 0; return 0;
} }
static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid)
static __inline__ struct atm_flow_data *lookup_flow(struct Qdisc *sch,
u32 classid)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
for (flow = p->flows; flow; flow = flow->next) for (flow = p->flows; flow; flow = flow->next)
if (flow->classid == classid) break; if (flow->classid == classid)
break;
return flow; return flow;
} }
static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
static int atm_tc_graft(struct Qdisc *sch,unsigned long arg, struct Qdisc *new, struct Qdisc **old)
struct Qdisc *new,struct Qdisc **old)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = (struct atm_flow_data *) arg; struct atm_flow_data *flow = (struct atm_flow_data *)arg;
DPRINTK("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",sch, DPRINTK("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
p,flow,new,old); sch, p, flow, new, old);
if (!find_flow(p,flow)) return -EINVAL; if (!find_flow(p, flow))
if (!new) new = &noop_qdisc; return -EINVAL;
*old = xchg(&flow->q,new); if (!new)
if (*old) qdisc_reset(*old); new = &noop_qdisc;
*old = xchg(&flow->q, new);
if (*old)
qdisc_reset(*old);
return 0; return 0;
} }
static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl)
static struct Qdisc *atm_tc_leaf(struct Qdisc *sch,unsigned long cl)
{ {
struct atm_flow_data *flow = (struct atm_flow_data *) cl; struct atm_flow_data *flow = (struct atm_flow_data *)cl;
DPRINTK("atm_tc_leaf(sch %p,flow %p)\n",sch,flow); DPRINTK("atm_tc_leaf(sch %p,flow %p)\n", sch, flow);
return flow ? flow->q : NULL; return flow ? flow->q : NULL;
} }
static unsigned long atm_tc_get(struct Qdisc *sch, u32 classid)
static unsigned long atm_tc_get(struct Qdisc *sch,u32 classid)
{ {
struct atm_qdisc_data *p __attribute__((unused)) = PRIV(sch); struct atm_qdisc_data *p __maybe_unused = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
DPRINTK("atm_tc_get(sch %p,[qdisc %p],classid %x)\n",sch,p,classid); DPRINTK("atm_tc_get(sch %p,[qdisc %p],classid %x)\n", sch, p, classid);
flow = lookup_flow(sch,classid); flow = lookup_flow(sch, classid);
if (flow) flow->ref++; if (flow)
DPRINTK("atm_tc_get: flow %p\n",flow); flow->ref++;
return (unsigned long) flow; DPRINTK("atm_tc_get: flow %p\n", flow);
return (unsigned long)flow;
} }
static unsigned long atm_tc_bind_filter(struct Qdisc *sch, static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
unsigned long parent, u32 classid) unsigned long parent, u32 classid)
{ {
return atm_tc_get(sch,classid); return atm_tc_get(sch, classid);
} }
/* /*
...@@ -159,72 +153,75 @@ static unsigned long atm_tc_bind_filter(struct Qdisc *sch, ...@@ -159,72 +153,75 @@ static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
* requested (atm_tc_destroy, etc.). The assumption here is that we never drop * requested (atm_tc_destroy, etc.). The assumption here is that we never drop
* anything that still seems to be in use. * anything that still seems to be in use.
*/ */
static void atm_tc_put(struct Qdisc *sch, unsigned long cl) static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = (struct atm_flow_data *) cl; struct atm_flow_data *flow = (struct atm_flow_data *)cl;
struct atm_flow_data **prev; struct atm_flow_data **prev;
DPRINTK("atm_tc_put(sch %p,[qdisc %p],flow %p)\n",sch,p,flow); DPRINTK("atm_tc_put(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
if (--flow->ref) return; if (--flow->ref)
return;
DPRINTK("atm_tc_put: destroying\n"); DPRINTK("atm_tc_put: destroying\n");
for (prev = &p->flows; *prev; prev = &(*prev)->next) for (prev = &p->flows; *prev; prev = &(*prev)->next)
if (*prev == flow) break; if (*prev == flow)
break;
if (!*prev) { if (!*prev) {
printk(KERN_CRIT "atm_tc_put: class %p not found\n",flow); printk(KERN_CRIT "atm_tc_put: class %p not found\n", flow);
return; return;
} }
*prev = flow->next; *prev = flow->next;
DPRINTK("atm_tc_put: qdisc %p\n",flow->q); DPRINTK("atm_tc_put: qdisc %p\n", flow->q);
qdisc_destroy(flow->q); qdisc_destroy(flow->q);
tcf_destroy_chain(flow->filter_list); tcf_destroy_chain(flow->filter_list);
if (flow->sock) { if (flow->sock) {
DPRINTK("atm_tc_put: f_count %d\n", DPRINTK("atm_tc_put: f_count %d\n",
file_count(flow->sock->file)); file_count(flow->sock->file));
flow->vcc->pop = flow->old_pop; flow->vcc->pop = flow->old_pop;
sockfd_put(flow->sock); sockfd_put(flow->sock);
} }
if (flow->excess) atm_tc_put(sch,(unsigned long) flow->excess); if (flow->excess)
if (flow != &p->link) kfree(flow); atm_tc_put(sch, (unsigned long)flow->excess);
if (flow != &p->link)
kfree(flow);
/* /*
* If flow == &p->link, the qdisc no longer works at this point and * If flow == &p->link, the qdisc no longer works at this point and
* needs to be removed. (By the caller of atm_tc_put.) * needs to be removed. (By the caller of atm_tc_put.)
*/ */
} }
static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
static void sch_atm_pop(struct atm_vcc *vcc,struct sk_buff *skb)
{ {
struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent; struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
D2PRINTK("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n",vcc,skb,p); D2PRINTK("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n", vcc, skb, p);
VCC2FLOW(vcc)->old_pop(vcc,skb); VCC2FLOW(vcc)->old_pop(vcc, skb);
tasklet_schedule(&p->task); tasklet_schedule(&p->task);
} }
static const u8 llc_oui_ip[] = { static const u8 llc_oui_ip[] = {
0xaa, /* DSAP: non-ISO */ 0xaa, /* DSAP: non-ISO */
0xaa, /* SSAP: non-ISO */ 0xaa, /* SSAP: non-ISO */
0x03, /* Ctrl: Unnumbered Information Command PDU */ 0x03, /* Ctrl: Unnumbered Information Command PDU */
0x00, /* OUI: EtherType */ 0x00, /* OUI: EtherType */
0x00, 0x00, 0x00, 0x00,
0x08, 0x00 }; /* Ethertype IP (0800) */ 0x08, 0x00
}; /* Ethertype IP (0800) */
static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
struct rtattr **tca, unsigned long *arg) struct rtattr **tca, unsigned long *arg)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = (struct atm_flow_data *) *arg; struct atm_flow_data *flow = (struct atm_flow_data *)*arg;
struct atm_flow_data *excess = NULL; struct atm_flow_data *excess = NULL;
struct rtattr *opt = tca[TCA_OPTIONS-1]; struct rtattr *opt = tca[TCA_OPTIONS - 1];
struct rtattr *tb[TCA_ATM_MAX]; struct rtattr *tb[TCA_ATM_MAX];
struct socket *sock; struct socket *sock;
int fd,error,hdr_len; int fd, error, hdr_len;
void *hdr; void *hdr;
DPRINTK("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x," DPRINTK("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
"flow %p,opt %p)\n",sch,p,classid,parent,flow,opt); "flow %p,opt %p)\n", sch, p, classid, parent, flow, opt);
/* /*
* The concept of parents doesn't apply for this qdisc. * The concept of parents doesn't apply for this qdisc.
*/ */
...@@ -237,33 +234,36 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, ...@@ -237,33 +234,36 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
* class needs to be removed and a new one added. (This may be changed * class needs to be removed and a new one added. (This may be changed
* later.) * later.)
*/ */
if (flow) return -EBUSY; if (flow)
return -EBUSY;
if (opt == NULL || rtattr_parse_nested(tb, TCA_ATM_MAX, opt)) if (opt == NULL || rtattr_parse_nested(tb, TCA_ATM_MAX, opt))
return -EINVAL; return -EINVAL;
if (!tb[TCA_ATM_FD-1] || RTA_PAYLOAD(tb[TCA_ATM_FD-1]) < sizeof(fd)) if (!tb[TCA_ATM_FD - 1] || RTA_PAYLOAD(tb[TCA_ATM_FD - 1]) < sizeof(fd))
return -EINVAL; return -EINVAL;
fd = *(int *) RTA_DATA(tb[TCA_ATM_FD-1]); fd = *(int *)RTA_DATA(tb[TCA_ATM_FD - 1]);
DPRINTK("atm_tc_change: fd %d\n",fd); DPRINTK("atm_tc_change: fd %d\n", fd);
if (tb[TCA_ATM_HDR-1]) { if (tb[TCA_ATM_HDR - 1]) {
hdr_len = RTA_PAYLOAD(tb[TCA_ATM_HDR-1]); hdr_len = RTA_PAYLOAD(tb[TCA_ATM_HDR - 1]);
hdr = RTA_DATA(tb[TCA_ATM_HDR-1]); hdr = RTA_DATA(tb[TCA_ATM_HDR - 1]);
} } else {
else {
hdr_len = RFC1483LLC_LEN; hdr_len = RFC1483LLC_LEN;
hdr = NULL; /* default LLC/SNAP for IP */ hdr = NULL; /* default LLC/SNAP for IP */
} }
if (!tb[TCA_ATM_EXCESS-1]) excess = NULL; if (!tb[TCA_ATM_EXCESS - 1])
excess = NULL;
else { else {
if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS-1]) != sizeof(u32)) if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS - 1]) != sizeof(u32))
return -EINVAL; return -EINVAL;
excess = (struct atm_flow_data *) atm_tc_get(sch, excess = (struct atm_flow_data *)
*(u32 *) RTA_DATA(tb[TCA_ATM_EXCESS-1])); atm_tc_get(sch, *(u32 *)RTA_DATA(tb[TCA_ATM_EXCESS - 1]));
if (!excess) return -ENOENT; if (!excess)
return -ENOENT;
} }
DPRINTK("atm_tc_change: type %d, payload %d, hdr_len %d\n", DPRINTK("atm_tc_change: type %d, payload %d, hdr_len %d\n",
opt->rta_type,RTA_PAYLOAD(opt),hdr_len); opt->rta_type, RTA_PAYLOAD(opt), hdr_len);
if (!(sock = sockfd_lookup(fd,&error))) return error; /* f_count++ */ if (!(sock = sockfd_lookup(fd, &error)))
DPRINTK("atm_tc_change: f_count %d\n",file_count(sock->file)); return error; /* f_count++ */
DPRINTK("atm_tc_change: f_count %d\n", file_count(sock->file));
if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) { if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
error = -EPROTOTYPE; error = -EPROTOTYPE;
goto err_out; goto err_out;
...@@ -276,37 +276,37 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, ...@@ -276,37 +276,37 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
error = -EINVAL; error = -EINVAL;
goto err_out; goto err_out;
} }
if (find_flow(p,flow)) { if (find_flow(p, flow)) {
error = -EEXIST; error = -EEXIST;
goto err_out; goto err_out;
} }
} } else {
else {
int i; int i;
unsigned long cl; unsigned long cl;
for (i = 1; i < 0x8000; i++) { for (i = 1; i < 0x8000; i++) {
classid = TC_H_MAKE(sch->handle,0x8000 | i); classid = TC_H_MAKE(sch->handle, 0x8000 | i);
if (!(cl = atm_tc_get(sch,classid))) break; if (!(cl = atm_tc_get(sch, classid)))
atm_tc_put(sch,cl); break;
atm_tc_put(sch, cl);
} }
} }
DPRINTK("atm_tc_change: new id %x\n",classid); DPRINTK("atm_tc_change: new id %x\n", classid);
flow = kmalloc(sizeof(struct atm_flow_data)+hdr_len,GFP_KERNEL); flow = kmalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL);
DPRINTK("atm_tc_change: flow %p\n",flow); DPRINTK("atm_tc_change: flow %p\n", flow);
if (!flow) { if (!flow) {
error = -ENOBUFS; error = -ENOBUFS;
goto err_out; goto err_out;
} }
memset(flow,0,sizeof(*flow)); memset(flow, 0, sizeof(*flow));
flow->filter_list = NULL; flow->filter_list = NULL;
if (!(flow->q = qdisc_create_dflt(sch->dev,&pfifo_qdisc_ops,classid))) if (!(flow->q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid)))
flow->q = &noop_qdisc; flow->q = &noop_qdisc;
DPRINTK("atm_tc_change: qdisc %p\n",flow->q); DPRINTK("atm_tc_change: qdisc %p\n", flow->q);
flow->sock = sock; flow->sock = sock;
flow->vcc = ATM_SD(sock); /* speedup */ flow->vcc = ATM_SD(sock); /* speedup */
flow->vcc->user_back = flow; flow->vcc->user_back = flow;
DPRINTK("atm_tc_change: vcc %p\n",flow->vcc); DPRINTK("atm_tc_change: vcc %p\n", flow->vcc);
flow->old_pop = flow->vcc->pop; flow->old_pop = flow->vcc->pop;
flow->parent = p; flow->parent = p;
flow->vcc->pop = sch_atm_pop; flow->vcc->pop = sch_atm_pop;
...@@ -317,50 +317,53 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, ...@@ -317,50 +317,53 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
p->link.next = flow; p->link.next = flow;
flow->hdr_len = hdr_len; flow->hdr_len = hdr_len;
if (hdr) if (hdr)
memcpy(flow->hdr,hdr,hdr_len); memcpy(flow->hdr, hdr, hdr_len);
else else
memcpy(flow->hdr,llc_oui_ip,sizeof(llc_oui_ip)); memcpy(flow->hdr, llc_oui_ip, sizeof(llc_oui_ip));
*arg = (unsigned long) flow; *arg = (unsigned long)flow;
return 0; return 0;
err_out: err_out:
if (excess) atm_tc_put(sch,(unsigned long) excess); if (excess)
atm_tc_put(sch, (unsigned long)excess);
sockfd_put(sock); sockfd_put(sock);
return error; return error;
} }
static int atm_tc_delete(struct Qdisc *sch, unsigned long arg)
static int atm_tc_delete(struct Qdisc *sch,unsigned long arg)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = (struct atm_flow_data *) arg; struct atm_flow_data *flow = (struct atm_flow_data *)arg;
DPRINTK("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n",sch,p,flow); DPRINTK("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
if (!find_flow(PRIV(sch),flow)) return -EINVAL; if (!find_flow(PRIV(sch), flow))
if (flow->filter_list || flow == &p->link) return -EBUSY; return -EINVAL;
if (flow->filter_list || flow == &p->link)
return -EBUSY;
/* /*
* Reference count must be 2: one for "keepalive" (set at class * Reference count must be 2: one for "keepalive" (set at class
* creation), and one for the reference held when calling delete. * creation), and one for the reference held when calling delete.
*/ */
if (flow->ref < 2) { if (flow->ref < 2) {
printk(KERN_ERR "atm_tc_delete: flow->ref == %d\n",flow->ref); printk(KERN_ERR "atm_tc_delete: flow->ref == %d\n", flow->ref);
return -EINVAL; return -EINVAL;
} }
if (flow->ref > 2) return -EBUSY; /* catch references via excess, etc.*/ if (flow->ref > 2)
atm_tc_put(sch,arg); return -EBUSY; /* catch references via excess, etc. */
atm_tc_put(sch, arg);
return 0; return 0;
} }
static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
static void atm_tc_walk(struct Qdisc *sch,struct qdisc_walker *walker)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
DPRINTK("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n",sch,p,walker); DPRINTK("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
if (walker->stop) return; if (walker->stop)
return;
for (flow = p->flows; flow; flow = flow->next) { for (flow = p->flows; flow; flow = flow->next) {
if (walker->count >= walker->skip) if (walker->count >= walker->skip)
if (walker->fn(sch,(unsigned long) flow,walker) < 0) { if (walker->fn(sch, (unsigned long)flow, walker) < 0) {
walker->stop = 1; walker->stop = 1;
break; break;
} }
...@@ -368,73 +371,74 @@ static void atm_tc_walk(struct Qdisc *sch,struct qdisc_walker *walker) ...@@ -368,73 +371,74 @@ static void atm_tc_walk(struct Qdisc *sch,struct qdisc_walker *walker)
} }
} }
static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch, unsigned long cl)
static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch,unsigned long cl)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = (struct atm_flow_data *) cl; struct atm_flow_data *flow = (struct atm_flow_data *)cl;
DPRINTK("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n",sch,p,flow); DPRINTK("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
return flow ? &flow->filter_list : &p->link.filter_list; return flow ? &flow->filter_list : &p->link.filter_list;
} }
/* --------------------------- Qdisc operations ---------------------------- */ /* --------------------------- Qdisc operations ---------------------------- */
static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = NULL ; /* @@@ */ struct atm_flow_data *flow = NULL; /* @@@ */
struct tcf_result res; struct tcf_result res;
int result; int result;
int ret = NET_XMIT_POLICED; int ret = NET_XMIT_POLICED;
D2PRINTK("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p); D2PRINTK("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
result = TC_POLICE_OK; /* be nice to gcc */ result = TC_POLICE_OK; /* be nice to gcc */
if (TC_H_MAJ(skb->priority) != sch->handle || if (TC_H_MAJ(skb->priority) != sch->handle ||
!(flow = (struct atm_flow_data *) atm_tc_get(sch,skb->priority))) !(flow = (struct atm_flow_data *)atm_tc_get(sch, skb->priority)))
for (flow = p->flows; flow; flow = flow->next) for (flow = p->flows; flow; flow = flow->next)
if (flow->filter_list) { if (flow->filter_list) {
result = tc_classify(skb,flow->filter_list, result = tc_classify(skb, flow->filter_list,
&res); &res);
if (result < 0) continue; if (result < 0)
flow = (struct atm_flow_data *) res.class; continue;
if (!flow) flow = lookup_flow(sch,res.classid); flow = (struct atm_flow_data *)res.class;
if (!flow)
flow = lookup_flow(sch, res.classid);
break; break;
} }
if (!flow) flow = &p->link; if (!flow)
flow = &p->link;
else { else {
if (flow->vcc) if (flow->vcc)
ATM_SKB(skb)->atm_options = flow->vcc->atm_options; ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
/*@@@ looks good ... but it's not supposed to work :-)*/ /*@@@ looks good ... but it's not supposed to work :-) */
#ifdef CONFIG_NET_CLS_POLICE #ifdef CONFIG_NET_CLS_POLICE
switch (result) { switch (result) {
case TC_POLICE_SHOT: case TC_POLICE_SHOT:
kfree_skb(skb); kfree_skb(skb);
break; break;
case TC_POLICE_RECLASSIFY: case TC_POLICE_RECLASSIFY:
if (flow->excess) flow = flow->excess; if (flow->excess)
else { flow = flow->excess;
ATM_SKB(skb)->atm_options |= else {
ATM_ATMOPT_CLP; ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP;
break;
}
/* fall through */
case TC_POLICE_OK:
/* fall through */
default:
break; break;
}
/* fall through */
case TC_POLICE_OK:
/* fall through */
default:
break;
} }
#endif #endif
} }
if ( if (
#ifdef CONFIG_NET_CLS_POLICE #ifdef CONFIG_NET_CLS_POLICE
result == TC_POLICE_SHOT || result == TC_POLICE_SHOT ||
#endif #endif
(ret = flow->q->enqueue(skb,flow->q)) != 0) { (ret = flow->q->enqueue(skb, flow->q)) != 0) {
sch->qstats.drops++; sch->qstats.drops++;
if (flow) flow->qstats.drops++; if (flow)
flow->qstats.drops++;
return ret; return ret;
} }
sch->bstats.bytes += skb->len; sch->bstats.bytes += skb->len;
...@@ -458,7 +462,6 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch) ...@@ -458,7 +462,6 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
return NET_XMIT_BYPASS; return NET_XMIT_BYPASS;
} }
/* /*
* Dequeue packets and send them over ATM. Note that we quite deliberately * Dequeue packets and send them over ATM. Note that we quite deliberately
* avoid checking net_device's flow control here, simply because sch_atm * avoid checking net_device's flow control here, simply because sch_atm
...@@ -466,167 +469,163 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch) ...@@ -466,167 +469,163 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
* non-ATM interfaces. * non-ATM interfaces.
*/ */
static void sch_atm_dequeue(unsigned long data) static void sch_atm_dequeue(unsigned long data)
{ {
struct Qdisc *sch = (struct Qdisc *) data; struct Qdisc *sch = (struct Qdisc *)data;
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
struct sk_buff *skb; struct sk_buff *skb;
D2PRINTK("sch_atm_dequeue(sch %p,[qdisc %p])\n",sch,p); D2PRINTK("sch_atm_dequeue(sch %p,[qdisc %p])\n", sch, p);
for (flow = p->link.next; flow; flow = flow->next) for (flow = p->link.next; flow; flow = flow->next)
/* /*
* If traffic is properly shaped, this won't generate nasty * If traffic is properly shaped, this won't generate nasty
* little bursts. Otherwise, it may ... (but that's okay) * little bursts. Otherwise, it may ... (but that's okay)
*/ */
while ((skb = flow->q->dequeue(flow->q))) { while ((skb = flow->q->dequeue(flow->q))) {
if (!atm_may_send(flow->vcc,skb->truesize)) { if (!atm_may_send(flow->vcc, skb->truesize)) {
(void) flow->q->ops->requeue(skb,flow->q); (void)flow->q->ops->requeue(skb, flow->q);
break; break;
} }
D2PRINTK("atm_tc_dequeue: sending on class %p\n",flow); D2PRINTK("atm_tc_dequeue: sending on class %p\n", flow);
/* remove any LL header somebody else has attached */ /* remove any LL header somebody else has attached */
skb_pull(skb, skb_network_offset(skb)); skb_pull(skb, skb_network_offset(skb));
if (skb_headroom(skb) < flow->hdr_len) { if (skb_headroom(skb) < flow->hdr_len) {
struct sk_buff *new; struct sk_buff *new;
new = skb_realloc_headroom(skb,flow->hdr_len); new = skb_realloc_headroom(skb, flow->hdr_len);
dev_kfree_skb(skb); dev_kfree_skb(skb);
if (!new) continue; if (!new)
continue;
skb = new; skb = new;
} }
D2PRINTK("sch_atm_dequeue: ip %p, data %p\n", D2PRINTK("sch_atm_dequeue: ip %p, data %p\n",
skb_network_header(skb), skb->data); skb_network_header(skb), skb->data);
ATM_SKB(skb)->vcc = flow->vcc; ATM_SKB(skb)->vcc = flow->vcc;
memcpy(skb_push(skb,flow->hdr_len),flow->hdr, memcpy(skb_push(skb, flow->hdr_len), flow->hdr,
flow->hdr_len); flow->hdr_len);
atomic_add(skb->truesize, atomic_add(skb->truesize,
&sk_atm(flow->vcc)->sk_wmem_alloc); &sk_atm(flow->vcc)->sk_wmem_alloc);
/* atm.atm_options are already set by atm_tc_enqueue */ /* atm.atm_options are already set by atm_tc_enqueue */
(void) flow->vcc->send(flow->vcc,skb); flow->vcc->send(flow->vcc, skb);
} }
} }
static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch) static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct sk_buff *skb; struct sk_buff *skb;
D2PRINTK("atm_tc_dequeue(sch %p,[qdisc %p])\n",sch,p); D2PRINTK("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
tasklet_schedule(&p->task); tasklet_schedule(&p->task);
skb = p->link.q->dequeue(p->link.q); skb = p->link.q->dequeue(p->link.q);
if (skb) sch->q.qlen--; if (skb)
sch->q.qlen--;
return skb; return skb;
} }
static int atm_tc_requeue(struct sk_buff *skb, struct Qdisc *sch)
static int atm_tc_requeue(struct sk_buff *skb,struct Qdisc *sch)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
int ret; int ret;
D2PRINTK("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n",skb,sch,p); D2PRINTK("atm_tc_requeue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
ret = p->link.q->ops->requeue(skb,p->link.q); ret = p->link.q->ops->requeue(skb, p->link.q);
if (!ret) { if (!ret) {
sch->q.qlen++; sch->q.qlen++;
sch->qstats.requeues++; sch->qstats.requeues++;
} else { } else {
sch->qstats.drops++; sch->qstats.drops++;
p->link.qstats.drops++; p->link.qstats.drops++;
} }
return ret; return ret;
} }
static unsigned int atm_tc_drop(struct Qdisc *sch) static unsigned int atm_tc_drop(struct Qdisc *sch)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
unsigned int len; unsigned int len;
DPRINTK("atm_tc_drop(sch %p,[qdisc %p])\n",sch,p); DPRINTK("atm_tc_drop(sch %p,[qdisc %p])\n", sch, p);
for (flow = p->flows; flow; flow = flow->next) for (flow = p->flows; flow; flow = flow->next)
if (flow->q->ops->drop && (len = flow->q->ops->drop(flow->q))) if (flow->q->ops->drop && (len = flow->q->ops->drop(flow->q)))
return len; return len;
return 0; return 0;
} }
static int atm_tc_init(struct Qdisc *sch, struct rtattr *opt)
static int atm_tc_init(struct Qdisc *sch,struct rtattr *opt)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
DPRINTK("atm_tc_init(sch %p,[qdisc %p],opt %p)\n",sch,p,opt); DPRINTK("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
p->flows = &p->link; p->flows = &p->link;
if(!(p->link.q = qdisc_create_dflt(sch->dev,&pfifo_qdisc_ops, if (!(p->link.q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops,
sch->handle))) sch->handle)))
p->link.q = &noop_qdisc; p->link.q = &noop_qdisc;
DPRINTK("atm_tc_init: link (%p) qdisc %p\n",&p->link,p->link.q); DPRINTK("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
p->link.filter_list = NULL; p->link.filter_list = NULL;
p->link.vcc = NULL; p->link.vcc = NULL;
p->link.sock = NULL; p->link.sock = NULL;
p->link.classid = sch->handle; p->link.classid = sch->handle;
p->link.ref = 1; p->link.ref = 1;
p->link.next = NULL; p->link.next = NULL;
tasklet_init(&p->task,sch_atm_dequeue,(unsigned long) sch); tasklet_init(&p->task, sch_atm_dequeue, (unsigned long)sch);
return 0; return 0;
} }
static void atm_tc_reset(struct Qdisc *sch) static void atm_tc_reset(struct Qdisc *sch)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
DPRINTK("atm_tc_reset(sch %p,[qdisc %p])\n",sch,p); DPRINTK("atm_tc_reset(sch %p,[qdisc %p])\n", sch, p);
for (flow = p->flows; flow; flow = flow->next) qdisc_reset(flow->q); for (flow = p->flows; flow; flow = flow->next)
qdisc_reset(flow->q);
sch->q.qlen = 0; sch->q.qlen = 0;
} }
static void atm_tc_destroy(struct Qdisc *sch) static void atm_tc_destroy(struct Qdisc *sch)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow; struct atm_flow_data *flow;
DPRINTK("atm_tc_destroy(sch %p,[qdisc %p])\n",sch,p); DPRINTK("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
/* races ? */ /* races ? */
while ((flow = p->flows)) { while ((flow = p->flows)) {
tcf_destroy_chain(flow->filter_list); tcf_destroy_chain(flow->filter_list);
flow->filter_list = NULL; flow->filter_list = NULL;
if (flow->ref > 1) if (flow->ref > 1)
printk(KERN_ERR "atm_destroy: %p->ref = %d\n",flow, printk(KERN_ERR "atm_destroy: %p->ref = %d\n", flow,
flow->ref); flow->ref);
atm_tc_put(sch,(unsigned long) flow); atm_tc_put(sch, (unsigned long)flow);
if (p->flows == flow) { if (p->flows == flow) {
printk(KERN_ERR "atm_destroy: putting flow %p didn't " printk(KERN_ERR "atm_destroy: putting flow %p didn't "
"kill it\n",flow); "kill it\n", flow);
p->flows = flow->next; /* brute force */ p->flows = flow->next; /* brute force */
break; break;
} }
} }
tasklet_kill(&p->task); tasklet_kill(&p->task);
} }
static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
struct sk_buff *skb, struct tcmsg *tcm) struct sk_buff *skb, struct tcmsg *tcm)
{ {
struct atm_qdisc_data *p = PRIV(sch); struct atm_qdisc_data *p = PRIV(sch);
struct atm_flow_data *flow = (struct atm_flow_data *) cl; struct atm_flow_data *flow = (struct atm_flow_data *)cl;
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
struct rtattr *rta; struct rtattr *rta;
DPRINTK("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n", DPRINTK("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
sch,p,flow,skb,tcm); sch, p, flow, skb, tcm);
if (!find_flow(p,flow)) return -EINVAL; if (!find_flow(p, flow))
return -EINVAL;
tcm->tcm_handle = flow->classid; tcm->tcm_handle = flow->classid;
tcm->tcm_info = flow->q->handle; tcm->tcm_info = flow->q->handle;
rta = (struct rtattr *) b; rta = (struct rtattr *)b;
RTA_PUT(skb,TCA_OPTIONS,0,NULL); RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
RTA_PUT(skb,TCA_ATM_HDR,flow->hdr_len,flow->hdr); RTA_PUT(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr);
if (flow->vcc) { if (flow->vcc) {
struct sockaddr_atmpvc pvc; struct sockaddr_atmpvc pvc;
int state; int state;
...@@ -635,16 +634,16 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, ...@@ -635,16 +634,16 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1; pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
pvc.sap_addr.vpi = flow->vcc->vpi; pvc.sap_addr.vpi = flow->vcc->vpi;
pvc.sap_addr.vci = flow->vcc->vci; pvc.sap_addr.vci = flow->vcc->vci;
RTA_PUT(skb,TCA_ATM_ADDR,sizeof(pvc),&pvc); RTA_PUT(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc);
state = ATM_VF2VS(flow->vcc->flags); state = ATM_VF2VS(flow->vcc->flags);
RTA_PUT(skb,TCA_ATM_STATE,sizeof(state),&state); RTA_PUT(skb, TCA_ATM_STATE, sizeof(state), &state);
} }
if (flow->excess) if (flow->excess)
RTA_PUT(skb,TCA_ATM_EXCESS,sizeof(u32),&flow->classid); RTA_PUT(skb, TCA_ATM_EXCESS, sizeof(u32), &flow->classid);
else { else {
static u32 zero; static u32 zero;
RTA_PUT(skb,TCA_ATM_EXCESS,sizeof(zero),&zero); RTA_PUT(skb, TCA_ATM_EXCESS, sizeof(zero), &zero);
} }
rta->rta_len = skb_tail_pointer(skb) - b; rta->rta_len = skb_tail_pointer(skb) - b;
return skb->len; return skb->len;
...@@ -655,9 +654,9 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, ...@@ -655,9 +654,9 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
} }
static int static int
atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg, atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
struct gnet_dump *d) struct gnet_dump *d)
{ {
struct atm_flow_data *flow = (struct atm_flow_data *) arg; struct atm_flow_data *flow = (struct atm_flow_data *)arg;
flow->qstats.qlen = flow->q->q.qlen; flow->qstats.qlen = flow->q->q.qlen;
...@@ -674,38 +673,35 @@ static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -674,38 +673,35 @@ static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
} }
static struct Qdisc_class_ops atm_class_ops = { static struct Qdisc_class_ops atm_class_ops = {
.graft = atm_tc_graft, .graft = atm_tc_graft,
.leaf = atm_tc_leaf, .leaf = atm_tc_leaf,
.get = atm_tc_get, .get = atm_tc_get,
.put = atm_tc_put, .put = atm_tc_put,
.change = atm_tc_change, .change = atm_tc_change,
.delete = atm_tc_delete, .delete = atm_tc_delete,
.walk = atm_tc_walk, .walk = atm_tc_walk,
.tcf_chain = atm_tc_find_tcf, .tcf_chain = atm_tc_find_tcf,
.bind_tcf = atm_tc_bind_filter, .bind_tcf = atm_tc_bind_filter,
.unbind_tcf = atm_tc_put, .unbind_tcf = atm_tc_put,
.dump = atm_tc_dump_class, .dump = atm_tc_dump_class,
.dump_stats = atm_tc_dump_class_stats, .dump_stats = atm_tc_dump_class_stats,
}; };
static struct Qdisc_ops atm_qdisc_ops = { static struct Qdisc_ops atm_qdisc_ops = {
.next = NULL, .cl_ops = &atm_class_ops,
.cl_ops = &atm_class_ops, .id = "atm",
.id = "atm", .priv_size = sizeof(struct atm_qdisc_data),
.priv_size = sizeof(struct atm_qdisc_data), .enqueue = atm_tc_enqueue,
.enqueue = atm_tc_enqueue, .dequeue = atm_tc_dequeue,
.dequeue = atm_tc_dequeue, .requeue = atm_tc_requeue,
.requeue = atm_tc_requeue, .drop = atm_tc_drop,
.drop = atm_tc_drop, .init = atm_tc_init,
.init = atm_tc_init, .reset = atm_tc_reset,
.reset = atm_tc_reset, .destroy = atm_tc_destroy,
.destroy = atm_tc_destroy, .dump = atm_tc_dump,
.change = NULL, .owner = THIS_MODULE,
.dump = atm_tc_dump,
.owner = THIS_MODULE,
}; };
static int __init atm_init(void) static int __init atm_init(void)
{ {
return register_qdisc(&atm_qdisc_ops); return register_qdisc(&atm_qdisc_ops);
......
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