6 #include <sys/socket.h>
7 -#include <sys/utsname.h>
9 #include <linux/version.h>
10 #include <linux/netlink.h>
11 @@ -72,7 +71,7 @@ struct my_nfgenmsg {
13 #define NL_ALIGN(len) (((len)+3) & ~(3))
14 static const struct sockaddr_nl snl = { .nl_family = AF_NETLINK };
15 -static int ipset_sock, old_kernel;
16 +static int ipset_sock;
19 static inline void add_attr(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
20 @@ -87,25 +86,7 @@ static inline void add_attr(struct nlmsg
24 - struct utsname utsname;
28 - if (uname(&utsname) < 0)
29 - die(_("failed to find kernel version: %s"), NULL, EC_MISC);
31 - split = strtok(utsname.release, ".");
32 - version = (split ? atoi(split) : 0);
33 - split = strtok(NULL, ".");
34 - version = version * 256 + (split ? atoi(split) : 0);
35 - split = strtok(NULL, ".");
36 - version = version * 256 + (split ? atoi(split) : 0);
37 - old_kernel = (version < KERNEL_VERSION(2,6,32));
39 - if (old_kernel && (ipset_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) != -1)
44 (buffer = safe_malloc(BUFF_SZ)) &&
45 (ipset_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER)) != -1 &&
46 (bind(ipset_sock, (struct sockaddr *)&snl, sizeof(snl)) != -1))
47 @@ -168,62 +149,16 @@ static int new_add_to_ipset(const char *
51 -static int old_add_to_ipset(const char *setname, const struct all_addr *ipaddr, int remove)
54 - struct ip_set_req_adt_get {
58 - char name[IPSET_MAXNAMELEN];
61 - char typename[IPSET_MAXNAMELEN];
63 - struct ip_set_req_adt {
69 - if (strlen(setname) >= sizeof(req_adt_get.set.name))
71 - errno = ENAMETOOLONG;
75 - req_adt_get.op = 0x10;
76 - req_adt_get.version = 3;
77 - strcpy(req_adt_get.set.name, setname);
78 - size = sizeof(req_adt_get);
79 - if (getsockopt(ipset_sock, SOL_IP, 83, &req_adt_get, &size) < 0)
81 - req_adt.op = remove ? 0x102 : 0x101;
82 - req_adt.index = req_adt_get.set.index;
83 - req_adt.ip = ntohl(ipaddr->addr.addr4.s_addr);
84 - if (setsockopt(ipset_sock, SOL_IP, 83, &req_adt, sizeof(req_adt)) < 0)
92 int add_to_ipset(const char *setname, const struct all_addr *ipaddr, int flags, int remove)
100 - /* old method only supports IPv4 */
106 - return old_kernel ? old_add_to_ipset(setname, ipaddr, remove) : new_add_to_ipset(setname, ipaddr, af, remove);
107 + return new_add_to_ipset(setname, ipaddr, af, remove);