* Applied patch by Vegard that moves the resolver configuration to where it
belongs (with a few changes by myself). Thanks! * This closes ticket #5636. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36135 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -11,10 +11,8 @@
|
|||||||
#include "DHCPClient.h"
|
#include "DHCPClient.h"
|
||||||
#include "NetServer.h"
|
#include "NetServer.h"
|
||||||
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <MessageRunner.h>
|
#include <MessageRunner.h>
|
||||||
#include <Path.h>
|
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -336,6 +334,7 @@ dhcp_message::FinishOptions(uint8* options)
|
|||||||
DHCPClient::DHCPClient(BMessenger target, const char* device)
|
DHCPClient::DHCPClient(BMessenger target, const char* device)
|
||||||
: AutoconfigClient("dhcp", target, device),
|
: AutoconfigClient("dhcp", target, device),
|
||||||
fConfiguration(kMsgConfigureInterface),
|
fConfiguration(kMsgConfigureInterface),
|
||||||
|
fResolverConfiguration(kMsgConfigureResolver),
|
||||||
fRunner(NULL),
|
fRunner(NULL),
|
||||||
fLeaseTime(0)
|
fLeaseTime(0)
|
||||||
{
|
{
|
||||||
@@ -519,7 +518,8 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
BMessage address;
|
BMessage address;
|
||||||
address.AddString("family", "inet");
|
address.AddString("family", "inet");
|
||||||
address.AddString("address", _ToString(fAssignedAddress));
|
address.AddString("address", _ToString(fAssignedAddress));
|
||||||
_ParseOptions(*message, address);
|
fResolverConfiguration.MakeEmpty();
|
||||||
|
_ParseOptions(*message, address, fResolverConfiguration);
|
||||||
|
|
||||||
fConfiguration.AddMessage("address", &address);
|
fConfiguration.AddMessage("address", &address);
|
||||||
|
|
||||||
@@ -543,7 +543,8 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
|
|
||||||
// TODO: we might want to configure the stuff, don't we?
|
// TODO: we might want to configure the stuff, don't we?
|
||||||
BMessage address;
|
BMessage address;
|
||||||
_ParseOptions(*message, address);
|
fResolverConfiguration.MakeEmpty();
|
||||||
|
_ParseOptions(*message, address, fResolverConfiguration);
|
||||||
// TODO: currently, only lease time and DNS is updated this way
|
// TODO: currently, only lease time and DNS is updated this way
|
||||||
|
|
||||||
// our address request has been acknowledged
|
// our address request has been acknowledged
|
||||||
@@ -552,6 +553,12 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
// configure interface
|
// configure interface
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status = Target().SendMessage(&fConfiguration, &reply);
|
status = Target().SendMessage(&fConfiguration, &reply);
|
||||||
|
if (status == B_OK)
|
||||||
|
status = reply.FindInt32("status", &fStatus);
|
||||||
|
|
||||||
|
// configure resolver
|
||||||
|
reply.MakeEmpty();
|
||||||
|
status = Target().SendMessage(&fResolverConfiguration, &reply);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = reply.FindInt32("status", &fStatus);
|
status = reply.FindInt32("status", &fStatus);
|
||||||
break;
|
break;
|
||||||
@@ -609,20 +616,13 @@ DHCPClient::_RestartLease(bigtime_t leaseTime)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
|
DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address,
|
||||||
|
BMessage& resolverConfiguration)
|
||||||
{
|
{
|
||||||
dhcp_option_cookie cookie;
|
dhcp_option_cookie cookie;
|
||||||
message_option option;
|
message_option option;
|
||||||
const uint8* data;
|
const uint8* data;
|
||||||
size_t size;
|
size_t size;
|
||||||
// TODO: resolv.conf should be parsed, all information should be
|
|
||||||
// maintained and it should be distinguished between user entered
|
|
||||||
// and auto-generated parts of the file, with this method only re-writing
|
|
||||||
// the auto-generated parts of course.
|
|
||||||
// TODO: We write resolv.conf once per _ParseOptions invokation, there
|
|
||||||
// is the first DHCP_OFFER message and the final DHCP_ACK message
|
|
||||||
// from the same server, which should contain all the final data.
|
|
||||||
bool resolvConfCreated = false;
|
|
||||||
while (message.NextOption(cookie, option, data, size)) {
|
while (message.NextOption(cookie, option, data, size)) {
|
||||||
// iterate through all options
|
// iterate through all options
|
||||||
switch (option) {
|
switch (option) {
|
||||||
@@ -637,24 +637,14 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
|
|||||||
break;
|
break;
|
||||||
case OPTION_DOMAIN_NAME_SERVER:
|
case OPTION_DOMAIN_NAME_SERVER:
|
||||||
{
|
{
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK
|
|
||||||
|| path.Append("network/resolv.conf") != B_OK) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* openMode = resolvConfCreated ? "a" : "w";
|
|
||||||
FILE* file = fopen(path.Path(), openMode);
|
|
||||||
for (uint32 i = 0; i < size / 4; i++) {
|
for (uint32 i = 0; i < size / 4; i++) {
|
||||||
syslog(LOG_INFO, "DNS: %s\n",
|
syslog(LOG_INFO, "DNS: %s\n",
|
||||||
_ToString(&data[i * 4]).String());
|
_ToString(&data[i * 4]).String());
|
||||||
if (file != NULL) {
|
resolverConfiguration.AddString("nameserver",
|
||||||
resolvConfCreated = true;
|
_ToString(&data[i * 4]).String());
|
||||||
fprintf(file, "nameserver %s\n",
|
|
||||||
_ToString(&data[i * 4]).String());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fclose(file);
|
resolverConfiguration.AddInt32("nameserver_count",
|
||||||
|
size / 4);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OPTION_SERVER_ADDRESS:
|
case OPTION_SERVER_ADDRESS:
|
||||||
@@ -678,29 +668,19 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTION_HOST_NAME:
|
case OPTION_HOST_NAME:
|
||||||
syslog(LOG_INFO, "DHCP host name: \"%.*s\"\n",
|
syslog(LOG_INFO, "DHCP host name: \"%.*s\"\n", (int)size,
|
||||||
(int)size, (const char*)data);
|
(const char*)data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTION_DOMAIN_NAME:
|
case OPTION_DOMAIN_NAME:
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "DHCP domain name: \"%.*s\"\n",
|
char domain[256];
|
||||||
(int)size, (const char*)data);
|
strlcpy(domain, (const char*)data,
|
||||||
|
min_c(size + 1, sizeof(domain)));
|
||||||
|
|
||||||
BPath path;
|
syslog(LOG_INFO, "DHCP domain name: \"%s\"\n", domain);
|
||||||
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK
|
|
||||||
|| path.Append("network/resolv.conf") != B_OK) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* openMode = resolvConfCreated ? "a" : "w";
|
resolverConfiguration.AddString("domain", domain);
|
||||||
FILE* file = fopen(path.Path(), openMode);
|
|
||||||
if (file != NULL) {
|
|
||||||
resolvConfCreated = true;
|
|
||||||
fprintf(file, "domain %.*s\n", (int)size,
|
|
||||||
(const char*)data);
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
status_t _Negotiate(dhcp_state state);
|
status_t _Negotiate(dhcp_state state);
|
||||||
void _ParseOptions(dhcp_message& message,
|
void _ParseOptions(dhcp_message& message,
|
||||||
BMessage& address);
|
BMessage& address,
|
||||||
|
BMessage& resolverConfiguration);
|
||||||
void _PrepareMessage(dhcp_message& message,
|
void _PrepareMessage(dhcp_message& message,
|
||||||
dhcp_state state);
|
dhcp_state state);
|
||||||
status_t _SendMessage(int socket, dhcp_message& message,
|
status_t _SendMessage(int socket, dhcp_message& message,
|
||||||
@@ -55,6 +56,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BMessage fConfiguration;
|
BMessage fConfiguration;
|
||||||
|
BMessage fResolverConfiguration;
|
||||||
BMessageRunner* fRunner;
|
BMessageRunner* fRunner;
|
||||||
uint8 fMAC[6];
|
uint8 fMAC[6];
|
||||||
uint32 fTransactionID;
|
uint32 fTransactionID;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Axel Dörfler, [email protected]
|
* Axel Dörfler, [email protected]
|
||||||
|
* Vegard Wærp, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <Server.h>
|
#include <Server.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
|
||||||
#include "AutoconfigLooper.h"
|
#include "AutoconfigLooper.h"
|
||||||
#include "Services.h"
|
#include "Services.h"
|
||||||
@@ -57,6 +59,7 @@ class NetServer : public BServer {
|
|||||||
bool _TestForInterface(int socket, const char* name);
|
bool _TestForInterface(int socket, const char* name);
|
||||||
status_t _ConfigureInterface(int socket, BMessage& interface,
|
status_t _ConfigureInterface(int socket, BMessage& interface,
|
||||||
bool fromMessage = false);
|
bool fromMessage = false);
|
||||||
|
status_t _ConfigureResolver(BMessage& resolverConfiguration);
|
||||||
bool _QuitLooperForDevice(const char* device);
|
bool _QuitLooperForDevice(const char* device);
|
||||||
AutoconfigLooper* _LooperForDevice(const char* device);
|
AutoconfigLooper* _LooperForDevice(const char* device);
|
||||||
status_t _ConfigureDevice(int socket, const char* path);
|
status_t _ConfigureDevice(int socket, const char* path);
|
||||||
@@ -300,6 +303,7 @@ NetServer::MessageReceived(BMessage* message)
|
|||||||
close(socket);
|
close(socket);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kMsgInterfaceSettingsUpdated:
|
case kMsgInterfaceSettingsUpdated:
|
||||||
{
|
{
|
||||||
// we need a socket to talk to the networking stack
|
// we need a socket to talk to the networking stack
|
||||||
@@ -345,6 +349,16 @@ NetServer::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case kMsgConfigureResolver:
|
||||||
|
{
|
||||||
|
status_t status = _ConfigureResolver(*message);
|
||||||
|
|
||||||
|
BMessage reply(B_REPLY);
|
||||||
|
reply.AddInt32("status", status);
|
||||||
|
message->SendReply(&reply);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(message);
|
BApplication::MessageReceived(message);
|
||||||
return;
|
return;
|
||||||
@@ -720,6 +734,37 @@ NetServer::_ConfigureInterface(int socket, BMessage& interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
NetServer::_ConfigureResolver(BMessage& resolverConfiguration)
|
||||||
|
{
|
||||||
|
// TODO: resolv.conf should be parsed, all information should be
|
||||||
|
// maintained and it should be distinguished between user entered
|
||||||
|
// and auto-generated parts of the file, with this method only re-writing
|
||||||
|
// the auto-generated parts of course.
|
||||||
|
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK
|
||||||
|
|| path.Append("network/resolv.conf") != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
FILE* file = fopen(path.Path(), "w");
|
||||||
|
if (file != NULL) {
|
||||||
|
const char* nameserver;
|
||||||
|
for (int32 i = 0; resolverConfiguration.FindString("nameserver", i,
|
||||||
|
&nameserver) == B_OK; i++) {
|
||||||
|
fprintf(file, "nameserver %s\n", nameserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* domain;
|
||||||
|
if (resolverConfiguration.FindString("domain", &domain) == B_OK)
|
||||||
|
fprintf(file, "domain %s\n", domain);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
NetServer::_QuitLooperForDevice(const char* device)
|
NetServer::_QuitLooperForDevice(const char* device)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -15,9 +15,10 @@
|
|||||||
|
|
||||||
|
|
||||||
// NOTE: this header is used by other applications (such as ifconfig,
|
// NOTE: this header is used by other applications (such as ifconfig,
|
||||||
// and Network) because of these two defines
|
// and Network) because of these three defines
|
||||||
#define kNetServerSignature "application/x-vnd.haiku-net_server"
|
#define kNetServerSignature "application/x-vnd.haiku-net_server"
|
||||||
#define kMsgConfigureInterface 'COif'
|
#define kMsgConfigureInterface 'COif'
|
||||||
|
#define kMsgConfigureResolver 'COrs'
|
||||||
|
|
||||||
|
|
||||||
extern bool get_family_index(const char* name, int32& familyIndex);
|
extern bool get_family_index(const char* name, int32& familyIndex);
|
||||||
|
|||||||
Reference in New Issue
Block a user