Remove IP when udhcpc exits, change route table to not be a pointer in the interface, and conditionally check if either route table or vrf is present as they collide

This commit is contained in:
Alex D. 2024-12-13 07:33:19 +00:00
parent 72076c2b6d
commit 0a70be7e65
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
5 changed files with 25 additions and 19 deletions

View File

@ -182,7 +182,7 @@ func (t *S6SvcTree) NetdevIfaceDHCP(iface Iface, ipv int) *S6Svc {
NETDEV_EXECLINE_HEADER, NETDEV_EXECLINE_HEADER,
ExeclineDefine("INTERFACE", iface.Name), ExeclineDefine("INTERFACE", iface.Name),
"fdmove -c 2 1", "fdmove -c 2 1",
fmt.Sprintf("%s -i $INTERFACE -f -S", daemon), fmt.Sprintf("%s -i $INTERFACE -f -S -R", daemon),
}, "\n") }, "\n")
l.ProducerFor = t.S6New("logger.udhcpc", &S6SvcTypes.Longrun) l.ProducerFor = t.S6New("logger.udhcpc", &S6SvcTypes.Longrun)
@ -192,7 +192,7 @@ func (t *S6SvcTree) NetdevIfaceDHCP(iface Iface, ipv int) *S6Svc {
return l return l
} }
func (t *S6SvcTree) NetdevIfaceWPASupplicant(iface Iface, ipv int) *S6Svc { func (t *S6SvcTree) NetdevIfaceWPASupplicant(iface Iface) *S6Svc {
svc_name := S6SvcName(fmt.Sprintf("interface.%s.wpa_supplicant", iface.Name)).Sanitize() svc_name := S6SvcName(fmt.Sprintf("interface.%s.wpa_supplicant", iface.Name)).Sanitize()
l := t.S6New(svc_name, &S6SvcTypes.Longrun) l := t.S6New(svc_name, &S6SvcTypes.Longrun)
@ -205,11 +205,11 @@ func (t *S6SvcTree) NetdevIfaceWPASupplicant(iface Iface, ipv int) *S6Svc {
ExeclineDefine("INTERFACE", iface.Name), ExeclineDefine("INTERFACE", iface.Name),
ExeclineImportas("CONFIG", false, "${XDG_CONFIG_HOME}/wpa_supplicant/wpa_supplicant.conf"), ExeclineImportas("CONFIG", false, "${XDG_CONFIG_HOME}/wpa_supplicant/wpa_supplicant.conf"),
"fdmove -c 2 1", "fdmove -c 2 1",
fmt.Sprintf("%s -i $INTERFACE -dd -C $CONFIG", daemon), fmt.Sprintf("%s -i $INTERFACE -dd -c $CONFIG", daemon),
}, "\n") }, "\n")
l.ProducerFor = t.S6New("logger.wpa_supplicant", &S6SvcTypes.Longrun) l.ProducerFor = t.S6New("logger.wpa_supplicant", &S6SvcTypes.Longrun)
l.S6Children(t.LinkIfaceService(iface.Name)) l.S6Children(t.LinkIfaceService(iface.Name), t.S6New("bundle.wpa_supplicant.deps", &S6SvcTypes.Bundle))
t.NetdevDependBundleStage(iface.Name, "ready", l) t.NetdevDependBundleStage(iface.Name, "ready", l)
return l return l
@ -299,7 +299,11 @@ func (t *S6SvcTree) netdevRouteTemplate(iface Iface, route Route) (up, down stri
cmd = append(cmd, "metric", "$METRIC") cmd = append(cmd, "metric", "$METRIC")
} }
if route.Vrf != nil && route.Vrf.Type == &NetdevIfTypes.Vrf { // Table overrides VRF if defined
if route.Table != 0 {
lines = append(lines, ExeclineImportas("TABLE", false, fmt.Sprintf("%d", route.Table)))
cmd = append(cmd, "table", "$TABLE")
} else if route.Vrf != nil && route.Vrf.Type == &NetdevIfTypes.Vrf {
// Parent is VRF // Parent is VRF
lines = append(lines, ExeclineImportas("VRF", false, route.Vrf.Name)) lines = append(lines, ExeclineImportas("VRF", false, route.Vrf.Name))
cmd = append(cmd, "vrf", "$VRF") cmd = append(cmd, "vrf", "$VRF")

View File

@ -23,7 +23,7 @@ func (i *Iface) NetdevIfaceAddAddr(addr string) (err error) {
return return
} }
func (i *Iface) NetdevIfaceAddRoute(def bool, route, r_type, via string, vrf *Iface, table *RouteTable, metric Metric) (err error) { func (i *Iface) NetdevIfaceAddRoute(def bool, route, r_type, via string, vrf *Iface, table RouteTable, metric Metric) (err error) {
var ( var (
r = Route{ r = Route{
Default: def, Default: def,

20
misc.go
View File

@ -9,15 +9,17 @@ import (
var ( var (
dummy_svc_blacklist = map[S6SvcName]interface{}{ dummy_svc_blacklist = map[S6SvcName]interface{}{
"bundle.hw-coldplug": nil, "bundle.hw-coldplug": nil,
"module.8021q": nil, "module.8021q": nil,
"module.bonding": nil, "module.bonding": nil,
"module.bridge": nil, "module.bridge": nil,
"module.vrf": nil, "module.vrf": nil,
"module.ipv6": nil, "module.ipv6": nil,
"module.wireguard": nil, "module.wireguard": nil,
"mount.proc": nil, "mount.proc": nil,
"logger.udhcpc": nil, "logger.udhcpc": nil,
"logger.wpa_supplicant": nil,
"bundle.wpa_supplicant.deps": nil,
} }
) )

View File

@ -99,7 +99,7 @@ func (t *S6SvcTree) ConfigureServices(i Iface) (r []*S6Svc) {
r = append(r, t.NetdevIfaceDHCP(i, 6)) r = append(r, t.NetdevIfaceDHCP(i, 6))
} }
if i.WPA_Supplicant { if i.WPA_Supplicant {
r = append(r, t.NetdevIfaceWpaSupplicant(i)) r = append(r, t.NetdevIfaceWPASupplicant(i))
} }
for _, v := range i.Sysctls.V4 { for _, v := range i.Sysctls.V4 {

View File

@ -38,8 +38,8 @@ type Iface struct {
Addresses []netip.Prefix // Addresses to be assigned to interface Addresses []netip.Prefix // Addresses to be assigned to interface
Routes []Route // Routes to be assigned to interface Routes []Route // Routes to be assigned to interface
DHCP DHCP_IP // Should we start dhcp on this interface? DHCP DHCP_IP // Should we start dhcp on this interface?
WPA_Supplicant bool // Should we start wpa_supplicant on this interface? WPA_Supplicant bool // Should we start wpa_supplicant on this interface?
Properties []Property // List of properties of the interface, valid for many Properties []Property // List of properties of the interface, valid for many
Sysctls Sysctl_IP // Sysctls associated with this interface Sysctls Sysctl_IP // Sysctls associated with this interface
@ -53,7 +53,7 @@ type Route struct {
Net netip.Prefix Net netip.Prefix
Via netip.Addr Via netip.Addr
Vrf *Iface Vrf *Iface
Table *RouteTable Table RouteTable
Metric Metric // Should be explicitly initialised to 1024 Metric Metric // Should be explicitly initialised to 1024
} }