initial: ZeroTier-like P2P mesh VPN server with multi-tenant Web UI
This commit is contained in:
38
internal/vl2/network.go
Normal file
38
internal/vl2/network.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package vl2
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"zeromesh/internal/identity"
|
||||
)
|
||||
|
||||
type NetworkConfig struct {
|
||||
ID uint32
|
||||
Name string
|
||||
IPRange string
|
||||
IP6Range string
|
||||
MTU int
|
||||
Multicast bool
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
Config NetworkConfig
|
||||
Switch *Switch
|
||||
ARP *ARPProxy
|
||||
LocalMAC [6]byte
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewNetwork(config NetworkConfig, nodeAddr identity.Address, sender PeerSender, log *slog.Logger) *Network {
|
||||
netLog := log.With("network", config.ID, "name", config.Name)
|
||||
mac := GenerateMAC(config.ID, nodeAddr)
|
||||
var macArr [6]byte
|
||||
copy(macArr[:], mac)
|
||||
return &Network{
|
||||
Config: config,
|
||||
Switch: NewSwitch(config.ID, sender, netLog),
|
||||
ARP: NewARPProxy(netLog),
|
||||
LocalMAC: macArr,
|
||||
log: netLog,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user