|
|
e2d397 |
diff --git a/config.h.in b/config.h.in
|
|
|
e2d397 |
index 3b06bfa..2beb538 100644
|
|
|
e2d397 |
--- a/config.h.in
|
|
|
e2d397 |
+++ b/config.h.in
|
|
|
e2d397 |
@@ -735,6 +735,14 @@
|
|
|
e2d397 |
/* Define to 1 to use ipsecmod support. */
|
|
|
e2d397 |
#undef USE_IPSECMOD
|
|
|
e2d397 |
|
|
|
e2d397 |
+/* WARNING! This is only for the libunbound on Linux and does not affect
|
|
|
e2d397 |
+ unbound resolving daemon itself. This may severely limit the number of
|
|
|
e2d397 |
+ available outgoing ports and thus decrease randomness. Define this only
|
|
|
e2d397 |
+ when the target system restricts (e.g. some of SELinux enabled
|
|
|
e2d397 |
+ distributions) the use of non-ephemeral ports. Define this to enable use of
|
|
|
e2d397 |
+ /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range. */
|
|
|
e2d397 |
+#undef USE_LINUX_IP_LOCAL_PORT_RANGE
|
|
|
e2d397 |
+
|
|
|
e2d397 |
/* Define if you want to use internal select based events */
|
|
|
e2d397 |
#undef USE_MINI_EVENT
|
|
|
e2d397 |
|
|
|
e2d397 |
diff --git a/configure b/configure
|
|
|
e2d397 |
index 16d50d0..36cf3fa 100755
|
|
|
e2d397 |
--- a/configure
|
|
|
e2d397 |
+++ b/configure
|
|
|
e2d397 |
@@ -878,6 +878,7 @@ enable_dnscrypt
|
|
|
e2d397 |
with_libsodium
|
|
|
e2d397 |
enable_cachedb
|
|
|
e2d397 |
enable_ipsecmod
|
|
|
e2d397 |
+enable_linux_ip_local_port_range
|
|
|
e2d397 |
with_libunbound_only
|
|
|
e2d397 |
'
|
|
|
e2d397 |
ac_precious_vars='build_alias
|
|
|
e2d397 |
@@ -1565,6 +1566,16 @@ Optional Features:
|
|
|
e2d397 |
storage
|
|
|
e2d397 |
--enable-ipsecmod Enable ipsecmod module that facilitates
|
|
|
e2d397 |
opportunistic IPsec
|
|
|
e2d397 |
+ --enable-linux-ip-local-port-range
|
|
|
e2d397 |
+ WARNING! This is only for the libunbound on Linux
|
|
|
e2d397 |
+ and does not affect unbound resolving daemon itself.
|
|
|
e2d397 |
+ This may severely limit the number of available
|
|
|
e2d397 |
+ outgoing ports and thus decrease randomness. Use
|
|
|
e2d397 |
+ this option only when the target system restricts
|
|
|
e2d397 |
+ the use of non-ephemeral ports. (e.g. some of
|
|
|
e2d397 |
+ SELinux enabled distributions) Enable this option to
|
|
|
e2d397 |
+ use /proc/sys/net/ipv4/ip_local_port_range as a
|
|
|
e2d397 |
+ default outgoing port range
|
|
|
e2d397 |
|
|
|
e2d397 |
Optional Packages:
|
|
|
e2d397 |
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
|
|
|
e2d397 |
@@ -4147,6 +4158,13 @@ else
|
|
|
e2d397 |
else on_mingw="no"; fi
|
|
|
e2d397 |
fi
|
|
|
e2d397 |
|
|
|
e2d397 |
+# are we on Linux?
|
|
|
e2d397 |
+if uname -s 2>&1 | grep -i linux >/dev/null; then on_linux="yes"
|
|
|
e2d397 |
+else
|
|
|
e2d397 |
+ if echo $host $target | grep linux >/dev/null; then on_linux="yes"
|
|
|
e2d397 |
+ else on_linux="no"; fi
|
|
|
e2d397 |
+fi
|
|
|
e2d397 |
+
|
|
|
e2d397 |
#
|
|
|
e2d397 |
# Determine configuration file
|
|
|
e2d397 |
# the eval is to evaluate shell expansion twice
|
|
|
e2d397 |
@@ -20899,6 +20917,23 @@ $as_echo "#define USE_IPSECMOD 1" >>confdefs.h
|
|
|
e2d397 |
;;
|
|
|
e2d397 |
esac
|
|
|
e2d397 |
|
|
|
e2d397 |
+if test $on_linux = "yes"; then
|
|
|
e2d397 |
+ # Check whether --enable-linux-ip-local-port-range was given.
|
|
|
e2d397 |
+if test "${enable_linux_ip_local_port_range+set}" = set; then :
|
|
|
e2d397 |
+ enableval=$enable_linux_ip_local_port_range;
|
|
|
e2d397 |
+fi
|
|
|
e2d397 |
+
|
|
|
e2d397 |
+ case "$enable_linux_ip_local_port_range" in
|
|
|
e2d397 |
+ yes)
|
|
|
e2d397 |
+
|
|
|
e2d397 |
+$as_echo "#define USE_LINUX_IP_LOCAL_PORT_RANGE 1" >>confdefs.h
|
|
|
e2d397 |
+
|
|
|
e2d397 |
+ ;;
|
|
|
e2d397 |
+ no|*)
|
|
|
e2d397 |
+ ;;
|
|
|
e2d397 |
+ esac
|
|
|
e2d397 |
+fi
|
|
|
e2d397 |
+
|
|
|
e2d397 |
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if ${MAKE:-make} supports $< with implicit rule in scope" >&5
|
|
|
e2d397 |
$as_echo_n "checking if ${MAKE:-make} supports $< with implicit rule in scope... " >&6; }
|
|
|
e2d397 |
# on openBSD, the implicit rule make $< work.
|
|
|
e2d397 |
diff --git a/configure.ac b/configure.ac
|
|
|
e2d397 |
index 1bff4ed..525ad62 100644
|
|
|
e2d397 |
--- a/configure.ac
|
|
|
e2d397 |
+++ b/configure.ac
|
|
|
e2d397 |
@@ -131,6 +131,13 @@ else
|
|
|
e2d397 |
else on_mingw="no"; fi
|
|
|
e2d397 |
fi
|
|
|
e2d397 |
|
|
|
e2d397 |
+# are we on Linux?
|
|
|
e2d397 |
+if uname -s 2>&1 | grep -i linux >/dev/null; then on_linux="yes"
|
|
|
e2d397 |
+else
|
|
|
e2d397 |
+ if echo $host $target | grep linux >/dev/null; then on_linux="yes"
|
|
|
e2d397 |
+ else on_linux="no"; fi
|
|
|
e2d397 |
+fi
|
|
|
e2d397 |
+
|
|
|
e2d397 |
#
|
|
|
e2d397 |
# Determine configuration file
|
|
|
e2d397 |
# the eval is to evaluate shell expansion twice
|
|
|
e2d397 |
@@ -1520,6 +1527,17 @@ case "$enable_ipsecmod" in
|
|
|
e2d397 |
;;
|
|
|
e2d397 |
esac
|
|
|
e2d397 |
|
|
|
e2d397 |
+if test $on_linux = "yes"; then
|
|
|
e2d397 |
+ AC_ARG_ENABLE(linux-ip-local-port-range, AC_HELP_STRING([--enable-linux-ip-local-port-range], [WARNING! This is only for the libunbound on Linux and does not affect unbound resolving daemon itself. This may severely limit the number of available outgoing ports and thus decrease randomness. Use this option only when the target system restricts the use of non-ephemeral ports. (e.g. some of SELinux enabled distributions) Enable this option to use /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range]))
|
|
|
e2d397 |
+ case "$enable_linux_ip_local_port_range" in
|
|
|
e2d397 |
+ yes)
|
|
|
e2d397 |
+ AC_DEFINE([USE_LINUX_IP_LOCAL_PORT_RANGE], [1], [WARNING! This is only for the libunbound on Linux and does not affect unbound resolving daemon itself. This may severely limit the number of available outgoing ports and thus decrease randomness. Define this only when the target system restricts (e.g. some of SELinux enabled distributions) the use of non-ephemeral ports. Define this to enable use of /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range.])
|
|
|
e2d397 |
+ ;;
|
|
|
e2d397 |
+ no|*)
|
|
|
e2d397 |
+ ;;
|
|
|
e2d397 |
+ esac
|
|
|
e2d397 |
+fi
|
|
|
e2d397 |
+
|
|
|
e2d397 |
AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
|
|
|
e2d397 |
# on openBSD, the implicit rule make $< work.
|
|
|
e2d397 |
# on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
|
|
|
e2d397 |
diff --git a/libunbound/context.c b/libunbound/context.c
|
|
|
e2d397 |
index 6ac8086..e1fbc64 100644
|
|
|
e2d397 |
--- a/libunbound/context.c
|
|
|
e2d397 |
+++ b/libunbound/context.c
|
|
|
e2d397 |
@@ -60,6 +60,7 @@ context_finalize(struct ub_ctx* ctx)
|
|
|
e2d397 |
if(ctx->logfile_override)
|
|
|
e2d397 |
log_file(ctx->log_out);
|
|
|
e2d397 |
else log_init(cfg->logfile, cfg->use_syslog, NULL);
|
|
|
e2d397 |
+ cfg_apply_local_port_policy(cfg, 65536);
|
|
|
e2d397 |
config_apply(cfg);
|
|
|
e2d397 |
if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
|
|
|
e2d397 |
return UB_INITFAIL;
|
|
|
e2d397 |
diff --git a/util/config_file.c b/util/config_file.c
|
|
|
e2d397 |
index 68a0a15..eaf1ca3 100644
|
|
|
e2d397 |
--- a/util/config_file.c
|
|
|
e2d397 |
+++ b/util/config_file.c
|
|
|
e2d397 |
@@ -1474,6 +1474,37 @@ int cfg_condense_ports(struct config_file* cfg, int** avail)
|
|
|
e2d397 |
return num;
|
|
|
e2d397 |
}
|
|
|
e2d397 |
|
|
|
e2d397 |
+void cfg_apply_local_port_policy(struct config_file* cfg, int num) {
|
|
|
e2d397 |
+(void)cfg;
|
|
|
e2d397 |
+(void)num;
|
|
|
e2d397 |
+#ifdef USE_LINUX_IP_LOCAL_PORT_RANGE
|
|
|
e2d397 |
+ {
|
|
|
e2d397 |
+ int i = 0;
|
|
|
e2d397 |
+ FILE* range_fd;
|
|
|
e2d397 |
+ if ((range_fd = fopen(LINUX_IP_LOCAL_PORT_RANGE_PATH, "r")) != NULL) {
|
|
|
e2d397 |
+ int min_port = 0;
|
|
|
e2d397 |
+ int max_port = num - 1;
|
|
|
e2d397 |
+ if (fscanf(range_fd, "%d %d", &min_port, &max_port) == 2) {
|
|
|
e2d397 |
+ for(i=0; i
|
|
|
e2d397 |
+ cfg->outgoing_avail_ports[i] = 0;
|
|
|
e2d397 |
+ }
|
|
|
e2d397 |
+ for(i=max_port+1; i
|
|
|
e2d397 |
+ cfg->outgoing_avail_ports[i] = 0;
|
|
|
e2d397 |
+ }
|
|
|
e2d397 |
+ } else {
|
|
|
e2d397 |
+ log_err("unexpected port range in %s",
|
|
|
e2d397 |
+ LINUX_IP_LOCAL_PORT_RANGE_PATH);
|
|
|
e2d397 |
+ }
|
|
|
e2d397 |
+ fclose(range_fd);
|
|
|
e2d397 |
+ } else {
|
|
|
e2d397 |
+ log_warn("failed to read from file: %s (%s)",
|
|
|
e2d397 |
+ LINUX_IP_LOCAL_PORT_RANGE_PATH,
|
|
|
e2d397 |
+ strerror(errno));
|
|
|
e2d397 |
+ }
|
|
|
e2d397 |
+ }
|
|
|
e2d397 |
+#endif
|
|
|
e2d397 |
+}
|
|
|
e2d397 |
+
|
|
|
e2d397 |
/** print error with file and line number */
|
|
|
e2d397 |
static void ub_c_error_va_list(const char *fmt, va_list args)
|
|
|
e2d397 |
{
|
|
|
e2d397 |
diff --git a/util/config_file.h b/util/config_file.h
|
|
|
e2d397 |
index 1e7f402..3aa71b7 100644
|
|
|
e2d397 |
--- a/util/config_file.h
|
|
|
e2d397 |
+++ b/util/config_file.h
|
|
|
e2d397 |
@@ -1009,6 +1009,13 @@ int cfg_mark_ports(const char* str, int allow, int* avail, int num);
|
|
|
e2d397 |
*/
|
|
|
e2d397 |
int cfg_condense_ports(struct config_file* cfg, int** avail);
|
|
|
e2d397 |
|
|
|
e2d397 |
+/**
|
|
|
e2d397 |
+ * Apply system specific port range policy.
|
|
|
e2d397 |
+ * @param cfg: config file.
|
|
|
e2d397 |
+ * @param num: size of the array (65536).
|
|
|
e2d397 |
+ */
|
|
|
e2d397 |
+void cfg_apply_local_port_policy(struct config_file* cfg, int num);
|
|
|
e2d397 |
+
|
|
|
e2d397 |
/**
|
|
|
e2d397 |
* Scan ports available
|
|
|
e2d397 |
* @param avail: the array from cfg.
|
|
|
e2d397 |
@@ -1138,4 +1145,8 @@ void w_config_adjust_directory(struct config_file* cfg);
|
|
|
e2d397 |
/** debug option for unit tests. */
|
|
|
e2d397 |
extern int fake_dsa, fake_sha1;
|
|
|
e2d397 |
|
|
|
e2d397 |
+#ifdef USE_LINUX_IP_LOCAL_PORT_RANGE
|
|
|
e2d397 |
+#define LINUX_IP_LOCAL_PORT_RANGE_PATH "/proc/sys/net/ipv4/ip_local_port_range"
|
|
|
e2d397 |
+#endif
|
|
|
e2d397 |
+
|
|
|
e2d397 |
#endif /* UTIL_CONFIG_FILE_H */
|