net_interface & datalink: Fix MTU handling.
The device is what actually controls the MTU, and it has its own field for this, so having a second one just meant the MTU never got updated after startup. Remove the "mtu" field from the interface, use the "device->mtu" directly, and then actually invoke device->module->set_mtu when updating.
This commit is contained in:
@@ -48,7 +48,6 @@ typedef struct net_interface {
|
|||||||
uint32 index;
|
uint32 index;
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
uint8 type;
|
uint8 type;
|
||||||
uint32 mtu;
|
|
||||||
uint32 metric;
|
uint32 metric;
|
||||||
} net_interface;
|
} net_interface;
|
||||||
|
|
||||||
|
|||||||
@@ -1580,7 +1580,7 @@ ipv4_send_routed_data(net_protocol* _protocol, struct net_route* route,
|
|||||||
TRACE_SK(protocol, " SendRoutedData(): destination: %08x",
|
TRACE_SK(protocol, " SendRoutedData(): destination: %08x",
|
||||||
ntohl(destination.sin_addr.s_addr));
|
ntohl(destination.sin_addr.s_addr));
|
||||||
|
|
||||||
uint32 mtu = route->mtu ? route->mtu : interface->mtu;
|
uint32 mtu = route->mtu ? route->mtu : interface->device->mtu;
|
||||||
if (buffer->size > mtu) {
|
if (buffer->size > mtu) {
|
||||||
// we need to fragment the packet
|
// we need to fragment the packet
|
||||||
return send_fragments(protocol, route, buffer, mtu);
|
return send_fragments(protocol, route, buffer, mtu);
|
||||||
@@ -1689,7 +1689,7 @@ ipv4_get_mtu(net_protocol* protocol, const struct sockaddr* address)
|
|||||||
if (route->mtu != 0)
|
if (route->mtu != 0)
|
||||||
mtu = route->mtu;
|
mtu = route->mtu;
|
||||||
else
|
else
|
||||||
mtu = route->interface_address->interface->mtu;
|
mtu = route->interface_address->interface->device->mtu;
|
||||||
|
|
||||||
sDatalinkModule->put_route(sDomain, route);
|
sDatalinkModule->put_route(sDomain, route);
|
||||||
return mtu - sizeof(ipv4_header);
|
return mtu - sizeof(ipv4_header);
|
||||||
|
|||||||
@@ -1330,7 +1330,7 @@ ipv6_send_routed_data(net_protocol* _protocol, struct net_route* route,
|
|||||||
ip6_sprintf(&destination.sin6_addr, addrbuf);
|
ip6_sprintf(&destination.sin6_addr, addrbuf);
|
||||||
TRACE_SK(protocol, " SendRoutedData(): destination: %s", addrbuf);
|
TRACE_SK(protocol, " SendRoutedData(): destination: %s", addrbuf);
|
||||||
|
|
||||||
uint32 mtu = route->mtu ? route->mtu : interface->mtu;
|
uint32 mtu = route->mtu ? route->mtu : interface->device->mtu;
|
||||||
if (buffer->size > mtu) {
|
if (buffer->size > mtu) {
|
||||||
// we need to fragment the packet
|
// we need to fragment the packet
|
||||||
return send_fragments(protocol, route, buffer, mtu);
|
return send_fragments(protocol, route, buffer, mtu);
|
||||||
@@ -1428,7 +1428,7 @@ ipv6_get_mtu(net_protocol* protocol, const struct sockaddr* address)
|
|||||||
if (route->mtu != 0)
|
if (route->mtu != 0)
|
||||||
mtu = route->mtu;
|
mtu = route->mtu;
|
||||||
else
|
else
|
||||||
mtu = route->interface_address->interface->mtu;
|
mtu = route->interface_address->interface->device->mtu;
|
||||||
|
|
||||||
sDatalinkModule->put_route(sDomain, route);
|
sDatalinkModule->put_route(sDomain, route);
|
||||||
// TODO: what about extension headers?
|
// TODO: what about extension headers?
|
||||||
|
|||||||
@@ -875,7 +875,7 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option,
|
|||||||
{
|
{
|
||||||
// get MTU
|
// get MTU
|
||||||
struct ifreq request;
|
struct ifreq request;
|
||||||
request.ifr_mtu = interface->mtu;
|
request.ifr_mtu = interface->device->mtu;
|
||||||
|
|
||||||
return user_memcpy(&((struct ifreq*)argument)->ifr_mtu,
|
return user_memcpy(&((struct ifreq*)argument)->ifr_mtu,
|
||||||
&request.ifr_mtu, sizeof(request.ifr_mtu));
|
&request.ifr_mtu, sizeof(request.ifr_mtu));
|
||||||
@@ -884,17 +884,14 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option,
|
|||||||
{
|
{
|
||||||
// set MTU
|
// set MTU
|
||||||
struct ifreq request;
|
struct ifreq request;
|
||||||
if (user_memcpy(&request, argument, sizeof(struct ifreq)) < B_OK)
|
if (user_memcpy(&request, argument, sizeof(struct ifreq)) != B_OK)
|
||||||
return B_BAD_ADDRESS;
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
// check for valid bounds
|
status_t status = interface->device->module->set_mtu(
|
||||||
if (request.ifr_mtu < 100
|
interface->device, request.ifr_mtu);
|
||||||
|| (uint32)request.ifr_mtu > interface->device->mtu)
|
if (status == B_OK)
|
||||||
return B_BAD_VALUE;
|
notify_interface_changed(interface);
|
||||||
|
return status;
|
||||||
interface->mtu = request.ifr_mtu;
|
|
||||||
notify_interface_changed(interface);
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case SIOCSIFMEDIA:
|
case SIOCSIFMEDIA:
|
||||||
|
|||||||
@@ -464,7 +464,6 @@ Interface::Interface(const char* interfaceName,
|
|||||||
index = ++sInterfaceIndex;
|
index = ++sInterfaceIndex;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
type = 0;
|
type = 0;
|
||||||
mtu = deviceInterface->device->mtu;
|
|
||||||
metric = 0;
|
metric = 0;
|
||||||
|
|
||||||
fDeviceInterface = acquire_device_interface(deviceInterface);
|
fDeviceInterface = acquire_device_interface(deviceInterface);
|
||||||
@@ -1049,7 +1048,6 @@ Interface::Dump() const
|
|||||||
kprintf("index: %" B_PRIu32 "\n", index);
|
kprintf("index: %" B_PRIu32 "\n", index);
|
||||||
kprintf("flags: %#" B_PRIx32 "\n", flags);
|
kprintf("flags: %#" B_PRIx32 "\n", flags);
|
||||||
kprintf("type: %u\n", type);
|
kprintf("type: %u\n", type);
|
||||||
kprintf("mtu: %" B_PRIu32 "\n", mtu);
|
|
||||||
kprintf("metric: %" B_PRIu32 "\n", metric);
|
kprintf("metric: %" B_PRIu32 "\n", metric);
|
||||||
kprintf("ref count: %" B_PRId32 "\n", CountReferences());
|
kprintf("ref count: %" B_PRId32 "\n", CountReferences());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user