[PC-BSD Commits] r5989 - pcbsd/trunk/pcbsd-netmanager/src/wificonfig

svn at pcbsd.org svn at pcbsd.org
Wed Jan 13 09:39:21 PST 2010


Author: kris
Date: 2010-01-13 09:39:21 -0800 (Wed, 13 Jan 2010)
New Revision: 5989

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

Updated the wificonfig tool, now it automatically sets up and uses the lagg0 interface for automatic
failover between wifi / wired network devices, which means you can unplug your wired device, go wireless,
re-plug the wired, and still keep a download going, or connection open



Modified: pcbsd/trunk/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp	2010-01-13 15:07:03 UTC (rev 5988)
+++ pcbsd/trunk/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.cpp	2010-01-13 17:39:21 UTC (rev 5989)
@@ -23,7 +23,88 @@
     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() )
+  {
+    saveValue( "/etc/rc.conf", "ifconfig_" + wiredDev, "ifconfig_" + wiredDev + "=\"up\"", -1);
+
+    // If we are using wlan device
+    if ( ! DeviceNameParent.isEmpty() ) {
+      saveValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
+      saveValue( "/etc/rc.conf", "ifconfig_" + DeviceNameParent, "ifconfig_" + DeviceNameParent + "=\"ether ${ifconfig_" + DeviceNameParent + "##*ether }\"", 2);
+      saveValue( "/etc/rc.conf", "wlans_" + DeviceNameParent, "wlans_" + DeviceNameParent + "=\"" + DeviceName + "\"", -1);
+    } else {
+      // On 7.x, no wlan0 device needed
+      saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + DeviceName + "=\"`ifconfig " + wiredDev + " ether`\"", -1);
+      saveValue( "/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 )
+  {
+    saveValue( "/etc/rc.conf", "ifconfig_" + dev, "ifconfig_" + dev + "=\"WPA\"", -1);
+    config = config.remove(0, config.indexOf("WPA") + 3);
+    config = config.simplified();
+  }
+
+  // Enable the lagg0 interface
+  saveValue( "/etc/rc.conf", "cloned_interfaces", "cloned_interfaces=\"lagg0\"", -1);
+
+  wiredDev = getFirstWiredDevice();
+  if ( ! wiredDev.isEmpty() )
+    saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + wiredDev + " laggport " + dev + " " + config + "\"", -1);
+  else
+    saveValue( "/etc/rc.conf", "ifconfig_lagg0", "ifconfig_lagg0=\"laggproto failover laggport " + dev + " " + config + "\"", -1);
+}
+
 void wificonfigwidgetbase::slotApply()
 {
     QString tmp;
@@ -71,14 +152,14 @@
 	    ifConfigLine="inet " + lineIP->text() + " netmask " + lineNetmask->text() + " ether " + lineMAC->text();
 	}
 	
-	
-	
     } else {
 	ifConfigLine="DHCP";
     }
+
+    
+    saveLaggLine(DeviceName, "WPA " + ifConfigLine);
+    //saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "ifconfig_" + DeviceName + "=\"WPA " + ifConfigLine + "\"", -1);
 	
-    saveValue( "/etc/rc.conf", "ifconfig_" + DeviceName, "ifconfig_" + DeviceName + "=\"WPA " + ifConfigLine + "\"", -1);
-	
     // Now create the wpa_supplicant file based on saved configuration
     QFile fileout( "/etc/wpa_supplicant.conf" );
     if ( fileout.open( QIODevice::WriteOnly ) ) {
@@ -168,6 +249,7 @@
 
 
    runCommand("chmod 755 /tmp/.netrestart.sh ; sh /tmp/.netrestart.sh");
+   runCommand("rm /tmp/.netrestart.sh");
      
    pushApply->setEnabled(FALSE);
 }
@@ -974,6 +1056,7 @@
     if ( DeviceName.indexOf("wlan") != -1 )
     {
       tmp = getWifiParent(DeviceName);
+      DeviceNameParent = getWifiParent(DeviceName);
 
       // Get HW Identify line
       tmp = getNameForIdent(tmp);
@@ -1018,12 +1101,12 @@
 
 void wificonfigwidgetbase::slotFinishLoading()
 {
-    QString tmp, tmp2;
-bool ok;
+   QString tmp, tmp2;
+   bool ok;
 
-  // Get the ifconfig string
-   tmp = getValue( "/etc/rc.conf", "ifconfig_" + DeviceName + "=", 1 );
-   if ( tmp != "" ) {
+   // Get the ifconfig string
+   tmp = getValue( "/etc/rc.conf", "ifconfig_lagg0=", 1 );
+   if ( tmp != "" && tmp.indexOf(DeviceName) != -1 ) {
    // If the device is setup, start loading the settings
 
    if ( tmp.indexOf("OFF") != -1 ) {
@@ -1052,7 +1135,8 @@
         // Get the IP address first
         tmp2 = tmp;
         tmp2 = tmp2.remove(0, tmp.indexOf("inet") + 5 );
-        tmp2.truncate(tmp.indexOf("netmask") -1 );
+        tmp2.truncate(tmp2.indexOf(" "));
+        tmp2 = tmp2.simplified();
         lineIP->setText(tmp2);
 
         // Look for the netmask
@@ -1070,8 +1154,9 @@
            lineNetmask->setText("255.255.255.0");
         }
    }
+   
+   }
 
-   
    // Look for the wpa_supplicant.conf file
    QFile file( "/etc/wpa_supplicant.conf" );
    if ( file.open( QIODevice::ReadOnly ) ) {
@@ -1237,7 +1322,6 @@
    loadInfo();
 
    pushApply->setEnabled(FALSE);
-   }
 }
 
 

Modified: pcbsd/trunk/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h
===================================================================
--- pcbsd/trunk/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h	2010-01-13 15:07:03 UTC (rev 5988)
+++ pcbsd/trunk/pcbsd-netmanager/src/wificonfig/wificonfigwidgetbase.h	2010-01-13 17:39:21 UTC (rev 5989)
@@ -77,7 +77,11 @@
     QString getGatewayForIdent( QString ident );
     QString getMediaForIdent( QString ident );
     QString getWifiParent( QString dev );
+    QString getFirstWiredDevice();
+    void saveLaggLine(QString dev, QString config);
+    void setupWifiLagg(QString dev);
     QString DeviceName;
+    QString DeviceNameParent;
     wifiselectiondialog *wifiselect;
     QProcess *netifProc;
 



More information about the Commits mailing list