[iptables] libiptc: make sockfd a per-handle thing
Patrick McHardy
netfilter-cvslog-bounces at lists.netfilter.org
Mon Nov 10 17:26:17 CET 2008
Gitweb: http://git.netfilter.org/cgi-bin/gitweb.cgi?p=iptables.git;a=commit;h=175f451104532f3054b1824695d16a4ee1d8ea34
commit 175f451104532f3054b1824695d16a4ee1d8ea34
Author: Jan Engelhardt <jengelh at medozas.de>
AuthorDate: Mon Nov 10 17:25:55 2008 +0100
Commit: Patrick McHardy <kaber at trash.net>
CommitDate: Mon Nov 10 17:25:55 2008 +0100
libiptc: make sockfd a per-handle thing
Get away from this singleton.
Signed-off-by: Jan Engelhardt <jengelh at medozas.de>
Signed-off-by: Patrick McHardy <kaber at trash.net>
via 175f451104532f3054b1824695d16a4ee1d8ea34 (commit)
from 6b6c096ca56975125edf2aadfd195f23d34df38f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 175f451104532f3054b1824695d16a4ee1d8ea34
Author: Jan Engelhardt <jengelh at medozas.de>
Date: Mon Nov 10 17:25:55 2008 +0100
libiptc: make sockfd a per-handle thing
Get away from this singleton.
Signed-off-by: Jan Engelhardt <jengelh at medozas.de>
Signed-off-by: Patrick McHardy <kaber at trash.net>
-----------------------------------------------------------------------
libiptc/libiptc.c | 38 ++++++++++++++------------------------
1 files changed, 14 insertions(+), 24 deletions(-)
Get away from this singleton.
Signed-off-by: Jan Engelhardt <jengelh at medozas.de>
Signed-off-by: Patrick McHardy <kaber at trash.net>
diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
index 3f311a6..13e4c69 100644
--- a/libiptc/libiptc.c
+++ b/libiptc/libiptc.c
@@ -47,8 +47,6 @@
#define debug(x, args...)
#endif
-static int sockfd = -1;
-static int sockfd_use = 0;
static void *iptc_fn = NULL;
static const char *hooknames[] = {
@@ -128,6 +126,7 @@ struct chain_head
STRUCT_TC_HANDLE
{
+ int sockfd;
int changed; /* Have changes been made? */
struct list_head chains;
@@ -1309,6 +1308,7 @@ TC_INIT(const char *tablename)
STRUCT_GETINFO info;
unsigned int tmp;
socklen_t s;
+ int sockfd;
iptc_fn = TC_INIT;
@@ -1316,22 +1316,17 @@ TC_INIT(const char *tablename)
errno = EINVAL;
return NULL;
}
-
- if (sockfd_use == 0) {
- sockfd = socket(TC_AF, SOCK_RAW, IPPROTO_RAW);
- if (sockfd < 0)
- return NULL;
- }
- sockfd_use++;
+
+ sockfd = socket(TC_AF, SOCK_RAW, IPPROTO_RAW);
+ if (sockfd < 0)
+ return NULL;
+
retry:
s = sizeof(info);
strcpy(info.name, tablename);
if (getsockopt(sockfd, TC_IPPROTO, SO_GET_INFO, &info, &s) < 0) {
- if (--sockfd_use == 0) {
- close(sockfd);
- sockfd = -1;
- }
+ close(sockfd);
return NULL;
}
@@ -1340,21 +1335,19 @@ retry:
if ((h = alloc_handle(info.name, info.size, info.num_entries))
== NULL) {
- if (--sockfd_use == 0) {
- close(sockfd);
- sockfd = -1;
- }
+ close(sockfd);
return NULL;
}
/* Initialize current state */
+ h->sockfd = sockfd;
h->info = info;
h->entries->size = h->info.size;
tmp = sizeof(STRUCT_GET_ENTRIES) + h->info.size;
- if (getsockopt(sockfd, TC_IPPROTO, SO_GET_ENTRIES, h->entries,
+ if (getsockopt(h->sockfd, TC_IPPROTO, SO_GET_ENTRIES, h->entries,
&tmp) < 0)
goto error;
@@ -1388,10 +1381,7 @@ TC_FREE(struct xtc_handle *h)
struct chain_head *c, *tmp;
iptc_fn = TC_FREE;
- if (--sockfd_use == 0) {
- close(sockfd);
- sockfd = -1;
- }
+ close(h->sockfd);
list_for_each_entry_safe(c, tmp, &h->chains, list) {
struct rule_head *r, *rtmp;
@@ -2614,7 +2604,7 @@ TC_COMMIT(struct xtc_handle *handle)
}
#endif
- ret = setsockopt(sockfd, TC_IPPROTO, SO_SET_REPLACE, repl,
+ ret = setsockopt(handle->sockfd, TC_IPPROTO, SO_SET_REPLACE, repl,
sizeof(*repl) + repl->size);
if (ret < 0)
goto out_free_newcounters;
@@ -2690,7 +2680,7 @@ TC_COMMIT(struct xtc_handle *handle)
}
#endif
- ret = setsockopt(sockfd, TC_IPPROTO, SO_SET_ADD_COUNTERS,
+ ret = setsockopt(handle->sockfd, TC_IPPROTO, SO_SET_ADD_COUNTERS,
newcounters, counterlen);
if (ret < 0)
goto out_free_newcounters;
More information about the netfilter-cvslog
mailing list