1/*
2 * lib/route/qdisc_api.c            Queueing Discipline Module API
3 *
4 *	This library is free software; you can redistribute it and/or
5 *	modify it under the terms of the GNU Lesser General Public
6 *	License as published by the Free Software Foundation version 2.1
7 *	of the License.
8 *
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10 */
11
12/**
13 * @ingroup qdisc
14 * @defgroup qdisc_api Queueing Discipline Modules
15 * @{
16 */
17
18#include <netlink-local.h>
19#include <netlink-tc.h>
20#include <netlink/netlink.h>
21#include <netlink/utils.h>
22#include <netlink/route/link.h>
23#include <netlink/route/tc.h>
24#include <netlink/route/qdisc.h>
25#include <netlink/route/class.h>
26#include <netlink/route/classifier.h>
27#include <netlink/route/qdisc-modules.h>
28
29static struct rtnl_qdisc_ops *qdisc_ops_list;
30
31/**
32 * @name Module API
33 * @{
34 */
35
36/**
37 * Register a qdisc module
38 * @arg qops		qdisc module operations
39 */
40int rtnl_qdisc_register(struct rtnl_qdisc_ops *qops)
41{
42	struct rtnl_qdisc_ops *o, **op;
43
44	if (!qops->qo_kind[0])
45		BUG();
46
47	for (op = &qdisc_ops_list; (o = *op) != NULL; op = &o->qo_next)
48		if (!strcasecmp(qops->qo_kind, o->qo_kind))
49			return -NLE_EXIST;
50
51	qops->qo_next = NULL;
52	*op = qops;
53
54	return 0;
55}
56
57/**
58 * Unregister a qdisc module
59 * @arg qops		qdisc module operations
60 */
61int rtnl_qdisc_unregister(struct rtnl_qdisc_ops *qops)
62{
63	struct rtnl_qdisc_ops *o, **op;
64
65	for (op = &qdisc_ops_list; (o = *op) != NULL; op = &o->qo_next)
66		if (!strcasecmp(qops->qo_kind, o->qo_kind))
67			break;
68
69	if (!o)
70		return -NLE_OBJ_NOTFOUND;
71
72	*op = qops->qo_next;
73
74	return 0;
75}
76
77struct rtnl_qdisc_ops *__rtnl_qdisc_lookup_ops(const char *kind)
78{
79	struct rtnl_qdisc_ops *qops;
80
81	for (qops = qdisc_ops_list; qops; qops = qops->qo_next)
82		if (!strcmp(kind, qops->qo_kind))
83			return qops;
84
85	return NULL;
86}
87
88struct rtnl_qdisc_ops *rtnl_qdisc_lookup_ops(struct rtnl_qdisc *qdisc)
89{
90	if (!qdisc->q_ops)
91		qdisc->q_ops = __rtnl_qdisc_lookup_ops(qdisc->q_kind);
92
93	return qdisc->q_ops;
94}
95
96/** @} */
97
98/** @} */
99