brctl

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

package brctl provides a Go interface to the Linux bridge control (brctl) command. It allows you to manage Ethernet bridges and their interfaces, including adding and deleting bridges, adding and deleting interfaces, and configuring various bridge parameters.

The original C implementation offers the ability to issue the bridge configuration in 2 ways: 1. `ioctl` and 2. `sysfs`. Since all modern systems deploy the `sysfs` we use it to configure the bridges whenever possible. The create and deletion of bridges and their interfaces is achieved via `ioctl`.

Index

Constants

View Source
const (
	BRCTL_SYS_NET    = "/sys/class/net"
	BRCTL_SYS_SUFFIX = 0x0a
)
View Source
const (
	BRCTL_ADD_BRIDGE          = 2
	BRCTL_DEL_BRIDGE          = 3
	BRCTL_ADD_I               = 4
	BRCTL_DEL_I               = 5
	BRCTL_SET_AEGING_TIME     = 11
	BRCTL_SET_BRIDGE_PRIORITY = 15
	BRCTL_SET_PORT_PRIORITY   = 16
	BRCTL_SET_PATH_COST       = 17
)
View Source
const (
	BRCTL_ROOT_ID                  = "root_id"
	BRCTL_ROOT_PATH_COST           = "root_path_cost"
	BRCTL_AGEING_TIME              = "ageing_time"
	BRCTL_STP_STATE                = "stp_state"
	BRCTL_BRIDGE_PRIO              = "priority"
	BRCTL_FORWARD_DELAY            = "forward_delay"
	BRCTL_HELLO_TIME               = "hello_time"
	BRCTL_HELLO_TIMER              = "hello_timer"
	BRCTL_TCN_TIMER                = "tcn_timer"
	BRCTL_TOPOLOGY_CHANGE          = "topology_change"
	BRCTL_TOPOLOGY_CHANGE_DETECTED = "topology_change_detected"
	BRCTL_TOPOLOGY_CHANGE_TIMER    = "topology_change_timer"
	BRCTL_GC_TIMER                 = "gc_timer"
	BRCTL_ROOT_PORT                = "root_port"
	BRCTL_TRILL_ENABLED            = "trill_state"
	BRCTL_MAX_AGE                  = "max_age"
	BRCTL_PATH_COST                = "path_cost"
	BRCTL_PRIORITY                 = "priority"
	BRCTL_HAIRPIN                  = "hairpin_mode"
	BRCTL_BRFORWARD                = "brforward"
	BRCTL_BRIDGE_ID                = "bridge_id"
	BRCTL_BRIDGE_DIR               = "bridge"
	BRCTL_BRIDGE_INTERFACE_DIR     = "brif"
	BRCTL_PORT_ID                  = "port_id"
	BRCTL_PORT_NO                  = "port_no"
	BRCTL_DESIGNATED_ROOT          = "designated_root"
	BRCTL_DESIGNATED_COST          = "designated_cost"
	BRCTL_DESIGNATED_BRIDGE        = "designated_bridge"
	BRCTL_DESIGNATED_PORT          = "designated_port"
	BRCTL_PORT_ROLE                = "port_role"
	BRCTL_PORT_STATE               = "state"
	BRCTL_PORT_FLAGS               = "port_flags"
	BRCTL_MSG_AGE_TIMER            = "message_age_timer"
	BRCTL_FORWARD_DELAY_TIMER      = "forward_delay_timer"
	BRCTL_HOLD_TIMER               = "hold_timer"
)
View Source
const ShowBridgeFmt = "%-15s %23s %15v %20v\n"

Variables

View Source
var ErrBridgeNotExist = errors.New("bridge does not exist")
View Source
var ErrPortNotExist = errors.New("port does not exist")

Functions

func Addbr

func Addbr(name string) error

Addbr adds a bridge with the provided name.

func Addif

func Addif(bridge string, iface string) error

Addif adds an interface to bridge.

func Delbr

func Delbr(name string) error

Delbr deletes a bridge with the provided name.

func Delif

func Delif(bridge string, iface string) error

Delif deletes an interface from bridge.

func Hairpin

func Hairpin(bridge string, port string, hairpinmode string) error

