aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-04-28 22:57:34 -0400
committerDavid S. Miller <davem@davemloft.net>2014-04-30 13:31:26 -0400
commit5c98631cca574ac6255885cf372f6bcf9dcfd483 (patch)
tree53e82fe083c0db2aeca000e70872f1d01e0b4146
parenta22adce5f97c172398082bf9a713ccfba6c2364f (diff)
net: ipv6: Introduce ip6_sk_dst_hoplimit.
This replaces 6 identical code snippets with a call to a new static inline function. Signed-off-by: Lorenzo Colitti <lorenzo@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/addrconf.h5
-rw-r--r--include/net/ipv6.h19
-rw-r--r--net/ipv6/icmp.c14
-rw-r--r--net/ipv6/ip6_flowlabel.c1
-rw-r--r--net/ipv6/ping.c7
-rw-r--r--net/ipv6/raw.c10
-rw-r--r--net/ipv6/udp.c10
-rw-r--r--net/l2tp/l2tp_ip6.c10
8 files changed, 28 insertions, 48 deletions
diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 933a9f22a05f..f679877bb601 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -306,11 +306,6 @@ static inline void addrconf_addr_solict_mult(const struct in6_addr *addr,
306 htonl(0xFF000000) | addr->s6_addr32[3]); 306 htonl(0xFF000000) | addr->s6_addr32[3]);
307} 307}
308 308
309static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr)
310{
311 return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
312}
313
314static inline bool ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr) 309static inline bool ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr)
315{ 310{
316#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 311#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index d640925bc454..5b40ad297b8c 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -583,6 +583,11 @@ static inline bool ipv6_addr_orchid(const struct in6_addr *a)
583 return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010); 583 return (a->s6_addr32[0] & htonl(0xfffffff0)) == htonl(0x20010010);
584} 584}
585 585
586static inline bool ipv6_addr_is_multicast(const struct in6_addr *addr)
587{
588 return (addr->s6_addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
589}
590
586static inline void ipv6_addr_set_v4mapped(const __be32 addr, 591static inline void ipv6_addr_set_v4mapped(const __be32 addr,
587 struct in6_addr *v4mapped) 592 struct in6_addr *v4mapped)
588{ 593{
@@ -664,6 +669,20 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt);
664 669
665int ip6_dst_hoplimit(struct dst_entry *dst); 670int ip6_dst_hoplimit(struct dst_entry *dst);
666 671
672static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
673 struct dst_entry *dst)
674{
675 int hlimit;
676
677 if (ipv6_addr_is_multicast(&fl6->daddr))
678 hlimit = np->mcast_hops;
679 else
680 hlimit = np->hop_limit;
681 if (hlimit < 0)
682 hlimit = ip6_dst_hoplimit(dst);
683 return hlimit;
684}
685
667/* 686/*
668 * Header manipulation 687 * Header manipulation
669 */ 688 */
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 7b326529e6a2..3b0905b77127 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -493,12 +493,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
493 if (IS_ERR(dst)) 493 if (IS_ERR(dst))
494 goto out; 494 goto out;
495 495
496 if (ipv6_addr_is_multicast(&fl6.daddr)) 496 hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
497 hlimit = np->mcast_hops;
498 else
499 hlimit = np->hop_limit;
500 if (hlimit < 0)
501 hlimit = ip6_dst_hoplimit(dst);
502 497
503 msg.skb = skb; 498 msg.skb = skb;
504 msg.offset = skb_network_offset(skb); 499 msg.offset = skb_network_offset(skb);
@@ -593,12 +588,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
593 if (IS_ERR(dst)) 588 if (IS_ERR(dst))
594 goto out; 589 goto out;
595 590
596 if (ipv6_addr_is_multicast(&fl6.daddr)) 591 hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
597 hlimit = np->mcast_hops;
598 else
599 hlimit = np->hop_limit;
600 if (hlimit < 0)
601 hlimit = ip6_dst_hoplimit(dst);
602 592
603 idev = __in6_dev_get(skb->dev); 593 idev = __in6_dev_get(skb->dev);
604 594
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index 0961b5ef866d..4052694c6f2c 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -26,7 +26,6 @@
26#include <net/sock.h> 26#include <net/sock.h>
27 27
28#include <net/ipv6.h> 28#include <net/ipv6.h>
29#include <net/addrconf.h>
30#include <net/rawv6.h> 29#include <net/rawv6.h>
31#include <net/transp_v6.h> 30#include <net/transp_v6.h>
32 31
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index bda74291c3e0..a2a1d80dfe0c 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -168,12 +168,7 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
168 pfh.wcheck = 0; 168 pfh.wcheck = 0;
169 pfh.family = AF_INET6; 169 pfh.family = AF_INET6;
170 170
171 if (ipv6_addr_is_multicast(&fl6.daddr)) 171 hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
172 hlimit = np->mcast_hops;
173 else
174 hlimit = np->hop_limit;
175 if (hlimit < 0)
176 hlimit = ip6_dst_hoplimit(dst);
177 172
178 lock_sock(sk); 173 lock_sock(sk);
179 err = ip6_append_data(sk, ping_getfrag, &pfh, len, 174 err = ip6_append_data(sk, ping_getfrag, &pfh, len,
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 1f29996e368a..dddfb5fa2b7a 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -873,14 +873,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
873 err = PTR_ERR(dst); 873 err = PTR_ERR(dst);
874 goto out; 874 goto out;
875 } 875 }
876 if (hlimit < 0) { 876 if (hlimit < 0)
877 if (ipv6_addr_is_multicast(&fl6.daddr)) 877 hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
878 hlimit = np->mcast_hops;
879 else
880 hlimit = np->hop_limit;
881 if (hlimit < 0)
882 hlimit = ip6_dst_hoplimit(dst);
883 }
884 878
885 if (tclass < 0) 879 if (tclass < 0)
886 tclass = np->tclass; 880 tclass = np->tclass;
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 1e586d92260e..d8d6ca04bb9d 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1232,14 +1232,8 @@ do_udp_sendmsg:
1232 goto out; 1232 goto out;
1233 } 1233 }
1234 1234
1235 if (hlimit < 0) { 1235 if (hlimit < 0)
1236 if (ipv6_addr_is_multicast(&fl6.daddr)) 1236 hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
1237 hlimit = np->mcast_hops;
1238 else
1239 hlimit = np->hop_limit;
1240 if (hlimit < 0)
1241 hlimit = ip6_dst_hoplimit(dst);
1242 }
1243 1237
1244 if (tclass < 0) 1238 if (tclass < 0)
1245 tclass = np->tclass; 1239 tclass = np->tclass;
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 7704ea9502fd..e472d44a3b91 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -605,14 +605,8 @@ static int l2tp_ip6_sendmsg(struct kiocb *iocb, struct sock *sk,
605 goto out; 605 goto out;
606 } 606 }
607 607
608 if (hlimit < 0) { 608 if (hlimit < 0)
609 if (ipv6_addr_is_multicast(&fl6.daddr)) 609 hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
610 hlimit = np->mcast_hops;
611 else
612 hlimit = np->hop_limit;
613 if (hlimit < 0)
614 hlimit = ip6_dst_hoplimit(dst);
615 }
616 610
617 if (tclass < 0) 611 if (tclass < 0)
618 tclass = np->tclass; 612 tclass = np->tclass;