30 Commits

Author SHA1 Message Date
Aaron U'Ren
054d5d1ceb
feat(lint): add basic typos checker to ensure less spelling mistakes in the future 2026-03-15 13:44:32 -05:00
Cat C
440ad4d0a1 fix: Replace all netlink functions that throw ErrDumpInterrupted with a retry wrapper 2026-01-09 09:17:43 -06:00
ccoVeille
1e8976bd79 build(deps): update github.com/ccoveille/go-safecast to v2.0.0 2025-11-08 01:13:51 +01:00
ccoVeille
e8a59fda2e build(deps): bump github.com/ccoveille/go-safecast to 1.8.1 2025-11-03 12:04:58 +01:00
Aaron U'Ren
700620509f feat(DSR): disable routing DSR traffic via kube-bridge
This was originally added in PR #210, but it appears to cause more
problems in my testing scenarios than it solves. When this is enabled,
it makes it so that services cannot be routed to from kube workers to
DSR enabled services when routed to other nodes in the cluster.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
2ebcac62ec feat(linux_networking): add some additional logging 2025-06-29 17:42:18 -05:00
Aaron U'Ren
8504c52e80 fix(DSR): setup source routing for all external IPs
Previously, kube-router was only considering externalIPs when setting up
source routing policy, notably absent was consideration of LoadBalancer
IPs which are equally important for getting right with DSR.

This appears to have been a long-standing use-case that was never
correctly considered since when kube-router added a LoadBalancer
controller.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
e6edc853fb fix(ipAddrDel): check to see if IP exists on interface before delete
Rather than yolo'ing a delete of the IP on the interface, check to see
if it exists and save the user some warning in their logs.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
94bfc0d9ba fix(ipAddrDel): check for routes before trying to delete
Instead of deleting and just hoping for the best, this change makes it
so that we check first whether or not a route exists. This helps to
reduce needless warnings that the user receives and is just all around
more accurate.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
3c895955f7 fact(utils): factor out single subnet ip logic
Removes repeated logic of calculating IP address subnets for single
subnet hosts and consolidates it in one place.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
b070531ec5 fix: add proper nil rule src handling
When ip rules are evaluated in the netlink library, default routes for
src and dst are equated to nil. This makes it difficult to evaluate
them and requires additional handling in order for them.

I filed an issue upstream so that this could potentially get fixed:
https://github.com/vishvananda/netlink/issues/1080 however if it doesn't
get resolved, this should allow us to move forward.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
f2b0d785a0 fact: add ip utils library & add unit testing
Consolidate IP utility functions into a new file and add proper unit
testing. Additionally consolidate logic and references to default route
subnets.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
4795a07e7c fix(ip rule): use NewRule() for all rule creations
It has proven to be tricky to insert new rules without calling the
designated NewRule() function from the netlink library. Usually attempts
will fail with an operation not supported message.

This improves the reliability of rule insertion.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
56076051f8 fix(linux_networking.go): add scope to local routes
In order for a local route to be valid it needs to have the scope set to
host. When we were executing ip commands iproute2 just did this for us
to make the command accurate. Now that we're communicating with the
netlink socket, we need to do this conversion for ourselves.

Without this we get an error that says "invalid argument" from the
netlink subsystem. But if the route isn't local, then most of the
routing logic for services doesn't work correctly because it acts upon
external traffic as well as local traffic which isn't correct.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
80328ace67 fix(linux_networking.go): filter routes to be deleted by table
Previously we were accidentally deleting all routes that were found,
this mimics the previous functionality better by only deleting external
IPs that were found in the externalIPRouteTable that are no longer in
the activeExternalIPs map.

Also improves logging around any routes that are deleted as this is
likely of interest to all kube-router administrators.
2025-06-29 17:42:18 -05:00
Aaron U'Ren
f59a4f5ae8 feat: convert execs to ip to netlink calls
Not making direct exec calls to user binary interfaces has long been a
principle of kube-router. When kube-router was first coded, the netlink
library was missing significant features that forced us to exec out.
However, now netlink seems to have most of the functionality that we
need.

This converts all of the places where we can use netlink to use the
netlink functionality.
2025-06-29 17:42:18 -05:00
Manuel Rüger
6a1d15c24c Use golangci-lint 2.0.2 2025-04-23 22:56:24 +02:00
Aaron U'Ren
858fdf659d fix(lint): prevent against integer overflow errors 2025-02-14 14:18:26 -06:00
Aaron U'Ren
e8962dd8b2 fix(linux_networking.go): remove dangling IPv6 routes
Remove extra routes added by iproute2 when addresses are added to
interfaces which block IPv6 service VIPs from routing from the host.

See: https://github.com/cloudnativelabs/kube-router/issues/1698
2024-07-05 15:34:35 -05:00
Aaron U'Ren
567c891348 fix(linux_networking): add more information to errors 2024-04-27 13:28:09 -05:00
Aaron U'Ren
70920609dc fix(rt_tables): add path fallback logic
Ever since version v6.5.0 of iproute2, iproute2 no longer automatically
creates the /etc/iproute2 files, instead preferring to add files to
/usr/lib/iproute2 and then later on /usr/share/iproute2.

This adds fallback path matching to kube-router so that it can find
/etc/iproute2/rt_tables wherever it is defined instead of just failing.

This also means people running kube-router in containers will need to
change their mounts depending on where this file is located on their
host OS. However, ensuring that this file is copied to `/etc/iproute2`
is a legitimate way to ensure that this is consistent across a fleet of
multiple OS versions.
2024-03-25 18:56:23 -05:00
Aaron U'Ren
ced5102d99 feat(NSC): add IPVS service timeouts
This is a feature that has been requested a few times over the years and
would bring us closer to feature parity with other k8s network
implementations for service proxy.
2023-12-26 14:26:11 -06:00
Aaron U'Ren
eb462bae08 feat(linux_networking.go): add more error info
Direct people to a potentially missing hostPID attribute in their
kube-router deployment if they are getting a no such file or directory
message.
2023-12-08 17:01:48 -06:00
Aaron U'Ren
0f3714b9b7 fix(hairpin): set hairpin_mode for veth iface
It used to be that the kubelet handled setting hairpin mode for us:
https://github.com/kubernetes/kubernetes/pull/13628

Then this functionality moved to the dockershim:
https://github.com/kubernetes/kubernetes/pull/62212

Then the functionality was removed entirely:
https://github.com/kubernetes/kubernetes/commit/83265c9171f

Unfortunately, it was lost that we ever depended on this in order for
our hairpin implementation to work, if we ever knew it at all.
Additionally, I suspect that containerd and cri-o implementations never
worked correctly with hairpinning.

Without this, the NAT rules that we implement for hairpinning don't work
correctly. Because hairpin_mode isn't implemented on the virtual
interface of the container on the host, the packet bubbles up to the
kube-bridge. At some point in the traffic flow, the route back to the
pod gets resolved to the mac address inside the container, at that
point, the packet's source mac and destination mac don't match the
kube-bridge interface and the packet is black-holed.

This can also be fixed by putting the kube-bridge interface into
promiscuous mode so that it accepts all mac addresses, but I think that
going back to the original functionality of enabling hairpin_mode on the
veth interface of the container is likely the lesser of two evils here
as putting the kube-bridge interface into promiscuous mode will likely
have unintentional consequences.
2023-12-07 12:44:51 -06:00
Aaron U'Ren
1a891c33ee fix(dsr): add family specific link inside pod
For IPv6 we need to have family specific links inside the pod to receive
the ip6ip6 and ipip traffic that we are sending.
2023-10-07 08:52:31 -05:00
Aaron U'Ren
514a8af7ed fix(dsr): add family for fwmark 2023-10-07 08:52:31 -05:00
Aaron U'Ren
9f23cf5a6e fix(linux_networking.go): add better error messages 2023-10-07 08:52:31 -05:00
Aaron U'Ren
7ce09a64d9 fix(linux_networking.go): don't return err on warn 2023-10-07 08:52:31 -05:00
Aaron U'Ren
c62e1b7902 feat(linux_networking.go): add more logging info
Adds more logging information (in the form of warnings) when we come
across common errors that are not big enough to stop processing, but
will still confuse users when the error gets bubbled up to NSC.
2023-10-07 08:52:31 -05:00
Aaron U'Ren
25ecb098c6 feat(nsc): add dualstack capabilities 2023-10-07 08:52:31 -05:00