Add interface disabling support.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37091 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -74,7 +74,9 @@ static const uint32 kMsgRevert = 'rvrt';
|
|||||||
static const uint32 kMsgClose = 'clse';
|
static const uint32 kMsgClose = 'clse';
|
||||||
static const uint32 kMsgField = 'fild';
|
static const uint32 kMsgField = 'fild';
|
||||||
static const uint32 kMsgInfo = 'info';
|
static const uint32 kMsgInfo = 'info';
|
||||||
static const uint32 kMsgMode = 'mode';
|
static const uint32 kMsgStaticMode = 'stcm';
|
||||||
|
static const uint32 kMsgDHCPMode = 'dynm';
|
||||||
|
static const uint32 kMsgDisabledMode = 'disa';
|
||||||
static const uint32 kMsgChange = 'chng';
|
static const uint32 kMsgChange = 'chng';
|
||||||
|
|
||||||
|
|
||||||
@@ -127,12 +129,12 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
|
|
||||||
BPopUpMenu* modeMenu = new BPopUpMenu("modes");
|
BPopUpMenu* modeMenu = new BPopUpMenu("modes");
|
||||||
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
|
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
|
||||||
new BMessage(kMsgMode)));
|
new BMessage(kMsgStaticMode)));
|
||||||
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"),
|
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"),
|
||||||
new BMessage(kMsgMode)));
|
new BMessage(kMsgDHCPMode)));
|
||||||
//modeMenu->AddSeparatorItem();
|
modeMenu->AddSeparatorItem();
|
||||||
//BMenuItem* offItem = new BMenuItem("Disabled", NULL);
|
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Disabled"),
|
||||||
//modeMenu->AddItem(offItem);
|
new BMessage(kMsgDisabledMode)));
|
||||||
|
|
||||||
fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu);
|
fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu);
|
||||||
layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0);
|
layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0);
|
||||||
@@ -320,15 +322,19 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
|||||||
fGatewayTextControl->SetText(settings->Gateway());
|
fGatewayTextControl->SetText(settings->Gateway());
|
||||||
fNetMaskTextControl->SetText(settings->Netmask());
|
fNetMaskTextControl->SetText(settings->Netmask());
|
||||||
|
|
||||||
if (settings->AutoConfigure() == true)
|
enableControls = false;
|
||||||
|
|
||||||
|
if (settings->IsDisabled())
|
||||||
|
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Disabled"));
|
||||||
|
else if (settings->AutoConfigure() == true)
|
||||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP"));
|
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("DHCP"));
|
||||||
else
|
else {
|
||||||
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static"));
|
item = fTypeMenuField->Menu()->FindItem(B_TRANSLATE("Static"));
|
||||||
|
enableControls = true;
|
||||||
|
}
|
||||||
if (item)
|
if (item)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
enableControls = settings->AutoConfigure() == false;
|
|
||||||
|
|
||||||
if (settings->NameServers().CountItems() >= 2) {
|
if (settings->NameServers().CountItems() >= 2) {
|
||||||
fSecondaryDNSTextControl->SetText(
|
fSecondaryDNSTextControl->SetText(
|
||||||
settings->NameServers().ItemAt(1)->String());
|
settings->NameServers().ItemAt(1)->String());
|
||||||
@@ -371,6 +377,10 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
|
|||||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
||||||
B_TRANSLATE("DHCP")) == 0);
|
B_TRANSLATE("DHCP")) == 0);
|
||||||
|
|
||||||
|
fCurrentSettings->SetDisabled(
|
||||||
|
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
||||||
|
B_TRANSLATE("Disabled")) == 0);
|
||||||
|
|
||||||
fCurrentSettings->NameServers().MakeEmpty();
|
fCurrentSettings->NameServers().MakeEmpty();
|
||||||
fCurrentSettings->NameServers().AddItem(new BString(
|
fCurrentSettings->NameServers().AddItem(new BString(
|
||||||
fPrimaryDNSTextControl->Text()));
|
fPrimaryDNSTextControl->Text()));
|
||||||
@@ -444,7 +454,9 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
|||||||
// loop over all adapters. open the settings file only once,
|
// loop over all adapters. open the settings file only once,
|
||||||
// append the settins of each non-autoconfiguring adapter
|
// append the settins of each non-autoconfiguring adapter
|
||||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||||
if (fSettings.ItemAt(i)->AutoConfigure())
|
Settings* settings = fSettings.ItemAt(i);
|
||||||
|
|
||||||
|
if (settings->AutoConfigure())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
@@ -456,16 +468,20 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "interface %s {\n\t\taddress {\n",
|
fprintf(fp, "interface %s {\n",
|
||||||
fSettings.ItemAt(i)->Name());
|
settings->Name());
|
||||||
fprintf(fp, "\t\t\tfamily\tinet\n");
|
|
||||||
fprintf(fp, "\t\t\taddress\t%s\n",
|
if (settings->IsDisabled())
|
||||||
fSettings.ItemAt(i)->IP());
|
fprintf(fp, "\tdisabled\ttrue\n");
|
||||||
fprintf(fp, "\t\t\tgateway\t%s\n",
|
else {
|
||||||
fSettings.ItemAt(i)->Gateway());
|
fprintf(fp, "\taddress {\n");
|
||||||
fprintf(fp, "\t\t\tmask\t%s\n",
|
fprintf(fp, "\t\tfamily\tinet\n");
|
||||||
fSettings.ItemAt(i)->Netmask());
|
fprintf(fp, "\t\taddress\t%s\n", settings->IP());
|
||||||
fprintf(fp, "\t\t}\n}\n\n");
|
fprintf(fp, "\t\tgateway\t%s\n", settings->Gateway());
|
||||||
|
fprintf(fp, "\t\tmask\t%s\n", settings->Netmask());
|
||||||
|
fprintf(fp, "\t}\n");
|
||||||
|
}
|
||||||
|
fprintf(fp, "}\n\n");
|
||||||
}
|
}
|
||||||
if (fp) {
|
if (fp) {
|
||||||
printf("%s saved.\n", path.Path());
|
printf("%s saved.\n", path.Path());
|
||||||
@@ -565,10 +581,10 @@ void
|
|||||||
EthernetSettingsView::MessageReceived(BMessage* message)
|
EthernetSettingsView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgMode:
|
case kMsgStaticMode:
|
||||||
if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked())
|
case kMsgDHCPMode:
|
||||||
_EnableTextControls(strcmp(item->Label(),
|
case kMsgDisabledMode:
|
||||||
B_TRANSLATE("DHCP")) != 0);
|
_EnableTextControls(message->what == kMsgStaticMode);
|
||||||
fApplyButton->SetEnabled(true);
|
fApplyButton->SetEnabled(true);
|
||||||
fRevertButton->SetEnabled(true);
|
fRevertButton->SetEnabled(true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
Settings::Settings(const char* name)
|
Settings::Settings(const char* name)
|
||||||
:
|
:
|
||||||
fAuto(true),
|
fAuto(true),
|
||||||
|
fDisabled(false),
|
||||||
fNameServers(5, true)
|
fNameServers(5, true)
|
||||||
{
|
{
|
||||||
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public:
|
|||||||
void SetDomain(BString domain) { fDomain = domain; }
|
void SetDomain(BString domain) { fDomain = domain; }
|
||||||
void SetAutoConfigure(bool autoConfigure)
|
void SetAutoConfigure(bool autoConfigure)
|
||||||
{ fAuto = autoConfigure; }
|
{ fAuto = autoConfigure; }
|
||||||
|
void SetDisabled(bool disabled)
|
||||||
|
{ fDisabled = disabled; }
|
||||||
|
|
||||||
const char* IP() { return fIP.String(); }
|
const char* IP() { return fIP.String(); }
|
||||||
const char* Gateway() { return fGateway.String(); }
|
const char* Gateway() { return fGateway.String(); }
|
||||||
@@ -32,6 +34,7 @@ public:
|
|||||||
const char* Name() { return fName.String(); }
|
const char* Name() { return fName.String(); }
|
||||||
const char* Domain() { return fDomain.String(); }
|
const char* Domain() { return fDomain.String(); }
|
||||||
bool AutoConfigure() { return fAuto; }
|
bool AutoConfigure() { return fAuto; }
|
||||||
|
bool IsDisabled() { return fDisabled; }
|
||||||
|
|
||||||
BObjectList<BString>& NameServers() { return fNameServers; }
|
BObjectList<BString>& NameServers() { return fNameServers; }
|
||||||
|
|
||||||
@@ -47,6 +50,7 @@ private:
|
|||||||
BString fDomain;
|
BString fDomain;
|
||||||
int fSocket;
|
int fSocket;
|
||||||
bool fAuto;
|
bool fAuto;
|
||||||
|
bool fDisabled;
|
||||||
BObjectList<BString> fNameServers;
|
BObjectList<BString> fNameServers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool _IsValidInterface(int socket, const char* name);
|
bool _IsValidInterface(int socket, const char* name);
|
||||||
void _RemoveInvalidInterfaces(int socket);
|
void _RemoveInvalidInterfaces(int socket);
|
||||||
|
status_t _RemoveInterface(int socket, const char* name);
|
||||||
|
status_t _DisableInterface(int socket, const char* name);
|
||||||
bool _TestForInterface(int socket, const char* name);
|
bool _TestForInterface(int socket, const char* name);
|
||||||
status_t _ConfigureInterface(int socket,
|
status_t _ConfigureInterface(int socket,
|
||||||
BMessage& interface,
|
BMessage& interface,
|
||||||
@@ -461,14 +463,7 @@ NetServer::_RemoveInvalidInterfaces(int socket)
|
|||||||
for (uint32 i = 0; i < count; i++) {
|
for (uint32 i = 0; i < count; i++) {
|
||||||
if (!_IsValidInterface(socket, interface->ifr_name)) {
|
if (!_IsValidInterface(socket, interface->ifr_name)) {
|
||||||
// remove invalid interface
|
// remove invalid interface
|
||||||
ifreq request;
|
_RemoveInterface(socket, interface->ifr_name);
|
||||||
if (!prepare_request(request, interface->ifr_name))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (ioctl(socket, SIOCDIFADDR, &request, sizeof(request)) < 0) {
|
|
||||||
fprintf(stderr, "%s: Could not delete interface %s: %s\n",
|
|
||||||
Name(), interface->ifr_name, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
|
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
|
||||||
@@ -527,6 +522,50 @@ NetServer::_TestForInterface(int socket, const char* name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
NetServer::_RemoveInterface(int socket, const char* name)
|
||||||
|
{
|
||||||
|
ifreq request;
|
||||||
|
if (!prepare_request(request, name))
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
if (ioctl(socket, SIOCDIFADDR, &request, sizeof(request)) < 0) {
|
||||||
|
fprintf(stderr, "%s: Could not delete interface %s: %s\n",
|
||||||
|
Name(), name, strerror(errno));
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
NetServer::_DisableInterface(int socket, const char* name)
|
||||||
|
{
|
||||||
|
ifreq request;
|
||||||
|
if (!prepare_request(request, name))
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
if (ioctl(socket, SIOCGIFFLAGS, &request, sizeof(struct ifreq)) < 0) {
|
||||||
|
fprintf(stderr, "%s: Getting flags failed: %s\n", Name(),
|
||||||
|
strerror(errno));
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
// Set interface down
|
||||||
|
request.ifr_flags &= ~(IFF_UP | IFF_AUTO_CONFIGURED | IFF_CONFIGURING);
|
||||||
|
|
||||||
|
if (ioctl(socket, SIOCSIFFLAGS, &request, sizeof(struct ifreq)) < 0) {
|
||||||
|
fprintf(stderr, "%s: Setting flags failed: %s\n", Name(),
|
||||||
|
strerror(errno));
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "%s: set %s interface down...\n", Name(), name);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
NetServer::_ConfigureInterface(int socket, BMessage& interface,
|
NetServer::_ConfigureInterface(int socket, BMessage& interface,
|
||||||
bool fromMessage)
|
bool fromMessage)
|
||||||
@@ -823,7 +862,6 @@ NetServer::_ConfigureDevices(int socket, const char* startPath,
|
|||||||
struct stat stat;
|
struct stat stat;
|
||||||
BPath path;
|
BPath path;
|
||||||
if (entry.GetName(name) != B_OK
|
if (entry.GetName(name) != B_OK
|
||||||
|| !strcmp(name, "stack")
|
|
||||||
|| entry.GetPath(&path) != B_OK
|
|| entry.GetPath(&path) != B_OK
|
||||||
|| entry.GetStat(&stat) != B_OK)
|
|| entry.GetStat(&stat) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
@@ -853,6 +891,13 @@ NetServer::_ConfigureInterfaces(int socket, BMessage* _missingDevice)
|
|||||||
if (interface.FindString("device", &device) != B_OK)
|
if (interface.FindString("device", &device) != B_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
bool disabled = false;
|
||||||
|
if (interface.FindBool("disabled", &disabled) == B_OK && disabled) {
|
||||||
|
// disabled by user request
|
||||||
|
_DisableInterface(socket, device);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strncmp(device, "/dev/net/", 9)) {
|
if (!strncmp(device, "/dev/net/", 9)) {
|
||||||
// it's a kernel device, check if it's present
|
// it's a kernel device, check if it's present
|
||||||
BEntry entry(device);
|
BEntry entry(device);
|
||||||
@@ -943,16 +988,8 @@ NetServer::_HandleDeviceMonitor(int socket, BMessage* message)
|
|||||||
|
|
||||||
if (opcode == B_ENTRY_CREATED)
|
if (opcode == B_ENTRY_CREATED)
|
||||||
_ConfigureDevice(socket, path);
|
_ConfigureDevice(socket, path);
|
||||||
else {
|
else
|
||||||
ifreq request;
|
_RemoveInterface(socket, path);
|
||||||
if (!prepare_request(request, path))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ioctl(socket, SIOCDIFADDR, &request, sizeof(request)) < 0) {
|
|
||||||
fprintf(stderr, "%s: Could not delete interface %s: %s\n",
|
|
||||||
Name(), path, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ const static settings_template kInterfaceAddressTemplate[] = {
|
|||||||
|
|
||||||
const static settings_template kInterfaceTemplate[] = {
|
const static settings_template kInterfaceTemplate[] = {
|
||||||
{B_STRING_TYPE, "device", NULL, true},
|
{B_STRING_TYPE, "device", NULL, true},
|
||||||
|
{B_BOOL_TYPE, "disabled", NULL},
|
||||||
{B_MESSAGE_TYPE, "address", kInterfaceAddressTemplate},
|
{B_MESSAGE_TYPE, "address", kInterfaceAddressTemplate},
|
||||||
{B_INT32_TYPE, "flags", NULL},
|
{B_INT32_TYPE, "flags", NULL},
|
||||||
{B_INT32_TYPE, "metric", NULL},
|
{B_INT32_TYPE, "metric", NULL},
|
||||||
|
|||||||
Reference in New Issue
Block a user