1a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf/* 2a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * lib/route/link/api.c Link Info API 3a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * 4a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * This library is free software; you can redistribute it and/or 5a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * modify it under the terms of the GNU Lesser General Public 6a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * License as published by the Free Software Foundation version 2.1 7a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * of the License. 8a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * 9a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> 10a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf */ 11a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 12a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf/** 13a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @ingroup link 14a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @defgroup link_info Link Info API 15a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @brief 16a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * 17a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @par 1) Registering/Unregistering a new link info type 18a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @code 19a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * static struct rtnl_link_info_ops vlan_info_ops = { 20a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * .io_name = "vlan", 21a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * .io_alloc = vlan_alloc, 22a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * .io_parse = vlan_parse, 23a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * .io_dump[NL_DUMP_BRIEF] = vlan_dump_brief, 24a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * .io_dump[NL_DUMP_FULL] = vlan_dump_full, 25a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * .io_free = vlan_free, 26a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * }; 27a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * 28a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * static void __init vlan_init(void) 29a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * { 30a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * rtnl_link_register_info(&vlan_info_ops); 31a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * } 32a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * 33a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * static void __exit vlan_exit(void) 34a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * { 35a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * rtnl_link_unregister_info(&vlan_info_ops); 36a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * } 37a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @endcode 38a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * 39a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf * @{ 40a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf */ 41a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 42a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf#include <netlink-local.h> 43a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf#include <netlink/netlink.h> 44a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf#include <netlink/utils.h> 45a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf#include <netlink/route/link.h> 46a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf#include <netlink/route/link/info-api.h> 47a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 48a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Grafstatic struct rtnl_link_info_ops *info_ops; 49a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 50a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Grafstruct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *name) 51a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf{ 52a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf struct rtnl_link_info_ops *ops; 53a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 54a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf for (ops = info_ops; ops; ops = ops->io_next) 55a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf if (!strcmp(ops->io_name, name)) 56a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf return ops; 57a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 58a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf return NULL; 59a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf} 60a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 61a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Grafint rtnl_link_register_info(struct rtnl_link_info_ops *ops) 62a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf{ 63a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf if (ops->io_name == NULL) 648a3efffa5b3fde252675239914118664d36a2c24Thomas Graf return -NLE_INVAL; 65a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 66a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf if (rtnl_link_info_ops_lookup(ops->io_name)) 678a3efffa5b3fde252675239914118664d36a2c24Thomas Graf return -NLE_EXIST; 68a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 69a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf NL_DBG(1, "Registered link info operations %s\n", ops->io_name); 70a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 71a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf ops->io_next = info_ops; 72a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf info_ops = ops; 73a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 74a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf return 0; 75a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf} 76a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 77a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Grafint rtnl_link_unregister_info(struct rtnl_link_info_ops *ops) 78a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf{ 79a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf struct rtnl_link_info_ops *t, **tp; 80a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 81a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf for (tp = &info_ops; (t=*tp) != NULL; tp = &t->io_next) 82a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf if (t == ops) 83a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf break; 84a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 85a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf if (!t) 868a3efffa5b3fde252675239914118664d36a2c24Thomas Graf return -NLE_OPNOTSUPP; 87a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 88a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf if (t->io_refcnt > 0) 898a3efffa5b3fde252675239914118664d36a2c24Thomas Graf return -NLE_BUSY; 90a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 91a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf NL_DBG(1, "Unregistered link info perations %s\n", ops->io_name); 92a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 93a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf *tp = t->io_next; 94a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf return 0; 95a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf} 96a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 97a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf/** @} */ 98a7469ce758fac3631df6ce72eb3f89150070e7f8Thomas Graf 99