package main import ( "fmt" "log" "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 []string{"p1s0", "p9s0"} { ifs.AddIf(&s6netdev.Iface{ Name: fmt.Sprintf("en%s", v), Type: &s6netdev.NetdevIfTypes.Phys, }) } // Bridge interfaces ifs.AddIf(&s6netdev.Iface{ Name: "br-home", Type: &s6netdev.NetdevIfTypes.Bridge, 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{ // No IPv6 autoconf V6: []s6netdev.Property{ {Key: "accept_ra", Value: "0", Default: "0"}, }, }, }) ifs.AddIf(&s6netdev.Iface{ Name: "br-main", Type: &s6netdev.NetdevIfTypes.Bridge, Properties: []s6netdev.Property{ {Key: "stp_state", Value: "0", Default: "0"}, {Key: "mcast_snooping", Value: "0", Default: "1"}, }, }) // VRFs ifs.AddIf(&s6netdev.Iface{ Name: "vrf-v6", Type: &s6netdev.NetdevIfTypes.Vrf, Table: 10, }) for _, m := range []struct { Master string Slaves []string }{ { Master: "vrf-v6", Slaves: []string{ "br-main", }, }, { Master: "br-main", Slaves: []string{ "enp1s0", }, }, { Master: "br-home", Slaves: []string{ "enp9s0", }, }, } { master := ifs[m.Master] for _, slave := range m.Slaves { master.Slaves = append(master.Slaves, ifs[slave]) } ifs[m.Master] = master } // Unreachable routes ifs["lo"].Routes = append(ifs["lo"].Routes, s6netdev.Route{ Default: true, IPver: 6, Type: "unreachable", Vrf: ifs["vrf-v6"], Metric: 4278198272, }) 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) } } }