Initial commit

This commit is contained in:
Alex D. 2024-11-06 12:58:11 +00:00
commit 62cead3fb7
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
11 changed files with 1601 additions and 0 deletions

96
dongguan.china/main.go Normal file
View File

@ -0,0 +1,96 @@
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", "p11s0"} {
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"},
},
})
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "br-main",
Slaves: []string{
"enp1s0",
},
},
{
Master: "br-home",
Slaves: []string{
"enp11s0",
},
},
} {
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)
}
}
}

72
generic/main.go Normal file
View File

@ -0,0 +1,72 @@
package main
import (
"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
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)
}
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)
}
}
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.redxen.eu/caskd/s6-netdev
go 1.22.8
require git.redxen.eu/nnd/s6-netdev v0.0.0-20241106103743-03b649623f4e

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
git.redxen.eu/nnd/s6-netdev v0.0.0-20241106103743-03b649623f4e h1:t4/qeNtyQNYFcWQMw7akxafvWJT8+8yErqNiu/Y/1/o=
git.redxen.eu/nnd/s6-netdev v0.0.0-20241106103743-03b649623f4e/go.mod h1:3P2jgoez/bos+RdMFoDCs63PlCKFw1POQz/TfE1dq5g=

233
izmaylovo.russia/main.go Normal file
View File

@ -0,0 +1,233 @@
package main
import (
"fmt"
"log"
"net/netip"
"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,
})
// VRFs
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-phys",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 10,
})
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-b00b",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 20,
})
// Physical interfaces
for _, v := range []string{"p4s0f0", "p4s0f1", "p2s0f0", "p2s0f1", "p2s0f2", "p2s0f3"} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("en%s", v),
Type: &s6netdev.NetdevIfTypes.Phys,
})
}
// VLAN Interfaces
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("phys.%d", 66),
Type: &s6netdev.NetdevIfTypes.Vlan,
VlanId: s6netdev.VLAN(66),
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:b00b:921b:eff:fee3:9e84/64"),
},
Routes: []s6netdev.Route{
{
Net: netip.MustParsePrefix("2a04:5b81:2060:b00b::/64"),
Via: netip.MustParseAddr("fe80::ff:fe00:b00b"),
Metric: 128,
},
},
// Disable autoconf, we statically assign it to have it early
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "autoconf", 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.7/32"),
netip.MustParsePrefix("fd42:42:42::2:7/128"),
},
Routes: []s6netdev.Route{
{Net: netip.MustParsePrefix("172.22.12.0/24")},
{Net: netip.MustParsePrefix("fd42:42:42::2:0/120")},
},
})
// Bridge interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "phys",
Type: &s6netdev.NetdevIfTypes.Bridge,
Properties: []s6netdev.Property{
{Key: "priority", Value: "16384", Default: "32768"},
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "0", Default: "0"},
{Key: "accept_ra", Value: "0", Default: "1"},
},
},
})
// Currently there exists no mechanism to depend routes on the addresses, these are manual deps
phys_addr_v4 := t.NetdevIfaceAddr(*ifs["phys"], netip.MustParsePrefix("10.24.0.10/24"))
phys_defrt_v4_vrf := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 4,
Vrf: ifs["vrf-phys"],
Via: netip.MustParseAddr("10.24.0.1"),
Metric: 1024,
},
)
phys_defrt_v4_vrf.Children = append(phys_defrt_v4_vrf.Children, phys_addr_v4)
phys_defrt_v4_main := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 4,
Via: netip.MustParseAddr("10.24.0.1"),
Metric: 1024,
},
)
phys_defrt_v4_main.Children = append(phys_defrt_v4_main.Children, phys_addr_v4)
phys_addr_v6 := t.NetdevIfaceAddr(*ifs["phys"], netip.MustParsePrefix("2a02:810d:95bf:f999:921b:eff:fee3:9e84/64"))
phys_defrt_v6_vrf := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 6,
Vrf: ifs["vrf-phys"],
Via: netip.MustParseAddr("fe80::2e91:abff:fe90:9bb5"),
Metric: 1024,
},
)
phys_defrt_v6_vrf.Children = append(phys_defrt_v6_vrf.Children, phys_addr_v6)
phys_defrt_v6_main := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 6,
Via: netip.MustParseAddr("fe80::2e91:abff:fe90:9bb5"),
Metric: 1024,
},
)
phys_defrt_v6_main.Children = append(phys_defrt_v6_main.Children, phys_addr_v6)
// Private Bridges
for _, name := range []string{
"b00b",
"d00d",
"f33d",
"dn42",
} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("virbr-%s", name),
Type: &s6netdev.NetdevIfTypes.Bridge,
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "0", Default: "0"},
{Key: "accept_ra", Value: "0", Default: "1"},
},
},
})
}
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "vrf-b00b",
Slaves: []string{
"phys.66",
},
},
{
Master: "vrf-phys",
Slaves: []string{
"phys",
},
},
{
Master: "phys",
Slaves: []string{
"enp4s0f0",
"enp4s0f1",
"enp2s0f0",
"enp2s0f1",
"enp2s0f2",
"enp2s0f3",
},
},
} {
master := ifs[m.Master]
for _, slave := range m.Slaves {
master.Slaves = append(master.Slaves, ifs[slave])
}
ifs[m.Master] = master
}
// Parent of VLANs
ifs[fmt.Sprintf("phys.%d", 66)].Parent = ifs["phys"]
// Unreachable routes
for _, vrf := range []string{"vrf-phys", "vrf-b00b"} {
// TODO: iproute2 inconsistency for ipv4?
for _, ver := range []int{6} {
ifs["lo"].Routes = append(ifs["lo"].Routes,
s6netdev.Route{
Type: "unreachable",
Default: true,
IPver: ver,
Vrf: ifs[vrf],
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)
}
}
}

