util-lib: add new ifname_valid() call that validates interface names
Make use of this in nspawn at a couple of places. A later commit should port more code over to this, including networkd.
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
#include "netlink-util.h"
|
||||
#include "nspawn-network.h"
|
||||
#include "siphash24.h"
|
||||
#include "socket-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "util.h"
|
||||
@@ -515,13 +517,13 @@ int veth_extra_parse(char ***l, const char *p) {
|
||||
r = extract_first_word(&p, &a, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0 || isempty(a))
|
||||
if (r == 0 || !ifname_valid(a))
|
||||
return -EINVAL;
|
||||
|
||||
r = extract_first_word(&p, &b, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0 || isempty(b)) {
|
||||
if (r == 0 || !ifname_valid(b)) {
|
||||
free(b);
|
||||
b = strdup(a);
|
||||
if (!b)
|
||||
|
||||
@@ -467,6 +467,12 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_NETWORK_BRIDGE:
|
||||
|
||||
if (!ifname_valid(optarg)) {
|
||||
log_error("Bridge interface name not valid: %s", optarg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = free_and_strdup(&arg_network_bridge, optarg);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
@@ -489,6 +495,12 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_NETWORK_INTERFACE:
|
||||
|
||||
if (!ifname_valid(optarg)) {
|
||||
log_error("Network interface name not valid: %s", optarg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (strv_extend(&arg_network_interfaces, optarg) < 0)
|
||||
return log_oom();
|
||||
|
||||
@@ -497,6 +509,12 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_NETWORK_MACVLAN:
|
||||
|
||||
if (!ifname_valid(optarg)) {
|
||||
log_error("MACVLAN network interface name not valid: %s", optarg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (strv_extend(&arg_network_macvlan, optarg) < 0)
|
||||
return log_oom();
|
||||
|
||||
@@ -505,6 +523,12 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_NETWORK_IPVLAN:
|
||||
|
||||
if (!ifname_valid(optarg)) {
|
||||
log_error("IPVLAN network interface name not valid: %s", optarg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (strv_extend(&arg_network_ipvlan, optarg) < 0)
|
||||
return log_oom();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user