From: Ido Schimmel <idosch@nvidia.com>
To: Ujjal Roy <royujjal@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Nikolay Aleksandrov <razor@blackwall.org>,
David Ahern <dsahern@kernel.org>, Shuah Khan <shuah@kernel.org>,
Andy Roulin <aroulin@nvidia.com>, Yong Wang <yongwang@nvidia.com>,
Petr Machata <petrm@nvidia.com>, Ujjal Roy <ujjal@alumnux.com>,
bridge@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v3 1/5] ipv4: igmp: get rid of IGMPV3_{QQIC,MRC} and simplify calculation
Date: Tue, 7 Apr 2026 16:44:11 +0300 [thread overview]
Message-ID: <20260407134411.GA849209@shredder> (raw)
In-Reply-To: <20260403150050.1235-2-royujjal@gmail.com>
On Fri, Apr 03, 2026 at 03:00:46PM +0000, Ujjal Roy wrote:
> Get rid of the IGMPV3_MRC macro and use the igmpv3_mrt() API to
> calculate the Max Resp Time from the Maximum Response Code.
>
> Similarly, for IGMPV3_QQIC, use the igmpv3_qqi() API to calculate
> the Querier's Query Interval from the QQIC field.
>
> Signed-off-by: Ujjal Roy <royujjal@gmail.com>
Looks fine, but see a few nits below
> ---
> include/linux/igmp.h | 84 +++++++++++++++++++++++++++++++++++----
> net/bridge/br_multicast.c | 2 +-
> net/ipv4/igmp.c | 6 +--
> 3 files changed, 80 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/igmp.h b/include/linux/igmp.h
> index 073b30a9b850..0624410e75c6 100644
> --- a/include/linux/igmp.h
> +++ b/include/linux/igmp.h
> @@ -92,15 +92,83 @@ struct ip_mc_list {
> struct rcu_head rcu;
> };
>
> +/* RFC3376, relevant sections:
> + * - 4.1.1. Maximum Response Code
> + * - 4.1.7. QQIC (Querier's Query Interval Code)
> + *
> + * For both MRC and QQIC, values >= 128 use the same floating-point
> + * encoding as follows:
> + *
> + * 0 1 2 3 4 5 6 7
> + * +-+-+-+-+-+-+-+-+
> + * |1| exp | mant |
> + * +-+-+-+-+-+-+-+-+
> + */
> +#define IGMPV3_FP_EXP(value) (((value) >> 4) & 0x07)
> +#define IGMPV3_FP_MAN(value) ((value) & 0x0f)
> +
> +/* IGMPV3 floating-point exponential field threshold */
> +#define IGMPV3_EXP_MIN_THRESHOLD 128
> +
> /* V3 exponential field decoding */
> -#define IGMPV3_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
> -#define IGMPV3_EXP(thresh, nbmant, nbexp, value) \
> - ((value) < (thresh) ? (value) : \
> - ((IGMPV3_MASK(value, nbmant) | (1<<(nbmant))) << \
> - (IGMPV3_MASK((value) >> (nbmant), nbexp) + (nbexp))))
> -
> -#define IGMPV3_QQIC(value) IGMPV3_EXP(0x80, 4, 3, value)
> -#define IGMPV3_MRC(value) IGMPV3_EXP(0x80, 4, 3, value)
> +
> +/* IGMPv3 QQIC/MRC 8-bit exponential field decode.
> + *
> + * RFC3376, 4.1.1 & 4.1.7. defines the decoding formula:
> + * 0 1 2 3 4 5 6 7
> + * +-+-+-+-+-+-+-+-+
> + * |1| exp | mant |
> + * +-+-+-+-+-+-+-+-+
> + * Max Resp Time = (mant | 0x10) << (exp + 3)
> + * QQI = (mant | 0x10) << (exp + 3)
> + */
> +static inline unsigned long igmpv3_exp_field_decode(const u8 code)
> +{
> + /* RFC3376, relevant sections:
> + * - 4.1.1. Maximum Response Code
> + * - 4.1.7. QQIC (Querier's Query Interval Code)
> + */
I find it weird to have a comment at the beginning of the function when
there's already a comment above the function. Let's remove this comment
since this information is already present in the MRC/QQIC functions
below.
> + if (code < IGMPV3_EXP_MIN_THRESHOLD) {
> + return code;
> + } else {
> + unsigned long mc_man, mc_exp;
> +
> + mc_exp = IGMPV3_FP_EXP(code);
> + mc_man = IGMPV3_FP_MAN(code);
> +
> + return (mc_man | 0x10) << (mc_exp + 3);
> + }
> +}
> +
> +/* Calculate Max Resp Time from Maximum Response Code
> + *
> + * After decode, MRC represents the Maximum Response Time (MRT) in units
> + * of 0.1 seconds (100 ms).
> + */
> +static inline unsigned long igmpv3_mrt(const struct igmpv3_query *ih3)
> +{
> + /* RFC3376, relevant sections:
> + * - 4.1.1. Maximum Response Code
> + * - 8.3. Query Response Interval
> + */
Please move this to the comment above the function
> + return igmpv3_exp_field_decode(ih3->code);
> +}
> +
> +/* Calculate Querier's Query Interval from Querier's Query Interval Code
> + *
> + * After decode, QQIC represents the Querier's Query Interval in units
> + * of seconds.
> + */
> +static inline unsigned long igmpv3_qqi(const struct igmpv3_query *ih3)
> +{
> + /* RFC3376, relevant sections:
> + * - 4.1.7. QQIC (Querier's Query Interval Code)
> + * - 8.2. Query Interval
> + * - 8.12. Older Version Querier Present Timeout
> + * (the [Query Interval] in the last Query received)
> + */
Likewise
> + return igmpv3_exp_field_decode(ih3->qqic);
> +}
>
> static inline int ip_mc_may_pull(struct sk_buff *skb, unsigned int len)
> {
> diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
> index 881d866d687a..9fec76e887bc 100644
> --- a/net/bridge/br_multicast.c
> +++ b/net/bridge/br_multicast.c
> @@ -3518,7 +3518,7 @@ static void br_ip4_multicast_query(struct net_bridge_mcast *brmctx,
> goto out;
>
> max_delay = ih3->code ?
> - IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
> + igmpv3_mrt(ih3) * (HZ / IGMP_TIMER_SCALE) : 1;
> } else {
> goto out;
> }
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index a674fb44ec25..d7eff36d98c3 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
> @@ -991,7 +991,7 @@ static bool igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,
> * different encoding. We use the v3 encoding as more likely
> * to be intended in a v3 query.
> */
> - max_delay = IGMPV3_MRC(ih3->code)*(HZ/IGMP_TIMER_SCALE);
> + max_delay = igmpv3_mrt(ih3) * (HZ / IGMP_TIMER_SCALE);
> if (!max_delay)
> max_delay = 1; /* can't mod w/ 0 */
> } else { /* v3 */
> @@ -1006,7 +1006,7 @@ static bool igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,
> ih3 = igmpv3_query_hdr(skb);
> }
>
> - max_delay = IGMPV3_MRC(ih3->code)*(HZ/IGMP_TIMER_SCALE);
> + max_delay = igmpv3_mrt(ih3) * (HZ / IGMP_TIMER_SCALE);
> if (!max_delay)
> max_delay = 1; /* can't mod w/ 0 */
> WRITE_ONCE(in_dev->mr_maxdelay, max_delay);
> @@ -1016,7 +1016,7 @@ static bool igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb,
> * configured value.
> */
> in_dev->mr_qrv = ih3->qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv);
> - in_dev->mr_qi = IGMPV3_QQIC(ih3->qqic)*HZ ?: IGMP_QUERY_INTERVAL;
> + in_dev->mr_qi = igmpv3_qqi(ih3) * HZ ? : IGMP_QUERY_INTERVAL;
>
> /* RFC3376, 8.3. Query Response Interval:
> * The number of seconds represented by the [Query Response
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-04-07 13:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 15:00 [PATCH net-next v3 0/5] net: bridge: mcast: support exponential field encoding Ujjal Roy
2026-04-03 15:00 ` [PATCH net-next v3 1/5] ipv4: igmp: get rid of IGMPV3_{QQIC,MRC} and simplify calculation Ujjal Roy
2026-04-07 13:44 ` Ido Schimmel [this message]
2026-04-03 15:00 ` [PATCH net-next v3 2/5] ipv6: mld: rename mldv2_mrc() and add mldv2_qqi() Ujjal Roy
2026-04-07 13:44 ` Ido Schimmel
2026-04-03 15:00 ` [PATCH net-next v3 3/5] ipv4: igmp: encode multicast exponential fields Ujjal Roy
2026-04-07 13:44 ` Ido Schimmel
2026-04-03 15:00 ` [PATCH net-next v3 4/5] ipv6: mld: " Ujjal Roy
2026-04-07 13:45 ` Ido Schimmel
2026-04-07 14:09 ` Nikolay Aleksandrov
2026-04-03 15:00 ` [PATCH net-next v3 5/5] selftests: net: bridge: add tests for MRC and QQIC validation Ujjal Roy
2026-04-07 1:25 ` Jakub Kicinski
2026-04-07 6:53 ` Ujjal Roy
2026-04-07 13:45 ` Ido Schimmel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260407134411.GA849209@shredder \
--to=idosch@nvidia.com \
--cc=aroulin@nvidia.com \
--cc=bridge@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=razor@blackwall.org \
--cc=royujjal@gmail.com \
--cc=shuah@kernel.org \
--cc=ujjal@alumnux.com \
--cc=yongwang@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox