[Olsr-dev] [PATCH] dyn gw plugin - add PingCmd parameter
cholin
(spam-protected)
Sat Sep 27 13:43:13 CEST 2014
From: Nico Geyso <(spam-protected)>
Add possibilty to set PingCmd by config. This is useful for instance
if you do want to set an interface or execute your own script. See
README_DYN_GW for an example. Branched of v0.6.6.2.
---
lib/dyn_gw/README_DYN_GW | 3 +++
lib/dyn_gw/src/olsrd_dyn_gw.c | 25 ++++++++++++++++++++++---
lib/dyn_gw/src/olsrd_dyn_gw.h | 2 ++
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/lib/dyn_gw/README_DYN_GW b/lib/dyn_gw/README_DYN_GW
index 0aea1f9..8f3e02d 100644
--- a/lib/dyn_gw/README_DYN_GW
+++ b/lib/dyn_gw/README_DYN_GW
@@ -87,6 +87,9 @@ LoadPlugin "olsrd_dyn_gw.so.0.5"
PlParam "HNA" "192.168.200.0 255.255.255.0"
PlParam "HNA" "192.168.201.0 255.255.255.0"
PlParam "HNA" "192.168.202.0 255.255.255.0"
+
+ # Set custom ping command - %s will be replaced with IP to ping
+ PlParam "PingCmd" "ping -c 1 -q -I vpn %s"
}
--------------------------------------------------------------------------------
diff --git a/lib/dyn_gw/src/olsrd_dyn_gw.c b/lib/dyn_gw/src/olsrd_dyn_gw.c
index 027863c..5df1039 100644
--- a/lib/dyn_gw/src/olsrd_dyn_gw.c
+++ b/lib/dyn_gw/src/olsrd_dyn_gw.c
@@ -128,6 +128,8 @@ static bool check_gw(union olsr_ip_addr *, uint8_t, struct ping_list *);
static int ping_is_possible(struct ping_list *);
+static char ping_cmd[PING_CMD_MAX_LEN] = { DEFAULT_PING_CHECK_INTERVAL };
+
/* Event function to register with the scheduler */
static void olsr_event_doing_hna(void *);
@@ -205,12 +207,29 @@ set_plugin_hna(const char *value, void *data __attribute__ ((unused)), set_plugi
return 0;
}
+static int
+set_plugin_cmd(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
+{
+ size_t len = strlen(value);
+
+ if (len < PING_CMD_MAX_LEN) {
+ memcpy(ping_cmd, value, len);
+ OLSR_PRINTF(2, "Set ping command to: %s\n", ping_cmd);
+ return 0;
+ }
+
+ OLSR_PRINTF(0, "Ping command exceed max length: %d > %zu", PING_CMD_MAX_LEN, len);
+
+ return 1;
+}
+
static const struct olsrd_plugin_parameters plugin_parameters[] = {
{.name = "interval", .set_plugin_parameter = &set_plugin_int, .data = &ping_check_interval },
{.name = "pinginterval", .set_plugin_parameter = &set_plugin_int, .data = &ping_check_interval },
{.name = "checkinterval", .set_plugin_parameter = &set_plugin_int, .data = &hna_check_interval },
{.name = "ping", .set_plugin_parameter = &set_plugin_ping, .data = NULL },
{.name = "hna", .set_plugin_parameter = &set_plugin_hna, .data = NULL },
+ {.name = "pingcmd", .set_plugin_parameter = &set_plugin_cmd, .data = &ping_cmd },
};
void
@@ -536,9 +555,9 @@ ping_is_possible(struct ping_list *the_ping_list)
{
struct ping_list *list;
for (list = the_ping_list; list; list = list->next) {
- char ping_command[50];
- snprintf(ping_command, sizeof(ping_command), "ping -c 1 -q %s", list->ping_address);
- olsr_printf(1, "\nDo ping on %s ...\n", list->ping_address);
+ char ping_command[96];
+ snprintf(ping_command, sizeof(ping_command), ping_cmd, list->ping_address);
+ olsr_printf(1, "\nDo ping on (%s) %s ...\n", ping_cmd, list->ping_address);
if (system(ping_command) == 0) {
olsr_printf(1, "...OK\n\n");
return 1;
diff --git a/lib/dyn_gw/src/olsrd_dyn_gw.h b/lib/dyn_gw/src/olsrd_dyn_gw.h
index 4db0838..bdca978 100644
--- a/lib/dyn_gw/src/olsrd_dyn_gw.h
+++ b/lib/dyn_gw/src/olsrd_dyn_gw.h
@@ -54,6 +54,8 @@
#define DEFAULT_HNA_CHECK_INTERVAL 1000
#define DEFAULT_PING_CHECK_INTERVAL 5
+#define DEFAULT_PING_CMD "ping -c 1 -q %s"
+#define PING_CMD_MAX_LEN 64
int olsrd_plugin_init(void);
--
2.1.0
More information about the Olsr-dev
mailing list