65 #include <netlink-local.h> 66 #include <netlink/netlink.h> 67 #include <netlink/netfilter/nfnl.h> 109 int flags, uint8_t family, uint16_t res_id)
111 struct nfgenmsg hdr = {
112 .nfgen_family = family,
113 .version = NFNETLINK_V0,
114 .res_id = htons(res_id),
117 return nl_send_simple(handle, NFNLMSG_TYPE(subsys_id, type), flags,
154 return nfg->nfgen_family;
165 return ntohs(nfg->res_id);
175 static int nfnlmsg_append(
struct nl_msg *msg, uint8_t family, uint16_t res_id)
177 struct nfgenmsg *nfg;
181 return nl_errno(ENOMEM);
183 nfg->nfgen_family = family;
184 nfg->version = NFNETLINK_V0;
185 nfg->res_id = htons(res_id);
186 NL_DBG(2,
"msg %p: Added nfnetlink header family=%d res_id=%d\n",
187 msg, family, res_id);
202 uint8_t family, uint16_t res_id)
210 if (nfnlmsg_append(msg, family, res_id) < 0)
211 goto nla_put_failure;
232 uint8_t subsys_id, uint8_t type,
int flags, uint8_t family,
237 nlh =
nlmsg_put(msg, pid, seq, NFNLMSG_TYPE(subsys_id, type), 0, flags);
239 return nl_get_errno();
241 return nfnlmsg_append(msg, family, res_id);
void * nlmsg_data(const struct nlmsghdr *nlh)
head of message payload
uint16_t nlmsg_type
Message type (content type)
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 *n)
Free a netlink message.
uint8_t nfnlmsg_subsys(struct nlmsghdr *nlh)
Get netfilter subsystem id from message.
uint8_t nfnlmsg_subtype(struct nlmsghdr *nlh)
Get netfilter message type 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.
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.
int nfnl_connect(struct nl_handle *handle)
Create and connect netfilter netlink socket.
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()
uint8_t nfnlmsg_family(struct nlmsghdr *nlh)
Get netfilter family from message.
int nfnl_send_simple(struct nl_handle *handle, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Send trivial netfilter netlink message.
int nl_connect(struct nl_handle *handle, int protocol)
Create and connect netlink socket.
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink 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.
uint16_t nfnlmsg_res_id(struct nlmsghdr *nlh)
Get netfilter resource id from message.