|
|
int | genl_connect (struct nl_handle *handle) |
| |
|
| int | genl_send_simple (struct nl_handle *handle, int family, int cmd, int version, int flags) |
| | Send trivial generic netlink message. More...
|
| |
|
|
int | genlmsg_valid_hdr (struct nlmsghdr *nlh, int hdrlen) |
| |
|
int | genlmsg_validate (struct nlmsghdr *nlh, int hdrlen, int maxtype, struct nla_policy *policy) |
| |
|
int | genlmsg_parse (struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy) |
| |
| void * | genlmsg_data (const struct genlmsghdr *gnlh) |
| | Get head of message payload. More...
|
| |
| int | genlmsg_len (const struct genlmsghdr *gnlh) |
| | Get lenght of message payload. More...
|
| |
| struct nlattr * | genlmsg_attrdata (const struct genlmsghdr *gnlh, int hdrlen) |
| | Get head of attribute data. More...
|
| |
| int | genlmsg_attrlen (const struct genlmsghdr *gnlh, int hdrlen) |
| | Get length of attribute data. More...
|
| |
|
| void * | genlmsg_put (struct nl_msg *msg, uint32_t pid, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version) |
| | Add generic netlink header to netlink message. More...
|
| |
- Message Format
<------- NLMSG_ALIGN(hlen) ------> <---- NLMSG_ALIGN(len) --->
+----------------------------+- - -+- - - - - - - - - - -+- - -+
| Header | Pad | Payload | Pad |
+----------------------------+- - -+- - - - - - - - - - -+- - -+
<-------- GENL_HDRLEN -------> <--- hdrlen -->
+------------------------+- - -+---------------+- - -+------------+
| Generic Netlink Header | Pad | Family Header | Pad | Attributes |
| struct genlmsghdr | | | | |
+------------------------+- - -+---------------+- - -+------------+
- Example
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
struct nl_handle *sock;
struct nl_msg *msg;
int family;
genl_connect(sock);
CMD_FOO_GET, FOO_VERSION);
static int parse_cb(struct nl_msg *msg, void *arg)
{
struct nlattr *attrs[ATTR_MAX+1];
genlmsg_parse(nlh, 0, attrs, ATTR_MAX, policy);
if (attrs[ATTR_FOO]) {
...
}
return 0;
}
◆ genl_send_simple()
| int genl_send_simple |
( |
struct nl_handle * |
handle, |
|
|
int |
family, |
|
|
int |
cmd, |
|
|
int |
version, |
|
|
int |
flags |
|
) |
| |
- Parameters
-
| handle | Netlink handle. |
| family | Generic netlink family |
| cmd | Command |
| version | Version |
| flags | Additional netlink message flags. |
Fills out a routing netlink request message and sends it out using nl_send_simple().
- Returns
- 0 on success or a negative error code.
Definition at line 128 of file genl.c.
131 struct genlmsghdr hdr = {
References nl_send_simple().
◆ genlmsg_data()
| void* genlmsg_data |
( |
const struct genlmsghdr * |
gnlh | ) |
|
- Parameters
-
| gnlh | genetlink messsage header |
Definition at line 191 of file genl.c.
193 return ((
unsigned char *) gnlh + GENL_HDRLEN);
Referenced by genlmsg_attrdata().
◆ genlmsg_len()
| int genlmsg_len |
( |
const struct genlmsghdr * |
gnlh | ) |
|
◆ genlmsg_attrdata()
| struct nlattr* genlmsg_attrdata |
( |
const struct genlmsghdr * |
gnlh, |
|
|
int |
hdrlen |
|
) |
| |
- Parameters
-
| gnlh | generic netlink message header |
| hdrlen | length of family specific header |
Definition at line 212 of file genl.c.
References genlmsg_data().
◆ genlmsg_attrlen()
| int genlmsg_attrlen |
( |
const struct genlmsghdr * |
gnlh, |
|
|
int |
hdrlen |
|
) |
| |
- Parameters
-
| gnlh | generic netlink message header |
| hdrlen | length of family specific header |
Definition at line 222 of file genl.c.
References genlmsg_len().
◆ genlmsg_put()
| void* genlmsg_put |
( |
struct nl_msg * |
msg, |
|
|
uint32_t |
pid, |
|
|
uint32_t |
seq, |
|
|
int |
family, |
|
|
int |
hdrlen, |
|
|
int |
flags, |
|
|
uint8_t |
cmd, |
|
|
uint8_t |
version |
|
) |
| |
- Parameters
-
| msg | netlink message |
| pid | netlink process id or NL_AUTO_PID |
| seq | sequence number of message or NL_AUTO_SEQ |
| family | generic netlink family |
| hdrlen | length of user specific header |
| flags | message flags |
| cmd | generic netlink command |
| version | protocol version |
Returns pointer to user specific header.
Definition at line 247 of file genl.c.
251 struct genlmsghdr hdr = {
256 nlh =
nlmsg_put(msg, pid, seq, family, GENL_HDRLEN + hdrlen, flags);
261 NL_DBG(2,
"msg %p: Added generic netlink header cmd=%d version=%d\n",
References nlmsg_data(), and nlmsg_put().
void * nlmsg_data(const struct nlmsghdr *nlh)
head of message payload
struct nlattr * genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen)
Get head of attribute data.
int nl_recvmsgs_default(struct nl_handle *handle)
Receive a set of message from a netlink socket using handlers in nl_handle.
struct nl_handle * nl_handle_alloc(void)
Allocate new netlink socket handle.
uint32_t nlmsg_len
Length of message including header.
@ NL_CB_CUSTOM
Customized handler specified by the user.
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of u32 attribute.
int nl_send_simple(struct nl_handle *handle, int type, int flags, void *buf, size_t size)
Send simple netlink message using nl_send_auto_complete()
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
int genlmsg_len(const struct genlmsghdr *gnlh)
Get lenght of message payload.
struct nl_msg * nlmsg_alloc(void)
Allocate a new netlink message with the default maximum payload size.
int nla_put_u32(struct nl_msg *n, int attrtype, uint32_t value)
Add a u32 netlink attribute to a netlink message.
#define NL_AUTO_PID
Will cause the netlink pid to be set to the pid assigned to the netlink handle (socket) just before s...
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
void * genlmsg_put(struct nl_msg *msg, uint32_t pid, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version)
Add generic netlink header to netlink message.
struct nlmsghdr * nlmsg_hdr(struct nl_msg *n)
Return actual netlink message.
int genl_ctrl_resolve(struct nl_handle *handle, const char *name)
Resolve generic netlink family name to its identifier.
int nl_socket_modify_cb(struct nl_handle *handle, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Modify the callback handler associated to the socket.
struct nlmsghdr * nlmsg_put(struct nl_msg *n, uint32_t pid, uint32_t seq, int type, int payload, int flags)
Add a netlink message header to a netlink message.
#define NL_AUTO_SEQ
May be used to refer to a sequence number which should be automatically set just before sending the m...
#define NLM_F_ECHO
Echo this request.
void * genlmsg_data(const struct genlmsghdr *gnlh)
Get head of message payload.
@ NL_CB_VALID
Message is valid.