110-ipset-remove-old-kernel-support.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #define NL_ALIGN(len) (((len)+3) & ~(3))
  13. static const struct sockaddr_nl snl = { .nl_family = AF_NETLINK };
  14. -static int ipset_sock, old_kernel;
  15. +static int ipset_sock;
  16. static char *buffer;
  17. static inline void add_attr(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
  18. @@ -87,25 +86,7 @@ static inline void add_attr(struct nlmsg
  19. void ipset_init(void)
  20. {
  21. - struct utsname utsname;
  22. - int version;
  23. - char *split;
  24. -
  25. - if (uname(&utsname) < 0)
  26. - die(_("failed to find kernel version: %s"), NULL, EC_MISC);
  27. -
  28. - split = strtok(utsname.release, ".");
  29. - version = (split ? atoi(split) : 0);
  30. - split = strtok(NULL, ".");
  31. - version = version * 256 + (split ? atoi(split) : 0);
  32. - split = strtok(NULL, ".");
  33. - version = version * 256 + (split ? atoi(split) : 0);
  34. - old_kernel = (version < KERNEL_VERSION(2,6,32));
  35. -
  36. - if (old_kernel && (ipset_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) != -1)
  37. - return;
  38. -
  39. - if (!old_kernel &&
  40. + if (
  41. (buffer = safe_malloc(BUFF_SZ)) &&
  42. (ipset_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER)) != -1 &&
  43. (bind(ipset_sock, (struct sockaddr *)&snl, sizeof(snl)) != -1))
  44. @@ -168,62 +149,16 @@ static int new_add_to_ipset(const char *
  45. }
  46. -static int old_add_to_ipset(const char *setname, const struct all_addr *ipaddr, int remove)
  47. -{
  48. - socklen_t size;
  49. - struct ip_set_req_adt_get {
  50. - unsigned op;
  51. - unsigned version;
  52. - union {
  53. - char name[IPSET_MAXNAMELEN];
  54. - uint16_t index;
  55. - } set;
  56. - char typename[IPSET_MAXNAMELEN];
  57. - } req_adt_get;
  58. - struct ip_set_req_adt {
  59. - unsigned op;
  60. - uint16_t index;
  61. - uint32_t ip;
  62. - } req_adt;
  63. -
  64. - if (strlen(setname) >= sizeof(req_adt_get.set.name))
  65. - {
  66. - errno = ENAMETOOLONG;
  67. - return -1;
  68. - }
  69. -
  70. - req_adt_get.op = 0x10;
  71. - req_adt_get.version = 3;
  72. - strcpy(req_adt_get.set.name, setname);
  73. - size = sizeof(req_adt_get);
  74. - if (getsockopt(ipset_sock, SOL_IP, 83, &req_adt_get, &size) < 0)
  75. - return -1;
  76. - req_adt.op = remove ? 0x102 : 0x101;
  77. - req_adt.index = req_adt_get.set.index;
  78. - req_adt.ip = ntohl(ipaddr->addr.addr4.s_addr);
  79. - if (setsockopt(ipset_sock, SOL_IP, 83, &req_adt, sizeof(req_adt)) < 0)
  80. - return -1;
  81. -
  82. - return 0;
  83. -}
  84. -
  85. -
  86. -
  87. int add_to_ipset(const char *setname, const struct all_addr *ipaddr, int flags, int remove)
  88. {
  89. int af = AF_INET;
  90. #ifdef HAVE_IPV6
  91. if (flags & F_IPV6)
  92. - {
  93. af = AF_INET6;
  94. - /* old method only supports IPv4 */
  95. - if (old_kernel)
  96. - return -1;
  97. - }
  98. #endif
  99. - return old_kernel ? old_add_to_ipset(setname, ipaddr, remove) : new_add_to_ipset(setname, ipaddr, af, remove);
  100. + return new_add_to_ipset(setname, ipaddr, af, remove);
  101. }
  102. #endif