2 * include/net/l3mdev.h - L3 master device API
3 * Copyright (c) 2015 Cumulus Networks
4 * Copyright (c) 2015 David Ahern <dsa@cumulusnetworks.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 #ifndef _NET_L3MDEV_H_
12 #define _NET_L3MDEV_H_
15 * struct l3mdev_ops - l3mdev operations
17 * @l3mdev_fib_table: Get FIB table id to use for lookups
19 * @l3mdev_get_rtable: Get cached IPv4 rtable (dst_entry) for device
21 * @l3mdev_get_saddr: Get source address for a flow
23 * @l3mdev_get_rt6_dst: Get cached IPv6 rt6_info (dst_entry) for device
27 u32 (*l3mdev_fib_table)(const struct net_device *dev);
30 struct rtable * (*l3mdev_get_rtable)(const struct net_device *dev,
31 const struct flowi4 *fl4);
32 int (*l3mdev_get_saddr)(struct net_device *dev,
36 struct dst_entry * (*l3mdev_get_rt6_dst)(const struct net_device *dev,
37 const struct flowi6 *fl6);
40 #ifdef CONFIG_NET_L3_MASTER_DEV
42 int l3mdev_master_ifindex_rcu(struct net_device *dev);
43 static inline int l3mdev_master_ifindex(struct net_device *dev)
48 ifindex = l3mdev_master_ifindex_rcu(dev);
54 static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
56 struct net_device *dev;
59 if (likely(ifindex)) {
62 dev = dev_get_by_index_rcu(net, ifindex);
64 rc = l3mdev_master_ifindex_rcu(dev);
72 /* get index of an interface to use for FIB lookups. For devices
73 * enslaved to an L3 master device FIB lookups are based on the
76 static inline int l3mdev_fib_oif_rcu(struct net_device *dev)
78 return l3mdev_master_ifindex_rcu(dev) ? : dev->ifindex;
81 static inline int l3mdev_fib_oif(struct net_device *dev)
86 oif = l3mdev_fib_oif_rcu(dev);
92 u32 l3mdev_fib_table_rcu(const struct net_device *dev);
93 u32 l3mdev_fib_table_by_index(struct net *net, int ifindex);
94 static inline u32 l3mdev_fib_table(const struct net_device *dev)
99 tb_id = l3mdev_fib_table_rcu(dev);
105 static inline struct rtable *l3mdev_get_rtable(const struct net_device *dev,
106 const struct flowi4 *fl4)
108 if (netif_is_l3_master(dev) && dev->l3mdev_ops->l3mdev_get_rtable)
109 return dev->l3mdev_ops->l3mdev_get_rtable(dev, fl4);
114 static inline bool netif_index_is_l3_master(struct net *net, int ifindex)
116 struct net_device *dev;
124 dev = dev_get_by_index_rcu(net, ifindex);
126 rc = netif_is_l3_master(dev);
133 static inline int l3mdev_get_saddr(struct net *net, int ifindex,
136 struct net_device *dev;
143 dev = dev_get_by_index_rcu(net, ifindex);
144 if (dev && netif_is_l3_master(dev) &&
145 dev->l3mdev_ops->l3mdev_get_saddr) {
146 rc = dev->l3mdev_ops->l3mdev_get_saddr(dev, fl4);
155 static inline struct dst_entry *l3mdev_get_rt6_dst(const struct net_device *dev,
156 const struct flowi6 *fl6)
158 if (netif_is_l3_master(dev) && dev->l3mdev_ops->l3mdev_get_rt6_dst)
159 return dev->l3mdev_ops->l3mdev_get_rt6_dst(dev, fl6);
165 struct dst_entry *l3mdev_rt6_dst_by_oif(struct net *net,
166 const struct flowi6 *fl6)
168 struct dst_entry *dst = NULL;
169 struct net_device *dev;
171 dev = dev_get_by_index(net, fl6->flowi6_oif);
173 dst = l3mdev_get_rt6_dst(dev, fl6);
182 static inline int l3mdev_master_ifindex_rcu(struct net_device *dev)
186 static inline int l3mdev_master_ifindex(struct net_device *dev)
191 static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
196 static inline int l3mdev_fib_oif_rcu(struct net_device *dev)
198 return dev ? dev->ifindex : 0;
200 static inline int l3mdev_fib_oif(struct net_device *dev)
202 return dev ? dev->ifindex : 0;
205 static inline u32 l3mdev_fib_table_rcu(const struct net_device *dev)
209 static inline u32 l3mdev_fib_table(const struct net_device *dev)
213 static inline u32 l3mdev_fib_table_by_index(struct net *net, int ifindex)
218 static inline struct rtable *l3mdev_get_rtable(const struct net_device *dev,
219 const struct flowi4 *fl4)
224 static inline bool netif_index_is_l3_master(struct net *net, int ifindex)
229 static inline int l3mdev_get_saddr(struct net *net, int ifindex,
236 struct dst_entry *l3mdev_get_rt6_dst(const struct net_device *dev,
237 const struct flowi6 *fl6)
242 struct dst_entry *l3mdev_rt6_dst_by_oif(struct net *net,
243 const struct flowi6 *fl6)
249 #endif /* _NET_L3MDEV_H_ */