Skip to contentSkip to conversation

NET_LWIP breaks common/log_syslog.c

DISCUSSION Heinrich Schuchardt 2 participants 2 messages Apr 22, 2025

lore
Share & tools
lore
#0 lore raw

Hello Jerome,

I am trying to compile with CONFIG_LOG_SYSLOG=y and CONFIG_NET_LWIP=y and get:

common/log_syslog.c: In function ‘log_syslog_emit’:
common/log_syslog.c:59:24: error: implicit declaration of function ‘net_set_ether’; did you mean ‘env_set_hex’? [-Wimplicit-function-declaration]
59 | eth_hdr_size = net_set_ether((uchar *)ptr,

net_bcast_ethaddr, PROT_IP);
      |                        ^~~~~~~~~~~~~
      |                        env_set_hex
common/log_syslog.c:102:9: error: implicit declaration of function ‘net_set_udp_header’ [-Wimplicit-function-declaration]
  102 |         net_set_udp_header((uchar *)iphdr, bcast_ip, 514, 514, 
ptr - log_msg);
      |         ^~~~~~~~~~~~~~~~~~

As these function just prepare packet buffers, should they be moved to common code used both for the legacy and the new network stack?

Best regards

Heinrich

#1 lore raw

Hi Heinrich,

Quoted 20 lines · Heinrich Schuchardt

Hello Jerome,

I am trying to compile with CONFIG_LOG_SYSLOG=y and CONFIG_NET_LWIP=y and get:

common/log_syslog.c: In function ‘log_syslog_emit’:
common/log_syslog.c:59:24: error: implicit declaration of function ‘net_set_ether’; did you mean ‘env_set_hex’? [-Wimplicit-function-declaration]
59 | eth_hdr_size = net_set_ether((uchar *)ptr,

net_bcast_ethaddr, PROT_IP);
       |                        ^~~~~~~~~~~~~
       |                        env_set_hex
common/log_syslog.c:102:9: error: implicit declaration of function
‘net_set_udp_header’ [-Wimplicit-function-declaration]
   102 |         net_set_udp_header((uchar *)iphdr, bcast_ip, 514, 514,
ptr - log_msg);
       |         ^~~~~~~~~~~~~~~~~~
Quoted 2 lines

As these function just prepare packet buffers, should they be moved to common code used both for the legacy and the new network stack?

Doing so may not be the best option, since it will be pulling a few more globals we don't have (and don't want) with NET_LWIP: net_our_vlan, net_native_vlan, net_ethaddr... I believe the best course of action is to rewrite log_syslog_emit()
to use the lwIP UDP API when NET_LWIP is enabled. It should not be too hard. Something like that:

struct pbuf *p;
struct netif *netif;

netif = net_lwip_new_netif(eth_get_dev());
pcb = udp_new();
udp_bind_netif(pcb, netif);
udp_bind(pcb, ip, src_port); /* maybe not needed if src_port doesn't matter */ p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
memcpy(p->payload, data, len);
udp_sendto_if(pcb, dst_ip, dst_port, netif);
pbuf_free(p);
udp_remove(pcb);
net_lwip_remove_netif(netif);

See also lib/lwip/lwip/src/apps/tftp/tftp.c for usage of the UDP API.

HTH,

Signature · 1 line
Jerome
Quoted 4 lines

Best regards

Heinrich