[netfilter-cvslog] r7287 - in trunk/conntrack-tools: . include src

pablo at netfilter.org pablo at netfilter.org
Wed Jan 23 11:30:21 CET 2008


Author: pablo at netfilter.org
Date: 2008-01-23 11:30:21 +0100 (Wed, 23 Jan 2008)
New Revision: 7287

Modified:
   trunk/conntrack-tools/ChangeLog
   trunk/conntrack-tools/include/conntrackd.h
   trunk/conntrack-tools/include/local.h
   trunk/conntrack-tools/src/local.c
   trunk/conntrack-tools/src/run.c
Log:
Max Kellermann <max at duempel.org>:
added struct local_server, several cleanups in local socket infrastructure

This patch include minor changes by the comitter


Modified: trunk/conntrack-tools/ChangeLog
===================================================================
--- trunk/conntrack-tools/ChangeLog	2008-01-23 10:16:03 UTC (rev 7286)
+++ trunk/conntrack-tools/ChangeLog	2008-01-23 10:30:21 UTC (rev 7287)
@@ -91,6 +91,7 @@
 o merge mod_alarm() into add_alarm(), remove alarm_set_expiration()
 o remove init_alarm() before add_alarm()
 o fix error checking of local_create_server()
+o added struct local_server, several cleanups in local socket infrastructure
 
 version 0.9.5 (2007/07/29)
 ------------------------------

Modified: trunk/conntrack-tools/include/conntrackd.h
===================================================================
--- trunk/conntrack-tools/include/conntrackd.h	2008-01-23 10:16:03 UTC (rev 7286)
+++ trunk/conntrack-tools/include/conntrackd.h	2008-01-23 10:30:21 UTC (rev 7287)
@@ -98,7 +98,7 @@
 	sigset_t 			block;
 	FILE 				*log;
 	FILE				*stats_log;
-	int 				local;
+	struct local_server		local;
 	struct ct_mode 			*mode;
 	struct ignore_pool		*ignore_pool;
 

Modified: trunk/conntrack-tools/include/local.h
===================================================================
--- trunk/conntrack-tools/include/local.h	2008-01-23 10:16:03 UTC (rev 7286)
+++ trunk/conntrack-tools/include/local.h	2008-01-23 10:30:21 UTC (rev 7287)
@@ -11,10 +11,15 @@
 	char path[UNIX_PATH_MAX];
 };
 
+struct local_server {
+	int fd;
+	char path[UNIX_PATH_MAX];
+};
+
 /* local server */
-int local_server_create(struct local_conf *conf);
-void local_server_destroy(int fd, const char *);
-int do_local_server_step(int fd, void *data, 
+int local_server_create(struct local_server *server, struct local_conf *conf);
+void local_server_destroy(struct local_server *server);
+int do_local_server_step(struct local_server *server, void *data, 
 			 void (*process)(int fd, void *data));
 
 /* local client */

Modified: trunk/conntrack-tools/src/local.c
===================================================================
--- trunk/conntrack-tools/src/local.c	2008-01-23 10:16:03 UTC (rev 7286)
+++ trunk/conntrack-tools/src/local.c	2008-01-23 10:30:21 UTC (rev 7287)
@@ -26,7 +26,7 @@
 #include <arpa/inet.h>
 #include <sys/un.h>
 
-int local_server_create(struct local_conf *conf)
+int local_server_create(struct local_server *server, struct local_conf *conf)
 {
 	int fd;
 	int len;
@@ -59,23 +59,27 @@
 		return -1;
 	}
 
-	return fd;
+	server->fd = fd;
+	strcpy(server->path, conf->path);
+
+	return 0;
 }
 
-void local_server_destroy(int fd, const char *path)
+void local_server_destroy(struct local_server *server)
 {
-	unlink(path);
-	close(fd);
+	unlink(server->path);
+	close(server->fd);
 }
 
-int do_local_server_step(int fd, void *data, 
+int do_local_server_step(struct local_server *server, void *data, 
 			 void (*process)(int fd, void *data))
 {
 	int rfd;
 	struct sockaddr_un local;
 	socklen_t sin_size = sizeof(struct sockaddr_un);
 	
-	if ((rfd = accept(fd, (struct sockaddr *)&local, &sin_size)) == -1)
+	rfd = accept(server->fd, (struct sockaddr *) &local, &sin_size);
+	if (rfd == -1)
 		return -1;
 
 	process(rfd, data);

Modified: trunk/conntrack-tools/src/run.c
===================================================================
--- trunk/conntrack-tools/src/run.c	2008-01-23 10:16:03 UTC (rev 7286)
+++ trunk/conntrack-tools/src/run.c	2008-01-23 10:30:21 UTC (rev 7287)
@@ -40,7 +40,7 @@
 	nfct_close(STATE(dump));
 
 	ignore_pool_destroy(STATE(ignore_pool));
-	local_server_destroy(STATE(local), CONFIG(local).path);
+	local_server_destroy(&STATE(local));
 	STATE(mode)->kill();
 	destroy_alarm_hash();
 	unlink(CONFIG(lockfile));
@@ -115,8 +115,7 @@
 	}
 
 	/* local UNIX socket */
-	STATE(local) = local_server_create(&CONFIG(local));
-	if (STATE(local) == -1) {
+	if (local_server_create(&STATE(local), &CONFIG(local)) == -1) {
 		dlog(LOG_ERR, "can't open unix socket!");
 		return -1;
 	}
@@ -165,10 +164,10 @@
 	fd_set readfds;
 
 	FD_ZERO(&readfds);
-	FD_SET(STATE(local), &readfds);
+	FD_SET(STATE(local).fd, &readfds);
 	FD_SET(nfct_fd(STATE(event)), &readfds);
 
-	max = MAX(STATE(local), nfct_fd(STATE(event)));
+	max = MAX(STATE(local).fd, nfct_fd(STATE(event)));
 
 	if (STATE(mode)->add_fds_to_set)
 		max = MAX(max, STATE(mode)->add_fds_to_set(&readfds));
@@ -187,8 +186,8 @@
 	sigprocmask(SIG_BLOCK, &STATE(block), NULL);		
 
 	/* order received via UNIX socket */
-	if (FD_ISSET(STATE(local), &readfds))
-		do_local_server_step(STATE(local), NULL, local_handler);
+	if (FD_ISSET(STATE(local).fd, &readfds))
+		do_local_server_step(&STATE(local), NULL, local_handler);
 
 	/* conntrack event has happened */
 	if (FD_ISSET(nfct_fd(STATE(event)), &readfds)) {




More information about the netfilter-cvslog mailing list