mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-29 03:23:56 +01:00
2475473227
All routes are now installed in a custom netbird routing table. Management and wireguard traffic is now marked with a custom fwmark. When the mark is present the traffic is routed via the main routing table, bypassing the VPN. When the mark is absent the traffic is routed via the netbird routing table, if: - there's no match in the main routing table - it would match the default route in the routing table IPv6 traffic is blocked when a default route IPv4 route is configured to avoid leakage.
48 lines
941 B
Go
48 lines
941 B
Go
package iface
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
// WGAddress Wireguard parsed address
|
|
type WGAddress struct {
|
|
IP net.IP
|
|
Network *net.IPNet
|
|
}
|
|
|
|
// parseWGAddress parse a string ("1.2.3.4/24") address to WG Address
|
|
func parseWGAddress(address string) (WGAddress, error) {
|
|
ip, network, err := net.ParseCIDR(address)
|
|
if err != nil {
|
|
return WGAddress{}, err
|
|
}
|
|
return WGAddress{
|
|
IP: ip,
|
|
Network: network,
|
|
}, nil
|
|
}
|
|
|
|
// Masked returns the WGAddress with the IP address part masked according to its network mask.
|
|
func (addr WGAddress) Masked() WGAddress {
|
|
ip := addr.IP.To4()
|
|
if ip == nil {
|
|
ip = addr.IP.To16()
|
|
}
|
|
|
|
maskedIP := make(net.IP, len(ip))
|
|
for i := range ip {
|
|
maskedIP[i] = ip[i] & addr.Network.Mask[i]
|
|
}
|
|
|
|
return WGAddress{
|
|
IP: maskedIP,
|
|
Network: addr.Network,
|
|
}
|
|
}
|
|
|
|
func (addr WGAddress) String() string {
|
|
maskSize, _ := addr.Network.Mask.Size()
|
|
return fmt.Sprintf("%s/%d", addr.IP.String(), maskSize)
|
|
}
|