[PC-BSD Commits] r19763 - in pcbsd/current/src-qt4: libpcbsd pc-netmanager/src/NetworkManager pc-netmanager/src/ethernetconfig pc-netmanager/src/wificonfig

svn at pcbsd.org svn at pcbsd.org
Thu Oct 18 07:58:13 PDT 2012


Author: kris
Date: 2012-10-18 14:58:13 +0000 (Thu, 18 Oct 2012)
New Revision: 19763

Modified:
   pcbsd/current/src-qt4/libpcbsd/netif.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h
   pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp
   pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp
   pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
   pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h
Log:

Move all "lagg" functionality to a single function in libpcbsd

Now we can call this function from wificonfig, ethernetconfig, and the 
network manager if the user enables the "lagg" option, so they don't have to 
go into the wifi-manager and save it a single time before its enabled. 



Modified: pcbsd/current/src-qt4/libpcbsd/netif.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/netif.cpp	2012-10-18 10:09:33 UTC (rev 19762)
+++ pcbsd/current/src-qt4/libpcbsd/netif.cpp	2012-10-18 14:58:13 UTC (rev 19763)
@@ -552,3 +552,50 @@
    
    return;
 }
+
+// Function which sets up the lagg0 interface for the specified wlan[0-9] device
+void NetworkInterface::enableLagg(QString dev)
+{
+  // Get the first wired device, we will enable lagg0 to use it
+  QString wiredDev, wifiParent, wifiConf, tmp;
+  wiredDev = NetworkInterface::getFirstWiredDevice();
+  wifiParent = NetworkInterface::getWifiParent(dev);
+
+  // If no wired device on this box or no valid wifi parent we can return, no need to setup lagg
+  if ( wiredDev.isEmpty() || wifiParent.isEmpty() )
+     return;
+
+  // Get the config for this wifi device
+  wifiConf = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_" + dev + "=", 1 );
+  if ( wifiConf.isEmpty() )
+     wifiConf = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+  else if ( wifiConf == "WPA" ) {
+     // If it just equals WPA, check if anything already exists in lagg0 line
+     tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+     if ( ! tmp.isEmpty() )
+        wifiConf = tmp;
+  }
+
+  // No valid config? We can't save this..
+  if ( wifiConf.isEmpty() )
+     return;
+
+  // Setup the ethernet mac address cloning for this device
+  Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + wifiParent, "ifconfig_" + wifiParent + "=\"`ifconfig " + wiredDev + " ether`\"", 1);
+  Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + wifiParent, "ifconfig_" + wifiParent + "=\"ether ${ifconfig_" + wifiParent + "##*ether }\"", 2);
+  Utils::setConfFileValue( "/etc/rc.conf", "wlans_" + wifiParent, "wlans_" + wifiParent + "=\"" + dev + "\"", -1);
+
+
+  // Check if we have a WPA setting, and put it in the right device slot
+  if ( wifiConf.indexOf("WPA") != -1 )
+  {
+    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
+    wifiConf = wifiConf.replace("WPA", "");
+    wifiConf = wifiConf.simplified();
+  }
+
+  // Enable the lagg0 interface
+  Utils::setConfFileValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
+  Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + wifiConf + "\"", -1);
+
+}

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h	2012-10-18 10:09:33 UTC (rev 19762)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h	2012-10-18 14:58:13 UTC (rev 19763)
@@ -57,6 +57,7 @@
    static void wifiQuickConnect(QString SSID, QString netKey, QString DeviceName);
    static QString getFirstWiredDevice();
    static QString getWifiParent(QString dev);
+   static void enableLagg(QString dev);
 
 private:
    QString name;

Modified: pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp	2012-10-18 10:09:33 UTC (rev 19762)
+++ pcbsd/current/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp	2012-10-18 14:58:13 UTC (rev 19763)
@@ -942,6 +942,10 @@
     QSettings settings("PCBSD");
     settings.setValue("/pc-netmanager/useLagg", checkLagg->isChecked());
 
+    // Make sure we enable lagg for this system
+    if ( checkLagg->isChecked() )
+       NetworkInterface::enableLagg(QString("wlan0"));
+
     // Save the proxy config
     saveProxyConfig();
    

Modified: pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp	2012-10-18 10:09:33 UTC (rev 19762)
+++ pcbsd/current/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp	2012-10-18 14:58:13 UTC (rev 19763)
@@ -65,36 +65,6 @@
 		return false;
 }
 
-// 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
-  Utils::setConfFileValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
-
-  tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
-  if ( tmp.isEmpty() ) {
-    Utils::setConfFileValue( "/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()); 
-    }
-
-    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover" + devices + " laggport " + dev + " " + config + "\"", -1);
-  }
-}
-
 void ethernetconfig::slot_apply()
 {
 
@@ -171,15 +141,13 @@
           Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "_ipv6=", "ifconfig_" + DeviceName + "_ipv6=\"" + tmp + " -accept_rtadv\"", -1);
        }
     }
+
+   Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "ifconfig_" + DeviceName + "=\"" + ifConfigLine + "\"", -1); 
+
+   // See if we need to enable lagg on this device
+   if ( isWifiEnabled() && useLagg )
+      NetworkInterface::enableLagg(QString("wlan0"));
     
-   // Check if we want to use the lagg interface
-   if ( useLagg ) {
-   	saveLaggLine(DeviceName, ifConfigLine);
-        runCommand("ifconfig lagg0 destroy");
-   } else {
-        Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", "ifconfig_" + DeviceName + "=\"" + ifConfigLine + "\"", -1); 
-   }
-
    Utils::restartNetworking();
 
    // Done, now set the apply button to off
@@ -406,7 +374,8 @@
    // Start loading the device information
    if ( useLagg )
       tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
-   else
+
+   if ( tmp.isEmpty() )
       tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
 
    // Using WPAE config?

Modified: pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp	2012-10-18 10:09:33 UTC (rev 19762)
+++ pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp	2012-10-18 14:58:13 UTC (rev 19763)
@@ -29,82 +29,21 @@
     exit(0);
 }
 
-void wificonfigwidgetbase::setupWifiLagg(QString dev)
-{
-  QString wiredDev, tmp;
-
-  wiredDev = NetworkInterface::getFirstWiredDevice();
-
-  // If we have a valid wired device, clone the MAC of it to the wireless device
-  if ( ! wiredDev.isEmpty() )
-  {
-    // If we are using wlan device
-    if ( ! DeviceNameParent.isEmpty() ) {
-      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"`ifconfig " + wiredDev + " ether`\"", 1);
-      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"ether ${ifconfig_" + DeviceNameParent + "##*ether }\"", 2);
-      Utils::setConfFileValue( "/etc/rc.conf", "wlans_" + DeviceNameParent, "wlans_" + DeviceNameParent + "=\"" + DeviceName + "\"", -1);
-    } else {
-      // On 7.x, no wlan0 device needed
-      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
-      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"ether ${ifconfig_" + dev + "##*ether }\"", -1);
-    }
-  }
-
-
-}
-
-// Function which sets up the lagg0 interface, and returns the corrected string we'll be
-// saving to rc.conf
-void wificonfigwidgetbase::saveLaggLine(QString dev, QString config)
-{
-  QString wiredDev;
-
-  // Start by enabling lagg for this device
-  setupWifiLagg(dev);
-
-  // Check if we have a WPA setting, and put it in the right device slot
-  if ( config.indexOf("WPA") != -1 )
-  {
-    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
-    config = config.remove(0, config.indexOf("WPA") + 3);
-    config = config.simplified();
-  }
-
-  // Enable the lagg0 interface
-  Utils::setConfFileValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
-
-  wiredDev = NetworkInterface::getFirstWiredDevice();
-  if ( ! wiredDev.isEmpty() )
-    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + config + "\"", -1);
-  else
-    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
-}
-
 void wificonfigwidgetbase::slotApply()
 {
     QString tmp;
     QString ifConfigLine;
-    bool listEmpty = false;
     if ( ! pushApply->isEnabled() ) {
 	return;
     }
-    
-    // If the user disabled the device, do so now
-    if ( checkDisableWireless->isChecked() && ! WPAONLY )
+
+    // Get ifConfig Line
+    if (! checkDHCP->isChecked() )
     {
-	 Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "", -1);
-	 runCommand("ifconfig " + DeviceName + " down");
-         pushApply->setEnabled(FALSE);
-	 return;
-    } 
-    
-    if (! checkDHCP->isChecked() && ! WPAONLY)
-    {
 	if ( lineIP->text() == "..." || lineNetmask->text() == "..." )
 	{
 	    QMessageBox::information( this, tr("Missing Fields"),
                     tr("You must enter an IP and Netmask to continue!\n") );
-	    
 	    return;
 	}
 	
@@ -120,26 +59,57 @@
 	   return;
                }
 	
-	if ( checkMAC->isChecked() ) { 
+	if ( checkMAC->isChecked() )
 	    ifConfigLine=lineIP->text() + " netmask " + lineNetmask->text();
-	} else {
+	else
 	    ifConfigLine=lineIP->text() + " netmask " + lineNetmask->text() + " ether " + lineMAC->text();
-	}
-	
+
     } else {
 	ifConfigLine="SYNCDHCP";
     } 
 
-    // Check if we want to use the lagg interface
-    if ( usingLagg && ! WPAONLY )
-      saveLaggLine(DeviceName, "WPA " + ifConfigLine);
-    else if ( ! WPAONLY ) {
-      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "", -1);
-      Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, \
-		 "ifconfig_" + DeviceName + "=\"WPA " + ifConfigLine + "\"", -1);
-    }
-	
     // Now create the wpa_supplicant file based on saved configuration
+    updateWPASupp();
+
+    // Only updating WPA supp?
+    if (WPAONLY) 
+       return;
+    
+    // If the user disabled the device, do so now
+    if ( checkDisableWireless->isChecked() )
+    {
+	 Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "", -1);
+	 runCommand("ifconfig " + DeviceName + " down");
+         pushApply->setEnabled(FALSE);
+	 return;
+    } 
+
+    // Save the config
+    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "", -1);
+    Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, \
+	 "ifconfig_" + DeviceName + "=\"WPA " + ifConfigLine + "\"", -1);
+
+    // Check if we need to enable LAGG
+    if ( usingLagg )
+      NetworkInterface::enableLagg(DeviceName);
+
+    // Set perms on wpa_supplicant.conf
+    system("chmod 600 /etc/wpa_supplicant.conf");
+
+    // Restart the network
+    buttonCancel->setEnabled(false);
+    Utils::restartNetworking();
+
+    buttonCancel->setEnabled(true);
+    pushApply->setEnabled(FALSE);
+}
+
+
+void wificonfigwidgetbase::updateWPASupp()
+{
+    bool listEmpty = false;
+    QString tmp;
+
     QFile fileout( "/etc/wpa_supplicant.conf" );
     if ( fileout.open( QIODevice::WriteOnly ) ) {
        QTextStream streamout( &fileout );
@@ -238,17 +208,10 @@
     // If no networks, clear out WPA supplicant.conf and reset rc.conf
     if ( listEmpty  && ! WPAONLY ){
        fileout.remove();
+       Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_lagg0", "", -1);
        Utils::setConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "ifconfig_" + DeviceName + "=\"SYNCDHCP\"");
-    }
+    }  
 
-    if ( ! WPAONLY )
-      Utils::restartNetworking();
-
-    system("chmod 600 /etc/wpa_supplicant.conf");
-
-    buttonCancel->setEnabled(false);
-    buttonCancel->setEnabled(true);
-    pushApply->setEnabled(FALSE);
 }
 
 
@@ -1004,7 +967,6 @@
     if ( DeviceName.indexOf("wlan") != -1 )
     {
       tmp = NetworkInterface::getWifiParent(DeviceName);
-      DeviceNameParent = NetworkInterface::getWifiParent(DeviceName);
 
       // Get HW Identify line
       tmp = getNameForIdent(tmp);
@@ -1065,7 +1027,8 @@
    // Get the ifconfig string
    if ( usingLagg )
      tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
-   else
+
+   if ( tmp.isEmpty() )
      tmp = Utils::getConfFileValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
 
    if ( tmp.isEmpty() || tmp.indexOf("OFF") != -1 )  {

Modified: pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h
===================================================================
--- pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h	2012-10-18 10:09:33 UTC (rev 19762)
+++ pcbsd/current/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h	2012-10-18 14:58:13 UTC (rev 19763)
@@ -86,10 +86,8 @@
     QString getGatewayForIdent( QString ident );
     QString getMediaForIdent( QString ident );
     QString getWifiParent( QString dev );
-    void saveLaggLine(QString dev, QString config);
-    void setupWifiLagg(QString dev);
+    void updateWPASupp();
     QString DeviceName;
-    QString DeviceNameParent;
     
     dialogWPAPersonal *dialogWPA;
     wepConfig *dialogWEP;



More information about the Commits mailing list