Skip to content

Commit df12241

Browse files
fix(go): create and remove alias during create and close; (#1229)
1 parent 63cd3d4 commit df12241

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

wireguard/wireguard_darwin.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ import (
1515

1616
// NCIface.Create - makes a new Wireguard interface for darwin users (userspace)
1717
func (nc *NCIface) Create() error {
18-
return nc.createUserSpaceWG()
18+
err := nc.createUserSpaceWG()
19+
if err != nil {
20+
return err
21+
}
22+
23+
cmd := exec.Command("ifconfig", "lo0", "alias", "127.51.8.21")
24+
out, err := cmd.CombinedOutput()
25+
if err != nil {
26+
slog.Error("failed to add address for dns server", "command", cmd.String(), "error", string(out))
27+
return err
28+
}
29+
30+
return nil
1931
}
2032

2133
// NCIface.ApplyAddrs - applies address for darwin userspace
@@ -56,13 +68,6 @@ func (nc *NCIface) ApplyAddrs() error {
5668

5769
}
5870

59-
cmd := exec.Command("ifconfig", "lo0", "alias", "127.51.8.21")
60-
out, err := cmd.CombinedOutput()
61-
if err != nil {
62-
slog.Error("failed to add address for dns server", "command", cmd.String(), "error", string(out))
63-
return err
64-
}
65-
6671
return nil
6772
}
6873

@@ -100,12 +105,6 @@ func RemoveRoutes(addrs []ifaceAddress) {
100105
}
101106

102107
}
103-
104-
cmd = exec.Command("ifconfig", "lo0", "-alias", "127.51.8.21")
105-
out, err := cmd.CombinedOutput()
106-
if err != nil {
107-
slog.Error("failed to remove address for dns server", "command", cmd.String(), "error", string(out))
108-
}
109108
}
110109

111110
// SetRoutes - sets additional routes to the interface
@@ -167,6 +166,11 @@ func (nc *NCIface) Close() {
167166
}
168167
}
169168

169+
cmd := exec.Command("ifconfig", "lo0", "-alias", "127.51.8.21")
170+
out, err := cmd.CombinedOutput()
171+
if err != nil {
172+
slog.Error("failed to remove address for dns server", "command", cmd.String(), "error", string(out))
173+
}
170174
}
171175

172176
// DeleteOldInterface - removes named interface

0 commit comments

Comments
 (0)