64 #include <netlink-private/netlink.h> 65 #include <netlink/netlink.h> 66 #include <netlink/netfilter/nfnl.h> 68 #include <linux/netfilter/nfnetlink.h> 111 int flags, uint8_t family, uint16_t res_id)
113 struct nfgenmsg hdr = {
114 .nfgen_family = family,
115 .version = NFNETLINK_V0,
116 .res_id = htons(res_id),
136 return NFNL_SUBSYS_ID(nlh->nlmsg_type);
145 return NFNL_MSG_TYPE(nlh->nlmsg_type);
156 return nfg->nfgen_family;
167 return ntohs(nfg->res_id);
177 static int nfnlmsg_append(
struct nl_msg *msg, uint8_t family, uint16_t res_id)
179 struct nfgenmsg *nfg;
185 nfg->nfgen_family = family;
186 nfg->version = NFNETLINK_V0;
187 nfg->res_id = htons(res_id);
188 NL_DBG(2,
"msg %p: Added nfnetlink header family=%d res_id=%d\n",
189 msg, family, res_id);
204 uint8_t family, uint16_t res_id)
212 if (nfnlmsg_append(msg, family, res_id) < 0)
213 goto nla_put_failure;
234 uint8_t subsys_id, uint8_t type,
int flags, uint8_t family,
237 struct nlmsghdr *nlh;
239 nlh =
nlmsg_put(msg, pid, seq, NFNLMSG_TYPE(subsys_id, type), 0, flags);
243 return nfnlmsg_append(msg, family, res_id);
void nlmsg_free(struct nl_msg *msg)
Release a reference from an 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.
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.
int nl_connect(struct nl_sock *sk, int protocol)
Create file descriptor and bind 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.
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_family(struct nlmsghdr *nlh)
Get netfilter family from message.
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf, size_t size)
Construct and transmit a Netlink message.
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
int nfnl_connect(struct nl_sock *sk)
Create and connect netfilter netlink socket.
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.