View File

@ -0,0 +1,333 @@
package main
import (
"fmt"
"log"
"net"
"net/netip"
"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, 13, 16, 17, 18} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("enp%ds0", v),
Type: &s6netdev.NetdevIfTypes.Phys,
})
}
// VLAN Interfaces
for _, v := range []int{42, 66, 100, 101} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("phys.%d", v),
Type: &s6netdev.NetdevIfTypes.Vlan,
VlanId: s6netdev.VLAN(v),
})
}
// Wireguard interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "famfo",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::1422:1/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "mark22k",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::4546/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "highdef",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::2/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "kioubit",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::2/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "lare",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::2/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "haktron",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::2/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "vultrbgp",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{
netip.MustParsePrefix("fe80::2/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
// Bridge interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "phys",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x52, 0x54, 0x00, 0xf4, 0x2b, 0xd1},
DHCP: s6netdev.DHCP_IP{V4: true},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "0", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "br-dn42",
Type: &s6netdev.NetdevIfTypes.Bridge,
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "b00b",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x02, 0x00, 0x00, 0x00, 0xb0, 0x0b},
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:b00b::1/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "autoconf", Value: "0", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "f33d",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x02, 0x00, 0x00, 0x00, 0xf3, 0x3d},
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:f33d::1/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "autoconf", Value: "0", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "d00d",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x02, 0x00, 0x00, 0x00, 0xd0, 0x0d},
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:d00d::1/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "autoconf", Value: "0", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
// VRFs
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-dn42",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 20,
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-v6",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 10,
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "vrf-dn42",
Slaves: []string{
"br-dn42",
"famfo",
"mark22k",
"highdef",
"kioubit",
"lare",
"haktron",
},
},
{
Master: "vrf-v6",
Slaves: []string{
"vultrbgp",
"b00b",
"f33d",
"d00d",
},
},
{
Master: "phys",
Slaves: []string{
"enp13s0",
},
},
{
Master: "b00b",
Slaves: []string{
"enp16s0",
"phys.66",
},
},
{
Master: "br-dn42",
Slaves: []string{
"enp2s0",
"phys.42",
},
},
{
Master: "f33d",
Slaves: []string{
"enp17s0",
"phys.100",
},
},
{
Master: "d00d",
Slaves: []string{
"enp18s0",
"phys.101",
},
},
} {
master := ifs[m.Master]
for _, slave := range m.Slaves {
master.Slaves = append(master.Slaves, ifs[slave])
}
ifs[m.Master] = master
}
// Parent of VLANs
for _, v := range []int{42, 66, 100, 101} {
ifs[fmt.Sprintf("phys.%d", v)].Parent = ifs["phys"]
}
// Unreachable routes
ifs["lo"].Routes = append(ifs["lo"].Routes, s6netdev.Route{
Type: "unreachable",
Net: netip.MustParsePrefix("2a04:5b81:2060::/44"),
Vrf: ifs["vrf-v6"],
Metric: 4278198272,
}, s6netdev.Route{
Type: "unreachable",
Default: true,
IPver: 6,
Vrf: ifs["vrf-dn42"],
Metric: 4278198272,
})
// Self-referencing
ifs["vultrbgp"].Routes = append(ifs["vultrbgp"].Routes, s6netdev.Route{
Default: true,
IPver: 6,
Vrf: ifs["vrf-v6"],
})
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)
}
}
}

