Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-4370: Filter out IP addresses added by keepalived #3552

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion go-controller/pkg/util/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net"
"reflect"
"strings"
"time"

"github.com/j-keck/arping"
Expand Down Expand Up @@ -470,6 +471,7 @@ func DeleteConntrack(ip string, port int32, protocol kapi.Protocol, ipFilterType
}

// GetNetworkInterfaceIPs returns the IP addresses for the network interface 'iface'.
// We filter out addresses that are link local, reserved for internal use or added by keepalived.
func GetNetworkInterfaceIPs(iface string) ([]*net.IPNet, error) {
link, err := netLinkOps.LinkByName(iface)
if err != nil {
Expand All @@ -483,7 +485,7 @@ func GetNetworkInterfaceIPs(iface string) ([]*net.IPNet, error) {

var ips []*net.IPNet
for _, addr := range addrs {
if addr.IP.IsLinkLocalUnicast() || IsAddressReservedForInternalUse(addr.IP) {
if addr.IP.IsLinkLocalUnicast() || IsAddressReservedForInternalUse(addr.IP) || IsAddressAddedByKeepAlived(addr) {
continue
}
// Ignore addresses marked as secondary or deprecated since they may
Expand Down Expand Up @@ -514,6 +516,13 @@ func IsAddressReservedForInternalUse(addr net.IP) bool {
return subnet.Contains(addr)
}

// IsAddressAddedByKeepAlived returns true if the input interface address obtained
// through netlink has a label that ends with ":vip", which is how keepalived
// marks the IP addresses it adds (https://github.com/openshift/machine-config-operator/pull/3683)
func IsAddressAddedByKeepAlived(addr netlink.Addr) bool {
return strings.HasSuffix(addr.Label, ":vip")
}

// GetIPv6OnSubnet when given an IPv6 address with a 128 prefix for an interface,
// looks for possible broadest subnet on-link routes and returns the same address
// with the found subnet prefix. Otherwise it returns the provided address unchanged.
Expand Down