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
- Variables
- func Addbr(name string) error
- func Addif(bridge string, iface string) error
- func Delbr(name string) error
- func Delif(bridge string, iface string) error
- func Hairpin(bridge string, port string, hairpinmode string) error
- func SetAgeingTime(name string, time string) error
- func SetBridgePrio(bridge string, bridgePriority string) error
- func SetForwardDelay(bridge string, time string) error
- func SetHello(bridge string, time string) error
- func SetMaxAge(bridge string, time string) error
- func SetPathCost(bridge string, port string, cost string) error
- func SetPortPrio(bridge string, port string, prio string) error
- func SetSTP(bridge string, state string) error
- func Show(out io.Writer, names ...string) error
- func ShowMACs(bridge string, out io.Writer) error
- func ShowStp(out io.Writer, bridge string) error
- type Info
- type PortInfo
Constants ¶
const ( BRCTL_SYS_NET = "/sys/class/net" BRCTL_SYS_SUFFIX = 0x0a )
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 )
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" )
const ShowBridgeFmt = "%-15s %23s %15v %20v\n"
Variables ¶
var ErrBridgeNotExist = errors.New("bridge does not exist")
var ErrPortNotExist = errors.New("port does not exist")
Functions ¶
func SetAgeingTime ¶
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 ¶
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 ¶
SetForwardDelay sets the bridge's 'bridge forward delay' to <time> seconds.
func SetPathCost ¶
Setpathcost sets the port cost of the port <port> to <cost>. This is a dimensionless metric.
func SetPortPrio ¶
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 ¶
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 ¶
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 ¶
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
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
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 ¶
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.