implement *basic* network interface Healing action; make fNetworkInterface a pointer so it actually works right
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40917 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -167,6 +167,16 @@ InterfacesAddOn::MessageReceived(BMessage* msg)
|
||||
break;
|
||||
}
|
||||
|
||||
case kMsgInterfaceHeal:
|
||||
{
|
||||
if (!item)
|
||||
break;
|
||||
|
||||
NetworkSettings* ns = item->GetSettings();
|
||||
ns->HealInterface();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BBox::MessageReceived(msg);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ NetworkSettings::NetworkSettings(const char* name)
|
||||
fName = name;
|
||||
_DetectProtocols();
|
||||
|
||||
fNetworkInterface = new BNetworkInterface(fName);
|
||||
|
||||
ReadConfiguration();
|
||||
}
|
||||
|
||||
@@ -109,17 +111,16 @@ NetworkSettings::_DetectProtocols()
|
||||
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 @@ NetworkSettings::ReadConfiguration()
|
||||
// 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 @@ NetworkSettings::ReadConfiguration()
|
||||
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 @@ NetworkSettings::SetConfiguration()
|
||||
BNetworkInterfaceAddress interfaceConfig;
|
||||
interfaceConfig.SetAddress(fAddress[inet_id]);
|
||||
interfaceConfig.SetMask(fNetmask[inet_id]);
|
||||
fNetworkInterface.AddAddress(interfaceConfig);
|
||||
fNetworkInterface->AddAddress(interfaceConfig);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -330,3 +330,26 @@ NetworkSettings::WriteConfiguration()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! 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;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ public:
|
||||
void SetDisabled(bool disabled)
|
||||
{ fDisabled = disabled; }
|
||||
|
||||
status_t HealInterface();
|
||||
|
||||
// void SetWirelessNetwork(const char* name)
|
||||
// { fWirelessNetwork.SetTo(name); }
|
||||
// void SetDomain(const BString& domain)
|
||||
@@ -97,10 +99,6 @@ public:
|
||||
|
||||
private:
|
||||
status_t _DetectProtocols();
|
||||
BNetworkInterface fNetworkInterface;
|
||||
InterfaceAddressMap fInterfaceAddressMap;
|
||||
|
||||
protocols fProtocols[MAX_PROTOCOLS];
|
||||
|
||||
// Stored network addresses and paramaters
|
||||
BoolMap fAutoConfigure;
|
||||
@@ -113,6 +111,10 @@ private:
|
||||
bool fDisabled;
|
||||
BObjectList<BString> fNameServers;
|
||||
BString fWirelessNetwork;
|
||||
|
||||
protocols fProtocols[MAX_PROTOCOLS];
|
||||
BNetworkInterface* fNetworkInterface;
|
||||
InterfaceAddressMap fInterfaceAddressMap;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user