2024-09-04 12:22:10 +00:00
|
|
|
package s6netdev
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2024-09-10 13:20:23 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2024-09-10 13:20:23 +00:00
|
|
|
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
|
|
|
|
}
|
2024-09-10 13:20:23 +00:00
|
|
|
|
|
|
|
func NetdevOnlyMAC(x net.HardwareAddr, _ error) net.HardwareAddr {
|
|
|
|
return x
|
|
|
|
}
|