s6-netdev/types.go
Alex Denes e9a673688b
Bugfixes and more restructuring
- Remove nav, can result in cycles
- Add IfMap for writing easily-referencable lists
- Fix missing references
- Fix wrong default routing table
- Set metric type to uint32 to allow really high metrics
- Add explicit ipv to route for default routes
2024-09-11 17:13:27 +00:00

75 lines
1.9 KiB
Go

package s6netdev
import (
"net"
"net/netip"
)
type (
RouteTable uint16
Metric uint32
VLAN uint16
)
type Property struct {
Key, Value, Default string
}
type Sysctl_IP struct {
V4, V6 []Property
}
type DHCP_IP struct {
V4, V6 bool // Should we start dhcp on this interface?
}
type Iface struct {
Name string // Interface name
Type *NetdevIfType // Type of interface
Slaves []*Iface // Slaves for VRFs, Bridges and Bonds etc...
VlanId VLAN // VLAN id for VLAN interfaces
Parent *Iface // Parent interface for VLAN interfaces
Table RouteTable // Routing table, for VRF
MACAddr net.HardwareAddr // MAC address of interface (only valid for physical, bridges and VLAN)
Addresses []netip.Prefix // Addresses to be assigned to interface
Routes []Route // Routes to be assigned to interface
DHCP DHCP_IP // Should we start dhcp on this interface?
Properties []Property // List of properties of the interface, valid for many
Sysctls Sysctl_IP // Sysctls associated with this interface
}
type Route struct {
Default bool
// VRF would be a field but it can be derived from parent
Type string // unicast default, can be others
IPver int // if 0, will guess based on Net
Net netip.Prefix
Via netip.Addr
Vrf *Iface
Table *RouteTable
Metric Metric // Should be explicitly initialised to 1024
}
type NetdevIfType struct {
str string
deps []S6SvcName
}
var NetdevIfTypes = struct {
Phys, Loopback, Bridge, Vlan, Wireguard, Bond, Vrf NetdevIfType
}{
Phys: NetdevIfType{"", []S6SvcName{"bundle.hw-coldplug"}},
Loopback: NetdevIfType{"loopback", []S6SvcName{}},
Bridge: NetdevIfType{"bridge", []S6SvcName{"module.bridge"}},
Vlan: NetdevIfType{"vlan", []S6SvcName{"module.8021q"}},
Wireguard: NetdevIfType{"wireguard", []S6SvcName{"module.wireguard"}},
Bond: NetdevIfType{"bond", []S6SvcName{"module.bonding"}},
Vrf: NetdevIfType{"vrf", []S6SvcName{"module.vrf"}},
}