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

Configure Feed

Select the types of activity you want to include in your feed.

ip6_gre: Factor out common ip6gre tunnel match into helper

Extract common ip6gre tunnel match from ip6gre_tunnel_lookup() into new
helper function ip6gre_tunnel_match() to reduce code duplication.

No functional change intended.

Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250719081551.963670-1-yuehaibing@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Yue Haibing and committed by
Paolo Abeni
db8a5149 cdb79400

+34 -66
+34 -66
net/ipv6/ip6_gre.c
··· 111 111 #define tunnels_l tunnels[1] 112 112 #define tunnels_wc tunnels[0] 113 113 114 - /* Given src, dst and key, find appropriate for input tunnel. */ 114 + static bool ip6gre_tunnel_match(struct ip6_tnl *t, int dev_type, int link, 115 + int *cand_score, struct ip6_tnl **ret) 116 + { 117 + int score = 0; 115 118 119 + if (t->dev->type != ARPHRD_IP6GRE && 120 + t->dev->type != dev_type) 121 + return false; 122 + 123 + if (t->parms.link != link) 124 + score |= 1; 125 + if (t->dev->type != dev_type) 126 + score |= 2; 127 + if (score == 0) { 128 + *ret = t; 129 + return true; 130 + } 131 + 132 + if (score < *cand_score) { 133 + *ret = t; 134 + *cand_score = score; 135 + } 136 + return false; 137 + } 138 + 139 + /* Given src, dst and key, find appropriate for input tunnel. */ 116 140 static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev, 117 141 const struct in6_addr *remote, const struct in6_addr *local, 118 142 __be32 key, __be16 gre_proto) ··· 151 127 gre_proto == htons(ETH_P_ERSPAN) || 152 128 gre_proto == htons(ETH_P_ERSPAN2)) ? 153 129 ARPHRD_ETHER : ARPHRD_IP6GRE; 154 - int score, cand_score = 4; 155 130 struct net_device *ndev; 131 + int cand_score = 4; 156 132 157 133 for_each_ip_tunnel_rcu(t, ign->tunnels_r_l[h0 ^ h1]) { 158 134 if (!ipv6_addr_equal(local, &t->parms.laddr) || ··· 161 137 !(t->dev->flags & IFF_UP)) 162 138 continue; 163 139 164 - if (t->dev->type != ARPHRD_IP6GRE && 165 - t->dev->type != dev_type) 166 - continue; 167 - 168 - score = 0; 169 - if (t->parms.link != link) 170 - score |= 1; 171 - if (t->dev->type != dev_type) 172 - score |= 2; 173 - if (score == 0) 174 - return t; 175 - 176 - if (score < cand_score) { 177 - cand = t; 178 - cand_score = score; 179 - } 140 + if (ip6gre_tunnel_match(t, dev_type, link, &cand_score, &cand)) 141 + return cand; 180 142 } 181 143 182 144 for_each_ip_tunnel_rcu(t, ign->tunnels_r[h0 ^ h1]) { ··· 171 161 !(t->dev->flags & IFF_UP)) 172 162 continue; 173 163 174 - if (t->dev->type != ARPHRD_IP6GRE && 175 - t->dev->type != dev_type) 176 - continue; 177 - 178 - score = 0; 179 - if (t->parms.link != link) 180 - score |= 1; 181 - if (t->dev->type != dev_type) 182 - score |= 2; 183 - if (score == 0) 184 - return t; 185 - 186 - if (score < cand_score) { 187 - cand = t; 188 - cand_score = score; 189 - } 164 + if (ip6gre_tunnel_match(t, dev_type, link, &cand_score, &cand)) 165 + return cand; 190 166 } 191 167 192 168 for_each_ip_tunnel_rcu(t, ign->tunnels_l[h1]) { ··· 183 187 !(t->dev->flags & IFF_UP)) 184 188 continue; 185 189 186 - if (t->dev->type != ARPHRD_IP6GRE && 187 - t->dev->type != dev_type) 188 - continue; 189 - 190 - score = 0; 191 - if (t->parms.link != link) 192 - score |= 1; 193 - if (t->dev->type != dev_type) 194 - score |= 2; 195 - if (score == 0) 196 - return t; 197 - 198 - if (score < cand_score) { 199 - cand = t; 200 - cand_score = score; 201 - } 190 + if (ip6gre_tunnel_match(t, dev_type, link, &cand_score, &cand)) 191 + return cand; 202 192 } 203 193 204 194 for_each_ip_tunnel_rcu(t, ign->tunnels_wc[h1]) { ··· 192 210 !(t->dev->flags & IFF_UP)) 193 211 continue; 194 212 195 - if (t->dev->type != ARPHRD_IP6GRE && 196 - t->dev->type != dev_type) 197 - continue; 198 - 199 - score = 0; 200 - if (t->parms.link != link) 201 - score |= 1; 202 - if (t->dev->type != dev_type) 203 - score |= 2; 204 - if (score == 0) 205 - return t; 206 - 207 - if (score < cand_score) { 208 - cand = t; 209 - cand_score = score; 210 - } 213 + if (ip6gre_tunnel_match(t, dev_type, link, &cand_score, &cand)) 214 + return cand; 211 215 } 212 216 213 217 if (cand)