modernize backfire 10.03 so it can be operational again
[openwrt-10.03/.git] / package / dnsmasq / patches / 110-ipset-remove-old-kernel-support.patch
1 --- a/src/ipset.c
2 +++ b/src/ipset.c
3 @@ -22,7 +22,6 @@
4  #include <errno.h>
5  #include <sys/types.h>
6  #include <sys/socket.h>
7 -#include <sys/utsname.h>
8  #include <arpa/inet.h>
9  #include <linux/version.h>
10  #include <linux/netlink.h>
11 @@ -72,7 +71,7 @@ struct my_nfgenmsg {
12  
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;
17  static char *buffer;
18  
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
21  
22  void ipset_init(void)
23  {
24 -  struct utsname utsname;
25 -  int version;
26 -  char *split;
27 -  
28 -  if (uname(&utsname) < 0)
29 -    die(_("failed to find kernel version: %s"), NULL, EC_MISC);
30 -  
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));
38 -  
39 -  if (old_kernel && (ipset_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) != -1)
40 -    return;
41 -  
42 -  if (!old_kernel && 
43 +  if ( 
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 *
48  }
49  
50  
51 -static int old_add_to_ipset(const char *setname, const struct all_addr *ipaddr, int remove)
52 -{
53 -  socklen_t size;
54 -  struct ip_set_req_adt_get {
55 -    unsigned op;
56 -    unsigned version;
57 -    union {
58 -      char name[IPSET_MAXNAMELEN];
59 -      uint16_t index;
60 -    } set;
61 -    char typename[IPSET_MAXNAMELEN];
62 -  } req_adt_get;
63 -  struct ip_set_req_adt {
64 -    unsigned op;
65 -    uint16_t index;
66 -    uint32_t ip;
67 -  } req_adt;
68 -  
69 -  if (strlen(setname) >= sizeof(req_adt_get.set.name)) 
70 -    {
71 -      errno = ENAMETOOLONG;
72 -      return -1;
73 -    }
74 -  
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)
80 -    return -1;
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)
85 -    return -1;
86 -  
87 -  return 0;
88 -}
89 -
90 -
91 -
92  int add_to_ipset(const char *setname, const struct all_addr *ipaddr, int flags, int remove)
93  {
94    int af = AF_INET;
95  
96  #ifdef HAVE_IPV6
97    if (flags & F_IPV6)
98 -    {
99        af = AF_INET6;
100 -      /* old method only supports IPv4 */
101 -      if (old_kernel)
102 -       return -1;
103 -    }
104  #endif
105    
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);
108  }
109  
110  #endif