#define debug(x, args...)
#endif
-static int sockfd = -1;
-static int sockfd_use = 0;
static void *iptc_fn = NULL;
static const char *hooknames[] = {
STRUCT_TC_HANDLE
{
+ int sockfd;
int changed; /* Have changes been made? */
struct list_head chains;
STRUCT_GETINFO info;
unsigned int tmp;
socklen_t s;
+ int sockfd;
iptc_fn = TC_INIT;
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;
}
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;
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;
}
#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;
}
#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;