make protocol selection more generic and easy to configure; this adds complexity but allows us to configure ipv4/ipv6 support from a single point.. now just have to figure out how to check for the presence of the IPv4 vs IPv6 network add-ons
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40584 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,8 +15,8 @@
|
|||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
|
|
||||||
|
|
||||||
InterfaceAddressView::InterfaceAddressView(BRect frame, const char* name,
|
InterfaceAddressView::InterfaceAddressView(BRect frame, int family,
|
||||||
int family, NetworkSettings* settings)
|
NetworkSettings* settings)
|
||||||
:
|
:
|
||||||
BGroupView(B_VERTICAL),
|
BGroupView(B_VERTICAL),
|
||||||
fSettings(settings),
|
fSettings(settings),
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ enum {
|
|||||||
class InterfaceAddressView : public BGroupView {
|
class InterfaceAddressView : public BGroupView {
|
||||||
public:
|
public:
|
||||||
InterfaceAddressView(BRect frame,
|
InterfaceAddressView(BRect frame,
|
||||||
const char* name, int family,
|
int family, NetworkSettings* settings);
|
||||||
NetworkSettings* settings);
|
|
||||||
virtual ~InterfaceAddressView();
|
virtual ~InterfaceAddressView();
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
|||||||
@@ -60,16 +60,25 @@ InterfaceWindow::~InterfaceWindow()
|
|||||||
void
|
void
|
||||||
InterfaceWindow::MessageReceived(BMessage* message)
|
InterfaceWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
|
int* supportedFamilies = fNetworkSettings->ProtocolVersions();
|
||||||
|
unsigned int index;
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_IP_REVERT:
|
case MSG_IP_REVERT:
|
||||||
// RFC : we could check fTabView for Selection
|
for (index = 0; index < sizeof(supportedFamilies); index++)
|
||||||
// here and only revert the selected tab.
|
{
|
||||||
fIPv4TabView->RevertFields();
|
int protocol = supportedFamilies[index];
|
||||||
fIPv6TabView->RevertFields();
|
if (protocol > 0)
|
||||||
|
fTabIPView[protocol]->RevertFields();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MSG_IP_SAVE:
|
case MSG_IP_SAVE:
|
||||||
fIPv4TabView->SaveFields();
|
for (index = 0; index < sizeof(supportedFamilies); index++)
|
||||||
fIPv6TabView->SaveFields();
|
{
|
||||||
|
int protocol = supportedFamilies[index];
|
||||||
|
if (protocol > 0)
|
||||||
|
fTabIPView[protocol]->SaveFields();
|
||||||
|
}
|
||||||
this->Quit();
|
this->Quit();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -83,19 +92,22 @@ status_t
|
|||||||
InterfaceWindow::_PopulateTabs()
|
InterfaceWindow::_PopulateTabs()
|
||||||
{
|
{
|
||||||
BRect frame = fTabView->Bounds();
|
BRect frame = fTabView->Bounds();
|
||||||
fIPv4TabView = new InterfaceAddressView(frame, "net_settings_ipv4",
|
int* supportedFamilies = fNetworkSettings->ProtocolVersions();
|
||||||
AF_INET, fNetworkSettings);
|
|
||||||
fIPv6TabView = new InterfaceAddressView(frame, "net_settings_ipv6",
|
|
||||||
AF_INET6, fNetworkSettings);
|
|
||||||
|
|
||||||
BTab* tab4 = new BTab;
|
unsigned int index;
|
||||||
BTab* tab6 = new BTab;
|
for (index = 0; index < sizeof(supportedFamilies); index++)
|
||||||
|
{
|
||||||
fTabView->AddTab(fIPv4TabView, tab4);
|
int protocol = supportedFamilies[index];
|
||||||
tab4->SetLabel("IPv4");
|
if (protocol > 0)
|
||||||
|
{
|
||||||
fTabView->AddTab(fIPv6TabView, tab6);
|
fTabIPView[protocol] = new InterfaceAddressView(frame,
|
||||||
tab6->SetLabel("IPv6");
|
protocol, fNetworkSettings);
|
||||||
|
BTab* tab = new BTab;
|
||||||
|
fTabView->AddTab(fTabIPView[protocol], tab);
|
||||||
|
tab->SetLabel((protocol == AF_INET) ? "IPv4" : "IPv6");
|
||||||
|
// TODO : find a better way
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_IP_SAVE = 'ipap',
|
MSG_IP_SAVE = 'ipap',
|
||||||
@@ -26,6 +28,9 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::map<int, InterfaceAddressView*> IPViewMap;
|
||||||
|
|
||||||
|
|
||||||
class InterfaceWindow : public BWindow {
|
class InterfaceWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
InterfaceWindow(NetworkSettings* settings);
|
InterfaceWindow(NetworkSettings* settings);
|
||||||
@@ -41,8 +46,7 @@ private:
|
|||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
BTabView* fTabView;
|
BTabView* fTabView;
|
||||||
|
|
||||||
InterfaceAddressView* fIPv4TabView;
|
IPViewMap fTabIPView;
|
||||||
InterfaceAddressView* fIPv6TabView;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,19 +38,35 @@ NetworkSettings::NetworkSettings(const char* name)
|
|||||||
fDisabled(false),
|
fDisabled(false),
|
||||||
fNameServers(5, true)
|
fNameServers(5, true)
|
||||||
{
|
{
|
||||||
fSocket[AF_INET] = socket(AF_INET, SOCK_DGRAM, 0);
|
// TODO : Detect supported IP protocol versions
|
||||||
fSocket[AF_INET6] = socket(AF_INET6, SOCK_DGRAM, 0);
|
memset(fProtocolVersions, 0, sizeof(fProtocolVersions));
|
||||||
|
fProtocolVersions[0] = AF_INET;
|
||||||
|
fProtocolVersions[1] = AF_INET6;
|
||||||
|
|
||||||
|
unsigned int index;
|
||||||
|
for (index = 0; index < sizeof(fProtocolVersions); index++)
|
||||||
|
{
|
||||||
|
int protocol = fProtocolVersions[index];
|
||||||
|
if (protocol > 0)
|
||||||
|
fSocket[protocol] = socket(protocol, SOCK_DGRAM, 0);
|
||||||
|
}
|
||||||
|
|
||||||
fName = name;
|
fName = name;
|
||||||
|
|
||||||
|
|
||||||
ReadConfiguration();
|
ReadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NetworkSettings::~NetworkSettings()
|
NetworkSettings::~NetworkSettings()
|
||||||
{
|
{
|
||||||
close(fSocket[AF_INET]);
|
unsigned int index;
|
||||||
close(fSocket[AF_INET6]);
|
for (index = 0; index < sizeof(fProtocolVersions); index++)
|
||||||
|
{
|
||||||
|
int protocol = fProtocolVersions[index];
|
||||||
|
if (protocol > 0)
|
||||||
|
close(fSocket[protocol]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,23 +78,22 @@ NetworkSettings::ReadConfiguration()
|
|||||||
{
|
{
|
||||||
BNetworkInterface fNetworkInterface(fName);
|
BNetworkInterface fNetworkInterface(fName);
|
||||||
|
|
||||||
// Obtain possible IPv4 and IPv6 addresses
|
unsigned int index;
|
||||||
int32 zeroAddrV4 = fNetworkInterface.FindFirstAddress(AF_INET);
|
for (index = 0; index < sizeof(fProtocolVersions); index++)
|
||||||
int32 zeroAddrV6 = fNetworkInterface.FindFirstAddress(AF_INET6);
|
{
|
||||||
|
int protocol = fProtocolVersions[index];
|
||||||
|
|
||||||
BNetworkInterfaceAddress netIntAddr4;
|
if (protocol > 0) {
|
||||||
BNetworkInterfaceAddress netIntAddr6;
|
int32 zeroAddr = fNetworkInterface.FindFirstAddress(protocol);
|
||||||
|
if (zeroAddr >= 0) {
|
||||||
if (zeroAddrV4 >= 0) {
|
fNetworkInterface.GetAddressAt(zeroAddr,
|
||||||
fNetworkInterface.GetAddressAt(zeroAddrV4, netIntAddr4);
|
fInterfaceAddressMap[protocol]);
|
||||||
fAddress[AF_INET] = netIntAddr4.Address();
|
fAddress[protocol]
|
||||||
fNetmask[AF_INET] = netIntAddr4.Mask();
|
= fInterfaceAddressMap[protocol].Address();
|
||||||
|
fNetmask[protocol]
|
||||||
|
= fInterfaceAddressMap[protocol].Mask();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zeroAddrV6 >= 0) {
|
|
||||||
fNetworkInterface.GetAddressAt(zeroAddrV6, netIntAddr6);
|
|
||||||
fAddress[AF_INET6] = netIntAddr6.Address();
|
|
||||||
fNetmask[AF_INET6] = netIntAddr6.Mask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain gateway
|
// Obtain gateway
|
||||||
@@ -206,3 +221,10 @@ NetworkSettings::ReadConfiguration()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkSettings::WriteConfiguration()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef std::map<int, BNetworkAddress> AddressMap;
|
typedef std::map<int, BNetworkAddress> AddressMap;
|
||||||
|
typedef std::map<int, BNetworkInterfaceAddress> InterfaceAddressMap;
|
||||||
typedef std::map<int, bool> BoolMap;
|
typedef std::map<int, bool> BoolMap;
|
||||||
typedef std::map<int, int> SocketMap;
|
typedef std::map<int, int> SocketMap;
|
||||||
|
|
||||||
@@ -29,6 +30,9 @@ public:
|
|||||||
NetworkSettings(const char* name);
|
NetworkSettings(const char* name);
|
||||||
virtual ~NetworkSettings();
|
virtual ~NetworkSettings();
|
||||||
|
|
||||||
|
int* ProtocolVersions()
|
||||||
|
{ return fProtocolVersions; }
|
||||||
|
|
||||||
void SetIP(int family, const char* ip)
|
void SetIP(int family, const char* ip)
|
||||||
{ fAddress[family].SetTo(ip); }
|
{ fAddress[family].SetTo(ip); }
|
||||||
void SetNetmask(int family, const char* mask)
|
void SetNetmask(int family, const char* mask)
|
||||||
@@ -69,10 +73,15 @@ public:
|
|||||||
BObjectList<BString>& NameServers() { return fNameServers; }
|
BObjectList<BString>& NameServers() { return fNameServers; }
|
||||||
|
|
||||||
void ReadConfiguration();
|
void ReadConfiguration();
|
||||||
|
void WriteConfiguration();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SocketMap fSocket;
|
SocketMap fSocket;
|
||||||
BNetworkInterface fNetworkInterface;
|
BNetworkInterface fNetworkInterface;
|
||||||
|
InterfaceAddressMap fInterfaceAddressMap;
|
||||||
|
|
||||||
|
int fProtocolVersions[3];
|
||||||
|
// OS Supported protocol versions
|
||||||
|
|
||||||
// Stored network addresses and paramaters
|
// Stored network addresses and paramaters
|
||||||
BoolMap fAutoConfigure;
|
BoolMap fAutoConfigure;
|
||||||
|
|||||||
Reference in New Issue
Block a user