Commit 3f1c15e2 authored by Mike Hibler's avatar Mike Hibler

Framework for supporting 802.1q tagged VLANs as a form of multiplexed link.

Actually, most of the changes here were just to generalize the "virtual
interface" state in the DB.  Other than the client-side scripts, there
is very little specific here specific to tagged VLANs.

In fact, you cannot specify "vlan" as a type yet as we haven't done the
snmpit support for setting up the switches.

For more info see bas:~mike/flux/doc/testbed-virtinterfaces.txt, which I
will integrate into the knowledge base and the Emulab doc at some point.
parent 702ca300
......@@ -765,7 +765,7 @@ sub TBDB_PHYSICAL_NODE_TABLES() {
'tunnels' => [ 'node_id' ],
'uidnodelastlogin' => [ 'node_id' ],
'v2pmap' => [ 'node_id' ],
'veth_interfaces' => [ 'node_id' ],
'vinterfaces' => [ 'node_id' ],
'widearea_accounts' => [ 'node_id' ],
'widearea_delays' => [ 'node_id1', 'node_id2' ],
'widearea_nodeinfo' => [ 'node_id' ],
......
......@@ -353,8 +353,8 @@ foreach my $n (@freed_nodes) {
# Reset its port allocation stuff.
DBQueryWarn("delete from nodeipportnum where node_id='$n'") || $error++;
# Clean the veth_interfaces table for this node.
DBQueryWarn("delete from veth_interfaces where node_id='$n'") || $error++;
# Clean the vinterfaces table for this node.
DBQueryWarn("delete from vinterfaces where node_id='$n'") || $error++;
# Clean the interface_settings table for this node.
DBQueryWarn("delete from interface_settings where node_id='$n'") || $error++;
......
......@@ -162,7 +162,7 @@ my %experiment_fields = ("multiplex_factor" => 1,
"cpu_usage" => 1,
"mem_usage" => 1,
"allowfixnode" => 1,
"veth_encapsulate" => 1,
"encap_style" => 1,
"jail_osname" => 1,
"delay_osname" => 1,
"sync_server" => 1,
......
......@@ -776,6 +776,7 @@ CREATE TABLE experiments (
idx int(10) unsigned NOT NULL auto_increment,
sim_reswap_count smallint(5) unsigned NOT NULL default '0',
veth_encapsulate tinyint(4) NOT NULL default '1',
encap_style enum('alias','veth','veth-ne','vlan','default') NOT NULL default 'default',
allowfixnode tinyint(4) NOT NULL default '1',
jail_osname varchar(20) default NULL,
delay_osname varchar(20) default NULL,
......@@ -1100,7 +1101,6 @@ CREATE TABLE interfaces (
port tinyint(3) unsigned NOT NULL default '0',
mac varchar(12) NOT NULL default '000000000000',
IP varchar(15) default NULL,
IPalias varchar(15) default NULL,
IPaliases text,
mask varchar(15) default NULL,
interface_type varchar(30) default NULL,
......@@ -2564,6 +2564,25 @@ CREATE TABLE veth_interfaces (
KEY IP (IP)
) TYPE=MyISAM;
--
-- Table structure for table `vinterfaces`
--
CREATE TABLE vinterfaces (
node_id varchar(32) NOT NULL default '',
unit int(10) unsigned NOT NULL auto_increment,
mac varchar(12) NOT NULL default '000000000000',
IP varchar(15) default NULL,
mask varchar(15) default NULL,
type enum('alias','veth','veth-ne','vlan') NOT NULL default 'veth',
iface varchar(10) default NULL,
rtabid smallint(5) unsigned NOT NULL default '0',
vnode_id varchar(32) default NULL,
PRIMARY KEY (node_id,unit),
KEY bynode (node_id,iface),
KEY type (type)
) TYPE=MyISAM;
--
-- Table structure for table `virt_agents`
--
......@@ -2672,6 +2691,7 @@ CREATE TABLE virt_lans (
nobwshaping tinyint(4) default '0',
mustdelay tinyint(1) default '0',
usevethiface tinyint(4) default '0',
encap_style enum('alias','veth','veth-ne','vlan','default') NOT NULL default 'default',
trivial_ok tinyint(4) default '1',
protocol varchar(30) NOT NULL default 'ethernet',
is_accesspoint tinyint(4) default '0',
......@@ -2893,8 +2913,9 @@ CREATE TABLE vlans (
virtual varchar(64) default NULL,
members text NOT NULL,
id int(11) NOT NULL auto_increment,
tag smallint(5) NOT NULL default '0',
PRIMARY KEY (id),
KEY pid (pid,eid)
KEY pid (pid,eid,virtual)
) TYPE=MyISAM;
--
......
......@@ -612,6 +612,7 @@ REPLACE INTO table_regex VALUES ('virt_lans','emulated','int','redirect','defaul
REPLACE INTO table_regex VALUES ('virt_lans','uselinkdelay','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_lans','nobwshaping','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_lans','usevethiface','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_lans','encap_style','text','redirect','experiments:encap_style',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_lans','trivial_ok','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_lans','traced','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('virt_lans','trace_type','text','regex','^(header|packet|monitor)$',0,0,NULL);
......@@ -682,6 +683,7 @@ REPLACE INTO table_regex VALUES ('projects','num_members','int','redirect','defa
REPLACE INTO table_regex VALUES ('projects','num_pcs','int','redirect','default:int',0,2048,NULL);
REPLACE INTO table_regex VALUES ('projects','num_pcplab','int','redirect','default:int',0,2048,NULL);
REPLACE INTO table_regex VALUES ('projects','num_ron','int','redirect','default:int',0,1024,NULL);
REPLACE INTO table_regex VALUES ('experiments','encap_style','text','regex','^(alias|veth|veth-ne|vlan|default)$',0,0,NULL);
REPLACE INTO table_regex VALUES ('experiments','veth_encapsulate','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('experiments','allowfixnode','int','redirect','default:boolean',0,0,NULL);
REPLACE INTO table_regex VALUES ('experiments','jail_osname','text','redirect','os_info:osname',0,0,NULL);
......
......@@ -3434,3 +3434,49 @@ last_net_act,last_cpu_act,last_ext_act);
alter table widearea_nodeinfo add latitude float(3,5);
alter table widearea_nodeinfo add longitude float(3,5);
4.71: Support for 802.1q tagged VLAN based virtual interfaces.
First, generalize the encapsulation field. For compatibility,
we create a new field, we'll delete the old veth_encapsulate at
some future time. We also add a VLAN number field to the vlans
table, create
alter table experiments add encap_style \
enum('alias','veth','veth-ne','vlan','default') \
NOT NULL default 'default' after veth_encapsulate;
insert into table_regex values \
('experiments','encap_style','text','regex','^(alias|veth|veth-ne|vlan|default)$',0,0,NULL);
update experiments set encap_style='veth-ne' where veth_encapsulate=0;
alter table virt_lans add encap_style \
enum('alias','veth','veth-ne','vlan','default') \
NOT NULL default 'default' after usevethiface;
insert into table_regex values \
('virt_lans','encap_style','text','redirect','experiments:encap_style',0,0,NULL);
update virt_lans set encap_style='veth' where usevethiface=1;
alter table vlans add tag smallint(5) NOT NULL default '0' \
after id;
alter table vlans drop index pid;
alter table vlans add index pid (pid,eid,virtual);
alter table interfaces drop column IPalias;
CREATE TABLE vinterfaces (
node_id varchar(32) NOT NULL default '',
unit int(10) unsigned NOT NULL auto_increment,
mac varchar(12) NOT NULL default '000000000000',
IP varchar(15) default NULL,
mask varchar(15) default NULL,
type enum('alias','veth','veth-ne','vlan') NOT NULL default 'veth',
iface varchar(10) default NULL,
rtabid smallint(5) unsigned NOT NULL default '0',
vnode_id varchar(32) default NULL,
PRIMARY KEY (node_id, unit),
KEY bynode (node_id, iface),
KEY type (type)
) TYPE=MyISAM;
To populate the vinterfaces table run:
sudo ./initvinterfaces.pl
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use lib "/usr/testbed/lib";
use libdb;
use libtestbed;
#
# Untaint the path
#
$ENV{'PATH'} = '/bin:/usr/bin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Fill the new vinterfaces table using info from veth_interfaces and
# IPaliases from the interfaces table.
#
# First, veth_interfaces...
DBQueryFatal("insert into vinterfaces select ".
"node_id,veth_id,mac,IP,mask,'veth',iface,rtabid,vnode_id ".
"from veth_interfaces");
# Now, IPalias info from the interfaces table...
my $query_result =
DBQueryFatal("select node_id,mac,IP,IPaliases,mask,iface from interfaces ".
"where IPaliases is not NULL and IPaliases!=''");
while (my ($node,$mac,$IP,$aliases,$mask,$iface) = $query_result->fetchrow_array()) {
my @alist = split(',', $aliases);
foreach my $alias (@alist) {
DBQueryFatal("insert into vinterfaces (node_id,IP,mask,type,iface) ".
"values ('$node','$alias','$mask','alias','$iface')");
}
}
#
# Everything is peachy, remove the old info.
# We are leaving the veth_interfaces table around for now.
#
DBQueryFatal("update interfaces set IPaliases=NULL ".
"where IPaliases is not NULL");
DBQueryFatal("delete from veth_interfaces");
exit(0);
This diff is collapsed.
......@@ -411,10 +411,10 @@ if ($query_result->numrows) {
#
# The MAC address is either in interfaces (for physical interfaces)
# or veth_interfaces (for virtual interfaces).
# or vinterfaces (for virtual interfaces).
#
# The multiplexing style is either "veth" if there is a row in the
# veth_interfaces table or "none" otherwise. This is reflected in
# vinterfaces table or "none" otherwise. This is reflected in
# the following query as: style is "veth" if vmac!=NULL.
#
# Linkdelays are in use if the link has a row in the linkdelays table.
......@@ -422,27 +422,38 @@ if ($query_result->numrows) {
# We could look in the delays table to further distinguish unshaped
# links, but at the moment, we don't need that info.
#
# Argh...further complicated by the reserved table node_id being either
# a pnode or a vnode name while vinterfaces identifies a pnode with
# node_id if vnode_id==NULL and a vnode with vnode_id if vnode_id!=NULL.
#
$query_result =
DBQueryFatal("select v.member,v.vname,i.mac,ve.mac,l.iface".
DBQueryFatal("select v.member,v.vname,i.mac,vi.mac,vi.type,l.iface".
" from reserved as r join virt_lans as v".
" left join interfaces as i".
" on v.ip=i.IP and r.node_id=i.node_id".
" left join linkdelays as l".
" on r.pid=l.pid and r.eid=l.eid and".
" v.vname=l.vlan and v.vnode=l.vnode and v.ip=l.ip".
" left join veth_interfaces as ve".
" on v.ip=ve.IP and r.node_id=ve.vnode_id".
" left join vinterfaces as vi".
" on v.ip=vi.IP and".
" (vi.vnode_id is NULL and r.node_id=vi.node_id".
" or".
" vi.vnode_id is not NULL and r.node_id=vi.vnode_id)".
" where".
" r.pid=v.pid and r.eid=v.eid and r.vname=v.vnode and".
" r.pid='$pid' and r.eid='$eid'");
if ($query_result->numrows) {
while (my ($memb,$vlan,$imac,$vmac,$iface) =
while (my ($memb,$vlan,$imac,$vmac,$vtype,$iface) =
$query_result->fetchrow_array) {
if (exists($virt_lans{$vlan}->{"MEMBERS"}->{$memb})) {
my $member = $virt_lans{$vlan}->{"MEMBERS"}->{$memb};
if (defined($vmac)) {
$member->{"mac"} = $vmac;
$member->{"encap"} = "veth";
if ($vtype eq "veth") {
$member->{"encap"} = "veth";
} else {
$member->{"encap"} = "none";
}
} else {
$member->{"mac"} = $imac;
$member->{"encap"} = "none";
......
......@@ -207,8 +207,8 @@ LanLink instproc init {s nodes bw d type} {
# assignment.
$self set mustdelay 0
# Allow user to turn on veth devices on emulated links.
$self set useveth 0
# Allow user to specify encapsulation on emulated links.
$self set encap "default"
# XXX Allow user to set the accesspoint.
$self set accesspoint {}
......@@ -636,7 +636,7 @@ Link instproc updatedb {DB} {
$self instvar uselinkdelay
$self instvar emulated
$self instvar nobwshaping
$self instvar useveth
$self instvar encap
$self instvar sim
$self instvar netmask
$self instvar protocol
......@@ -702,7 +702,7 @@ Link instproc updatedb {DB} {
set nodeportraw [join $nodeport ":"]
set fields [list "vname" "member" "mask" "delay" "rdelay" "bandwidth" "rbandwidth" "lossrate" "rlossrate" "cost" "widearea" "emulated" "uselinkdelay" "nobwshaping" "usevethiface" "q_limit" "q_maxthresh" "q_minthresh" "q_weight" "q_linterm" "q_qinbytes" "q_bytes" "q_meanpsize" "q_wait" "q_setbit" "q_droptail" "q_red" "q_gentle" "trivial_ok" "vnode" "vport" "ip" "mustdelay"]
set fields [list "vname" "member" "mask" "delay" "rdelay" "bandwidth" "rbandwidth" "lossrate" "rlossrate" "cost" "widearea" "emulated" "uselinkdelay" "nobwshaping" "encap_style" "q_limit" "q_maxthresh" "q_minthresh" "q_weight" "q_linterm" "q_qinbytes" "q_bytes" "q_meanpsize" "q_wait" "q_setbit" "q_droptail" "q_red" "q_gentle" "trivial_ok" "vnode" "vport" "ip" "mustdelay"]
# Treat estimated bandwidths differently - leave them out of the lists
# unless the user gave a value - this way, they get the defaults if not
......@@ -724,7 +724,7 @@ Link instproc updatedb {DB} {
lappend fields "trace_endnode"
}
set values [list $self $nodeportraw $netmask $delay($nodeport) $rdelay($nodeport) $bandwidth($nodeport) $rbandwidth($nodeport) $loss($nodeport) $rloss($nodeport) $cost($nodeport) $widearea $emulated $uselinkdelay $nobwshaping $useveth $limit_ $maxthresh_ $thresh_ $q_weight_ $linterm_ ${queue-in-bytes_} $bytes_ $mean_pktsize_ $wait_ $setbit_ $droptail_ $red_ $gentle_ $trivial_ok $node $port $ip $mustdelay]
set values [list $self $nodeportraw $netmask $delay($nodeport) $rdelay($nodeport) $bandwidth($nodeport) $rbandwidth($nodeport) $loss($nodeport) $rloss($nodeport) $cost($nodeport) $widearea $emulated $uselinkdelay $nobwshaping $encap $limit_ $maxthresh_ $thresh_ $q_weight_ $linterm_ ${queue-in-bytes_} $bytes_ $mean_pktsize_ $wait_ $setbit_ $droptail_ $red_ $gentle_ $trivial_ok $node $port $ip $mustdelay]
if { [info exists ebandwidth($nodeport)] } {
lappend values $ebandwidth($nodeport)
......@@ -768,7 +768,7 @@ Lan instproc updatedb {DB} {
$self instvar uselinkdelay
$self instvar emulated
$self instvar nobwshaping
$self instvar useveth
$self instvar encap
$self instvar sim
$self instvar netmask
$self instvar protocol
......@@ -849,7 +849,7 @@ Lan instproc updatedb {DB} {
set is_accesspoint 1
}
set fields [list "vname" "member" "mask" "delay" "rdelay" "bandwidth" "rbandwidth" "lossrate" "rlossrate" "cost" "widearea" "emulated" "uselinkdelay" "nobwshaping" "usevethiface" "q_limit" "q_maxthresh" "q_minthresh" "q_weight" "q_linterm" "q_qinbytes" "q_bytes" "q_meanpsize" "q_wait" "q_setbit" "q_droptail" "q_red" "q_gentle" "trivial_ok" "protocol" "is_accesspoint" "vnode" "vport" "ip" "mustdelay"]
set fields [list "vname" "member" "mask" "delay" "rdelay" "bandwidth" "rbandwidth" "lossrate" "rlossrate" "cost" "widearea" "emulated" "uselinkdelay" "nobwshaping" "encap_style" "q_limit" "q_maxthresh" "q_minthresh" "q_weight" "q_linterm" "q_qinbytes" "q_bytes" "q_meanpsize" "q_wait" "q_setbit" "q_droptail" "q_red" "q_gentle" "trivial_ok" "protocol" "is_accesspoint" "vnode" "vport" "ip" "mustdelay"]
# Treat estimated bandwidths differently - leave them out of the lists
# unless the user gave a value - this way, they get the defaults if not
......@@ -871,7 +871,7 @@ Lan instproc updatedb {DB} {
lappend fields "trace_endnode"
}
set values [list $self $nodeportraw $netmask $delay($nodeport) $rdelay($nodeport) $bandwidth($nodeport) $rbandwidth($nodeport) $loss($nodeport) $rloss($nodeport) $cost($nodeport) $widearea $emulated $uselinkdelay $nobwshaping $useveth $limit_ $maxthresh_ $thresh_ $q_weight_ $linterm_ ${queue-in-bytes_} $bytes_ $mean_pktsize_ $wait_ $setbit_ $droptail_ $red_ $gentle_ $trivial_ok $protocol $is_accesspoint $node $port $ip $mustdelay]
set values [list $self $nodeportraw $netmask $delay($nodeport) $rdelay($nodeport) $bandwidth($nodeport) $rbandwidth($nodeport) $loss($nodeport) $rloss($nodeport) $cost($nodeport) $widearea $emulated $uselinkdelay $nobwshaping $encap $limit_ $maxthresh_ $thresh_ $q_weight_ $linterm_ ${queue-in-bytes_} $bytes_ $mean_pktsize_ $wait_ $setbit_ $droptail_ $red_ $gentle_ $trivial_ok $protocol $is_accesspoint $node $port $ip $mustdelay]
if { [info exists ebandwidth($nodeport)] } {
lappend values $ebandwidth($nodeport)
......
......@@ -49,6 +49,7 @@ proc tb-set-multiplexed {link onoff} {}
proc tb-set-endnodeshaping {link onoff} {}
proc tb-set-noshaping {link onoff} {}
proc tb-set-useveth {link onoff} {}
proc tb-set-link-encap {link style} {}
proc tb-set-allowcolocate {lanlink onoff} {}
proc tb-set-colocate-factor {factor} {}
proc tb-set-sync-server {node} {}
......@@ -57,6 +58,7 @@ proc tb-set-cpu-usage {usage} {}
proc tb-bind-parent {sub phys} {}
proc tb-fix-current-resources {onoff} {}
proc tb-set-encapsulate {onoff} {}
proc tb-set-vlink-emulation {style} {}
proc tb-set-jail-os {os} {}
proc tb-set-delay-os {os} {}
proc tb-set-delay-capacity {cap} {}
......
......@@ -239,8 +239,10 @@ namespace eval GLOBALS {
# Flag to disable doing a fix-node
variable fix_current_resources 1
# Control veth encapsulation
variable veth_encapsulate 1
# Control virtual link encapsulation
# XXX "default" is for backward compat so we can distinguish
# specified vs. unspecified in assign_wrapper
variable vlink_encapsulate "default"
# Allow override of jail and delay osids.
variable jail_osname {}
......
......@@ -380,7 +380,7 @@ Simulator instproc run {} {
var_import ::GLOBALS::cpu_usage
var_import ::GLOBALS::mem_usage
var_import ::GLOBALS::fix_current_resources
var_import ::GLOBALS::veth_encapsulate
var_import ::GLOBALS::vlink_encapsulate
var_import ::GLOBALS::jail_osname
var_import ::GLOBALS::delay_osname
var_import ::GLOBALS::delay_capacity
......@@ -572,8 +572,8 @@ Simulator instproc run {} {
$tg updatedb "sql"
}
set fields [list "mem_usage" "cpu_usage" "forcelinkdelays" "uselinkdelays" "usewatunnels" "uselatestwadata" "wa_delay_solverweight" "wa_bw_solverweight" "wa_plr_solverweight" "veth_encapsulate" "allowfixnode"]
set values [list $mem_usage $cpu_usage $forcelinkdelays $uselinkdelays $usewatunnels $uselatestwadata $wa_delay_solverweight $wa_bw_solverweight $wa_plr_solverweight $veth_encapsulate $fix_current_resources]
set fields [list "mem_usage" "cpu_usage" "forcelinkdelays" "uselinkdelays" "usewatunnels" "uselatestwadata" "wa_delay_solverweight" "wa_bw_solverweight" "wa_plr_solverweight" "encap_style" "allowfixnode"]
set values [list $mem_usage $cpu_usage $forcelinkdelays $uselinkdelays $usewatunnels $uselatestwadata $wa_delay_solverweight $wa_bw_solverweight $wa_plr_solverweight $vlink_encapsulate $fix_current_resources]
if { $multiplex_factor != {} } {
lappend fields "multiplex_factor"
......
......@@ -898,15 +898,55 @@ proc tb-set-noshaping {lanlink onoff} {
#
# For emulated links, allow veth device to be used. Not a user option.
# XXX backward compat, use tb-set-link-encap now.
#
proc tb-set-useveth {lanlink onoff} {
if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan"} {
perror "\[tb-set-useveth] $link is not a link or a lan."
return
}
$lanlink set useveth $onoff
if {$onoff == 0} {
$lanlink set encap "default"
} else {
$lanlink set encap "veth"
}
}
#
# For emulated links, allow specifying encapsulation style.
# Generalizes tb-set-useveth.
#
proc tb-set-link-encap {lanlink style} {
if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan"} {
perror "\[tb-set-link-encap] $link is not a link or a lan."
return
}
switch -- $style {
"alias" {
set style "alias"
}
"veth" {
set style "veth"
}
"veth-ne" {
set style "veth-ne"
}
"vlan" {
perror "\[tb-set-link-encap] 'vlan' encap not yet supported"
return
# set style "vlan"
}
default {
perror "\[tb-set-link-encap] one of: 'alias', 'veth', 'veth-ne', 'vlan'"
return
}
}
$lanlink set encap $style
}
#
# Control linkdelays for lans and links
#
......@@ -1041,13 +1081,44 @@ proc tb-fix-current-resources {onoff} {
# Control veth encapsulation.
#
proc tb-set-encapsulate {onoff} {
var_import ::GLOBALS::veth_encapsulate
var_import ::GLOBALS::vlink_encapsulate
if {$onoff < 0 || $onoff > 1} {
perror "\[tb-set-encapsulate] must be 0 or 1."
return
if {$onoff == 0} {
set vlink_encapsulate "veth-ne"
} elseif {$onoff == 1} {
set vlink_encapsulate "default"
} else {
perror "\[tb-set-encapsulate] $onoff must be 0/1"
}
}
#
# Control virtual link emulation style.
#
proc tb-set-vlink-emulation {style} {
var_import ::GLOBALS::vlink_encapsulate
switch -- $style {
"alias" {
set style "alias"
}
"veth" {
set style "veth"
}
"veth-ne" {
set style "veth-ne"
}
"vlan" {
perror "\[tb-set-encapsulate] 'vlan' encap not yet supported"
return
# set style "vlan"
}
default {
perror "\[tb-set-encapsulate] one of: 'alias', 'veth', 'veth-ne', 'vlan'"
return
}
}
set veth_encapsulate $onoff
set vlink_encapsulate $style
}
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004, 2005 University of Utah and the Flux Group.
# Copyright (c) 2004, 2005, 2006 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
......@@ -121,8 +121,9 @@ sub doboot()
return 0
if (! @ifacelist);
my %oscookie = ();
foreach my $ifconfig (@ifacelist) {
if (! $ifconfig->{ISVETH}) {
if (! $ifconfig->{ISVIRT}) {
my $inet = $ifconfig->{IPADDR};
my $type = $ifconfig->{TYPE};
my $mask = $ifconfig->{IPMASK};
......@@ -162,22 +163,18 @@ sub doboot()
my ($upline, $downline) =
os_ifconfig_line($iface, $inet, $mask,
$speed, $duplex, $aliases,
$type, $settings, $ifrtabid);
$type, $settings, $ifrtabid, \%oscookie);
$upcmds .= "$upline\n "
if (defined($upline));
$upcmds .= TMROUTECONFIG . " $inet up\n "
if ($inet ne "");
if (defined($upline) && $upline) {
$upcmds .= "$upline\n ";
$upcmds .= TMROUTECONFIG . " $inet up\n "
if ($inet ne "");
}
$downcmds .= TMROUTECONFIG . " $inet down\n "
if ($inet ne "");
$downcmds .= "$downline\n "
if (defined($downline));
# There could be routes for each alias.
foreach my $alias (split(',', $aliases)) {
$upcmds .= TMROUTECONFIG . " $alias up\n ";
$downcmds .= TMROUTECONFIG . " $alias down\n ";
if (defined($downline)) {
$downcmds .= TMROUTECONFIG . " $inet down\n "
if ($inet ne "");
$downcmds .= "$downline\n ";
}
# Trivially parsable map for users, which associate an IP
......@@ -185,6 +182,7 @@ sub doboot()
push(@ifacemap, "$iface $inet $mac");
}
else {
my $itype = $ifconfig->{ITYPE};
my $inet = $ifconfig->{IPADDR};
my $mask = $ifconfig->{IPMASK};
my $id = $ifconfig->{ID};
......@@ -218,14 +216,16 @@ sub doboot()
my ($upline, $downline) =
os_ifconfig_veth($iface, $inet, $mask, $id, $vmac,
$ifrtabid, $encap, $vtag);
$ifrtabid, $encap, $vtag, $itype, \%oscookie);
$upcmds .= "$upline\n ";
$upcmds .= TMROUTECONFIG . " $inet up\n ";
$downcmds .= TMROUTECONFIG . " $inet down\n ";
$downcmds .= "$downline\n "
if (defined($downline));
if (defined($upline) && $upline) {
$upcmds .= "$upline\n ";
$upcmds .= TMROUTECONFIG . " $inet up\n ";
}
if (defined($downline)) {
$downcmds .= TMROUTECONFIG . " $inet down\n ";
$downcmds .= "$downline\n ";
}
}
}
......
......@@ -47,7 +47,7 @@ use libtmcc;
#
# BE SURE TO BUMP THIS AS INCOMPATIBILE CHANGES TO TMCD ARE MADE!
#
sub TMCD_VERSION() { 26; };
sub TMCD_VERSION() { 27; };
libtmcc::configtmcc("version", TMCD_VERSION());
# Control tmcc timeout.
......@@ -497,7 +497,7 @@ sub getifconfig($)
}
my $ethpat = q(INTERFACE IFACETYPE=(\w*) INET=([0-9.]*) MASK=([0-9.]*) );
$ethpat .= q(MAC=(\w*) SPEED=(\w*) DUPLEX=(\w*) IPALIASES="(.*)" );
$ethpat .= q(MAC=(\w*) SPEED=(\w*) DUPLEX=(\w*) );
$ethpat .= q(IFACE=(\w*) RTABID=(\d*) LAN=([-\w\(\)]*));
my $vethpat = q(INTERFACE IFACETYPE=(\w*) INET=([0-9.]*) MASK=([0-9.]*) );
......@@ -532,10 +532,9 @@ sub getifconfig($)
my $mac = $4;
my $speed = $5;
my $duplex = $6;
my $aliases = $7;
my $iface = $8;
my $rtabid = $9;
my $lan = $10;
my $iface = $7;
my $rtabid = $8;
my $lan = $9;
#
# XXX GNU Radio hack
......@@ -559,14 +558,14 @@ sub getifconfig($)
next;
}
$ifconfig->{"ISVETH"} = 0;
$ifconfig->{"ISVIRT"} = 0;
$ifconfig->{"TYPE"} = $ifacetype;
$ifconfig->{"IPADDR"} = $inet;
$ifconfig->{"IPMASK"} = $mask;
$ifconfig->{"MAC"} = $mac;
$ifconfig->{"SPEED"} = $speed;
$ifconfig->{"DUPLEX"} = $duplex;
$ifconfig->{"ALIASES"} = $aliases;
$ifconfig->{"ALIASES"} = ""; # gone as of version 27
$ifconfig->{"IFACE"} = $iface;
$ifconfig->{"RTABID"} = $rtabid;
$ifconfig->{"LAN"} = $lan;
......@@ -575,6 +574,7 @@ sub getifconfig($)
$ifacehash{$mac} = $ifconfig;
}
elsif ($str =~ /$vethpat/) {
my $ifacetype= $1;
my $inet = $2;
my $mask = $3;
my $id = $4;
......@@ -613,7 +613,8 @@ sub getifconfig($)
}
}
$ifconfig->{"ISVETH"} = 1;
$ifconfig->{"ISVIRT"} = 1;
$ifconfig->{"ITYPE"} = $ifacetype;
$ifconfig->{"IPADDR"} = $inet;
$ifconfig->{"IPMASK"} = $mask;
$ifconfig->{"ID"} = $id;
......@@ -752,10 +753,17 @@ sub genhostsfile($@)
#
# Convert from MAC to iface name (eth0/fxp0/etc) using little helper program.
#
# If the optional second arg is set, it is an IP address with which we
# validate the interface. If the queries by MAC and IP return different
# interfaces, we believe the latter. We do this because some virtual
# interfaces (like vlans and IP aliases on Linux) use the MAC address of
# the underlying physical device. Hence, look up by MAC on those will
# return the physical interface.
#
sub findiface($)
sub findiface($;$)
{
my($mac) = @_;
my($mac,$ip) = @_;
my($iface);
open(FIF, FINDIF . " $mac |")
......@@ -768,6 +776,20 @@ sub findiface($)
}
$iface =~ s/\n//g;
if (defined($ip)) {
open(FIF, FINDIF . " -i $ip |")
or die "Cannot start " . FINDIF . ": $!";
my $ipiface = <FIF>;
if (!close(FIF)) {
return 0;
}
$ipiface =~ s/\n//g;
if ($ipiface ne "" && $ipiface ne $iface) {
$iface = $ipiface;
}
}
return $iface;
}
......
......@@ -26,4 +26,4 @@
* NB: See ron/libsetup.pm. That is version 4! I'll merge that in.
*/
#define DEFAULT_VERSION 2
#define CURRENT_VERSION 26
#define CURRENT_VERSION 27
......@@ -74,11 +74,12 @@ my $CHPASS = "/usr/bin/chpass -p";
my $MKDB = "/usr/sbin/pwd_mkdb -p";
my $IFCONFIGBIN = "/sbin/ifconfig";
my $IFCONFIG = "$IFCONFIGBIN %s inet %s netmask %s %s %s";
my $IFALIAS = "$IFCONFIGBIN %s alias %s netmask 0xffffff00";
my $IFALIAS = "$IFCONFIGBIN %s alias %s netmask %s";
my $IFC_1000MBS = "media 1000baseTX";
my $IFC_100MBS = "media 100baseTX";
my $IFC_10MBS = "media 10baseT/UTP";
my $IFC_FDUPLEX = "mediaopt full-duplex";
my $IFC_HDUPLEX = "mediaopt half-duplex";
my $MKDIR = "/bin/mkdir";
my $GATED = "/usr/local/sbin/gated";
my $ROUTE = "/sbin/route";
......@@ -113,10 +114,10 @@ sub os_account_cleanup()
# Generate and return an ifconfig line that is approriate for putting
# into a shell script (invoked at bootup).
#
sub os_ifconfig_line($$$$$$$;$$)
sub os_ifconfig_line($$$$$$$;$$%)
{
my ($iface, $inet, $mask, $speed, $duplex, $aliases,
$iface_type, $settings, $rtabid) = @_;
my ($iface, $inet, $mask, $speed, $duplex, $aliases, $iface_type,
$settings, $rtabid, $cookie) = @_;
my $media = "";
my $mediaopt = "";
my ($uplines, $downlines);
......@@ -132,7 +133,7 @@ sub os_ifconfig_line($$$$$$$;$$)
$speed = $1 / 1000;
}
else {
warn("*** Bad speed units in ifconfig!\n");
warn("*** Bad speed units $2 in ifconfig, default to 100Mbps\n");
$speed = 100;
}
if ($speed == 1000) {
......@@ -145,7 +146,8 @@ sub os_ifconfig_line($$$$$$$;$$)
$media = $IFC_10MBS;
}
else {
warn("*** Bad Speed in ifconfig!\n");
warn("*** Bad Speed $speed in ifconfig, default to 100Mbps\n");
$speed = 100;
$media = $IFC_100MBS;
}
}
......@@ -153,6 +155,14 @@ sub os_ifconfig_line($$$$$$$;$$)
if ($duplex eq "full") {
$mediaopt = $IFC_FDUPLEX;
}
elsif ($duplex eq "half") {