Files
drivers/netlink/bridge.go
T
Scott Feldman 1fd8a768ae netlink: add L2 bridge/bond/vlan intermediate drivers
This adds three new L2 (intermediate) drivers for bridge/bond/vlan.
Theses drivers are incomplete but illustrate how to stack L2 drivers.
Here are some examples of how these driver would stack with the cy243439
driver:

  Bridge: bridge two cyw43 devices together, connecting the two LANs:

	cyw43_0 := cyw43439.NewDevice(...)
	cyw43_1 := cyw43439.NewDevice(...)

	bridge := NewBridge([]netlink.Netlinker{cyw43_0, cyw43_1})

	stack := tcpip.NewStack(bridge)
	netdev.UseNetdev(stack)

  Bond: bond two cyw43 devices together, creating one logical device.
  The first physical device is primary, the second is backup (fail-over)
  device:

	cyw43_0 := cyw43439.NewDevice(...)  // primary
	cyw43_1 := cyw43439.NewDevice(...)  // secondary (backup)

	bond := NewBond([]netlink.Netlinker{cyw43_0, cyw43_1})

	stack := tcpip.NewStack(bond)
	netdev.UseNetdev(stack)

   Vlan: add tagged VLAN ID=100 to cyw43:

	cyw43 := cyw43439.NewDevice(...)

	vlan100 := NewVlan(100, cyw43)

	stack := tcpip.NewStack(vlan100)
	netdev.UseNetdev(stack)
2023-12-06 20:09:39 +01:00

40 lines
712 B
Go

package netlink
import (
"net"
)
// Bridge connects links into an Ethernet (L2) broadcast domain
type Bridge struct {
ip net.IP
links []Netlinker
recvEth func([]byte) error
}
func NewBridge(links []Netlinker) *Bridge {
return &Bridge{links: links}
}
func (b *Bridge) NetConnect(params *ConnectParams) error {
return nil
}
func (b *Bridge) NetDisconnect() {
}
func (b *Bridge) NetNotify(cb func(Event)) {
}
func (b *Bridge) GetHardwareAddr() (net.HardwareAddr, error) {
return net.HardwareAddr{}, nil
}
func (b *Bridge) SendEth(pkt []byte) error {
// L2 Forward ethernet pkt to zero of more []links
return nil
}
func (b *Bridge) RecvEthFunc(cb func(pkt []byte) error) {
b.recvEth = cb
}