Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Oct 19, 2024
1 parent 3dfb43e commit 7b8f9be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/vpn/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Router interface {
type Ruler interface {
RuleAdd(rule netlink.Rule) error
RuleDel(rule netlink.Rule) error
RuleList(family int) (rules []netlink.Rule, err error)
}

type Linker interface {
Expand Down
1 change: 1 addition & 0 deletions internal/wireguard/netlinker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Router interface {
type Ruler interface {
RuleAdd(rule netlink.Rule) error
RuleDel(rule netlink.Rule) error
RuleList(family int) ([]netlink.Rule, error)
}

type Linker interface {
Expand Down
15 changes: 15 additions & 0 deletions internal/wireguard/netlinker_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions internal/wireguard/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wireguard

import (
"fmt"
"strings"

"github.com/qdm12/gluetun/internal/netlink"
)
Expand All @@ -16,6 +17,18 @@ func (w *Wireguard) addRule(rulePriority int, firewallMark uint32,
rule.Table = int(firewallMark)
rule.Family = family
if err := w.netlink.RuleAdd(rule); err != nil {
if strings.Contains(err.Error(), "file exists") {
rules, listErr := w.netlink.RuleList(family)
if listErr != nil {
return nil, fmt.Errorf("listing rules for family %d due to %q: %w",
family, err, listErr)
}
ruleStrings := make([]string, len(rules))
for i := range rules {
ruleStrings[i] = rules[i].String()
}
w.logger.Info("existing rules are:\n" + strings.Join(ruleStrings, "\n"))
}
return nil, fmt.Errorf("adding rule %s: %w", rule, err)
}

Expand Down

0 comments on commit 7b8f9be

Please sign in to comment.