12 #ifndef NETLINK_MSG_H_ 13 #define NETLINK_MSG_H_ 15 #include <netlink/netlink.h> 16 #include <netlink/object.h> 17 #include <netlink/attr.h> 35 #define NL_AUTO_PORT 0 36 #define NL_AUTO_PID NL_AUTO_PORT 56 extern void *
nlmsg_data(
const struct nlmsghdr *);
58 extern void * nlmsg_tail(
const struct nlmsghdr *);
61 extern struct nlattr *
nlmsg_attrdata(
const struct nlmsghdr *,
int);
65 extern int nlmsg_valid_hdr(
const struct nlmsghdr *,
int);
66 extern int nlmsg_ok(
const struct nlmsghdr *,
int);
67 extern struct nlmsghdr *
nlmsg_next(
struct nlmsghdr *,
int *);
68 extern int nlmsg_parse(
struct nlmsghdr *,
int,
struct nlattr **,
81 extern int nlmsg_append(
struct nl_msg *,
void *,
size_t,
int);
84 extern struct nlmsghdr *
nlmsg_put(
struct nl_msg *, uint32_t, uint32_t,
86 extern struct nlmsghdr *
nlmsg_hdr(
struct nl_msg *);
91 extern void nlmsg_set_proto(
struct nl_msg *,
int);
92 extern int nlmsg_get_proto(
struct nl_msg *);
93 extern size_t nlmsg_get_max_size(
struct nl_msg *);
94 extern void nlmsg_set_src(
struct nl_msg *,
struct sockaddr_nl *);
95 extern struct sockaddr_nl *nlmsg_get_src(
struct nl_msg *);
96 extern void nlmsg_set_dst(
struct nl_msg *,
struct sockaddr_nl *);
97 extern struct sockaddr_nl *nlmsg_get_dst(
struct nl_msg *);
98 extern void nlmsg_set_creds(
struct nl_msg *,
struct ucred *);
99 extern struct ucred * nlmsg_get_creds(
struct nl_msg *);
101 extern char * nl_nlmsgtype2str(
int,
char *,
size_t);
102 extern int nl_str2nlmsgtype(
const char *);
104 extern char * nl_nlmsg_flags2str(
int,
char *,
size_t);
106 extern int nl_msg_parse(
struct nl_msg *,
107 void (*cb)(
struct nl_object *,
void *),
125 #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \ 126 nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \ 127 nlmsg_attrlen(nlh, hdrlen), rem) 135 #define nlmsg_for_each(pos, head, len) \ 136 for (int rem = len, pos = head; \ 137 nlmsg_ok(pos, rem); \ 138 pos = nlmsg_next(pos, &rem)) 140 #define nlmsg_for_each_msg(pos, head, len, rem) \ 141 nlmsg_for_each(pos, head, len) struct nl_msg * nlmsg_alloc_size(size_t)
Allocate a new netlink message with maximum payload size specified.
void nlmsg_free(struct nl_msg *)
Release a reference from an netlink message.
int nlmsg_attrlen(const struct nlmsghdr *, int)
length of attributes data
void * nlmsg_data(const struct nlmsghdr *)
Return pointer to message payload.
int nlmsg_size(int)
Calculates size of netlink message based on payload length.
struct nl_msg * nlmsg_inherit(struct nlmsghdr *)
Allocate a new netlink message and inherit netlink message header.
void * nlmsg_reserve(struct nl_msg *, size_t, int)
Reserve room for additional data in a netlink message.
Attribute validation policy.
struct nl_msg * nlmsg_alloc(void)
Allocate a new netlink message with the default maximum payload size.
void nlmsg_set_default_size(size_t)
Set the default maximum message payload size for allocated messages.
int nlmsg_ok(const struct nlmsghdr *, int)
check if the netlink message fits into the remaining bytes
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
parse attributes of a netlink message
struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int)
nlmsg_find_attr - find a specific attribute in a netlink message
int nlmsg_total_size(int)
Calculates size of netlink message including padding based on payload length.
struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int)
head of attributes data
struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *)
next netlink message in message stream
struct nlmsghdr * nlmsg_put(struct nl_msg *, uint32_t, uint32_t, int, int, int)
Add a netlink message header to a netlink message.
int nlmsg_datalen(const struct nlmsghdr *)
Return length of message payload.
void nl_msg_dump(struct nl_msg *, FILE *)
Dump message in human readable format to file descriptor.
struct nlmsghdr * nlmsg_hdr(struct nl_msg *)
Return actual netlink message.
int nlmsg_expand(struct nl_msg *, size_t)
Expand maximum payload size of a netlink message.
int nlmsg_padlen(int)
Size of padding that needs to be added at end of message.
void nlmsg_get(struct nl_msg *)
Acquire a reference on a netlink message.
int nlmsg_append(struct nl_msg *, void *, size_t, int)
Append data to tail of a netlink message.
struct nl_msg * nlmsg_alloc_simple(int, int)
Allocate a new netlink message.
int nlmsg_validate(struct nlmsghdr *, int, int, struct nla_policy *)
nlmsg_validate - validate a netlink message including attributes
struct nl_msg * nlmsg_convert(struct nlmsghdr *)
Convert a netlink message received from a netlink socket to a nl_msg.