lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #64965] udp_sendto() doesn't remove any added headers


From: Shawn Silverman
Subject: [lwip-devel] [bug #64965] udp_sendto() doesn't remove any added headers if the send fails
Date: Sat, 2 Dec 2023 15:15:31 -0500 (EST)

URL:
  <https://savannah.nongnu.org/bugs/?64965>

                 Summary: udp_sendto() doesn't remove any added headers if the
send fails
                   Group: lwIP - A Lightweight TCP/IP stack
               Submitter: ssilverman
               Submitted: Sat 02 Dec 2023 08:15:29 PM UTC
                Category: UDP
                Severity: 3 - Normal
              Item Group: Faulty Behaviour
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: git head


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Sat 02 Dec 2023 08:15:29 PM UTC By: Shawn Silverman <ssilverman>
I recently encountered this when I was retrying a UDP send. I was getting
ERR_BUF errors then realized any added headers down the chain (UDP->IP->etc)
weren't removed on failure.

For my specific use case, I do retries until not ERR_WOULDBLOCK because my
low-level driver returns that if there are no TX buffers yet available.

My fix looks like this (see the "udp_sendto() may have added a header" part):

  // Note: Use PBUF_RAM for TX
  struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
  if (p == nullptr) {
    return false;
  }

  pbuf_take(p, data, len);
  err_t err;

  // Repeat until not ERR_WOULDBLOCK because the low-level driver returns
that
  // if there are no internal TX buffers available
  do {
    err = udp_sendto(pcb_, p, ipaddr, port);
    if (err != ERR_WOULDBLOCK) {
      break;
    }

    // udp_sendto() may have added a header
    if (p->tot_len > len) {
      pbuf_remove_header(p, p->tot_len - len);
    }
  } while (true);


It feels like a failure should revert the pbuf, unless this is intended
behaviour? In my view, a failure should never cause inputs to be modified, or
at least restore the state if they are.

That also leads to the question: should it be assumed that any pbufs passed to
lwIP functions, even for successful calls, could be modified?







    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?64965>

_______________________________________________
Message sent via Savannah
https://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]