[haiku-commits] r40917 - haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn

Author: kallisti5
Date: 2011-03-11 19:20:57 +0100 (Fri, 11 Mar 2011)
New Revision: 40917
Changeset: http://dev.haiku-os.org/changeset/40917

Modified:
   haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp
   haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp
   haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h
Log:
implement *basic* network interface Healing action; make fNetworkInterface a 
pointer so it actually works right

Modified: 
haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp
===================================================================
--- haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp  
2011-03-11 16:39:49 UTC (rev 40916)
+++ haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp  
2011-03-11 18:20:57 UTC (rev 40917)
@@ -167,6 +167,16 @@
                        break;
                }
 
+               case kMsgInterfaceHeal:
+               {
+                       if (!item)
+                               break;
+
+                       NetworkSettings* ns = item->GetSettings();
+                       ns->HealInterface();
+                       break;
+               }
+
                default:
                        BBox::MessageReceived(msg);
        }

Modified: 
haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp
===================================================================
--- haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp  
2011-03-11 16:39:49 UTC (rev 40916)
+++ haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp  
2011-03-11 18:20:57 UTC (rev 40917)
@@ -41,6 +41,8 @@
        fName = name;
        _DetectProtocols();
 
+       fNetworkInterface = new BNetworkInterface(fName);
+
        ReadConfiguration();
 }
 
@@ -109,17 +111,16 @@
 void
 NetworkSettings::ReadConfiguration()
 {
-       BNetworkInterface fNetworkInterface(fName);
-       fDisabled = (fNetworkInterface.Flags() & IFF_UP) == 0;
+       fDisabled = (fNetworkInterface->Flags() & IFF_UP) == 0;
 
        for (int index = 0; index < MAX_PROTOCOLS; index++) {
                int inet_id = fProtocols[index].inet_id;
 
                if (fProtocols[index].present) {
                        // --- Obtain IP Addresses
-                       int32 zeroAddr = 
fNetworkInterface.FindFirstAddress(inet_id);
+                       int32 zeroAddr = 
fNetworkInterface->FindFirstAddress(inet_id);
                        if (zeroAddr >= 0) {
-                               fNetworkInterface.GetAddressAt(zeroAddr,
+                               fNetworkInterface->GetAddressAt(zeroAddr,
                                        fInterfaceAddressMap[inet_id]);
                                fAddress[inet_id].SetTo(
                                        
fInterfaceAddressMap[inet_id].Address());
@@ -205,7 +206,7 @@
                        //        AutoConfiguration on the IP level doesn't 
exist yet
                        //                ( 
fInterfaceAddressMap[AF_INET].Flags() )
                        if (fProtocols[index].socket_id >= 0) {
-                               fAutoConfigure[inet_id] = 
(fNetworkInterface.Flags()
+                               fAutoConfigure[inet_id] = 
(fNetworkInterface->Flags()
                                        & (IFF_AUTO_CONFIGURED | 
IFF_CONFIGURING)) != 0;
                        }
                }
@@ -283,20 +284,19 @@
 void
 NetworkSettings::SetConfiguration()
 {
-       BNetworkInterface fNetworkInterface(fName);
        printf("Setting %s\n", Name());
        for (int index = 0; index < MAX_PROTOCOLS; index++) {
                int inet_id = fProtocols[index].inet_id;
                if (fProtocols[index].present) {
-                       int32 zeroAddr = 
fNetworkInterface.FindFirstAddress(inet_id);
+                       int32 zeroAddr = 
fNetworkInterface->FindFirstAddress(inet_id);
                        if (zeroAddr >= 0) {
                                BNetworkInterfaceAddress interfaceConfig;
-                               fNetworkInterface.GetAddressAt(zeroAddr,
+                               fNetworkInterface->GetAddressAt(zeroAddr,
                                        interfaceConfig);
                                interfaceConfig.SetAddress(fAddress[inet_id]);
                                interfaceConfig.SetMask(fNetmask[inet_id]);
-                               fNetworkInterface.SetAddress(interfaceConfig);
-                               fNetworkInterface.SetTo(zeroAddr);
+                               fNetworkInterface->SetAddress(interfaceConfig);
+                               fNetworkInterface->SetTo(zeroAddr);
                        } else {
                                // TODO : test this case (no address set for 
this protocol)
                                printf("no zeroAddr found for %s(%d), found 
%lu\n",
@@ -304,7 +304,7 @@
                                BNetworkInterfaceAddress interfaceConfig;
                                interfaceConfig.SetAddress(fAddress[inet_id]);
                                interfaceConfig.SetMask(fNetmask[inet_id]);
-                               fNetworkInterface.AddAddress(interfaceConfig);
+                               fNetworkInterface->AddAddress(interfaceConfig);
                        }
 
                }
@@ -330,3 +330,26 @@
 {
 
 }
+
+
+/*! HealInterface performs a address renegotiation in an attempt to fix
+       connectivity problems
+*/
+status_t
+NetworkSettings::HealInterface()
+{
+       for (int index = 0; index < MAX_PROTOCOLS; index++) {
+               int inet_id = fProtocols[index].inet_id;
+               if (fProtocols[index].present
+                       && AutoConfigure(inet_id)) {
+                       // If protocol is active, and set to auto
+                       printf("Healing %d\n", inet_id);
+                       fNetworkInterface->RemoveDefaultRoute(inet_id);
+                               // Remove default route
+                       fNetworkInterface->AutoConfigure(inet_id);
+                               // Perform AutoConfiguration
+               }
+       }
+
+       return B_OK;
+}

Modified: 
haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h
===================================================================
--- haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h    
2011-03-11 16:39:49 UTC (rev 40916)
+++ haiku/trunk/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h    
2011-03-11 18:20:57 UTC (rev 40917)
@@ -59,6 +59,8 @@
                        void                            SetDisabled(bool 
disabled)
                                                                        { 
fDisabled = disabled; }
 
+                       status_t                        HealInterface();
+
 //                     void                            
SetWirelessNetwork(const char* name)
 //                                                                     { 
fWirelessNetwork.SetTo(name); }
 //                     void                            SetDomain(const 
BString& domain)
@@ -97,11 +99,7 @@
 
 private:
                        status_t                        _DetectProtocols();
-                       BNetworkInterface       fNetworkInterface;
-                       InterfaceAddressMap     fInterfaceAddressMap;
 
-                       protocols                       
fProtocols[MAX_PROTOCOLS];
-
                        // Stored network addresses and paramaters
                        BoolMap                         fAutoConfigure;
                        AddressMap                      fAddress;
@@ -113,6 +111,10 @@
                        bool                            fDisabled;
                        BObjectList<BString> fNameServers;
                        BString                         fWirelessNetwork;
+
+                       protocols                       
fProtocols[MAX_PROTOCOLS];
+                       BNetworkInterface*      fNetworkInterface;
+                       InterfaceAddressMap     fInterfaceAddressMap;
 };
 
 


Other related posts: