1 /* 2 * lib/route/class_api.c Queueing Classes 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-2008 Thomas Graf <tgraf@suug.ch> 10 */ 11 12 /** 13 * @ingroup class 14 * @defgroup class_api Class Modules 15 * @{ 16 */ 17 18 #include <netlink-local.h> 19 #include <netlink-tc.h> 20 #include <netlink/netlink.h> 21 #include <netlink/route/tc.h> 22 #include <netlink/route/class.h> 23 #include <netlink/route/class-modules.h> 24 #include <netlink/utils.h> 25 26 static struct rtnl_class_ops *class_ops_list; 27 28 /** 29 * @name Module API 30 * @{ 31 */ 32 33 /** 34 * Register a class module 35 * @arg cops class module operations 36 */ rtnl_class_register(struct rtnl_class_ops * cops)37int rtnl_class_register(struct rtnl_class_ops *cops) 38 { 39 struct rtnl_class_ops *o, **op; 40 41 if (!cops->co_kind[0]) 42 BUG(); 43 44 for (op = &class_ops_list; (o = *op) != NULL; op = &o->co_next) 45 if (!strcasecmp(cops->co_kind, o->co_kind)) 46 return -NLE_EXIST; 47 48 cops->co_next = NULL; 49 *op = cops; 50 51 return 0; 52 } 53 54 /** 55 * Unregister a class module 56 * @arg cops class module operations 57 */ rtnl_class_unregister(struct rtnl_class_ops * cops)58int rtnl_class_unregister(struct rtnl_class_ops *cops) 59 { 60 struct rtnl_class_ops *o, **op; 61 62 for (op = &class_ops_list; (o = *op) != NULL; op = &o->co_next) 63 if (!strcasecmp(cops->co_kind, o->co_kind)) 64 break; 65 66 if (!o) 67 return -NLE_OBJ_NOTFOUND; 68 69 *op = cops->co_next; 70 71 return 0; 72 } 73 __rtnl_class_lookup_ops(const char * kind)74struct rtnl_class_ops *__rtnl_class_lookup_ops(const char *kind) 75 { 76 struct rtnl_class_ops *cops; 77 78 for (cops = class_ops_list; cops; cops = cops->co_next) 79 if (!strcmp(kind, cops->co_kind)) 80 return cops; 81 82 return NULL; 83 } 84 85 /** 86 * Lookup class operations for a class object 87 * @arg class Class object. 88 * 89 * @return Class operations or NULL if not found. 90 */ rtnl_class_lookup_ops(struct rtnl_class * class)91struct rtnl_class_ops *rtnl_class_lookup_ops(struct rtnl_class *class) 92 { 93 if (!class->c_ops) 94 class->c_ops = __rtnl_class_lookup_ops(class->c_kind); 95 96 return class->c_ops; 97 } 98 99 100 /** @} */ 101 102 /** @} */ 103