Skip to content

Commit

Permalink
datapath: Move IPsec logic to get local IPs
Browse files Browse the repository at this point in the history
Those helper functions to retrieve the local IPs are all IPsec specific
so let's move them to the ipsec.go file. No functional changes in this
commit.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
  • Loading branch information
pchaigno committed Mar 25, 2024
1 parent 72ad54e commit bee8535
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
34 changes: 34 additions & 0 deletions pkg/datapath/linux/ipsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ import (
"github.com/cilium/cilium/pkg/option"
)

// getDefaultEncryptionInterface() is needed to find the interface used when
// populating neighbor table and doing arpRequest. For most configurations
// there is only a single interface so choosing [0] works by choosing the only
// interface. However EKS, uses multiple interfaces, but fortunately for us
// in EKS any interface would work so pick the [0] index here as well.
func getDefaultEncryptionInterface() string {
iface := ""
if len(option.Config.EncryptInterface) > 0 {
iface = option.Config.EncryptInterface[0]
}
return iface
}

func getLinkLocalIP(family int) (net.IP, error) {
iface := getDefaultEncryptionInterface()
link, err := netlink.LinkByName(iface)
if err != nil {
return nil, err
}
addr, err := netlink.AddrList(link, family)
if err != nil {
return nil, err
}
return addr[0].IPNet.IP, nil
}

func getV4LinkLocalIP() (net.IP, error) {
return getLinkLocalIP(netlink.FAMILY_V4)
}

func getV6LinkLocalIP() (net.IP, error) {
return getLinkLocalIP(netlink.FAMILY_V6)
}

func upsertIPsecLog(err error, spec string, loc, rem *net.IPNet, spi uint8, nodeID uint16) error {
scopedLog := log.WithFields(logrus.Fields{
logfields.Reason: spec,
Expand Down
34 changes: 0 additions & 34 deletions pkg/datapath/linux/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,40 +926,6 @@ func (n *linuxNodeHandler) DeleteMiscNeighbor(oldNode *nodeTypes.Node) {
n.deleteNeighbor(oldNode)
}

// getDefaultEncryptionInterface() is needed to find the interface used when
// populating neighbor table and doing arpRequest. For most configurations
// there is only a single interface so choosing [0] works by choosing the only
// interface. However EKS, uses multiple interfaces, but fortunately for us
// in EKS any interface would work so pick the [0] index here as well.
func getDefaultEncryptionInterface() string {
iface := ""
if len(option.Config.EncryptInterface) > 0 {
iface = option.Config.EncryptInterface[0]
}
return iface
}

func getLinkLocalIP(family int) (net.IP, error) {
iface := getDefaultEncryptionInterface()
link, err := netlink.LinkByName(iface)
if err != nil {
return nil, err
}
addr, err := netlink.AddrList(link, family)
if err != nil {
return nil, err
}
return addr[0].IPNet.IP, nil
}

func getV4LinkLocalIP() (net.IP, error) {
return getLinkLocalIP(netlink.FAMILY_V4)
}

func getV6LinkLocalIP() (net.IP, error) {
return getLinkLocalIP(netlink.FAMILY_V6)
}

// Must be called with linuxNodeHandler.mutex held.
func (n *linuxNodeHandler) nodeUpdate(oldNode, newNode *nodeTypes.Node, firstAddition bool) error {
var (
Expand Down

0 comments on commit bee8535

Please sign in to comment.