Skip to content

Commit

Permalink
Add loopback configuration to network setup
Browse files Browse the repository at this point in the history
  • Loading branch information
buty4649 committed Apr 18, 2024
1 parent 488185d commit 1f622e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var applyCmd = &cobra.Command{
}
}

err := SetupLoopback(netns)
err := SetupLoopback(netns, values.Loopback)
if err != nil {
return err
}
Expand Down Expand Up @@ -184,8 +184,11 @@ func SetNetns(name string, netns string) error {
return ip.SetNetns(name, netns)
}

func SetupLoopback(netns string) error {
return SetLinkUp(ip.IntoNetns(netns), "lo")
func SetupLoopback(netns string, ethernet config.Ethernet) error {
slog.Debug("setup loopback", "netns", netns, "addresses", ethernet.Addresses, "routes", ethernet.Routes)

n := ip.IntoNetns(netns)
return SetupDevice(n, "lo", ethernet.Addresses, ethernet.Routes)
}

func SetupEthernets(netns string, ethernets map[string]config.Ethernet) error {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
}

type Netns struct {
Loopback Ethernet `yaml:"loopback,omitempty"`
Ethernets map[string]Ethernet `yaml:"ethernets,omitempty"`
DummyDevices map[string]Ethernet `yaml:"dummy-devices,omitempty"`
VethDevices map[string]VethDevice `yaml:"veth-devices,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func TestLoadYamlFiles(t *testing.T) {
expected := &Config{
Netns: map[string]Netns{
"sample1": {
Loopback: Ethernet{
Addresses: []string{"127.0.0.53/8"},
Routes: []Route{{
To: "10.10.0.0/24",
Via: "127.0.0.53",
}},
},
Ethernets: map[string]Ethernet{
"eth0": {
Addresses: []string{
Expand Down
6 changes: 6 additions & 0 deletions testdata/config/sample1.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
netns:
sample1:
loopback:
addresses:
- 127.0.0.53/8
routes:
- to: 10.10.0.0/24
via: 127.0.0.53
ethernets:
eth0:
addresses:
Expand Down

0 comments on commit 1f622e4

Please sign in to comment.