You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.8 KiB

  1. commit cb046cfef1d6b954d3fc09f09a1fc3a7ffeb7593
  2. Author: Chen Minqiang <ptpt52@gmail.com>
  3. Date: Sun Jul 5 10:42:52 2020 +0800
  4. options: ext_ip_reserved_ignore support
  5. This make the port forwarding force to work even
  6. when the router is behind NAT
  7. Signed-off-by: Chen Minqiang <ptpt52@gmail.com>
  8. diff --git a/getifaddr.c b/getifaddr.c
  9. index 7c09064..46cae8c 100644
  10. --- a/getifaddr.c
  11. +++ b/getifaddr.c
  12. @@ -25,6 +25,7 @@
  13. #if defined(USE_GETIFADDRS) || defined(ENABLE_IPV6) || defined(ENABLE_PCP)
  14. #include <ifaddrs.h>
  15. #endif
  16. +#include "upnpglobalvars.h"
  17. int
  18. getifaddr(const char * ifname, char * buf, int len,
  19. @@ -295,6 +296,11 @@ addr_is_reserved(struct in_addr * addr)
  20. uint32_t address = ntohl(addr->s_addr);
  21. size_t i;
  22. + if(GETFLAG(EXTIPRESERVEDIGNOREMASK)) {
  23. + syslog(LOG_NOTICE, "private/reserved address checking is ignore");
  24. + return 0;
  25. + }
  26. +
  27. for (i = 0; i < sizeof(reserved)/sizeof(reserved[0]); ++i) {
  28. if ((address >> reserved[i].rmask) == (reserved[i].address >> reserved[i].rmask))
  29. return 1;
  30. diff --git a/miniupnpd.c b/miniupnpd.c
  31. index e9f9f61..86b4200 100644
  32. --- a/miniupnpd.c
  33. +++ b/miniupnpd.c
  34. @@ -1225,6 +1225,10 @@ init(int argc, char * * argv, struct runtime_vars * v)
  35. case UPNPEXT_IP:
  36. use_ext_ip_addr = ary_options[i].value;
  37. break;
  38. + case UPNPEXT_IP_RESERVED_IGNORE:
  39. + if(strcmp(ary_options[i].value, "yes") == 0)
  40. + SETFLAG(EXTIPRESERVEDIGNOREMASK);
  41. + break;
  42. case UPNPEXT_PERFORM_STUN:
  43. if(strcmp(ary_options[i].value, "yes") == 0)
  44. SETFLAG(PERFORMSTUNMASK);
  45. diff --git a/miniupnpd.conf b/miniupnpd.conf
  46. index 6274f67..c614192 100644
  47. --- a/miniupnpd.conf
  48. +++ b/miniupnpd.conf
  49. @@ -9,6 +9,8 @@
  50. # Setting ext_ip is also useful in double NAT setup, you can declare here
  51. # the public IP address.
  52. #ext_ip=
  53. +#ignore even if ext_ip is reserved: default is no
  54. +#ext_ip_reserved_ignore=yes
  55. # WAN interface must have public IP address. Otherwise it is behind NAT
  56. # and port forwarding is impossible. In some cases WAN interface can be
  57. # behind unrestricted NAT 1:1 when all incoming traffic is NAT-ed and
  58. diff --git a/options.c b/options.c
  59. index 05fa317..3711094 100644
  60. --- a/options.c
  61. +++ b/options.c
  62. @@ -34,6 +34,7 @@ static const struct {
  63. { UPNPEXT_IFNAME6, "ext_ifname6" },
  64. #endif
  65. { UPNPEXT_IP, "ext_ip" },
  66. + { UPNPEXT_IP_RESERVED_IGNORE, "ext_ip_reserved_ignore" },
  67. { UPNPEXT_PERFORM_STUN, "ext_perform_stun" },
  68. { UPNPEXT_STUN_HOST, "ext_stun_host" },
  69. { UPNPEXT_STUN_PORT, "ext_stun_port" },
  70. diff --git a/options.h b/options.h
  71. index 96cdbbf..34c698f 100644
  72. --- a/options.h
  73. +++ b/options.h
  74. @@ -21,6 +21,7 @@ enum upnpconfigoptions {
  75. UPNPEXT_IFNAME6, /* ext_ifname6 */
  76. #endif
  77. UPNPEXT_IP, /* ext_ip */
  78. + UPNPEXT_IP_RESERVED_IGNORE, /* ignore if ext_ip is reserved */
  79. UPNPEXT_PERFORM_STUN, /* ext_perform_stun */
  80. UPNPEXT_STUN_HOST, /* ext_stun_host */
  81. UPNPEXT_STUN_PORT, /* ext_stun_port */
  82. diff --git a/testgetifaddr.c b/testgetifaddr.c
  83. index 8045b89..b5cdbb4 100644
  84. --- a/testgetifaddr.c
  85. +++ b/testgetifaddr.c
  86. @@ -13,6 +13,8 @@
  87. #include "config.h"
  88. #include "getifaddr.h"
  89. +int runtime_flags = 0;
  90. +
  91. #if defined(__sun)
  92. /* solaris 10 does not define LOG_PERROR */
  93. #define LOG_PERROR 0
  94. diff --git a/testportinuse.c b/testportinuse.c
  95. index 98574c6..507f830 100644
  96. --- a/testportinuse.c
  97. +++ b/testportinuse.c
  98. @@ -14,6 +14,8 @@
  99. #include "config.h"
  100. #include "portinuse.h"
  101. +int runtime_flags = 0;
  102. +
  103. int main(int argc, char * * argv)
  104. {
  105. #ifndef CHECK_PORTINUSE
  106. diff --git a/upnpglobalvars.h b/upnpglobalvars.h
  107. index a474353..4f5bbdd 100644
  108. --- a/upnpglobalvars.h
  109. +++ b/upnpglobalvars.h
  110. @@ -84,6 +84,8 @@ extern int runtime_flags;
  111. #define PERFORMSTUNMASK 0x1000
  112. +#define EXTIPRESERVEDIGNOREMASK 0x2000
  113. +
  114. #define SETFLAG(mask) runtime_flags |= mask
  115. #define GETFLAG(mask) (runtime_flags & mask)
  116. #define CLEARFLAG(mask) runtime_flags &= ~mask