Improve parse_ingress()

This commit is contained in:
René van Dorst
2026-08-25 07:54:15 +02:00
parent 724fd1e061
commit 17642699d4
+15 -6
View File
@@ -283,6 +283,12 @@ __bit cmd_is_space(uint8_t idx) {
return cmd_buffer[idx] == ' '; return cmd_buffer[idx] == ' ';
} }
// check if the cmd_buffer[idx] is a space or null.
__bit cmd_is_space_or_null(uint8_t idx) {
uint8_t c = cmd_buffer[idx];
return c == ' ' || c == '\0';
}
// returns 0 when on parser error or invalid value or no space. // returns 0 when on parser error or invalid value or no space.
// return non-zero number of bytes consumed including the space. // return non-zero number of bytes consumed including the space.
// Stops at a space or NULL. // Stops at a space or NULL.
@@ -598,10 +604,13 @@ void parse_ingress(void)
if (cmd_words_len < 2) { if (cmd_words_len < 2) {
goto err; goto err;
} }
__xdata uint8_t log_port = 0; uint8_t log_port = 0;
__xdata vlan_ingress_mode_t mode = VLAN_INVALID; __xdata vlan_ingress_mode_t mode = VLAN_INVALID;
uint8_t idx = cmd_words_b[1];
if (vlan_ingress_mode_parse(cmd_buffer[cmd_words_b[1]], &mode)) { if (vlan_ingress_mode_parse(cmd_buffer[idx++], &mode)) {
if (!cmd_is_space_or_null(idx))
goto err;
// Setting mode for all ports at once // Setting mode for all ports at once
for (log_port = machine.min_port; log_port <= machine.max_port; log_port++) { for (log_port = machine.min_port; log_port <= machine.max_port; log_port++) {
if (!port_ingress_filter(log_port, mode)) { if (!port_ingress_filter(log_port, mode)) {
@@ -613,17 +622,17 @@ void parse_ingress(void)
} }
} else { } else {
for(uint8_t w = 1; w < cmd_words_len; w++) { for(uint8_t w = 1; w < cmd_words_len; w++) {
uint8_t idx = cmd_words_b[w]; idx = cmd_words_b[w];
char p = cmd_buffer[idx]; char p = cmd_buffer[idx];
uint8_t ret = cmd_parse_port_space(idx, false); uint8_t ret = cmd_parse_port(idx, false);
if (ret == 0) { if (ret != 1) {
print_string("Invalid physical port number\n"); print_string("Invalid physical port number\n");
continue; continue;
} }
log_port = atoi_results_u8; log_port = atoi_results_u8;
idx += ret; idx += ret;
if (!vlan_ingress_mode_parse(cmd_buffer[idx], &mode)) { if (!vlan_ingress_mode_parse(cmd_buffer[idx++], &mode) || !cmd_is_space_or_null(idx)) {
print_string("Invalid ingress mode for port "); write_char(p); print_string(" in ingress command\n"); print_string("Invalid ingress mode for port "); write_char(p); print_string(" in ingress command\n");
goto err; goto err;
} }