From: Nikolay Aleksandrov <nikolay@redhat.com>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org, pablo@netfilter.org
Subject: Re: [RFC PATCH] netfilter: nf_tables: extend payload to support writing data
Date: Mon, 17 Feb 2014 19:43:38 +0100 [thread overview]
Message-ID: <5302585A.9070309@redhat.com> (raw)
In-Reply-To: <20140217183751.GB10701@macbook.localnet>
On 02/17/2014 07:37 PM, Patrick McHardy wrote:
> On Mon, Feb 17, 2014 at 07:12:17PM +0100, Nikolay Aleksandrov wrote:
>> This patch extends the payload expression to support packet writing.
>> The new payload attribute - SREG specifies the source register to use
>> when changing packet data, the rest of the attributes are the same:
>> base - where to start from
>> offset - offset in the packet
>> len - length to write
>>
>> The DREG attribute should not be set if writing is intended, if both
>> attributes are set the SREG (packet writing) will take precedence.
>> When the expression is dumped both registers will get dumped and the
>> user can differentiate the type of the payload (reading/writing) by
>> checking if the sreg attribute is different from zero.
>
> I'd suggest to return an error if both are set. We should only accept
> clearly defined input and reject everything else.
>
Okay, will do.
>> I'm sending this patch early thus the RFC (I'm still testing),
>> just to see if you have any comments on the structure and changes. Now to
>> justify a few of the changes:
>> I added the sreg as a separate variable to struct nft_payload in order for
>> the user to be able to recognize which payload type is the expression when
>> dumping since both SREG and DREG get dumped.
>
> Adding another register seems fine. I'd suggest to only dump the one
> actually used though.
>
Given the previous comment, yep :)
>> I also factored the offset code in nft_payload_make_offset since it's used
>> by both evaluation functions, returns -1 on error.
>> The two init functions check only the registers as that's what is different
>> the rest of the attributes are still checked by the select_ops. I've also
>> allowed to have both SREG and DREG set but in such case SREG takes
>> precedence.
>
> See above.
>
>> I left the old payload names as they were, but they can get _get or
>> something else if you'd like.
>
> Actually I dislike the _get and _set suffixes, so I'm happy to use them
> as little as possible :)
>
>> diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
>> index a2aeb31..1b42668 100644
>> --- a/net/netfilter/nft_payload.c
>> +++ b/net/netfilter/nft_payload.c
>> @@ -17,23 +17,19 @@
>> #include <net/netfilter/nf_tables_core.h>
>> #include <net/netfilter/nf_tables.h>
>>
>> -static void nft_payload_eval(const struct nft_expr *expr,
>> - struct nft_data data[NFT_REG_MAX + 1],
>> - const struct nft_pktinfo *pkt)
>> +static int nft_payload_make_offset(const struct nft_pktinfo *pkt,
>> + const struct nft_payload *payload)
>
> We're using priv everywhere. Please keep this consistent. Also please
> make sure (in the entire patch) that arguments are aligned with the
> opening (.
>
Okay, I'll use the priv.
They're adjusted, apply the patch and see for yourself, or do you mean some
other adjustment ?
Both arguments are aligned from what I can see.
>> {
>> - const struct nft_payload *priv = nft_expr_priv(expr);
>> - const struct sk_buff *skb = pkt->skb;
>> - struct nft_data *dest = &data[priv->dreg];
>> - int offset;
>> + int offset = -1;
>>
>> - switch (priv->base) {
>> + switch (payload->base) {
>> case NFT_PAYLOAD_LL_HEADER:
>> - if (!skb_mac_header_was_set(skb))
>> - goto err;
>> - offset = skb_mac_header(skb) - skb->data;
>> + if (!skb_mac_header_was_set(pkt->skb))
>
> Why don't you keep the local skb pointer?
>
Anyway is fine by me, I'll leave it.
>> + return offset;
>> + offset = skb_mac_header(pkt->skb) - pkt->skb->data;
>> break;
>> case NFT_PAYLOAD_NETWORK_HEADER:
>> - offset = skb_network_offset(skb);
>> + offset = skb_network_offset(pkt->skb);
>> break;
>> case NFT_PAYLOAD_TRANSPORT_HEADER:
>> offset = pkt->xt.thoff;
>
>> +static void nft_payload_set_eval(const struct nft_expr *expr,
>> + struct nft_data data[NFT_REG_MAX + 1],
>> + const struct nft_pktinfo *pkt)
>> +{
>> + const struct nft_payload *priv = nft_expr_priv(expr);
>> + struct nft_data *source = &data[priv->sreg];
>> + int offset = nft_payload_make_offset(pkt, priv);
>> +
>> + if (offset == -1)
>> + goto err;
>> + if (!skb_make_writable(pkt->skb, offset + priv->len))
>> + goto err;
>> + memcpy(pkt->skb->data + offset, source, priv->len);
>
> We need to take care of checksumming. Shouldn't be too hard to get *most*
> cases right using the existing checksum helpers.
>
Yes, but would you like to do that in here or have a separate op which
is configurable i.e. you can set what to calculate and where to put it,
or would you prefer to make it automatic based on what we're changing here ?
>> +
>> + return;
>> +err:
>> + data[NFT_REG_VERDICT].verdict = NFT_BREAK;
>> +}
>> +
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2014-02-17 18:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-17 18:12 [RFC PATCH] netfilter: nf_tables: extend payload to support writing data Nikolay Aleksandrov
2014-02-17 18:37 ` Patrick McHardy
2014-02-17 18:43 ` Nikolay Aleksandrov [this message]
2014-02-17 18:46 ` Patrick McHardy
2014-02-19 16:12 ` Nikolay Aleksandrov
2014-02-19 16:25 ` Patrick McHardy
2014-02-19 16:22 ` Nikolay Aleksandrov
-- strict thread matches above, loose matches on Subject: below --
2014-02-23 17:32 Nikolay Aleksandrov
2014-02-23 18:09 ` Patrick McHardy
2014-02-23 18:34 ` Nikolay Aleksandrov
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=5302585A.9070309@redhat.com \
--to=nikolay@redhat.com \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).