2 * include/net/net_vrf.h - adds vrf dev structure definitions
3 * Copyright (c) 2015 Cumulus Networks
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 #ifndef __LINUX_NET_VRF_H
12 #define __LINUX_NET_VRF_H
16 int ifindex; /* ifindex of master dev */
17 u32 tb_id; /* table id for VRF */
21 struct list_head list;
22 struct net_device *dev;
26 struct list_head all_slaves;
30 struct slave_queue queue;
36 #if IS_ENABLED(CONFIG_NET_VRF)
37 /* called with rcu_read_lock() */
38 static inline int vrf_master_ifindex_rcu(const struct net_device *dev)
40 struct net_vrf_dev *vrf_ptr;
46 if (netif_is_vrf(dev)) {
47 ifindex = dev->ifindex;
49 vrf_ptr = rcu_dereference(dev->vrf_ptr);
51 ifindex = vrf_ptr->ifindex;
57 static inline int vrf_master_ifindex(const struct net_device *dev)
62 ifindex = vrf_master_ifindex_rcu(dev);
68 /* called with rcu_read_lock */
69 static inline u32 vrf_dev_table_rcu(const struct net_device *dev)
74 struct net_vrf_dev *vrf_ptr;
76 vrf_ptr = rcu_dereference(dev->vrf_ptr);
78 tb_id = vrf_ptr->tb_id;
83 static inline u32 vrf_dev_table(const struct net_device *dev)
88 tb_id = vrf_dev_table_rcu(dev);
94 static inline u32 vrf_dev_table_ifindex(struct net *net, int ifindex)
96 struct net_device *dev;
104 dev = dev_get_by_index_rcu(net, ifindex);
106 tb_id = vrf_dev_table_rcu(dev);
113 /* called with rtnl */
114 static inline u32 vrf_dev_table_rtnl(const struct net_device *dev)
119 struct net_vrf_dev *vrf_ptr;
121 vrf_ptr = rtnl_dereference(dev->vrf_ptr);
123 tb_id = vrf_ptr->tb_id;
128 /* caller has already checked netif_is_vrf(dev) */
129 static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
131 struct rtable *rth = ERR_PTR(-ENETUNREACH);
132 struct net_vrf *vrf = netdev_priv(dev);
136 atomic_inc(&rth->dst.__refcnt);
142 static inline int vrf_master_ifindex_rcu(const struct net_device *dev)
147 static inline int vrf_master_ifindex(const struct net_device *dev)
152 static inline u32 vrf_dev_table_rcu(const struct net_device *dev)
157 static inline u32 vrf_dev_table(const struct net_device *dev)
162 static inline u32 vrf_dev_table_ifindex(struct net *net, int ifindex)
167 static inline u32 vrf_dev_table_rtnl(const struct net_device *dev)
172 static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
174 return ERR_PTR(-ENETUNREACH);
178 #endif /* __LINUX_NET_VRF_H */