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.

110 lines
3.2 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. --- a/getifaddr.c
  9. +++ b/getifaddr.c
  10. @@ -25,6 +25,7 @@
  11. #if defined(USE_GETIFADDRS) || defined(ENABLE_IPV6) || defined(ENABLE_PCP)
  12. #include <ifaddrs.h>
  13. #endif
  14. +#include "upnpglobalvars.h"
  15. int
  16. getifaddr(const char * ifname, char * buf, int len,
  17. @@ -295,6 +296,11 @@ addr_is_reserved(struct in_addr * addr)
  18. uint32_t address = ntohl(addr->s_addr);
  19. size_t i;
  20. + if(GETFLAG(EXTIPRESERVEDIGNOREMASK)) {
  21. + syslog(LOG_NOTICE, "private/reserved address checking is ignore");
  22. + return 0;
  23. + }
  24. +
  25. for (i = 0; i < sizeof(reserved)/sizeof(reserved[0]); ++i) {
  26. if ((address >> reserved[i].rmask) == (reserved[i].address >> reserved[i].rmask))
  27. return 1;
  28. --- a/miniupnpd.c
  29. +++ b/miniupnpd.c
  30. @@ -1225,6 +1225,10 @@ init(int argc, char * * argv, struct run
  31. case UPNPEXT_IP:
  32. use_ext_ip_addr = ary_options[i].value;
  33. break;
  34. + case UPNPEXT_IP_RESERVED_IGNORE:
  35. + if(strcmp(ary_options[i].value, "yes") == 0)
  36. + SETFLAG(EXTIPRESERVEDIGNOREMASK);
  37. + break;
  38. case UPNPEXT_PERFORM_STUN:
  39. if(strcmp(ary_options[i].value, "yes") == 0)
  40. SETFLAG(PERFORMSTUNMASK);
  41. --- a/miniupnpd.conf
  42. +++ b/miniupnpd.conf
  43. @@ -9,6 +9,8 @@
  44. # Setting ext_ip is also useful in double NAT setup, you can declare here
  45. # the public IP address.
  46. #ext_ip=
  47. +#ignore even if ext_ip is reserved: default is no
  48. +#ext_ip_reserved_ignore=yes
  49. # WAN interface must have public IP address. Otherwise it is behind NAT
  50. # and port forwarding is impossible. In some cases WAN interface can be
  51. # behind unrestricted NAT 1:1 when all incoming traffic is NAT-ed and
  52. --- a/options.c
  53. +++ b/options.c
  54. @@ -34,6 +34,7 @@ static const struct {
  55. { UPNPEXT_IFNAME6, "ext_ifname6" },
  56. #endif
  57. { UPNPEXT_IP, "ext_ip" },
  58. + { UPNPEXT_IP_RESERVED_IGNORE, "ext_ip_reserved_ignore" },
  59. { UPNPEXT_PERFORM_STUN, "ext_perform_stun" },
  60. { UPNPEXT_STUN_HOST, "ext_stun_host" },
  61. { UPNPEXT_STUN_PORT, "ext_stun_port" },
  62. --- a/options.h
  63. +++ b/options.h
  64. @@ -21,6 +21,7 @@ enum upnpconfigoptions {
  65. UPNPEXT_IFNAME6, /* ext_ifname6 */
  66. #endif
  67. UPNPEXT_IP, /* ext_ip */
  68. + UPNPEXT_IP_RESERVED_IGNORE, /* ignore if ext_ip is reserved */
  69. UPNPEXT_PERFORM_STUN, /* ext_perform_stun */
  70. UPNPEXT_STUN_HOST, /* ext_stun_host */
  71. UPNPEXT_STUN_PORT, /* ext_stun_port */
  72. --- a/testgetifaddr.c
  73. +++ b/testgetifaddr.c
  74. @@ -13,6 +13,8 @@
  75. #include "config.h"
  76. #include "getifaddr.h"
  77. +int runtime_flags = 0;
  78. +
  79. #if defined(__sun)
  80. /* solaris 10 does not define LOG_PERROR */
  81. #define LOG_PERROR 0
  82. --- a/testportinuse.c
  83. +++ b/testportinuse.c
  84. @@ -14,6 +14,8 @@
  85. #include "config.h"
  86. #include "portinuse.h"
  87. +int runtime_flags = 0;
  88. +
  89. int main(int argc, char * * argv)
  90. {
  91. #ifndef CHECK_PORTINUSE
  92. --- a/upnpglobalvars.h
  93. +++ b/upnpglobalvars.h
  94. @@ -84,6 +84,8 @@ extern int runtime_flags;
  95. #define PERFORMSTUNMASK 0x1000
  96. +#define EXTIPRESERVEDIGNOREMASK 0x2000
  97. +
  98. #define SETFLAG(mask) runtime_flags |= mask
  99. #define GETFLAG(mask) (runtime_flags & mask)
  100. #define CLEARFLAG(mask) runtime_flags &= ~mask