b1b134a98c24407fa7c02c6f68fd9eac2010c724
[openwrt/staging/noltari.git] / package / network / services / dnsmasq / patches / 100-remove-old-runtime-kernel-support.patch
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
5
6 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
7 ---
8 src/dnsmasq.c | 4 ----
9 src/dnsmasq.h | 5 +---
10 src/ipset.c | 64 ++++-----------------------------------------------
11 src/util.c | 19 ---------------
12 4 files changed, 5 insertions(+), 87 deletions(-)
13
14 --- a/src/dnsmasq.c
15 +++ b/src/dnsmasq.c
16 @@ -103,10 +103,6 @@ int main (int argc, char **argv)
17
18 read_opts(argc, argv, compile_opts);
19
20 -#ifdef HAVE_LINUX_NETWORK
21 - daemon->kernel_version = kernel_version();
22 -#endif
23 -
24 if (daemon->edns_pktsz < PACKETSZ)
25 daemon->edns_pktsz = PACKETSZ;
26
27 --- a/src/dnsmasq.h
28 +++ b/src/dnsmasq.h
29 @@ -1229,7 +1229,7 @@ extern struct daemon {
30 int inotifyfd;
31 #endif
32 #if defined(HAVE_LINUX_NETWORK)
33 - int netlinkfd, kernel_version;
34 + int netlinkfd;
35 #elif defined(HAVE_BSD_NETWORK)
36 int dhcp_raw_fd, dhcp_icmp_fd, routefd;
37 #endif
38 @@ -1422,9 +1422,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);
44 -#endif
45
46 /* log.c */
47 void die(char *message, char *arg1, int exit_code) ATTRIBUTE_NORETURN;
48 --- a/src/ipset.c
49 +++ b/src/ipset.c
50 @@ -70,7 +70,7 @@ struct my_nfgenmsg {
51
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;
56 static char *buffer;
57
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
60
61 void ipset_init(void)
62 {
63 - old_kernel = (daemon->kernel_version < KERNEL_VERSION(2,6,32));
64 -
65 - if (old_kernel && (ipset_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) != -1)
66 - return;
67 -
68 - if (!old_kernel &&
69 + if (
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;
75 }
76
77 -
78 -static int old_add_to_ipset(const char *setname, const union all_addr *ipaddr, int remove)
79 -{
80 - socklen_t size;
81 - struct ip_set_req_adt_get {
82 - unsigned op;
83 - unsigned version;
84 - union {
85 - char name[IPSET_MAXNAMELEN];
86 - uint16_t index;
87 - } set;
88 - char typename[IPSET_MAXNAMELEN];
89 - } req_adt_get;
90 - struct ip_set_req_adt {
91 - unsigned op;
92 - uint16_t index;
93 - uint32_t ip;
94 - } req_adt;
95 -
96 - if (strlen(setname) >= sizeof(req_adt_get.set.name))
97 - {
98 - errno = ENAMETOOLONG;
99 - return -1;
100 - }
101 -
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)
107 - return -1;
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)
112 - return -1;
113 -
114 - return 0;
115 -}
116 -
117 -
118 -
119 int add_to_ipset(const char *setname, const union all_addr *ipaddr, int flags, int remove)
120 {
121 int ret = 0, af = AF_INET;
122
123 if (flags & F_IPV6)
124 - {
125 af = AF_INET6;
126 - /* old method only supports IPv4 */
127 - if (old_kernel)
128 - {
129 - errno = EAFNOSUPPORT ;
130 - ret = -1;
131 - }
132 - }
133 -
134 - if (ret != -1)
135 - ret = old_kernel ? old_add_to_ipset(setname, ipaddr, remove) : new_add_to_ipset(setname, ipaddr, af, remove);
136 +
137 + ret = new_add_to_ipset(setname, ipaddr, af, remove);
138
139 if (ret == -1)
140 my_syslog(LOG_ERR, _("failed to update ipset %s: %s"), setname, strerror(errno));
141 --- a/src/util.c
142 +++ b/src/util.c
143 @@ -833,22 +833,3 @@ int wildcard_matchn(const char* wildcard
144
145 return (!num) || (*wildcard == *match);
146 }
147 -
148 -#ifdef HAVE_LINUX_NETWORK
149 -int kernel_version(void)
150 -{
151 - struct utsname utsname;
152 - int version;
153 - char *split;
154 -
155 - if (uname(&utsname) < 0)
156 - die(_("failed to find kernel version: %s"), NULL, EC_MISC);
157 -
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);
164 -}
165 -#endif