|
| 1 | +// Copyright (c) Tailscale Inc & AUTHORS |
| 2 | +// SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +package router |
| 5 | + |
| 6 | +import ( |
| 7 | + "strings" |
| 8 | + |
| 9 | + "github.com/tailscale/wireguard-go/tun" |
| 10 | + "tailscale.com/health" |
| 11 | + "tailscale.com/net/netmon" |
| 12 | + "tailscale.com/types/logger" |
| 13 | +) |
| 14 | + |
| 15 | +// For now this router only supports the userspace WireGuard implementations. |
| 16 | + |
| 17 | +func newUserspaceRouter(logf logger.Logf, tundev tun.Device, linkMon *netmon.Monitor, health *health.Tracker) (Router, error) { |
| 18 | + return newUserspaceSunosRouter(logf, tundev, linkMon, health) |
| 19 | +} |
| 20 | + |
| 21 | +func cleanUp(logf logger.Logf, interfaceName string) { |
| 22 | + ipadm := []string{"ipadm", "show-addr", "-p", "-o", "addrobj"} |
| 23 | + out, err := cmd(ipadm...).Output() |
| 24 | + if err != nil { |
| 25 | + logf("ipadm show-addr: %v\n%s", err, out) |
| 26 | + } |
| 27 | + for _, a := range strings.Fields(string(out)) { |
| 28 | + s := strings.Split(a, "/") |
| 29 | + if len(s) > 1 && strings.Contains(s[1], "tailscale") { |
| 30 | + ipadm = []string{"ipadm", "down-addr", "-t", a} |
| 31 | + cmdVerbose(logf, ipadm) |
| 32 | + ipadm = []string{"ipadm", "delete-addr", a} |
| 33 | + cmdVerbose(logf, ipadm) |
| 34 | + ipadm = []string{"ipadm", "delete-if", s[0]} |
| 35 | + cmdVerbose(logf, ipadm) |
| 36 | + } |
| 37 | + } |
| 38 | + ifcfg := []string{"ifconfig", interfaceName, "unplumb"} |
| 39 | + if out, err := cmd(ifcfg...).CombinedOutput(); err != nil { |
| 40 | + logf("ifconfig unplumb: %v\n%s", err, out) |
| 41 | + } |
| 42 | + ifcfg = []string{"ifconfig", interfaceName, "inet6", "unplumb"} |
| 43 | + if out, err := cmd(ifcfg...).CombinedOutput(); err != nil { |
| 44 | + logf("ifconfig inet6 unplumb: %v\n%s", err, out) |
| 45 | + } |
| 46 | +} |
0 commit comments