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:
Augustin Cavalier 2022-05-27 16:36:12 -04:00
parent 05cb1b0e05
commit 41faeb1df9
5 changed files with 11 additions and 17 deletions

View File

@ -48,7 +48,6 @@ typedef struct net_interface {
uint32 index;
uint32 flags;
uint8 type;
uint32 mtu;
uint32 metric;
} net_interface;

View File

@ -1580,7 +1580,7 @@ ipv4_send_routed_data(net_protocol* _protocol, struct net_route* route,
TRACE_SK(protocol, " SendRoutedData(): destination: %08x",
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) {
// we need to fragment the packet
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)
mtu = route->mtu;
else
mtu = route->interface_address->interface->mtu;
mtu = route->interface_address->interface->device->mtu;
sDatalinkModule->put_route(sDomain, route);
return mtu - sizeof(ipv4_header);

View File

@ -1330,7 +1330,7 @@ ipv6_send_routed_data(net_protocol* _protocol, struct net_route* route,
ip6_sprintf(&destination.sin6_addr, 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) {
// we need to fragment the packet
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)
mtu = route->mtu;
else
mtu = route->interface_address->interface->mtu;
mtu = route->interface_address->interface->device->mtu;
sDatalinkModule->put_route(sDomain, route);
// TODO: what about extension headers?

View File

@ -875,7 +875,7 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option,
{
// get MTU
struct ifreq request;
request.ifr_mtu = interface->mtu;
request.ifr_mtu = interface->device->mtu;
return user_memcpy(&((struct ifreq*)argument)->ifr_mtu,
&request.ifr_mtu, sizeof(request.ifr_mtu));
@ -884,17 +884,14 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option,
{
// set MTU
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;
// check for valid bounds
if (request.ifr_mtu < 100
|| (uint32)request.ifr_mtu > interface->device->mtu)
return B_BAD_VALUE;
interface->mtu = request.ifr_mtu;
notify_interface_changed(interface);
return B_OK;
status_t status = interface->device->module->set_mtu(
interface->device, request.ifr_mtu);
if (status == B_OK)
notify_interface_changed(interface);
return status;
}
case SIOCSIFMEDIA:

View File

@ -464,7 +464,6 @@ Interface::Interface(const char* interfaceName,
index = ++sInterfaceIndex;
flags = 0;
type = 0;
mtu = deviceInterface->device->mtu;
metric = 0;
fDeviceInterface = acquire_device_interface(deviceInterface);
@ -1049,7 +1048,6 @@ Interface::Dump() const
kprintf("index: %" B_PRIu32 "\n", index);
kprintf("flags: %#" B_PRIx32 "\n", flags);
kprintf("type: %u\n", type);
kprintf("mtu: %" B_PRIu32 "\n", mtu);
kprintf("metric: %" B_PRIu32 "\n", metric);
kprintf("ref count: %" B_PRId32 "\n", CountReferences());