Skip to content

vrrrpd: improve error handling in several paths - #21251

Merged
Jafaral merged 3 commits into
FRRouting:masterfrom
mjstapp:fix_vrrp_pkts
Mar 20, 2026
Merged

vrrrpd: improve error handling in several paths#21251
Jafaral merged 3 commits into
FRRouting:masterfrom
mjstapp:fix_vrrp_pkts

Conversation

@mjstapp

@mjstapp mjstapp commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Improve and harden some error-condition handling in several paths, especially packet-processing. Replace several asserts with logs and/or error returns.

@frrbot frrbot Bot added the vrrp label Mar 18, 2026
@greptile-apps

greptile-apps Bot commented Mar 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens error handling across the vrrpd packet-processing and socket-setup paths by replacing hard assert() calls with graceful log-and-return patterns, which improves daemon resilience against unexpected runtime conditions.

Key changes:

  • vrrp.c: assert(c) in vrrp_socket replaced with zlog_err + goto done when no valid INET address is found; incoming VRRPv3 adver_int values are now masked with 0x0FFF to enforce the 12-bit field boundary defined in RFC 5798.
  • vrrp_arp.c: assert(r->family == AF_INET) in vrrp_garp_send_all replaced with zlog_warn + early return; vrrp_build_garp now uses the constant ETH_ALEN instead of ifp->hw_addr_len, which correctly matches the fixed-size GARP_BUFFER_SIZE buffer and prevents a potential overrun on interfaces with non-standard hardware address lengths.
  • vrrp_ndisc.c: assert(r->family == AF_INET6) in vrrp_ndisc_una_send replaced with zlog_warn + return -1; the corresponding assert in vrrp_ndisc_una_send_all is removed but no equivalent early-return guard is added at that level, creating a minor inconsistency with the treatment of vrrp_garp_send_all.
  • vrrp_packet.c: Two asserts replaced β€” one in vrrp_pkt_checksum (invalid version β†’ return chksum_pre+1 to guarantee checksum mismatch) and one in vrrp_pkt_parse_datagram (unknown family β†’ VRRP_PKT_VCHECK(false, ...)).

Confidence Score: 4/5

  • PR is safe to merge; all changes improve robustness by replacing crash-inducing asserts with graceful log-and-return paths, with one minor consistency gap in vrrp_ndisc.c.
  • All assert-to-log replacements are correct and the logic is sound. The ETH_ALEN fix in vrrp_build_garp closes a latent buffer-offset inconsistency. The only notable gap is that vrrp_ndisc_una_send_all lacks the same early-return family guard added to vrrp_garp_send_all, which could produce redundant warning log lines on a wrong-family call β€” a style/consistency issue, not a correctness bug. No new logic bugs or regressions are introduced.
  • vrrpd/vrrp_ndisc.c β€” missing early-return family check in vrrp_ndisc_una_send_all for consistency with the vrrp_garp_send_all treatment.

Important Files Changed

Filename Overview
vrrpd/vrrp.c Replaces an assert(c) with a graceful error log + goto done when no valid INET address is found during socket setup; also adds a 0x0FFF mask to master_adver_interval when receiving VRRPv3 advertisements to properly enforce the 12-bit field boundary.
vrrpd/vrrp_arp.c Replaces assert(r->family == AF_INET) in vrrp_garp_send_all with a zlog_warn + early return; also corrects vrrp_build_garp to use the constant ETH_ALEN instead of ifp->hw_addr_len, keeping ARP payload offsets consistent with the fixed GARP_BUFFER_SIZE macro and preventing a potential buffer overrun with non-6-byte hw addresses.
vrrpd/vrrp_ndisc.c Replaces assert(r->family == AF_INET6) in vrrp_ndisc_una_send with a zlog_warn + return -1; removes the assert from vrrp_ndisc_una_send_all but does NOT add an equivalent early-return guard there, creating an inconsistency with the vrrp_garp_send_all treatment and risking N warning logs on a wrong-family call.
vrrpd/vrrp_packet.c Replaces assert(!"Invalid VRRP protocol version") in vrrp_pkt_checksum with chksum = chksum_pre + 1 (ensuring checksum validation always fails for an invalid version); replaces assert(!"Unknown address family") in vrrp_pkt_parse_datagram with VRRP_PKT_VCHECK(false, ...) for consistent graceful error handling.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Receive VRRP Packet] --> B[vrrp_pkt_parse_datagram]
    B --> C{family == AF_INET\nor AF_INET6?}
    C -- "neither" --> D["VRRP_PKT_VCHECK(false)\nreturn -1\n(was: assert)"]
    C -- "AF_INET/AF_INET6" --> E[Version & Size Checks]
    E --> F[vrrp_pkt_checksum]
    F --> G{Valid version\nin packet?}
    G -- "invalid" --> H["return chksum_pre+1\n(checksum mismatch guaranteed)\n(was: assert)"]
    G -- "valid" --> I[Compute real checksum]
    I --> J[Checksum Match?]
    J -- "no" --> K[return -1]
    J -- "yes" --> L[vrrp_recv_advertisement]
    L --> M{VRRPv3?}
    M -- "yes" --> N["master_adver_interval &= 0x0FFF\n(enforce 12-bit field)"]
    N --> O[vrrp_recalculate_timers]
    M -- "no" --> O

    subgraph Socket Setup
        P[vrrp_socket] --> Q{IPv4 address\nfound on iface?}
        Q -- "no" --> R["zlog_err + goto done\n(was: assert)"]
        Q -- "yes" --> S[setsockopt multicast join]
    end

    subgraph Gratuitous ARP
        T[vrrp_garp_send_all] --> U{family == AF_INET?}
        U -- "no" --> V["zlog_warn + return\n(was: assert)"]
        U -- "yes" --> W[vrrp_garp_send]
    end

    subgraph Neighbor Discovery
        X[vrrp_ndisc_una_send_all] --> Y[vrrp_ndisc_una_send per addr]
        Y --> Z{family == AF_INET6?}
        Z -- "no" --> AA["zlog_warn + return -1\n(was: assert)"]
        Z -- "yes" --> AB[Send ND packet]
    end
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: vrrpd/vrrp_ndisc.c
Line: 193-201

