From cbe995992145455a3b56295a138fe7a9860da295 Mon Sep 17 00:00:00 2001 From: Duncan Roe Date: Mon, 24 Feb 2020 13:21:51 +1100 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- examples/nf-queue.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'examples') diff --git a/examples/nf-queue.c b/examples/nf-queue.c index 960e244..3da2c24 100644 --- a/examples/nf-queue.c +++ b/examples/nf-queue.c @@ -20,21 +20,6 @@ static struct mnl_socket *nl; -static struct nlmsghdr * -nfq_hdr_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; -} - static void nfq_send_verdict(int queue_num, uint32_t id) { @@ -42,7 +27,7 @@ nfq_send_verdict(int queue_num, uint32_t id) struct nlmsghdr *nlh; struct nlattr *nest; - nlh = nfq_hdr_put(buf, NFQNL_MSG_VERDICT, queue_num); + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_VERDICT, queue_num); nfq_nlmsg_verdict_put(nlh, id, NF_ACCEPT); /* example to set the connmark. First, start NFQA_CT section: */ @@ -150,7 +135,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, queue_num); + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND); if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { @@ -158,7 +143,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, queue_num); + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); nfq_nlmsg_cfg_put_params(nlh, NFQNL_COPY_PACKET, 0xffff); mnl_attr_put_u32(nlh, NFQA_CFG_FLAGS, htonl(NFQA_CFG_F_GSO)); -- cgit v1.2.3