1 /* 2 * netlink-private/route/link/api.h Link Modules 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-2013 Thomas Graf <tgraf@suug.ch> 10 */ 11 12 #ifndef NETLINK_LINK_API_H_ 13 #define NETLINK_LINK_API_H_ 14 15 #include <netlink/netlink.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * @ingroup link_api 23 * 24 * Available operations to modules implementing a link info type. 25 */ 26 struct rtnl_link_info_ops 27 { 28 /** Name of link info type, must match name on kernel side */ 29 char * io_name; 30 31 /** Reference count, DO NOT MODIFY */ 32 int io_refcnt; 33 34 /** Called to assign an info type to a link. 35 * Has to allocate enough resources to hold attributes. Can 36 * use link->l_info to store a pointer. */ 37 int (*io_alloc)(struct rtnl_link *); 38 39 /** Called to parse the link info attribute. 40 * Must parse the attribute and assign all values to the link. 41 */ 42 int (*io_parse)(struct rtnl_link *, 43 struct nlattr *, 44 struct nlattr *); 45 46 /** Called when the link object is dumped. 47 * Must dump the info type specific attributes. */ 48 void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, 49 struct nl_dump_params *); 50 51 /** Called when a link object is cloned. 52 * Must clone all info type specific attributes. */ 53 int (*io_clone)(struct rtnl_link *, struct rtnl_link *); 54 55 /** Called when construction a link netlink message. 56 * Must append all info type specific attributes to the message. */ 57 int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *); 58 59 /** Called to release all resources previously allocated 60 * in either io_alloc() or io_parse(). */ 61 void (*io_free)(struct rtnl_link *); 62 63 /** Called to compare link info parameters between two links. */ 64 int (*io_compare)(struct rtnl_link *, struct rtnl_link *, 65 int flags); 66 67 struct nl_list_head io_list; 68 }; 69 70 extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *); 71 extern void rtnl_link_info_ops_put(struct rtnl_link_info_ops *); 72 extern int rtnl_link_register_info(struct rtnl_link_info_ops *); 73 extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *); 74 75 76 /** 77 * @ingroup link_api 78 * 79 * Available operations to modules implementing a link address family. 80 */ 81 struct rtnl_link_af_ops 82 { 83 /** The address family this operations set implements */ 84 const unsigned int ao_family; 85 86 /** Number of users of this operations, DO NOT MODIFY. */ 87 int ao_refcnt; 88 89 /** Validation policy for IFLA_PROTINFO attribute. This pointer 90 * can be set to a nla_policy structure describing the minimal 91 * requirements the attribute must meet. Failure of meeting these 92 * requirements will result in a parsing error. */ 93 const struct nla_policy *ao_protinfo_policy; 94 95 /** Called after address family has been assigned to link. Must 96 * allocate data buffer to hold address family specific data and 97 * store it in link->l_af_data. */ 98 void * (*ao_alloc)(struct rtnl_link *); 99 100 /** Called when the link is cloned, must allocate a clone of the 101 * address family specific buffer and return it. */ 102 void * (*ao_clone)(struct rtnl_link *, void *); 103 104 /** Called when the link gets freed. Must free all allocated data */ 105 void (*ao_free)(struct rtnl_link *, void *); 106 107 /** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically 108 * stores the parsed data in the address family specific buffer. */ 109 int (*ao_parse_protinfo)(struct rtnl_link *, 110 struct nlattr *, void *); 111 112 /** Called if a IFLA_AF_SPEC attribute needs to be parsed. Typically 113 * stores the parsed data in the address family specific buffer. */ 114 int (*ao_parse_af)(struct rtnl_link *, 115 struct nlattr *, void *); 116 117 /** Called if a link message is sent to the kernel. Must append the 118 * link address family specific attributes to the message. */ 119 int (*ao_fill_af)(struct rtnl_link *, 120 struct nl_msg *msg, void *); 121 122 /** Called if the full IFLA_AF_SPEC data needs to be parsed. Typically 123 * stores the parsed data in the address family specific buffer. */ 124 int (*ao_parse_af_full)(struct rtnl_link *, 125 struct nlattr *, void *); 126 127 /** Called for GETLINK message to the kernel. Used to append 128 * link address family specific attributes to the request message. */ 129 int (*ao_get_af)(struct nl_msg *msg, 130 uint32_t *ext_filter_mask); 131 132 /** Dump address family specific link attributes */ 133 void (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *, 134 struct nl_dump_params *, 135 void *); 136 137 /** Comparison function 138 * 139 * Will be called when two links are compared for their af data. It 140 * takes two link objects in question, an object specific bitmask 141 * defining which attributes should be compared and flags to control 142 * the behaviour 143 * 144 * The function must return a bitmask with the relevant bit set for 145 * each attribute that mismatches 146 */ 147 int (*ao_compare)(struct rtnl_link *, 148 struct rtnl_link *, int, uint32_t, int); 149 150 /* RTM_NEWLINK override 151 * 152 * Called if a change link request is set to the kernel. If this returns 153 * anything other than zero, RTM_NEWLINK will be overriden with 154 * RTM_SETLINK when rtnl_link_build_change_request() is called. 155 */ 156 int (*ao_override_rtm)(struct rtnl_link *); 157 158 /** Called if a link message is sent to the kernel. Must append the 159 * link protocol specific attributes to the message. (IFLA_PROTINFO) */ 160 int (*ao_fill_pi)(struct rtnl_link *, 161 struct nl_msg *msg, void *); 162 163 /** PROTINFO type 164 * 165 * Called if a link message is sent to the kernel. If this is set, 166 * the default IFLA_PROTINFO is bitmasked with what is specified 167 * here. (eg. NLA_F_NESTED) 168 */ 169 const int ao_fill_pi_flags; 170 171 /** IFLA_AF_SPEC nesting override 172 * 173 * Called if a link message is sent to the kernel. If this is set, 174 * the AF specific nest is not created. Instead, AF specific attributes 175 * are nested directly in the IFLA_AF_SPEC attribute. 176 */ 177 const int ao_fill_af_no_nest; 178 }; 179 180 extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int); 181 extern void rtnl_link_af_ops_put(struct rtnl_link_af_ops *); 182 extern void * rtnl_link_af_alloc(struct rtnl_link *, 183 const struct rtnl_link_af_ops *); 184 extern void * rtnl_link_af_data(const struct rtnl_link *, 185 const struct rtnl_link_af_ops *); 186 extern int rtnl_link_af_register(struct rtnl_link_af_ops *); 187 extern int rtnl_link_af_unregister(struct rtnl_link_af_ops *); 188 extern int rtnl_link_af_data_compare(struct rtnl_link *a, 189 struct rtnl_link *b, 190 int family); 191 extern int rtnl_link_info_data_compare(struct rtnl_link *a, 192 struct rtnl_link *b, 193 int flags); 194 195 #ifdef __cplusplus 196 } 197 #endif 198 199 #endif 200