-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
daemon: move datapath cell to pkg/datapath
Now that there are no more circular imports, we can move the datapath cell and associated initialization code to pkg/datapath. The sysctl stuff should most definitely not live toplevel here, but one step at a time. Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
- Loading branch information
Showing
6 changed files
with
92 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package datapath | ||
|
||
import ( | ||
"log" | ||
"path/filepath" | ||
|
||
"github.com/cilium/cilium/pkg/datapath/iptables" | ||
"github.com/cilium/cilium/pkg/datapath/link" | ||
linuxdatapath "github.com/cilium/cilium/pkg/datapath/linux" | ||
"github.com/cilium/cilium/pkg/datapath/types" | ||
"github.com/cilium/cilium/pkg/defaults" | ||
"github.com/cilium/cilium/pkg/hive" | ||
"github.com/cilium/cilium/pkg/hive/cell" | ||
ipcache "github.com/cilium/cilium/pkg/ipcache/types" | ||
"github.com/cilium/cilium/pkg/option" | ||
wg "github.com/cilium/cilium/pkg/wireguard/agent" | ||
wgTypes "github.com/cilium/cilium/pkg/wireguard/types" | ||
) | ||
|
||
// Datapath provides the privileged operations to apply control-plane | ||
// decision to the kernel. | ||
var Cell = cell.Module( | ||
"datapath", | ||
"Datapath", | ||
|
||
cell.Provide( | ||
newWireguardAgent, | ||
newDatapath, | ||
), | ||
|
||
cell.Provide(func(dp types.Datapath) ipcache.NodeHandler { | ||
return dp.Node() | ||
}), | ||
) | ||
|
||
func newWireguardAgent(lc hive.Lifecycle) *wg.Agent { | ||
var wgAgent *wg.Agent | ||
if option.Config.EnableWireguard { | ||
if option.Config.EnableIPSec { | ||
log.Fatalf("Wireguard (--%s) cannot be used with IPSec (--%s)", | ||
option.EnableWireguard, option.EnableIPSecName) | ||
} | ||
|
||
var err error | ||
privateKeyPath := filepath.Join(option.Config.StateDir, wgTypes.PrivKeyFilename) | ||
wgAgent, err = wg.NewAgent(privateKeyPath) | ||
if err != nil { | ||
log.Fatalf("failed to initialize wireguard: %s", err) | ||
} | ||
|
||
lc.Append(hive.Hook{ | ||
OnStop: func(hive.HookContext) error { | ||
wgAgent.Close() | ||
return nil | ||
}, | ||
}) | ||
} else { | ||
// Delete wireguard device from previous run (if such exists) | ||
link.DeleteByName(wgTypes.IfaceName) | ||
} | ||
return wgAgent | ||
} | ||
|
||
func newDatapath(lc hive.Lifecycle, wgAgent *wg.Agent) types.Datapath { | ||
datapathConfig := linuxdatapath.DatapathConfiguration{ | ||
HostDevice: defaults.HostDevice, | ||
ProcFs: option.Config.ProcFs, | ||
} | ||
|
||
iptablesManager := &iptables.IptablesManager{} | ||
|
||
lc.Append(hive.Hook{ | ||
OnStart: func(hive.HookContext) error { | ||
// FIXME enableIPForwarding should not live here | ||
if err := enableIPForwarding(); err != nil { | ||
log.Fatalf("enabling IP forwarding via sysctl failed: %s", err) | ||
} | ||
|
||
iptablesManager.Init() | ||
return nil | ||
}}) | ||
|
||
return linuxdatapath.NewDatapath(datapathConfig, iptablesManager, wgAgent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
//go:build linux | ||
|
||
package cmd | ||
package datapath | ||
|
||
import ( | ||
"github.com/cilium/cilium/pkg/testutils" | ||
|