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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case kMsgInterfaceHeal:
|
||||||
|
{
|
||||||
|
if (!item)
|
||||||
|
break;
|
||||||
|
|
||||||
|
NetworkSettings* ns = item->GetSettings();
|
||||||
|
ns->HealInterface();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BBox::MessageReceived(msg);
|
BBox::MessageReceived(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ NetworkSettings::NetworkSettings(const char* name)
|
|||||||
fName = name;
|
fName = name;
|
||||||
_DetectProtocols();
|
_DetectProtocols();
|
||||||
|
|
||||||
|
fNetworkInterface = new BNetworkInterface(fName);
|
||||||
|
|
||||||
ReadConfiguration();
|
ReadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,17 +111,16 @@ NetworkSettings::_DetectProtocols()
|
|||||||
void
|
void
|
||||||
NetworkSettings::ReadConfiguration()
|
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++) {
|
for (int index = 0; index < MAX_PROTOCOLS; index++) {
|
||||||
int inet_id = fProtocols[index].inet_id;
|
int inet_id = fProtocols[index].inet_id;
|
||||||
|
|
||||||
if (fProtocols[index].present) {
|
if (fProtocols[index].present) {
|
||||||
// --- Obtain IP Addresses
|
// --- Obtain IP Addresses
|
||||||
int32 zeroAddr = fNetworkInterface.FindFirstAddress(inet_id);
|
int32 zeroAddr = fNetworkInterface->FindFirstAddress(inet_id);
|
||||||
if (zeroAddr >= 0) {
|
if (zeroAddr >= 0) {
|
||||||
fNetworkInterface.GetAddressAt(zeroAddr,
|
fNetworkInterface->GetAddressAt(zeroAddr,
|
||||||
fInterfaceAddressMap[inet_id]);
|
fInterfaceAddressMap[inet_id]);
|
||||||
fAddress[inet_id].SetTo(
|
fAddress[inet_id].SetTo(
|
||||||
fInterfaceAddressMap[inet_id].Address());
|
fInterfaceAddressMap[inet_id].Address());
|
||||||
@@ -205,7 +206,7 @@ NetworkSettings::ReadConfiguration()
|
|||||||
// AutoConfiguration on the IP level doesn't exist yet
|
// AutoConfiguration on the IP level doesn't exist yet
|
||||||
// ( fInterfaceAddressMap[AF_INET].Flags() )
|
// ( fInterfaceAddressMap[AF_INET].Flags() )
|
||||||
if (fProtocols[index].socket_id >= 0) {
|
if (fProtocols[index].socket_id >= 0) {
|
||||||
fAutoConfigure[inet_id] = (fNetworkInterface.Flags()
|
fAutoConfigure[inet_id] = (fNetworkInterface->Flags()
|
||||||
& (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
|
& (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,20 +284,19 @@ NetworkSettings::ReadConfiguration()
|
|||||||
void
|
void
|
||||||
NetworkSettings::SetConfiguration()
|
NetworkSettings::SetConfiguration()
|
||||||
{
|
{
|
||||||
BNetworkInterface fNetworkInterface(fName);
|
|
||||||
printf("Setting %s\n", Name());
|
printf("Setting %s\n", Name());
|
||||||
for (int index = 0; index < MAX_PROTOCOLS; index++) {
|
for (int index = 0; index < MAX_PROTOCOLS; index++) {
|
||||||
int inet_id = fProtocols[index].inet_id;
|
int inet_id = fProtocols[index].inet_id;
|
||||||
if (fProtocols[index].present) {
|
if (fProtocols[index].present) {
|
||||||
int32 zeroAddr = fNetworkInterface.FindFirstAddress(inet_id);
|
int32 zeroAddr = fNetworkInterface->FindFirstAddress(inet_id);
|
||||||
if (zeroAddr >= 0) {
|
if (zeroAddr >= 0) {
|
||||||
BNetworkInterfaceAddress interfaceConfig;
|
BNetworkInterfaceAddress interfaceConfig;
|
||||||
fNetworkInterface.GetAddressAt(zeroAddr,
|
fNetworkInterface->GetAddressAt(zeroAddr,
|
||||||
interfaceConfig);
|
interfaceConfig);
|
||||||
interfaceConfig.SetAddress(fAddress[inet_id]);
|
interfaceConfig.SetAddress(fAddress[inet_id]);
|
||||||
interfaceConfig.SetMask(fNetmask[inet_id]);
|
interfaceConfig.SetMask(fNetmask[inet_id]);
|
||||||
fNetworkInterface.SetAddress(interfaceConfig);
|
fNetworkInterface->SetAddress(interfaceConfig);
|
||||||
fNetworkInterface.SetTo(zeroAddr);
|
fNetworkInterface->SetTo(zeroAddr);
|
||||||
} else {
|
} else {
|
||||||
// TODO : test this case (no address set for this protocol)
|
// TODO : test this case (no address set for this protocol)
|
||||||
printf("no zeroAddr found for %s(%d), found %lu\n",
|
printf("no zeroAddr found for %s(%d), found %lu\n",
|
||||||
@@ -304,7 +304,7 @@ NetworkSettings::SetConfiguration()
|
|||||||
BNetworkInterfaceAddress interfaceConfig;
|
BNetworkInterfaceAddress interfaceConfig;
|
||||||
interfaceConfig.SetAddress(fAddress[inet_id]);
|
interfaceConfig.SetAddress(fAddress[inet_id]);
|
||||||
interfaceConfig.SetMask(fNetmask[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)
|
void SetDisabled(bool disabled)
|
||||||
{ fDisabled = disabled; }
|
{ fDisabled = disabled; }
|
||||||
|
|
||||||
|
status_t HealInterface();
|
||||||
|
|
||||||
// void SetWirelessNetwork(const char* name)
|
// void SetWirelessNetwork(const char* name)
|
||||||
// { fWirelessNetwork.SetTo(name); }
|
// { fWirelessNetwork.SetTo(name); }
|
||||||
// void SetDomain(const BString& domain)
|
// void SetDomain(const BString& domain)
|
||||||
@@ -97,10 +99,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _DetectProtocols();
|
status_t _DetectProtocols();
|
||||||
BNetworkInterface fNetworkInterface;
|
|
||||||
InterfaceAddressMap fInterfaceAddressMap;
|
|
||||||
|
|
||||||
protocols fProtocols[MAX_PROTOCOLS];
|
|
||||||
|
|
||||||
// Stored network addresses and paramaters
|
// Stored network addresses and paramaters
|
||||||
BoolMap fAutoConfigure;
|
BoolMap fAutoConfigure;
|
||||||
@@ -113,6 +111,10 @@ private:
|
|||||||
bool fDisabled;
|
bool fDisabled;
|
||||||
BObjectList<BString> fNameServers;
|
BObjectList<BString> fNameServers;
|
||||||
BString fWirelessNetwork;
|
BString fWirelessNetwork;
|
||||||
|
|
||||||
|
protocols fProtocols[MAX_PROTOCOLS];
|
||||||
|
BNetworkInterface* fNetworkInterface;
|
||||||
|
InterfaceAddressMap fInterfaceAddressMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user