1 From 02fbe60e1c7e74d2ba57109575e7bfc238b1b5d4 Mon Sep 17 00:00:00 2001
2 From: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
3 Date: Sun, 5 Apr 2020 17:18:23 +0100
4 Subject: [PATCH] drop runtime old kernel support
6 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
10 src/ipset.c | 64 ++++-----------------------------------------------
11 src/util.c | 19 ---------------
12 4 files changed, 5 insertions(+), 87 deletions(-)
16 @@ -105,10 +105,6 @@ int main (int argc, char **argv)
18 read_opts(argc, argv, compile_opts);
20 -#ifdef HAVE_LINUX_NETWORK
21 - daemon->kernel_version = kernel_version();
24 if (daemon->edns_pktsz < PACKETSZ)
25 daemon->edns_pktsz = PACKETSZ;
29 @@ -1277,7 +1277,7 @@ extern struct daemon {
32 #if defined(HAVE_LINUX_NETWORK)
33 - int netlinkfd, kernel_version;
35 #elif defined(HAVE_BSD_NETWORK)
36 int dhcp_raw_fd, dhcp_icmp_fd, routefd;
38 @@ -1491,9 +1491,6 @@ int read_write(int fd, unsigned char *pa
39 void close_fds(long max_fd, int spare1, int spare2, int spare3);
40 int wildcard_match(const char* wildcard, const char* match);
41 int wildcard_matchn(const char* wildcard, const char* match, int num);
42 -#ifdef HAVE_LINUX_NETWORK
43 -int kernel_version(void);
47 void die(char *message, char *arg1, int exit_code) ATTRIBUTE_NORETURN;
50 @@ -70,7 +70,7 @@ struct my_nfgenmsg {
52 #define NL_ALIGN(len) (((len)+3) & ~(3))
53 static const struct sockaddr_nl snl = { .nl_family = AF_NETLINK };
54 -static int ipset_sock, old_kernel;
55 +static int ipset_sock;
58 static inline void add_attr(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
59 @@ -85,12 +85,7 @@ static inline void add_attr(struct nlmsg
63 - old_kernel = (daemon->kernel_version < KERNEL_VERSION(2,6,32));
65 - if (old_kernel && (ipset_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) != -1)
70 (buffer = safe_malloc(BUFF_SZ)) &&
71 (ipset_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER)) != -1 &&
72 (bind(ipset_sock, (struct sockaddr *)&snl, sizeof(snl)) != -1))
73 @@ -147,65 +142,14 @@ static int new_add_to_ipset(const char *
74 return errno == 0 ? 0 : -1;
78 -static int old_add_to_ipset(const char *setname, const union all_addr *ipaddr, int remove)
81 - struct ip_set_req_adt_get {
85 - char name[IPSET_MAXNAMELEN];
88 - char typename[IPSET_MAXNAMELEN];
90 - struct ip_set_req_adt {
96 - if (strlen(setname) >= sizeof(req_adt_get.set.name))
98 - errno = ENAMETOOLONG;
102 - req_adt_get.op = 0x10;
103 - req_adt_get.version = 3;
104 - strcpy(req_adt_get.set.name, setname);
105 - size = sizeof(req_adt_get);
106 - if (getsockopt(ipset_sock, SOL_IP, 83, &req_adt_get, &size) < 0)
108 - req_adt.op = remove ? 0x102 : 0x101;
109 - req_adt.index = req_adt_get.set.index;
110 - req_adt.ip = ntohl(ipaddr->addr4.s_addr);
111 - if (setsockopt(ipset_sock, SOL_IP, 83, &req_adt, sizeof(req_adt)) < 0)
119 int add_to_ipset(const char *setname, const union all_addr *ipaddr, int flags, int remove)
121 int ret = 0, af = AF_INET;
126 - /* old method only supports IPv4 */
129 - errno = EAFNOSUPPORT ;
135 - ret = old_kernel ? old_add_to_ipset(setname, ipaddr, remove) : new_add_to_ipset(setname, ipaddr, af, remove);
137 + ret = new_add_to_ipset(setname, ipaddr, af, remove);
140 my_syslog(LOG_ERR, _("failed to update ipset %s: %s"), setname, strerror(errno));
143 @@ -866,22 +866,3 @@ int wildcard_matchn(const char* wildcard
145 return (!num) || (*wildcard == *match);
148 -#ifdef HAVE_LINUX_NETWORK
149 -int kernel_version(void)
151 - struct utsname utsname;
155 - if (uname(&utsname) < 0)
156 - die(_("failed to find kernel version: %s"), NULL, EC_MISC);
158 - split = strtok(utsname.release, ".");
159 - version = (split ? atoi(split) : 0);
160 - split = strtok(NULL, ".");
161 - version = version * 256 + (split ? atoi(split) : 0);
162 - split = strtok(NULL, ".");
163 - return version * 256 + (split ? atoi(split) : 0);