aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-12-01 23:29:06 -0500
committerDavid S. Miller <davem@davemloft.net>2014-12-08 20:28:47 -0500
commit60c04aecd8a72a84869308bdf2289a7aabb9a88c (patch)
treed1ab7ab4a17e112d6f27ab5b5268f602cc1be3a1 /net/ipv6
parentb0ba512e25d729a43858ad1f6cb8b94dbb95dbeb (diff)
udp: Neaten and reduce size of compute_score functions
The compute_score functions are a bit difficult to read. Neaten them a bit to reduce object sizes and make them a bit more intelligible. Return early to avoid indentation and avoid unnecessary initializations. (allyesconfig, but w/ -O2 and no profiling) $ size net/ipv[46]/udp.o.* text data bss dec hex filename 28680 1184 25 29889 74c1 net/ipv4/udp.o.new 28756 1184 25 29965 750d net/ipv4/udp.o.old 17600 1010 2 18612 48b4 net/ipv6/udp.o.new 17632 1010 2 18644 48d4 net/ipv6/udp.o.old Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r--net/ipv6/udp.c113
1 files changed, 63 insertions, 50 deletions
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 7cfb5d745a2d..7f96432292ce 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -148,72 +148,85 @@ static inline int compute_score(struct sock *sk, struct net *net,
148 const struct in6_addr *daddr, __be16 dport, 148 const struct in6_addr *daddr, __be16 dport,
149 int dif) 149 int dif)
150{ 150{
151 int score = -1; 151 int score;
152 struct inet_sock *inet;
152 153
153 if (net_eq(sock_net(sk), net) && udp_sk(sk)->udp_port_hash == hnum && 154 if (!net_eq(sock_net(sk), net) ||
154 sk->sk_family == PF_INET6) { 155 udp_sk(sk)->udp_port_hash != hnum ||
155 struct inet_sock *inet = inet_sk(sk); 156 sk->sk_family != PF_INET6)
157 return -1;
156 158
157 score = 0; 159 score = 0;
158 if (inet->inet_dport) { 160 inet = inet_sk(sk);
159 if (inet->inet_dport != sport) 161
160 return -1; 162 if (inet->inet_dport) {
161 score++; 163 if (inet->inet_dport != sport)
162 } 164 return -1;
163 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) { 165 score++;
164 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
165 return -1;
166 score++;
167 }
168 if (!ipv6_addr_any(&sk->sk_v6_daddr)) {
169 if (!ipv6_addr_equal(&sk->sk_v6_daddr, saddr))
170 return -1;
171 score++;
172 }
173 if (sk->sk_bound_dev_if) {
174 if (sk->sk_bound_dev_if != dif)
175 return -1;
176 score++;
177 }
178 } 166 }
167
168 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
169 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
170 return -1;
171 score++;
172 }
173
174 if (!ipv6_addr_any(&sk->sk_v6_daddr)) {
175 if (!ipv6_addr_equal(&sk->sk_v6_daddr, saddr))
176 return -1;
177 score++;
178 }
179
180 if (sk->sk_bound_dev_if) {
181 if (sk->sk_bound_dev_if != dif)
182 return -1;
183 score++;
184 }
185
179 return score; 186 return score;
180} 187}
181 188
182#define SCORE2_MAX (1 + 1 + 1) 189#define SCORE2_MAX (1 + 1 + 1)
183static inline int compute_score2(struct sock *sk, struct net *net, 190static inline int compute_score2(struct sock *sk, struct net *net,
184 const struct in6_addr *saddr, __be16 sport, 191 const struct in6_addr *saddr, __be16 sport,
185 const struct in6_addr *daddr, unsigned short hnum, 192 const struct in6_addr *daddr,
186 int dif) 193 unsigned short hnum, int dif)
187{ 194{
188 int score = -1; 195 int score;
196 struct inet_sock *inet;
189 197
190 if (net_eq(sock_net(sk), net) && udp_sk(sk)->udp_port_hash == hnum && 198 if (!net_eq(sock_net(sk), net) ||
191 sk->sk_family == PF_INET6) { 199 udp_sk(sk)->udp_port_hash != hnum ||
192 struct inet_sock *inet = inet_sk(sk); 200 sk->sk_family != PF_INET6)
201 return -1;
193 202
194 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr)) 203 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
204 return -1;
205
206 score = 0;
207 inet = inet_sk(sk);
208
209 if (inet->inet_dport) {
210 if (inet->inet_dport != sport)
195 return -1; 211 return -1;
196 score = 0; 212 score++;
197 if (inet->inet_dport) {
198 if (inet->inet_dport != sport)
199 return -1;
200 score++;
201 }
202 if (!ipv6_addr_any(&sk->sk_v6_daddr)) {
203 if (!ipv6_addr_equal(&sk->sk_v6_daddr, saddr))
204 return -1;
205 score++;
206 }
207 if (sk->sk_bound_dev_if) {
208 if (sk->sk_bound_dev_if != dif)
209 return -1;
210 score++;
211 }
212 } 213 }
214
215 if (!ipv6_addr_any(&sk->sk_v6_daddr)) {
216 if (!ipv6_addr_equal(&sk->sk_v6_daddr, saddr))
217 return -1;
218 score++;
219 }
220
221 if (sk->sk_bound_dev_if) {
222 if (sk->sk_bound_dev_if != dif)
223 return -1;
224 score++;
225 }
226
213 return score; 227 return score;
214} 228}
215 229
216
217/* called with read_rcu_lock() */ 230/* called with read_rcu_lock() */
218static struct sock *udp6_lib_lookup2(struct net *net, 231static struct sock *udp6_lib_lookup2(struct net *net,
219 const struct in6_addr *saddr, __be16 sport, 232 const struct in6_addr *saddr, __be16 sport,