Changeset f8fa72b for fedkit/gateway_lib.pm
- Timestamp:
- Mar 5, 2010 3:26:09 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 444790d
- Parents:
- c119839
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedkit/gateway_lib.pm
rc119839 rf8fa72b 27 27 my $FINDIF = "/usr/local/etc/emulab/findif"; 28 28 my $TMCC = "/usr/local/etc/emulab/tmcc"; 29 30 # Linux choices 31 my $BRCTL = "/usr/sbin/brctl"; 32 my $IPROUTE = "/sbin/ip route "; 29 33 30 34 # Takes an ssh config file and a reference to a hash of keys whose values must … … 176 180 } 177 181 178 system("ifconfig $bridge create"); 179 warn "Cannot create bridge: $?\n" if $?; 180 foreach my $a (@addr) { 181 system("ifconfig $iface delete $a"); 182 warn "Cannot delete address $a: $?\n" if $?; 183 } 184 system("ifconfig $bridge addm $iface up"); 185 warn "Cannot add intefrace $iface to bridge: $?\n" if $?; 186 system("ifconfig $bridge addm $tap"); 187 warn "Cannot add intefrace $tap to bridge: $?\n" if $?; 188 return $?; 182 my $uname = `uname`; 183 chomp $uname; 184 185 if ($uname =~ /FreeBSD/) { 186 system("ifconfig $bridge create"); 187 warn "Cannot create bridge: $?\n" if $?; 188 foreach my $a (@addr) { 189 system("ifconfig $iface delete $a"); 190 warn "Cannot delete address $a: $?\n" if $?; 191 } 192 system("ifconfig $bridge addm $iface up"); 193 warn "Cannot add intefrace $iface to bridge: $?\n" if $?; 194 system("ifconfig $bridge addm $tap"); 195 warn "Cannot add intefrace $tap to bridge: $?\n" if $?; 196 return $?; 197 } 198 elsif ($uname =~ /Linux/) { 199 system("$IFCONFIG $iface 0.0.0.0 down"); 200 system("$BRCTL addbr $bridge"); 201 warn "Cannot create bridge: $?\n" if $?; 202 system("$BRCTL addif $bridge $tap"); 203 system("$BRCTL addif $bridge $iface"); 204 system("$BRCTL stp $bridge off"); 205 system("$IFCONFIG $bridge up"); 206 system("$IFCONFIG $tap up"); 207 system("$IFCONFIG $iface up"); 208 return $?; 209 } 189 210 } 190 211 … … 194 215 my $ipipe = new IO::Pipe() || die "Can't create pipe for ifconfig: $!\n"; 195 216 my @addr; 217 my $uname = `uname`; 218 my $ipre = "inet\\s+([0-9\\.]+)"; 219 chomp $uname; 220 221 if ($uname =~ /Linux/) { 222 $ipre = "inet\\s+addr:\\s*([0-9\\.]+)"; 223 } 196 224 197 225 $ipipe->reader("$IFCONFIG $iface"); 198 226 while(<$ipipe>) { 199 / inet\s+([0-9\.]+)/ && push(@addr, $1);227 /$ipre/ && push(@addr, $1); 200 228 } 201 229 $ipipe->close(); … … 207 235 my($dest) =@_; 208 236 my $rpipe = new IO::Pipe() || die "Can't create pipe for route: $!\n"; 209 210 $rpipe->reader("$ROUTE get $dest"); 237 my $uname = `uname`; 238 chomp $uname; 239 my $route; 240 my $dev_re; 241 242 if ($uname =~ /Linux/) { 243 $route = $IPROUTE; 244 $dev_re = "\\s+dev\\s+(\\S+)"; 245 } 246 elsif ($uname =~ /FreeBSD/) { 247 $route = $ROUTE; 248 $dev_re = 'interface:\\s*([[:alnum:]]+)'; 249 } 250 251 252 print "$route get $dest\n"; 253 $rpipe->reader("$route get $dest"); 211 254 while (<$rpipe>) { 212 / interface:\s*([[:alnum:]]+)/ && do {255 /$dev_re/ && do { 213 256 my $iface = $1; 214 257 $rpipe->close(); 258 print "matched: $iface\n"; 215 259 return $iface; 216 260 }; … … 290 334 291 335 292 sub emulab_config_filename { 293 # Find the configuration file in the usual place, which depends on what 294 # experiment and project we're in. 336 sub config_filename { 337 # Find the configuration file in the usual places, if there is one in 338 # /usr/local/federation/etc, use it, otherwise look in the emulab standard 339 # filesystems which depends on what experiment and project we're in. 295 340 my $pid; 296 341 my $eid; 297 342 my $filename; 343 my $fed_dir = "/usr/local/federation/etc/"; 344 my $hn = `hostname`; 345 chomp $hn; 346 $hn =~ s/\..*//; 347 348 return "$fed_dir/$hn.gw.conf" if -r "$fed_dir/$hn.gw.conf"; 349 298 350 my $tmcd = new IO::Pipe() || die "Can't create pipe: $!\n"; 299 351 … … 308 360 } 309 361 $tmcd->close(); 310 my $hn = `hostname`;311 chomp $hn;312 $hn =~ s/\..*//;313 362 $filename = "/proj/$pid/exp/$eid/tmp/$hn.gw.conf" 314 363 if $pid and $eid; … … 316 365 return $filename; 317 366 } 367 318 368 319 369 sub wait_for_port {
Note: See TracChangeset
for help on using the changeset viewer.