Skip to content

Commit 6b60170

Browse files
netdeverAnthony Timmins
andauthored
Support /32 tunnel-source (#5144)
There exists a use case for sourcing tunnel traffic from a /32 address assigned to the lo interface of the node. The lo interface typically comes with a localhost address (ie. 127.0.0.1). This change excludes localhost addresses from acting as the tunnel source. It also permits using a /32 address for the tunnel source if the host-tunnel-src variable is set to true (false by default). Signed-off-by: Anthony Timmins <anthony.timmins@crowdstrike.com> --------- Signed-off-by: Anthony Timmins <anthony.timmins@crowdstrike.com> Signed-off-by: netdever <46330739+netdever@users.noreply.github.com> Co-authored-by: Anthony Timmins <anthony.timmins@crowdstrike.com>
1 parent 7c8c730 commit 6b60170

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/daemon/config.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Configuration struct {
3838
// interface being used for tunnel
3939
tunnelIface string
4040
Iface string
41+
HostTunnelSrc bool
4142
DPDKTunnelIface string
4243
MTU int
4344
MSS int
@@ -87,6 +88,7 @@ func ParseFlags() *Configuration {
8788

8889
argNodeName = pflag.String("node-name", "", "Name of the node on which the daemon is running on.")
8990
argIface = pflag.String("iface", "", "The iface used to inter-host pod communication, can be a nic name or a group of regex separated by comma (default the default route iface)")
91+
argHostTunnelSrc = pflag.Bool("host-tunnel-src", false, "Enable /32 address selection for the tunnel source, excludes localhost addresses unless explicitly allowed.")
9092
argDPDKTunnelIface = pflag.String("dpdk-tunnel-iface", "br-phy", "Specifies the name of the dpdk tunnel iface.")
9193
argMTU = pflag.Int("mtu", 0, "The MTU used by pod iface in overlay networks (default iface MTU - 100)")
9294
argEnableMirror = pflag.Bool("enable-mirror", false, "Enable traffic mirror (default false)")
@@ -147,6 +149,7 @@ func ParseFlags() *Configuration {
147149
CniConfFile: *argCniConfFile,
148150
CniConfName: *argsCniConfName,
149151
Iface: *argIface,
152+
HostTunnelSrc: *argHostTunnelSrc,
150153
DPDKTunnelIface: *argDPDKTunnelIface,
151154
MTU: *argMTU,
152155
EnableMirror: *argEnableMirror,
@@ -257,17 +260,19 @@ func (config *Configuration) initNicConfig(nicBridgeMappings map[string]string)
257260
for _, addr := range addrs {
258261
_, ipCidr, err := net.ParseCIDR(addr.String())
259262
if err != nil {
260-
klog.Errorf("Failed to parse CIDR address %s: %v", addr.String(), err)
263+
klog.Errorf("Failed to parse CIDR address %s: %v, skipping", addr.String(), err)
261264
continue
262265
}
263-
// exclude the vip as encap ip
264-
if ones, bits := ipCidr.Mask.Size(); ones == bits {
266+
// exclude the vip as encap ip unless host-tunnel-src is true
267+
if ones, bits := ipCidr.Mask.Size(); ones == bits && !config.HostTunnelSrc {
265268
klog.Infof("Skip address %s", ipCidr.String())
266269
continue
267270
}
268271

272+
// exclude link-local and localhost addresses
269273
ipStr := strings.Split(addr.String(), "/")[0]
270-
if ip := net.ParseIP(ipStr); ip == nil || ip.IsLinkLocalUnicast() {
274+
_, localhost, _ := net.ParseCIDR("127.0.0.0/8")
275+
if ip := net.ParseIP(ipStr); ip == nil || ip.IsLinkLocalUnicast() || localhost.Contains(ip) {
271276
continue
272277
}
273278
if len(srcIPs) == 0 || slices.Contains(srcIPs, ipStr) {

0 commit comments

Comments
 (0)