diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-11-11 14:50:49 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-11-11 14:50:49 (GMT) |
commit | 3fa6a6b4104729e8e6bc07be61e04ee25b8d3611 (patch) | |
tree | ec5a9d3e73f2b44d20d4bb026cf3002ea1d01018 /include | |
parent | fd857eeb9fb17509563657a25312aafa562e90c2 (diff) | |
download | libnl-3fa6a6b4104729e8e6bc07be61e04ee25b8d3611.zip libnl-3fa6a6b4104729e8e6bc07be61e04ee25b8d3611.tar.gz libnl-3fa6a6b4104729e8e6bc07be61e04ee25b8d3611.tar.bz2 |
link: API for address family specific link data
Introduces a new API to handle address familiy specific link data such as
IFLA_PROTINFO. It provides entry hooks for parsing IFLA_PROTINFO attributes
and allows to include the parsed data when a link object is dumped.
Diffstat (limited to 'include')
-rw-r--r-- | include/netlink-types.h | 48 | ||||
-rw-r--r-- | include/netlink/route/link/api.h | 115 | ||||
-rw-r--r-- | include/netlink/route/link/info-api.h | 59 |
3 files changed, 143 insertions, 79 deletions
diff --git a/include/netlink-types.h b/include/netlink-types.h index 5b0ec5f..24911b9 100644 --- a/include/netlink-types.h +++ b/include/netlink-types.h @@ -150,31 +150,31 @@ struct rtnl_link { NLHDR_COMMON - char l_name[IFNAMSIZ]; - - uint32_t l_family; - uint32_t l_arptype; - uint32_t l_index; - uint32_t l_flags; - uint32_t l_change; - uint32_t l_mtu; - uint32_t l_link; - uint32_t l_txqlen; - uint32_t l_weight; - uint32_t l_master; - struct nl_addr *l_addr; - struct nl_addr *l_bcast; - char l_qdisc[IFQDISCSIZ]; - struct rtnl_link_map l_map; - uint64_t l_stats[RTNL_LINK_STATS_MAX+1]; - uint32_t l_flag_mask; - uint32_t l_num_vf; - uint8_t l_operstate; - uint8_t l_linkmode; + char l_name[IFNAMSIZ]; + uint32_t l_family; + uint32_t l_arptype; + uint32_t l_index; + uint32_t l_flags; + uint32_t l_change; + uint32_t l_mtu; + uint32_t l_link; + uint32_t l_txqlen; + uint32_t l_weight; + uint32_t l_master; + struct nl_addr * l_addr; + struct nl_addr * l_bcast; + char l_qdisc[IFQDISCSIZ]; + struct rtnl_link_map l_map; + uint64_t l_stats[RTNL_LINK_STATS_MAX+1]; + uint32_t l_flag_mask; + uint32_t l_num_vf; + uint8_t l_operstate; + uint8_t l_linkmode; /* 2 byte hole */ - struct rtnl_link_info_ops *l_info_ops; - void * l_info; - char * l_ifalias; + struct rtnl_link_info_ops * l_info_ops; + void * l_af_data[AF_MAX]; + void * l_info; + char * l_ifalias; }; struct rtnl_ncacheinfo diff --git a/include/netlink/route/link/api.h b/include/netlink/route/link/api.h new file mode 100644 index 0000000..ae5af59 --- /dev/null +++ b/include/netlink/route/link/api.h @@ -0,0 +1,115 @@ +/* + * netlink/route/link/api.h Link Modules 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-2010 Thomas Graf <tgraf@suug.ch> + */ + +#ifndef NETLINK_LINK_API_H_ +#define NETLINK_LINK_API_H_ + +#include <netlink/netlink.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup link_info + * + * Link info operations + */ +struct rtnl_link_info_ops +{ + /** Name of operations, must match name on kernel side */ + char * io_name; + + /** Reference count (internal, do not use) */ + int io_refcnt; + + /** Called to assign an info type to a link. + * Has to allocate enough resources to hold attributes. Can + * use link->l_info to store a pointer. */ + int (*io_alloc)(struct rtnl_link *); + + /** Called to parse the link info attribute. + * Must parse the attribute and assign all values to the link. + */ + int (*io_parse)(struct rtnl_link *, + struct nlattr *, + struct nlattr *); + + /** Called when the link object is dumped. + * Must dump the info type specific attributes. */ + void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, + struct nl_dump_params *); + + /** Called when a link object is cloned. + * Must clone all info type specific attributes. */ + int (*io_clone)(struct rtnl_link *, struct rtnl_link *); + + /** Called when construction a link netlink message. + * Must append all info type specific attributes to the message. */ + int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *); + + /** Called to release all resources previously allocated + * in either io_alloc() or io_parse(). */ + void (*io_free)(struct rtnl_link *); + + struct rtnl_link_info_ops * io_next; +}; + +extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *); + +extern int rtnl_link_register_info(struct rtnl_link_info_ops *); +extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *); + + +struct rtnl_link_af_ops +{ + /** The address family this operations set implements */ + const unsigned int ao_family; + + /** Number of users of this operations, DO NOT MODIFY. */ + int ao_refcnt; + + /** Validation policy for IFLA_PROTINFO attribute. This pointer + * can be set to a nla_policy structure describing the minimal + * requirements the attribute must meet. Failure of meeting these + * requirements will result in a parsing error. */ + const struct nla_policy *ao_protinfo_policy; + + /** Called after address family has been assigned to link. Must + * allocate data buffer to hold address family specific data and + * store it in link->l_af_data. */ + void * (*ao_alloc)(struct rtnl_link *); + + /** Called when the link is cloned, must allocate a clone of the + * address family specific buffer and return it. */ + void * (*ao_clone)(struct rtnl_link *, void *); + + /** Called when the link gets freed. Must free all allocated data */ + void (*ao_free)(struct rtnl_link *, void *); + + /** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically + * stores the parsed data in the address family specific buffer. */ + int (*ao_parse_protinfo)(struct rtnl_link *, + struct nlattr *, void *); + + /** Dump address family specific link attributes */ + void (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *, + struct nl_dump_params *, + void *); +}; + +extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int); +extern void rtnl_link_af_ops_put(struct rtnl_link_af_ops *); +extern int rtnl_link_af_register(struct rtnl_link_af_ops *); +extern int rtnl_link_af_unregister(struct rtnl_link_af_ops *); + + +#endif diff --git a/include/netlink/route/link/info-api.h b/include/netlink/route/link/info-api.h index 7e18e31..4750e18 100644 --- a/include/netlink/route/link/info-api.h +++ b/include/netlink/route/link/info-api.h @@ -6,66 +6,15 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch> */ #ifndef NETLINK_LINK_INFO_API_H_ #define NETLINK_LINK_INFO_API_H_ -#include <netlink/netlink.h> +#warning "<netlink/route/link/info-api.h> is obsolete and may be removed in the future." +#warning "include <netlink/route/link/api.h> instead. -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @ingroup link_info - * - * Link info operations - */ -struct rtnl_link_info_ops -{ - /** Name of operations, must match name on kernel side */ - char * io_name; - - /** Reference count (internal, do not use) */ - int io_refcnt; - - /** Called to assign an info type to a link. - * Has to allocate enough resources to hold attributes. Can - * use link->l_info to store a pointer. */ - int (*io_alloc)(struct rtnl_link *); - - /** Called to parse the link info attribute. - * Must parse the attribute and assign all values to the link. - */ - int (*io_parse)(struct rtnl_link *, - struct nlattr *, - struct nlattr *); - - /** Called when the link object is dumped. - * Must dump the info type specific attributes. */ - void (*io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, - struct nl_dump_params *); - - /** Called when a link object is cloned. - * Must clone all info type specific attributes. */ - int (*io_clone)(struct rtnl_link *, struct rtnl_link *); - - /** Called when construction a link netlink message. - * Must append all info type specific attributes to the message. */ - int (*io_put_attrs)(struct nl_msg *, struct rtnl_link *); - - /** Called to release all resources previously allocated - * in either io_alloc() or io_parse(). */ - void (*io_free)(struct rtnl_link *); - - struct rtnl_link_info_ops * io_next; -}; - -extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *); - -extern int rtnl_link_register_info(struct rtnl_link_info_ops *); -extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *); +#include <netlink/route/link/api.h> #endif |