[PATCH conntrack-tools] conntrack: add --reliable option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To be used with connection tracking events: kernel will retry
delivery of DESTROY event until userspace can receive the message.

Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 include/conntrack.h |  2 +-
 src/conntrack.c     | 58 +++++++++++++++++++++++++++++----------------
 2 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/include/conntrack.h b/include/conntrack.h
index 1c1720e998ad..3083ad503b24 100644
--- a/include/conntrack.h
+++ b/include/conntrack.h
@@ -12,7 +12,7 @@
 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
 
 #define NUMBER_OF_CMD   19
-#define NUMBER_OF_OPT   29
+#define NUMBER_OF_OPT   30
 
 struct nf_conntrack;
 
diff --git a/src/conntrack.c b/src/conntrack.c
index fe5574d205a6..55f59bcd581b 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -114,6 +114,7 @@ struct ct_cmd {
 	int		options;
 	int		family;
 	int		protonum;
+	bool		reliable_events;
 	size_t		socketbuffersize;
 	struct ct_tmpl	tmpl;
 };
@@ -389,6 +390,7 @@ static struct option original_opts[] = {
 	{"label-del", 2, 0, '>'},
 	{"orig-zone", 1, 0, '('},
 	{"reply-zone", 1, 0, ')'},
+	{"reliable", 0, 0, 'R'},
 	{0, 0, 0, 0}
 };
 
@@ -409,26 +411,26 @@ static const char *getopt_str = ":L::I::U::D::G::E::F::hVs:d:r:q:"
 static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] =
 /* Well, it's better than "Re: Linux vs FreeBSD" */
 {
-          /*   s d r q p t u z e [ ] { } a m i f n g o c b j w l < > ( ) */
-/*CT_LIST*/   {2,2,2,2,2,0,2,2,0,0,0,2,2,0,2,0,2,2,2,2,2,0,2,2,2,0,0,2,2},
-/*CT_CREATE*/ {3,3,3,3,1,1,2,0,0,0,0,0,0,2,2,0,0,2,2,0,0,0,0,2,0,2,0,2,2},
-/*CT_UPDATE*/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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*EXP_DELETE*/{1,1,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*EXP_GET*/   {1,1,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*EXP_FLUSH*/ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*EXP_EVENT*/ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0},
+/*CT_COUNT*/  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*EXP_COUNT*/ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*CT_STATS*/  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+/*EXP_STATS*/ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
 };
 
 static const int cmd2type[][2] = {
@@ -2933,6 +2935,7 @@ static void do_parse(struct ct_cmd *ct_cmd, int argc, char *argv[])
 {
 	unsigned int type = 0, event_mask = 0, l4flags = 0, status = 0;
 	int protonum = 0, family = AF_UNSPEC;
+	bool reliable_events = false;
 	size_t socketbuffersize = 0;
 	unsigned int command = 0;
 	unsigned int options = 0;
@@ -3175,6 +3178,9 @@ static void do_parse(struct ct_cmd *ct_cmd, int argc, char *argv[])
 			socketbuffersize = atol(optarg);
 			options |= CT_OPT_BUFFERSIZE;
 			break;
+		case 'R':
+			reliable_events = true;
+			break;
 		case ':':
 			exit_error(PARAMETER_PROBLEM,
 				   "option `%s' requires an "
@@ -3248,6 +3254,7 @@ static void do_parse(struct ct_cmd *ct_cmd, int argc, char *argv[])
 	ct_cmd->protonum = protonum;
 	ct_cmd->event_mask = event_mask;
 	ct_cmd->socketbuffersize = socketbuffersize;
+	ct_cmd->reliable_events = reliable_events;
 }
 
 static int do_command_ct(const char *progname, struct ct_cmd *cmd)
@@ -3516,6 +3523,17 @@ static int do_command_ct(const char *progname, struct ct_cmd *cmd)
 					socketbuffersize);
 		}
 
+		if (cmd->reliable_events) {
+			int on = 1;
+
+			mnl_socket_setsockopt(sock->mnl,
+					     NETLINK_BROADCAST_SEND_ERROR,
+					     &on, sizeof(int));
+			mnl_socket_setsockopt(sock->mnl,
+					     NETLINK_NO_ENOBUFS,
+					     &on, sizeof(int));
+		}
+
 		nfct_filter_init(cmd);
 
 		signal(SIGINT, event_sighandler);
-- 
2.34.1




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux