Skip to content

Commit

Permalink
net: Replace vrf_master_ifindex{, _rcu} with l3mdev equivalents
Browse files Browse the repository at this point in the history
Replace calls to vrf_master_ifindex_rcu and vrf_master_ifindex with either
l3mdev_master_ifindex_rcu or l3mdev_master_ifindex.

The pattern:
    oif = vrf_master_ifindex(dev) ? : dev->ifindex;
is replaced with
    oif = l3mdev_fib_oif(dev);

And remove the now unused vrf macros.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David Ahern authored and David S. Miller committed Sep 30, 2015
1 parent ee15ee5 commit 385add9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 63 deletions.
41 changes: 0 additions & 41 deletions include/net/vrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,6 @@ struct net_vrf {


#if IS_ENABLED(CONFIG_NET_VRF)
/* called with rcu_read_lock() */
static inline int vrf_master_ifindex_rcu(const struct net_device *dev)
{
struct net_vrf_dev *vrf_ptr;
int ifindex = 0;

if (!dev)
return 0;

if (netif_is_l3_master(dev)) {
ifindex = dev->ifindex;
} else {
vrf_ptr = rcu_dereference(dev->vrf_ptr);
if (vrf_ptr)
ifindex = vrf_ptr->ifindex;
}

return ifindex;
}

static inline int vrf_master_ifindex(const struct net_device *dev)
{
int ifindex;

rcu_read_lock();
ifindex = vrf_master_ifindex_rcu(dev);
rcu_read_unlock();

return ifindex;
}

/* called with rcu_read_lock */
static inline u32 vrf_dev_table_rcu(const struct net_device *dev)
{
Expand Down Expand Up @@ -139,16 +108,6 @@ static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
}

#else
static inline int vrf_master_ifindex_rcu(const struct net_device *dev)
{
return 0;
}

static inline int vrf_master_ifindex(const struct net_device *dev)
{
return 0;
}

static inline u32 vrf_dev_table_rcu(const struct net_device *dev)
{
return 0;
Expand Down
5 changes: 3 additions & 2 deletions net/ipv4/fib_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <net/rtnetlink.h>
#include <net/xfrm.h>
#include <net/vrf.h>
#include <net/l3mdev.h>
#include <trace/events/fib.h>

#ifndef CONFIG_IP_MULTIPLE_TABLES
Expand Down Expand Up @@ -332,7 +333,7 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
bool dev_match;

fl4.flowi4_oif = 0;
fl4.flowi4_iif = vrf_master_ifindex_rcu(dev);
fl4.flowi4_iif = l3mdev_master_ifindex_rcu(dev);
if (!fl4.flowi4_iif)
fl4.flowi4_iif = oif ? : LOOPBACK_IFINDEX;
fl4.daddr = src;
Expand Down Expand Up @@ -366,7 +367,7 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
if (nh->nh_dev == dev) {
dev_match = true;
break;
} else if (vrf_master_ifindex_rcu(nh->nh_dev) == dev->ifindex) {
} else if (l3mdev_master_ifindex_rcu(nh->nh_dev) == dev->ifindex) {
dev_match = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
#include <net/xfrm.h>
#include <net/inet_common.h>
#include <net/ip_fib.h>
#include <net/vrf.h>
#include <net/l3mdev.h>

/*
* Build xmit assembly blocks
Expand Down Expand Up @@ -309,7 +309,7 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,

rc = false;
if (icmp_global_allow()) {
int vif = vrf_master_ifindex(dst->dev);
int vif = l3mdev_master_ifindex(dst->dev);
struct inet_peer *peer;

peer = inet_getpeer_v4(net->ipv4.peers, fl4->daddr, vif, 1);
Expand Down Expand Up @@ -427,7 +427,7 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
fl4.flowi4_mark = mark;
fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
fl4.flowi4_proto = IPPROTO_ICMP;
fl4.flowi4_oif = vrf_master_ifindex(skb->dev);
fl4.flowi4_oif = l3mdev_master_ifindex(skb->dev);
security_skb_classify_flow(skb, flowi4_to_flowi(&fl4));
rt = ip_route_output_key(net, &fl4);
if (IS_ERR(rt))
Expand Down Expand Up @@ -461,7 +461,7 @@ static struct rtable *icmp_route_lookup(struct net *net,
fl4->flowi4_proto = IPPROTO_ICMP;
fl4->fl4_icmp_type = type;
fl4->fl4_icmp_code = code;
fl4->flowi4_oif = vrf_master_ifindex(skb_in->dev);
fl4->flowi4_oif = l3mdev_master_ifindex(skb_in->dev);

security_skb_classify_flow(skb_in, flowi4_to_flowi(fl4));
rt = __ip_route_output_key(net, fl4);
Expand Down
6 changes: 3 additions & 3 deletions net/ipv4/ip_fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include <linux/inet.h>
#include <linux/netfilter_ipv4.h>
#include <net/inet_ecn.h>
#include <net/vrf.h>
#include <net/l3mdev.h>

/* NOTE. Logic of IP defragmentation is parallel to corresponding IPv6
* code now. If you change something here, _PLEASE_ update ipv6/reassembly.c
Expand Down Expand Up @@ -78,7 +78,7 @@ struct ipq {
u8 ecn; /* RFC3168 support */
u16 max_df_size; /* largest frag with DF set seen */
int iif;
int vif; /* VRF device index */
int vif; /* L3 master device index */
unsigned int rid;
struct inet_peer *peer;
};
Expand Down Expand Up @@ -657,7 +657,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
int ip_defrag(struct sk_buff *skb, u32 user)
{
struct net_device *dev = skb->dev ? : skb_dst(skb)->dev;
int vif = vrf_master_ifindex_rcu(dev);
int vif = l3mdev_master_ifindex_rcu(dev);
struct net *net = dev_net(dev);
struct ipq *qp;

Expand Down
7 changes: 4 additions & 3 deletions net/ipv4/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
#include <net/secure_seq.h>
#include <net/ip_tunnels.h>
#include <net/vrf.h>
#include <net/l3mdev.h>

#define RT_FL_TOS(oldflp4) \
((oldflp4)->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))
Expand Down Expand Up @@ -847,7 +848,7 @@ void ip_rt_send_redirect(struct sk_buff *skb)
return;
}
log_martians = IN_DEV_LOG_MARTIANS(in_dev);
vif = vrf_master_ifindex_rcu(rt->dst.dev);
vif = l3mdev_master_ifindex_rcu(rt->dst.dev);
rcu_read_unlock();

net = dev_net(rt->dst.dev);
Expand Down Expand Up @@ -941,7 +942,7 @@ static int ip_error(struct sk_buff *skb)
}

peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr,
vrf_master_ifindex(skb->dev), 1);
l3mdev_master_ifindex(skb->dev), 1);

send = true;
if (peer) {
Expand Down Expand Up @@ -1739,7 +1740,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
* Now we are ready to route packet.
*/
fl4.flowi4_oif = 0;
fl4.flowi4_iif = vrf_master_ifindex_rcu(dev) ? : dev->ifindex;
fl4.flowi4_iif = l3mdev_fib_oif_rcu(dev);
fl4.flowi4_mark = skb->mark;
fl4.flowi4_tos = tos;
fl4.flowi4_scope = RT_SCOPE_UNIVERSE;
Expand Down
8 changes: 3 additions & 5 deletions net/ipv4/xfrm4_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <net/dst.h>
#include <net/xfrm.h>
#include <net/ip.h>
#include <net/vrf.h>
#include <net/l3mdev.h>

static struct xfrm_policy_afinfo xfrm4_policy_afinfo;

Expand Down Expand Up @@ -111,10 +111,8 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
struct flowi4 *fl4 = &fl->u.ip4;
int oif = 0;

if (skb_dst(skb)) {
oif = vrf_master_ifindex(skb_dst(skb)->dev) ?
: skb_dst(skb)->dev->ifindex;
}
if (skb_dst(skb))
oif = l3mdev_fib_oif(skb_dst(skb)->dev);

memset(fl4, 0, sizeof(struct flowi4));
fl4->flowi4_mark = skb->mark;
Expand Down
8 changes: 3 additions & 5 deletions net/ipv6/xfrm6_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/ip6_route.h>
#include <net/vrf.h>
#include <net/l3mdev.h>
#if IS_ENABLED(CONFIG_IPV6_MIP6)
#include <net/mip6.h>
#endif
Expand Down Expand Up @@ -132,10 +132,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)

nexthdr = nh[nhoff];

if (skb_dst(skb)) {
oif = vrf_master_ifindex(skb_dst(skb)->dev) ?
: skb_dst(skb)->dev->ifindex;
}
if (skb_dst(skb))
oif = l3mdev_fib_oif(skb_dst(skb)->dev);

memset(fl6, 0, sizeof(struct flowi6));
fl6->flowi6_mark = skb->mark;
Expand Down

0 comments on commit 385add9

Please sign in to comment.