[haiku-commits] haiku: hrev56164 - src/libs/compat/freebsd_network

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 8 Jun 2022 03:55:19 +0000 (UTC)

hrev56164 adds 3 changesets to branch 'master'
old head: db1800ca17dec1c4079b3ed3452a1ad8532accc3
new head: 44d08ffc4a3da5664127c1155d830dd9d8686f02
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=44d08ffc4a3d+%5Edb1800ca17de

----------------------------------------------------------------------------

68f0117d8308: freebsd_network: Disable IFMEDIA_DEBUG.
  
  It is not really that useful to print most of this information
  by default and it just fills up syslogs unnecessarily.

d765574fdb1c: freebsd_network: Adjust too-large packet handling in read().
  
  Before ca6a44c1333c467706a7ceae2842d0de380139cb, this function returned
  whatever amount of the buffer it could and silently discarded the rest.
  After that change and before this one, it would refuse to return anything,
  which meant that as soon as we got one packet too large to handle,
  we would never receive any more packets (and the errors displayed in
  e.g. ifconfig would go up forever.)
  
  Now, we discard too-large packets so RX will not stall completely
  and still return E2BIG (so error counts will go up), but we also
  print an error to syslog, so that precisely what has gone wrong
  will be easily known.

44d08ffc4a3d: freebsd_network: Add another MTU to attempt to set devices to.
  
  IEEE 802.11 has its own maximum MTU which is smaller than PAGESIZE
  but larger than the ETHERMTU default. So we now attempt to set this
  as well. In doing so, refactor the set into a loop based off an array
  of possible MTUs.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 26 insertions(+), 19 deletions(-)
src/libs/compat/freebsd_network/device_hooks.c  | 39 ++++++++++++---------
src/libs/compat/freebsd_network/fbsd_if_media.c |  6 ++--

############################################################################

Commit:      68f0117d83082aad7b1ba540a52ea384f72ec132
URL:         https://git.haiku-os.org/haiku/commit/?id=68f0117d8308
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Jun  8 03:46:25 2022 UTC

freebsd_network: Disable IFMEDIA_DEBUG.

It is not really that useful to print most of this information
by default and it just fills up syslogs unnecessarily.

----------------------------------------------------------------------------

diff --git a/src/libs/compat/freebsd_network/fbsd_if_media.c 
b/src/libs/compat/freebsd_network/fbsd_if_media.c
index 24be63b013..2fcf113d95 100644
--- a/src/libs/compat/freebsd_network/fbsd_if_media.c
+++ b/src/libs/compat/freebsd_network/fbsd_if_media.c
@@ -64,9 +64,11 @@
  *     Useful for debugging newly-ported  drivers.
  */
 
-#define IFMEDIA_DEBUG
+//#define IFMEDIA_DEBUG
 #ifdef IFMEDIA_DEBUG
 #   define TRACE(x...) dprintf(x)
+
+static void ifmedia_printword(int);
 #else
 #   define TRACE(x...) ;
 #endif
@@ -74,8 +76,6 @@
 static struct ifmedia_entry *ifmedia_match(struct ifmedia *ifm,
        int flags, int mask);
 
-static void ifmedia_printword(int);
-
 /*
  * Initialize if_media struct for a specific interface instance.
  */

############################################################################

Commit:      d765574fdb1c4ee05150da04d2d06ddfcddb3c93
URL:         https://git.haiku-os.org/haiku/commit/?id=d765574fdb1c
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Jun  8 03:49:17 2022 UTC

freebsd_network: Adjust too-large packet handling in read().

Before ca6a44c1333c467706a7ceae2842d0de380139cb, this function returned
whatever amount of the buffer it could and silently discarded the rest.
After that change and before this one, it would refuse to return anything,
which meant that as soon as we got one packet too large to handle,
we would never receive any more packets (and the errors displayed in
e.g. ifconfig would go up forever.)

Now, we discard too-large packets so RX will not stall completely
and still return E2BIG (so error counts will go up), but we also
print an error to syslog, so that precisely what has gone wrong
will be easily known.

----------------------------------------------------------------------------

diff --git a/src/libs/compat/freebsd_network/device_hooks.c 
b/src/libs/compat/freebsd_network/device_hooks.c
index 9389a6b99e..4ab25af2f0 100644
--- a/src/libs/compat/freebsd_network/device_hooks.c
+++ b/src/libs/compat/freebsd_network/device_hooks.c
@@ -134,16 +134,17 @@ compat_read(void *cookie, off_t position, void *buffer, 
size_t *numBytes)
                } else if (status < B_OK)
                        return status;
 
-               IF_LOCK(&ifp->receive_queue);
-               if (ifp->receive_queue.ifq_head != NULL
-                               && ifp->receive_queue.ifq_head->m_pkthdr.len >= 
length) {
-                       IF_UNLOCK(&ifp->receive_queue);
-                       return E2BIG;
-               }
-               _IF_DEQUEUE(&ifp->receive_queue, mb);
-               IF_UNLOCK(&ifp->receive_queue);
+               IF_DEQUEUE(&ifp->receive_queue, mb);
        } while (mb == NULL);
 
+       if (mb->m_pkthdr.len > length) {
+               if_printf(ifp, "error reading packet: too large! (%d > %" 
B_PRIuSIZE ")\n",
+                       mb->m_pkthdr.len, length);
+               m_freem(mb);
+               *numBytes = 0;
+               return E2BIG;
+       }
+
        length = min_c(max_c((size_t)mb->m_pkthdr.len, 0), length);
 
        m_copydata(mb, 0, length, buffer);

############################################################################

Revision:    hrev56164
Commit:      44d08ffc4a3da5664127c1155d830dd9d8686f02
URL:         https://git.haiku-os.org/haiku/commit/?id=44d08ffc4a3d
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Jun  8 03:50:54 2022 UTC

freebsd_network: Add another MTU to attempt to set devices to.

IEEE 802.11 has its own maximum MTU which is smaller than PAGESIZE
but larger than the ETHERMTU default. So we now attempt to set this
as well. In doing so, refactor the set into a loop based off an array
of possible MTUs.

----------------------------------------------------------------------------

diff --git a/src/libs/compat/freebsd_network/device_hooks.c 
b/src/libs/compat/freebsd_network/device_hooks.c
index 4ab25af2f0..37165fda42 100644
--- a/src/libs/compat/freebsd_network/device_hooks.c
+++ b/src/libs/compat/freebsd_network/device_hooks.c
@@ -237,15 +237,21 @@ compat_control(void *cookie, uint32 op, void *arg, size_t 
length)
                        if (length < 4)
                                return B_BAD_VALUE;
 
+                       const int MTUs[] = {
+                               ETHERMTU_JUMBO,
+                               PAGESIZE - (ETHER_HDR_LEN + ETHER_CRC_LEN),
+                               2290, /* IEEE80211_MTU_MAX */
+                               0
+                       };
+
                        // This is (usually) only invoked during initialization 
to get the
-                       // maximum frame size. Thus we try to set the largest 
possible one,
-                       // as there is no way to determine what the driver 
might support.
-                       struct ifreq ifr;
-                       ifr.ifr_mtu = ETHERMTU_JUMBO;
-                       if (compat_control(cookie, SIOCSIFMTU, &ifr, 
sizeof(ifr)) != 0) {
-                               // Try again with 4K at least.
-                               ifr.ifr_mtu = 4096 - (ETHER_HDR_LEN + 
ETHER_CRC_LEN);
-                               compat_control(cookie, SIOCSIFMTU, &ifr, 
sizeof(ifr));
+                       // maximum frame size. Thus we try a few common 
possible values,
+                       // as there is no way to determine what is supported 
(or required).
+                       for (int i = 0; MTUs[i] != 0; i++) {
+                               struct ifreq ifr;
+                               ifr.ifr_mtu = MTUs[i];
+                               if (compat_control(cookie, SIOCSIFMTU, &ifr, 
sizeof(ifr)) == 0)
+                                       break;
                        }
 
                        frameSize = ifp->if_mtu + (ETHER_HDR_LEN + 
ETHER_CRC_LEN);


Other related posts:

  • » [haiku-commits] haiku: hrev56164 - src/libs/compat/freebsd_network - waddlesplash