Home | History | Annotate | Download | only in link
      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 (at) 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 	struct nl_list_head		io_list;
     64 };
     65 
     66 extern struct rtnl_link_info_ops *rtnl_link_info_ops_lookup(const char *);
     67 extern void			rtnl_link_info_ops_put(struct rtnl_link_info_ops *);
     68 extern int			rtnl_link_register_info(struct rtnl_link_info_ops *);
     69 extern int			rtnl_link_unregister_info(struct rtnl_link_info_ops *);
     70 
     71 
     72 /**
     73  * @ingroup link_api
     74  *
     75  * Available operations to modules implementing a link address family.
     76  */
     77 struct rtnl_link_af_ops
     78 {
     79 	/** The address family this operations set implements */
     80 	const unsigned int	ao_family;
     81 
     82 	/** Number of users of this operations, DO NOT MODIFY. */
     83 	int			ao_refcnt;
     84 
     85 	/** Validation policy for IFLA_PROTINFO attribute. This pointer
     86 	 * can be set to a nla_policy structure describing the minimal
     87 	 * requirements the attribute must meet. Failure of meeting these
     88 	 * requirements will result in a parsing error. */
     89 	const struct nla_policy *ao_protinfo_policy;
     90 
     91 	/** Called after address family has been assigned to link. Must
     92 	 * allocate data buffer to hold address family specific data and
     93 	 * store it in link->l_af_data. */
     94 	void *		      (*ao_alloc)(struct rtnl_link *);
     95 
     96 	/** Called when the link is cloned, must allocate a clone of the
     97 	 * address family specific buffer and return it. */
     98 	void *		      (*ao_clone)(struct rtnl_link *, void *);
     99 
    100 	/** Called when the link gets freed. Must free all allocated data */
    101 	void		      (*ao_free)(struct rtnl_link *, void *);
    102 
    103 	/** Called if a IFLA_PROTINFO attribute needs to be parsed. Typically
    104 	 * stores the parsed data in the address family specific buffer. */
    105 	int		      (*ao_parse_protinfo)(struct rtnl_link *,
    106 						   struct nlattr *, void *);
    107 
    108 	/** Called if a IFLA_AF_SPEC attribute needs to be parsed. Typically
    109 	 * stores the parsed data in the address family specific buffer. */
    110 	int		      (*ao_parse_af)(struct rtnl_link *,
    111 					     struct nlattr *, void *);
    112 
    113 	/** Called if a link message is sent to the kernel. Must append the
    114 	 * link address family specific attributes to the message. */
    115 	int		      (*ao_fill_af)(struct rtnl_link *,
    116 					    struct nl_msg *msg, void *);
    117 
    118 	/** Dump address family specific link attributes */
    119 	void		      (*ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *,
    120 							struct nl_dump_params *,
    121 							void *);
    122 
    123 	/** Comparison function
    124 	 *
    125 	 * Will be called when two links are compared for their af data. It
    126 	 * takes two link objects in question, an object specific bitmask
    127 	 * defining which attributes should be compared and flags to control
    128 	 * the behaviour
    129 	 *
    130 	 * The function must return a bitmask with the relevant bit set for
    131 	 * each attribute that mismatches
    132 	 */
    133 	int		      (*ao_compare)(struct rtnl_link *,
    134 					    struct rtnl_link *, int, uint32_t, int);
    135 };
    136 
    137 extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int);
    138 extern void			rtnl_link_af_ops_put(struct rtnl_link_af_ops *);
    139 extern void *			rtnl_link_af_alloc(struct rtnl_link *,
    140 						const struct rtnl_link_af_ops *);
    141 extern void *			rtnl_link_af_data(const struct rtnl_link *,
    142 						const struct rtnl_link_af_ops *);
    143 extern int			rtnl_link_af_register(struct rtnl_link_af_ops *);
    144 extern int			rtnl_link_af_unregister(struct rtnl_link_af_ops *);
    145 extern int			rtnl_link_af_data_compare(struct rtnl_link *a,
    146 							  struct rtnl_link *b,
    147 							  int family);
    148 
    149 #ifdef __cplusplus
    150 }
    151 #endif
    152 
    153 #endif
    154