[netfilter-cvslog] r3791 - branches/netfilter-ha/linux-2.6-actact/cts_gen

laforge at netfilter.org laforge at netfilter.org
Sat Mar 12 14:19:49 CET 2005


Author: laforge at netfilter.org
Date: 2005-03-12 14:19:49 +0100 (Sat, 12 Mar 2005)
New Revision: 3791

Modified:
   branches/netfilter-ha/linux-2.6-actact/cts_gen/cts_gen.c
Log:
- add del_conntrack mode
- add master_announce mode
- add support for user-defined initial seqno


Modified: branches/netfilter-ha/linux-2.6-actact/cts_gen/cts_gen.c
===================================================================
--- branches/netfilter-ha/linux-2.6-actact/cts_gen/cts_gen.c	2005-03-12 11:16:17 UTC (rev 3790)
+++ branches/netfilter-ha/linux-2.6-actact/cts_gen/cts_gen.c	2005-03-12 13:19:49 UTC (rev 3791)
@@ -28,6 +28,17 @@
 	struct ct_sync_conntrack sct;
 };
 
+struct cts_del_conntrack {
+	struct ct_sync_pkthdr pkthdr;
+	struct ct_sync_msghdr msg;
+	struct ip_conntrack_tuple tuple;
+};
+
+struct cts_master_announce {
+	struct ct_sync_pkthdr pkthdr;
+	struct ct_sync_master_announce ma;
+};
+
 static u_int16_t pktseq = 0;
 
 static void
@@ -85,7 +96,7 @@
 }
 
 static void
-create_newconntrack(struct cts_new_conntrack *nct,
+fill_newconntrack(struct cts_new_conntrack *nct,
 		    u_int32_t sip, u_int16_t spt,
 		    u_int32_t dip, u_int16_t dpt,
 		    u_int16_t protocol,
@@ -102,6 +113,26 @@
 	sct->expires = expires;
 }
 
+static void
+fill_delconntrack(struct cts_del_conntrack *dct,
+		  u_int32_t sip, u_int16_t spt,
+		  u_int32_t dip, u_int16_t dpt,
+		  u_int16_t protocol)
+{
+	pkthdr_init(&dct->pkthdr, CT_SYNC_PKT_SYNC, 0);
+	msghdr_init(&dct->msg, CT_SYNC_RES_CONNTRACK, CT_SYNC_MSG_DELETE,
+		    sizeof(dct->tuple), 0);
+	build_tuple(&dct->tuple, sip, spt, dip, dpt, protocol);
+}
+
+static void
+fill_master_announce(struct cts_master_announce *ma)
+{
+	pkthdr_init(&ma->pkthdr, CT_SYNC_PKT_MASTER_ANNOUNCE, 0);
+	memset(&ma->ma, 0, sizeof(ma->ma));
+	ma->ma.upsince = 1;
+}
+
 static int
 create_socket(const char *destination)
 {
@@ -115,9 +146,10 @@
 	hint.ai_socktype = SOCK_DGRAM;
 	hint.ai_protocol = IPPROTO_UDP;
 
-	ret = getaddrinfo(destination, NULL, &hint, &ai);
+	ret = getaddrinfo(destination, "1999", &hint, &ai);
 	if (ret != 0) {
-		fprintf(stderr, "error: %s\n", gai_strerror(ret));
+		fprintf(stderr, "error (%s): %s\n", destination,
+			gai_strerror(ret));
 		return -1;
 	}
 
@@ -146,15 +178,22 @@
 	{ "spt-inc", 1, 0, 'i' },
 	{ "spt-max", 1, 0, 'm' },
 
+	{ "seq", 1, 0, 's' },
+
 	{ "help", 0, 0, 'h' },
 	{ NULL, 0, 0, 0 }
 };
 
+void usage(int ret)
+{
+	exit(ret);
+}
 
 int main(int argc, char ** argv)
 {
 	int c;
 	int option_index = 0;
+	int ret;
 
 	int fd;
 
@@ -198,32 +237,63 @@
 		case 'm':
 			port_max = atoi(optarg);
 			break;
+		case 's':
+			pktseq = atoi(optarg);
+			break;
 		case 'h':
 			/* FIXME */
+			usage(0);
 			break;
 		}
 	}
 
 	if (optind >= argc) {
 		fprintf(stderr, "you have to specify a multicast address\n");
-		exit(2);
+		usage(2);
 	}
 
 	fd = create_socket(argv[optind++]);
 	if (fd < 0)
-		exit(2);
-	
-	for (dip = ip_base; dip < ip_max; dip += ip_inc) {
-		for (dpt = port_base; dpt < port_max; dpt += port_inc) {
-			struct cts_new_conntrack nct;
-			int ret;
-			create_newconntrack(&nct, sip, spt, dip, dpt, 
-					    IPPROTO_UDP, 9999);
-			ret = send(fd, &nct, sizeof(nct), 0);
-			if (ret < 0)
-				fprintf(stderr, "error during send: %s\n",
-					strerror(errno));
+		exit(1);
+
+	if (optind >= argc) {
+		fprintf(stderr, "you have to specify a mode\n");
+		usage(2);
+	}
+
+	if (!strcmp(argv[optind], "master_announce")) {
+		struct cts_master_announce ma;
+		fill_master_announce(&ma);
+		ret = send(fd, &ma, sizeof(ma), 0);
+		if (ret < 0)
+			fprintf(stderr, "error during send: %s\n",
+				strerror(errno));
+	} else if (!strcmp(argv[optind], "new_conntrack") ||
+		   !strcmp(argv[optind], "del_conntrack")) {
+		for (dip = ip_base; dip < ip_max; dip += ip_inc) {
+			for (dpt = port_base; dpt < port_max; dpt += port_inc) {
+				if (!strcmp(argv[optind], "new_conntrack")) {
+					struct cts_new_conntrack nct;
+					fill_newconntrack(&nct, sip, spt, 
+							  dip, dpt, 
+							  IPPROTO_UDP, 9999);
+					ret = send(fd, &nct, sizeof(nct), 0);
+				} else {
+					struct cts_del_conntrack dct;
+					fill_delconntrack(&dct, sip, spt,
+							  dip, dpt,
+							  IPPROTO_UDP);
+					ret = send(fd, &dct, sizeof(dct), 0);
+				}
+				if (ret < 0)
+					fprintf(stderr, 
+						"error during send: %s\n",
+						strerror(errno));
+			}
 		}
+	} else {
+		fprintf(stderr, "unknown mode `%s'\n", argv[optind]);
+		usage(2);
 	}
 	exit(0);
 }




More information about the netfilter-cvslog mailing list