Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at ee9dce44362b2d8132c32964656ab6dff7dfbc6a 364 lines 7.8 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * include/net/l3mdev.h - L3 master device API 4 * Copyright (c) 2015 Cumulus Networks 5 * Copyright (c) 2015 David Ahern <dsa@cumulusnetworks.com> 6 */ 7#ifndef _NET_L3MDEV_H_ 8#define _NET_L3MDEV_H_ 9 10#include <net/dst.h> 11#include <net/fib_rules.h> 12 13enum l3mdev_type { 14 L3MDEV_TYPE_UNSPEC, 15 L3MDEV_TYPE_VRF, 16 __L3MDEV_TYPE_MAX 17}; 18 19#define L3MDEV_TYPE_MAX (__L3MDEV_TYPE_MAX - 1) 20 21typedef int (*lookup_by_table_id_t)(struct net *net, u32 table_d); 22 23/** 24 * struct l3mdev_ops - l3mdev operations 25 * 26 * @l3mdev_fib_table: Get FIB table id to use for lookups 27 * 28 * @l3mdev_l3_rcv: Hook in L3 receive path 29 * 30 * @l3mdev_l3_out: Hook in L3 output path 31 * 32 * @l3mdev_link_scope_lookup: IPv6 lookup for linklocal and mcast destinations 33 */ 34 35struct l3mdev_ops { 36 u32 (*l3mdev_fib_table)(const struct net_device *dev); 37 struct sk_buff * (*l3mdev_l3_rcv)(struct net_device *dev, 38 struct sk_buff *skb, u16 proto); 39 struct sk_buff * (*l3mdev_l3_out)(struct net_device *dev, 40 struct sock *sk, struct sk_buff *skb, 41 u16 proto); 42 43 /* IPv6 ops */ 44 struct dst_entry * (*l3mdev_link_scope_lookup)(const struct net_device *dev, 45 struct flowi6 *fl6); 46}; 47 48#ifdef CONFIG_NET_L3_MASTER_DEV 49 50int l3mdev_table_lookup_register(enum l3mdev_type l3type, 51 lookup_by_table_id_t fn); 52 53void l3mdev_table_lookup_unregister(enum l3mdev_type l3type, 54 lookup_by_table_id_t fn); 55 56int l3mdev_ifindex_lookup_by_table_id(enum l3mdev_type l3type, struct net *net, 57 u32 table_id); 58 59int l3mdev_fib_rule_match(struct net *net, struct flowi *fl, 60 struct fib_lookup_arg *arg); 61 62static inline 63bool l3mdev_fib_rule_iif_match(const struct flowi *fl, int iifindex) 64{ 65 return !(fl->flowi_flags & FLOWI_FLAG_L3MDEV_OIF) && 66 fl->flowi_l3mdev == iifindex; 67} 68 69static inline 70bool l3mdev_fib_rule_oif_match(const struct flowi *fl, int oifindex) 71{ 72 return fl->flowi_flags & FLOWI_FLAG_L3MDEV_OIF && 73 fl->flowi_l3mdev == oifindex; 74} 75 76void l3mdev_update_flow(struct net *net, struct flowi *fl); 77 78int l3mdev_master_ifindex_rcu(const struct net_device *dev); 79static inline int l3mdev_master_ifindex(struct net_device *dev) 80{ 81 int ifindex; 82 83 rcu_read_lock(); 84 ifindex = l3mdev_master_ifindex_rcu(dev); 85 rcu_read_unlock(); 86 87 return ifindex; 88} 89 90static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex) 91{ 92 struct net_device *dev; 93 int rc = 0; 94 95 if (ifindex) { 96 rcu_read_lock(); 97 98 dev = dev_get_by_index_rcu(net, ifindex); 99 if (dev) 100 rc = l3mdev_master_ifindex_rcu(dev); 101 102 rcu_read_unlock(); 103 } 104 105 return rc; 106} 107 108static inline 109struct net_device *l3mdev_master_dev_rcu(const struct net_device *_dev) 110{ 111 /* netdev_master_upper_dev_get_rcu calls 112 * list_first_or_null_rcu to walk the upper dev list. 113 * list_first_or_null_rcu does not handle a const arg. We aren't 114 * making changes, just want the master device from that list so 115 * typecast to remove the const 116 */ 117 struct net_device *dev = (struct net_device *)_dev; 118 struct net_device *master; 119 120 if (!dev) 121 return NULL; 122 123 if (netif_is_l3_master(dev)) 124 master = dev; 125 else if (netif_is_l3_slave(dev)) 126 master = netdev_master_upper_dev_get_rcu(dev); 127 else 128 master = NULL; 129 130 return master; 131} 132 133int l3mdev_master_upper_ifindex_by_index_rcu(struct net *net, int ifindex); 134static inline 135int l3mdev_master_upper_ifindex_by_index(struct net *net, int ifindex) 136{ 137 rcu_read_lock(); 138 ifindex = l3mdev_master_upper_ifindex_by_index_rcu(net, ifindex); 139 rcu_read_unlock(); 140 141 return ifindex; 142} 143 144u32 l3mdev_fib_table_rcu(const struct net_device *dev); 145u32 l3mdev_fib_table_by_index(struct net *net, int ifindex); 146static inline u32 l3mdev_fib_table(const struct net_device *dev) 147{ 148 u32 tb_id; 149 150 rcu_read_lock(); 151 tb_id = l3mdev_fib_table_rcu(dev); 152 rcu_read_unlock(); 153 154 return tb_id; 155} 156 157static inline bool netif_index_is_l3_master(struct net *net, int ifindex) 158{ 159 struct net_device *dev; 160 bool rc = false; 161 162 if (ifindex == 0) 163 return false; 164 165 rcu_read_lock(); 166 167 dev = dev_get_by_index_rcu(net, ifindex); 168 if (dev) 169 rc = netif_is_l3_master(dev); 170 171 rcu_read_unlock(); 172 173 return rc; 174} 175 176struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6); 177 178static inline 179struct sk_buff *l3mdev_l3_rcv(struct sk_buff *skb, u16 proto) 180{ 181 struct net_device *master = NULL; 182 183 if (netif_is_l3_slave(skb->dev)) 184 master = netdev_master_upper_dev_get_rcu(skb->dev); 185 else if (netif_is_l3_master(skb->dev) || 186 netif_has_l3_rx_handler(skb->dev)) 187 master = skb->dev; 188 189 if (master && master->l3mdev_ops->l3mdev_l3_rcv) 190 skb = master->l3mdev_ops->l3mdev_l3_rcv(master, skb, proto); 191 192 return skb; 193} 194 195static inline 196struct sk_buff *l3mdev_ip_rcv(struct sk_buff *skb) 197{ 198 return l3mdev_l3_rcv(skb, AF_INET); 199} 200 201static inline 202struct sk_buff *l3mdev_ip6_rcv(struct sk_buff *skb) 203{ 204 return l3mdev_l3_rcv(skb, AF_INET6); 205} 206 207static inline 208struct sk_buff *l3mdev_l3_out(struct sock *sk, struct sk_buff *skb, u16 proto) 209{ 210 struct net_device *dev; 211 212 rcu_read_lock(); 213 dev = skb_dst_dev_rcu(skb); 214 if (netif_is_l3_slave(dev)) { 215 struct net_device *master; 216 217 master = netdev_master_upper_dev_get_rcu(dev); 218 if (master && master->l3mdev_ops->l3mdev_l3_out) 219 skb = master->l3mdev_ops->l3mdev_l3_out(master, sk, 220 skb, proto); 221 } 222 rcu_read_unlock(); 223 224 return skb; 225} 226 227static inline 228struct sk_buff *l3mdev_ip_out(struct sock *sk, struct sk_buff *skb) 229{ 230 return l3mdev_l3_out(sk, skb, AF_INET); 231} 232 233static inline 234struct sk_buff *l3mdev_ip6_out(struct sock *sk, struct sk_buff *skb) 235{ 236 return l3mdev_l3_out(sk, skb, AF_INET6); 237} 238#else 239 240static inline int l3mdev_master_ifindex_rcu(const struct net_device *dev) 241{ 242 return 0; 243} 244static inline int l3mdev_master_ifindex(struct net_device *dev) 245{ 246 return 0; 247} 248 249static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex) 250{ 251 return 0; 252} 253 254static inline 255int l3mdev_master_upper_ifindex_by_index_rcu(struct net *net, int ifindex) 256{ 257 return 0; 258} 259static inline 260int l3mdev_master_upper_ifindex_by_index(struct net *net, int ifindex) 261{ 262 return 0; 263} 264 265static inline 266struct net_device *l3mdev_master_dev_rcu(const struct net_device *dev) 267{ 268 return NULL; 269} 270 271static inline u32 l3mdev_fib_table_rcu(const struct net_device *dev) 272{ 273 return 0; 274} 275static inline u32 l3mdev_fib_table(const struct net_device *dev) 276{ 277 return 0; 278} 279static inline u32 l3mdev_fib_table_by_index(struct net *net, int ifindex) 280{ 281 return 0; 282} 283 284static inline bool netif_index_is_l3_master(struct net *net, int ifindex) 285{ 286 return false; 287} 288 289static inline 290struct dst_entry *l3mdev_link_scope_lookup(struct net *net, struct flowi6 *fl6) 291{ 292 return NULL; 293} 294 295static inline 296struct sk_buff *l3mdev_ip_rcv(struct sk_buff *skb) 297{ 298 return skb; 299} 300 301static inline 302struct sk_buff *l3mdev_ip6_rcv(struct sk_buff *skb) 303{ 304 return skb; 305} 306 307static inline 308struct sk_buff *l3mdev_ip_out(struct sock *sk, struct sk_buff *skb) 309{ 310 return skb; 311} 312 313static inline 314struct sk_buff *l3mdev_ip6_out(struct sock *sk, struct sk_buff *skb) 315{ 316 return skb; 317} 318 319static inline 320int l3mdev_table_lookup_register(enum l3mdev_type l3type, 321 lookup_by_table_id_t fn) 322{ 323 return -EOPNOTSUPP; 324} 325 326static inline 327void l3mdev_table_lookup_unregister(enum l3mdev_type l3type, 328 lookup_by_table_id_t fn) 329{ 330} 331 332static inline 333int l3mdev_ifindex_lookup_by_table_id(enum l3mdev_type l3type, struct net *net, 334 u32 table_id) 335{ 336 return -ENODEV; 337} 338 339static inline 340int l3mdev_fib_rule_match(struct net *net, struct flowi *fl, 341 struct fib_lookup_arg *arg) 342{ 343 return 1; 344} 345 346static inline 347bool l3mdev_fib_rule_iif_match(const struct flowi *fl, int iifindex) 348{ 349 return false; 350} 351 352static inline 353bool l3mdev_fib_rule_oif_match(const struct flowi *fl, int oifindex) 354{ 355 return false; 356} 357 358static inline 359void l3mdev_update_flow(struct net *net, struct flowi *fl) 360{ 361} 362#endif 363 364#endif /* _NET_L3MDEV_H_ */