net: Replace vrf_dev_table and friends
[linux-2.6-block.git] / include / net / vrf.h
1 /*
2  * include/net/net_vrf.h - adds vrf dev structure definitions
3  * Copyright (c) 2015 Cumulus Networks
4  *
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.
9  */
10
11 #ifndef __LINUX_NET_VRF_H
12 #define __LINUX_NET_VRF_H
13
14 struct net_vrf_dev {
15         struct rcu_head         rcu;
16         int                     ifindex; /* ifindex of master dev */
17         u32                     tb_id;   /* table id for VRF */
18 };
19
20 struct slave {
21         struct list_head        list;
22         struct net_device       *dev;
23 };
24
25 struct slave_queue {
26         struct list_head        all_slaves;
27 };
28
29 struct net_vrf {
30         struct slave_queue      queue;
31         struct rtable           *rth;
32         u32                     tb_id;
33 };
34
35
36 #if IS_ENABLED(CONFIG_NET_VRF)
37 /* caller has already checked netif_is_l3_master(dev) */
38 static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
39 {
40         struct rtable *rth = ERR_PTR(-ENETUNREACH);
41         struct net_vrf *vrf = netdev_priv(dev);
42
43         if (vrf) {
44                 rth = vrf->rth;
45                 atomic_inc(&rth->dst.__refcnt);
46         }
47         return rth;
48 }
49
50 #else
51 static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
52 {
53         return ERR_PTR(-ENETUNREACH);
54 }
55 #endif
56
57 #endif /* __LINUX_NET_VRF_H */