79
79
snprintf(cmd, 256, "-A POSTROUTING -d ! %s/%d -j MASQUERADE", network, slashnet);
80
80
rc = vnetApplySingleTableRule(vnetconfig, "nat", cmd);
82
snprintf(cmd, 256, "%s/usr/share/eucalyptus/euca_rootwrap ip addr add 169.254.169.254 dev %s", vnetconfig->eucahome, vnetconfig->pubInterface);
85
snprintf(cmd, 256, "-A PREROUTING -s %s/%d -d 169.254.169.254 -p tcp --dport 80 -j DNAT --to 169.254.169.254:8773", network, slashnet);
86
rc = vnetApplySingleTableRule(vnetconfig, "nat", cmd);
82
88
unm = 0xFFFFFFFF - numaddrs;
84
90
for (vlan=2; vlan<NUMBER_OF_VLANS; vlan++) {
639
645
int check_device(char *dev) {
640
char rbuf[256], devbuf[256];
646
char rbuf[256], devbuf[256], *ptr;
643
650
if (!dev) return(1);
645
snprintf(devbuf, 255, "%s:", dev);
647
652
FH = fopen("/proc/net/dev", "r");
652
657
while(fgets(rbuf, 256, FH)) {
653
if (strstr(rbuf, devbuf)) {
658
ptr = strrchr(rbuf, ':');
661
ptr = strrchr(rbuf, ' ');
667
if (!strcmp(ptr, dev)) {
663
679
int check_bridge(char *brname) {
664
char rbuf[256], devbuf[256];
667
if (!brname) return(1);
669
snprintf(devbuf, 255, "%s:", brname);
671
FH = fopen("/proc/net/dev", "r");
676
while(fgets(rbuf, 256, FH)) {
677
if (strstr(rbuf, devbuf)) {
680
return(check_device(brname));
687
683
int vnetStartNetworkManaged(vnetConfig *vnetconfig, int vlan, char *userName, char *netName, char **outbrname) {
733
730
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap brctl addif %s %s", vnetconfig->eucahome, newbrname, newdevname);
734
731
rc = system(cmd);
734
// snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip addr add 0.0.0.0 dev %s", vnetconfig->eucahome, newbrname);
736
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s up", vnetconfig->eucahome, newbrname);
740
// snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip addr add 0.0.0.0 dev %s", vnetconfig->eucahome, newdevname);
742
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s up", vnetconfig->eucahome, newdevname);
736
746
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ifconfig %s 0.0.0.0 up", vnetconfig->eucahome, newbrname);
737
747
rc = system(cmd);
738
748
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ifconfig %s up", vnetconfig->eucahome, newdevname);
739
749
rc = system(cmd);
742
753
snprintf(newbrname, 32, "%s", vnetconfig->bridgedev);
776
snprintf(newbrname, 32, "eucabr%d", vlan);
777
rc = check_bridge(newbrname);
779
// bridge does not yet exist
780
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap brctl addbr %s", vnetconfig->eucahome, newbrname);
783
logprintfl(EUCAERROR, "could not create new bridge %s\n", newbrname);
788
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap brctl addif %s %s", vnetconfig->eucahome, newbrname, newdevname);
792
// snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip addr add 0.0.0.0 dev %s", vnetconfig->eucahome, newbrname);
794
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s up", vnetconfig->eucahome, newbrname);
796
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip addr flush %s", vnetconfig->eucahome, newbrname);
800
// snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip addr add 0.0.0.0 dev %s", vnetconfig->eucahome, newdevname);
802
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s up", vnetconfig->eucahome, newdevname);
805
snprintf(newdevname, 32, "%s", newbrname);
764
807
snprintf(newdevname, 32, "%s", vnetconfig->pubInterface);
772
newip = hex2dot(vnetconfig->networks[vlan].router);
773
netmask = hex2dot(vnetconfig->networks[vlan].nm);
775
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ifconfig %s %s netmask %s up", vnetconfig->eucahome, newdevname, newip, netmask);
778
logprintfl(EUCAERROR, "could not bring up new device %s with ip %s\n", newdevname, newip);
779
if (newip) free(newip);
780
if (netmask) free(netmask);
783
if (newip) free(newip);
784
if (netmask) free(netmask);
787
815
*outbrname = strdup(newdevname);
812
840
if (newip) free(newip);
813
841
if (broadcast) free(broadcast);
815
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ifconfig %s up", vnetconfig->eucahome, devname);
843
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s up", vnetconfig->eucahome, devname);
816
844
rc = system(cmd);
818
846
logprintfl(EUCAERROR, "could not bring up interface '%s'\n", devname);
854
if (vnetconfig->role == NC) {
882
//if (vnetconfig->role == NC) {
856
if (!strcmp(vnetconfig->mode, "MANAGED")) {
857
snprintf(newbrname, 32, "eucabr%d", vlan);
858
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ifconfig %s down", vnetconfig->eucahome, newbrname);
861
logprintfl(EUCAERROR, "cmd '%s' failed\n", cmd);
884
if (!strcmp(vnetconfig->mode, "MANAGED")) {
885
snprintf(newbrname, 32, "eucabr%d", vlan);
886
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s down", vnetconfig->eucahome, newbrname);
889
logprintfl(EUCAERROR, "cmd '%s' failed\n", cmd);
868
896
if (!strcmp(vnetconfig->mode, "MANAGED")) {
869
897
snprintf(newdevname, 32, "%s.%d", vnetconfig->pubInterface, vlan);
870
898
rc = check_device(newdevname);
872
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ifconfig %s down", vnetconfig->eucahome, newdevname);
900
snprintf(cmd, 1024, "%s/usr/share/eucalyptus/euca_rootwrap ip link set dev %s down", vnetconfig->eucahome, newdevname);
873
901
rc = system(cmd);
875
903
logprintfl(EUCAERROR, "cmd '%s' failed\n", cmd);
915
snprintf(newdevname, 32, "%s", newbrname);
888
917
snprintf(newdevname, 32, "%s", vnetconfig->pubInterface);
896
925
logprintfl(EUCAERROR, "could not remove '%s' from list of interfaces\n", newdevname);
899
rc = vnetDelGatewayIP(vnetconfig, vlan, newdevname);
928
rc = vnetDelGatewayIP(vnetconfig, vlan, newdevname);
902
930
if (userName && netName) {
903
931
rc = vnetDeleteChain(vnetconfig, userName, netName);