118
mangong.taiwan/main.go Normal file
View File

@ -0,0 +1,118 @@
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)
}
}
}

150
mika.frankfurt/main.go Normal file
View File

@ -0,0 +1,150 @@
package main
import (
"fmt"
"log"
"net/netip"
"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,
})
// VRFs
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-wgate",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 20,
})
// Bridge interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "br-uplink",
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{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "accept_ra", Value: "2", Default: "0"},
},
},
})
// Physical interfaces
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("enp1s0"),
Type: &s6netdev.NetdevIfTypes.Phys,
})
// Wireguard interfaces
for _, v := range []struct{ ifn, ll, route string }{
{ifn: "tristan", ll: "fe80::1/64", route: "2a04:5b81:2010::/48"},
{ifn: "tristan-travel", ll: "fe80::1/64", route: "2a04:5b81:201f::/48"},
{ifn: "gustav", ll: "fe80::1/64", route: "2a04:5b81:2011::/48"},
{ifn: "caskd-lakewood", ll: "fe80::1/64", route: "2a04:5b81:2060::/48"},
} {
ifs.AddIf(&s6netdev.Iface{
Name: v.ifn,
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix(v.ll)},
Routes: []s6netdev.Route{
{Net: netip.MustParsePrefix(v.route), Vrf: ifs["vrf-wgate"]},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
}
ifs.AddIf(&s6netdev.Iface{
Name: "caskd-thetford",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{netip.MustParsePrefix("fe80::1/64")},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "vrf-wgate",
Slaves: []string{
"br-uplink",
"tristan",
"tristan-travel",
"gustav",
"caskd-lakewood",
"caskd-thetford",
},
},
{
Master: "br-uplink",
Slaves: []string{
"enp1s0",
},
},
} {
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{
Type: "unreachable",
Net: netip.MustParsePrefix("2a04:5b81:2060::/44"),
Vrf: ifs["vrf-wgate"],
Metric: 4096,
}, s6netdev.Route{
Type: "unreachable",
Net: netip.MustParsePrefix("2a04:5b81:2010::/44"),
Vrf: ifs["vrf-wgate"],
Metric: 4096,
}, s6netdev.Route{
Type: "unreachable",
Default: true,
IPver: 6,
Vrf: ifs["vrf-wgate"],
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)
}
}
}

View File

@ -0,0 +1,90 @@
package main
import (
"fmt"
"log"
"net/netip"
"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"} {
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")},
{Default: true, IPver: 4},
},
})
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)
}
}
}

233
tarui.japan/main.go Normal file
View File