Comment:
**Missing early-return family guard in `_send_all`**

The companion function `vrrp_garp_send_all` in `vrrp_arp.c` received an explicit family check with a single `zlog_warn` and an early return. `vrrp_ndisc_una_send_all` had its `assert` removed but received no equivalent guard. If this function is called with `r->family != AF_INET6` and `r->addrs` contains N addresses, `vrrp_ndisc_una_send` will fire N separate warning log lines instead of one. Adding an early-return check here keeps the two `_send_all` functions consistent:

```suggestion
int vrrp_ndisc_una_send_all(struct vrrp_router *r)
{
	struct listnode *ln;
	struct ipaddr *ip;

	if (r->family != AF_INET6) {
		zlog_warn(VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
			  "Unable to send unsolicited Neighbor Advertisements on %s: not INET6",
			  r->vr->vrid, family2str(r->family),
			  r->mvl_ifp->name);
		return -1;
	}

	for (ALL_LIST_ELEMENTS_RO(r->addrs, ln, ip))
		vrrp_ndisc_una_send(r, ip);

	return 0;
}
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "vrrpd: replace some ..."

Comment thread vrrpd/vrrp.c Outdated
Comment thread vrrpd/vrrp.c Outdated
Mark Stapp added 3 commits March 18, 2026 16:01
Ensure advertised vrrpv3 timers are limited to 12 bits.

Signed-off-by: Mark Stapp <mjs@cisco.com>
Don't mix explicit ethernet and per-interface hw values;
we only support ethernet for g-ARP messages.

Signed-off-by: Mark Stapp <mjs@cisco.com>
Replace several asserts with error returns, especially in
packet-processing paths.

Signed-off-by: Mark Stapp <mjs@cisco.com>
@mjstapp

mjstapp commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

cleaned up a couple of greptile comments

@mjstapp

mjstapp commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@Jafaral

Jafaral commented Mar 19, 2026

Copy link
Copy Markdown
Member

@Mergifyio backport stable/10.6 stable/10.5 stable/10.4 stable/10.3 stable/10.2

@mergify

mergify Bot commented Mar 19, 2026

Copy link
Copy Markdown

backport stable/10.6 stable/10.5 stable/10.4 stable/10.3 stable/10.2

βœ… Backports have been created

Details

@Jafaral
Jafaral merged commit 6503ac5 into FRRouting:master Mar 20, 2026
20 checks passed
ton31337 added a commit that referenced this pull request Mar 20, 2026
vrrrpd: improve error handling in several paths (backport #21251)
ton31337 added a commit that referenced this pull request Mar 20, 2026
vrrrpd: improve error handling in several paths (backport #21251)
ton31337 added a commit that referenced this pull request Mar 20, 2026
vrrrpd: improve error handling in several paths (backport #21251)
ton31337 added a commit that referenced this pull request Mar 20, 2026
vrrrpd: improve error handling in several paths (backport #21251)
ton31337 added a commit that referenced this pull request Mar 20, 2026
vrrrpd: improve error handling in several paths (backport #21251)
@mjstapp
mjstapp deleted the fix_vrrp_pkts branch June 1, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants