[Olsr-dev] [PATCH v1 038/115] txtinfo: convert INFO_ALLOW_LOCALHOST define into a plugin parameter
Ferry Huberts
(spam-protected)
Wed Dec 2 21:28:11 CET 2015
From: Ferry Huberts <(spam-protected)>
Signed-off-by: Ferry Huberts <(spam-protected)>
---
lib/txtinfo/README_TXTINFO | 3 +++
lib/txtinfo/src/olsrd_plugin.c | 3 +++
lib/txtinfo/src/olsrd_txtinfo.c | 9 +--------
lib/txtinfo/src/olsrd_txtinfo.h | 4 +---
4 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/lib/txtinfo/README_TXTINFO b/lib/txtinfo/README_TXTINFO
index ab5f828..57b1ea9 100644
--- a/lib/txtinfo/README_TXTINFO
+++ b/lib/txtinfo/README_TXTINFO
@@ -74,6 +74,9 @@ LoadPlugin "olsrd_txtinfo.so.0.1"
# Set to true to prepend HTTP headers before the reply
# PlParam "httpheaders" "true"
+ # Set to true to always allow connections from 127.0.0.1
+ # PlParam "allowlocalhost" "false"
+
# Set to true to only listen on IPv6 addresses when running in IPv6 mode.
# PlParam "ipv6only" "false"
}
\ No newline at end of file
diff --git a/lib/txtinfo/src/olsrd_plugin.c b/lib/txtinfo/src/olsrd_plugin.c
index 3752867..cc50e6f 100644
--- a/lib/txtinfo/src/olsrd_plugin.c
+++ b/lib/txtinfo/src/olsrd_plugin.c
@@ -64,6 +64,7 @@ union olsr_ip_addr txtinfo_listen_ip;
int ipc_port;
int nompr;
bool http_headers;
+bool allow_localhost;
int txtinfo_ipv6_only;
static void my_init(void) __attribute__ ((constructor));
@@ -79,6 +80,7 @@ static void my_init(void) {
/* defaults for parameters */
ipc_port = 2006;
http_headers = true;
+ allow_localhost = false;
txtinfo_ipv6_only = false;
if (olsr_cnf->ip_version == AF_INET) {
@@ -116,6 +118,7 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = { //
{ .name = "accept", .set_plugin_parameter = &set_plugin_ipaddress, .data = &txtinfo_accept_ip }, //
{ .name = "listen", .set_plugin_parameter = &set_plugin_ipaddress, .data = &txtinfo_listen_ip }, //
{ .name = "httpheaders", .set_plugin_parameter = &set_plugin_boolean, .data = &http_headers }, //
+ { .name = "allowlocalhost", .set_plugin_parameter = &set_plugin_boolean, .data = &allow_localhost }, //
{ .name = "ipv6only", .set_plugin_parameter = &set_plugin_boolean, .data = &txtinfo_ipv6_only } //
};
diff --git a/lib/txtinfo/src/olsrd_txtinfo.c b/lib/txtinfo/src/olsrd_txtinfo.c
index e1f6ddf..a48b645 100644
--- a/lib/txtinfo/src/olsrd_txtinfo.c
+++ b/lib/txtinfo/src/olsrd_txtinfo.c
@@ -65,9 +65,6 @@
#define info_accept_ip txtinfo_accept_ip
#define info_listen_ip txtinfo_listen_ip
#define info_ipv6_only txtinfo_ipv6_only
-#ifdef TXTINFO_ALLOW_LOCALHOST
-#define INFO_ALLOW_LOCALHOST TXTINFO_ALLOW_LOCALHOST
-#endif
static int ipc_socket;
@@ -293,15 +290,11 @@ static void ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int
if (inet_ntop(olsr_cnf->ip_version, &pin.in4.sin_addr, addr, INET6_ADDRSTRLEN) == NULL)
addr[0] = '\0';
if (!ip4equal(&pin.in4.sin_addr, &info_accept_ip.v4) && info_accept_ip.v4.s_addr != INADDR_ANY) {
-#ifdef INFO_ALLOW_LOCALHOST
- if (ntohl(pin.in4.sin_addr.s_addr) != INADDR_LOOPBACK) {
-#endif /* INFO_ALLOW_LOCALHOST */
+ if (!allow_localhost || ntohl(pin.in4.sin_addr.s_addr) != INADDR_LOOPBACK) {
olsr_printf(1, "("PLUGIN_NAME") From host(%s) not allowed!\n", addr);
close(ipc_connection);
return;
-#ifdef INFO_ALLOW_LOCALHOST
}
-#endif /* INFO_ALLOW_LOCALHOST */
}
} else {
if (inet_ntop(olsr_cnf->ip_version, &pin.in6.sin6_addr, addr, INET6_ADDRSTRLEN) == NULL)
diff --git a/lib/txtinfo/src/olsrd_txtinfo.h b/lib/txtinfo/src/olsrd_txtinfo.h
index c0659ba..eac3aca 100644
--- a/lib/txtinfo/src/olsrd_txtinfo.h
+++ b/lib/txtinfo/src/olsrd_txtinfo.h
@@ -53,14 +53,12 @@
/* uncomment this to include VTime values into Link/Topology command */
/* #define ACTIVATE_VTIME_TXTINFO */
-/* uncomment this to allow connections from 127.0.0.1 regardless of olsrd.conf (useful to allow externel ip/network + localhost) (ipv4 only)*/
-/* #define TXTINFO_ALLOW_LOCALHOST */
-
extern union olsr_ip_addr txtinfo_accept_ip;
extern union olsr_ip_addr txtinfo_listen_ip;
extern int ipc_port;
extern int nompr;
extern bool http_headers;
+extern bool allow_localhost;
extern int txtinfo_ipv6_only;
int olsrd_plugin_interface_version(void);
--
2.5.0
More information about the Olsr-dev
mailing list