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 #include <net/fib_rules.h>
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_link_scope_lookup: IPv6 lookup for linklocal and mcast destinations
30 u32 (*l3mdev_fib_table)(const struct net_device *dev);
31 struct sk_buff * (*l3mdev_l3_rcv)(struct net_device *dev,
32 struct sk_buff *skb, u16 proto);
33 struct sk_buff * (*l3mdev_l3_out)(struct net_device *dev,
34 struct sock *sk, struct sk_buff *skb,
38 struct dst_entry * (*l3mdev_link_scope_lookup)(const struct net_device *dev,
42 #ifdef CONFIG_NET_L3_MASTER_DEV
44 int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
45 struct fib_lookup_arg *arg);
47 void l3mdev_update_flow(struct net *net, struct flowi *fl);
49 int l3mdev_master_ifindex_rcu(const struct net_device *dev);
50 static inline int l3mdev_master_ifindex(struct net_device *dev)
55 ifindex = l3mdev_master_ifindex_rcu(dev);
61 static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
63 struct net_device *dev;
66 if (likely(ifindex)) {
69 dev = dev_get_by_index_rcu(net, ifindex);
71 rc = l3mdev_master_ifindex_rcu(dev);
80 struct net_device *l3mdev_master_dev_rcu(const struct net_device *_dev)
82 /* netdev_master_upper_dev_get_rcu calls
83 * list_first_or_null_rcu to walk the upper dev list.
84 * list_first_or_null_rcu does not handle a const arg. We aren't
85 * making changes, just want the master device from that list so
86 * typecast to remove the const
88 struct net_device *dev = (struct net_device *)_dev;
89 struct net_device *master;
94 if (netif_is_l3_master(dev))
96 else if (netif_is_l3_slave(dev))
97 master = netdev_master_upper_dev_get_rcu(dev);
104 u32 l3mdev_fib_table_rcu(const struct net_device *dev);
105 u32 l3mdev_fib_table_by_index(struct net *net, int ifindex);
106 static inline u32 l3mdev_fib_table(const struct net_device *dev)
111 tb_id = l3mdev_fib_table_rcu(dev);
117 struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6);
120 struct sk_buff *l3mdev_l3_rcv(struct sk_buff *skb, u16 proto)
122 struct net_device *master = NULL;
124 if (netif_is_l3_slave(skb->dev))
125 master = netdev_master_upper_dev_get_rcu(skb->dev);
126 else if (netif_is_l3_master(skb->dev))
129 if (master && master->l3mdev_ops->l3mdev_l3_rcv)
130 skb = master->l3mdev_ops->l3mdev_l3_rcv(master, skb, proto);
136 struct sk_buff *l3mdev_ip_rcv(struct sk_buff *skb)
138 return l3mdev_l3_rcv(skb, AF_INET);
142 struct sk_buff *l3mdev_ip6_rcv(struct sk_buff *skb)
144 return l3mdev_l3_rcv(skb, AF_INET6);
148 struct sk_buff *l3mdev_l3_out(struct sock *sk, struct sk_buff *skb, u16 proto)
150 struct net_device *dev = skb_dst(skb)->dev;
152 if (netif_is_l3_slave(dev)) {
153 struct net_device *master;
155 master = netdev_master_upper_dev_get_rcu(dev);
156 if (master && master->l3mdev_ops->l3mdev_l3_out)
157 skb = master->l3mdev_ops->l3mdev_l3_out(master, sk,
165 struct sk_buff *l3mdev_ip_out(struct sock *sk, struct sk_buff *skb)
167 return l3mdev_l3_out(sk, skb, AF_INET);
171 struct sk_buff *l3mdev_ip6_out(struct sock *sk, struct sk_buff *skb)
173 return l3mdev_l3_out(sk, skb, AF_INET6);
177 static inline int l3mdev_master_ifindex_rcu(const struct net_device *dev)
181 static inline int l3mdev_master_ifindex(struct net_device *dev)
186 static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
192 struct net_device *l3mdev_master_dev_rcu(const struct net_device *dev)
197 static inline u32 l3mdev_fib_table_rcu(const struct net_device *dev)
201 static inline u32 l3mdev_fib_table(const struct net_device *dev)
205 static inline u32 l3mdev_fib_table_by_index(struct net *net, int ifindex)
211 struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6)
217 struct sk_buff *l3mdev_ip_rcv(struct sk_buff *skb)
223 struct sk_buff *l3mdev_ip6_rcv(struct sk_buff *skb)
229 struct sk_buff *l3mdev_ip_out(struct sock *sk, struct sk_buff *skb)
235 struct sk_buff *l3mdev_ip6_out(struct sock *sk, struct sk_buff *skb)
241 int l3mdev_fib_rule_match(struct net *net, struct flowi *fl,
242 struct fib_lookup_arg *arg)
247 void l3mdev_update_flow(struct net *net, struct flowi *fl)
252 #endif /* _NET_L3MDEV_H_ */