Skip to content

Commit 8e677c9

Browse files
committed
ncm-network: Restrictions on device naming should match kernel
That is: - Maximum 15 characters (16 including null) - No whitespace - No forward-slashes - No colons (but they are allowed in filenames to label alias IPs) While we're at it, make the regexp in the module absolute, as we're actually matching filenames there. Similar validation should also happen in the schema as only throwing errors at runtime is _really_ unfriendly.
1 parent 124f057 commit 8e677c9

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

ncm-network/src/main/pan/components/network/types/network.pan

+9-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ type structure_network = {
5353
"gatewaydev" ? valid_interface
5454
@{Per interface network settings.
5555
These values are used to generate the /etc/sysconfig/network-scripts/ifcfg-<interface> files
56-
when using ncm-network.}
57-
"interfaces" : network_interface{}
56+
when using ncm-network.
57+
Interface names must be no more than 15 characters in and cannot contain whitespace, ".", "/" or ":".
58+
}
59+
"interfaces" : network_interface{} with {
60+
foreach (i; _; SELF) {
61+
match(i, '^[^\s\/.:]{1,15}$') || error('Device name "%s" is invalid', i);
62+
};
63+
true;
64+
}
5865
"nameserver" ? type_ip[]
5966
"nisdomain" ? string(1..64) with match(SELF, '^\S+$')
6067
@{Setting nozeroconf to true stops an interface from being assigned an automatic address in the 169.254.0.0 subnet.}

ncm-network/src/main/perl/network.pm

+6-25
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ use CAF::FileEditor;
9595
use CAF::FileWriter;
9696
use CAF::Path 17.7.0;
9797
use NetAddr::IP;
98+
use File::Basename;
9899

99100
use POSIX qw(WIFEXITED WEXITSTATUS);
100101
use Readonly;
@@ -153,30 +154,10 @@ Readonly my $HARDWARE_PATH => '/hardware/cards/nic';
153154

154155
# Regexp for the supported ifcfg-<device> devices.
155156
# $1 must match the device name
157+
# Note that device names cannot contain ":", but the filenames generated may use ":" to delimit named alias IPs
156158
Readonly my $DEVICE_REGEXP => qr{
157-
- # separator from e.g. ifcfg or route
158-
( # start whole match group $1
159-
( # start devicename group $2
160-
(?:
161-
eth|seth|em|
162-
bond|br|ovirtmgmt|
163-
vlan|usb|vxlan|
164-
ib|
165-
tun|
166-
p\d+p|
167-
en(?:
168-
o(?:\d+d)?| # onboard
169-
(?:p\d+)?s(?:\d+f)?(?:\d+d)? # [pci]slot[function][device]
170-
)(?:\d+np)? # [partition]
171-
)\d+| # mandatory numbering
172-
enx[[:xdigit:]]{12} # enx MAC address
173-
)
174-
(?:_(\w+))? # opional suffix group $3
175-
(?:\.\d+)? # optional VLAN
176-
(?::\w+)? # optional alias
177-
) # end whole matching group
178-
$
179-
}x;
159+
/^(?:ifcfg|route6?)-([^\s\/.]{1,15})$/
160+
};
180161

181162
Readonly our $NETWORKCFG => "/etc/sysconfig/network";
182163

@@ -228,10 +209,10 @@ sub _is_executable
228209
# undef otherwise.
229210
sub is_valid_interface
230211
{
231-
my ($self, $filename) = @_;
212+
my ($self, $filepath) = @_;
213+
my $filename = basename($filepath);
232214

233215
# Very primitive, based on regex only
234-
# Not even the full filename (eg ifcfg) or anything
235216
if ($filename =~ m/$DEVICE_REGEXP/) {
236217
my $ifupdownname = $1;
237218
my $name = $2;

0 commit comments

Comments
 (0)