mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-06 07:53:41 +00:00
1fd8a768ae
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)
42 lines
681 B
Go
42 lines
681 B
Go
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
|
|
}
|