From: Joan Lledó <[email protected]>

Add support for `ipi_spec_dst`. Due to the limited concept of
routing lwip implements. This field will always hold the interface
address as value.
---
 debian/patches/in_pktinfo | 61 +++++++++++++++++++++++++++++++++++++++
 debian/patches/series     |  1 +
 2 files changed, 62 insertions(+)
 create mode 100644 debian/patches/in_pktinfo

diff --git a/debian/patches/in_pktinfo b/debian/patches/in_pktinfo
new file mode 100644
index 0000000..2276c39
--- /dev/null
+++ b/debian/patches/in_pktinfo
@@ -0,0 +1,61 @@
+Description: Add `ipi_spec_dst` field to `struct in_pktinfo`
+Author: Joan Lledó <[email protected]>
+Last-Update: 2025-12-26
+
+Index: lwip-deb/src/api/sockets.c
+===================================================================
+--- lwip-deb.orig/src/api/sockets.c    2025-12-27 12:20:46.000000000 +0100
++++ lwip-deb/src/api/sockets.c 2025-12-27 17:30:29.000000000 +0100
+@@ -1272,6 +1272,7 @@
+           chdr->cmsg_type = IP_PKTINFO;
+           chdr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
+           pkti->ipi_ifindex = buf->p->if_idx;
++          inet_addr_from_ip4addr(&pkti->ipi_spec_dst, 
ip_2_ip4(netbuf_ifaddr(buf)));
+           inet_addr_from_ip4addr(&pkti->ipi_addr, 
ip_2_ip4(netbuf_destaddr(buf)));
+           msg->msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo));
+           wrote_msg = 1;
+Index: lwip-deb/src/include/lwip/sockets.h
+===================================================================
+--- lwip-deb.orig/src/include/lwip/sockets.h   2025-12-27 12:20:46.000000000 
+0100
++++ lwip-deb/src/include/lwip/sockets.h        2025-12-27 12:20:46.000000000 
+0100
+@@ -334,6 +334,7 @@
+ #if LWIP_IPV4
+ struct in_pktinfo {
+   unsigned int   ipi_ifindex;  /* Interface index */
++  struct in_addr ipi_spec_dst; /* Destination (from routing) address */
+   struct in_addr ipi_addr;     /* Destination (from header) address */
+ };
+ #endif /* LWIP_IPV4 */
+Index: lwip-deb/src/api/api_msg.c
+===================================================================
+--- lwip-deb.orig/src/api/api_msg.c    2025-12-27 17:35:43.000000000 +0100
++++ lwip-deb/src/api/api_msg.c 2025-12-27 17:36:43.000000000 +0100
+@@ -263,6 +263,7 @@
+       /* get the UDP header - always in the first pbuf, ensured by udp_input 
*/
+       const struct udp_hdr *udphdr = (const struct udp_hdr 
*)ip_next_header_ptr();
+       buf->flags = NETBUF_FLAG_DESTADDR;
++      ip_addr_set(&buf->ifaddr, netif_ip_addr4(ip_current_netif()));
+       ip_addr_set(&buf->toaddr, ip_current_dest_addr());
+       buf->toport_chksum = udphdr->dest;
+     }
+Index: lwip-deb/src/include/lwip/netbuf.h
+===================================================================
+--- lwip-deb.orig/src/include/lwip/netbuf.h    2025-12-27 17:35:49.000000000 
+0100
++++ lwip-deb/src/include/lwip/netbuf.h 2025-12-27 17:36:37.000000000 +0100
+@@ -65,6 +65,7 @@
+   u8_t flags;
+   u16_t toport_chksum;
+ #if LWIP_NETBUF_RECVINFO
++  ip_addr_t ifaddr;
+   ip_addr_t toaddr;
+ #endif /* LWIP_NETBUF_RECVINFO */
+ #endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
+@@ -96,6 +97,8 @@
+ #if LWIP_NETBUF_RECVINFO
+ #define netbuf_destaddr(buf)         (&((buf)->toaddr))
+ #define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), 
destaddr)
++#define netbuf_ifaddr(buf)         (&((buf)->ifaddr))
++#define netbuf_set_ifaddr(buf, ifaddr) ip_addr_set(&((buf)->ifaddr), ifaddr)
+ #if LWIP_CHECKSUM_ON_COPY
+ #define netbuf_destport(buf)         (((buf)->flags & NETBUF_FLAG_DESTADDR) ? 
(buf)->toport_chksum : 0)
+ #else /* LWIP_CHECKSUM_ON_COPY */
diff --git a/debian/patches/series b/debian/patches/series
index d3b8ef5..196d4b7 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,3 +3,4 @@ empty_block_last
 max_sockets
 doxygen
 doxygen2
+in_pktinfo
-- 
2.50.1


Reply via email to