mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add dhcpd VLAN parameter to restrict dhcpd to given VLAN
This commit is contained in:
@@ -44,6 +44,7 @@ extern __xdata struct dhcp_state dhcp_state;
|
|||||||
__xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
__xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
||||||
__xdata uint16_t vlan_ptr;
|
__xdata uint16_t vlan_ptr;
|
||||||
extern __xdata uint16_t management_vlan;
|
extern __xdata uint16_t management_vlan;
|
||||||
|
extern __xdata uint16_t dhcpd_vlan;
|
||||||
__xdata uint8_t gpio_last_value[8] = { 0 };
|
__xdata uint8_t gpio_last_value[8] = { 0 };
|
||||||
|
|
||||||
// Temporatly for str to hex convertion value.
|
// Temporatly for str to hex convertion value.
|
||||||
@@ -1001,6 +1002,10 @@ void cmd_parser(void) __banked
|
|||||||
}
|
}
|
||||||
} else if (cmd_compare(0, "dhcpd")) {
|
} else if (cmd_compare(0, "dhcpd")) {
|
||||||
if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) {
|
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();
|
dhcpd_start();
|
||||||
} else {
|
} else {
|
||||||
print_string("DHCP Server disabled\n");
|
print_string("DHCP Server disabled\n");
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ struct dhcp_pkt {
|
|||||||
__xdata uint32_t long_value;
|
__xdata uint32_t long_value;
|
||||||
__xdata struct dhcpd_cstate cstates[DHCPD_MAX_CLIENTS];
|
__xdata struct dhcpd_cstate cstates[DHCPD_MAX_CLIENTS];
|
||||||
__xdata uint8_t client_idx;
|
__xdata uint8_t client_idx;
|
||||||
|
__xdata uint16_t dhcpd_vlan;
|
||||||
|
|
||||||
void dhcp_print_ip(uint8_t *a)
|
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");
|
print_string("dhcpd_start failed to set up socket\n");
|
||||||
return;
|
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.state = DHCP_SERVER;
|
||||||
|
|
||||||
dhcp_state.server[1] = uip_hostaddr[0] >> 8; dhcp_state.server[0] = uip_hostaddr[0] & 0xff;
|
dhcp_state.server[1] = uip_hostaddr[0] >> 8; dhcp_state.server[0] = uip_hostaddr[0] & 0xff;
|
||||||
|
|||||||
+2
-1
@@ -63,7 +63,8 @@
|
|||||||
When updating the above settings, remember to point your browser to the new IP afterwards:<br/>
|
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/>
|
<input style="width:40%;" class="action" id="ip_sub" onclick="ipSub();" type="button" value="Update Settings"><br/>
|
||||||
<br/><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/>
|
<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/>
|
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">
|
<input style="width:40%;" class="action" id="flash_sub" onclick="flashSave();" type="button" value="Save Settings to Flash">
|
||||||
|
|||||||
+6
-1
@@ -42,9 +42,14 @@ async function ipSub() {
|
|||||||
}
|
}
|
||||||
async function dhcpdSub() {
|
async function dhcpdSub() {
|
||||||
var dhcpd_cmd = "dhcpd off";
|
var dhcpd_cmd = "dhcpd off";
|
||||||
if (document.getElementById('dhcpd').checked)
|
if (document.getElementById('dhcpd').checked) {
|
||||||
dhcpd_cmd = "dhcpd on";
|
dhcpd_cmd = "dhcpd on";
|
||||||
|
var v=document.getElementById('dhcpd_vid').value
|
||||||
|
if (v && v!= 0)
|
||||||
|
dhcpd_cmd = dhcpd_cmd + " " + v;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
console.log("Sending: ", dhcpd_cmd);
|
||||||
const response = await fetch('/cmd', {
|
const response = await fetch('/cmd', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: dhcpd_cmd
|
body: dhcpd_cmd
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ struct flash_region_t {
|
|||||||
|
|
||||||
extern __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE+2];
|
extern __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE+2];
|
||||||
extern __xdata struct uip_eth_addr uip_ethaddr;
|
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)
|
// Headers for calls in the common code area (HOME/BANK0)
|
||||||
void print_string(__code char *p);
|
void print_string(__code char *p);
|
||||||
|
|||||||
@@ -924,7 +924,7 @@ uip_process(u8_t flag) __banked
|
|||||||
UIP_STAT(++uip_stat.ip.drop);
|
UIP_STAT(++uip_stat.ip.drop);
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else /* UIP_CONF_IPV6 */
|
#else /* UIP_CONF_IPV6 */
|
||||||
/* For IPv6, packet reception is a little trickier as we need to
|
/* For IPv6, packet reception is a little trickier as we need to
|
||||||
make sure that we listen to certain multicast addresses (all
|
make sure that we listen to certain multicast addresses (all
|
||||||
@@ -938,7 +938,11 @@ uip_process(u8_t flag) __banked
|
|||||||
}
|
}
|
||||||
#endif /* UIP_CONF_IPV6 */
|
#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_CONF_IPV6
|
||||||
// if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
|
// if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
|
||||||
// checksum. */
|
// checksum. */
|
||||||
|
|||||||
Reference in New Issue
Block a user