diff options
author | Thomas Graf <tgr@deb.localdomain> | 2008-01-08 14:00:46 (GMT) |
---|---|---|
committer | Thomas Graf <tgr@deb.localdomain> | 2008-01-08 14:00:46 (GMT) |
commit | a7469ce758fac3631df6ce72eb3f89150070e7f8 (patch) | |
tree | 4e429eaac1902755cdc36ed680cdb1126a0c2d61 /lib/route/link/api.c | |
parent | 195241473723527e2f30ac120087f106c607ce3e (diff) | |
download | libnl-a7469ce758fac3631df6ce72eb3f89150070e7f8.zip libnl-a7469ce758fac3631df6ce72eb3f89150070e7f8.tar.gz libnl-a7469ce758fac3631df6ce72eb3f89150070e7f8.tar.bz2 |
Link info interface and vlan support
Adds an external interface to implement link info types and
implements the type vlan.
Diffstat (limited to 'lib/route/link/api.c')
-rw-r--r-- | lib/route/link/api.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/route/link/api.c b/lib/route/link/api.c new file mode 100644 index 0000000..afe00b1 --- /dev/null +++ b/lib/route/link/api.c @@ -0,0 +1,98 @@ +/* + * lib/route/link/api.c Link Info API + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + */ + +/** + * @ingroup link + * @defgroup link_info Link Info API + * @brief + * + * @par 1) Registering/Unregistering a new link info type + * @code + * static struct rtnl_link_info_ops vlan_info_ops = { + * .io_name = "vlan", + * .io_alloc = vlan_alloc, + * .io_parse = vlan_parse, + * .io_dump[NL_DUMP_BRIEF] = vlan_dump_brief, + * .io_dump[NL_DUMP_FULL] = vlan_dump_full, + * .io_free = vlan_free, + * }; + * + * static void __init vlan_init(void) + * { + * rtnl_link_register_info(&vlan_info_ops); + * } + * + * static void __exit vlan_exit(void) + * { + * rtnl_link_unregister_info(&vlan_info_ops); + * } + * @endcode + * + * @{ + */ + +#include <netlink-local.h> +#include <netlink/netlink.h> +#include <netlink/utils.h> +#include <netlink/route/link.h> +#include <netlink/route/link/info-api.h> + +static struct rtnl_link_info_ops *info_ops; + +struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *name) +{ + struct rtnl_link_info_ops *ops; + + for (ops = info_ops; ops; ops = ops->io_next) + if (!strcmp(ops->io_name, name)) + return ops; + + return NULL; +} + +int rtnl_link_register_info(struct rtnl_link_info_ops *ops) +{ + if (ops->io_name == NULL) + return nl_error(EINVAL, "No name specified"); + + if (rtnl_link_info_ops_lookup(ops->io_name)) + return nl_error(EEXIST, "Link info operations already exist"); + + NL_DBG(1, "Registered link info operations %s\n", ops->io_name); + + ops->io_next = info_ops; + info_ops = ops; + + return 0; +} + +int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops) +{ + struct rtnl_link_info_ops *t, **tp; + + for (tp = &info_ops; (t=*tp) != NULL; tp = &t->io_next) + if (t == ops) + break; + + if (!t) + return nl_error(ENOENT, "No such link info operations"); + + if (t->io_refcnt > 0) + return nl_error(EBUSY, "Info operations in use"); + + NL_DBG(1, "Unregistered link info perations %s\n", ops->io_name); + + *tp = t->io_next; + return 0; +} + +/** @} */ + |