Skip to content

Commit

Permalink
fix(wireguard): specify family for new route
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Dec 27, 2024
1 parent 8dae352 commit abcb7af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/wireguard/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ func (w *Wireguard) addRoutes(link netlink.Link, destinations []netip.Prefix,
func (w *Wireguard) addRoute(link netlink.Link, dst netip.Prefix,
firewallMark uint32,
) (err error) {
family := netlink.FamilyV4
if dst.Addr().Is6() {
family = netlink.FamilyV6
}
route := netlink.Route{
LinkIndex: link.Index,
Dst: dst,
Family: family,
Table: int(firewallMark),
}

Expand Down
2 changes: 2 additions & 0 deletions internal/wireguard/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Test_Wireguard_addRoute(t *testing.T) {
expectedRoute: netlink.Route{
LinkIndex: linkIndex,
Dst: ipPrefix,
Family: netlink.FamilyV4,
Table: firewallMark,
},
},
Expand All @@ -49,6 +50,7 @@ func Test_Wireguard_addRoute(t *testing.T) {
expectedRoute: netlink.Route{
LinkIndex: linkIndex,
Dst: ipPrefix,
Family: netlink.FamilyV4,
Table: firewallMark,
},
routeAddErr: errDummy,
Expand Down

0 comments on commit abcb7af

Please sign in to comment.