58#include <netlink-private/netlink.h>
59#include <netlink/netlink.h>
60#include <netlink/netfilter/nfnl.h>
62#include <linux/netfilter/nfnetlink.h>
105 int flags, uint8_t family, uint16_t res_id)
107 struct nfgenmsg hdr = {
108 .nfgen_family = family,
109 .version = NFNETLINK_V0,
110 .res_id = htons(res_id),
130 return NFNL_SUBSYS_ID(nlh->nlmsg_type);
139 return NFNL_MSG_TYPE(nlh->nlmsg_type);
150 return nfg->nfgen_family;
161 return ntohs(nfg->res_id);
171static int nfnlmsg_append(
struct nl_msg *msg, uint8_t family, uint16_t res_id)
173 struct nfgenmsg *nfg;
179 nfg->nfgen_family = family;
180 nfg->version = NFNETLINK_V0;
181 nfg->res_id = htons(res_id);
182 NL_DBG(2,
"msg %p: Added nfnetlink header family=%d res_id=%d\n",
183 msg, family, res_id);
198 uint8_t family, uint16_t res_id)
206 if (nfnlmsg_append(msg, family, res_id) < 0)
207 goto nla_put_failure;
228 uint8_t subsys_id, uint8_t type,
int flags, uint8_t family,
231 struct nlmsghdr *nlh;
233 nlh =
nlmsg_put(msg, pid, seq, NFNLMSG_TYPE(subsys_id, type), 0, flags);
237 return nfnlmsg_append(msg, family, res_id);
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
void * nlmsg_data(const struct nlmsghdr *nlh)
Return pointer to message payload.
void * nlmsg_reserve(struct nl_msg *n, size_t len, int pad)
Reserve room for additional data in a netlink message.
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
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.
uint16_t nfnlmsg_res_id(struct nlmsghdr *nlh)
Get netfilter resource id from message.
uint8_t nfnlmsg_subsys(struct nlmsghdr *nlh)
Get netfilter subsystem id from message.
uint8_t nfnlmsg_family(struct nlmsghdr *nlh)
Get netfilter family from message.
int nfnlmsg_put(struct nl_msg *msg, uint32_t pid, uint32_t seq, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Add netlink and netfilter netlink headers to netlink message.
int nfnl_connect(struct nl_sock *sk)
Create and connect netfilter netlink socket.
int nfnl_send_simple(struct nl_sock *sk, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Send trivial netfilter netlink message.
uint8_t nfnlmsg_subtype(struct nlmsghdr *nlh)
Get netfilter message type from message.
struct nl_msg * nfnlmsg_alloc_simple(uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Allocate a new netfilter netlink message.
int nl_connect(struct nl_sock *sk, int protocol)
Create file descriptor and bind socket.
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf, size_t size)
Construct and transmit a Netlink message.