Help us shape the future of Go! Take the 2026 Go Developer Survey

netctl

package
v1.3.104 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package netctl pkg/vpn/netctl/netctl_linux.go c4-app-vpn

netctl is a Go-native (netlink + /proc) replacement for the `ip` and `sysctl` shell-outs the VPN router/client used to make via osutil.RunElevated. Talking netlink directly is what `ip` does under the hood — identical kernel behavior — but with no iproute2 dependency, no PATH assumptions, and no per-command pkexec/sudo. That removes the "pkexec flood" on non-root hosts and, crucially, lets skywire's router run on a userland-less appliance (gokrazy) that has no `ip` binary at all. The process must hold CAP_NET_ADMIN (i.e. run privileged), which it already does wherever it performs network setup.

Firewall rules (iptables) are handled separately; see the netctl nftables backend (Phase 0b).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRuleIif

func AddRuleIif(ifName string, table int) error

AddRuleIif adds an ip rule matching packets forwarded in from ifName to look up the given table (≡ `ip rule add iif <if> lookup <t>`). It first deletes any identical rule so a restart doesn't stack duplicates.

func AddrAdd

func AddrAdd(ifName, cidr string) error

AddrAdd assigns cidr to ifName (≡ `ip addr add <cidr> dev`).

func AddrDel

func AddrDel(ifName, cidr string) error

AddrDel removes cidr from ifName (≡ `ip addr del <cidr> dev`).

func DelRuleIif

func DelRuleIif(ifName string, table int) error

DelRuleIif removes the `iif <if> lookup <t>` rule (≡ `ip rule del ...`).

func FlushAddrs

func FlushAddrs(ifName string) error

FlushAddrs removes every IPv4 address from ifName (≡ `ip addr flush dev`).

func FlushTable

func FlushTable(table int) error

FlushTable removes every route from a routing table (≡ `ip route flush table <t>`).

func GetIPv4Forwarding

func GetIPv4Forwarding() (string, error)

GetIPv4Forwarding reads net.ipv4.ip_forward (≡ `sysctl net.ipv4.ip_forward`).

func GetIPv6Forwarding

func GetIPv6Forwarding() (string, error)

GetIPv6Forwarding reads net.ipv6.conf.all.forwarding.

func LinkUp

func LinkUp(ifName string) error

LinkUp brings ifName up (≡ `ip link set <if> up`).

func ReplaceDefaultRouteDev

func ReplaceDefaultRouteDev(ifName string, table int) error

ReplaceDefaultRouteDev installs a default route out ifName (no gateway — a point-to-point tun) in the given routing table (≡ `ip route replace default dev <if> table <t>`).

func RouteAddViaGateway

func RouteAddViaGateway(dst, gateway string) error

RouteAddViaGateway adds a route to dst through gateway, failing if it already exists (≡ `ip route add <dst> via <gw>` — distinct from replace, which the callers rely on to detect a pre-existing route).

func RouteDelViaGateway

func RouteDelViaGateway(dst, gateway string) error

RouteDelViaGateway removes a route to dst through gateway (≡ `ip route del <dst> via <gw>`).

func RouteReplaceDev added in v1.3.100

func RouteReplaceDev(dst, ifName string) error

RouteReplaceDev installs a route to dst out ifName with no gateway, as for a point to point tun (≡ `ip route replace <dst> dev <if>`).

func RouteReplaceViaGateway

func RouteReplaceViaGateway(dst, gateway string) error

RouteReplaceViaGateway installs/updates a route to dst through gateway (≡ `ip route replace <dst> via <gw>` — also covers `add`/`change`, which the kernel treats as replace-or-create for our purposes).

func SetIPv4Forwarding

func SetIPv4Forwarding(val string) error

SetIPv4Forwarding writes net.ipv4.ip_forward (≡ `sysctl -w ...`).

func SetIPv6Forwarding

func SetIPv6Forwarding(val string) error

SetIPv6Forwarding writes net.ipv6.conf.all.forwarding.

func SetMTU

func SetMTU(ifName string, mtu int) error

SetMTU sets ifName's MTU (≡ `ip link set dev <if> mtu <n>`).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL