Skip to content

Commit a0f00f6

Browse files
committed
feat(stack): add AcceptBroadcast4 config for AP/DHCP server mode
Wire xnet.StackConfig.AcceptIPv4Broadcast through espradio.StackConfig so AP-mode stacks accept IPv4 broadcast destinations. Required for DHCP server to receive client Discovers/Requests sent to 255.255.255.255. Enable it in netlink/ap.go and examples/ap. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent da6521c commit a0f00f6

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

espstack.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type StackConfig struct {
3636
MaxTCPPorts int
3737
MaxUDPPorts int
3838
PassivePeers int
39+
// AcceptBroadcast4 enables reception of IPv4 broadcast packets.
40+
// Must be true when running a DHCP server (AP mode).
41+
AcceptBroadcast4 bool
3942
}
4043

4144
// DHCPConfig configures DHCP address acquisition.
@@ -57,15 +60,16 @@ func NewStack(dev *NetDev, cfg StackConfig) (*Stack, error) {
5760
stack := &Stack{dev: dev}
5861
const MTU = MaxFrameSize - ethernet.MaxOverheadSize + 4 // CRC not included:+4
5962
xcfg := xnet.StackConfig{
60-
DNSServer: cfg.DNSServer,
61-
NTPServer: cfg.NTPServer,
62-
Hostname: cfg.Hostname,
63-
MaxActiveTCPPorts: uint16(cfg.MaxTCPPorts),
64-
MaxActiveUDPPorts: uint16(cfg.MaxUDPPorts),
65-
RandSeed: time.Now().UnixNano() ^ cfg.RandSeed,
66-
HardwareAddress: mac,
67-
MTU: MTU,
68-
PassivePeers: cfg.PassivePeers,
63+
DNSServer: cfg.DNSServer,
64+
NTPServer: cfg.NTPServer,
65+
Hostname: cfg.Hostname,
66+
MaxActiveTCPPorts: uint16(cfg.MaxTCPPorts),
67+
MaxActiveUDPPorts: uint16(cfg.MaxUDPPorts),
68+
RandSeed: time.Now().UnixNano() ^ cfg.RandSeed,
69+
HardwareAddress: mac,
70+
MTU: MTU,
71+
PassivePeers: cfg.PassivePeers,
72+
AcceptIPv4Broadcast: cfg.AcceptBroadcast4,
6973
}
7074
if cfg.StaticAddress.IsValid() && cfg.StaticAddress.Is4() {
7175
xcfg.StaticAddress4 = cfg.StaticAddress.As4()

examples/ap/main-ap.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ func main() {
5050

5151
println("ap: creating lneto stack...")
5252
stack, err := espradio.NewStack(nd, espradio.StackConfig{
53-
Hostname: ssid,
54-
StaticAddress: addr,
55-
MaxUDPPorts: 2,
53+
Hostname: ssid,
54+
StaticAddress: addr,
55+
MaxUDPPorts: 2,
56+
AcceptBroadcast4: true,
5657
})
5758
if err != nil {
5859
failure("ap: stack err: " + err.Error())

netlink/ap.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ func (n *Esplink) NetConnectAP(params APConnectParams) error {
102102
udpPorts = 1 // reserve one slot for the DHCP server
103103
}
104104
espstack, err := espradio.NewStack(nd, espradio.StackConfig{
105-
Hostname: params.Hostname,
106-
StaticAddress: params.StaticAddr,
107-
MaxUDPPorts: udpPorts,
108-
MaxTCPPorts: params.MaxTCPPorts,
109-
PassivePeers: params.PassivePeers,
105+
Hostname: params.Hostname,
106+
StaticAddress: params.StaticAddr,
107+
MaxUDPPorts: udpPorts,
108+
MaxTCPPorts: params.MaxTCPPorts,
109+
PassivePeers: params.PassivePeers,
110+
AcceptBroadcast4: true,
110111
})
111112
if err != nil {
112113
if debug {

0 commit comments

Comments
 (0)