2022-09-25 22:04:44 +03:00
|
|
|
package tun
|
|
|
|
|
2023-10-25 00:34:12 +03:00
|
|
|
import "net"
|
|
|
|
|
2022-09-25 22:04:44 +03:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
2023-10-25 00:34:12 +03:00
|
|
|
|
|
|
|
// Route adds an entry to the system route table
|
|
|
|
func Route(dest net.IPNet) Option {
|
|
|
|
return func(tun *TUN) error {
|
|
|
|
return tun.addRoute(dest)
|
|
|
|
}
|
|
|
|
}
|
2023-10-26 04:31:05 +03:00
|
|
|
|
|
|
|
// RemoveRoute removes an entry from the system route table
|
|
|
|
func RemoveRoute(dest net.IPNet) Option {
|
|
|
|
return func(tun *TUN) error {
|
|
|
|
return tun.delRoute(dest)
|
|
|
|
}
|
|
|
|
}
|