Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ipv6: mld: get rid of MLDV2_MRC and simplify calculation

Get rid of MLDV2_MRC and use our new macros for mantisse and
exponent to calculate Maximum Response Delay out of the Maximum
Response Code.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Daniel Borkmann and committed by
David S. Miller
e3f5b170 6c567b78

+23 -26
+19 -9
include/net/mld.h
··· 63 63 #define mld2q_mrc mld2q_hdr.icmp6_maxdelay 64 64 #define mld2q_resv1 mld2q_hdr.icmp6_dataun.un_data16[1] 65 65 66 - /* Max Response Code, TODO: transform this to use the below */ 67 - #define MLDV2_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value)) 68 - #define MLDV2_EXP(thresh, nbmant, nbexp, value) \ 69 - ((value) < (thresh) ? (value) : \ 70 - ((MLDV2_MASK(value, nbmant) | (1<<(nbmant))) << \ 71 - (MLDV2_MASK((value) >> (nbmant), nbexp) + (nbexp)))) 72 - 73 - #define MLDV2_MRC(value) MLDV2_EXP(0x8000, 12, 3, value) 74 - 75 66 /* RFC3810, 5.1.3. Maximum Response Code: 76 67 * 77 68 * If Maximum Response Code >= 32768, Maximum Response Code represents a ··· 87 96 */ 88 97 #define MLDV2_QQIC_EXP(value) (((value) >> 4) & 0x07) 89 98 #define MLDV2_QQIC_MAN(value) ((value) & 0x0f) 99 + 100 + static inline unsigned long mldv2_mrc(const struct mld2_query *mlh2) 101 + { 102 + /* RFC3810, 5.1.3. Maximum Response Code */ 103 + unsigned long ret, mc_mrc = ntohs(mlh2->mld2q_mrc); 104 + 105 + if (mc_mrc < 32768) { 106 + ret = mc_mrc; 107 + } else { 108 + unsigned long mc_man, mc_exp; 109 + 110 + mc_exp = MLDV2_MRC_EXP(mc_mrc); 111 + mc_man = MLDV2_MRC_MAN(mc_mrc); 112 + 113 + ret = (mc_man | 0x1000) << (mc_exp + 3); 114 + } 115 + 116 + return ret; 117 + } 90 118 91 119 #endif
+2 -1
net/bridge/br_multicast.c
··· 1203 1203 mld2q = (struct mld2_query *)icmp6_hdr(skb); 1204 1204 if (!mld2q->mld2q_nsrcs) 1205 1205 group = &mld2q->mld2q_mca; 1206 - max_delay = mld2q->mld2q_mrc ? MLDV2_MRC(ntohs(mld2q->mld2q_mrc)) : 1; 1206 + 1207 + max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL); 1207 1208 } 1208 1209 1209 1210 br_multicast_query_received(br, port, !ipv6_addr_any(&ip6h->saddr),
+2 -16
net/ipv6/mcast.c
··· 1195 1195 * - 5.1.3. Maximum Response Code 1196 1196 * - 9.3. Query Response Interval 1197 1197 */ 1198 - unsigned long mc_qri, mc_mrc = ntohs(mlh2->mld2q_mrc); 1199 - 1200 - if (mc_mrc < 32768) { 1201 - mc_qri = mc_mrc; 1202 - } else { 1203 - unsigned long mc_man, mc_exp; 1204 - 1205 - mc_exp = MLDV2_MRC_EXP(mc_mrc); 1206 - mc_man = MLDV2_MRC_MAN(mc_mrc); 1207 - 1208 - mc_qri = (mc_man | 0x1000) << (mc_exp + 3); 1209 - } 1210 - 1211 - idev->mc_qri = msecs_to_jiffies(mc_qri); 1198 + idev->mc_qri = msecs_to_jiffies(mldv2_mrc(mlh2)); 1212 1199 } 1213 1200 1214 1201 /* called with rcu_read_lock() */ ··· 1264 1277 1265 1278 mlh2 = (struct mld2_query *)skb_transport_header(skb); 1266 1279 1267 - max_delay = max(msecs_to_jiffies(MLDV2_MRC(ntohs(mlh2->mld2q_mrc))), 1UL); 1268 - 1280 + max_delay = max(msecs_to_jiffies(mldv2_mrc(mlh2)), 1UL); 1269 1281 idev->mc_maxdelay = max_delay; 1270 1282 1271 1283 mld_update_qrv(idev, mlh2);