[PATCH 2/4] ipv6: mld: rename mldv2_mrc() and add mldv2_qqi()

Ujjal Roy posted 4 patches 1 week ago
There is a newer version of this series
[PATCH 2/4] ipv6: mld: rename mldv2_mrc() and add mldv2_qqi()
Posted by Ujjal Roy 1 week ago
Rename mldv2_mrc() to mldv2_mrd() as it used to calculate
the Maximum Response Delay from the Maximum Response Code.

Introduce a new API mldv2_qqi() to define the existing
calculation logic of QQI from QQIC. This also organizes
the existing mld_update_qi() API.

Added by e3f5b1704 ("net: ipv6: mld: get rid of MLDV2_MRC and simplify calculation").

Signed-off-by: Ujjal Roy <royujjal@gmail.com>
---
 include/net/mld.h         | 64 +++++++++++++++++++++++++++++++++------
 net/bridge/br_multicast.c |  2 +-
 net/ipv6/mcast.c          | 19 ++----------
 3 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/include/net/mld.h b/include/net/mld.h
index c07359808493..6373eb76efe5 100644
--- a/include/net/mld.h
+++ b/include/net/mld.h
@@ -89,29 +89,73 @@ struct mld2_query {
 #define MLDV2_QQIC_EXP(value)	(((value) >> 4) & 0x07)
 #define MLDV2_QQIC_MAN(value)	((value) & 0x0f)
 
-#define MLD_EXP_MIN_LIMIT	32768UL
-#define MLDV1_MRD_MAX_COMPAT	(MLD_EXP_MIN_LIMIT - 1)
+#define MLD_QQIC_MIN_THRESHOLD	128
+#define MLD_MRC_MIN_THRESHOLD	32768UL
+#define MLDV1_MRD_MAX_COMPAT	(MLD_MRC_MIN_THRESHOLD - 1)
 
 #define MLD_MAX_QUEUE		8
 #define MLD_MAX_SKBS		32
 
-static inline unsigned long mldv2_mrc(const struct mld2_query *mlh2)
-{
-	/* RFC3810, 5.1.3. Maximum Response Code */
-	unsigned long ret, mc_mrc = ntohs(mlh2->mld2q_mrc);
+/* V2 exponential field decoding */
 
-	if (mc_mrc < MLD_EXP_MIN_LIMIT) {
-		ret = mc_mrc;
+/* Calculate Maximum Response Delay from Maximum Response Code
+ *
+ * RFC3810, 5.1.3. defines the decoding formula:
+ *      0 1 2 3 4 5 6 7 8 9 A B C D E F
+ *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *     |1| exp |          mant         |
+ *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * Maximum Response Delay = (mant | 0x1000) << (exp+3)
+ */
+static inline unsigned long mldv2_mrd(const struct mld2_query *mlh2)
+{
+	/* RFC3810, relevant sections:
+	 *  - 5.1.3. Maximum Response Code
+	 *  - 9.3. Query Response Interval
+	 */
+	unsigned long mc_mrc = ntohs(mlh2->mld2q_mrc);
+
+	if (mc_mrc < MLD_MRC_MIN_THRESHOLD) {
+		return mc_mrc;
 	} else {
 		unsigned long mc_man, mc_exp;
 
 		mc_exp = MLDV2_MRC_EXP(mc_mrc);
 		mc_man = MLDV2_MRC_MAN(mc_mrc);
 
-		ret = (mc_man | 0x1000) << (mc_exp + 3);
+		return ((mc_man | 0x1000) << (mc_exp + 3));
 	}
+}
 
-	return ret;
+/* Calculate Querier's Query Interval from Querier's Query Interval Code
+ *
+ * RFC3810, 5.1.9. defines the decoding formula:
+ *      0 1 2 3 4 5 6 7
+ *     +-+-+-+-+-+-+-+-+
+ *     |1| exp | mant  |
+ *     +-+-+-+-+-+-+-+-+
+ * QQI = (mant | 0x10) << (exp + 3)
+ */
+static inline unsigned long mldv2_qqi(const struct mld2_query *mlh2)
+{
+	/* RFC3810, relevant sections:
+	 *  - 5.1.9. QQIC (Querier's Query Interval Code)
+	 *  - 9.2. Query Interval
+	 *  - 9.12. Older Version Querier Present Timeout
+	 *    (the [Query Interval] in the last Query received)
+	 */
+	unsigned long qqic = ntohs(mlh2->mld2q_qqic);
+
+	if (qqic < MLD_QQIC_MIN_THRESHOLD) {
+		return qqic;
+	} else {
+		unsigned long mc_man, mc_exp;
+
+		mc_exp = MLDV2_QQIC_EXP(qqic);
+		mc_man = MLDV2_QQIC_MAN(qqic);
+
+		return ((mc_man | 0x10) << (mc_exp + 3));
+	}
 }
 
 #endif
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 9fec76e887bc..1438c023db62 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -3606,7 +3606,7 @@ static int br_ip6_multicast_query(struct net_bridge_mcast *brmctx,
 		    mld2q->mld2q_suppress)
 			goto out;
 
-		max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL);
+		max_delay = max(msecs_to_jiffies(mldv2_mrd(mld2q)), 1UL);
 	}
 
 	is_general_query = group && ipv6_addr_any(group);
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 3330adcf26db..6ddc18ac59b9 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -1315,20 +1315,7 @@ static void mld_update_qi(struct inet6_dev *idev,
 	 *  - 9.12. Older Version Querier Present Timeout
 	 *    (the [Query Interval] in the last Query received)
 	 */
-	unsigned long mc_qqi;
-
-	if (mlh2->mld2q_qqic < 128) {
-		mc_qqi = mlh2->mld2q_qqic;
-	} else {
-		unsigned long mc_man, mc_exp;
-
-		mc_exp = MLDV2_QQIC_EXP(mlh2->mld2q_qqic);
-		mc_man = MLDV2_QQIC_MAN(mlh2->mld2q_qqic);
-
-		mc_qqi = (mc_man | 0x10) << (mc_exp + 3);
-	}
-
-	idev->mc_qi = mc_qqi * HZ;
+	idev->mc_qi = mldv2_qqi(mlh2) * HZ;
 }
 
 static void mld_update_qri(struct inet6_dev *idev,
@@ -1338,7 +1325,7 @@ static void mld_update_qri(struct inet6_dev *idev,
 	 *  - 5.1.3. Maximum Response Code
 	 *  - 9.3. Query Response Interval
 	 */
-	idev->mc_qri = msecs_to_jiffies(mldv2_mrc(mlh2));
+	idev->mc_qri = msecs_to_jiffies(mldv2_mrd(mlh2));
 }
 
 static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld,
@@ -1390,7 +1377,7 @@ static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld,
 static void mld_process_v2(struct inet6_dev *idev, struct mld2_query *mld,
 			   unsigned long *max_delay)
 {
-	*max_delay = max(msecs_to_jiffies(mldv2_mrc(mld)), 1UL);
+	*max_delay = max(msecs_to_jiffies(mldv2_mrd(mld)), 1UL);
 
 	mld_update_qrv(idev, mld);
 	mld_update_qi(idev, mld);
-- 
2.43.0
Re: [PATCH 2/4] ipv6: mld: rename mldv2_mrc() and add mldv2_qqi()
Posted by kernel test robot 6 days, 4 hours ago
Hi Ujjal,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]
[also build test WARNING on net/main klassert-ipsec/master linus/master v7.0-rc5 next-20260326]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ujjal-Roy/ipv4-igmp-get-rid-of-IGMPV3_-QQIC-MRC-and-simplify-calculation/20260327-083159
base:   net-next/main
patch link:    https://lore.kernel.org/r/20260326150742.50289-3-royujjal%40gmail.com
patch subject: [PATCH 2/4] ipv6: mld: rename mldv2_mrc() and add mldv2_qqi()
config: x86_64-randconfig-121-20260327 (https://download.01.org/0day-ci/archive/20260327/202603272318.WLQHm8jS-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260327/202603272318.WLQHm8jS-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603272318.WLQHm8jS-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   net/ipv6/mcast.c: note: in included file:
   include/net/mld.h:32:43: sparse: sparse: array of flexible structures
>> include/net/mld.h:147:30: sparse: sparse: cast to restricted __be16

vim +147 include/net/mld.h

    29	
    30	struct mld2_report {
    31		struct icmp6hdr		mld2r_hdr;
  > 32		struct mld2_grec	mld2r_grec[];
    33	};
    34	
    35	#define mld2r_type		mld2r_hdr.icmp6_type
    36	#define mld2r_resv1		mld2r_hdr.icmp6_code
    37	#define mld2r_cksum		mld2r_hdr.icmp6_cksum
    38	#define mld2r_resv2		mld2r_hdr.icmp6_dataun.un_data16[0]
    39	#define mld2r_ngrec		mld2r_hdr.icmp6_dataun.un_data16[1]
    40	
    41	/* MLDv2 Query */
    42	struct mld2_query {
    43		struct icmp6hdr		mld2q_hdr;
    44		struct in6_addr		mld2q_mca;
    45	#if defined(__LITTLE_ENDIAN_BITFIELD)
    46		__u8			mld2q_qrv:3,
    47					mld2q_suppress:1,
    48					mld2q_resv2:4;
    49	#elif defined(__BIG_ENDIAN_BITFIELD)
    50		__u8			mld2q_resv2:4,
    51					mld2q_suppress:1,
    52					mld2q_qrv:3;
    53	#else
    54	#error "Please fix <asm/byteorder.h>"
    55	#endif
    56		__u8			mld2q_qqic;
    57		__be16			mld2q_nsrcs;
    58		struct in6_addr		mld2q_srcs[];
    59	};
    60	
    61	#define mld2q_type		mld2q_hdr.icmp6_type
    62	#define mld2q_code		mld2q_hdr.icmp6_code
    63	#define mld2q_cksum		mld2q_hdr.icmp6_cksum
    64	#define mld2q_mrc		mld2q_hdr.icmp6_maxdelay
    65	#define mld2q_resv1		mld2q_hdr.icmp6_dataun.un_data16[1]
    66	
    67	/* RFC3810, 5.1.3. Maximum Response Code:
    68	 *
    69	 * If Maximum Response Code >= 32768, Maximum Response Code represents a
    70	 * floating-point value as follows:
    71	 *
    72	 *  0 1 2 3 4 5 6 7 8 9 A B C D E F
    73	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    74	 * |1| exp |          mant         |
    75	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    76	 */
    77	#define MLDV2_MRC_EXP(value)	(((value) >> 12) & 0x0007)
    78	#define MLDV2_MRC_MAN(value)	((value) & 0x0fff)
    79	
    80	/* RFC3810, 5.1.9. QQIC (Querier's Query Interval Code):
    81	 *
    82	 * If QQIC >= 128, QQIC represents a floating-point value as follows:
    83	 *
    84	 *  0 1 2 3 4 5 6 7
    85	 * +-+-+-+-+-+-+-+-+
    86	 * |1| exp | mant  |
    87	 * +-+-+-+-+-+-+-+-+
    88	 */
    89	#define MLDV2_QQIC_EXP(value)	(((value) >> 4) & 0x07)
    90	#define MLDV2_QQIC_MAN(value)	((value) & 0x0f)
    91	
    92	#define MLD_QQIC_MIN_THRESHOLD	128
    93	#define MLD_MRC_MIN_THRESHOLD	32768UL
    94	#define MLDV1_MRD_MAX_COMPAT	(MLD_MRC_MIN_THRESHOLD - 1)
    95	
    96	#define MLD_MAX_QUEUE		8
    97	#define MLD_MAX_SKBS		32
    98	
    99	/* V2 exponential field decoding */
   100	
   101	/* Calculate Maximum Response Delay from Maximum Response Code
   102	 *
   103	 * RFC3810, 5.1.3. defines the decoding formula:
   104	 *      0 1 2 3 4 5 6 7 8 9 A B C D E F
   105	 *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   106	 *     |1| exp |          mant         |
   107	 *     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   108	 * Maximum Response Delay = (mant | 0x1000) << (exp+3)
   109	 */
   110	static inline unsigned long mldv2_mrd(const struct mld2_query *mlh2)
   111	{
   112		/* RFC3810, relevant sections:
   113		 *  - 5.1.3. Maximum Response Code
   114		 *  - 9.3. Query Response Interval
   115		 */
   116		unsigned long mc_mrc = ntohs(mlh2->mld2q_mrc);
   117	
   118		if (mc_mrc < MLD_MRC_MIN_THRESHOLD) {
   119			return mc_mrc;
   120		} else {
   121			unsigned long mc_man, mc_exp;
   122	
   123			mc_exp = MLDV2_MRC_EXP(mc_mrc);
   124			mc_man = MLDV2_MRC_MAN(mc_mrc);
   125	
   126			return ((mc_man | 0x1000) << (mc_exp + 3));
   127		}
   128	}
   129	
   130	/* Calculate Querier's Query Interval from Querier's Query Interval Code
   131	 *
   132	 * RFC3810, 5.1.9. defines the decoding formula:
   133	 *      0 1 2 3 4 5 6 7
   134	 *     +-+-+-+-+-+-+-+-+
   135	 *     |1| exp | mant  |
   136	 *     +-+-+-+-+-+-+-+-+
   137	 * QQI = (mant | 0x10) << (exp + 3)
   138	 */
   139	static inline unsigned long mldv2_qqi(const struct mld2_query *mlh2)
   140	{
   141		/* RFC3810, relevant sections:
   142		 *  - 5.1.9. QQIC (Querier's Query Interval Code)
   143		 *  - 9.2. Query Interval
   144		 *  - 9.12. Older Version Querier Present Timeout
   145		 *    (the [Query Interval] in the last Query received)
   146		 */
 > 147		unsigned long qqic = ntohs(mlh2->mld2q_qqic);
   148	
   149		if (qqic < MLD_QQIC_MIN_THRESHOLD) {
   150			return qqic;
   151		} else {
   152			unsigned long mc_man, mc_exp;
   153	
   154			mc_exp = MLDV2_QQIC_EXP(qqic);
   155			mc_man = MLDV2_QQIC_MAN(qqic);
   156	
   157			return ((mc_man | 0x10) << (mc_exp + 3));
   158		}
   159	}
   160	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki