f-88: netif: MAC d'IP flottante, règles de routage par source #88

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-29 21:14:39 +01:00
commit 19eeb0c281
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
5 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,34 @@
//go:build linux
package netif
import (
"errors"
"net"
"syscall"
"github.com/vishvananda/netlink"
)
func sourceRule(src net.IP, table, priority int, suppressDefault bool) *netlink.Rule {
r := netlink.NewRule()
r.Family = netlink.FAMILY_V4
r.Src = &net.IPNet{IP: src.To4(), Mask: net.CIDRMask(32, 32)}
r.Table = table
r.Priority = priority
if suppressDefault {
r.SuppressPrefixlen = 0
}
return r
}
func RuleAddFrom(src net.IP, table, priority int, suppressDefault bool) error {
return netlink.RuleAdd(sourceRule(src, table, priority, suppressDefault))
}
func RuleDelFromIfExists(src net.IP, table, priority int, suppressDefault bool) error {
if err := netlink.RuleDel(sourceRule(src, table, priority, suppressDefault)); err != nil && !errors.Is(err, syscall.ENOENT) {
return err
}
return nil
}