Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

[NET_SCHED]: sch_atm: Lindent

parent f13ec93f
Loading
Loading
Loading
Loading
+232 −236
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

/* Written 1998-2000 by Werner Almesberger, EPFL ICA */


#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
@@ -15,7 +14,6 @@
#include <net/netlink.h>
#include <net/pkt_sched.h>


extern struct socket *sockfd_lookup(int fd, int *err);	/* @@@ fix this */

#if 0 /* control */
@@ -30,7 +28,6 @@ extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
#define D2PRINTK(format,args...)
#endif


/*
 * The ATM queuing discipline provides a framework for invoking classifiers
 * (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 */
 *  - should lock the flow while there is data in the queue (?)
 */


#define PRIV(sch) qdisc_priv(sch)
#define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))


struct atm_flow_data {
	struct Qdisc		*q;	/* FIFO, TBF, etc. */
	struct tcf_proto	*filter_list;
	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 socket		*sock;		/* for closing */
	u32			classid;	/* x:y type ID */
@@ -82,50 +78,49 @@ struct atm_qdisc_data {
	struct tasklet_struct	task;		/* requeue tasklet */
};


/* ------------------------- Class/flow operations ------------------------- */


static int find_flow(struct atm_qdisc_data *qdisc, struct atm_flow_data *flow)
{
	struct atm_flow_data *walk;

	DPRINTK("find_flow(qdisc %p,flow %p)\n", qdisc, flow);
	for (walk = qdisc->flows; walk; walk = walk->next)
		if (walk == flow) return 1;
		if (walk == flow)
			return 1;
	DPRINTK("find_flow: not found\n");
	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_flow_data *flow;

	for (flow = p->flows; flow; flow = flow->next)
		if (flow->classid == classid) break;
		if (flow->classid == classid)
			break;
	return flow;
}


static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
			struct Qdisc *new, struct Qdisc **old)
{
	struct atm_qdisc_data *p = PRIV(sch);
	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,
	    p,flow,new,old);
	if (!find_flow(p,flow)) return -EINVAL;
	if (!new) new = &noop_qdisc;
	DPRINTK("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
		sch, p, flow, new, old);
	if (!find_flow(p, flow))
		return -EINVAL;
	if (!new)
		new = &noop_qdisc;
	*old = xchg(&flow->q, new);
	if (*old) qdisc_reset(*old);
	if (*old)
		qdisc_reset(*old);
	return 0;
}


static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl)
{
	struct atm_flow_data *flow = (struct atm_flow_data *)cl;
@@ -134,20 +129,19 @@ static struct Qdisc *atm_tc_leaf(struct Qdisc *sch,unsigned long cl)
	return flow ? flow->q : NULL;
}


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;

	DPRINTK("atm_tc_get(sch %p,[qdisc %p],classid %x)\n", sch, p, classid);
	flow = lookup_flow(sch, classid);
	if (flow) flow->ref++;
	if (flow)
		flow->ref++;
	DPRINTK("atm_tc_get: flow %p\n", flow);
	return (unsigned long)flow;
}


static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
					unsigned long parent, u32 classid)
{
@@ -159,7 +153,6 @@ static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
 * requested (atm_tc_destroy, etc.). The assumption here is that we never drop
 * anything that still seems to be in use.
 */

static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -167,10 +160,12 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
	struct atm_flow_data **prev;

	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");
	for (prev = &p->flows; *prev; prev = &(*prev)->next)
		if (*prev == flow) break;
		if (*prev == flow)
			break;
	if (!*prev) {
		printk(KERN_CRIT "atm_tc_put: class %p not found\n", flow);
		return;
@@ -185,15 +180,16 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
		flow->vcc->pop = flow->old_pop;
		sockfd_put(flow->sock);
	}
	if (flow->excess) atm_tc_put(sch,(unsigned long) flow->excess);
	if (flow != &p->link) kfree(flow);
	if (flow->excess)
		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
	 * needs to be removed. (By the caller of atm_tc_put.)
	 */
}


static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
{
	struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
@@ -209,7 +205,8 @@ static const u8 llc_oui_ip[] = {
	0x03,			/* Ctrl: Unnumbered Information Command PDU */
	0x00,			/* OUI: EtherType */
	0x00, 0x00,
	0x08, 0x00 };	/* Ethertype IP (0800) */
	0x08, 0x00
};				/* Ethertype IP (0800) */

