/
cell.go
67 lines (59 loc) · 1.49 KB
/
cell.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package mtu
import (
"github.com/cilium/cilium/daemon/cmd/cni"
"github.com/cilium/cilium/pkg/datapath/tunnel"
"github.com/cilium/cilium/pkg/datapath/types"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/node"
"github.com/cilium/cilium/pkg/option"
)
var Cell = cell.Module(
"mtu",
"MTU discovery",
cell.Provide(newForCell),
)
type MTU interface {
GetDeviceMTU() int
GetRouteMTU() int
GetRoutePostEncryptMTU() int
}
type mtuParams struct {
cell.In
LocalNode *node.LocalNodeStore
IPsec types.IPsecKeyCustodian
CNI cni.CNIConfigManager
TunnelConfig tunnel.Config
}
func newForCell(lc cell.Lifecycle, p mtuParams) MTU {
c := &Configuration{}
lc.Append(cell.Hook{
OnStart: func(ctx cell.HookContext) error {
node, err := p.LocalNode.Get(ctx)
if err != nil {
return err
}
externalIP := node.GetNodeIP(false)
if externalIP == nil {
externalIP = node.GetNodeIP(true)
}
configuredMTU := option.Config.MTU
if mtu := p.CNI.GetMTU(); mtu > 0 {
configuredMTU = mtu
log.WithField("mtu", configuredMTU).Info("Overwriting MTU based on CNI configuration")
}
*c = NewConfiguration(
p.IPsec.AuthKeySize(),
option.Config.EnableIPSec,
p.TunnelConfig.ShouldAdaptMTU(),
option.Config.EnableWireguard,
option.Config.EnableHighScaleIPcache && option.Config.EnableNodePort,
configuredMTU,
externalIP,
)
return nil
},
})
return c
}