Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
7ee63200
Commit
7ee63200
authored
Jul 17, 2012
by
Leigh B Stoller
Browse files
Add checks around calls to GenFakeMac() to ensure uniqueness.
parent
bb66f52e
Changes
2
Hide whitespace changes
Inline
Side-by-side
db/Interface.pm.in
View file @
7ee63200
...
...
@@ -15,6 +15,7 @@ use vars qw(@ISA @EXPORT);
use
libdb
;
use
libtestbed
;
use
emutil
qw
(
GenFakeMac
);
use
English
;
use
Data
::
Dumper
;
use
overload
(
'""'
=>
'Stringify'
);
...
...
@@ -373,6 +374,8 @@ sub Create($$$)
#
DBQueryWarn
(
"lock tables interfaces write, "
.
" interface_state write, "
.
" vinterfaces read, "
.
" node_history read, "
.
" wires write"
)
or
return
undef
;
...
...
@@ -388,6 +391,32 @@ sub Create($$$)
DBQueryWarn
(
"unlock tables"
);
return
Interface
->
Lookup
($
node_id
,
$
card
,
$
port
);
}
#
#
Generate
a
fake
mac
if
requested
.
#
if
($
MAC
eq
"genfake"
)
{
while
(
1
)
{
$
MAC
=
GenFakeMac
();
#
Check
to
make
sure
unique
.
If
not
,
try
again
.
$
query_result
=
DBQueryWarn
(
"(select mac from interfaces "
.
" where mac='$MAC') "
.
"union "
.
"(select mac from vinterfaces "
.
" where mac='$MAC') "
.
"union "
.
"(select cnet_mac as mac from node_history "
.
" where cnet_mac='$MAC')"
);
if
(
!$query_result) {
DBQueryWarn
(
"unlock tables"
);
return
undef
;
}
last
if
(
!$query_result->numrows);
}
}
if
(
!DBQueryWarn("insert into interfaces set ".
" node_id='$node_id', logical='$logical', "
.
...
...
@@ -759,6 +788,7 @@ sub TypeCapability($$$)
package Interface::VInterface;
use libdb;
use libtestbed;
use emutil qw(GenFakeMac);
use English;
use overload ('
""
' => '
Stringify
');
...
...
@@ -846,14 +876,48 @@ sub Create($$$)
delete($argref->{'
unit
'})
if (exists($argref->{'
unit
'}));
DBQueryWarn("lock tables interfaces read, ".
" vinterfaces write, ".
" node_history read")
or return undef;
#
# Generate a fake mac if requested.
#
if (exists($argref->{'
mac
'}) && $argref->{'
mac
'} eq "genfake") {
while (1) {
my $mac = GenFakeMac();
# Check to make sure unique. If not, try again.
my $query_result =
DBQueryWarn("(select mac from interfaces ".
" where mac='
$
mac
') ".
"union ".
"(select mac from vinterfaces ".
" where mac='
$
mac
') ".
"union ".
"(select cnet_mac as mac from node_history ".
" where cnet_mac='
$
mac
')");
if (!$query_result) {
DBQueryWarn("unlock tables");
return undef;
}
if (!$query_result->numrows) {
$argref->{'
mac
'} = $mac;
last;
}
}
}
my $query = "insert into vinterfaces set ".
join(",", map("$_='
" . $argref->{$_} . "
'", keys(%{$argref})));
my $query_result = DBQueryWarn($query);
DBQueryWarn("unlock tables");
return undef
if (!defined($query_result));
my $unit
= $query_result->insertid;
my $unit= $query_result->insertid;
return Interface::VInterface->Lookup($nodeid, $unit);
}
...
...
tbsetup/libvtop_test.pm.in
View file @
7ee63200
...
...
@@ -6878,19 +6878,10 @@ sub NewVirtIface($$$$;$)
}
}
#
#
Random
/
Unique
mac
address
.
#
my
$
mac
=
GenFakeMac
();
if
(
!defined($mac)) {
tberror
(
"Could not generate fake mac!
\n
"
);
return
undef
;
}
#
#
Create
new
virtiface
in
the
DB
.
#
my
%
argref
=
(
"mac"
=>
$
mac
,
my
%
argref
=
(
"mac"
=>
"genfake"
,
"IP"
=>
$
ip
,
"mask"
=>
$
mask
,
"type"
=>
$
type
,
...
...
@@ -6909,7 +6900,7 @@ sub NewVirtIface($$$$;$)
if
(
!defined($virtiface)) {
return
undef
;
}
$
self
->
printdb
(
"$virtiface: $member, isvdev:$isvdev, isveth:$isveth
, $mac
\n
"
);
$
self
->
printdb
(
"$virtiface: $member, isvdev:$isvdev, isveth:$isveth
\n
"
);
my
$
newid
=
$
virtiface
->
unit
();
#
Record
this
vinterface
mapping
.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment