* DHCP now actually uses the new SO_BINDTODEVICE socket option to make sure
the request is sent only on the device it should. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28017 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/sockio.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -408,6 +409,24 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
int option = 1;
|
int option = 1;
|
||||||
setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &option, sizeof(option));
|
setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &option, sizeof(option));
|
||||||
|
|
||||||
|
if (state == INIT) {
|
||||||
|
// The local interface does not have an address yet, bind the socket
|
||||||
|
// to the device directly.
|
||||||
|
int linkSocket = ::socket(AF_LINK, SOCK_DGRAM, 0);
|
||||||
|
if (linkSocket >= 0) {
|
||||||
|
// we need to know the index of the device to be able to bind to it
|
||||||
|
ifreq request;
|
||||||
|
prepare_request(request, fDevice.String());
|
||||||
|
if (ioctl(linkSocket, SIOCGIFINDEX, &request, sizeof(struct ifreq))
|
||||||
|
== 0) {
|
||||||
|
setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE,
|
||||||
|
&request.ifr_index, sizeof(int));
|
||||||
|
}
|
||||||
|
|
||||||
|
close(linkSocket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bigtime_t previousLeaseTime = fLeaseTime;
|
bigtime_t previousLeaseTime = fLeaseTime;
|
||||||
fLeaseTime = 0;
|
fLeaseTime = 0;
|
||||||
fRenewalTime = 0;
|
fRenewalTime = 0;
|
||||||
|
|||||||
@@ -588,14 +588,8 @@ NetServer::_ConfigureInterface(int socket, BMessage& interface, bool fromMessage
|
|||||||
request.ifr_route = route;
|
request.ifr_route = route;
|
||||||
|
|
||||||
if (autoConfig) {
|
if (autoConfig) {
|
||||||
// add a default route to make the interface accessible, even without an address
|
_QuitLooperForDevice(device);
|
||||||
if (ioctl(socket, SIOCADDRT, &request, sizeof(request)) < 0) {
|
startAutoConfig = true;
|
||||||
fprintf(stderr, "%s: Could not add route for %s: %s\n",
|
|
||||||
Name(), device, strerror(errno));
|
|
||||||
} else {
|
|
||||||
_QuitLooperForDevice(device);
|
|
||||||
startAutoConfig = true;
|
|
||||||
}
|
|
||||||
} else if (addressMessage.FindString("gateway", &string) == B_OK
|
} else if (addressMessage.FindString("gateway", &string) == B_OK
|
||||||
&& parse_address(familyIndex, string, gateway)) {
|
&& parse_address(familyIndex, string, gateway)) {
|
||||||
// add gateway route, if we're asked for it
|
// add gateway route, if we're asked for it
|
||||||
|
|||||||
Reference in New Issue
Block a user