Conversation
WalkthroughThis PR refactors the ChangesRoute Structure and Initialization Refactoring
🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)src/dhcpcd.cIn file included from src/dhcpcd.c:53: ... [truncated 769 characters] ... src/dhcp.cIn file included from src/dhcp.c:63: ... [truncated 763 characters] ... m" src/if-bsd.csrc/if-bsd.c:34:10: fatal error: 'sys/sysctl.h' file not found ... [truncated 670 characters] ...
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/ipv4.c (1)
324-329:⚠️ Potential issue | 🟠 Major | ⚡ Quick winUse
rt_copyinstead of rawmemcpy.Line 328 is no longer safe after the
struct rtrefactor.memcpy(rt, r, sizeof(*rt))copiesrt_dest/rt_netmask/rt_gateway/rt_ifaas-is, so this clone keeps pointing atr'srt_ss_*storage instead of its own. The latersa_in_init(rt->rt_ifa, ...)in this function then mutates the source route, and the copied route will dangle once the source tree is freed. Use the new route copy helper here.Suggested fix
- memcpy(rt, r, sizeof(*rt)); + rt_copy(rt, r);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/ipv4.c` around lines 324 - 329, Replace the raw memcpy(rt, r, sizeof(*rt)) with the route copy helper: allocate the new route via rt_new0(ifp->ctx) as you do, then call rt_copy(rt, r) (checking its return for error if rt_copy returns non-zero/NULL) to duplicate all internal sa storage safely, and then call rt_setif(rt, ifp); remove the memcpy line and any code that assumes the memcpy behavior (e.g., do not rely on shared rt_ss_* storage); keep the surrounding checks (sa_is_unspecified, rt_new0) as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/ipv4ll.c`:
- Around line 512-513: The callback currently returns early when
sa_is_unspecified(rt->rt_dest) is true, which incorrectly skips handling the
default-route case; invert the check so the function returns early only for
non-default routes by negating the sa_is_unspecified(rt->rt_dest) condition
(i.e., return 0 when rt->rt_dest is NOT unspecified) so the default-route
updates are processed while unrelated route updates are ignored.
- Line 120: Replace the invalid designated initializer for struct in_addr by
using the correct syntax (use .s_addr = INADDR_ANY) where the variable `in` is
declared; in `ipv4ll_recvrt()` invert the default-route early-return so the
function does not skip processing when `rt_dest` is unspecified, and
additionally gate this check by testing that `rt_netmask` is also unspecified
(or call/check `rt_is_default()`), ensuring default-route entries created by
`ipv4ll_defaultroute()` cause the route table to be rebuilt rather than being
ignored.
---
Outside diff comments:
In `@src/ipv4.c`:
- Around line 324-329: Replace the raw memcpy(rt, r, sizeof(*rt)) with the route
copy helper: allocate the new route via rt_new0(ifp->ctx) as you do, then call
rt_copy(rt, r) (checking its return for error if rt_copy returns non-zero/NULL)
to duplicate all internal sa storage safely, and then call rt_setif(rt, ifp);
remove the memcpy line and any code that assumes the memcpy behavior (e.g., do
not rely on shared rt_ss_* storage); keep the surrounding checks
(sa_is_unspecified, rt_new0) as-is.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b70e511b-c24c-4860-abd6-e0be11b3f0ef
📒 Files selected for processing (13)
src/dhcp.csrc/dhcpcd.csrc/if-bsd.csrc/if-linux.csrc/if-options.csrc/if-sun.csrc/ipv4.csrc/ipv4ll.csrc/ipv6.csrc/route.csrc/route.hsrc/sa.csrc/sa.h
💤 Files with no reviewable changes (1)
- src/sa.h
For each sockaddr, put a sockaddr_storage in the rt and reference it. This removes the need of a union and the macro dance around it.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/sa.c (1)
284-290: 💤 Low valueStatic analyzer false positive on sockaddr_storage initialization.
Cppcheck flags line 288 for an uninitialized variable, but the code is correct: C99 designated initializers zero-fill all unspecified members, so the entire
ssstructure exceptss_familyis zeroed. The subsequentsa_fromprefixcall will populate the address bytes and (ifHAVE_SA_LENis defined) setsa_len.If you want to silence the static analyzer warning explicitly, consider:
📝 Optional: more explicit initialization
- struct sockaddr_storage ss = { .ss_family = sa->sa_family }; - struct sockaddr *ss_sa = (struct sockaddr *)&ss; + struct sockaddr_storage ss; + struct sockaddr *ss_sa = (struct sockaddr *)&ss; + memset(&ss, 0, sizeof(ss)); + ss.ss_family = sa->sa_family; sa_inprefix = true;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/sa.c` around lines 284 - 290, Cppcheck reports a false positive for uninitialized bytes in struct sockaddr_storage `ss` despite using a designated initializer; to silence this, explicitly zero the structure before setting the family: replace the `struct sockaddr_storage ss = { .ss_family = sa->sa_family };` pattern with an explicit zero-init (e.g., `struct sockaddr_storage ss; memset(&ss, 0, sizeof ss); ss.ss_family = sa->sa_family;`) so `sa_fromprefix`, `sa_cmp`, and the `ss` usage are unambiguously initialized; alternatively, if you prefer suppressing the analyzer, add a localized cppcheck suppression comment near the `ss` declaration (e.g., `/* cppcheck-suppress uninitvar */`) referencing `ss`, but do not change the subsequent calls to `sa_fromprefix`, `sa_cmp`, or the `sa_inprefix` toggling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/sa.c`:
- Around line 284-290: Cppcheck reports a false positive for uninitialized bytes
in struct sockaddr_storage `ss` despite using a designated initializer; to
silence this, explicitly zero the structure before setting the family: replace
the `struct sockaddr_storage ss = { .ss_family = sa->sa_family };` pattern with
an explicit zero-init (e.g., `struct sockaddr_storage ss; memset(&ss, 0, sizeof
ss); ss.ss_family = sa->sa_family;`) so `sa_fromprefix`, `sa_cmp`, and the `ss`
usage are unambiguously initialized; alternatively, if you prefer suppressing
the analyzer, add a localized cppcheck suppression comment near the `ss`
declaration (e.g., `/* cppcheck-suppress uninitvar */`) referencing `ss`, but do
not change the subsequent calls to `sa_fromprefix`, `sa_cmp`, or the
`sa_inprefix` toggling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2cd21565-ae64-4cbb-852e-e44a315bf1a2
📒 Files selected for processing (13)
src/dhcp.csrc/dhcpcd.csrc/if-bsd.csrc/if-linux.csrc/if-options.csrc/if-sun.csrc/ipv4.csrc/ipv4ll.csrc/ipv6.csrc/route.csrc/route.hsrc/sa.csrc/sa.h
💤 Files with no reviewable changes (1)
- src/sa.h
🚧 Files skipped from review as they are similar to previous changes (11)
- src/dhcpcd.c
- src/ipv6.c
- src/dhcp.c
- src/if-linux.c
- src/ipv4ll.c
- src/if-options.c
- src/route.h
- src/ipv4.c
- src/if-bsd.c
- src/if-sun.c
- src/route.c
For each sockaddr, put a sockaddr_storage in the rt and reference it.
This removes the need of a union and the macro dance around it.