[PC-BSD Commits] r19764 - in pcbsd/branches/9.1/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 08:00:01 PDT 2012


Author: kris
Date: 2012-10-18 15:00:01 +0000 (Thu, 18 Oct 2012)
New Revision: 19764

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

MFC the fixes to move lagg into libpcbsd, and enable it via ethernet, wifi,
and network manager utilties



Modified: pcbsd/branches/9.1/src-qt4/libpcbsd/netif.cpp
===================================================================
--- pcbsd/branches/9.1/src-qt4/libpcbsd/netif.cpp	2012-10-18 14:58:13 UTC (rev 19763)
+++ pcbsd/branches/9.1/src-qt4/libpcbsd/netif.cpp	2012-10-18 15:00:01 UTC (rev 19764)
@@ -392,6 +392,42 @@
   return securityType;
 }
 
+QString NetworkInterface::getFirstWiredDevice()
+{
+  QString tmp;
+
+  QStringList ifs = getInterfaces();
+  for ( QStringList::Iterator it = ifs.begin(); it != ifs.end(); ++it )
+  {
+     QString tmpDev = *it;
+     if (tmpDev.indexOf("lo0") == -1
+         && tmpDev.indexOf("lo1") == -1
+         && tmpDev.indexOf("lo2") == -1
+         && tmpDev.indexOf("lo3") == -1
+         && tmpDev.indexOf("fwe") == -1
+         && tmpDev.indexOf("plip") == -1
+         && tmpDev.indexOf("pfsync") == -1
+         && tmpDev.indexOf("pflog") == -1
+         && tmpDev.indexOf("wlan") == -1
+         && tmpDev.indexOf("tun") == -1)
+     {
+        NetworkInterface ifr(tmpDev);
+        if (! ifr.isWireless()) {
+          return tmpDev;
+        }
+     }
+  }
+
+  return tmp;
+}
+
+QString NetworkInterface::getWifiParent(QString dev)
+{
+   dev.remove(0, dev.size() -1 );
+   QString DevNum = dev;
+   return Utils::sysctl("net.wlan." + DevNum + ".%parent");
+}
+
 void NetworkInterface::wifiQuickConnect(QString SSID, QString netKey, QString DeviceName){
   /* 
      This function uses a set of defaults to connect to a wifi access point with a minimum
@@ -516,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/branches/9.1/src-qt4/libpcbsd/pcbsd-netif.h
===================================================================
--- pcbsd/branches/9.1/src-qt4/libpcbsd/pcbsd-netif.h	2012-10-18 14:58:13 UTC (rev 19763)
+++ pcbsd/branches/9.1/src-qt4/libpcbsd/pcbsd-netif.h	2012-10-18 15:00:01 UTC (rev 19764)
@@ -55,6 +55,9 @@
    static QString getWifiSecurity(QString SSID,QString deviceName);
    static QString parseWifiSecurity( QString caps, QString etc );
    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/branches/9.1/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp
===================================================================
--- pcbsd/branches/9.1/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp	2012-10-18 14:58:13 UTC (rev 19763)
+++ pcbsd/branches/9.1/src-qt4/pc-netmanager/src/NetworkManager/networkman.cpp	2012-10-18 15:00:01 UTC (rev 19764)
@@ -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/branches/9.1/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp
===================================================================
--- pcbsd/branches/9.1/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp	2012-10-18 14:58:13 UTC (rev 19763)
+++ pcbsd/branches/9.1/src-qt4/pc-netmanager/src/ethernetconfig/ethernetconfig.cpp	2012-10-18 15:00:01 UTC (rev 19764)
@@ -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/branches/9.1/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
===================================================================
--- pcbsd/branches/9.1/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp	2012-10-18 14:58:13 UTC (rev 19763)
+++ pcbsd/branches/9.1/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.cpp	2012-10-18 15:00:01 UTC (rev 19764)
@@ -29,111 +29,21 @@
     exit(0);
 }
 
-QString wificonfigwidgetbase::getFirstWiredDevice()
-{
-  QString tmp;
-
-  QStringList ifs = NetworkInterface::getInterfaces();
-  for ( QStringList::Iterator it = ifs.begin(); it != ifs.end(); ++it )
-  {
-     QString tmpDev = *it;
-     if (tmpDev.indexOf("lo0") == -1
-         && tmpDev.indexOf("lo1") == -1
-         && tmpDev.indexOf("lo2") == -1
-         && tmpDev.indexOf("lo3") == -1
-         && tmpDev.indexOf("fwe") == -1
-         && tmpDev.indexOf("plip") == -1
-         && tmpDev.indexOf("pfsync") == -1
-         && tmpDev.indexOf("pflog") == -1
-         && tmpDev.indexOf("wlan") == -1
-         && tmpDev.indexOf("tun") == -1)
-     {
-        NetworkInterface ifr(tmpDev);
-        if (! ifr.isWireless()) {
-          return tmpDev;
-        }
-     }
-  }
-
-  return tmp;
-}
-
-void wificonfigwidgetbase::setupWifiLagg(QString dev)
-{
-  QString wiredDev, tmp;
-
-  wiredDev = 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 = 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;
 	}
 	
@@ -149,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 );
@@ -267,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);
 }
 
 
@@ -1024,15 +958,6 @@
    return ifr.desc();
 }
 
-
-// Function which locates the parent device of a wlan child device
-QString wificonfigwidgetbase::getWifiParent(QString dev)
-{
-   dev.remove(0, dev.size() -1 );
-   QString DevNum = dev;
-   return Utils::sysctl("net.wlan." + DevNum + ".%parent");
-}
-
 void wificonfigwidgetbase::loadInfo()
 {
   QString tmp;
@@ -1041,8 +966,7 @@
   if ( textInfoName->text().isEmpty() ) {
     if ( DeviceName.indexOf("wlan") != -1 )
     {
-      tmp = getWifiParent(DeviceName);
-      DeviceNameParent = getWifiParent(DeviceName);
+      tmp = NetworkInterface::getWifiParent(DeviceName);
 
       // Get HW Identify line
       tmp = getNameForIdent(tmp);
@@ -1103,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/branches/9.1/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h
===================================================================
--- pcbsd/branches/9.1/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h	2012-10-18 14:58:13 UTC (rev 19763)
+++ pcbsd/branches/9.1/src-qt4/pc-netmanager/src/wificonfig/wificonfigwidgetbase.h	2012-10-18 15:00:01 UTC (rev 19764)
@@ -86,11 +86,8 @@
     QString getGatewayForIdent( QString ident );
     QString getMediaForIdent( QString ident );
     QString getWifiParent( QString dev );
-    QString getFirstWiredDevice();
-    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