Update generic for usage in base service list

This commit is contained in:
Alex D. 2024-09-21 13:50:45 +00:00
parent 43eb413045
commit 65d1e24916
Signed by: caskd
GPG Key ID: F92BA85F61F4C173

View File

@ -2,7 +2,6 @@ package main
import (
"log"
"net/netip"
"os"
"git.redxen.eu/caskd/s6-netdev"
@ -12,43 +11,54 @@ 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()
// No VRF
lo := s6netdev.Iface{
// Loopback
ifs.AddIf(&s6netdev.Iface{
Name: "lo",
Type: &s6netdev.NetdevIfTypes.Loopback,
}
t.NavServices(lo)
})
// Main VRF
main_vrf := s6netdev.Iface{
Name: "vrf-main",
Type: &s6netdev.NetdevIfTypes.Vrf,
Slaves: []*s6netdev.Iface{
{
Name: "br-main",
Type: &s6netdev.NetdevIfTypes.Bridge,
Routes: []s6netdev.Route{
{
Net: netip.MustParsePrefix("fd00::/64"),
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Slaves: []*s6netdev.Iface{
{
Name: "enp1s0",
Type: &s6netdev.NetdevIfTypes.Phys,
},
},
// Physical interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "eth0",
Type: &s6netdev.NetdevIfTypes.Phys,
})
// Bridge interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "br0",
Type: &s6netdev.NetdevIfTypes.Bridge,
DHCP: s6netdev.DHCP_IP{V4: true},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "br0",
Slaves: []string{
"eth0",
},
},
} {
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)
}
t.NavServices(main_vrf)
for _, v := range t.S6Services() {
if s6netdev.NetdevIsDummy(v.Name) {