s6-netdev/misc.go

61 lines
1.3 KiB
Go
Raw Normal View History

2024-09-04 12:22:10 +00:00
package s6netdev
import (
"fmt"
"net"
"net/netip"
2024-09-04 12:22:10 +00:00
"strings"
)
var (
dummy_svc_blacklist = map[S6SvcName]interface{}{
"bundle.hw-coldplug": nil,
"module.8021q": nil,
"module.bonding": nil,
"module.bridge": nil,
"module.vrf": nil,
"module.ipv6": nil,
"module.wireguard": nil,
"mount.proc": nil,
"logger.udhcpc": nil,
}
)
func (t *S6SvcTree) NetdevEnslaveInterface(iface, master string) *S6Svc {
svc_name := S6SvcName(fmt.Sprintf("interface.%s.master.%s", iface, master))
l := t.S6New(svc_name, &S6SvcTypes.Oneshot)
l.Up = strings.Join([]string{
NETDEV_EXECLINE_HEADER,
ExeclineDefine("INTERFACE", iface),
ExeclineDefine("MASTER", master),
"ip link set dev $INTERFACE master $MASTER",
}, "\n")
l.Down = strings.Join([]string{
NETDEV_EXECLINE_HEADER,
ExeclineDefine("INTERFACE", iface),
"ip link set dev $INTERFACE nomaster",
}, "\n")
l.S6Children(t.CreateIfaceService(iface), t.CreateIfaceService(master))
t.NetdevDependBundleStage(iface, "configure", l)
return l
}
func NetdevIPAddrVer(IP netip.Addr) int {
if IP.Is6() {
2024-09-04 12:22:10 +00:00
return 6
}
return 4
}
func NetdevIsDummy(s S6SvcName) (r bool) {
_, r = dummy_svc_blacklist[s]
return
}
func NetdevOnlyMAC(x net.HardwareAddr, _ error) net.HardwareAddr {
return x
}