depot/packages/networking/hyprspace/tun/options.go
Max 7086f652a8 packages/hyprspace: 0.7.0 -> 0.7.1
- implement route add, route del
2023-10-26 03:31:05 +02:00

44 lines
1.1 KiB
Go

package tun
import "net"
// Option defines a TUN device modifier option.
type Option func(tun *TUN) error
// Address sets the local address and subnet for an interface.
// On MacOS devices use this function to set the Src Address
// for an interface and use DestAddress to set the destination ip.
func Address(address string) Option {
return func(tun *TUN) error {
return tun.setAddress(address)
}
}
// MTU sets the Maximum Transmission Unit size for an interface.
func MTU(mtu int) Option {
return func(tun *TUN) error {
return tun.setMTU(mtu)
}
}
// DestAddress sets the destination address for a point-to-point interface.
// Only use this option on MacOS devices.
func DestAddress(address string) Option {
return func(tun *TUN) error {
return tun.setDestAddress(address)
}
}
// Route adds an entry to the system route table
func Route(dest net.IPNet) Option {
return func(tun *TUN) error {
return tun.addRoute(dest)
}
}
// RemoveRoute removes an entry from the system route table
func RemoveRoute(dest net.IPNet) Option {
return func(tun *TUN) error {
return tun.delRoute(dest)
}
}