Hairpin sets the hairpin mode of the <port> attached to <bridge>

func SetAgeingTime

func SetAgeingTime(name string, time string) error

SetAgeingTime sets the ethernet (MAC) address ageing time, in seconds. After <time> seconds of not having seen a frame coming from a certain address, the bridge will time out (delete) that address from the Forwarding DataBase (fdb).

func SetBridgePrio

func SetBridgePrio(bridge string, bridgePriority string) error

SetBridgePrio sets the port <port>'s priority to <priority>. The priority value is an unsigned 8-bit quantity (a number between 0 and 255), and has no dimension. This metric is used in the designated port and root port selection algorithms.

func SetForwardDelay

func SetForwardDelay(bridge string, time string) error

SetForwardDelay sets the bridge's 'bridge forward delay' to <time> seconds.

func SetHello

func SetHello(bridge string, time string) error

SetHello sets the bridge's 'bridge hello time' to <time> seconds.

func SetMaxAge

func SetMaxAge(bridge string, time string) error

SetMaxAge sets the bridge's 'maximum message age' to <time> seconds.

func SetPathCost

func SetPathCost(bridge string, port string, cost string) error

Setpathcost sets the port cost of the port <port> to <cost>. This is a dimensionless metric.

func SetPortPrio

func SetPortPrio(bridge string, port string, prio string) error

SetPortPrio sets the port <port>'s priority to <priority>. The priority value is an unsigned 8-bit quantity (a number between 0 and 255), and has no dimension. This metric is used in the designated port and root port selection algorithms.

func SetSTP

func SetSTP(bridge string, state string) error

SetSTP set the STP state of the bridge to on or off Enable using "on" or "yes", disable by providing anything else The manpage states: > If <state> is "on" or "yes" the STP will be turned on, otherwise it will be turned off So this is actually the described behavior, not checking for "off" and "no"

func Show

func Show(out io.Writer, names ...string) error

Show performs the brctl show command. If no names are provided, it will show all bridges. If names are provided, it will show the specified bridges.

func ShowMACs

func ShowMACs(bridge string, out io.Writer) error

ShowMACs shows a list of learned MAC addresses for this bridge. The following byte format applies according to the kernel source [1] 0-5: MAC address 6: port number 7: is_local 8-11: ageing timer 12-15: unused in this context

[1] https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_bridge.h#L93

func ShowStp

func ShowStp(out io.Writer, bridge string) error

Types

type Info

type Info struct {
	Name                   string
	RootID                 string
	BridgeID               string
	RootPathCost           int
	MaxAge                 unix.Timeval
	HelloTime              unix.Timeval
	ForwardDelay           unix.Timeval
	BridgeMaxAge           unix.Timeval
	BridgeHelloTime        unix.Timeval
	BridgeForwardDelay     unix.Timeval
	RootPort               uint16
	StpEnabled             bool
	TopologyChange         bool
	TopologyChangeDetected bool
	AgingTime              unix.Timeval
	HelloTimer             unix.Timeval
	TCNTimer               unix.Timeval
	TopologyChangeTimer    unix.Timeval
	GCTimer                unix.Timeval
	Interfaces             []PortInfo
}

Info contains details about a bridge device and its ports. This information is not exhaustive, only the most important fields are included

func NewInfo

func NewInfo(name string) (Info, error)

NewInfo returns a new Info struct populated with the details of the bridge device with the given name and its ports. Information is read from sysfs.

type PortInfo

type PortInfo struct {
	Name              string
	PortID            string
	PortNumber        int
	State             int
	PathCost          int
	DesignatedRoot    string
	DesignatedCost    int
	DesignatedBridge  string
	DesignatedPort    string
	MessageAgeTimer   unix.Timeval
	ForwardDelayTimer unix.Timeval
	HoldTimer         unix.Timeval
	HairpinMode       bool
}

func NewPortInfo

func NewPortInfo(bridge, port string) (PortInfo, error)

NewPortInfo returns a new PortInfo struct populated with the details of the port with the given name on the bridge device with the given name. Information is read from sysfs.

Jump to

Keyboard shortcuts

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