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