libnl: /data/src/libnl3/lib/route/link/link-api.h Source File

libnl 3.10.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 */
19 struct rtnl_link_info_ops
20{
21 /** Name of link info type, must match name on kernel side */
22 char * io_name;
23
24 /** Reference count, DO NOT MODIFY */
25 int io_refcnt;
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 *);
66extern int rtnl_link_register_info(struct rtnl_link_info_ops *);
67extern int rtnl_link_unregister_info(struct rtnl_link_info_ops *);
68
69
70/**
71 * @ingroup link_api
72 *
73 * Available operations to modules implementing a link address family.
74 */
75 struct rtnl_link_af_ops
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. */
81 int ao_refcnt;
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. */
87 const struct nla_policy *ao_protinfo_policy;
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. */
103 int (*ao_parse_protinfo)(struct rtnl_link *,
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. */
118 int (*ao_parse_af_full)(struct rtnl_link *,
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 */
163 const int ao_fill_pi_flags;
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 */
171 const int ao_fill_af_no_nest;
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
rtnl_link_af_ops_put
void rtnl_link_af_ops_put(struct rtnl_link_af_ops *)
Give back reference to a set of operations.
Definition api.c:226
rtnl_link_register_info
int rtnl_link_register_info(struct rtnl_link_info_ops *)
Register operations for a link info type.
Definition api.c:127
rtnl_link_af_alloc
void * rtnl_link_af_alloc(struct rtnl_link *, const struct rtnl_link_af_ops *)
Allocate and return data buffer for link address family modules.
Definition api.c:249
rtnl_link_info_data_compare
int rtnl_link_info_data_compare(struct rtnl_link *a, struct rtnl_link *b, int flags)
Compare link info data.
Definition api.c:425
rtnl_link_unregister_info
int rtnl_link_unregister_info(struct rtnl_link_info_ops *)
Unregister operations for a link info type.
Definition api.c:162
rtnl_link_info_ops_get
void rtnl_link_info_ops_get(struct rtnl_link_info_ops *)
Take reference to a set of operations.
Definition api.c:90
rtnl_link_af_unregister
int rtnl_link_af_unregister(struct rtnl_link_af_ops *)
Unregister operations for a link address family.
Definition api.c:344
rtnl_link_af_register
int rtnl_link_af_register(struct rtnl_link_af_ops *)
Register operations for a link address family.
Definition api.c:305
rtnl_link_info_ops_lookup
struct rtnl_link_info_ops * rtnl_link_info_ops_lookup(const char *)
Return operations of a specific link info type.
Definition api.c:74
rtnl_link_af_data_compare
int rtnl_link_af_data_compare(struct rtnl_link *a, struct rtnl_link *b, int family)
Compare af data for a link address family.
Definition api.c:385
rtnl_link_info_ops_put
void rtnl_link_info_ops_put(struct rtnl_link_info_ops *)
Give back reference to a set of operations.
Definition api.c:104
rtnl_link_af_ops_lookup
struct rtnl_link_af_ops * rtnl_link_af_ops_lookup(unsigned int)
Return operations of a specific link address family.
Definition api.c:209
rtnl_link_af_data
void * rtnl_link_af_data(const struct rtnl_link *, const struct rtnl_link_af_ops *)
Return data buffer for link address family modules.
Definition api.c:284
nl_dump_params
Dumping parameters.
Definition types.h:32
nl_list_head
Definition list.h:16
nla_policy
Attribute validation policy.
Definition attr.h:63
rtnl_link_af_ops
Available operations to modules implementing a link address family.
Definition link-api.h:76
rtnl_link_af_ops::ao_protinfo_policy
const struct nla_policy * ao_protinfo_policy
Validation policy for IFLA_PROTINFO attribute.
Definition link-api.h:87
rtnl_link_af_ops::ao_parse_protinfo
int(* ao_parse_protinfo)(struct rtnl_link *, struct nlattr *, void *)
Called if a IFLA_PROTINFO attribute needs to be parsed.
Definition link-api.h:103
rtnl_link_af_ops::ao_free
void(* ao_free)(struct rtnl_link *, void *)
Called when the link gets freed.
Definition link-api.h:99
rtnl_link_af_ops::ao_compare
int(* ao_compare)(struct rtnl_link *, struct rtnl_link *, int, uint32_t, int)
Comparison function.
Definition link-api.h:141
rtnl_link_af_ops::ao_fill_pi
int(* ao_fill_pi)(struct rtnl_link *, struct nl_msg *msg, void *)
Called if a link message is sent to the kernel.
Definition link-api.h:154
rtnl_link_af_ops::ao_fill_af_no_nest
const int ao_fill_af_no_nest
IFLA_AF_SPEC nesting override.
Definition link-api.h:171
rtnl_link_af_ops::ao_family
const unsigned int ao_family
The address family this operations set implements.
Definition link-api.h:78
rtnl_link_af_ops::ao_dump
void(* ao_dump[NL_DUMP_MAX+1])(struct rtnl_link *, struct nl_dump_params *, void *)
Dump address family specific link attributes.
Definition link-api.h:127
rtnl_link_af_ops::ao_parse_af
int(* ao_parse_af)(struct rtnl_link *, struct nlattr *, void *)
Called if a IFLA_AF_SPEC attribute needs to be parsed.
Definition link-api.h:108
rtnl_link_af_ops::ao_parse_af_full
int(* ao_parse_af_full)(struct rtnl_link *, struct nlattr *, void *)
Called if the full IFLA_AF_SPEC data needs to be parsed.
Definition link-api.h:118
rtnl_link_af_ops::ao_get_af
int(* ao_get_af)(struct nl_msg *msg, uint32_t *ext_filter_mask)
Called for GETLINK message to the kernel.
Definition link-api.h:123
rtnl_link_af_ops::ao_refcnt
int ao_refcnt
Number of users of this operations, DO NOT MODIFY.
Definition link-api.h:81
rtnl_link_af_ops::ao_fill_af
int(* ao_fill_af)(struct rtnl_link *, struct nl_msg *msg, void *)
Called if a link message is sent to the kernel.
Definition link-api.h:113
rtnl_link_af_ops::ao_fill_pi_flags
const int ao_fill_pi_flags
PROTINFO type.
Definition link-api.h:163
rtnl_link_info_ops
Available operations to modules implementing a link info type.
Definition link-api.h:20
rtnl_link_info_ops::io_name
char * io_name
Name of link info type, must match name on kernel side.
Definition link-api.h:22
rtnl_link_info_ops::io_dump
void(* io_dump[NL_DUMP_MAX+1])(struct rtnl_link *, struct nl_dump_params *)
Called when the link object is dumped.
Definition link-api.h:41
rtnl_link_info_ops::io_free
void(* io_free)(struct rtnl_link *)
Called to release all resources previously allocated in either io_alloc() or io_parse().
Definition link-api.h:54
rtnl_link_info_ops::io_refcnt
int io_refcnt
Reference count, DO NOT MODIFY.
Definition link-api.h:25
rtnl_link_info_ops::io_compare
int(* io_compare)(struct rtnl_link *, struct rtnl_link *, int flags)
Called to compare link info parameters between two links.
Definition link-api.h:57
rtnl_link_info_ops::io_alloc
int(* io_alloc)(struct rtnl_link *)
Called to assign an info type to a link.
Definition link-api.h:30
rtnl_link_info_ops::io_parse
int(* io_parse)(struct rtnl_link *, struct nlattr *, struct nlattr *)
Called to parse the link info attribute.
Definition link-api.h:35
rtnl_link_info_ops::io_clone
int(* io_clone)(struct rtnl_link *, struct rtnl_link *)
Called when a link object is cloned.
Definition link-api.h:46
rtnl_link_info_ops::io_put_attrs
int(* io_put_attrs)(struct nl_msg *, struct rtnl_link *)
Called when construction a link netlink message.
Definition link-api.h:50
rtnl_link
Link object.
Definition nl-route.h:29