iptables_runner.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build linux
  4. package linuxfw
  5. import (
  6. "fmt"
  7. "net/netip"
  8. "os/exec"
  9. "strconv"
  10. "strings"
  11. "github.com/coreos/go-iptables/iptables"
  12. "tailscale.com/net/tsaddr"
  13. "tailscale.com/types/logger"
  14. "tailscale.com/util/multierr"
  15. )
  16. type iptablesInterface interface {
  17. // Adding this interface for testing purposes so we can mock out
  18. // the iptables library, in reality this is a wrapper to *iptables.IPTables.
  19. Insert(table, chain string, pos int, args ...string) error
  20. Append(table, chain string, args ...string) error
  21. Exists(table, chain string, args ...string) (bool, error)
  22. Delete(table, chain string, args ...string) error
  23. ClearChain(table, chain string) error
  24. NewChain(table, chain string) error
  25. DeleteChain(table, chain string) error
  26. }
  27. type iptablesRunner struct {
  28. ipt4 iptablesInterface
  29. ipt6 iptablesInterface
  30. v6Available bool
  31. v6NATAvailable bool
  32. }
  33. func checkIP6TablesExists() error {
  34. // Some distros ship ip6tables separately from iptables.
  35. if _, err := exec.LookPath("ip6tables"); err != nil {
  36. return fmt.Errorf("path not found: %w", err)
  37. }
  38. return nil
  39. }
  40. // newIPTablesRunner constructs a NetfilterRunner that programs iptables rules.
  41. // If the underlying iptables library fails to initialize, that error is
  42. // returned. The runner probes for IPv6 support once at initialization time and
  43. // if not found, no IPv6 rules will be modified for the lifetime of the runner.
  44. func newIPTablesRunner(logf logger.Logf) (*iptablesRunner, error) {
  45. ipt4, err := iptables.NewWithProtocol(iptables.ProtocolIPv4)
  46. if err != nil {
  47. return nil, err
  48. }
  49. supportsV6, supportsV6NAT := false, false
  50. v6err := checkIPv6(logf)
  51. ip6terr := checkIP6TablesExists()
  52. switch {
  53. case v6err != nil:
  54. logf("disabling tunneled IPv6 due to system IPv6 config: %v", v6err)
  55. case ip6terr != nil:
  56. logf("disabling tunneled IPv6 due to missing ip6tables: %v", ip6terr)
  57. default:
  58. supportsV6 = true
  59. supportsV6NAT = supportsV6 && checkSupportsV6NAT()
  60. logf("v6nat = %v", supportsV6NAT)
  61. }
  62. var ipt6 *iptables.IPTables
  63. if supportsV6 {
  64. ipt6, err = iptables.NewWithProtocol(iptables.ProtocolIPv6)
  65. if err != nil {
  66. return nil, err
  67. }
  68. }
  69. return &iptablesRunner{ipt4, ipt6, supportsV6, supportsV6NAT}, nil
  70. }
  71. // HasIPV6 reports true if the system supports IPv6.
  72. func (i *iptablesRunner) HasIPV6() bool {
  73. return i.v6Available
  74. }
  75. // HasIPV6NAT reports true if the system supports IPv6 NAT.
  76. func (i *iptablesRunner) HasIPV6NAT() bool {
  77. return i.v6NATAvailable
  78. }
  79. func isErrChainNotExist(err error) bool {
  80. return errCode(err) == 1
  81. }
  82. // getIPTByAddr returns the iptablesInterface with correct IP family
  83. // that we will be using for the given address.
  84. func (i *iptablesRunner) getIPTByAddr(addr netip.Addr) iptablesInterface {
  85. nf := i.ipt4
  86. if addr.Is6() {
  87. nf = i.ipt6
  88. }
  89. return nf
  90. }
  91. // AddLoopbackRule adds an iptables rule to permit loopback traffic to
  92. // a local Tailscale IP.
  93. func (i *iptablesRunner) AddLoopbackRule(addr netip.Addr) error {
  94. if err := i.getIPTByAddr(addr).Insert("filter", "ts-input", 1, "-i", "lo", "-s", addr.String(), "-j", "ACCEPT"); err != nil {
  95. return fmt.Errorf("adding loopback allow rule for %q: %w", addr, err)
  96. }
  97. return nil
  98. }
  99. // tsChain returns the name of the tailscale sub-chain corresponding
  100. // to the given "parent" chain (e.g. INPUT, FORWARD, ...).
  101. func tsChain(chain string) string {
  102. return "ts-" + strings.ToLower(chain)
  103. }
  104. // DelLoopbackRule removes the iptables rule permitting loopback
  105. // traffic to a Tailscale IP.
  106. func (i *iptablesRunner) DelLoopbackRule(addr netip.Addr) error {
  107. if err := i.getIPTByAddr(addr).Delete("filter", "ts-input", "-i", "lo", "-s", addr.String(), "-j", "ACCEPT"); err != nil {
  108. return fmt.Errorf("deleting loopback allow rule for %q: %w", addr, err)
  109. }
  110. return nil
  111. }
  112. // getTables gets the available iptablesInterface in iptables runner.
  113. func (i *iptablesRunner) getTables() []iptablesInterface {
  114. if i.HasIPV6() {
  115. return []iptablesInterface{i.ipt4, i.ipt6}
  116. }
  117. return []iptablesInterface{i.ipt4}
  118. }
  119. // getNATTables gets the available iptablesInterface in iptables runner.
  120. // If the system does not support IPv6 NAT, only the IPv4 iptablesInterface
  121. // is returned.
  122. func (i *iptablesRunner) getNATTables() []iptablesInterface {
  123. if i.HasIPV6NAT() {
  124. return i.getTables()
  125. }
  126. return []iptablesInterface{i.ipt4}
  127. }
  128. // AddHooks inserts calls to tailscale's netfilter chains in
  129. // the relevant main netfilter chains. The tailscale chains must
  130. // already exist. If they do not, an error is returned.
  131. func (i *iptablesRunner) AddHooks() error {
  132. // divert inserts a jump to the tailscale chain in the given table/chain.
  133. // If the jump already exists, it is a no-op.
  134. divert := func(ipt iptablesInterface, table, chain string) error {
  135. tsChain := tsChain(chain)
  136. args := []string{"-j", tsChain}
  137. exists, err := ipt.Exists(table, chain, args...)
  138. if err != nil {
  139. return fmt.Errorf("checking for %v in %s/%s: %w", args, table, chain, err)
  140. }
  141. if exists {
  142. return nil
  143. }
  144. if err := ipt.Insert(table, chain, 1, args...); err != nil {
  145. return fmt.Errorf("adding %v in %s/%s: %w", args, table, chain, err)
  146. }
  147. return nil
  148. }
  149. for _, ipt := range i.getTables() {
  150. if err := divert(ipt, "filter", "INPUT"); err != nil {
  151. return err
  152. }
  153. if err := divert(ipt, "filter", "FORWARD"); err != nil {
  154. return err
  155. }
  156. }
  157. for _, ipt := range i.getNATTables() {
  158. if err := divert(ipt, "nat", "POSTROUTING"); err != nil {
  159. return err
  160. }
  161. }
  162. return nil
  163. }
  164. // AddChains creates custom Tailscale chains in netfilter via iptables
  165. // if the ts-chain doesn't already exist.
  166. func (i *iptablesRunner) AddChains() error {
  167. // create creates a chain in the given table if it doesn't already exist.
  168. // If the chain already exists, it is a no-op.
  169. create := func(ipt iptablesInterface, table, chain string) error {
  170. err := ipt.ClearChain(table, chain)
  171. if isErrChainNotExist(err) {
  172. // nonexistent chain. let's create it!
  173. return ipt.NewChain(table, chain)
  174. }
  175. if err != nil {
  176. return fmt.Errorf("setting up %s/%s: %w", table, chain, err)
  177. }
  178. return nil
  179. }
  180. for _, ipt := range i.getTables() {
  181. if err := create(ipt, "filter", "ts-input"); err != nil {
  182. return err
  183. }
  184. if err := create(ipt, "filter", "ts-forward"); err != nil {
  185. return err
  186. }
  187. }
  188. for _, ipt := range i.getNATTables() {
  189. if err := create(ipt, "nat", "ts-postrouting"); err != nil {
  190. return err
  191. }
  192. }
  193. return nil
  194. }
  195. // AddBase adds some basic processing rules to be supplemented by
  196. // later calls to other helpers.
  197. func (i *iptablesRunner) AddBase(tunname string) error {
  198. if err := i.addBase4(tunname); err != nil {
  199. return err
  200. }
  201. if i.HasIPV6() {
  202. if err := i.addBase6(tunname); err != nil {
  203. return err
  204. }
  205. }
  206. return nil
  207. }
  208. // addBase4 adds some basic IPv4 processing rules to be
  209. // supplemented by later calls to other helpers.
  210. func (i *iptablesRunner) addBase4(tunname string) error {
  211. // Only allow CGNAT range traffic to come from tailscale0. There
  212. // is an exception carved out for ranges used by ChromeOS, for
  213. // which we fall out of the Tailscale chain.
  214. //
  215. // Note, this will definitely break nodes that end up using the
  216. // CGNAT range for other purposes :(.
  217. args := []string{"!", "-i", tunname, "-s", tsaddr.ChromeOSVMRange().String(), "-j", "RETURN"}
  218. if err := i.ipt4.Append("filter", "ts-input", args...); err != nil {
  219. return fmt.Errorf("adding %v in v4/filter/ts-input: %w", args, err)
  220. }
  221. args = []string{"!", "-i", tunname, "-s", tsaddr.CGNATRange().String(), "-j", "DROP"}
  222. if err := i.ipt4.Append("filter", "ts-input", args...); err != nil {
  223. return fmt.Errorf("adding %v in v4/filter/ts-input: %w", args, err)
  224. }
  225. // Explicitly allow all other inbound traffic to the tun interface
  226. args = []string{"-i", tunname, "-j", "ACCEPT"}
  227. if err := i.ipt4.Append("filter", "ts-input", args...); err != nil {
  228. return fmt.Errorf("adding %v in v4/filter/ts-input: %w", args, err)
  229. }
  230. // Forward all traffic from the Tailscale interface, and drop
  231. // traffic to the tailscale interface by default. We use packet
  232. // marks here so both filter/FORWARD and nat/POSTROUTING can match
  233. // on these packets of interest.
  234. //
  235. // In particular, we only want to apply SNAT rules in
  236. // nat/POSTROUTING to packets that originated from the Tailscale
  237. // interface, but we can't match on the inbound interface in
  238. // POSTROUTING. So instead, we match on the inbound interface in
  239. // filter/FORWARD, and set a packet mark that nat/POSTROUTING can
  240. // use to effectively run that same test again.
  241. args = []string{"-i", tunname, "-j", "MARK", "--set-mark", TailscaleSubnetRouteMark + "/" + TailscaleFwmarkMask}
  242. if err := i.ipt4.Append("filter", "ts-forward", args...); err != nil {
  243. return fmt.Errorf("adding %v in v4/filter/ts-forward: %w", args, err)
  244. }
  245. args = []string{"-m", "mark", "--mark", TailscaleSubnetRouteMark + "/" + TailscaleFwmarkMask, "-j", "ACCEPT"}
  246. if err := i.ipt4.Append("filter", "ts-forward", args...); err != nil {
  247. return fmt.Errorf("adding %v in v4/filter/ts-forward: %w", args, err)
  248. }
  249. args = []string{"-o", tunname, "-s", tsaddr.CGNATRange().String(), "-j", "DROP"}
  250. if err := i.ipt4.Append("filter", "ts-forward", args...); err != nil {
  251. return fmt.Errorf("adding %v in v4/filter/ts-forward: %w", args, err)
  252. }
  253. args = []string{"-o", tunname, "-j", "ACCEPT"}
  254. if err := i.ipt4.Append("filter", "ts-forward", args...); err != nil {
  255. return fmt.Errorf("adding %v in v4/filter/ts-forward: %w", args, err)
  256. }
  257. return nil
  258. }
  259. func (i *iptablesRunner) AddDNATRule(origDst, dst netip.Addr) error {
  260. table := i.getIPTByAddr(dst)
  261. return table.Insert("nat", "PREROUTING", 1, "--destination", origDst.String(), "-j", "DNAT", "--to-destination", dst.String())
  262. }
  263. func (i *iptablesRunner) AddSNATRuleForDst(src, dst netip.Addr) error {
  264. table := i.getIPTByAddr(dst)
  265. return table.Insert("nat", "POSTROUTING", 1, "--destination", dst.String(), "-j", "SNAT", "--to-source", src.String())
  266. }
  267. func (i *iptablesRunner) DNATNonTailscaleTraffic(tun string, dst netip.Addr) error {
  268. table := i.getIPTByAddr(dst)
  269. return table.Insert("nat", "PREROUTING", 1, "!", "-i", tun, "-j", "DNAT", "--to-destination", dst.String())
  270. }
  271. func (i *iptablesRunner) ClampMSSToPMTU(tun string, addr netip.Addr) error {
  272. table := i.getIPTByAddr(addr)
  273. return table.Append("mangle", "FORWARD", "-o", tun, "-p", "tcp", "--tcp-flags", "SYN,RST", "SYN", "-j", "TCPMSS", "--clamp-mss-to-pmtu")
  274. }
  275. // addBase6 adds some basic IPv6 processing rules to be
  276. // supplemented by later calls to other helpers.
  277. func (i *iptablesRunner) addBase6(tunname string) error {
  278. // TODO: only allow traffic from Tailscale's ULA range to come
  279. // from tailscale0.
  280. // Explicitly allow all other inbound traffic to the tun interface
  281. args := []string{"-i", tunname, "-j", "ACCEPT"}
  282. if err := i.ipt6.Append("filter", "ts-input", args...); err != nil {
  283. return fmt.Errorf("adding %v in v6/filter/ts-input: %w", args, err)
  284. }
  285. args = []string{"-i", tunname, "-j", "MARK", "--set-mark", TailscaleSubnetRouteMark + "/" + TailscaleFwmarkMask}
  286. if err := i.ipt6.Append("filter", "ts-forward", args...); err != nil {
  287. return fmt.Errorf("adding %v in v6/filter/ts-forward: %w", args, err)
  288. }
  289. args = []string{"-m", "mark", "--mark", TailscaleSubnetRouteMark + "/" + TailscaleFwmarkMask, "-j", "ACCEPT"}
  290. if err := i.ipt6.Append("filter", "ts-forward", args...); err != nil {
  291. return fmt.Errorf("adding %v in v6/filter/ts-forward: %w", args, err)
  292. }
  293. // TODO: drop forwarded traffic to tailscale0 from tailscale's ULA
  294. // (see corresponding IPv4 CGNAT rule).
  295. args = []string{"-o", tunname, "-j", "ACCEPT"}
  296. if err := i.ipt6.Append("filter", "ts-forward", args...); err != nil {
  297. return fmt.Errorf("adding %v in v6/filter/ts-forward: %w", args, err)
  298. }
  299. return nil
  300. }
  301. // DelChains removes the custom Tailscale chains from netfilter via iptables.
  302. func (i *iptablesRunner) DelChains() error {
  303. for _, ipt := range i.getTables() {
  304. if err := delChain(ipt, "filter", "ts-input"); err != nil {
  305. return err
  306. }
  307. if err := delChain(ipt, "filter", "ts-forward"); err != nil {
  308. return err
  309. }
  310. }
  311. for _, ipt := range i.getNATTables() {
  312. if err := delChain(ipt, "nat", "ts-postrouting"); err != nil {
  313. return err
  314. }
  315. }
  316. return nil
  317. }
  318. // DelBase empties but does not remove custom Tailscale chains from
  319. // netfilter via iptables.
  320. func (i *iptablesRunner) DelBase() error {
  321. del := func(ipt iptablesInterface, table, chain string) error {
  322. if err := ipt.ClearChain(table, chain); err != nil {
  323. if isErrChainNotExist(err) {
  324. // nonexistent chain. That's fine, since it's
  325. // the desired state anyway.
  326. return nil
  327. }
  328. return fmt.Errorf("flushing %s/%s: %w", table, chain, err)
  329. }
  330. return nil
  331. }
  332. for _, ipt := range i.getTables() {
  333. if err := del(ipt, "filter", "ts-input"); err != nil {
  334. return err
  335. }
  336. if err := del(ipt, "filter", "ts-forward"); err != nil {
  337. return err
  338. }
  339. }
  340. for _, ipt := range i.getNATTables() {
  341. if err := del(ipt, "nat", "ts-postrouting"); err != nil {
  342. return err
  343. }
  344. }
  345. return nil
  346. }
  347. // DelHooks deletes the calls to tailscale's netfilter chains
  348. // in the relevant main netfilter chains.
  349. func (i *iptablesRunner) DelHooks(logf logger.Logf) error {
  350. for _, ipt := range i.getTables() {
  351. if err := delTSHook(ipt, "filter", "INPUT", logf); err != nil {
  352. return err
  353. }
  354. if err := delTSHook(ipt, "filter", "FORWARD", logf); err != nil {
  355. return err
  356. }
  357. }
  358. for _, ipt := range i.getNATTables() {
  359. if err := delTSHook(ipt, "nat", "POSTROUTING", logf); err != nil {
  360. return err
  361. }
  362. }
  363. return nil
  364. }
  365. // AddSNATRule adds a netfilter rule to SNAT traffic destined for
  366. // local subnets.
  367. func (i *iptablesRunner) AddSNATRule() error {
  368. args := []string{"-m", "mark", "--mark", TailscaleSubnetRouteMark + "/" + TailscaleFwmarkMask, "-j", "MASQUERADE"}
  369. for _, ipt := range i.getNATTables() {
  370. if err := ipt.Append("nat", "ts-postrouting", args...); err != nil {
  371. return fmt.Errorf("adding %v in nat/ts-postrouting: %w", args, err)
  372. }
  373. }
  374. return nil
  375. }
  376. // DelSNATRule removes the netfilter rule to SNAT traffic destined for
  377. // local subnets. An error is returned if the rule does not exist.
  378. func (i *iptablesRunner) DelSNATRule() error {
  379. args := []string{"-m", "mark", "--mark", TailscaleSubnetRouteMark + "/" + TailscaleFwmarkMask, "-j", "MASQUERADE"}
  380. for _, ipt := range i.getNATTables() {
  381. if err := ipt.Delete("nat", "ts-postrouting", args...); err != nil {
  382. return fmt.Errorf("deleting %v in nat/ts-postrouting: %w", args, err)
  383. }
  384. }
  385. return nil
  386. }
  387. // buildMagicsockPortRule generates the string slice containing the arguments
  388. // to describe a rule accepting traffic on a particular port to iptables. It is
  389. // separated out here to avoid repetition in AddMagicsockPortRule and
  390. // RemoveMagicsockPortRule, since it is important that the same rule is passed
  391. // to Append() and Delete().
  392. func buildMagicsockPortRule(port uint16) []string {
  393. return []string{"-p", "udp", "--dport", strconv.FormatUint(uint64(port), 10), "-j", "ACCEPT"}
  394. }
  395. // AddMagicsockPortRule adds a rule to iptables to allow incoming traffic on
  396. // the specified UDP port, so magicsock can accept incoming connections.
  397. // network must be either "udp4" or "udp6" - this determines whether the rule
  398. // is added for IPv4 or IPv6.
  399. func (i *iptablesRunner) AddMagicsockPortRule(port uint16, network string) error {
  400. var ipt iptablesInterface
  401. switch network {
  402. case "udp4":
  403. ipt = i.ipt4
  404. case "udp6":
  405. ipt = i.ipt6
  406. default:
  407. return fmt.Errorf("unsupported network %s", network)
  408. }
  409. args := buildMagicsockPortRule(port)
  410. if err := ipt.Append("filter", "ts-input", args...); err != nil {
  411. return fmt.Errorf("adding %v in filter/ts-input: %w", args, err)
  412. }
  413. return nil
  414. }
  415. // DelMagicsockPortRule removes a rule added by AddMagicsockPortRule to accept
  416. // incoming traffic on a particular UDP port.
  417. // network must be either "udp4" or "udp6" - this determines whether the rule
  418. // is removed for IPv4 or IPv6.
  419. func (i *iptablesRunner) DelMagicsockPortRule(port uint16, network string) error {
  420. var ipt iptablesInterface
  421. switch network {
  422. case "udp4":
  423. ipt = i.ipt4
  424. case "udp6":
  425. ipt = i.ipt6
  426. default:
  427. return fmt.Errorf("unsupported network %s", network)
  428. }
  429. args := buildMagicsockPortRule(port)
  430. if err := ipt.Delete("filter", "ts-input", args...); err != nil {
  431. return fmt.Errorf("removing %v in filter/ts-input: %w", args, err)
  432. }
  433. return nil
  434. }
  435. // IPTablesCleanup removes all Tailscale added iptables rules.
  436. // Any errors that occur are logged to the provided logf.
  437. func IPTablesCleanup(logf logger.Logf) {
  438. err := clearRules(iptables.ProtocolIPv4, logf)
  439. if err != nil {
  440. logf("linuxfw: clear iptables: %v", err)
  441. }
  442. err = clearRules(iptables.ProtocolIPv6, logf)
  443. if err != nil {
  444. logf("linuxfw: clear ip6tables: %v", err)
  445. }
  446. }
  447. // delTSHook deletes hook in a chain that jumps to a ts-chain. If the hook does not
  448. // exist, it's a no-op since the desired state is already achieved but we log the
  449. // error because error code from the iptables module resists unwrapping.
  450. func delTSHook(ipt iptablesInterface, table, chain string, logf logger.Logf) error {
  451. tsChain := tsChain(chain)
  452. args := []string{"-j", tsChain}
  453. if err := ipt.Delete(table, chain, args...); err != nil {
  454. // TODO(apenwarr): check for errCode(1) here.
  455. // Unfortunately the error code from the iptables
  456. // module resists unwrapping, unlike with other
  457. // calls. So we have to assume if Delete fails,
  458. // it's because there is no such rule.
  459. logf("deleting %v in %s/%s: %v", args, table, chain, err)
  460. return nil
  461. }
  462. return nil
  463. }
  464. // delChain flushs and deletes a chain. If the chain does not exist, it's a no-op
  465. // since the desired state is already achieved. otherwise, it returns an error.
  466. func delChain(ipt iptablesInterface, table, chain string) error {
  467. if err := ipt.ClearChain(table, chain); err != nil {
  468. if isErrChainNotExist(err) {
  469. // nonexistent chain. nothing to do.
  470. return nil
  471. }
  472. return fmt.Errorf("flushing %s/%s: %w", table, chain, err)
  473. }
  474. if err := ipt.DeleteChain(table, chain); err != nil {
  475. return fmt.Errorf("deleting %s/%s: %w", table, chain, err)
  476. }
  477. return nil
  478. }
  479. // clearRules clears all the iptables rules created by Tailscale
  480. // for the given protocol. If error occurs, it's logged but not returned.
  481. func clearRules(proto iptables.Protocol, logf logger.Logf) error {
  482. ipt, err := iptables.NewWithProtocol(proto)
  483. if err != nil {
  484. return err
  485. }
  486. var errs []error
  487. if err := delTSHook(ipt, "filter", "INPUT", logf); err != nil {
  488. errs = append(errs, err)
  489. }
  490. if err := delTSHook(ipt, "filter", "FORWARD", logf); err != nil {
  491. errs = append(errs, err)
  492. }
  493. if err := delTSHook(ipt, "nat", "POSTROUTING", logf); err != nil {
  494. errs = append(errs, err)
  495. }
  496. if err := delChain(ipt, "filter", "ts-input"); err != nil {
  497. errs = append(errs, err)
  498. }
  499. if err := delChain(ipt, "filter", "ts-forward"); err != nil {
  500. errs = append(errs, err)
  501. }
  502. if err := delChain(ipt, "nat", "ts-postrouting"); err != nil {
  503. errs = append(errs, err)
  504. }
  505. return multierr.New(errs...)
  506. }