vrf.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef __LINUX_NET_VRF_H
  11. #define __LINUX_NET_VRF_H
  12. struct net_vrf_dev {
  13. struct rcu_head rcu;
  14. int ifindex; /* ifindex of master dev */
  15. u32 tb_id; /* table id for VRF */
  16. };
  17. struct slave {
  18. struct list_head list;
  19. struct net_device *dev;
  20. };
  21. struct slave_queue {
  22. struct list_head all_slaves;
  23. };
  24. struct net_vrf {
  25. struct slave_queue queue;
  26. struct rtable *rth;
  27. u32 tb_id;
  28. };
  29. #if IS_ENABLED(CONFIG_NET_VRF)
  30. /* caller has already checked netif_is_l3_master(dev) */
  31. static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
  32. {
  33. struct rtable *rth = ERR_PTR(-ENETUNREACH);
  34. struct net_vrf *vrf = netdev_priv(dev);
  35. if (vrf) {
  36. rth = vrf->rth;
  37. atomic_inc(&rth->dst.__refcnt);
  38. }
  39. return rth;
  40. }
  41. #else
  42. static inline struct rtable *vrf_dev_get_rth(const struct net_device *dev)
  43. {
  44. return ERR_PTR(-ENETUNREACH);
  45. }
  46. #endif
  47. #endif /* __LINUX_NET_VRF_H */