Add dhcpd VLAN parameter to restrict dhcpd to given VLAN

This commit is contained in:
logicog
2026-03-09 22:11:29 +01:00
parent aa12adc098
commit 855d587243
6 changed files with 26 additions and 4 deletions
+5
View File
@@ -44,6 +44,7 @@ extern __xdata struct dhcp_state dhcp_state;
__xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
__xdata uint16_t vlan_ptr;
extern __xdata uint16_t management_vlan;
extern __xdata uint16_t dhcpd_vlan;
__xdata uint8_t gpio_last_value[8] = { 0 };
// Temporatly for str to hex convertion value.
@@ -1001,6 +1002,10 @@ void cmd_parser(void) __banked
}
} else if (cmd_compare(0, "dhcpd")) {
if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) {
if (cmd_words_b[2] > 0)
atoi_short(&dhcpd_vlan, cmd_words_b[2]);
else
dhcpd_vlan = 0;
dhcpd_start();
} else {
print_string("DHCP Server disabled\n");
+5
View File
@@ -89,6 +89,7 @@ struct dhcp_pkt {
__xdata uint32_t long_value;
__xdata struct dhcpd_cstate cstates[DHCPD_MAX_CLIENTS];
__xdata uint8_t client_idx;
__xdata uint16_t dhcpd_vlan;
void dhcp_print_ip(uint8_t *a)
{
@@ -558,6 +559,10 @@ void dhcpd_start(void) __banked
print_string("dhcpd_start failed to set up socket\n");
return;
}
if (!dhcpd_vlan)
print_string("dhcpd: enabling for all VLANs\n");
else
print_string("dhcpd: enabling for VLAN "); print_short(dhcpd_vlan); write_char('\n');
dhcp_state.state = DHCP_SERVER;
dhcp_state.server[1] = uip_hostaddr[0] >> 8; dhcp_state.server[0] = uip_hostaddr[0] & 0xff;
+2 -1
View File
@@ -63,7 +63,8 @@
When updating the above settings, remember to point your browser to the new IP afterwards:<br/>
<input style="width:40%;" class="action" id="ip_sub" onclick="ipSub();" type="button" value="Update Settings"><br/>
<br/><br/>
<label class="dhcpdon">Enable DHCP Server: <input id="dhcpd" type="checkbox"></label><br/>
<label class="dhcpdon">Enable DHCP Server: <input id="dhcpd" type="checkbox"></label><br/><br/>
<label class="dhcpdvlan">Limit DHCP Server to VLAN (0: serve all VLANs): <input type="number" min="0" max="2047" value="0" id="dhcpd_vid" name="dhcpd_vid"></label><br/>
<input style="width:40%;" class="action" id="dhcpd_sub" onclick="dhcpdSub();" type="button" value="Change DHCPD State"><br/><br/><br/>
Save all current settings to Flash:<br/>
<input style="width:40%;" class="action" id="flash_sub" onclick="flashSave();" type="button" value="Save Settings to Flash">
+6 -1
View File
@@ -42,9 +42,14 @@ async function ipSub() {
}
async function dhcpdSub() {
var dhcpd_cmd = "dhcpd off";
if (document.getElementById('dhcpd').checked)
if (document.getElementById('dhcpd').checked) {
dhcpd_cmd = "dhcpd on";
var v=document.getElementById('dhcpd_vid').value
if (v && v!= 0)
dhcpd_cmd = dhcpd_cmd + " " + v;
}
try {
console.log("Sending: ", dhcpd_cmd);
const response = await fetch('/cmd', {
method: 'POST',
body: dhcpd_cmd
+2
View File
@@ -97,6 +97,8 @@ struct flash_region_t {
extern __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE+2];
extern __xdata struct uip_eth_addr uip_ethaddr;
extern __xdata uint16_t rx_packet_vlan;
extern __xdata uint16_t dhcpd_vlan;
// Headers for calls in the common code area (HOME/BANK0)
void print_string(__code char *p);
+6 -2
View File
@@ -924,7 +924,7 @@ uip_process(u8_t flag) __banked
UIP_STAT(++uip_stat.ip.drop);
goto drop;
}
}
}
#else /* UIP_CONF_IPV6 */
/* For IPv6, packet reception is a little trickier as we need to
make sure that we listen to certain multicast addresses (all
@@ -938,7 +938,11 @@ uip_process(u8_t flag) __banked
}
#endif /* UIP_CONF_IPV6 */
}
// If we serve only the designated DHCPD-VLAN, we drop the packet if not in that VLAN
if(BUF->proto == UIP_PROTO_UDP && dhcpd_vlan && UDPBUF->destport == HTONS(DHCP_SERVER_PORT) && dhcpd_vlan != rx_packet_vlan) {
UIP_STAT(++uip_stat.ip.drop);
goto drop;
}
#if !UIP_CONF_IPV6
// if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
// checksum. */