mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-04 12:27:39 +03:00
Fix tun[tun-in]: configure tun interface: file exists
This commit is contained in:
parent
3ae726d9f0
commit
10685a238e
1 changed files with 15 additions and 3 deletions
18
tun_linux.go
18
tun_linux.go
|
@ -128,7 +128,10 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
|
|||
addr4, _ := netlink.ParseAddr(address.String())
|
||||
err = netlink.AddrAdd(tunLink, addr4)
|
||||
if err != nil {
|
||||
return err
|
||||
if err == unix.EEXIST {
|
||||
continue
|
||||
}
|
||||
return E.Cause(err, "add addr v4")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,14 +140,17 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
|
|||
addr6, _ := netlink.ParseAddr(address.String())
|
||||
err = netlink.AddrAdd(tunLink, addr6)
|
||||
if err != nil {
|
||||
return err
|
||||
if err == unix.EEXIST {
|
||||
continue
|
||||
}
|
||||
return E.Cause(err, "add addr v6")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = netlink.LinkSetUp(tunLink)
|
||||
if err != nil {
|
||||
return err
|
||||
return E.Cause(err, "link up")
|
||||
}
|
||||
|
||||
if t.options.TableIndex == 0 {
|
||||
|
@ -623,6 +629,9 @@ func (t *NativeTun) setRoute(tunLink netlink.Link) error {
|
|||
for i, route := range t.routes(tunLink) {
|
||||
err := netlink.RouteAdd(&route)
|
||||
if err != nil {
|
||||
if err == unix.EEXIST {
|
||||
continue
|
||||
}
|
||||
return E.Cause(err, "add route ", i)
|
||||
}
|
||||
}
|
||||
|
@ -633,6 +642,9 @@ func (t *NativeTun) setRules() error {
|
|||
for i, rule := range t.rules() {
|
||||
err := netlink.RuleAdd(rule)
|
||||
if err != nil {
|
||||
if err == unix.EEXIST {
|
||||
continue
|
||||
}
|
||||
return E.Cause(err, "add rule ", i, "/", len(t.rules()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue