mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-17 17:04:01 +02:00
chore(all): replace netlink library for more flexibility (#3107)
This commit is contained in:
@@ -9,25 +9,33 @@ import (
|
||||
)
|
||||
|
||||
func (r *Routing) addRouteVia(destination netip.Prefix, gateway netip.Addr,
|
||||
iface string, table int,
|
||||
iface string, table uint32,
|
||||
) error {
|
||||
destinationStr := destination.String()
|
||||
r.logger.Info("adding route for " + destinationStr)
|
||||
r.logger.Debug("ip route replace " + destinationStr +
|
||||
" via " + gateway.String() +
|
||||
" dev " + iface +
|
||||
" table " + strconv.Itoa(table))
|
||||
" table " + strconv.Itoa(int(table)))
|
||||
|
||||
link, err := r.netLinker.LinkByName(iface)
|
||||
if err != nil {
|
||||
return fmt.Errorf("finding link for interface %s: %w", iface, err)
|
||||
}
|
||||
|
||||
family := netlink.FamilyV4
|
||||
if destination.Addr().Is6() {
|
||||
family = netlink.FamilyV6
|
||||
}
|
||||
route := netlink.Route{
|
||||
Dst: destination,
|
||||
Gw: gateway,
|
||||
LinkIndex: link.Index,
|
||||
Family: family,
|
||||
Table: table,
|
||||
Type: netlink.RouteTypeUnicast,
|
||||
Scope: netlink.ScopeUniverse,
|
||||
Proto: netlink.ProtoStatic,
|
||||
}
|
||||
if err := r.netLinker.RouteReplace(route); err != nil {
|
||||
return fmt.Errorf("replacing route for subnet %s at interface %s: %w",
|
||||
@@ -38,24 +46,29 @@ func (r *Routing) addRouteVia(destination netip.Prefix, gateway netip.Addr,
|
||||
}
|
||||
|
||||
func (r *Routing) deleteRouteVia(destination netip.Prefix, gateway netip.Addr,
|
||||
iface string, table int,
|
||||
iface string, table uint32,
|
||||
) (err error) {
|
||||
destinationStr := destination.String()
|
||||
r.logger.Info("deleting route for " + destinationStr)
|
||||
r.logger.Debug("ip route delete " + destinationStr +
|
||||
" via " + gateway.String() +
|
||||
" dev " + iface +
|
||||
" table " + strconv.Itoa(table))
|
||||
" table " + strconv.Itoa(int(table)))
|
||||
|
||||
link, err := r.netLinker.LinkByName(iface)
|
||||
if err != nil {
|
||||
return fmt.Errorf("finding link for interface %s: %w", iface, err)
|
||||
}
|
||||
|
||||
family := netlink.FamilyV4
|
||||
if destination.Addr().Is6() {
|
||||
family = netlink.FamilyV6
|
||||
}
|
||||
route := netlink.Route{
|
||||
Dst: destination,
|
||||
Gw: gateway,
|
||||
LinkIndex: link.Index,
|
||||
Family: family,
|
||||
Table: table,
|
||||
}
|
||||
if err := r.netLinker.RouteDel(route); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user