Revert files that were commit by mistake in previous commit. Sorry.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41279 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -58,19 +58,21 @@ AutoconfigLooper::_RemoveClient()
|
|||||||
void
|
void
|
||||||
AutoconfigLooper::_Configure()
|
AutoconfigLooper::_Configure()
|
||||||
{
|
{
|
||||||
// start with DHCP
|
|
||||||
|
|
||||||
if (fCurrentClient == NULL) {
|
|
||||||
fCurrentClient = new DHCPClient(fTarget, fDevice.String());
|
|
||||||
AddHandler(fCurrentClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set IFF_CONFIGURING flag on interface
|
// set IFF_CONFIGURING flag on interface
|
||||||
|
|
||||||
BNetworkInterface interface(fDevice.String());
|
BNetworkInterface interface(fDevice.String());
|
||||||
int32 flags = interface.Flags() & ~IFF_AUTO_CONFIGURED;
|
int32 flags = interface.Flags() & ~IFF_AUTO_CONFIGURED;
|
||||||
interface.SetFlags(flags | IFF_CONFIGURING);
|
interface.SetFlags(flags | IFF_CONFIGURING);
|
||||||
|
|
||||||
|
// remove current handler
|
||||||
|
|
||||||
|
_RemoveClient();
|
||||||
|
|
||||||
|
// start with DHCP
|
||||||
|
|
||||||
|
fCurrentClient = new DHCPClient(fTarget, fDevice.String());
|
||||||
|
AddHandler(fCurrentClient);
|
||||||
|
|
||||||
if (fCurrentClient->Initialize() == B_OK)
|
if (fCurrentClient->Initialize() == B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -89,7 +91,7 @@ AutoconfigLooper::_Configure()
|
|||||||
|
|
||||||
BMessage message(kMsgConfigureInterface);
|
BMessage message(kMsgConfigureInterface);
|
||||||
message.AddString("device", fDevice.String());
|
message.AddString("device", fDevice.String());
|
||||||
message.AddBool("auto_configured", true);
|
message.AddBool("auto", true);
|
||||||
|
|
||||||
BNetworkAddress link;
|
BNetworkAddress link;
|
||||||
uint8 last = 56;
|
uint8 last = 56;
|
||||||
|
|||||||
@@ -422,7 +422,6 @@ DHCPClient::DHCPClient(BMessenger target, const char* device)
|
|||||||
fConfiguration(kMsgConfigureInterface),
|
fConfiguration(kMsgConfigureInterface),
|
||||||
fResolverConfiguration(kMsgConfigureResolver),
|
fResolverConfiguration(kMsgConfigureResolver),
|
||||||
fRunner(NULL),
|
fRunner(NULL),
|
||||||
fAssignedAddress(0),
|
|
||||||
fServer(AF_INET, NULL, DHCP_SERVER_PORT),
|
fServer(AF_INET, NULL, DHCP_SERVER_PORT),
|
||||||
fLeaseTime(0)
|
fLeaseTime(0)
|
||||||
{
|
{
|
||||||
@@ -437,18 +436,6 @@ DHCPClient::DHCPClient(BMessenger target, const char* device)
|
|||||||
|
|
||||||
memcpy(fMAC, link.LinkLevelAddress(), sizeof(fMAC));
|
memcpy(fMAC, link.LinkLevelAddress(), sizeof(fMAC));
|
||||||
|
|
||||||
if ((interface.Flags() & IFF_AUTO_CONFIGURED) != 0) {
|
|
||||||
// Check for interface previous auto-configured address, if any.
|
|
||||||
BNetworkInterfaceAddress interfaceAddress;
|
|
||||||
int index = interface.FindFirstAddress(AF_INET);
|
|
||||||
if (index >= 0
|
|
||||||
&& interface.GetAddressAt(index, interfaceAddress) == B_OK) {
|
|
||||||
BNetworkAddress address = interfaceAddress.Address();
|
|
||||||
const sockaddr_in& addr = (sockaddr_in&)address.SockAddr();
|
|
||||||
fAssignedAddress = addr.sin_addr.s_addr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
openlog_thread("DHCP", 0, LOG_DAEMON);
|
openlog_thread("DHCP", 0, LOG_DAEMON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,8 +466,8 @@ DHCPClient::~DHCPClient()
|
|||||||
status_t
|
status_t
|
||||||
DHCPClient::Initialize()
|
DHCPClient::Initialize()
|
||||||
{
|
{
|
||||||
fStatus = _Negotiate(fAssignedAddress == 0 ? INIT : INIT_REBOOT);
|
fStatus = _Negotiate(INIT);
|
||||||
syslog(LOG_DEBUG, "%s: DHCP status = %s\n", Device(), strerror(fStatus));
|
syslog(LOG_DEBUG, "DHCP for %s, status: %s\n", Device(), strerror(fStatus));
|
||||||
return fStatus;
|
return fStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,15 +527,13 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
|
|
||||||
// send discover/request message
|
// send discover/request message
|
||||||
_SendMessage(socket, state == INIT ? discover : request,
|
_SendMessage(socket, state == INIT ? discover : request,
|
||||||
state != RENEWING ? broadcast : fServer);
|
state != RENEWAL ? broadcast : fServer);
|
||||||
// no need to check the status; in case of an error we'll just send
|
// no need to check the status; in case of an error we'll just send
|
||||||
// the message again
|
// the message again
|
||||||
|
|
||||||
// receive loop until we've got an offer and acknowledged it
|
// receive loop until we've got an offer and acknowledged it
|
||||||
|
|
||||||
while (state != BOUND) {
|
while (state != ACKNOWLEDGED) {
|
||||||
printf("DHCPClient::_Negotiate(%d)\n", (int)state);
|
|
||||||
|
|
||||||
char buffer[2048];
|
char buffer[2048];
|
||||||
struct sockaddr_in from;
|
struct sockaddr_in from;
|
||||||
socklen_t fromLength = sizeof(from);
|
socklen_t fromLength = sizeof(from);
|
||||||
@@ -561,8 +546,12 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
return B_TIMED_OUT;
|
return B_TIMED_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
_SendMessage(socket, state == INIT ? discover : request,
|
if (state == INIT)
|
||||||
state != RENEWING ? broadcast : fServer);
|
_SendMessage(socket, discover, broadcast);
|
||||||
|
else {
|
||||||
|
_SendMessage(socket, request,
|
||||||
|
state != RENEWAL ? broadcast : fServer);
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else if (bytesReceived < 0)
|
} else if (bytesReceived < 0)
|
||||||
@@ -577,15 +566,9 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance from startup state
|
syslog(LOG_DEBUG, "Received %s from %s for %s\n",
|
||||||
if (state == INIT)
|
dhcp_message::TypeToString(message->Type()),
|
||||||
state = SELECTING;
|
_AddressToString(from.sin_addr.s_addr).String(), Device());
|
||||||
else if (state == INIT_REBOOT)
|
|
||||||
state = REBOOTING;
|
|
||||||
|
|
||||||
syslog(LOG_DEBUG, "%s: Received %s from %s\n",
|
|
||||||
Device(), dhcp_message::TypeToString(message->Type()),
|
|
||||||
_AddressToString(from.sin_addr.s_addr).String());
|
|
||||||
|
|
||||||
switch (message->Type()) {
|
switch (message->Type()) {
|
||||||
case DHCP_NONE:
|
case DHCP_NONE:
|
||||||
@@ -596,7 +579,7 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
case DHCP_OFFER:
|
case DHCP_OFFER:
|
||||||
{
|
{
|
||||||
// first offer wins
|
// first offer wins
|
||||||
if (state != SELECTING)
|
if (state != INIT)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// collect interface options
|
// collect interface options
|
||||||
@@ -607,7 +590,7 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
|
|
||||||
fConfiguration.MakeEmpty();
|
fConfiguration.MakeEmpty();
|
||||||
fConfiguration.AddString("device", Device());
|
fConfiguration.AddString("device", Device());
|
||||||
fConfiguration.AddBool("auto_configured", true);
|
fConfiguration.AddBool("auto", true);
|
||||||
|
|
||||||
BMessage address;
|
BMessage address;
|
||||||
address.AddString("family", "inet");
|
address.AddString("family", "inet");
|
||||||
@@ -631,10 +614,8 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
|
|
||||||
case DHCP_ACK:
|
case DHCP_ACK:
|
||||||
{
|
{
|
||||||
if (state != REQUESTING
|
if (state != REQUESTING && state != REBINDING
|
||||||
&& state != REBOOTING
|
&& state != RENEWAL)
|
||||||
&& state != REBINDING
|
|
||||||
&& state != RENEWING)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO: we might want to configure the stuff, don't we?
|
// TODO: we might want to configure the stuff, don't we?
|
||||||
@@ -645,7 +626,7 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
// way
|
// way
|
||||||
|
|
||||||
// our address request has been acknowledged
|
// our address request has been acknowledged
|
||||||
state = BOUND;
|
state = ACKNOWLEDGED;
|
||||||
|
|
||||||
// configure interface
|
// configure interface
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
@@ -663,18 +644,9 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case DHCP_NACK:
|
case DHCP_NACK:
|
||||||
if (state != REQUESTING
|
if (state != REQUESTING)
|
||||||
&& state != REBOOTING
|
|
||||||
&& state != REBINDING
|
|
||||||
&& state != RENEWING)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (state == REBOOTING) {
|
|
||||||
// server reject our request on previous assigned address
|
|
||||||
// back to square one...
|
|
||||||
fAssignedAddress = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// try again (maybe we should prefer other servers if this
|
// try again (maybe we should prefer other servers if this
|
||||||
// happens more than once)
|
// happens more than once)
|
||||||
status = _SendMessage(socket, discover, broadcast);
|
status = _SendMessage(socket, discover, broadcast);
|
||||||
@@ -847,8 +819,7 @@ DHCPClient::_PrepareMessage(dhcp_message& message, dhcp_state state)
|
|||||||
(uint32)server.sin_addr.s_addr);
|
(uint32)server.sin_addr.s_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == INIT || state == INIT_REBOOT
|
if (state == INIT || state == REQUESTING) {
|
||||||
|| state == REQUESTING) {
|
|
||||||
next = message.PutOption(next, OPTION_REQUEST_IP_ADDRESS,
|
next = message.PutOption(next, OPTION_REQUEST_IP_ADDRESS,
|
||||||
(uint32)fAssignedAddress);
|
(uint32)fAssignedAddress);
|
||||||
} else
|
} else
|
||||||
@@ -895,7 +866,7 @@ DHCPClient::_TimeoutShift(int socket, time_t& timeout, uint32& tries)
|
|||||||
if (++tries > 2)
|
if (++tries > 2)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
syslog(LOG_DEBUG, "%s: Timeout shift: %lu secs (try %lu)\n",
|
syslog(LOG_DEBUG, "Timeout shift for %s: %lu secs (try %lu)\n",
|
||||||
Device(), timeout, tries);
|
Device(), timeout, tries);
|
||||||
|
|
||||||
struct timeval value;
|
struct timeval value;
|
||||||
@@ -927,16 +898,9 @@ status_t
|
|||||||
DHCPClient::_SendMessage(int socket, dhcp_message& message,
|
DHCPClient::_SendMessage(int socket, dhcp_message& message,
|
||||||
const BNetworkAddress& address) const
|
const BNetworkAddress& address) const
|
||||||
{
|
{
|
||||||
message_type type = message.Type();
|
syslog(LOG_DEBUG, "Send %s to %s on %s\n",
|
||||||
BString text;
|
dhcp_message::TypeToString(message.Type()),
|
||||||
text << dhcp_message::TypeToString(type);
|
address.ToString().String(), Device());
|
||||||
|
|
||||||
const uint8* requestAddress = message.FindOption(OPTION_REQUEST_IP_ADDRESS);
|
|
||||||
if (type == DHCP_REQUEST && requestAddress != NULL)
|
|
||||||
text << " for " << _AddressToString(requestAddress).String();
|
|
||||||
|
|
||||||
syslog(LOG_DEBUG, "%s: Send %s to %s\n", Device(), text.String(),
|
|
||||||
address.ToString().String());
|
|
||||||
|
|
||||||
ssize_t bytesSent = sendto(socket, &message, message.Size(),
|
ssize_t bytesSent = sendto(socket, &message, message.Size(),
|
||||||
address.IsBroadcast() ? MSG_BCAST : 0, address, address.Length());
|
address.IsBroadcast() ? MSG_BCAST : 0, address, address.Length());
|
||||||
@@ -957,7 +921,7 @@ DHCPClient::_CurrentState() const
|
|||||||
if (now >= fRebindingTime)
|
if (now >= fRebindingTime)
|
||||||
return REBINDING;
|
return REBINDING;
|
||||||
if (now >= fRenewalTime)
|
if (now >= fRenewalTime)
|
||||||
return RENEWING;
|
return RENEWAL;
|
||||||
|
|
||||||
return BOUND;
|
return BOUND;
|
||||||
}
|
}
|
||||||
@@ -974,7 +938,7 @@ DHCPClient::MessageReceived(BMessage* message)
|
|||||||
bigtime_t next;
|
bigtime_t next;
|
||||||
if (_Negotiate(state) == B_OK) {
|
if (_Negotiate(state) == B_OK) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case RENEWING:
|
case RENEWAL:
|
||||||
next = fRebindingTime;
|
next = fRebindingTime;
|
||||||
break;
|
break;
|
||||||
case REBINDING:
|
case REBINDING:
|
||||||
@@ -984,7 +948,7 @@ DHCPClient::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case RENEWING:
|
case RENEWAL:
|
||||||
next = (fLeaseTime - fRebindingTime) / 4 + system_time();
|
next = (fLeaseTime - fRebindingTime) / 4 + system_time();
|
||||||
break;
|
break;
|
||||||
case REBINDING:
|
case REBINDING:
|
||||||
|
|||||||
@@ -22,13 +22,11 @@ class dhcp_message;
|
|||||||
|
|
||||||
enum dhcp_state {
|
enum dhcp_state {
|
||||||
INIT,
|
INIT,
|
||||||
SELECTING,
|
|
||||||
INIT_REBOOT,
|
|
||||||
REBOOTING,
|
|
||||||
REQUESTING,
|
REQUESTING,
|
||||||
BOUND,
|
BOUND,
|
||||||
RENEWING,
|
RENEWAL,
|
||||||
REBINDING,
|
REBINDING,
|
||||||
|
ACKNOWLEDGED,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -57,9 +55,9 @@ private:
|
|||||||
bool _TimeoutShift(int socket, time_t& timeout,
|
bool _TimeoutShift(int socket, time_t& timeout,
|
||||||
uint32& tries);
|
uint32& tries);
|
||||||
void _RestartLease(bigtime_t lease);
|
void _RestartLease(bigtime_t lease);
|
||||||
|
|
||||||
static BString _AddressToString(const uint8* data);
|
static BString _AddressToString(const uint8* data);
|
||||||
static BString _AddressToString(in_addr_t address);
|
static BString _AddressToString(in_addr_t address);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMessage fConfiguration;
|
BMessage fConfiguration;
|
||||||
|
|||||||
Reference in New Issue
Block a user