Re: [PATCH net-next v2 3/5] ipv4: igmp: encode multicast exponential fields
From: Ido Schimmel
Date: Wed Apr 01 2026 - 03:39:51 EST
On Mon, Mar 30, 2026 at 07:16:09PM +0000, Ujjal Roy wrote:
> In IGMP, QQIC and MRC fields are not currently encoded
s/currently/correctly/ ?
> when generating query packets. Since the receiver of the
> query interprets these fields using the IGMPv3 floating-
> point decoding logic, any raw interval value that exceeds
> the linear threshold is currently parsed incorrectly as
> an exponential value, leading to an incorrect interval
> calculation.
>
> Encode and assign the corresponding protocol fields during
> query generation. Introduce the logic to dynamically
> calculate the exponent and mantissa using bit-scan (fls).
> This ensures QQIC and MRC fields (8-bit) are properly
> encoded when transmitting query packets with intervals
> that exceed their respective linear threshold value of
> 128 (for QQI/MRT).
>
> RFC 3376: if QQIC/MRC >= 128, the QQIC/MRC field represents
> a floating-point value as follows:
> 0 1 2 3 4 5 6 7
> +-+-+-+-+-+-+-+-+
> |1| exp | mant |
> +-+-+-+-+-+-+-+-+
>
> Signed-off-by: Ujjal Roy <royujjal@xxxxxxxxx>
[...]
> +static inline u8 igmpv3_exp_field_encode(unsigned long value)
> +{
> + u8 mc_exp, mc_man;
> +
> + /* RFC3376: QQIC/MRC < 128 is literal */
> + if (value < IGMPV3_EXP_MIN_THRESHOLD)
> + return (u8)value;
return value;
> +
> + /* Saturate at max representable (mant = 0xF, exp = 7) -> 31744 */
> + if (value >= IGMPV3_EXP_MAX_THRESHOLD)
> + return 0xFF;
> +
> + mc_exp = (u8)(fls(value) - 8);
> + mc_man = (u8)((value >> (mc_exp + 3)) & 0x0F);
Drop the casts?
Same in other places throughout the patchset.
> +
> + return 0x80 | (mc_exp << 4) | mc_man;
> +}