[PC-BSD Commits] r5990 - pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig

svn at pcbsd.org svn at pcbsd.org
Wed Jan 13 10:30:13 PST 2010


Author: kris
Date: 2010-01-13 10:30:13 -0800 (Wed, 13 Jan 2010)
New Revision: 5990

Modified:
   pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp
   pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h
Log:

Updated ethernetconfig to also understand lagg0 devices



Modified: pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp	2010-01-13 17:39:21 UTC (rev 5989)
+++ pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.cpp	2010-01-13 18:30:13 UTC (rev 5990)
@@ -97,30 +97,60 @@
 
 }
 
+// Function which sets up the lagg0 interface, and returns the corrected string we'll be
+// saving to rc.conf
+void ethernetconfig::saveLaggLine(QString dev, QString config)
+{
+  QString tmp, devices, tmp2;
+
+  // Enable the lagg0 interface
+  saveValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
+
+  tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+  if ( tmp.isEmpty() ) {
+    saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
+  } else {
+    if ( tmp.indexOf("laggport "+ dev ) != -1 )
+     tmp = tmp.remove(tmp.indexOf("laggport " + dev), 9 + dev.size()); // Remove the current laggport
+    // Find any other laggport devices and save them
+    while ( tmp.indexOf("laggport ") != -1 ) {
+      tmp2 = tmp;
+      tmp2.remove(0, tmp2.indexOf("laggport ") + 9 );
+      if ( tmp2.indexOf(" ") != -1 )
+        tmp2.truncate(tmp2.indexOf(" "));
+      devices += " laggport " + tmp2;
+
+      tmp = tmp.remove(tmp.indexOf("laggport "), 9 + tmp2.size()); 
+    }
+
+    saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + devices + " " + config + "\"", -1);
+  }
+}
+
 void ethernetconfig::slot_apply()
 {
 
-    if ( ! buttonApply->isEnabled() ) {
+   QString ifConfigLine;
+
+    if ( ! buttonApply->isEnabled() )
 	return;
-    }
 
 
-	if ( checkDisableNetwork->isChecked() )
-	{
-		saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "", -1);
-		runCommand("ifconfig " + DeviceName + " down");
-                buttonApply->setEnabled(FALSE);
-		return;
-	}
+    // If the user disabled the device, do so now
+    if ( checkDisableNetwork->isChecked() )
+    {
+      saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "", -1);
+      runCommand("ifconfig " + DeviceName + " down");
+      buttonApply->setEnabled(FALSE);
+      return;
+    }
 
-
+    
     if (! checkDHCP->isChecked() )
     {
-	if ( lineIP->text() == "..." || lineNetmask->text() == "..." )
-	{
+	if ( lineIP->text() == "..." || lineNetmask->text() == "..." ) {
 	    QMessageBox::information( this, tr("Missing Fields"),
                     tr("You must enter an IP and Netmask to continue!\n") );
-	    
 	    return;
 	}
 	
@@ -135,57 +165,44 @@
 	    tr("Netmask is out of range! (") + lineNetmask->text() + tr(") Fields must be between 0-255.") );
 	   return;
                }
-
-        if ( checkMAC->isChecked() ) {
-          saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "ifconfig_" + DeviceName + "=\"inet " + lineIP->text() + " netmask " + lineNetmask->text() + "\"", -1);
-        } else {
-          saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "ifconfig_" + DeviceName + "=\"inet " + lineIP->text() + " netmask " + lineNetmask->text() + " ether " + lineMAC->text() +"\"", -1);
-        }
-	  
-
+	
+	if ( checkMAC->isChecked() ) 
+	    ifConfigLine="inet " + lineIP->text() + " netmask " + lineNetmask->text();
+	else
+	    ifConfigLine="inet " + lineIP->text() \
+                        +" netmask " + lineNetmask->text() \
+                        + " ether " + lineMAC->text();
+	
     } else {
-         if ( checkMAC->isChecked() ) {
-	// Set the device to DHCP mode
-        saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "ifconfig_" + DeviceName + "=\"DHCP\"", -1);
-        } else {
-	saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "ifconfig_" + DeviceName + "=\"DHCP ether " + lineMAC->text() + "\"", -1);
-        }
+	ifConfigLine="DHCP";
     }
 
