libnl 1.1
|
00001 /* 00002 * lib/route/qdisc_api.c Queueing Discipline Module API 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 /** 00013 * @ingroup qdisc 00014 * @defgroup qdisc_api Queueing Discipline Modules 00015 * @{ 00016 */ 00017 00018 #include <netlink-local.h> 00019 #include <netlink-tc.h> 00020 #include <netlink/netlink.h> 00021 #include <netlink/utils.h> 00022 #include <netlink/route/link.h> 00023 #include <netlink/route/tc.h> 00024 #include <netlink/route/qdisc.h> 00025 #include <netlink/route/class.h> 00026 #include <netlink/route/classifier.h> 00027 #include <netlink/route/qdisc-modules.h> 00028 00029 static struct rtnl_qdisc_ops *qdisc_ops_list; 00030 00031 /** 00032 * @name Module API 00033 * @{ 00034 */ 00035 00036 /** 00037 * Register a qdisc module 00038 * @arg qops qdisc module operations 00039 */ 00040 int rtnl_qdisc_register(struct rtnl_qdisc_ops *qops) 00041 { 00042 struct rtnl_qdisc_ops *o, **op; 00043 00044 if (!qops->qo_kind[0]) 00045 BUG(); 00046 00047 for (op = &qdisc_ops_list; (o = *op) != NULL; op = &o->qo_next) 00048 if (!strcasecmp(qops->qo_kind, o->qo_kind)) 00049 return nl_errno(EEXIST); 00050 00051 qops->qo_next = NULL; 00052 *op = qops; 00053 00054 return 0; 00055 } 00056 00057 /** 00058 * Unregister a qdisc module 00059 * @arg qops qdisc module operations 00060 */ 00061 int rtnl_qdisc_unregister(struct rtnl_qdisc_ops *qops) 00062 { 00063 struct rtnl_qdisc_ops *o, **op; 00064 00065 for (op = &qdisc_ops_list; (o = *op) != NULL; op = &o->qo_next) 00066 if (!strcasecmp(qops->qo_kind, o->qo_kind)) 00067 break; 00068 00069 if (!o) 00070 return nl_errno(ENOENT); 00071 00072 *op = qops->qo_next; 00073 00074 return 0; 00075 } 00076 00077 struct rtnl_qdisc_ops *__rtnl_qdisc_lookup_ops(const char *kind) 00078 { 00079 struct rtnl_qdisc_ops *qops; 00080 00081 for (qops = qdisc_ops_list; qops; qops = qops->qo_next) 00082 if (!strcmp(kind, qops->qo_kind)) 00083 return qops; 00084 00085 return NULL; 00086 } 00087 00088 struct rtnl_qdisc_ops *rtnl_qdisc_lookup_ops(struct rtnl_qdisc *qdisc) 00089 { 00090 if (!qdisc->q_ops) 00091 qdisc->q_ops = __rtnl_qdisc_lookup_ops(qdisc->q_kind); 00092 00093 return qdisc->q_ops; 00094 } 00095 00096 /** @} */ 00097 00098 /** @} */