From 83ac9b727ce84c2cf08de4f468aadd19a5c3de76 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 13 Jun 2022 20:32:57 -0400 Subject: [PATCH] network/stack: Do not invoke SIOCGIFMEDIA but just return the already-fetched media. This functionally disables most of the functionality of the BSD-style SIOCGIFMEDIA, but it was never used in userland (because if it had, it would have triggered SMAP violations in the compatibility layer.) SIOCGIFMEDIA returns BSD-style media values, which mostly overlap with Haiku ones but have a few differences still. These are taken care of in the compat layer by ETHER_GET_LINK_STATE, which is where this media value comes from, but are not by SIOCGIFMEDIA which just passes back whatever the drivers do. Fixes #17770, at least for ethernet drivers. --- src/add-ons/kernel/network/stack/datalink.cpp | 16 ++++++---------- src/add-ons/kernel/network/stack/link.cpp | 12 ++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/add-ons/kernel/network/stack/datalink.cpp b/src/add-ons/kernel/network/stack/datalink.cpp index 9d4d7fb512..c1652a90c5 100644 --- a/src/add-ons/kernel/network/stack/datalink.cpp +++ b/src/add-ons/kernel/network/stack/datalink.cpp @@ -922,19 +922,15 @@ interface_protocol_control(net_datalink_protocol* _protocol, int32 option, return B_BAD_VALUE; struct ifmediareq request; - if (user_memcpy(&request, argument, sizeof(ifmediareq)) != B_OK) + if (user_memcpy(&request, argument, sizeof(request)) != B_OK) return B_BAD_ADDRESS; - // TODO: see above. - if (interface->device->module->control(interface->device, - SIOCGIFMEDIA, &request, - sizeof(struct ifmediareq)) != B_OK) { - memset(&request, 0, sizeof(struct ifmediareq)); - request.ifm_active = request.ifm_current - = interface->device->media; - } + // TODO: Support retrieving the media list? + memset(&request, 0, sizeof(struct ifmediareq)); + request.ifm_active = request.ifm_current + = interface->device->media; - return user_memcpy(argument, &request, sizeof(struct ifmediareq)); + return user_memcpy(argument, &request, sizeof(request)); } case SIOCGIFMETRIC: diff --git a/src/add-ons/kernel/network/stack/link.cpp b/src/add-ons/kernel/network/stack/link.cpp index 12f20ade7e..38486621d9 100644 --- a/src/add-ons/kernel/network/stack/link.cpp +++ b/src/add-ons/kernel/network/stack/link.cpp @@ -472,14 +472,10 @@ link_control(net_protocol* _protocol, int level, int option, void* value, return B_BAD_ADDRESS; } - // TODO: see above. - if (interface->device->module->control(interface->device, - SIOCGIFMEDIA, &request, - sizeof(struct ifmediareq)) != B_OK) { - memset(&request, 0, sizeof(struct ifmediareq)); - request.ifm_active = request.ifm_current - = interface->device->media; - } + // We do not support SIOCSIFMEDIA here, so ignore the media list. + memset(&request, 0, sizeof(struct ifmediareq)); + request.ifm_active = request.ifm_current = interface->device->media; + put_device_interface(interface); return user_memcpy(value, &request, sizeof(struct ifmediareq));