static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
			 struct rtattr **tca, unsigned long *arg)
@@ -237,7 +234,8 @@ 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
	 * later.)
	 */
	if (flow) return -EBUSY;
	if (flow)
		return -EBUSY;
	if (opt == NULL || rtattr_parse_nested(tb, TCA_ATM_MAX, opt))
		return -EINVAL;
	if (!tb[TCA_ATM_FD - 1] || RTA_PAYLOAD(tb[TCA_ATM_FD - 1]) < sizeof(fd))
@@ -247,22 +245,24 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
	if (tb[TCA_ATM_HDR - 1]) {
		hdr_len = RTA_PAYLOAD(tb[TCA_ATM_HDR - 1]);
		hdr = RTA_DATA(tb[TCA_ATM_HDR - 1]);
	}
	else {
	} else {
		hdr_len = RFC1483LLC_LEN;
		hdr = NULL;	/* default LLC/SNAP for IP */
	}
	if (!tb[TCA_ATM_EXCESS-1]) excess = NULL;
	if (!tb[TCA_ATM_EXCESS - 1])
		excess = NULL;
	else {
		if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS - 1]) != sizeof(u32))
			return -EINVAL;
		excess = (struct atm_flow_data *) atm_tc_get(sch,
		    *(u32 *) RTA_DATA(tb[TCA_ATM_EXCESS-1]));
		if (!excess) return -ENOENT;
		excess = (struct atm_flow_data *)
			atm_tc_get(sch, *(u32 *)RTA_DATA(tb[TCA_ATM_EXCESS - 1]));
		if (!excess)
			return -ENOENT;
	}
	DPRINTK("atm_tc_change: type %d, payload %d, hdr_len %d\n",
		opt->rta_type, RTA_PAYLOAD(opt), hdr_len);
	if (!(sock = sockfd_lookup(fd,&error))) return error; /* f_count++ */
	if (!(sock = sockfd_lookup(fd, &error)))
		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) {
		error = -EPROTOTYPE;
@@ -280,14 +280,14 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
			error = -EEXIST;
			goto err_out;
		}
	}
	else {
	} else {
		int i;
		unsigned long cl;

		for (i = 1; i < 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)))
				break;
			atm_tc_put(sch, cl);
		}
	}
@@ -323,20 +323,22 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
	*arg = (unsigned long)flow;
	return 0;
err_out:
	if (excess) atm_tc_put(sch,(unsigned long) excess);
	if (excess)
		atm_tc_put(sch, (unsigned long)excess);
	sockfd_put(sock);
	return error;
}


static int atm_tc_delete(struct Qdisc *sch, unsigned long arg)
{
	struct atm_qdisc_data *p = PRIV(sch);
	struct atm_flow_data *flow = (struct atm_flow_data *)arg;

	DPRINTK("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
	if (!find_flow(PRIV(sch),flow)) return -EINVAL;
	if (flow->filter_list || flow == &p->link) return -EBUSY;
	if (!find_flow(PRIV(sch), flow))
		return -EINVAL;
	if (flow->filter_list || flow == &p->link)
		return -EBUSY;
	/*
	 * Reference count must be 2: one for "keepalive" (set at class
	 * creation), and one for the reference held when calling delete.
@@ -345,19 +347,20 @@ static int atm_tc_delete(struct Qdisc *sch,unsigned long arg)
		printk(KERN_ERR "atm_tc_delete: flow->ref == %d\n", flow->ref);
		return -EINVAL;
	}
	if (flow->ref > 2) return -EBUSY; /* catch references via excess, etc.*/
	if (flow->ref > 2)
		return -EBUSY;	/* catch references via excess, etc. */
	atm_tc_put(sch, arg);
	return 0;
}


static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
	struct atm_qdisc_data *p = PRIV(sch);
	struct atm_flow_data *flow;

	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) {
		if (walker->count >= walker->skip)
			if (walker->fn(sch, (unsigned long)flow, walker) < 0) {
@@ -368,7 +371,6 @@ 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)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -378,10 +380,8 @@ static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch,unsigned long cl)
	return flow ? &flow->filter_list : &p->link.filter_list;
}


/* --------------------------- Qdisc operations ---------------------------- */


