mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2026-04-23 06:59:40 +08:00
7391bfcbc9
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
42 lines
864 B
Go
42 lines
864 B
Go
package device
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/stv0g/cunicu/pkg/errors"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (d *BSDKernelDevice) 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 errors.ErrNotSupported
|
|
}
|
|
|
|
args := []string{"route", "add", fmt.Sprintf("-%s", addressFamily(dst)), "-net", dst.String()}
|
|
if gw == nil {
|
|
args = append(args, "-interface", d.Name())
|
|
} else {
|
|
args = append(args, gw.String())
|
|
}
|
|
|
|
_, err := run(args...)
|
|
return err
|
|
}
|
|
|
|
func (d *BSDKernelDevice) DeleteRoute(dst net.IPNet, table int) error {
|
|
d.logger.Debug("Delete route",
|
|
zap.String("dst", dst.String()))
|
|
|
|
if table != 0 {
|
|
return errors.ErrNotSupported
|
|
}
|
|
|
|
_, err := run("route", "delete", "-net", dst.String(), "-interface", d.Name())
|
|
return err
|
|
}
|