libnl
3.2.3
|
00001 /* 00002 * netlink/route/link/api.h Link Modules 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-2010 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 #ifndef NETLINK_LINK_API_H_ 00013 #define NETLINK_LINK_API_H_ 00014 00015 #include <netlink/netlink.h> 00016 00017 #ifdef __cplusplus 00018 extern "C" { 00019 #endif 00020 00021 /** 00022 * @ingroup link_api 00023 * 00024 * Available operations to modules implementing a link info type. 00025 */ 00026 struct rtnl_link_info_ops 00027 { 00028 /** Name of link info type, must match name on kernel side */ 00029 char * io_name; 00030 00031 /** Reference count, DO NOT MODIFY */ 00032 int io_refcnt; 00033 00034 /** Called to assign an info type to a link. 00035 * Has to allocate enough resources to hold attributes. Can 00036 * use link->l_info to store a pointer. */ 00037 int (*io_alloc)(struct rtnl_link *); 00038 00039 /** Called to parse the link info attribute. 00040 * Must parse the attribute and assign all values to the link. 00041 */ 00042 int (*io_parse)(struct rtnl_link *, 00043 struct nlattr *, 00044 struct nlattr *); 00045 00046 /** Called when the link object is dumped. 00047 * Must dump the info type specific attributes. */ 00048 void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, 00049 struct nl_dump_params *); 00050 00051 /** Called when a link object is cloned. 00052 * Must clone all info type specific attributes. */ 00053 int (*io_clone)(struct rtnl_link *, struct rtnl_link *); 00054 00055 /** Called when construction a link netlink message. 00056 * Must append all info type specific attributes to the message. */ 00057 int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *); 00058 00059 /** Called to release all resources previously allocated 00060 * in either io_alloc() or io_parse(). */ 00061 void (*io_free)(struct rtnl_link *); 00062 00063 struct nl_list_head io_list; 00064 }; 00065 00066 extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *); 00067 extern void rtnl_link_info_ops_put(struct rtnl_link_info_ops *); 00068 extern int rtnl_link_register_info(struct rtnl_link_info_ops *); 00069 extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *); 00070 00071 00072 /** 00073 * @ingroup link_api 00074 * 00075 * Available operations to modules implementing a link address family. 00076 */ 00077 struct rtnl_link_af_ops 00078 { 00079 /** The address family this operations set implements */ 00080 const unsigned int ao_family; 00081 00082 /** Number of users of this operations, DO NOT MODIFY. */ 00083 int ao_refcnt; 00084 00085 /** Validation policy for IFLA_PROTINFO attribute. This pointer 00086 * can be set to a nla_policy structure describing the minimal 00087 * requirements the attribute must meet. Failure of meeting these 00088 * requirements will result in a parsing error. */ 00089 const struct nla_policy *ao_protinfo_policy; 00090 00091 /** Called after address family has been assigned to link. Must 00092 * allocate data buffer to hold address family specific data and 00093 * store it in link->l_af_data. */ 00094 void * (*ao_alloc)(struct rtnl_link *); 00095 00096 /** Called when the link is cloned, must allocate a clone of the 00097 * address family specific buffer and return it. */ 00098 void * (*ao_clone)(struct rtnl_link *, void *); 00099 00100 /** Called when the link gets freed. Must free all allocated data */ 00101 void (*ao_free)(struct rtnl_link *, void *); 00102 00103 /** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically 00104 * stores the parsed data in the address family specific buffer. */ 00105 int (*ao_parse_protinfo)(struct rtnl_link *, 00106 struct nlattr *, void *); 00107 00108 /** Called if a IFLA_AF_SPEC attribute needs to be parsed. Typically 00109 * stores the parsed data in the address family specific buffer. */ 00110 int (*ao_parse_af)(struct rtnl_link *, 00111 struct nlattr *, void *); 00112 00113 /** Called if a link message is sent to the kernel. Must append the 00114 * link address family specific attributes to the message. */ 00115 int (*ao_fill_af)(struct rtnl_link *, 00116 struct nl_msg *msg, void *); 00117 00118 /** Dump address family specific link attributes */ 00119 void (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *, 00120 struct nl_dump_params *, 00121 void *); 00122 }; 00123 00124 extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int); 00125 extern void rtnl_link_af_ops_put(struct rtnl_link_af_ops *); 00126 extern void * rtnl_link_af_alloc(struct rtnl_link *, 00127 const struct rtnl_link_af_ops *); 00128 extern void * rtnl_link_af_data(const struct rtnl_link *, 00129 const struct rtnl_link_af_ops *); 00130 extern int rtnl_link_af_register(struct rtnl_link_af_ops *); 00131 extern int rtnl_link_af_unregister(struct rtnl_link_af_ops *); 00132 00133 00134 #endif