0030-dnsmasq-add-patch-to-allow-setting-the-default-packet-mark.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 6 Jul 2014 08:12:35 +0200
  3. Subject: dnsmasq: add patch to allow setting the default packet mark
  4. diff --git a/package/dnsmasq/patches/901-packet-mark.patch b/package/dnsmasq/patches/901-packet-mark.patch
  5. new file mode 100644
  6. index 0000000..286af3a
  7. --- /dev/null
  8. +++ b/package/dnsmasq/patches/901-packet-mark.patch
  9. @@ -0,0 +1,103 @@
  10. +--- a/src/dnsmasq.h
  11. ++++ b/src/dnsmasq.h
  12. +@@ -802,6 +802,7 @@ extern struct daemon {
  13. + int cachesize, ftabsize;
  14. + int port, query_port, min_port;
  15. + unsigned long local_ttl, neg_ttl, max_ttl, max_cache_ttl, auth_ttl;
  16. ++ unsigned int packet_mark;
  17. + struct hostsfile *addn_hosts;
  18. + struct dhcp_context *dhcp, *dhcp6;
  19. + struct dhcp_config *dhcp_conf;
  20. +--- a/src/forward.c
  21. ++++ b/src/forward.c
  22. +@@ -366,17 +366,17 @@ static int forward_query(int udpfd, unio
  23. + daemon->rfd_save = forward->rfd4;
  24. + fd = forward->rfd4->fd;
  25. + }
  26. ++ }
  27. ++
  28. ++ unsigned int mark = daemon->packet_mark;
  29. +
  30. + #ifdef HAVE_CONNTRACK
  31. +- /* Copy connection mark of incoming query to outgoing connection. */
  32. +- if (option_bool(OPT_CONNTRACK))
  33. +- {
  34. +- unsigned int mark;
  35. +- if (get_incoming_mark(udpaddr, dst_addr, 0, &mark))
  36. +- setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(unsigned int));
  37. +- }
  38. ++ /* Copy connection mark of incoming query to outgoing connection. */
  39. ++ if (option_bool(OPT_CONNTRACK))
  40. ++ get_incoming_mark(udpaddr, dst_addr, 0, &mark);
  41. + #endif
  42. +- }
  43. ++
  44. ++ setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(unsigned int));
  45. +
  46. + if (sendto(fd, (char *)header, plen, 0,
  47. + &start->addr.sa,
  48. +@@ -1001,11 +1001,11 @@ unsigned char *tcp_request(int confd, ti
  49. + continue;
  50. + }
  51. +
  52. ++ unsigned int mark = daemon->packet_mark;
  53. + #ifdef HAVE_CONNTRACK
  54. + /* Copy connection mark of incoming query to outgoing connection. */
  55. + if (option_bool(OPT_CONNTRACK))
  56. + {
  57. +- unsigned int mark;
  58. + struct all_addr local;
  59. + #ifdef HAVE_IPV6
  60. + if (local_addr->sa.sa_family == AF_INET6)
  61. +@@ -1014,10 +1014,11 @@ unsigned char *tcp_request(int confd, ti
  62. + #endif
  63. + local.addr.addr4 = local_addr->in.sin_addr;
  64. +
  65. +- if (get_incoming_mark(&peer_addr, &local, 1, &mark))
  66. +- setsockopt(last_server->tcpfd, SOL_SOCKET, SO_MARK, &mark, sizeof(unsigned int));
  67. ++ get_incoming_mark(&peer_addr, &local, 1, &mark);
  68. + }
  69. + #endif
  70. ++
  71. ++ setsockopt(last_server->tcpfd, SOL_SOCKET, SO_MARK, &mark, sizeof(unsigned int));
  72. + }
  73. +
  74. + c1 = size >> 8;
  75. +--- a/src/option.c
  76. ++++ b/src/option.c
  77. +@@ -131,6 +131,7 @@ struct myoption {
  78. + #ifdef OPTION6_PREFIX_CLASS
  79. + #define LOPT_PREF_CLSS 320
  80. + #endif
  81. ++#define LOPT_PACKET_MARK 9001
  82. +
  83. + #ifdef HAVE_GETOPT_LONG
  84. + static const struct option opts[] =
  85. +@@ -267,6 +268,7 @@ static const struct myoption opts[] =
  86. + #ifdef OPTION6_PREFIX_CLASS
  87. + { "dhcp-prefix-class", 1, 0, LOPT_PREF_CLSS },
  88. + #endif
  89. ++ { "packet-mark", 1, 0, LOPT_PACKET_MARK },
  90. + { NULL, 0, 0, 0 }
  91. + };
  92. +
  93. +@@ -409,6 +411,7 @@ static struct {
  94. + #ifdef OPTION6_PREFIX_CLASS
  95. + { LOPT_PREF_CLSS, ARG_DUP, "set:tag,<class>", gettext_noop("Specify DHCPv6 prefix class"), NULL },
  96. + #endif
  97. ++ { LOPT_PACKET_MARK, ARG_ONE, "<integer>", gettext_noop("Specify default packet mark for DNS queries."), NULL },
  98. + { 0, 0, NULL, NULL, NULL }
  99. + };
  100. +
  101. +@@ -2189,6 +2192,11 @@ static int one_opt(int option, char *arg
  102. + break;
  103. + }
  104. +
  105. ++ case LOPT_PACKET_MARK: /* --packet-mark */
  106. ++ if (!atoi_check(arg, (int*)&daemon->packet_mark))
  107. ++ ret_err(gen_err);
  108. ++ break;
  109. ++
  110. + #ifdef HAVE_DHCP
  111. + case 'X': /* --dhcp-lease-max */
  112. + if (!atoi_check(arg, &daemon->dhcp_max))