From 28d66dcc641c7b344b5d8b0e81577fda033bb423 Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Thu, 19 Sep 2024 11:12:06 +0000 Subject: [PATCH] Add san-jorge.argentina --- hosts/san-jorge.argentina/main.go | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 hosts/san-jorge.argentina/main.go diff --git a/hosts/san-jorge.argentina/main.go b/hosts/san-jorge.argentina/main.go new file mode 100644 index 0000000..2399711 --- /dev/null +++ b/hosts/san-jorge.argentina/main.go @@ -0,0 +1,89 @@ +package main + +import ( + "fmt" + "log" + "net/netip" + "os" + + "git.redxen.eu/caskd/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"} { + ifs.AddIf(&s6netdev.Iface{ + Name: fmt.Sprintf("en%s", v), + Type: &s6netdev.NetdevIfTypes.Phys, + }) + } + + // Bridge interfaces + ifs.AddIf(&s6netdev.Iface{ + Name: "br-v6", + Type: &s6netdev.NetdevIfTypes.Bridge, + Properties: []s6netdev.Property{ + {Key: "stp_state", Value: "0", Default: "0"}, + {Key: "mcast_snooping", Value: "0", Default: "1"}, + }, + }) + + // Wireguard interfaces + ifs.AddIf(&s6netdev.Iface{ + Name: "wg-tunnel", + Type: &s6netdev.NetdevIfTypes.Wireguard, + Addresses: []netip.Prefix{ + netip.MustParsePrefix("172.22.12.8/32"), + netip.MustParsePrefix("fd42:42:42::2:8/128"), + }, + Routes: []s6netdev.Route{ + {Net: netip.MustParsePrefix("172.22.12.0/24")}, + {Net: netip.MustParsePrefix("fd42:42:42::2:0/120")}, + }, + }) + + for _, m := range []struct { + Master string + Slaves []string + }{ + { + Master: "br-v6", + Slaves: []string{ + "enp1s0", + }, + }, + } { + 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) + } + } +}