libnl 1.1
|
00001 /* 00002 * lib/route/link/api.c Link Info 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-2008 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 /** 00013 * @ingroup link 00014 * @defgroup link_info Link Info API 00015 * @brief 00016 * 00017 * @par 1) Registering/Unregistering a new link info type 00018 * @code 00019 * static struct rtnl_link_info_ops vlan_info_ops = { 00020 * .io_name = "vlan", 00021 * .io_alloc = vlan_alloc, 00022 * .io_parse = vlan_parse, 00023 * .io_dump[NL_DUMP_BRIEF] = vlan_dump_brief, 00024 * .io_dump[NL_DUMP_FULL] = vlan_dump_full, 00025 * .io_free = vlan_free, 00026 * }; 00027 * 00028 * static void __init vlan_init(void) 00029 * { 00030 * rtnl_link_register_info(&vlan_info_ops); 00031 * } 00032 * 00033 * static void __exit vlan_exit(void) 00034 * { 00035 * rtnl_link_unregister_info(&vlan_info_ops); 00036 * } 00037 * @endcode 00038 * 00039 * @{ 00040 */ 00041 00042 #include <netlink-local.h> 00043 #include <netlink/netlink.h> 00044 #include <netlink/utils.h> 00045 #include <netlink/route/link.h> 00046 #include <netlink/route/link/info-api.h> 00047 00048 static struct rtnl_link_info_ops *info_ops; 00049 00050 struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *name) 00051 { 00052 struct rtnl_link_info_ops *ops; 00053 00054 for (ops = info_ops; ops; ops = ops->io_next) 00055 if (!strcmp(ops->io_name, name)) 00056 return ops; 00057 00058 return NULL; 00059 } 00060 00061 int rtnl_link_register_info(struct rtnl_link_info_ops *ops) 00062 { 00063 if (ops->io_name == NULL) 00064 return nl_error(EINVAL, "No name specified"); 00065 00066 if (rtnl_link_info_ops_lookup(ops->io_name)) 00067 return nl_error(EEXIST, "Link info operations already exist"); 00068 00069 NL_DBG(1, "Registered link info operations %s\n", ops->io_name); 00070 00071 ops->io_next = info_ops; 00072 info_ops = ops; 00073 00074 return 0; 00075 } 00076 00077 int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops) 00078 { 00079 struct rtnl_link_info_ops *t, **tp; 00080 00081 for (tp = &info_ops; (t=*tp) != NULL; tp = &t->io_next) 00082 if (t == ops) 00083 break; 00084 00085 if (!t) 00086 return nl_error(ENOENT, "No such link info operations"); 00087 00088 if (t->io_refcnt > 0) 00089 return nl_error(EBUSY, "Info operations in use"); 00090 00091 NL_DBG(1, "Unregistered link info perations %s\n", ops->io_name); 00092 00093 *tp = t->io_next; 00094 return 0; 00095 } 00096 00097 /** @} */ 00098