File: zephyr/subsys/bacnet_datalink/bip-init.c
Description
When a static IP is pre-configured via bip_set_addr() and bip_set_broadcast_addr(), the function bip_set_interface() calls net_if_ipv4_set_netmask_by_addr() with BIP_Broadcast_Addr as the netmask parameter. This corrupts the interface netmask, breaking all IP routing including ping.
Affected code (bip-init.c ~line 491):
net_if_ipv4_set_netmask_by_addr(
iface, &BIP_Address, &BIP_Broadcast_Addr); // BUG: passing broadcast, not netmask
Function signature expects:
bool net_if_ipv4_set_netmask_by_addr(
struct net_if *iface,
const struct net_in_addr *addr,
const struct net_in_addr *netmask); // expects netmask, not broadcast
Impact
After bip_set_interface() runs, the interface netmask is set to the broadcast address (e.g. 192.255.255.255 for a /8 network). This breaks routing and makes the device unreachable via ping and unresponsive to BACnet discovery.
Workaround
After bacnet_port_init() returns, restore the correct netmask:
net_if_ipv4_set_netmask_by_addr(iface,
(struct net_in_addr *)ip,
(struct net_in_addr *)mask);
Suggested Fix
Replace BIP_Broadcast_Addr with the actual netmask. A separate variable BIP_Netmask should be stored and used here, similar to how the Linux/BSD ports handle it.
Environment
- Zephyr version: main (commit 8eed22ad9872)
- Board: NXP i.MX RT1020 (mimxrt1020_evk)
- bacnet-stack-zephyr commit: c1f1c1e
- bacnet-stack core version: 1.5.0 (bacnet-stack-1.5.0-25-g5d73544a)
- Tested with: CONFIG_BACNETSTACK=y, CONFIG_BACDL_BIP=y, static IP via net_if_ipv4_addr_add()
File:
zephyr/subsys/bacnet_datalink/bip-init.cDescription
When a static IP is pre-configured via
bip_set_addr()andbip_set_broadcast_addr(), the functionbip_set_interface()callsnet_if_ipv4_set_netmask_by_addr()withBIP_Broadcast_Addras the netmask parameter. This corrupts the interface netmask, breaking all IP routing including ping.Affected code (bip-init.c ~line 491):
Function signature expects:
Impact
After
bip_set_interface()runs, the interface netmask is set to the broadcast address (e.g.192.255.255.255for a/8network). This breaks routing and makes the device unreachable via ping and unresponsive to BACnet discovery.Workaround
After
bacnet_port_init()returns, restore the correct netmask:Suggested Fix
Replace
BIP_Broadcast_Addrwith the actual netmask. A separate variableBIP_Netmaskshould be stored and used here, similar to how the Linux/BSD ports handle it.Environment