Skip to content

net_if_ipv4_set_netmask_by_addr() called with broadcast address instead of netmask in bip-init.c** #69

@salimzedni

Description

@salimzedni

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions