Add nnd-navi
This commit is contained in:
parent
067760aac7
commit
b3f8f4102e
82
nnd-navi/main.go
Normal file
82
nnd-navi/main.go
Normal file
@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"git.redxen.eu/nnd/s6-netdev"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
err error
|
||||
l = log.New(os.Stderr, "s6-netdev: ", log.Ltime|log.Lshortfile|log.Lmsgprefix)
|
||||
ifs = make(s6netdev.IfMap)
|
||||
)
|
||||
t := s6netdev.S6NewTree()
|
||||
|
||||
// Loopback
|
||||
ifs.AddIf(&s6netdev.Iface{
|
||||
Name: "lo",
|
||||
Type: &s6netdev.NetdevIfTypes.Loopback,
|
||||
})
|
||||
|
||||
// Physical interfaces
|
||||
for _, v := range []int{2} {
|
||||
ifs.AddIf(&s6netdev.Iface{
|
||||
Name: fmt.Sprintf("enp%ds0f0", v),
|
||||
Type: &s6netdev.NetdevIfTypes.Phys,
|
||||
})
|
||||
}
|
||||
|
||||
// Bridge interfaces
|
||||
ifs.AddIf(&s6netdev.Iface{
|
||||
Name: "phys",
|
||||
Type: &s6netdev.NetdevIfTypes.Bridge,
|
||||
MACAddr: net.HardwareAddr{0x38, 0xf3, 0xab, 0x84, 0x3d, 0xa4},
|
||||
DHCP: s6netdev.DHCP_IP{V4: true},
|
||||
Properties: []s6netdev.Property{
|
||||
{Key: "stp_state", Value: "0", Default: "0"},
|
||||
{Key: "mcast_snooping", Value: "0", Default: "1"},
|
||||
},
|
||||
Sysctls: s6netdev.Sysctl_IP{
|
||||
V6: []s6netdev.Property{
|
||||
{Key: "forwarding", Value: "0", Default: "0"},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
for _, m := range []struct {
|
||||
Master string
|
||||
Slaves []string
|
||||
}{
|
||||
{
|
||||
Master: "phys",
|
||||
Slaves: []string{
|
||||
"enp2s0f0",
|
||||
},
|
||||
},
|
||||
} {
|
||||
master := ifs[m.Master]
|
||||
for _, slave := range m.Slaves {
|
||||
master.Slaves = append(master.Slaves, ifs[slave])
|
||||
}
|
||||
ifs[m.Master] = master
|
||||
}
|
||||
|
||||
for _, v := range ifs {
|
||||
t.Services(*v)
|
||||
}
|
||||
|
||||
for _, v := range t.S6Services() {
|
||||
if s6netdev.NetdevIsDummy(v.Name) {
|
||||
continue
|
||||
}
|
||||
l.Printf("Commiting %s\n", v.Name)
|
||||
if err = t.S6CommitService(v); err != nil {
|
||||
l.Fatalf("Failed to commit %s, %s\n", v.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user