libnl 1.1

lib/route/class_api.c

00001 /*
00002  * lib/route/class_api.c            Queueing Classes 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 class
00014  * @defgroup class_api Class Modules
00015  * @{
00016  */
00017 
00018 #include <netlink-local.h>
00019 #include <netlink-tc.h>
00020 #include <netlink/netlink.h>
00021 #include <netlink/route/tc.h>
00022 #include <netlink/route/class.h>
00023 #include <netlink/route/class-modules.h>
00024 #include <netlink/utils.h>
00025 
00026 static struct rtnl_class_ops *class_ops_list;
00027 
00028 /**
00029  * @name Module API
00030  * @{
00031  */
00032 
00033 /**
00034  * Register a class module
00035  * @arg cops            class module operations
00036  */
00037 int rtnl_class_register(struct rtnl_class_ops *cops)
00038 {
00039         struct rtnl_class_ops *o, **op;
00040 
00041         if (!cops->co_kind[0])
00042                 BUG();
00043 
00044         for (op = &class_ops_list; (o = *op) != NULL; op = &o->co_next)
00045                 if (!strcasecmp(cops->co_kind, o->co_kind))
00046                         return nl_errno(EEXIST);
00047 
00048         cops->co_next = NULL;
00049         *op = cops;
00050 
00051         return 0;
00052 }
00053 
00054 /**
00055  * Unregister a class module
00056  * @arg cops            class module operations
00057  */
00058 int rtnl_class_unregister(struct rtnl_class_ops *cops)
00059 {
00060         struct rtnl_class_ops *o, **op;
00061 
00062         for (op = &class_ops_list; (o = *op) != NULL; op = &o->co_next)
00063                 if (!strcasecmp(cops->co_kind, o->co_kind))
00064                         break;
00065 
00066         if (!o)
00067                 return nl_errno(ENOENT);
00068 
00069         *op = cops->co_next;
00070 
00071         return 0;
00072 }
00073 
00074 struct rtnl_class_ops *__rtnl_class_lookup_ops(const char *kind)
00075 {
00076         struct rtnl_class_ops *cops;
00077 
00078         for (cops = class_ops_list; cops; cops = cops->co_next)
00079                 if (!strcmp(kind, cops->co_kind))
00080                         return cops;
00081 
00082         return NULL;
00083 }
00084 
00085 /**
00086  * Lookup class operations for a class object
00087  * @arg class           Class object.
00088  *
00089  * @return Class operations or NULL if not found.
00090  */
00091 struct rtnl_class_ops *rtnl_class_lookup_ops(struct rtnl_class *class)
00092 {
00093         if (!class->c_ops)
00094                 class->c_ops = __rtnl_class_lookup_ops(class->c_kind);
00095 
00096         return class->c_ops;
00097 }
00098 
00099 
00100 /** @} */
00101 
00102 /** @} */