Skip to content

stp: Fix IPC layout and netlink handling between STPMGR and STP daemon - #97

Open
rdhegde wants to merge 7 commits into
sonic-net:masterfrom
rdhegde:rdhegde-pvst-stp
Open

stp: Fix IPC layout and netlink handling between STPMGR and STP daemon#97
rdhegde wants to merge 7 commits into
sonic-net:masterfrom
rdhegde:rdhegde-pvst-stp

Conversation

@rdhegde

@rdhegde rdhegde commented Jul 25, 2026

Copy link
Copy Markdown

Summary

  • Unify duplicated IPC structures between STPMGR and STP daemon into a
    single, packed definition with all required fields.
  • Add sanity checks and error logging for invalid IPC messages and
    unexpected protocol modes.
  • Fix stp_netlink_recv() passing an invalid if_db / ifname into
    stp_netlink_cb().

Motivation

PVST configuration fails when STPMGR and the STP daemon exchange
inconsistent or incomplete IPC data, or when netlink callbacks operate on
invalid interface state. This PR fixes the daemon-side IPC and netlink
handling required for PVST to work reliably.

Part of PVST fix series for #28624.

Changes

  • IPC structures
    • Remove duplicate IPC definitions between STPMGR and STP daemon
    • Pack all IPC structures and add missing structure members
  • Error handling
    • Add sanity check in stp_intf_netlink_cb()
    • Add error logs in stpmgr_process_ipc_msg() for unexpected protocol modes
  • Netlink
    • Fix stp_netlink_recv() calling stp_netlink_cb() with invalid
      if_db / ifname

Related PRs

Repo PR
sonic-buildimage sonic-net/sonic-buildimage#28624
sonic-swss sonic-net/sonic-swss#4790
sonic-utilities sonic-net/sonic-utilities#4716

Verification

  • 3-node PVST topology (GNS3 sonic-vs): config reached STP daemon,
    PVST converged
  • Marvell Prestera switches: same PVST validation

Notes for reviewers

  • Start with shared IPC header/struct definitions, then netlink callback path
  • IPC packing changes affect STPMGR ↔ STP message layout; review together
    with sonic-swss#4790

rdhegde added 5 commits July 9, 2026 10:00
- Packed stp IPC structures
- Added missing parameter `loop_guard` to align with swss(stpmgr)
- Renamed parameters: `edge` and `max_hop` to align with swss(stpmgr)
- Renamed MST_INST_CONFIG_MSG to STP_MST_INST_CONFIG_MSG for consistency

Signed-off-by: Ram Hegde <rhegde@marvell.com>
- fix socket return handling
- remove unused variable

Signed-off-by: Ram Hegde <rhegde@marvell.com>
Signed-off-by: Ram Hegde <rhegde@marvell.com>
- uninitialized if_db.ifname is not handled before calling
  stp_netlink_cb()

Signed-off-by: Ram Hegde <rhegde@marvell.com>
Signed-off-by: Ram Hegde <rhegde@marvell.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 25, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@rdhegde

rdhegde commented Jul 25, 2026

Copy link
Copy Markdown
Author

/easycla

* In stpmgr_process_rx_bpdu(), when PVST BPDUs has no VLAN get the
  port's untagged VLAN
* Fixed typos in code comments

Signed-off-by: Ram Hegde <rhegde@marvell.com>
@rdhegde
rdhegde force-pushed the rdhegde-pvst-stp branch from 1aa8c23 to 334e762 Compare July 25, 2026 13:55
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@rdhegde rdhegde changed the title PVST bug fixes stp: Fix IPC layout and netlink handling between STPMGR and STP daemon Jul 28, 2026
@rdhegde

rdhegde commented Aug 20, 2026

Copy link
Copy Markdown
Author

PVST test report
pvst-testing.md

Comment thread stp/stp_mgr.c Outdated
}

// sanity checks
if (!IS_VALID_VLAN(vlan_id))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move if (!IS_VALID_VLAN(vlan_id)) inside else case

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move if (!IS_VALID_VLAN(vlan_id)) inside else case

Updated as suggested

Comment thread stp/stp_mgr.c Outdated
{
// When BPDUs arrive without VLAN get the VLAN from port's untagged vlan
// configuration.
if ( vlan_id == 0 ) {

@divyachandralekha divyachandralekha Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this if case. vlan decision is made inside stpmgr_rx_stp_bpdu.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this if case. vlan decision is made inside stpmgr_rx_stp_bpdu.

Moved the vlan_id resolution code in stpmgr_rx_pvst_bpdu(). The current code accessed vlan_id even before it was populated.

Comment thread stp/stp_netlink.c
if_db.ifname, if_db.kif_index, if_db.oper_state,
if_db.is_bond, if_db.is_member, if_db.master_ifindex);

stp_netlink_cb( &if_db,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if rt_list[IFLA_IFNAME] is not set , how RTM_NEWLINK is handled ?
This portion of code changes are not required. I dnt see any issue with RTM_DELLINK when IFLA_IFNAME is not set. stp_netlink_cb is done outside of if(rt_list[IFLA_IFNAME] ) condition. please check.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if rt_list[IFLA_IFNAME] is not set , how RTM_NEWLINK is handled ? This portion of code changes are not required. I dnt see any issue with RTM_DELLINK when IFLA_IFNAME is not set. stp_netlink_cb is done outside of if(rt_list[IFLA_IFNAME] ) condition. please check.

The current call to stp_netlink_cb() is outside nlmsg_type check which means it would be called for anything other than add and del also. I just re-arragned the code for correctness such that add is called only with valid if_name while del can be called without it.

Comment thread include/stp_ipc.h
} PORT_ATTR;
// Add padding to align to 4 bytes
uint16_t padding;
} __attribute__((packed)) PORT_ATTR;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is a similar header file in swss repo, please change that also.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the duplicate header definition from swss and made it use stp_ipc.h. Please look at the changes from sonic-net/sonic-swss#4790

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Ram Hegde <rhegde@marvell.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants