netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: James Chapman <jchapman@katalix.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH v4] netfilter: introduce l2tp match extension
Date: Thu, 2 Jan 2014 21:57:13 +0100	[thread overview]
Message-ID: <20140102205713.GA3758@localhost> (raw)
In-Reply-To: <1386857622-17389-1-git-send-email-jchapman@katalix.com>

Hi,

On Thu, Dec 12, 2013 at 02:13:42PM +0000, James Chapman wrote:
> Introduce an xtables add-on for matching L2TP packets. Supports L2TPv2
> and L2TPv3 over IPv4 and IPv6. As well as filtering on L2TP tunnel-id
> and session-id, the filtering decision can also include the L2TP
> packet type (control or data), protocol version (2 or 3) and
> encapsulation type (UDP or IP).
> 
> The most common use for this will likely be to filter L2TP data
> packets of individual L2TP tunnels or sessions. While a u32 match can
> be used, the L2TP protocol headers are such that field offsets differ
> depending on bits set in the header, making rules for matching generic
> L2TP connections cumbersome. This match extension takes care of all
> that.
>
> An iptables patch will be submitted separately.

I'm testing this with the last userspace iptables patch that you
posted [1]. I'm using the example in the manpage:

# iptables -A INPUT -s 1.2.3.4 -m l2tp --tid 42
iptables: Invalid argument. Run `dmesg' for more information.
# dmesg
...
[  490.827569] xt_l2tp: missing encapsulation

The error message is added by the patch I made on top of your last
kernel patch (find it attached, feel free to merge it to your next v5).

> diff --git a/net/netfilter/xt_l2tp.c b/net/netfilter/xt_l2tp.c
> new file mode 100644
> index 0000000..d4ec208
> --- /dev/null
> +++ b/net/netfilter/xt_l2tp.c
[...]
> +static int l2tp_mt_check(const struct xt_mtchk_param *par)
> +{
> +	struct xt_l2tp_info *info = par->matchinfo;
> +
> +	/* Check for invalid flags */
> +	if (info->flags & ~(XT_L2TP_TID | XT_L2TP_SID | XT_L2TP_VERSION |
> +			    XT_L2TP_ENCAP | XT_L2TP_TYPE))
> +		return -EINVAL;
> +
> +	/* At least one of tid, sid or type=control must be specified */
> +	if ((!(info->flags & XT_L2TP_TID)) &&
> +	    (!(info->flags & XT_L2TP_SID)) &&
> +	    ((!(info->flags & XT_L2TP_TYPE)) ||
> +	     (info->type != XT_L2TP_TYPE_CONTROL)))
> +		return -EINVAL;
> +
> +	/* If version 2 is specified, check that incompatible params
> +	 * are not supplied
> +	 */
> +	if (info->flags & XT_L2TP_VERSION) {
> +		if ((info->version < 2) || (info->version > 3))
> +			return -EINVAL;
> +
> +		if (info->version == 2) {
> +			if ((info->flags & XT_L2TP_TID) &&
> +			    (info->tid > 0xffff))
> +				return -EINVAL;
> +			if ((info->flags & XT_L2TP_SID) &&
> +			    (info->sid > 0xffff))
> +				return -EINVAL;
> +			if ((info->flags & XT_L2TP_ENCAP) &&
> +			    (info->encap == XT_L2TP_ENCAP_IP))
> +				return -EINVAL;
> +
> +			/* Force UDP encap */
> +			info->encap = XT_L2TP_ENCAP_UDP;
> +			info->flags |= XT_L2TP_ENCAP;

Note that changing the info data area from the kernel side is
problematic in iptables, eg.

# iptables -A INPUT -s 1.2.3.4/32 -m l2tp --tid 42 --pversion 2
# iptables -D INPUT -s 1.2.3.4/32 -m l2tp --tid 42 --pversion 2
iptables: Bad rule (does a matching rule exist in that chain?).

Userspace needs to get exactly what it passes, no changes are allowed.
I think you need explicit option passing to indicate the behaviour you
want.

> +		}
> +	}
> +
> +	/* Encap must be specified */
> +	if (!(info->flags & XT_L2TP_ENCAP))
> +		return -EINVAL;
> +
> +	return 0;
> +}

Please, review this logic in the _check() function and send me a v5,
including a refreshed iptables version.

It would be great if you can include a list of iptables commands using
your l2tp match that you have used to validate this in the next round.
Thanks.

[1] http://patchwork.ozlabs.org/patch/288411/

  reply	other threads:[~2014-01-02 20:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-12 14:13 [PATCH v4] netfilter: introduce l2tp match extension James Chapman
2014-01-02 20:57 ` Pablo Neira Ayuso [this message]
2014-01-02 20:59   ` Pablo Neira Ayuso
2014-01-03 10:04   ` James Chapman

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=20140102205713.GA3758@localhost \
    --to=pablo@netfilter.org \
    --cc=jchapman@katalix.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 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).