libnl 3.5.0

mngt.h
1 /*
2 * netlink/genl/mngt.h Generic Netlink Management
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-2012 Thomas Graf <tgraf@suug.ch>
10 */
11
12 #ifndef NETLINK_GENL_MNGT_H_
13 #define NETLINK_GENL_MNGT_H_
14
15 #include <netlink/netlink.h>
16 #include <netlink/attr.h>
17 #include <netlink/list.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 struct nl_cache_ops;
24
25 /**
26 * @ingroup genl_mngt
27 * @struct genl_info netlink/genl/mngt.h
28 *
29 * Informative structure passed on to message parser callbacks
30 *
31 * This structure is passed on to all message parser callbacks and contains
32 * information about the sender of the message as well as pointers to all
33 * relevant sections of the parsed message.
34 *
35 * @see genl_cmd::c_msg_parser
36 */
37 struct genl_info
38 {
39 /** Socket address of sender */
40 struct sockaddr_nl * who;
41
42 /** Pointer to Netlink message header */
43 struct nlmsghdr * nlh;
44
45 /** Pointer to Generic Netlink message header */
46 struct genlmsghdr * genlhdr;
47
48 /** Pointer to user header */
49 void * userhdr;
50
51 /** Pointer to array of parsed attributes */
52 struct nlattr ** attrs;
53 };
54
55 /**
56 * @ingroup genl_mngt
57 * @struct genl_cmd netlink/genl/mngt.h
58 *
59 * Definition of a Generic Netlink command.
60 *
61 * This structure is used to define the list of available commands on the
62 * receiving side.
63 *
64 * @par Example:
65 * @code
66 * static struct genl_cmd foo_cmds[] = {
67 * {
68 * .c_id = FOO_CMD_NEW,
69 * .c_name = "NEWFOO" ,
70 * .c_maxattr = FOO_ATTR_MAX,
71 * .c_attr_policy = foo_policy,
72 * .c_msg_parser = foo_msg_parser,
73 * },
74 * {
75 * .c_id = FOO_CMD_DEL,
76 * .c_name = "DELFOO" ,
77 * },
78 * };
79 *
80 * static struct genl_ops my_genl_ops = {
81 * [...]
82 * .o_cmds = foo_cmds,
83 * .o_ncmds = ARRAY_SIZE(foo_cmds),
84 * };
85 * @endcode
86 */
87 struct genl_cmd
88 {
89 /** Numeric command identifier (required) */
90 int c_id;
91
92 /** Human readable name (required) */
93 char * c_name;
94
95 /** Maximum attribute identifier that the command is prepared to handle. */
96 int c_maxattr;
97
98 /** Called whenever a message for this command is received */
99 int (*c_msg_parser)(struct nl_cache_ops *,
100 struct genl_cmd *,
101 struct genl_info *, void *);
102
103 /** Attribute validation policy, enforced before the callback is called */
104 struct nla_policy * c_attr_policy;
105 };
106
107 /**
108 * @ingroup genl_mngt
109 * @struct genl_ops netlink/genl/mngt.h
110 *
111 * Definition of a Generic Netlink family
112 *
113 * @par Example:
114 * @code
115 * static struct genl_cmd foo_cmds[] = {
116 * [...]
117 * };
118 *
119 * static struct genl_ops my_genl_ops = {
120 * .o_name = "foo",
121 * .o_hdrsize = sizeof(struct my_hdr),
122 * .o_cmds = foo_cmds,
123 * .o_ncmds = ARRAY_SIZE(foo_cmds),
124 * };
125 *
126 * if ((err = genl_register_family(&my_genl_ops)) < 0)
127 * // ERROR
128 * @endcode
129 *
130 * @see genl_cmd
131 */
132 struct genl_ops
133 {
134 /** Length of user header */
135 unsigned int o_hdrsize;
136
137 /** Numeric identifier, automatically filled in by genl_ops_resolve() */
138 int o_id;
139
140 /** Human readable name, used by genl_ops_resolve() to resolve numeric id */
141 char * o_name;
142
143 /**
144 * If registered via genl_register(), will point to the related
145 * cache operations.
146 */
147 struct nl_cache_ops * o_cache_ops;
148
149 /** Optional array defining the available Generic Netlink commands */
150 struct genl_cmd * o_cmds;
151
152 /** Number of elements in \c o_cmds array */
153 int o_ncmds;
154
155 /**
156 * @private
157 * Used internally to link together all registered operations.
158 */
159 struct nl_list_head o_list;
160 };
161
162 extern int genl_register_family(struct genl_ops *);
163 extern int genl_unregister_family(struct genl_ops *);
164 extern int genl_handle_msg(struct nl_msg *, void *);
165
166 extern int genl_register(struct nl_cache_ops *);
167 extern void genl_unregister(struct nl_cache_ops *);
168
169 extern int genl_ops_resolve(struct nl_sock *, struct genl_ops *);
170 extern int genl_mngt_resolve(struct nl_sock *);
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif
genl_info::who
struct sockaddr_nl * who
Socket address of sender.
Definition: mngt.h:40
genl_mngt_resolve
int genl_mngt_resolve(struct nl_sock *)
Resolve all registered Generic Netlink families.
Definition: mngt.c:386
genl_cmd::c_attr_policy
struct nla_policy * c_attr_policy
Attribute validation policy, enforced before the callback is called.
Definition: mngt.h:104
genl_handle_msg
int genl_handle_msg(struct nl_msg *, void *)
Run a received message through the demultiplexer.
Definition: mngt.c:215
genl_register
int genl_register(struct nl_cache_ops *)
Register Generic Netlink family backed cache.
Definition: mngt.c:248
genl_ops::o_cmds
struct genl_cmd * o_cmds
Optional array defining the available Generic Netlink commands.
Definition: mngt.h:150
genl_cmd
Definition of a Generic Netlink command.
Definition: mngt.h:87
nla_policy
Attribute validation policy.
Definition: attr.h:69
genl_cmd::c_name
char * c_name
Human readable name (required)
Definition: mngt.h:93
genl_ops::o_ncmds
int o_ncmds
Number of elements in o_cmds array.
Definition: mngt.h:153
genl_unregister_family
int genl_unregister_family(struct genl_ops *)
Unregister Generic Netlink family.
Definition: mngt.c:201
genl_cmd::c_id
int c_id
Numeric command identifier (required)
Definition: mngt.h:90
genl_unregister
void genl_unregister(struct nl_cache_ops *)
Unregister cache based Generic Netlink family.
Definition: mngt.c:285
genl_ops
Definition of a Generic Netlink family.
Definition: mngt.h:132
genl_ops_resolve
int genl_ops_resolve(struct nl_sock *, struct genl_ops *)
Resolve a single Generic Netlink family.
Definition: mngt.c:358
genl_info
Informative structure passed on to message parser callbacks.
Definition: mngt.h:37
genl_register_family
int genl_register_family(struct genl_ops *)
Register Generic Netlink family and associated commands.
Definition: mngt.c:171
genl_ops::o_cache_ops
struct nl_cache_ops * o_cache_ops
If registered via genl_register(), will point to the related cache operations.
Definition: mngt.h:147
genl_info::genlhdr
struct genlmsghdr * genlhdr
Pointer to Generic Netlink message header.
Definition: mngt.h:46
genl_info::nlh
struct nlmsghdr * nlh
Pointer to Netlink message header.
Definition: mngt.h:43
genl_ops::o_hdrsize
unsigned int o_hdrsize
Length of user header.
Definition: mngt.h:135
genl_ops::o_id
int o_id
Numeric identifier, automatically filled in by genl_ops_resolve()
Definition: mngt.h:138
genl_ops::o_name
char * o_name
Human readable name, used by genl_ops_resolve() to resolve numeric id.
Definition: mngt.h:141
genl_info::attrs
struct nlattr ** attrs
Pointer to array of parsed attributes.
Definition: mngt.h:52
nl_list_head
Definition: list.h:17
genl_cmd::c_msg_parser
int(* c_msg_parser)(struct nl_cache_ops *, struct genl_cmd *, struct genl_info *, void *)
Called whenever a message for this command is received.
Definition: mngt.h:99
genl_ops::o_list
struct nl_list_head o_list
Used internally to link together all registered operations.
Definition: mngt.h:159
genl_cmd::c_maxattr
int c_maxattr
Maximum attribute identifier that the command is prepared to handle.
Definition: mngt.h:96
genl_info::userhdr
void * userhdr
Pointer to user header.
Definition: mngt.h:49