Skip to content

Commit 97f10c9

Browse files
authored
Merge pull request #9 from cozystack/fix/cilium-tunl0-fallback
fix(encapsulation): fall back to tunl0 when cilium_tunl is absent
2 parents c373706 + 858c628 commit 97f10c9

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

pkg/encapsulation/cilium.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import (
2727
const (
2828
ciliumHostIface = "cilium_host"
2929
// ciliumTunlIface is the kernel's default IPIP tunnel (tunl0) renamed
30-
// by Cilium when enable-ipip-termination is active. Unlike cilium_ipip4,
31-
// which is receive-only (for DSR), cilium_tunl supports both TX and RX.
30+
// by Cilium when enable-ipip-termination is enabled.
3231
ciliumTunlIface = "cilium_tunl"
3332
)
3433

@@ -92,17 +91,24 @@ func (c *cilium) Index() int {
9291
}
9392

9493
// Init initializes the IPIP tunnel interface.
95-
// When Cilium's enable-ipip-termination is active, it renames the kernel's
96-
// tunl0 to cilium_tunl and creates a receive-only cilium_ipip4 device.
97-
// We use cilium_tunl because it supports both sending and receiving IPIP
98-
// traffic, whereas cilium_ipip4 only handles incoming packets (DSR).
94+
// If Cilium is running with enable-ipip-termination, it renames the kernel's
95+
// tunl0 to cilium_tunl. In that case we reuse the existing cilium_tunl.
96+
// Otherwise we create the standard tunl0 ourselves.
9997
func (c *cilium) Init(base int) error {
98+
// If Cilium created cilium_tunl (enable-ipip-termination), reuse it.
10099
if link, err := netlink.LinkByName(ciliumTunlIface); err == nil {
101100
c.iface = link.Attrs().Index
102101
c.ownsTunnel = false
102+
// Ensure the interface is UP — Cilium may leave it DOWN.
103+
if link.Attrs().Flags&net.FlagUp == 0 {
104+
if err := iproute.Set(c.iface, true); err != nil {
105+
return fmt.Errorf("failed to set %s up: %v", ciliumTunlIface, err)
106+
}
107+
}
103108
return nil
104109
}
105-
iface, err := iproute.NewIPIPWithName(base, ciliumTunlIface)
110+
// No cilium_tunl — create standard tunl0.
111+
iface, err := iproute.NewIPIP(base)
106112
if err != nil {
107113
return fmt.Errorf("failed to create tunnel interface: %v", err)
108114
}

0 commit comments

Comments
 (0)