Skip to content

IGMP - Timer bug in igmp_start_timer() #3498

Closed
@forkineye

Description

@forkineye

Issue

igmp_start_timer() sometimes assigns excessive times to group->timer, causing IGMP memberships to expire. The problem is related to the usage of r_rand() via the LWIP_RAND() macro in the following function: https://github.com/esp8266/Arduino/blob/master/tools/sdk/lwip/src/core/ipv4/igmp.c#L703. group->timer should never exceed 100. Debug output in the function produces the following:

os_printf("igmp_start_timer: %8X / %u / %u \n", &group->group_address, group->timer, max_time);
igmp_start_timer: 3FFF55B4 / 65515 / 100 
igmp_start_timer: 3FFF559C / 65 / 100 
igmp_start_timer: 3FFF5584 / 65493 / 100 
igmp_start_timer: 3FFF556C / 65503 / 100 
igmp_start_timer: 3FFF5554 / 43 / 100 
igmp_start_timer: 3FFF5054 / 65531 / 100 

Fix

Assigning the output of LWIP_RAND() to a uint32_t variable and using that in place for the modulus fixes the issue.

Also, using RANDOM_REG32 in place of r_rand() works as well:

#define LWIP_RAND() *((volatile uint32_t *)(0x3FF20E44))  // RANDOM_REG32

Not sure why its breaking as is, but the above two fixes work for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions