aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2012-08-08 17:53:36 -0400
committerDavid S. Miller <davem@davemloft.net>2012-08-09 19:18:07 -0400
commit1fb9489bf190ce2b3fc03891f3de4b2d30600e28 (patch)
treeda4e17036949e72ae0b1f0fc3b6b31557de18353
parentaa79e66eee5d525e2fcbd2a5fcb87ae3dd4aa9e9 (diff)
net: Loopback ifindex is constant now
As pointed out, there are places, that access net->loopback_dev->ifindex and after ifindex generation is made per-net this value becomes constant equals 1. So go ahead and introduce the LOOPBACK_IFINDEX constant and use it where appropriate. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/loopback.c1
-rw-r--r--include/net/net_namespace.h7
-rw-r--r--net/decnet/dn_route.c6
-rw-r--r--net/ipv4/fib_frontend.c2
-rw-r--r--net/ipv4/ipmr.c2
-rw-r--r--net/ipv4/netfilter/ipt_rpfilter.c2
-rw-r--r--net/ipv4/route.c6
-rw-r--r--net/ipv6/route.c2
8 files changed, 18 insertions, 10 deletions
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index e2a06fd996d5..4a075babe193 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -197,6 +197,7 @@ static __net_init int loopback_net_init(struct net *net)
197 if (err) 197 if (err)
198 goto out_free_netdev; 198 goto out_free_netdev;
199 199
200 BUG_ON(dev->ifindex != LOOPBACK_IFINDEX);
200 net->loopback_dev = dev; 201 net->loopback_dev = dev;
201 return 0; 202 return 0;
202 203
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 6dc3db3466bf..97e441945c13 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -105,6 +105,13 @@ struct net {
105 struct sock *diag_nlsk; 105 struct sock *diag_nlsk;
106}; 106};
107 107
108/*
109 * ifindex generation is per-net namespace, and loopback is
110 * always the 1st device in ns (see net_dev_init), thus any
111 * loopback device should get ifindex 1
112 */
113
114#define LOOPBACK_IFINDEX 1
108 115
109#include <linux/seq_file_net.h> 116#include <linux/seq_file_net.h>
110 117
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 85a3604c87c8..c855e8d0738f 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -961,7 +961,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
961 .saddr = oldflp->saddr, 961 .saddr = oldflp->saddr,
962 .flowidn_scope = RT_SCOPE_UNIVERSE, 962 .flowidn_scope = RT_SCOPE_UNIVERSE,
963 .flowidn_mark = oldflp->flowidn_mark, 963 .flowidn_mark = oldflp->flowidn_mark,
964 .flowidn_iif = init_net.loopback_dev->ifindex, 964 .flowidn_iif = LOOPBACK_IFINDEX,
965 .flowidn_oif = oldflp->flowidn_oif, 965 .flowidn_oif = oldflp->flowidn_oif,
966 }; 966 };
967 struct dn_route *rt = NULL; 967 struct dn_route *rt = NULL;
@@ -979,7 +979,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *o
979 "dn_route_output_slow: dst=%04x src=%04x mark=%d" 979 "dn_route_output_slow: dst=%04x src=%04x mark=%d"
980 " iif=%d oif=%d\n", le16_to_cpu(oldflp->daddr), 980 " iif=%d oif=%d\n", le16_to_cpu(oldflp->daddr),
981 le16_to_cpu(oldflp->saddr), 981 le16_to_cpu(oldflp->saddr),
982 oldflp->flowidn_mark, init_net.loopback_dev->ifindex, 982 oldflp->flowidn_mark, LOOPBACK_IFINDEX,
983 oldflp->flowidn_oif); 983 oldflp->flowidn_oif);
984 984
985 /* If we have an output interface, verify its a DECnet device */ 985 /* If we have an output interface, verify its a DECnet device */
@@ -1042,7 +1042,7 @@ source_ok:
1042 if (!fld.daddr) 1042 if (!fld.daddr)
1043 goto out; 1043 goto out;
1044 } 1044 }
1045 fld.flowidn_oif = init_net.loopback_dev->ifindex; 1045 fld.flowidn_oif = LOOPBACK_IFINDEX;
1046 res.type = RTN_LOCAL; 1046 res.type = RTN_LOCAL;
1047 goto make_route; 1047 goto make_route;
1048 } 1048 }
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index c43ae3fba792..7f073a38c87d 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -218,7 +218,7 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
218 scope = RT_SCOPE_UNIVERSE; 218 scope = RT_SCOPE_UNIVERSE;
219 if (!ipv4_is_zeronet(ip_hdr(skb)->saddr)) { 219 if (!ipv4_is_zeronet(ip_hdr(skb)->saddr)) {
220 fl4.flowi4_oif = 0; 220 fl4.flowi4_oif = 0;
221 fl4.flowi4_iif = net->loopback_dev->ifindex; 221 fl4.flowi4_iif = LOOPBACK_IFINDEX;
222 fl4.daddr = ip_hdr(skb)->saddr; 222 fl4.daddr = ip_hdr(skb)->saddr;
223 fl4.saddr = 0; 223 fl4.saddr = 0;
224 fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos); 224 fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 8eec8f4a0536..3a57570c8ee5 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1798,7 +1798,7 @@ static struct mr_table *ipmr_rt_fib_lookup(struct net *net, struct sk_buff *skb)
1798 .flowi4_oif = (rt_is_output_route(rt) ? 1798 .flowi4_oif = (rt_is_output_route(rt) ?
1799 skb->dev->ifindex : 0), 1799 skb->dev->ifindex : 0),
1800 .flowi4_iif = (rt_is_output_route(rt) ? 1800 .flowi4_iif = (rt_is_output_route(rt) ?
1801 net->loopback_dev->ifindex : 1801 LOOPBACK_IFINDEX :
1802 skb->dev->ifindex), 1802 skb->dev->ifindex),
1803 .flowi4_mark = skb->mark, 1803 .flowi4_mark = skb->mark,
1804 }; 1804 };
diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c
index 31371be8174b..c30130062cd6 100644
--- a/net/ipv4/netfilter/ipt_rpfilter.c
+++ b/net/ipv4/netfilter/ipt_rpfilter.c
@@ -85,7 +85,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
85 return ipv4_is_local_multicast(iph->daddr) ^ invert; 85 return ipv4_is_local_multicast(iph->daddr) ^ invert;
86 flow.flowi4_iif = 0; 86 flow.flowi4_iif = 0;
87 } else { 87 } else {
88 flow.flowi4_iif = dev_net(par->in)->loopback_dev->ifindex; 88 flow.flowi4_iif = LOOPBACK_IFINDEX;
89 } 89 }
90 90
91 flow.daddr = iph->saddr; 91 flow.daddr = iph->saddr;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 21ad369014c0..c58137391a3d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1619,7 +1619,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1619 1619
1620 if (res.type == RTN_LOCAL) { 1620 if (res.type == RTN_LOCAL) {
1621 err = fib_validate_source(skb, saddr, daddr, tos, 1621 err = fib_validate_source(skb, saddr, daddr, tos,
1622 net->loopback_dev->ifindex, 1622 LOOPBACK_IFINDEX,
1623 dev, in_dev, &itag); 1623 dev, in_dev, &itag);
1624 if (err < 0) 1624 if (err < 0)
1625 goto martian_source_keep_err; 1625 goto martian_source_keep_err;
@@ -1895,7 +1895,7 @@ struct rtable *__ip_route_output_key(struct net *net, struct flowi4 *fl4)
1895 1895
1896 orig_oif = fl4->flowi4_oif; 1896 orig_oif = fl4->flowi4_oif;
1897 1897
1898 fl4->flowi4_iif = net->loopback_dev->ifindex; 1898 fl4->flowi4_iif = LOOPBACK_IFINDEX;
1899 fl4->flowi4_tos = tos & IPTOS_RT_MASK; 1899 fl4->flowi4_tos = tos & IPTOS_RT_MASK;
1900 fl4->flowi4_scope = ((tos & RTO_ONLINK) ? 1900 fl4->flowi4_scope = ((tos & RTO_ONLINK) ?
1901 RT_SCOPE_LINK : RT_SCOPE_UNIVERSE); 1901 RT_SCOPE_LINK : RT_SCOPE_UNIVERSE);
@@ -1984,7 +1984,7 @@ struct rtable *__ip_route_output_key(struct net *net, struct flowi4 *fl4)
1984 if (!fl4->daddr) 1984 if (!fl4->daddr)
1985 fl4->daddr = fl4->saddr = htonl(INADDR_LOOPBACK); 1985 fl4->daddr = fl4->saddr = htonl(INADDR_LOOPBACK);
1986 dev_out = net->loopback_dev; 1986 dev_out = net->loopback_dev;
1987 fl4->flowi4_oif = net->loopback_dev->ifindex; 1987 fl4->flowi4_oif = LOOPBACK_IFINDEX;
1988 res.type = RTN_LOCAL; 1988 res.type = RTN_LOCAL;
1989 flags |= RTCF_LOCAL; 1989 flags |= RTCF_LOCAL;
1990 goto make_route; 1990 goto make_route;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 8e80fd279100..0ddf2d132e7f 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -965,7 +965,7 @@ struct dst_entry * ip6_route_output(struct net *net, const struct sock *sk,
965{ 965{
966 int flags = 0; 966 int flags = 0;
967 967
968 fl6->flowi6_iif = net->loopback_dev->ifindex; 968 fl6->flowi6_iif = LOOPBACK_IFINDEX;
969 969
970 if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr)) 970 if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr))
971 flags |= RT6_LOOKUP_F_IFACE; 971 flags |= RT6_LOOKUP_F_IFACE;