static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -398,12 +398,15 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
			if (flow->filter_list) {
				result = tc_classify(skb, flow->filter_list,
						     &res);
				if (result < 0) continue;
				if (result < 0)
					continue;
				flow = (struct atm_flow_data *)res.class;
				if (!flow) flow = lookup_flow(sch,res.classid);
				if (!flow)
					flow = lookup_flow(sch, res.classid);
				break;
			}
	if (!flow) flow = &p->link;
	if (!flow)
		flow = &p->link;
	else {
		if (flow->vcc)
			ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
@@ -414,10 +417,10 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
			kfree_skb(skb);
			break;
		case TC_POLICE_RECLASSIFY:
				if (flow->excess) flow = flow->excess;
			if (flow->excess)
				flow = flow->excess;
			else {
					ATM_SKB(skb)->atm_options |=
					    ATM_ATMOPT_CLP;
				ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP;
				break;
			}
			/* fall through */
@@ -434,7 +437,8 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
#endif
		   (ret = flow->q->enqueue(skb, flow->q)) != 0) {
		sch->qstats.drops++;
		if (flow) flow->qstats.drops++;
		if (flow)
			flow->qstats.drops++;
		return ret;
	}
	sch->bstats.bytes += skb->len;
@@ -458,7 +462,6 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
	return NET_XMIT_BYPASS;
}


/*
 * Dequeue packets and send them over ATM. Note that we quite deliberately
 * avoid checking net_device's flow control here, simply because sch_atm
@@ -466,7 +469,6 @@ static int atm_tc_enqueue(struct sk_buff *skb,struct Qdisc *sch)
 * non-ATM interfaces.
 */


static void sch_atm_dequeue(unsigned long data)
{
	struct Qdisc *sch = (struct Qdisc *)data;
@@ -493,7 +495,8 @@ static void sch_atm_dequeue(unsigned long data)

				new = skb_realloc_headroom(skb, flow->hdr_len);
				dev_kfree_skb(skb);
				if (!new) continue;
				if (!new)
					continue;
				skb = new;
			}
			D2PRINTK("sch_atm_dequeue: ip %p, data %p\n",
@@ -504,11 +507,10 @@ static void sch_atm_dequeue(unsigned long data)
			atomic_add(skb->truesize,
				   &sk_atm(flow->vcc)->sk_wmem_alloc);
			/* 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)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -517,11 +519,11 @@ static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
	D2PRINTK("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
	tasklet_schedule(&p->task);
	skb = p->link.q->dequeue(p->link.q);
	if (skb) sch->q.qlen--;
	if (skb)
		sch->q.qlen--;
	return skb;
}


static int atm_tc_requeue(struct sk_buff *skb, struct Qdisc *sch)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -539,7 +541,6 @@ static int atm_tc_requeue(struct sk_buff *skb,struct Qdisc *sch)
	return ret;
}


static unsigned int atm_tc_drop(struct Qdisc *sch)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -553,7 +554,6 @@ static unsigned int atm_tc_drop(struct Qdisc *sch)
	return 0;
}


static int atm_tc_init(struct Qdisc *sch, struct rtattr *opt)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -574,18 +574,17 @@ static int atm_tc_init(struct Qdisc *sch,struct rtattr *opt)
	return 0;
}


static void atm_tc_reset(struct Qdisc *sch)
{
	struct atm_qdisc_data *p = PRIV(sch);
	struct atm_flow_data *flow;

	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;
}


static void atm_tc_destroy(struct Qdisc *sch)
{
	struct atm_qdisc_data *p = PRIV(sch);
@@ -610,7 +609,6 @@ static void atm_tc_destroy(struct Qdisc *sch)
	tasklet_kill(&p->task);
}


static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
			     struct sk_buff *skb, struct tcmsg *tcm)
{
@@ -621,7 +619,8 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,

	DPRINTK("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
		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_info = flow->q->handle;
	rta = (struct rtattr *)b;
@@ -689,7 +688,6 @@ static struct Qdisc_class_ops atm_class_ops = {
};

static struct Qdisc_ops atm_qdisc_ops = {
	.next		=	NULL,
	.cl_ops		= &atm_class_ops,
	.id		= "atm",
	.priv_size	= sizeof(struct atm_qdisc_data),
@@ -700,12 +698,10 @@ static struct Qdisc_ops atm_qdisc_ops = {
	.init		= atm_tc_init,
	.reset		= atm_tc_reset,
	.destroy	= atm_tc_destroy,
	.change		=	NULL,
	.dump		= atm_tc_dump,
	.owner		= THIS_MODULE,
};


static int __init atm_init(void)
{
	return register_qdisc(&atm_qdisc_ops);