Add primary routes to node

Signed-off-by: Kristoffer Dalby <kristoffer@dalby.cc>
This commit is contained in:
Kristoffer Dalby 2022-09-18 11:36:35 +02:00
parent a0a463494b
commit 33ae56acfa
No known key found for this signature in database

View File

@ -35,6 +35,11 @@ const (
maxHostnameLength = 255 maxHostnameLength = 255
) )
var (
ExitRouteV4 = netip.MustParsePrefix("0.0.0.0/0")
ExitRouteV6 = netip.MustParsePrefix("::/0")
)
// Machine is a Headscale client. // Machine is a Headscale client.
type Machine struct { type Machine struct {
ID uint64 `gorm:"primary_key"` ID uint64 `gorm:"primary_key"`
@ -633,10 +638,17 @@ func (machine Machine) toNode(
[]netip.Prefix{}, []netip.Prefix{},
addrs...) // we append the node own IP, as it is required by the clients addrs...) // we append the node own IP, as it is required by the clients
// TODO(kradalby): Needs investigation, We probably dont need this condition allowedIPs = append(allowedIPs, machine.EnabledRoutes...)
// now that we dont have shared nodes
if includeRoutes { primaryRoutes := []netip.Prefix{}
allowedIPs = append(allowedIPs, machine.EnabledRoutes...) if len(machine.EnabledRoutes) > 0 {
for _, route := range machine.EnabledRoutes {
if route == ExitRouteV4 || route == ExitRouteV6 {
continue
}
primaryRoutes = append(primaryRoutes, route)
}
} }
var derp string var derp string
@ -691,6 +703,7 @@ func (machine Machine) toNode(
DiscoKey: discoKey, DiscoKey: discoKey,
Addresses: addrs, Addresses: addrs,
AllowedIPs: allowedIPs, AllowedIPs: allowedIPs,
PrimaryRoutes: primaryRoutes,
Endpoints: machine.Endpoints, Endpoints: machine.Endpoints,
DERP: derp, DERP: derp,