net: updates/cleanup/docs for net, netdev, and netlink

This commit is contained in:
Scott Feldman
2023-06-11 20:34:18 -07:00
committed by Ron Evans
parent 196d1dd58d
commit 3089bf8b1b
23 changed files with 232 additions and 869 deletions
+19
View File
@@ -0,0 +1,19 @@
### Table of Contents
- [Netlinker](#netlinker)
## Netlinker
TinyGo's network device driver model comprises two Go interfaces: Netdever and
Netlinker. This README covers Netlinker.
The Netlinker interface describes an L2 network interface. A netlink is a
concrete implementation of a Netlinker. See [Netdev](../netdev/) for
the L4/L3 network interface.
A netlink can:
- Connect/disconnect device to/from network
- Notify of network events (e.g. link UP/DOWN)
- Send and receive Ethernet packets
- Get/set device's hardware address (MAC address)
-15
View File
@@ -1,15 +0,0 @@
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
@@ -1,39 +0,0 @@
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
}
+6 -8
View File
@@ -13,6 +13,7 @@ var (
ErrConnectFailed = errors.New("Connect failed")
ErrConnectTimeout = errors.New("Connect timed out")
ErrMissingSSID = errors.New("Missing WiFi SSID")
ErrAuthFailure = errors.New("Wifi authentication failure")
ErrAuthTypeNoGood = errors.New("Wifi authorization type not supported")
ErrConnectModeNoGood = errors.New("Connect mode not supported")
ErrNotSupported = errors.New("Not supported")
@@ -50,14 +51,19 @@ const (
const DefaultConnectTimeout = 10 * time.Second
type ConnectParams struct {
// Connect mode
ConnectMode
// SSID of Wifi AP
Ssid string
// Passphrase of Wifi AP
Passphrase string
// Wifi authorization type
AuthType
// Wifi country code as two-char string. E.g. "XX" for world-wide,
// "US" for USA, etc.
Country string
@@ -92,12 +98,4 @@ type Netlinker interface {
// GetHardwareAddr returns device MAC address
GetHardwareAddr() (net.HardwareAddr, error)
// SendEth sends an Ethernet packet
// TODO describe content of pkt
SendEth(pkt []byte) error
// RecvEth callback function for receiving Ethernet pkt
// TODO describe content of pkt
RecvEthFunc(cb func(pkt []byte) error)
}
-1
View File
@@ -4,7 +4,6 @@ package probe
import (
"machine"
"time"
"tinygo.org/x/drivers/netdev"
"tinygo.org/x/drivers/netlink"
-41
View File
@@ -1,41 +0,0 @@
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
}