Completed support for virtual interfaces with ip command

This commit is contained in:
Jamie Cameron
2014-08-03 16:43:57 -07:00
parent b178d2cb15
commit 3d2b904a72
2 changed files with 22 additions and 3 deletions

View File

@@ -73,3 +73,5 @@ Added support for the new ifconfig -a output format, as seen on Fedora 17.
A bridge that is not connected to any real interface can now be created.
---- Changes since 1.620 ----
Added support for IPv6, DHCP and new ethernet device names on FreeBSD.
---- Changes since 1.690 ----
Added support for configuring intefaces with the "ip" command, as seen on RHEL 7, CentOS 7 and other new Linux distributions.

View File

@@ -84,7 +84,6 @@ elsif (&has_command("ip")) {
$l =~ /^\d+:\s+(\S+):/ || next;
$ifc{'name'} = $1;
$ifc{'fullname'} = $1;
# XXX virtual?
if ($l =~ /\sinet\s+([0-9\.]+)\/(\d+)/) {
$ifc{'address'} = $1;
$ifc{'netmask'} = &prefix_to_mask("$2");
@@ -115,6 +114,26 @@ elsif (&has_command("ip")) {
$ifc{'edit'} = ($ifc{'name'} !~ /^ppp/);
$ifc{'index'} = scalar(@rv);
push(@rv, \%ifc);
# Add extra IPs as fake virtual interfaces
$l =~ s/\sinet\s+([0-9\.]+)\/(\d+)//;
my $i = 1;
while($l =~ s/\sinet\s+([0-9\.]+)\/(\d+)//) {
my %vifc;
$vifc{'name'} = $ifc{'name'};
$vifc{'fullname'} = $ifc{'name'}.":".$i;
$vifc{'address'} = $1;
$vifc{'netmask'} = &prefix_to_mask("$2");
$vifc{'broadcast'} = &compute_broadcast(
$vifc{'address'}, $vifc{'netmask'});
$vifc{'mtu'} = $ifc{'mtu'};
$vifc{'up'} = $ifc{'up'};
$vifc{'virtual'} = $i;
$vifc{'edit'} = ($vifc{'name'} !~ /^ppp/);
$vifc{'index'} = scalar(@rv);
push(@rv, \%vifc);
$i++;
}
}
}
else {
@@ -220,7 +239,6 @@ elsif (&has_command("ifconfig")) {
}
elsif (&has_command("ip")) {
# If the IP is changing, first remove it then re-add
# XXX what about virtual here?
my $readd = 0;
if ($old && $old->{'address'}) {
if ($old->{'address'} ne $a->{'address'} ||
@@ -252,7 +270,6 @@ elsif (&has_command("ip")) {
$cmd .= " dev $a->{'name'}";
}
}
# XXX what about virtual??
}
else {
&error("Both the ifconfig and ip commands are missing");