Fix tun[tun-in]: configure tun interface: file exists

This commit is contained in:
Songmin Li 2023-10-04 17:35:25 +08:00
parent 3ae726d9f0
commit 10685a238e
No known key found for this signature in database
GPG key ID: 41429E91BC1F9155

View file

@ -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()))
}
}