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)
This commit is contained in:
Scott Feldman
2023-06-09 14:50:30 -07:00
committed by Ron Evans
parent 8238f96319
commit 1fd8a768ae
4 changed files with 96 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
package netlink
// Bond aggregates links as one
type Bond struct {
*Bridge
}
func NewBond(links []Netlinker) *Bond {
return &Bond{Bridge: NewBridge(links)}
}
func (b *Bond) SendEth(pkt []byte) error {
// Send Ethernet pkt to active link(s)
return nil
}
+39
View File
@@ -0,0 +1,39 @@
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
}
+1 -1
View File
@@ -99,5 +99,5 @@ type Netlinker interface {
// RecvEth callback function for receiving Ethernet pkt
// TODO describe content of pkt
RecvEthFunc(func(pkt []byte) error)
RecvEthFunc(cb func(pkt []byte) error)
}
+41
View File
@@ -0,0 +1,41 @@
package netlink
import (
"net"
)
// Vlan is a virtual LAN
type Vlan struct {
ip net.IP
// Vlan ID
id uint16
link Netlinker
recvEth func([]byte) error
}
func NewVlan(id uint16, link Netlinker) *Vlan {
return &Vlan{id: id, link: link}
}
func (v *Vlan) NetConnect(params *ConnectParams) error {
return nil
}
func (v *Vlan) NetDisconnect() {
}
func (v *Vlan) NetNotify(cb func(Event)) {
}
func (v *Vlan) GetHardwareAddr() (net.HardwareAddr, error) {
return net.HardwareAddr{}, nil
}
func (v *Vlan) SendEth(pkt []byte) error {
// Prepend VLAN hdr to pkt and send on link
return nil
}
func (v *Vlan) RecvEthFunc(cb func(pkt []byte) error) {
v.recvEth = cb
}