Skip to content

Commit

Permalink
cmd, datapath: Support --devices for encryption interfaces
Browse files Browse the repository at this point in the history
The agent supported attaching the IPsec decryption logic to interfaces
given via --devices. In that case, this logic was contained in bpf_host
instead of bpf_network. This support is partially covered in ginkgo
end-to-end tests.

That support is however broken, as there doesn't seem to be anything
preventing bpf_network from being reloaded in place of bpf_host on the
same interfaces.

This commit fixes it by implementing proper support for --devices in
IPsec. If no devices flag is given then we fallback to using the
encrypt-interface flag. That should allow us to deprecate
encrypt-interface at a latter time.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
  • Loading branch information
pchaigno committed Mar 25, 2024
1 parent 4687325 commit 3c6f957
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions daemon/cmd/daemon_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ func initEnv(vp *viper.Viper) {
if option.Config.EnableIPSec &&
!option.Config.TunnelingEnabled() &&
len(option.Config.EncryptInterface) == 0 &&
len(option.Config.GetDevices()) == 0 &&
option.Config.IPAM != ipamOption.IPAMENI {
link, err := linuxdatapath.NodeDeviceNameWithDefaultRoute()
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions pkg/datapath/linux/ipsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ func (n *linuxNodeHandler) getDefaultEncryptionInterface() string {
if option.Config.TunnelingEnabled() {
return n.datapathConfig.TunnelDevice
}
iface := ""
devices := option.Config.GetDevices()
if len(devices) > 0 {
return devices[0]
}
if len(option.Config.EncryptInterface) > 0 {
iface = option.Config.EncryptInterface[0]
return option.Config.EncryptInterface[0]
}
return iface
return ""
}

func (n *linuxNodeHandler) getLinkLocalIP(family int) (net.IP, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/datapath/loader/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func cleanIngressQdisc() error {

// reinitializeIPSec is used to recompile and load encryption network programs.
func (l *loader) reinitializeIPSec(ctx context.Context) error {
if !option.Config.EnableIPSec {
// If devices are specified, then we are relying on autodetection and don't
// need the code below, specific to EncryptInterface.
if !option.Config.EnableIPSec || len(option.Config.GetDevices()) > 0 {
return nil
}

Expand Down

0 comments on commit 3c6f957

Please sign in to comment.