@ -0,0 +1,233 @@
package main
import (
"fmt"
"log"
"net/netip"
"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,
})
// VRFs
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-phys",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 10,
})
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-b00b",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 20,
})
// Physical interfaces
for _, v := range []string{"p129s0f0", "p129s0f1", "p131s0f0", "p131s0f1", "p131s0f2", "p131s0f3"} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("en%s", v),
Type: &s6netdev.NetdevIfTypes.Phys,
})
}
// VLAN Interfaces
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("phys.%d", 66),
Type: &s6netdev.NetdevIfTypes.Vlan,
VlanId: s6netdev.VLAN(66),
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:b00b:921b:eff:fe53:8b67/64"),
},
Routes: []s6netdev.Route{
{
Net: netip.MustParsePrefix("2a04:5b81:2060:b00b::/64"),
Via: netip.MustParseAddr("fe80::ff:fe00:b00b"),
Metric: 128,
},
},
// Disable autoconf, we statically assign it to have it early
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "autoconf", 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.7/32"),
netip.MustParsePrefix("fd42:42:42::2:7/128"),
},
Routes: []s6netdev.Route{
{Net: netip.MustParsePrefix("172.22.12.0/24")},
{Net: netip.MustParsePrefix("fd42:42:42::2:0/120")},
},
})
// Bridge interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "phys",
Type: &s6netdev.NetdevIfTypes.Bridge,
Properties: []s6netdev.Property{
{Key: "priority", Value: "16384", Default: "32768"},
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "0", Default: "0"},
{Key: "accept_ra", Value: "0", Default: "1"},
},
},
})
// Currently there exists no mechanism to depend routes on the addresses, these are manual deps
phys_addr_v4 := t.NetdevIfaceAddr(*ifs["phys"], netip.MustParsePrefix("10.24.0.11/24"))
phys_defrt_v4_vrf := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 4,
Vrf: ifs["vrf-phys"],
Via: netip.MustParseAddr("10.24.0.1"),
Metric: 1024,
},
)
phys_defrt_v4_vrf.Children = append(phys_defrt_v4_vrf.Children, phys_addr_v4)
phys_defrt_v4_main := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 4,
Via: netip.MustParseAddr("10.24.0.1"),
Metric: 1024,
},
)
phys_defrt_v4_main.Children = append(phys_defrt_v4_main.Children, phys_addr_v4)
phys_addr_v6 := t.NetdevIfaceAddr(*ifs["phys"], netip.MustParsePrefix("2a02:810d:95bf:f999:921b:eff:fe55:75ab/64"))
phys_defrt_v6_vrf := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 6,
Vrf: ifs["vrf-phys"],
Via: netip.MustParseAddr("fe80::2e91:abff:fe90:9bb5"),
Metric: 1024,
},
)
phys_defrt_v6_vrf.Children = append(phys_defrt_v6_vrf.Children, phys_addr_v6)
phys_defrt_v6_main := t.NetdevRoute(*ifs["phys"],
s6netdev.Route{
Default: true,
IPver: 6,
Via: netip.MustParseAddr("fe80::2e91:abff:fe90:9bb5"),
Metric: 1024,
},
)
phys_defrt_v6_main.Children = append(phys_defrt_v6_main.Children, phys_addr_v6)
// Private Bridges
for _, name := range []string{
"b00b",
"d00d",
"f33d",
"dn42",
} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("virbr-%s", name),
Type: &s6netdev.NetdevIfTypes.Bridge,
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "0", Default: "0"},
{Key: "accept_ra", Value: "0", Default: "1"},
},
},
})
}
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "vrf-b00b",
Slaves: []string{
"phys.66",
},
},
{
Master: "vrf-phys",
Slaves: []string{
"phys",
},
},
{
Master: "phys",
Slaves: []string{
"enp129s0f0",
"enp129s0f1",
"enp131s0f0",
"enp131s0f1",
"enp131s0f2",
"enp131s0f3",
},
},
} {
master := ifs[m.Master]
for _, slave := range m.Slaves {
master.Slaves = append(master.Slaves, ifs[slave])
}
ifs[m.Master] = master
}
// Parent of VLANs
ifs[fmt.Sprintf("phys.%d", 66)].Parent = ifs["phys"]
// Unreachable routes
for _, vrf := range []string{"vrf-phys", "vrf-b00b"} {
// TODO: iproute2 inconsistency for ipv4?
for _, ver := range []int{6} {
ifs["lo"].Routes = append(ifs["lo"].Routes,
s6netdev.Route{
Type: "unreachable",
Default: true,
IPver: ver,
Vrf: ifs[vrf],
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)
}
}
}

View File

@ -0,0 +1,269 @@
package main
import (
"fmt"
"log"
"net"
"net/netip"
"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{9, 12, 13, 14, 15} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("enp%ds0", v),
Type: &s6netdev.NetdevIfTypes.Phys,
})
}
// VLAN Interfaces
for _, v := range []int{42, 66, 100, 101} {
ifs.AddIf(&s6netdev.Iface{
Name: fmt.Sprintf("phys.%d", v),
Type: &s6netdev.NetdevIfTypes.Vlan,
VlanId: s6netdev.VLAN(v),
})
}
// Bridge interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "phys",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x52, 0x54, 0x00, 0x81, 0xcb, 0x62},
DHCP: s6netdev.DHCP_IP{V4: true},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "1", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "0", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "br-dn42",
Type: &s6netdev.NetdevIfTypes.Bridge,
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "b00b",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x02, 0x00, 0x00, 0x01, 0xb0, 0x0b},
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:b00b::2/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "autoconf", Value: "0", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "f33d",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x02, 0x00, 0x00, 0x01, 0xf3, 0x3d},
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:f33d::2/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "autoconf", Value: "0", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "d00d",
Type: &s6netdev.NetdevIfTypes.Bridge,
MACAddr: net.HardwareAddr{0x02, 0x00, 0x00, 0x01, 0xd0, 0x0d},
Addresses: []netip.Prefix{
netip.MustParsePrefix("2a04:5b81:2060:d00d::2/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
{Key: "autoconf", Value: "0", Default: "0"},
},
},
Properties: []s6netdev.Property{
{Key: "stp_state", Value: "0", Default: "0"},
{Key: "mcast_snooping", Value: "0", Default: "1"},
},
})
// VRFs
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-dn42",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 20,
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
ifs.AddIf(&s6netdev.Iface{
Name: "vrf-v6",
Type: &s6netdev.NetdevIfTypes.Vrf,
Table: 10,
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
// Wireguard interfaces
ifs.AddIf(&s6netdev.Iface{
Name: "vultrbgp",
Type: &s6netdev.NetdevIfTypes.Wireguard,
Addresses: []netip.Prefix{
netip.MustParsePrefix("fe80::2/64"),
},
Sysctls: s6netdev.Sysctl_IP{
V6: []s6netdev.Property{
{Key: "forwarding", Value: "1", Default: "0"},
},
},
})
for _, m := range []struct {
Master string
Slaves []string
}{
{
Master: "vrf-dn42",
Slaves: []string{
"br-dn42",
},
},
{
Master: "vrf-v6",
Slaves: []string{
"vultrbgp",
"b00b",
"f33d",
"d00d",
},
},
{
Master: "phys",
Slaves: []string{
"enp12s0",
},
},
{
Master: "b00b",
Slaves: []string{
"enp9s0",
"phys.66",
},
},
{
Master: "br-dn42",
Slaves: []string{
"enp15s0",
"phys.42",
},
},
{
Master: "f33d",
Slaves: []string{
"enp14s0",
"phys.100",
},
},
{
Master: "d00d",
Slaves: []string{
"enp13s0",
"phys.101",
},
},
} {
master := ifs[m.Master]
for _, slave := range m.Slaves {
master.Slaves = append(master.Slaves, ifs[slave])
}
ifs[m.Master] = master
}
// Parent of VLANs
for _, v := range []int{42, 66, 100, 101} {
ifs[fmt.Sprintf("phys.%d", v)].Parent = ifs["phys"]
}
// Unreachable routes
ifs["lo"].Routes = append(ifs["lo"].Routes, s6netdev.Route{
Type: "unreachable",
Default: true,
IPver: 6,
Vrf: ifs["vrf-v6"],
Metric: 4278198272,
}, s6netdev.Route{
Type: "unreachable",
Default: true,
IPver: 6,
Vrf: ifs["vrf-dn42"],
Metric: 4278198272,
})
// Default router for vrf (defrtr from ra isn't installed if autoconf not enabled)
ifs["b00b"].Routes = append(ifs["b00b"].Routes, s6netdev.Route{
Default: true,
Via: netip.MustParseAddr("fe80::ff:fe00:b00b"), // Link local of lakewood.united-states
Vrf: ifs["vrf-v6"],
Metric: 4096,
})
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)
}
}
}