[Olsr-dev] [PATCH v1 039/115] jsoninfo: convert INFO_ALLOW_LOCALHOST define into a plugin parameter
Ferry Huberts
(spam-protected)
Wed Dec 2 21:28:12 CET 2015
From: Ferry Huberts <(spam-protected)>
Signed-off-by: Ferry Huberts <(spam-protected)>
---
lib/jsoninfo/README_JSONINFO | 13 ++++++++-----
lib/jsoninfo/src/olsrd_jsoninfo.c | 9 +--------
lib/jsoninfo/src/olsrd_jsoninfo.h | 4 +---
lib/jsoninfo/src/olsrd_plugin.c | 3 +++
4 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/lib/jsoninfo/README_JSONINFO b/lib/jsoninfo/README_JSONINFO
index 854f093..8ae2e9f 100644
--- a/lib/jsoninfo/README_JSONINFO
+++ b/lib/jsoninfo/README_JSONINFO
@@ -76,16 +76,19 @@ LoadPlugin "olsrd_jsoninfo.so.0.0"
# will be used, others will be ignored.
# PlParam "listen" "0.0.0.0"
- # The first line of the specified file will be read. This line will then be
- # included in the JSON reply as the value of the 'uuid' field.
- # Mainly used for debugging.
- # PlParam "uuidfile" "uuid.txt"
-
# Set to true to prepend HTTP headers before the JSON reply
# PlParam "httpheaders" "false"
+ # 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"
+
+ # The first line of the specified file will be read. This line will then be
+ # included in the JSON reply as the value of the 'uuid' field.
+ # Mainly used for debugging.
+ # PlParam "uuidfile" "uuid.txt"
}
diff --git a/lib/jsoninfo/src/olsrd_jsoninfo.c b/lib/jsoninfo/src/olsrd_jsoninfo.c
index 4977ff6..8255514 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo.c
@@ -66,9 +66,6 @@
#define info_accept_ip jsoninfo_accept_ip
#define info_listen_ip jsoninfo_listen_ip
#define info_ipv6_only jsoninfo_ipv6_only
-#ifdef JSONINFO_ALLOW_LOCALHOST
-#define INFO_ALLOW_LOCALHOST JSONINFO_ALLOW_LOCALHOST
-#endif
static int ipc_socket;
@@ -294,15 +291,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/jsoninfo/src/olsrd_jsoninfo.h b/lib/jsoninfo/src/olsrd_jsoninfo.h
index fd1479a..0381154 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo.h
+++ b/lib/jsoninfo/src/olsrd_jsoninfo.h
@@ -50,14 +50,12 @@
#include "olsrd_plugin.h"
#include "plugin_util.h"
-/* uncomment this to allow connections from 127.0.0.1 regardless of olsrd.conf (useful to allow externel ip/network + localhost) (ipv4 only)*/
-/* #define JSONINFO_ALLOW_LOCALHOST */
-
extern union olsr_ip_addr jsoninfo_accept_ip;
extern union olsr_ip_addr jsoninfo_listen_ip;
extern int ipc_port;
extern int nompr;
extern bool http_headers;
+extern bool allow_localhost;
extern int jsoninfo_ipv6_only;
int olsrd_plugin_interface_version(void);
diff --git a/lib/jsoninfo/src/olsrd_plugin.c b/lib/jsoninfo/src/olsrd_plugin.c
index f1041f1..f62e6c3 100644
--- a/lib/jsoninfo/src/olsrd_plugin.c
+++ b/lib/jsoninfo/src/olsrd_plugin.c
@@ -64,6 +64,7 @@ union olsr_ip_addr jsoninfo_listen_ip;
int ipc_port;
int nompr;
bool http_headers;
+bool allow_localhost;
int jsoninfo_ipv6_only;
char uuidfile[FILENAME_MAX];
@@ -80,6 +81,7 @@ static void my_init(void) {
/* defaults for parameters */
ipc_port = 9090;
http_headers = true;
+ allow_localhost = false;
jsoninfo_ipv6_only = false;
if (olsr_cnf->ip_version == AF_INET) {
@@ -119,6 +121,7 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = { //
{ .name = "accept", .set_plugin_parameter = &set_plugin_ipaddress, .data = &jsoninfo_accept_ip }, //
{ .name = "listen", .set_plugin_parameter = &set_plugin_ipaddress, .data = &jsoninfo_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 = &jsoninfo_ipv6_only }, //
{ .name = "uuidfile", .set_plugin_parameter = &set_plugin_string, .data = uuidfile, .addon = { .ui = FILENAME_MAX - 1 } } //
};
--
2.5.0
More information about the Olsr-dev
mailing list