igmp: only hand reports to the CPU while snooping is on

handle_rx() dispatched to igmp_packet_handler() on the destination
address alone, so an ordinary IGMPv3 report off the wire reached the
handler and could write a table entry whether or not anyone had asked
for snooping. The STP branch right above it is gated on stpEnabled;
this brings the IGMP branch in line.

Snooping state lived only in the per-port registers, and the receive
path cannot afford to read one per packet, so the flag shadows it:
igmp_enable() sets it, igmp_setup() clears it, and igmp_setup() runs
from both the boot path and "igmp off".

While here, igmp off becomes an explicit subcommand instead of the
fall-through, and an unrecognised igmp subcommand prints the usage
line rather than silently turning snooping off.

Six bytes of BANK1 and one of xdata, no internal RAM.
This commit is contained in:
d00f
2026-08-16 23:42:46 +02:00
committed by d00f
parent 5103d1c168
commit 56fa96c494
3 changed files with 8 additions and 2 deletions
+3 -1
View File
@@ -1529,10 +1529,12 @@ void cmd_parser(void) __banked
} else if (cmd_compare(0, "igmp")) {
if (cmd_compare(1, "on"))
igmp_enable();
else if (cmd_compare(1, "off"))
igmp_setup();
else if (cmd_compare(1, "show"))
igmp_show();
else
igmp_setup(); // Reverts to default with IP-MC being flooded
print_string("Error: igmp on|off|show\n");
} else if (cmd_compare(0, "hostname")) {
/* "hostname" alone reports the current name; "hostname <text>"
* sets it, sanitized to JSON-safe printable ASCII. A name with
+3
View File
@@ -16,6 +16,7 @@
#include "machine.h"
extern __code struct machine machine;
extern __xdata uint8_t igmpEnabled;
#include "uip.h"
@@ -85,6 +86,7 @@ void igmp_setup(void) __banked
{
uint8_t i;
print_string("igmp_setup called\n");
igmpEnabled = 0;
// For now, forward all unkown IP-MC pkts (2 bits per port. 00: flood via floodmask, 01: drop, 10: trap, 11: to rport)
REG_SET(RTL837X_IPV4_PORT_MC_LM_ACT, LOOKUP_MISS_FLOOD);
REG_SET(RTL837X_IPV6_PORT_MC_LM_ACT, LOOKUP_MISS_FLOOD);
@@ -130,6 +132,7 @@ void igmp_setup(void) __banked
void igmp_enable(void) __banked
{
print_string("igmp_enable called\n");
igmpEnabled = 1;
// Configure trapping of unhandled IGMP protocol packets to CPU
REG_SET(RTL837X_IGMP_TRAP_CFG, IGMP_CPU_PORT | IGMP_TRAP_PRIORITY);
+2 -1
View File
@@ -121,6 +121,7 @@ __xdata uint16_t management_vlan;
__xdata uint8_t tx_seq;
__xdata uint8_t stpEnabled;
__xdata uint8_t igmpEnabled;
__xdata char hostname[24]; /* device hostname, default set at boot, see rtl837x_common.h */
__code uint16_t bit_mask[16] = {
@@ -1152,7 +1153,7 @@ void handle_rx(void)
print_string("STP TX\n");
tcpip_output();
}
} else if (uip_buf[0] == 0x01 && uip_buf[1] == 0x00 && uip_buf[2] == 0x5e // IPv4-MC packet?
} else if (igmpEnabled && uip_buf[0] == 0x01 && uip_buf[1] == 0x00 && uip_buf[2] == 0x5e // IPv4-MC packet?
&& uip_buf[3] == 0x00 && uip_buf[4] == 0x00 && uip_buf[5] == 0x16) {
igmp_packet_handler();
if (uip_len) {