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