libnl: /data/src/libnl/include/netlink/genl/mngt.h Source File

libnl 3.12.0

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