diff options
author | Joe Perches <joe@perches.com> | 2014-12-01 23:29:06 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-12-08 20:28:47 -0500 |
commit | 60c04aecd8a72a84869308bdf2289a7aabb9a88c (patch) | |
tree | d1ab7ab4a17e112d6f27ab5b5268f602cc1be3a1 /net/ipv4/udp.c | |
parent | b0ba512e25d729a43858ad1f6cb8b94dbb95dbeb (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/ipv4/udp.c')
-rw-r--r-- | net/ipv4/udp.c | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index b2d606833ce4..dd8e00634563 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -336,38 +336,45 @@ int udp_v4_get_port(struct sock *sk, unsigned short snum) | |||
336 | return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal, hash2_nulladdr); | 336 | return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal, hash2_nulladdr); |
337 | } | 337 | } |
338 | 338 | ||
339 | static inline int compute_score(struct sock *sk, struct net *net, __be32 saddr, | 339 | static inline int compute_score(struct sock *sk, struct net *net, |
340 | unsigned short hnum, | 340 | __be32 saddr, unsigned short hnum, __be16 sport, |
341 | __be16 sport, __be32 daddr, __be16 dport, int dif) | 341 | __be32 daddr, __be16 dport, int dif) |
342 | { | 342 | { |
343 | int score = -1; | 343 | int score; |
344 | struct inet_sock *inet; | ||
344 | 345 | ||
345 | if (net_eq(sock_net(sk), net) && udp_sk(sk)->udp_port_hash == hnum && | 346 | if (!net_eq(sock_net(sk), net) || |
346 | !ipv6_only_sock(sk)) { | 347 | udp_sk(sk)->udp_port_hash != hnum || |
347 | struct inet_sock *inet = inet_sk(sk); | 348 | ipv6_only_sock(sk)) |
349 | return -1; | ||
348 | 350 | ||
349 | score = (sk->sk_family == PF_INET ? 2 : 1); | 351 | score = (sk->sk_family == PF_INET) ? 2 : 1; |
350 | if (inet->inet_rcv_saddr) { | 352 | inet = inet_sk(sk); |
351 | if (inet->inet_rcv_saddr != daddr) | 353 | |
352 | return -1; | 354 | if (inet->inet_rcv_saddr) { |
353 | score += 4; | 355 | if (inet->inet_rcv_saddr != daddr) |
354 | } | 356 | return -1; |
355 | if (inet->inet_daddr) { | 357 | score += 4; |
356 | if (inet->inet_daddr != saddr) | 358 | } |
357 | return -1; | 359 | |
358 | score += 4; | 360 | if (inet->inet_daddr) { |
359 | } | 361 | if (inet->inet_daddr != saddr) |
360 | if (inet->inet_dport) { | 362 | return -1; |
361 | if (inet->inet_dport != sport) | 363 | score += 4; |
362 | return -1; | ||
363 | score += 4; | ||
364 | } | ||
365 | if (sk->sk_bound_dev_if) { | ||
366 | if (sk->sk_bound_dev_if != dif) | ||
367 | return -1; | ||
368 | score += 4; | ||
369 | } | ||
370 | } | 364 | } |
365 | |||
366 | if (inet->inet_dport) { | ||
367 | if (inet->inet_dport != sport) | ||
368 | return -1; | ||
369 | score += 4; | ||
370 | } | ||
371 | |||
372 | if (sk->sk_bound_dev_if) { | ||
373 | if (sk->sk_bound_dev_if != dif) | ||
374 | return -1; | ||
375 | score += 4; | ||
376 | } | ||
377 | |||
371 | return score; | 378 | return score; |
372 | } | 379 | } |
373 | 380 | ||
@@ -378,33 +385,39 @@ static inline int compute_score2(struct sock *sk, struct net *net, | |||
378 | __be32 saddr, __be16 sport, | 385 | __be32 saddr, __be16 sport, |
379 | __be32 daddr, unsigned int hnum, int dif) | 386 | __be32 daddr, unsigned int hnum, int dif) |
380 | { | 387 | { |
381 | int score = -1; | 388 | int score; |
389 | struct inet_sock *inet; | ||
390 | |||
391 | if (!net_eq(sock_net(sk), net) || | ||
392 | ipv6_only_sock(sk)) | ||
393 | return -1; | ||
382 | 394 | ||
383 | if (net_eq(sock_net(sk), net) && !ipv6_only_sock(sk)) { | 395 | inet = inet_sk(sk); |
384 | struct inet_sock *inet = inet_sk(sk); | ||
385 | 396 | ||
386 | if (inet->inet_rcv_saddr != daddr) | 397 | if (inet->inet_rcv_saddr != daddr || |
398 | inet->inet_num != hnum) | ||
399 | return -1; | ||
400 | |||
401 | score = (sk->sk_family == PF_INET) ? 2 : 1; | ||
402 | |||
403 | if (inet->inet_daddr) { | ||
404 | if (inet->inet_daddr != saddr) | ||
387 | return -1; | 405 | return -1; |
388 | if (inet->inet_num != hnum) | 406 | score += 4; |
407 | } | ||
408 | |||
409 | if (inet->inet_dport) { | ||
410 | if (inet->inet_dport != sport) | ||
389 | return -1; | 411 | return -1; |
412 | score += 4; | ||
413 | } | ||
390 | 414 | ||
391 | score = (sk->sk_family == PF_INET ? 2 : 1); | 415 | if (sk->sk_bound_dev_if) { |
392 | if (inet->inet_daddr) { | 416 | if (sk->sk_bound_dev_if != dif) |
393 | if (inet->inet_daddr != saddr) | 417 | return -1; |
394 | return -1; | 418 | score += 4; |
395 | score += 4; | ||
396 | } | ||
397 | if (inet->inet_dport) { | ||
398 | if (inet->inet_dport != sport) | ||
399 | return -1; | ||
400 | score += 4; | ||
401 | } | ||
402 | if (sk->sk_bound_dev_if) { | ||
403 | if (sk->sk_bound_dev_if != dif) | ||
404 | return -1; | ||
405 | score += 4; | ||
406 | } | ||
407 | } | 419 | } |
420 | |||
408 | return score; | 421 | return score; |
409 | } | 422 | } |
410 | 423 | ||