cthelper: Set up userspace helpers when daemon starts
Pablo Neira Ayuso
maintainerPATCH v2 1/2 cthelper: Set up userspace helpers when daemon starts
Add a new setting to allow conntrackd to autoconfigure the userspace helpers at startup.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: do not destroy helper, it hits EBUSY if it is used from the ruleset.
doc/helper/conntrackd.conf | 14 ++++++++++++-- include/conntrackd.h | 1 + src/cthelper.c | 5 +++++ src/read_config_lex.l | 1 + src/read_config_yy.y | 13 ++++++++++++- 5 files changed, 31 insertions(+), 3 deletions(-)
doc/helper/conntrackd.conf +12 -2
@@ -3,11 +3,21 @@ # Helper { - # Before this, you have to make sure you have registered the `ftp' - # user-space helper stub via: + # + # Set up the userspace helpers when the daemon is started. If unset, + # you have manually set up the user-space helper stub, e.g. # # nfct add helper ftp inet tcp # + # This new setting simplifies new deployment, so it is recommended to + # turn it on. On existing deployments, make sure to remove the nfct + # command invocation since it is not required anymore. + # + # Default: no (for backward compatibility reasons) + # Recommended: yes + # + Setup yes + Type ftp inet tcp { # # Set NFQUEUE number you want to use to receive traffic from
include/conntrackd.h +1 -0
@@ -138,6 +138,7 @@ struct ct_conf { } stats;struct {struct list_head list; +bool setup; } cthelper; };
src/cthelper.c +5 -0
@@ -49,6 +49,7 @@#include <linux/netfilter.h> #include <libnetfilter_queue/pktbuff.h> +void cthelper_kill (void ) {mnl_socket_close (STATE_CTH (nl));
@@ -386,6 +387,10 @@ static int cthelper_setup(struct ctd_helper_instance *cur)nfct_helper_attr_set_u32 (t,NFCTH_ATTR_QUEUE_NUM , cur->queue_num);nfct_helper_attr_set_u16 (t,NFCTH_ATTR_PROTO_L3NUM , cur->l3proto);nfct_helper_attr_set_u8 (t,NFCTH_ATTR_PROTO_L4NUM , cur->l4proto); +if (CONFIG (cthelper).setup) { +nfct_helper_attr_set_u32 (t,NFCTH_ATTR_PRIV_DATA_LEN , + cur->helper->priv_data_len); + }nfct_helper_attr_set_u32 (t,NFCTH_ATTR_STATUS ,NFCT_HELPER_STATUS_ENABLED );
src/read_config_lex.l +1 -0
@@ -141,6 +141,7 @@ notrack [N|n][O|o][T|t][R|r][A|a][C|c][K|k] "ExpectTimeout" { return T_HELPER_EXPECT_TIMEOUT; } "Systemd" { return T_SYSTEMD; } "StartupResync" { return T_STARTUP_RESYNC; } +"Setup" { return T_SETUP; } {is_true} { return T_ON; } {is_false} { return T_OFF; }
src/read_config_yy.y +12 -1
@@ -63,7 +63,7 @@ enum { %token T_IPV4_ADDR T_IPV4_IFACE T_PORT T_HASHSIZE T_HASHLIMIT T_MULTICAST %token T_PATH T_UNIX T_REFRESH T_IPV6_ADDR T_IPV6_IFACE -%token T_BACKLOG T_GROUP T_IGNORE +%token T_BACKLOG T_GROUP T_IGNORE T_SETUP %token T_LOG T_UDP T_ICMP T_IGMP T_VRRP T_TCP %token T_LOCK T_BUFFER_SIZE_MAX_GROWN T_EXPIRE T_TIMEOUT %token T_GENERAL T_SYNC T_STATS T_BUFFER_SIZE
@@ -1454,6 +1454,7 @@ helper_list: ; helper_line: helper_type + | helper_setup ; helper_type: T_TYPE T_STRING T_STRING T_STRING '{' helper_type_list '}'
@@ -1562,6 +1563,16 @@ helper_type: T_TYPE T_STRING T_STRING T_STRING '{' helper_type_list '}' list_add(&helper_inst->head, &CONFIG(cthelper).list); }; +helper_setup : T_SETUP T_ON +{ + CONFIG(cthelper).setup = true; +}; + +helper_setup : T_SETUP T_OFF +{ + CONFIG(cthelper).setup = false; +}; + helper_type_list: | helper_type_list helper_type_line ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 2/2 doc: manual: Document userspace helper configuration at daemon startup
Describe how to configure conntrackd using the new simple setup approach.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: no changes.
doc/manual/conntrack-tools.tmpl | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-)
doc/manual/conntrack-tools.tmpl +21 -21
@@ -905,32 +905,13 @@ maintainance.</para></listitem> <para>The following steps describe how to enable the RPC portmapper helper for NFSv3 (this is similar for other helpers):</para> <orderedlist> -<listitem><para>Register user-space helper: - -<programlisting> -nfct add helper rpc inet udp -nfct add helper rpc inet tcp -</programlisting> - -This registers the portmapper helper for both UDP and TCP (NFSv3 traffic goes both over TCP and UDP). -</para></listitem> - -<listitem><para>Add iptables rule using the CT target: - -<programlisting> -# iptables -I OUTPUT -t raw -p udp --dport 111 -j CT --helper rpc -# iptables -I OUTPUT -t raw -p tcp --dport 111 -j CT --helper rpc -</programlisting> - -With this, packets matching port TCP/UDP/111 are passed to user-space for -inspection. If there is no instance of conntrackd configured to support -user-space helpers, no inspection happens and packets are not sent to -user-space.</para></listitem> <listitem><para>Add configuration to conntrackd.conf: <programlisting> Helper { + Setup yes + Type rpc inet udp { QueueNum 1 QueueLen 10240
@@ -962,6 +943,25 @@ for inspection to user-space</para> </listitem> +<listitem><para>Run conntrackd: +<programlisting> +# conntrackd -d -C /path/to/conntrackd.conf +</programlisting> +</para> +</listitem> + +<listitem><para>Add iptables rule using the CT target: + +<programlisting> +# iptables -I OUTPUT -t raw -p udp --dport 111 -j CT --helper rpc +# iptables -I OUTPUT -t raw -p tcp --dport 111 -j CT --helper rpc +</programlisting> + +With this, packets matching port TCP/UDP/111 are passed to user-space for +inspection. If there is no instance of conntrackd configured to support +user-space helpers, no inspection happens and packets are not sent to +user-space.</para></listitem> + </orderedlist> <para>Now you can test this (assuming you have some working NFSv3 setup) with:
Signature · 1 line
2.30.2