diff options
author | Duncan Roe <duncan_roe@optusnet.com.au> | 2020-02-24 13:21:51 +1100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2020-02-24 10:38:43 +0100 |
commit | cbe995992145455a3b56295a138fe7a9860da295 (patch) | |
tree | 068425abbaa617bd69b369e3a7d024799dd1def0 /src | |
parent | caf166d8e6061a12ed531d5195396543d6f4dcee (diff) |
src: expose nfq_nlmsg_put
Move static nfq_hdr_put from examples/nf-queue.c into the library since
everyone is going to want it. Also rename nfq_hdr_put to nfq_nlmsg_put.
Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/nlmsg.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/nlmsg.c b/src/nlmsg.c index 4f09bf6..e141156 100644 --- a/src/nlmsg.c +++ b/src/nlmsg.c @@ -261,9 +261,9 @@ static int nfq_pkt_parse_attr_cb(const struct nlattr *attr, void *data) /** * nfq_nlmsg_parse - set packet attributes from netlink message - * \param nlh netlink message that you want to read. - * \param attr pointer to array of attributes to set. - * \returns MNL_CB_OK on success or MNL_CB_ERROR if any error occurs. + * \param nlh Pointer to netlink message + * \param attr Pointer to array of attributes to set + * \returns MNL_CB_OK on success or MNL_CB_ERROR if any error occurs */ EXPORT_SYMBOL int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr) @@ -273,5 +273,27 @@ int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr) } /** + * nfq_nlmsg_put - Convert memory buffer into a Netlink buffer + * \param *buf Pointer to memory buffer + * \param type Either NFQNL_MSG_CONFIG or NFQNL_MSG_VERDICT + * \param queue_num Queue number + * \returns Pointer to netlink message + */ +EXPORT_SYMBOL +struct nlmsghdr *nfq_nlmsg_put(char *buf, int type, uint32_t queue_num) +{ + struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf); + nlh->nlmsg_type = (NFNL_SUBSYS_QUEUE << 8) | type; + nlh->nlmsg_flags = NLM_F_REQUEST; + + struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg)); + nfg->nfgen_family = AF_UNSPEC; + nfg->version = NFNETLINK_V0; + nfg->res_id = htons(queue_num); + + return nlh; +} + +/** * @} */ |