Repository : ssh://git@open-mesh.org/batctl
On branch : master
commit cde0af82935131f37b308fde47aba06e6d15a5b7 Author: Sven Eckelmann sven@narfation.org Date: Sat Feb 23 08:41:08 2019 +0100
batctl: Add hop_penalty setting command
OpenWrt was switched to use batctl as abstraction of the sysfs and netlink configuration interface. The only additional configuration option to finish this process is hop_penalty. It is required to define the penalty which will be applied to an originator message's tq-field on every hop.
Signed-off-by: Sven Eckelmann sven@narfation.org
cde0af82935131f37b308fde47aba06e6d15a5b7 Makefile | 1 + README.rst | 15 ++++++++++++ orig_interval.c => hop_penalty.c | 50 ++++++++++++++++++++-------------------- man/batctl.8 | 4 ++++ 4 files changed, 45 insertions(+), 25 deletions(-)
diff --git a/Makefile b/Makefile index 4d8b709..55105cc 100755 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ $(eval $(call add_command,event,y)) $(eval $(call add_command,fragmentation,y)) $(eval $(call add_command,gateways,y)) $(eval $(call add_command,gw_mode,y)) +$(eval $(call add_command,hop_penalty,y)) $(eval $(call add_command,interface,y)) $(eval $(call add_command,isolation_mark,y)) $(eval $(call add_command,log,y)) diff --git a/README.rst b/README.rst index 4c0f544..e30b5b9 100644 --- a/README.rst +++ b/README.rst @@ -530,6 +530,21 @@ Usage:: batctl aggregation|ag [0|1]
+batctl hop_penalty +================== + +display or modify the hop_penalty (0-255) + +Usage:: + + batctl hop_penalty|hp [penalty] + +Example:: + + $ batctl penalty + 30 + + batctl isolation_mark =====================
diff --git a/orig_interval.c b/hop_penalty.c similarity index 62% copy from orig_interval.c copy to hop_penalty.c index d1501af..58067bf 100644 --- a/orig_interval.c +++ b/hop_penalty.c @@ -28,14 +28,14 @@ #include "main.h" #include "sys.h"
-static struct orig_interval_data { - uint32_t orig_interval; -} orig_interval; +static struct hop_penalty_data { + uint8_t hop_penalty; +} hop_penalty;
-static int parse_orig_interval(struct state *state, int argc, char *argv[]) +static int parse_hop_penalty(struct state *state, int argc, char *argv[]) { struct settings_data *settings = state->cmd->arg; - struct orig_interval_data *data = settings->data; + struct hop_penalty_data *data = settings->data; char *endptr;
if (argc != 2) { @@ -43,7 +43,7 @@ static int parse_orig_interval(struct state *state, int argc, char *argv[]) return -EINVAL; }
- data->orig_interval = strtoul(argv[1], &endptr, 0); + data->hop_penalty = strtoul(argv[1], &endptr, 0); if (!endptr || *endptr != '\0') { fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]); return -EINVAL; @@ -52,7 +52,7 @@ static int parse_orig_interval(struct state *state, int argc, char *argv[]) return 0; }
-static int print_orig_interval(struct nl_msg *msg, void *arg) +static int print_hop_penalty(struct nl_msg *msg, void *arg) { struct nlattr *attrs[BATADV_ATTR_MAX + 1]; struct nlmsghdr *nlh = nlmsg_hdr(msg); @@ -69,47 +69,47 @@ static int print_orig_interval(struct nl_msg *msg, void *arg) return NL_OK; }
- if (!attrs[BATADV_ATTR_ORIG_INTERVAL]) + if (!attrs[BATADV_ATTR_HOP_PENALTY]) return NL_OK;
- printf("%u\n", nla_get_u32(attrs[BATADV_ATTR_ORIG_INTERVAL])); + printf("%u\n", nla_get_u8(attrs[BATADV_ATTR_HOP_PENALTY]));
*result = 0; return NL_STOP; }
-static int get_orig_interval(struct state *state) +static int get_hop_penalty(struct state *state) { return sys_simple_nlquery(state, BATADV_CMD_GET_MESH, - NULL, print_orig_interval); + NULL, print_hop_penalty); }
-static int set_attrs_orig_interval(struct nl_msg *msg, void *arg) +static int set_attrs_hop_penalty(struct nl_msg *msg, void *arg) { struct state *state = arg; struct settings_data *settings = state->cmd->arg; - struct orig_interval_data *data = settings->data; + struct hop_penalty_data *data = settings->data;
- nla_put_u32(msg, BATADV_ATTR_ORIG_INTERVAL, data->orig_interval); + nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY, data->hop_penalty);
return 0; }
-static int set_orig_interval(struct state *state) +static int set_hop_penalty(struct state *state) { return sys_simple_nlquery(state, BATADV_CMD_SET_MESH, - set_attrs_orig_interval, NULL); + set_attrs_hop_penalty, NULL); }
-static struct settings_data batctl_settings_orig_interval = { - .sysfs_name = "orig_interval", - .data = &orig_interval, - .parse = parse_orig_interval, - .netlink_get = get_orig_interval, - .netlink_set = set_orig_interval, +static struct settings_data batctl_settings_hop_penalty = { + .sysfs_name = "hop_penalty", + .data = &hop_penalty, + .parse = parse_hop_penalty, + .netlink_get = get_hop_penalty, + .netlink_set = set_hop_penalty, };
-COMMAND_NAMED(SUBCOMMAND, orig_interval, "it", handle_sys_setting, +COMMAND_NAMED(SUBCOMMAND, hop_penalty, "hp", handle_sys_setting, COMMAND_FLAG_MESH_IFACE | COMMAND_FLAG_NETLINK, - &batctl_settings_orig_interval, - "[interval] \tdisplay or modify orig_interval setting"); + &batctl_settings_hop_penalty, + "[penalty] \tdisplay or modify hop_penalty setting"); diff --git a/man/batctl.8 b/man/batctl.8 index ed8e71f..0fbf1dd 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -97,6 +97,10 @@ when parameter \fB-t\fP is specified. Parameter \fB-r\fP will do the same but If no parameter is given the current fragmentation mode setting is displayed. Otherwise the parameter is used to enable or disable fragmentation. .br +.IP "\fBhop_penalty\fP|\fBhp\fP [\fBpenalty\fP]" +If no parameter is given the current hop penalty setting is displayed. Otherwise the parameter is used to set the +hop penalty. The penalty is can be 0-255 (255 sets originator message's TQ to zero when forwarded by this hop). +.br .IP "\fBnetwork_coding\fP|\fBnc\fP [\fB0\fP|\fB1\fP]" If no parameter is given the current network coding mode setting is displayed. Otherwise the parameter is used to enable or disable network coding.