moved IFF_LINK handling to the device module (ethernet in this case). Now domain interfaces only keep specific flags such as IFF_UP and the configuration flags. IFF_LINK, IFF_BROADCAST etc are maintained exclusively by the device.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20612 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Hugo Santos 2007-04-08 05:50:36 +00:00
parent fb300cfd25
commit ae074c5d15
6 changed files with 32 additions and 60 deletions

View File

@ -67,6 +67,11 @@ update_link_state(ethernet_device *device, bool notify = true)
device->link_quality = state.quality; device->link_quality = state.quality;
device->link_speed = state.speed; device->link_speed = state.speed;
if (device->media & IFM_ACTIVE)
device->flags |= IFF_LINK;
else
device->flags &= ~IFF_LINK;
dprintf("%s: media change, media 0x%0x quality %u speed %u\n", dprintf("%s: media change, media 0x%0x quality %u speed %u\n",
device->name, (unsigned int)device->media, device->name, (unsigned int)device->media,
(unsigned int)device->link_quality, (unsigned int)device->link_quality,
@ -132,7 +137,7 @@ ethernet_init(const char *name, net_device **_device)
memset(device, 0, sizeof(ethernet_device)); memset(device, 0, sizeof(ethernet_device));
strcpy(device->name, name); strcpy(device->name, name);
device->flags = IFF_BROADCAST; device->flags = IFF_BROADCAST | IFF_LINK;
device->type = IFT_ETHER; device->type = IFT_ETHER;
device->mtu = 1500; device->mtu = 1500;
device->media = IFM_ACTIVE | IFM_ETHER; device->media = IFM_ACTIVE | IFM_ETHER;

View File

@ -15,6 +15,7 @@
#include <net/if.h> #include <net/if.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/if_media.h>
#include <new> #include <new>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -85,9 +86,10 @@ loopback_init(const char *name, net_device **_device)
memset(device, 0, sizeof(loopback_device)); memset(device, 0, sizeof(loopback_device));
strcpy(device->name, name); strcpy(device->name, name);
device->flags = IFF_LOOPBACK; device->flags = IFF_LOOPBACK | IFF_LINK;
device->type = IFT_LOOP; device->type = IFT_LOOP;
device->mtu = 16384; device->mtu = 16384;
device->media = IFM_ACTIVE;
*_device = device; *_device = device;
return B_OK; return B_OK;

View File

@ -619,7 +619,7 @@ interface_protocol_control(net_datalink_protocol *_protocol,
{ {
// get flags // get flags
struct ifreq request; struct ifreq request;
request.ifr_flags = interface->flags; request.ifr_flags = interface->flags | interface->device->flags;
return user_memcpy(&((struct ifreq *)argument)->ifr_flags, return user_memcpy(&((struct ifreq *)argument)->ifr_flags,
&request.ifr_flags, sizeof(request.ifr_flags)); &request.ifr_flags, sizeof(request.ifr_flags));

View File

@ -219,30 +219,30 @@ domain_interface_control(net_domain_private *domain, int32 option,
net_interface *interface = find_interface(domain, name); net_interface *interface = find_interface(domain, name);
if (interface != NULL) { if (interface != NULL) {
switch (option) { switch (option) {
case SIOCDIFADDR: case SIOCDIFADDR:
remove_interface_from_domain(interface); remove_interface_from_domain(interface);
break; break;
case SIOCSIFFLAGS: case SIOCSIFFLAGS:
if (((uint32)request->ifr_flags & IFF_UP) {
!= (interface->flags & IFF_UP)) { uint32 requestFlags = request->ifr_flags;
if (interface->flags & IFF_UP) { request->ifr_flags &= ~(IFF_UP | IFF_LINK | IFF_BROADCAST);
interface_set_down(interface);
} else { if ((requestFlags & IFF_UP) != (interface->flags & IFF_UP)) {
status = interface->first_info->interface_up( if (requestFlags & IFF_UP) {
interface->first_protocol); status = interface->first_info->interface_up(
if (status == B_OK) { interface->first_protocol);
interface->flags |= IFF_UP; if (status == B_OK)
// TODO this doesn't belong here interface->flags |= IFF_UP;
if (interface->device->media & IFM_ACTIVE) } else {
interface->flags |= IFF_LINK; interface_set_down(interface);
} }
} }
}
if (status == B_OK) if (status == B_OK)
interface->flags |= request->ifr_flags & ~(IFF_UP | IFF_LINK); interface->flags |= request->ifr_flags;
break; break;
}
} }
} }
} }
@ -256,38 +256,6 @@ domain_interface_control(net_domain_private *domain, int32 option,
} }
void
domain_interfaces_link_changed(net_device *device)
{
// TODO: notify listeners about this!
BenaphoreLocker locker(sDomainLock);
net_domain_private *domain = NULL;
while (true) {
domain = (net_domain_private *)list_get_next_item(&sDomains, domain);
if (domain == NULL)
break;
BenaphoreLocker locker(domain->lock);
net_interface *interface = NULL;
while (true) {
interface = (net_interface *)list_get_next_item(&domain->interfaces,
interface);
if (interface == NULL)
break;
if (interface->device == device) {
// update IFF_LINK flag
interface->flags = (interface->flags & ~IFF_LINK)
| (device->media & IFM_ACTIVE ? IFF_LINK : 0);
}
}
}
}
void void
domain_interface_went_down(net_interface *interface) domain_interface_went_down(net_interface *interface)
{ {

View File

@ -36,7 +36,6 @@ uint32 count_domain_interfaces();
status_t list_domain_interfaces(void *buffer, size_t *_bufferSize); status_t list_domain_interfaces(void *buffer, size_t *_bufferSize);
status_t add_interface_to_domain(net_domain *domain, struct ifreq& request); status_t add_interface_to_domain(net_domain *domain, struct ifreq& request);
status_t remove_interface_from_domain(net_interface *interface); status_t remove_interface_from_domain(net_interface *interface);
void domain_interfaces_link_changed(net_device *device);
void domain_interface_went_down(net_interface *); void domain_interface_went_down(net_interface *);
void domain_removed_device_interface(net_device_interface *); void domain_removed_device_interface(net_device_interface *);
status_t domain_interface_control(net_domain_private *domain, int32 option, status_t domain_interface_control(net_domain_private *domain, int32 option,

View File

@ -141,7 +141,7 @@ create_interface(net_domain *domain, const char *name, const char *baseName,
interface->mask = NULL; interface->mask = NULL;
interface->index = ++sInterfaceIndex; interface->index = ++sInterfaceIndex;
interface->flags = deviceInterface->device->flags & ~IFF_UP; interface->flags = 0;
interface->type = 0; interface->type = 0;
interface->mtu = deviceInterface->device->mtu; interface->mtu = deviceInterface->device->mtu;
interface->metric = 0; interface->metric = 0;
@ -169,8 +169,7 @@ interface_set_down(net_interface *interface)
if ((interface->flags & IFF_UP) == 0) if ((interface->flags & IFF_UP) == 0)
return; return;
// TODO: IFF_LINK should belong in device only interface->flags &= ~IFF_UP;
interface->flags &= ~(IFF_UP | IFF_LINK);
interface->first_info->interface_down(interface->first_protocol); interface->first_info->interface_down(interface->first_protocol);
} }
@ -658,7 +657,6 @@ unregister_device_monitor(struct net_device *device,
status_t status_t
device_link_changed(net_device *device) device_link_changed(net_device *device)
{ {
domain_interfaces_link_changed(device);
return B_OK; return B_OK;
} }