Skip to content

Commit

Permalink
feat(routes): allows duplicate subnet ranges across users
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsingh21 authored and pallabpain committed Dec 7, 2023
1 parent 47a4355 commit 1be2446
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

- Code reorganisation, a lot of code has moved, please review the following PRs accordingly [#1444](https://github.com/juanfont/headscale/pull/1444)

### 0.22.3-rr (2023-XX-XX)

### Changes
- Set max open and idle connections for postgres
- Allows conflicting subnet ranges across users

## 0.22.3 (2023-05-12)

Expand Down
26 changes: 21 additions & 5 deletions hscontrol/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,31 @@ func (h *Headscale) DeleteMachineRoutes(m *Machine) error {

// isUniquePrefix returns if there is another machine providing the same route already.
func (h *Headscale) isUniquePrefix(route Route) bool {
var count int64
h.db.
Model(&Route{}).
var routes []Route
err := h.db.
Preload("Machine").
Where("prefix = ? AND machine_id != ? AND advertised = ? AND enabled = ?",
route.Prefix,
route.MachineID,
true, true).Count(&count)
true, true).
Find(&routes).Error
if err != nil {
return true
}

if len(routes) == 0 {
return true
}

for _, r := range routes {
// Return false, if there are more than one uniquePrefix for the same
// user. Else, true. This allows having the same prefix for two users.
if route.Machine.UserID == r.Machine.UserID && route.Machine.isOnline() {
return false
}
}

return count == 0
return true
}

func (h *Headscale) getPrimaryRoute(prefix netip.Prefix) (*Route, error) {
Expand Down

0 comments on commit 1be2446

Please sign in to comment.