Files
cunicu/pkg/link/link_darwin.go
Steffen Vogel 3bee839348 fix: Update copyright years
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2025-01-01 22:45:39 +01:00

49 lines
955 B
Go

// SPDX-FileCopyrightText: 2023-2025 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0
package link
import (
"net"
"go.uber.org/zap"
)
func (d *BSDLink) AddRoute(dst net.IPNet, gw net.IP, table int) error {
d.logger.Debug("Add route",
zap.String("dst", dst.String()),
zap.String("gw", gw.String()))
if table != 0 {
return errNotSupported
}
args := []string{"route", "add", "-" + addressFamily(dst), "-net", dst.String()}
if gw == nil {
args = append(args, "-interface", d.Name())
} else {
args = append(args, gw.String())
}
if _, err := run(args...); err != nil {
return err
}
return nil
}
func (d *BSDLink) DeleteRoute(dst net.IPNet, table int) error {
d.logger.Debug("Delete route",
zap.String("dst", dst.String()))
if table != 0 {
return errNotSupported
}
if _, err := run("route", "delete", "-net", dst.String(), "-interface", d.Name()); err != nil {
return err
}
return nil
}