core: services: cable_guy: api: manager: Remove subnet from deleted IP - #3996
core: services: cable_guy: api: manager: Remove subnet from deleted IP#3996patrickelectric wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
_remove_orphaned_subnet_routehelper hardcodes a /24 prefix, which may not match the actual prefix of the removed IP; consider deriving the subnet from the interface’s configured prefix instead of assuming /24. - In
_remove_orphaned_subnet_route, you useIPv4Addressand the string literal"0.0.0.0"; ifweak_is_ip_addresscan return true for IPv6 addresses, this path will fail—add an explicit IPv4-only guard or handle IPv6 routes separately. - When filtering out kernel-maintained routes in
get_routes, you directly indexraw_route["proto"]; for robustness against unexpected netlink messages, consider usingraw_route.get("proto")and handling missing or unknown values gracefully.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `_remove_orphaned_subnet_route` helper hardcodes a /24 prefix, which may not match the actual prefix of the removed IP; consider deriving the subnet from the interface’s configured prefix instead of assuming /24.
- In `_remove_orphaned_subnet_route`, you use `IPv4Address` and the string literal `"0.0.0.0"`; if `weak_is_ip_address` can return true for IPv6 addresses, this path will fail—add an explicit IPv4-only guard or handle IPv6 routes separately.
- When filtering out kernel-maintained routes in `get_routes`, you directly index `raw_route["proto"]`; for robustness against unexpected netlink messages, consider using `raw_route.get("proto")` and handling missing or unknown values gracefully.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Automated PR Review0. Summary
Adds 1. Correctness & Implementation Bugs
6. Code Quality & Style
7. Tests
8. Documentation
Generated by PR Review Bot. This is advisory, a human reviewer must still approve. |
| # Kernel-maintained connected routes are created/removed automatically alongside their | ||
| # interface addresses. Adopting them would turn them into persistent routes | ||
| # that outlive their IP, so we ignore them entirely. | ||
| if raw_route["proto"] == rtprotos["RTPROT_KERNEL"]: |
There was a problem hiding this comment.
I remember seeing a forever-growing list in some scenarios, and I think this must be it.
Delete the orphaned route on IP removal and scrub it from saved settings for good. Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
…utes
The kernel auto-creates and auto-removes connected routes (proto kernel)
alongside their interface address. cable_guy was reading them back and
persisting them, so they got re-added as proto-static routes the kernel no
longer manages, leaving orphaned /24s that outlived their IP and hijacked
the subnet. Ignore RTPROT_KERNEL routes entirely and let the kernel own
their lifecycle.
Btw, here is a penguin:
/~~~~~~\
/' -s- ~~~~\
/'dHHb ~~~~
/'dHHHA :
/' VHHHHaadHHb:
/' `VHHHHHHHHb:
/' `VHHHHHHH:
/' dHHHHHHH:
| dHHHHHHHH:
| dHHHHHHHH:
| VHHHHHHHHH:
| b HHHHHHHHV:
| Hb HHHHHHHV'
| HH dHHHHHHV'
| VHbdHHHHHHV'
| VHHHHHHHV'
\ VHHHHHHH:
\oodboooooodH
HHHHHHHHHHHHHHHHHHHHHHHHGGN94
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
7f9e402 to
ae7530d
Compare
joaoantoniocardoso
left a comment
There was a problem hiding this comment.
Some small changes to keep the IPv6 compatibility on the routes API.
| if not self.weak_is_ip_address(ip_address) or ip_address == "0.0.0.0": | ||
| return |
There was a problem hiding this comment.
| if not self.weak_is_ip_address(ip_address) or ip_address == "0.0.0.0": | |
| return | |
| # parse | |
| try: | |
| addr = ip_address(ip_address) | |
| except ValueError: | |
| return | |
| # check | |
| if addr.is_unspecified: | |
| return |
| return | ||
|
|
||
| # /24 mirrors the prefix used when adding/removing static IPs | ||
| subnet = ip_network(f"{ip_address}/24", strict=False) |
There was a problem hiding this comment.
| subnet = ip_network(f"{ip_address}/24", strict=False) | |
| prefixlen = 24 if addr.version == 4 else 64 | |
| subnet = ip_network((addr, prefixlen), strict=False) |
| if any(self.weak_is_ip_address(address.ip) and IPv4Address(address.ip) in subnet for address in remaining): | ||
| return |
There was a problem hiding this comment.
| if any(self.weak_is_ip_address(address.ip) and IPv4Address(address.ip) in subnet for address in remaining): | |
| return | |
| for address in remaining: | |
| # parse | |
| try: | |
| other = ipaddress.ip_address(address.ip) | |
| except ValueError: | |
| continue | |
| # check | |
| if other.version == addr.version and other in subnet: | |
| return |
Delete the orphaned route on IP removal and scrub it from saved settings for good.
Summary by Sourcery
Clean up orphaned subnet routes when removing IP addresses and avoid persisting kernel-managed connected routes.
Bug Fixes: