Skip to contentSkip to conversation

net: lwip: support syslog

PATCH In review James Hilliard 2 participants 3 messages Aug 26 – Sep 11 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: lwip: support syslog

LOG_SYSLOG depends on NET, but the raw Ethernet and UDP header builders it uses are only available with the legacy network stack. This makes LOG_SYSLOG fail to build with NET_LWIP.

Provide lwIP implementations using the selected Ethernet device and its indexed IP address from the environment. Move the shared declarations to net-common.h and extend the syslog test to check the source MAC address and IPv4 header checksum.

---
Changes v1 -> v2:
- Guard the lwIP raw-header helpers with LOG_SYSLOG (suggested by Peter Robinson)
- Link to v1: https://patch.msgid.link/[email protected]

---
 include/net-common.h   |  7 ++++++
 include/net-legacy.h   |  4 ----
 net/lwip/net-lwip.c    | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test/log/syslog_test.c |  2 ++
 test/log/syslog_test.h |  4 ++--
 5 files changed, 71 insertions(+), 6 deletions(-)
include/net-common.h +7 -0
index 0c260873c2c..3084a2b2a57 100644
@@ -362,6 +362,13 @@ struct ethernet_hdr {
 /* Ethernet header size */
 #define ETHER_HDR_SIZE	(sizeof(struct ethernet_hdr))
 
+/* Set Ethernet header; returns the size of the header */
+int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot);
+
+/* Set IPv4 and UDP headers */
+void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
+			int sport, int len);
+
 /**
  * net_random_ethaddr - Generate software assigned random Ethernet address
  * @addr: Pointer to a six-byte array containing the Ethernet address
include/net-legacy.h +0 -4
index d3b122c9062..d7f55d34a30 100644
@@ -344,15 +344,11 @@ int net_loop(enum proto_t);
 /* Get size of the ethernet header when we send */
 int net_eth_hdr_size(void);
 
-/* Set ethernet header; returns the size of the header */
-int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot);
 int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot);
 
 /* Set IP header */
 void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source,
 		       u16 pkt_len, u8 proto);
-void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
-			int sport, int len);
 
 /* Callbacks */
 rxhand_f *net_get_udp_handler(void);	/* Get UDP RX packet handler */
net/lwip/net-lwip.c +60 -0

66 lines not on this page · raw message

test/log/syslog_test.c +2 -0
index b6c0631aaf6..f848506fb1c 100644
@@ -34,11 +34,13 @@ int sb_log_tx_handler(struct udevice *dev, void *packet, unsigned int len)
 
 	/* Check Ethernet header */
 	ut_asserteq_mem(&eth_hdr->et_dest, net_bcast_ethaddr, ARP_HLEN);
+	ut_asserteq_mem(&eth_hdr->et_src, eth_get_ethaddr(), ARP_HLEN);
 	ut_asserteq(ntohs(eth_hdr->et_protlen), PROT_IP);
 
 	/* Check IP header */
 	buf += sizeof(struct ethernet_hdr);
 	ip_udp_hdr = (struct ip_udp_hdr *)buf;
+	ut_assert(ip_checksum_ok(ip_udp_hdr, IP_HDR_SIZE));
 	ut_asserteq(ip_udp_hdr->ip_p, IPPROTO_UDP);
 	ut_asserteq(ip_udp_hdr->ip_dst.s_addr, 0xffffffff);
 	ut_asserteq(ntohs(ip_udp_hdr->udp_dst), 514);
test/log/syslog_test.h +2 -2
index 39cce4ed498..89c86541f5e 100644
@@ -31,8 +31,8 @@ struct sb_log_env {
  *
  * The following checks are executed:
  *
- * * the Ethernet packet indicates a IP broadcast message
- * * the IP header is for a local UDP broadcast message to port 514
+ * * the Ethernet packet uses the selected interface and broadcast destination
+ * * the IP header checksum is valid and describes a UDP broadcast to port 514
  * * the UDP payload matches the expected string
  *
  * After testing the pointer to the expected string is set to NULL to signal

---
base-commit: 964ad5b5c91b7be56e443e899d7f873e6aa8c9fc
change-id: 20260825-lwip-syslog-v1-a5625eba2ea3

Best regards,

Signature · 1 line
James Hilliard <[email protected]>
Acked-by on v2 1/1
#1 lore raw
Quoted 14 lines · James Hilliard

LOG_SYSLOG depends on NET, but the raw Ethernet and UDP header builders it uses are only available with the legacy network stack. This makes LOG_SYSLOG fail to build with NET_LWIP.

Provide lwIP implementations using the selected Ethernet device and its indexed IP address from the environment. Move the shared declarations to net-common.h and extend the syslog test to check the source MAC address and IPv4 header checksum.

---
Changes v1 -> v2:
- Guard the lwIP raw-header helpers with LOG_SYSLOG (suggested by Peter Robinson)
- Link to v1: https://patch.msgid.link/[email protected]

Quoted 7 lines
---
 include/net-common.h   |  7 ++++++
 include/net-legacy.h   |  4 ----
 net/lwip/net-lwip.c    | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test/log/syslog_test.c |  2 ++
 test/log/syslog_test.h |  4 ++--
 5 files changed, 71 insertions(+), 6 deletions(-)

Thanks,

Signature · 1 line
Jerome
#2 lore raw
In reply to James Hilliard
Quoted 10 lines · James Hilliard

LOG_SYSLOG depends on NET, but the raw Ethernet and UDP header builders it uses are only available with the legacy network stack. This makes LOG_SYSLOG fail to build with NET_LWIP.

Provide lwIP implementations using the selected Ethernet device and its indexed IP address from the environment. Move the shared declarations to net-common.h and extend the syslog test to check the source MAC address and IPv4 header checksum.

[...]

Applied to u-boot-net branch for-main, thanks!

[1/1] net: lwip: support syslog

      commit: 6410670d25b4ca6ced6b5308d582318f7c888f9c

Best regards,

Signature · 1 line
Jerome Forissier <[email protected]>