We allow for multiple -n/--netmask options, and update the handling so
that each given prefix length is applied to the most recently added
address instead of always to addrs[0].
This allows per-address prefix configuration, such as:
-a 10.0.0.1 -n 24 -a 10.0.0.2 -n 16
If no address has been added yet, -n still applies to addrs[0] for
backwards compatibility.
Signed-off-by: Jon Maloy
---
conf.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/conf.c b/conf.c
index e9f217b..0a4a28a 100644
--- a/conf.c
+++ b/conf.c
@@ -1528,6 +1528,7 @@ void conf(struct ctx *c, int argc, char **argv)
size_t logsize = 0;
char *runas = NULL;
long fd_tap_opt;
+ int prefix, idx;
int name, ret;
uid_t uid;
gid_t gid;
@@ -1872,10 +1873,14 @@ void conf(struct ctx *c, int argc, char **argv)
die("Invalid address: %s", optarg);
break;
case 'n':
- c->ip4.addrs[0].prefix_len = conf_ip4_prefix(optarg);
- if (c->ip4.addrs[0].prefix_len < 0)
+ prefix = conf_ip4_prefix(optarg);
+
+ if (prefix < 0)
die("Invalid netmask: %s", optarg);
+ /* Apply to most recent address, or addrs[0] if none yet */
+ idx = c->ip4.addr_count ? c->ip4.addr_count - 1 : 0;
+ c->ip4.addrs[idx].prefix_len = prefix;
break;
case 'M':
parse_mac(c->our_tap_mac, optarg);
--
2.51.1