extensions: add connlabel match
Florian Westphal
maintainerPATCH 1/1 extensions: add connlabel match
allows to "tag" connections with up to 128 label names.
Labels are defined in /etc/xtables/connlabel.conf, example:
0 from eth0
1 via eth0
Labels can then be attached to flows, e.g.
-A PREROUTING -i eth0 -m connlabel --label "from eth0" --set
---
The main issue with this patch is the location of the connlabel config file. Upcoming patches to libnetfilter_conntrack add a lookup helper API, these need to know the pathname of said file.
[ preview at
http://git.breakpoint.cc/cgit.cgi/fw/libnetfilter_conntrack.git/log/?h=ctlabel_08 ]
I'd like to avoid that users of that API need to try out X different locations, thats why its hard-coded to /etc/xtables/connlabel.conf.
I'd be interested in feedback (esp. from disto maintainers) and possible alternatives to naming/location of this file.
Makefile.am | 4 + etc/xtables/connlabel.conf | 9 ++ extensions/libxt_connlabel.c | 210 ++++++++++++++++++++++++++++++++ extensions/libxt_connlabel.man | 32 +++++ include/linux/netfilter/xt_connlabel.h | 12 ++ 5 files changed, 267 insertions(+), 0 deletions(-) create mode 100644 etc/xtables/connlabel.conf create mode 100644 extensions/libxt_connlabel.c create mode 100644 extensions/libxt_connlabel.man create mode 100644 include/linux/netfilter/xt_connlabel.h
Makefile.am +4 -0
@@ -26,5 +26,9 @@ tarball: tar -C /tmp -cjf ${PACKAGE_TARNAME}-${PACKAGE_VERSION}.tar.bz2 --owner=root --group=root ${PACKAGE_TARNAME}-${PACKAGE_VERSION}/; rm -Rf /tmp/${PACKAGE_TARNAME}-${PACKAGE_VERSION}; +install-data-hook: + @mkdir -p -m 755 $(DESTDIR)/etc/xtables/ || : + @test -f /etc/xtables/connlabel.conf || $(INSTALL) -m 644 etc/xtables/connlabel.conf $(DESTDIR)/etc/xtables/connlabel.conf || : + config.status: extensions/GNUmakefile.in \ include/xtables-version.h.in include/iptables/internal.h.in
etc/xtables/connlabel.conf new file +9 -0
@@ -0,0 +1,9 @@ +# example connlabel.conf mapping file. +# used by the "connlabel" match to translate +# names to their bit-value. +0 eth0-in +1 eth0-out +2 ppp-in +3 ppp-out +4 bulk-traffic +5 interactive
extensions/libxt_connlabel.c new file +210 -0
210 lines not on this page · raw message
extensions/libxt_connlabel.man new file +32 -0
@@ -0,0 +1,32 @@ +Module matches or adds connlabels to a connection. +connlabels are similar to connmarks, except labels are bit-based; i.e. +all labels may be attached to a flow at the same time. +Up to 128 unique labels are currently supported. +.TP +[\fB!\fP] \fB\-\-label\fP \fBname\fP +matches if label \fBname\fP has been set on a connection. +Instead of a name (which will be translated to a number, see EXAMPLE below), +a number may be used instead. Using a number always overrides connlabel.conf. +.TP +\fB\-\-set\fP +if the label has not been set on the connection, set it. +Note that setting a label can fail. This is because the kernel allocates the +conntrack label storage area when the connection is created, and it only +reserves the amount of memory required by the ruleset that exists at +the time the connection is created. +In this case, the match will fail (or succeed, in case \fB\-\-label\fP +option was negated). +.PP +Label translation is done via the \fB/etc/xtables/connlabel.conf\fP configuration file. +.PP +Example: +.IP +.nf +0 eth0-in +1 eth0-out +2 ppp-in +3 ppp-out +4 bulk-traffic +5 interactive +.fi +.PP
include/linux/netfilter/xt_connlabel.h new file +12 -0
@@ -0,0 +1,12 @@ +#include <linux/types.h> + +#define XT_CONNLABEL_MAXBIT 127 +enum xt_connlabel_mtopts { +XT_CONNLABEL_OP_INVERT =1 <<0 , +XT_CONNLABEL_OP_SET =1 <<1 , +}; + +struct xt_connlabel_mtinfo { +__u16 bit; +__u16 options; +};
Signature · 1 line
1.7.8.6