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:
parent
6ecac451ee
commit
1aa7f177f9
5 changed files with 110 additions and 0 deletions
34
internal/netif/rule_linux.go
Normal file
34
internal/netif/rule_linux.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue