net: ipv6: Remove l3mdev_get_saddr6
[linux-2.6/btrfs-unstable.git] / include / net / l3mdev.h
bloba5e506eb51de59682010740eefae10f66e44a869
1 /*
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_
14 #include <net/dst.h>
15 #include <net/fib_rules.h>
17 /**
18 * struct l3mdev_ops - l3mdev operations
20 * @l3mdev_fib_table: Get FIB table id to use for lookups
22 * @l3mdev_l3_rcv: Hook in L3 receive path
24 * @l3mdev_l3_out: Hook in L3 output path
26 * @l3mdev_get_rtable: Get cached IPv4 rtable (dst_entry) for device
28 * @l3mdev_link_scope_lookup: IPv6 lookup for linklocal and mcast destinations
31 struct l3mdev_ops {
32 u32 (*l3mdev_fib_table)(const struct net_device *dev);
33 struct sk_buff * (*l3mdev_l3_rcv)(struct net_device *dev,
34 struct sk_buff *skb, u16 proto);
35 struct sk_buff * (*l3mdev_l3_out)(struct net_device *dev,
36 struct sock *sk, struct sk_buff *skb,
37 u16 proto);
39 /* IPv4 ops */
40 struct rtable * (*l3mdev_get_rtable)(const struct net_device *dev,
41 const struct flowi4 *fl4);
43 /* IPv6 ops */
44 struct dst_entry * (*l3mdev_link_scope_lookup)(const struct net_device *dev,
45 struct flowi6 *fl6);
48 #ifdef CONFIG_NET_L3_MASTER_DEV
50 int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
51 struct fib_lookup_arg *arg);
53 void l3mdev_update_flow(struct net *net, struct flowi *fl);
55 int l3mdev_master_ifindex_rcu(const struct net_device *dev);
56 static inline int l3mdev_master_ifindex(struct net_device *dev)
58 int ifindex;
60 rcu_read_lock();
61 ifindex = l3mdev_master_ifindex_rcu(dev);
62 rcu_read_unlock();
64 return ifindex;
67 static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
69 struct net_device *dev;
70 int rc = 0;
72 if (likely(ifindex)) {
73 rcu_read_lock();
75 dev = dev_get_by_index_rcu(net, ifindex);
76 if (dev)
77 rc = l3mdev_master_ifindex_rcu(dev);
79 rcu_read_unlock();
82 return rc;
85 static inline
86 struct net_device *l3mdev_master_dev_rcu(const struct net_device *_dev)
88 /* netdev_master_upper_dev_get_rcu calls
89 * list_first_or_null_rcu to walk the upper dev list.
90 * list_first_or_null_rcu does not handle a const arg. We aren't
91 * making changes, just want the master device from that list so
92 * typecast to remove the const
94 struct net_device *dev = (struct net_device *)_dev;
95 struct net_device *master;
97 if (!dev)
98 return NULL;
100 if (netif_is_l3_master(dev))
101 master = dev;
102 else if (netif_is_l3_slave(dev))
103 master = netdev_master_upper_dev_get_rcu(dev);
104 else
105 master = NULL;
107 return master;
110 /* get index of an interface to use for FIB lookups. For devices
111 * enslaved to an L3 master device FIB lookups are based on the
112 * master index
114 static inline int l3mdev_fib_oif_rcu(struct net_device *dev)
116 return l3mdev_master_ifindex_rcu(dev) ? : dev->ifindex;
119 static inline int l3mdev_fib_oif(struct net_device *dev)
121 int oif;
123 rcu_read_lock();
124 oif = l3mdev_fib_oif_rcu(dev);
125 rcu_read_unlock();
127 return oif;
130 u32 l3mdev_fib_table_rcu(const struct net_device *dev);
131 u32 l3mdev_fib_table_by_index(struct net *net, int ifindex);
132 static inline u32 l3mdev_fib_table(const struct net_device *dev)
134 u32 tb_id;
136 rcu_read_lock();
137 tb_id = l3mdev_fib_table_rcu(dev);
138 rcu_read_unlock();
140 return tb_id;
143 static inline struct rtable *l3mdev_get_rtable(const struct net_device *dev,
144 const struct flowi4 *fl4)
146 if (netif_is_l3_master(dev) && dev->l3mdev_ops->l3mdev_get_rtable)
147 return dev->l3mdev_ops->l3mdev_get_rtable(dev, fl4);
149 return NULL;
152 static inline bool netif_index_is_l3_master(struct net *net, int ifindex)
154 struct net_device *dev;
155 bool rc = false;
157 if (ifindex == 0)
158 return false;
160 rcu_read_lock();
162 dev = dev_get_by_index_rcu(net, ifindex);
163 if (dev)
164 rc = netif_is_l3_master(dev);
166 rcu_read_unlock();
168 return rc;
171 struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6);
173 static inline
174 struct sk_buff *l3mdev_l3_rcv(struct sk_buff *skb, u16 proto)
176 struct net_device *master = NULL;
178 if (netif_is_l3_slave(skb->dev))
179 master = netdev_master_upper_dev_get_rcu(skb->dev);
180 else if (netif_is_l3_master(skb->dev))
181 master = skb->dev;
183 if (master && master->l3mdev_ops->l3mdev_l3_rcv)
184 skb = master->l3mdev_ops->l3mdev_l3_rcv(master, skb, proto);
186 return skb;
189 static inline
190 struct sk_buff *l3mdev_ip_rcv(struct sk_buff *skb)
192 return l3mdev_l3_rcv(skb, AF_INET);
195 static inline
196 struct sk_buff *l3mdev_ip6_rcv(struct sk_buff *skb)
198 return l3mdev_l3_rcv(skb, AF_INET6);
201 static inline
202 struct sk_buff *l3mdev_l3_out(struct sock *sk, struct sk_buff *skb, u16 proto)
204 struct net_device *dev = skb_dst(skb)->dev;
206 if (netif_is_l3_slave(dev)) {
207 struct net_device *master;
209 master = netdev_master_upper_dev_get_rcu(dev);
210 if (master && master->l3mdev_ops->l3mdev_l3_out)
211 skb = master->l3mdev_ops->l3mdev_l3_out(master, sk,
212 skb, proto);
215 return skb;
218 static inline
219 struct sk_buff *l3mdev_ip_out(struct sock *sk, struct sk_buff *skb)
221 return l3mdev_l3_out(sk, skb, AF_INET);
224 static inline
225 struct sk_buff *l3mdev_ip6_out(struct sock *sk, struct sk_buff *skb)
227 return l3mdev_l3_out(sk, skb, AF_INET6);
229 #else
231 static inline int l3mdev_master_ifindex_rcu(const struct net_device *dev)
233 return 0;
235 static inline int l3mdev_master_ifindex(struct net_device *dev)
237 return 0;
240 static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
242 return 0;
245 static inline
246 struct net_device *l3mdev_master_dev_rcu(const struct net_device *dev)
248 return NULL;
251 static inline int l3mdev_fib_oif_rcu(struct net_device *dev)
253 return dev ? dev->ifindex : 0;
255 static inline int l3mdev_fib_oif(struct net_device *dev)
257 return dev ? dev->ifindex : 0;
260 static inline u32 l3mdev_fib_table_rcu(const struct net_device *dev)
262 return 0;
264 static inline u32 l3mdev_fib_table(const struct net_device *dev)
266 return 0;
268 static inline u32 l3mdev_fib_table_by_index(struct net *net, int ifindex)
270 return 0;
273 static inline struct rtable *l3mdev_get_rtable(const struct net_device *dev,
274 const struct flowi4 *fl4)
276 return NULL;
279 static inline bool netif_index_is_l3_master(struct net *net, int ifindex)
281 return false;
284 static inline
285 struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6)
287 return NULL;
290 static inline
291 struct sk_buff *l3mdev_ip_rcv(struct sk_buff *skb)
293 return skb;
296 static inline
297 struct sk_buff *l3mdev_ip6_rcv(struct sk_buff *skb)
299 return skb;
302 static inline
303 struct sk_buff *l3mdev_ip_out(struct sock *sk, struct sk_buff *skb)
305 return skb;
308 static inline
309 struct sk_buff *l3mdev_ip6_out(struct sock *sk, struct sk_buff *skb)
311 return skb;
314 static inline
315 int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
316 struct fib_lookup_arg *arg)
318 return 1;
320 static inline
321 void l3mdev_update_flow(struct net *net, struct flowi *fl)
324 #endif
326 #endif /* _NET_L3MDEV_H_ */