All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Ken-ichirou MATSUZAWA <chamaken@gmail.com>
Cc: The netfilter developer mailinglist <netfilter-devel@vger.kernel.org>
Subject: Re: [lnf-log RFC PATCH 2/2] utils: take a example from libmnl and use nflog_nlmsg_parse
Date: Tue, 18 Aug 2015 08:04:22 +0200	[thread overview]
Message-ID: <20150818060409.GA3062@salvia> (raw)
In-Reply-To: <20150810081752.GD25169@gmail.com>

This code can be generalized a bit so you can place it in
src/nlmsg.c, see below.

On Mon, Aug 10, 2015 at 05:17:53PM +0900, Ken-ichirou MATSUZAWA wrote:
[...]
> +static struct nlmsghdr *
> +nflog_build_cfg_pf_request(char *buf, uint8_t command)
> +{
> +	struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
> +	nlh->nlmsg_type	= (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG;
> +	nlh->nlmsg_flags = NLM_F_REQUEST;
> +
> +	struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
> +	nfg->nfgen_family = AF_INET;
> +	nfg->version = NFNETLINK_V0;
> +
> +	struct nfulnl_msg_config_cmd cmd = {
> +		.command = command,
> +	};
> +	mnl_attr_put(nlh, NFULA_CFG_CMD, sizeof(cmd), &cmd);
> +
> +	return nlh;
> +}

I suggest you use and implement the following new helper functions for
libnetfilter_log:

struct nlmsghdr *
nfnl_nlmsg_put_header(char *buf, uint8_t type, uint8_t cmd, uint16_t qnum);

int nfnl_attr_put_cfg_mode(struct nlmsghdr *nlh, struct nfulnl_msg_config_mode *mode);
int nfnl_attr_put_cfg_cmd(struct nlmsghdr *nlh, struct nfulnl_msg_config_cmd *cmd);

You can reuse code in the functions here below to make it. Thanks.

> +static struct nlmsghdr *
> +nflog_build_cfg_request(char *buf, uint8_t command, int qnum)
> +{
> +	struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
> +	nlh->nlmsg_type	= (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG;
> +	nlh->nlmsg_flags = NLM_F_REQUEST;
> +
> +	struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
> +	nfg->nfgen_family = AF_INET;
> +	nfg->version = NFNETLINK_V0;
> +	nfg->res_id = htons(qnum);
> +
> +	struct nfulnl_msg_config_cmd cmd = {
> +		.command = command,
> +	};
> +	mnl_attr_put(nlh, NFULA_CFG_CMD, sizeof(cmd), &cmd);
> +
> +	return nlh;
> +}
> +
> +static struct nlmsghdr *
> +nflog_build_cfg_params(char *buf, uint8_t mode, int range, int qnum)
> +{
> +	struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
> +	nlh->nlmsg_type	= (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG;
> +	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(qnum);
> +
> +	struct nfulnl_msg_config_mode params = {
> +		.copy_range = htonl(range),
> +		.copy_mode = mode,
> +	};
> +	mnl_attr_put(nlh, NFULA_CFG_MODE, sizeof(params), &params);
> +
> +	return nlh;
> +}
> +
[...]

  reply	other threads:[~2015-08-18  5:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-10  8:13 [lnf-log RFC PATCH 0/2] introduce new functions to use without nflog_handle Ken-ichirou MATSUZAWA
2015-08-10  8:15 ` [lnf-log RFC PATCH 1/2] " Ken-ichirou MATSUZAWA
2015-08-18  5:48   ` Pablo Neira Ayuso
2015-08-10  8:17 ` [lnf-log RFC PATCH 2/2] utils: take a example from libmnl and use nflog_nlmsg_parse Ken-ichirou MATSUZAWA
2015-08-18  6:04   ` Pablo Neira Ayuso [this message]
2015-08-19  7:11     ` Ken-ichirou MATSUZAWA
2015-08-19  7:13       ` [lnf-log RFC PATCH v2 1/2] introduce new functions independent from libnfnetlink Ken-ichirou MATSUZAWA
2015-08-19  7:15       ` [lnf-log RFC PATCH v2 2/2] utils: take a example from libmnl and use new functions Ken-ichirou MATSUZAWA
2015-08-19 22:04       ` [lnf-log RFC PATCH 2/2] utils: take a example from libmnl and use nflog_nlmsg_parse Pablo Neira Ayuso
2015-08-20  7:26         ` Ken-ichirou MATSUZAWA
2015-08-20  7:29           ` [lnf-log PATCH 1/2] introduce new functions independent from libnfnetlink Ken-ichirou MATSUZAWA
2015-08-20  7:31           ` [lnf-log PATCH 2/2] utils: take a example from libmnl and use new functions Ken-ichirou MATSUZAWA
2015-08-20 18:16           ` [lnf-log RFC PATCH 2/2] utils: take a example from libmnl and use nflog_nlmsg_parse Pablo Neira Ayuso
2015-08-21  0:23             ` Ken-ichirou MATSUZAWA
2015-08-21  0:26               ` [lnf-log PATCHv2 1/3] introduce new functions independent from libnfnetlink Ken-ichirou MATSUZAWA
2015-08-26 19:01                 ` Pablo Neira Ayuso
2015-08-21  0:27               ` [lnf-log PATCHv2 2/3] utils: take a example from libmnl and use new functions Ken-ichirou MATSUZAWA
2015-08-26 19:01                 ` Pablo Neira Ayuso
2015-08-21  0:30               ` [lnf-log PATCHv2 3/3] nlmsg: add printf function in conjunction with libmnl Ken-ichirou MATSUZAWA
2015-08-26 19:01                 ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150818060409.GA3062@salvia \
    --to=pablo@netfilter.org \
    --cc=chamaken@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.