-
     if ( checkIPv6Enable->isChecked() ) {
        // Get rid of the ifconfig line for the ipv6 interface
        saveValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", "", -1);
     } else {
        saveValue( "/etc/rc.conf", "ipv6_ifconfig_" + DeviceName + "=", "ipv6_ifconfig_" + DeviceName + "=\"" + lineIPv6Address->text() + "\"", -1);
     }
+    
+    saveLaggLine(DeviceName, ifConfigLine);
 
 
+   // Now restart the network for new settings to take effect
+   QFile filerestart( "/tmp/.netrestart.sh" );
+   if ( filerestart.open( QIODevice::WriteOnly ) ) {
+        QTextStream streamrestart( &filerestart );
+        streamrestart << "#!/bin/sh\n";
+        streamrestart << "/etc/rc.d/netif restart " << DeviceName << "\n";
+        //streamrestart << "/etc/rc.d/routing restart";
+        filerestart.close();
+   }
 
-    if ( ! checkMAC->isChecked() )
-    {
-       runCommand("ifconfig " + DeviceName + " ether " + lineMAC->text() );
-    }
 
-    //runCommand("/etc/rc.d/netif restart &");
-    //runCommand("/etc/rc.d/routing restart &");
+   //runCommand("chmod 755 /tmp/.netrestart.sh ; sh /tmp/.netrestart.sh");
+   //runCommand("rm /tmp/.netrestart.sh");
 
-     if ( checkDHCP->isChecked() )
-    {
-         runCommand("dhclient " + DeviceName + " &");
-    } else {
-         runCommand("ifconfig " + DeviceName + " inet " + lineIP->text() );
-	 runCommand("ifconfig " + DeviceName + " netmask " + lineNetmask->text() );
-    }
-
-    if ( ! checkIPv6Enable->isChecked() )
-    {
-	runCommand("ifconfig " + DeviceName + " inet6 " + lineIPv6Address->text() );
-    }
-
    // Done, now set the apply button to off
    buttonApply->setEnabled(FALSE);
-
 }
 
 void ethernetconfig::slotIPCheckbox()
@@ -214,10 +231,10 @@
    connect(checkDHCP, SIGNAL(clicked()), this, SLOT(slotIPCheckbox()) );
    connect(buttonOK, SIGNAL(clicked()), this, SLOT(slotOK()) );
    connect(checkMAC, SIGNAL(clicked()), this, SLOT(slotMacClicked()) );
-   connect(lineIP, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText(const QString &) ) );
-   connect(lineNetmask, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText(const QString &) ) );
-   connect(lineIPv6Address, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText(const QString &) ) );
-   connect(lineMAC, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText(const QString &) ) );
+   connect(lineIP, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText() ) );
+   connect(lineNetmask, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText() ) );
+   connect(lineIPv6Address, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText() ) );
+   connect(lineMAC, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText() ) );
 
 }
 
@@ -551,9 +568,7 @@
 
    QString tmp, tmp2;
    // Start loading the device information
-   tmp = getValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
-
-
+   tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
    if ( tmp.isEmpty() ) 
    {
 	checkDisableNetwork->setChecked(TRUE);
@@ -690,9 +705,8 @@
 	return status;
 }
 
-void ethernetconfig::slotCheckGlobalText(const QString &text )
+void ethernetconfig::slotCheckGlobalText()
 {
-   
   // Done, now set the apply button to off
   buttonApply->setEnabled(TRUE);
 }

Modified: pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h	2010-01-13 17:39:21 UTC (rev 5989)
+++ pcbsd/trunk/pcbsd-netmanager/src/ethernetconfig/ethernetconfig.h	2010-01-13 18:30:13 UTC (rev 5990)
@@ -71,12 +71,15 @@
     virtual QString getGatewayForIdent(QString ident);
     virtual QString getIPv6ForIdent(QString ident);
     virtual QString getMediaForIdent( QString ident );
+    void saveLaggLine(QString dev, QString config);
+    void setupEthLagg(QString dev);
+
     
 
 private slots:
     virtual void loadInfo();
     virtual void slotFinishLoad();
-    virtual void slotCheckGlobalText(const QString &text );
+    virtual void slotCheckGlobalText();
 };
 
 #endif



More information about the Commits mailing list