mirror of
https://git.openwrt.org/openwrt/openwrt.git
synced 2026-02-21 19:52:31 +01:00
wireguard-tools: fix handling of multi-value config options
Config options like addresses and ip6prefix can be passed as either a
space-separated string or an array. Add a to_array() helper and use it
consistently for all multi-value options (addresses, ip6prefix,
allowed_ips).
Fixes: https://github.com/openwrt/openwrt/issues/22102
Fixes: 41bc454602 ("wireguard-tools: rewrite proto handler in ucode")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
6c4c988a5f
commit
8f977b4a40
1 changed files with 7 additions and 3 deletions
|
|
@ -30,6 +30,10 @@ function ensure_key_is_generated(cursor, section_name) {
|
||||||
return private_key;
|
return private_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function to_array(val) {
|
||||||
|
return type(val) == 'array' ? val : split(val, /\s+/);
|
||||||
|
}
|
||||||
|
|
||||||
function parse_address(addr) {
|
function parse_address(addr) {
|
||||||
if (index(addr, ':') >= 0) {
|
if (index(addr, ':') >= 0) {
|
||||||
if (index(addr, '/') >= 0) {
|
if (index(addr, '/') >= 0) {
|
||||||
|
|
@ -125,7 +129,7 @@ function proto_setup(proto) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer.allowed_ips) {
|
if (peer.allowed_ips) {
|
||||||
let allowed_list = type(peer.allowed_ips) == 'array' ? peer.allowed_ips : split(peer.allowed_ips, ' ');
|
let allowed_list = to_array(peer.allowed_ips);
|
||||||
wg_config += sprintf('AllowedIPs=%s\n', join(', ', allowed_list));
|
wg_config += sprintf('AllowedIPs=%s\n', join(', ', allowed_list));
|
||||||
|
|
||||||
if (peer.route_allowed_ips) {
|
if (peer.route_allowed_ips) {
|
||||||
|
|
@ -166,7 +170,7 @@ function proto_setup(proto) {
|
||||||
let ipv6_addrs = [];
|
let ipv6_addrs = [];
|
||||||
|
|
||||||
if (config.addresses) {
|
if (config.addresses) {
|
||||||
let addr_list = split(config.addresses, ' ');
|
let addr_list = to_array(config.addresses);
|
||||||
for (let address in addr_list) {
|
for (let address in addr_list) {
|
||||||
let addr_info = parse_address(address);
|
let addr_info = parse_address(address);
|
||||||
let addr = { ipaddr: addr_info.address, mask: '' + addr_info.mask };
|
let addr = { ipaddr: addr_info.address, mask: '' + addr_info.mask };
|
||||||
|
|
@ -194,7 +198,7 @@ function proto_setup(proto) {
|
||||||
link_data.routes6 = ipv6_routes;
|
link_data.routes6 = ipv6_routes;
|
||||||
|
|
||||||
if (config.ip6prefix) {
|
if (config.ip6prefix) {
|
||||||
let prefix_list = split(config.ip6prefix, ' ');
|
let prefix_list = to_array(config.ip6prefix);
|
||||||
if (length(prefix_list) > 0)
|
if (length(prefix_list) > 0)
|
||||||
link_data.ip6prefix = prefix_list;
|
link_data.ip6prefix = prefix_list;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue