rtnetlink.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef __LINUX_RTNETLINK_H
  2. #define __LINUX_RTNETLINK_H
  3. #include <linux/mutex.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/wait.h>
  6. #include <uapi/linux/rtnetlink.h>
  7. extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo);
  8. extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid);
  9. extern void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid,
  10. u32 group, struct nlmsghdr *nlh, gfp_t flags);
  11. extern void rtnl_set_sk_err(struct net *net, u32 group, int error);
  12. extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
  13. extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst,
  14. u32 id, long expires, u32 error);
  15. void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags);
  16. struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
  17. unsigned change, gfp_t flags);
  18. void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev,
  19. gfp_t flags);
  20. /* RTNL is used as a global lock for all changes to network configuration */
  21. extern void rtnl_lock(void);
  22. extern void rtnl_unlock(void);
  23. extern int rtnl_trylock(void);
  24. extern int rtnl_is_locked(void);
  25. extern wait_queue_head_t netdev_unregistering_wq;
  26. extern struct mutex net_mutex;
  27. #ifdef CONFIG_PROVE_LOCKING
  28. extern bool lockdep_rtnl_is_held(void);
  29. #else
  30. static inline bool lockdep_rtnl_is_held(void)
  31. {
  32. return true;
  33. }
  34. #endif /* #ifdef CONFIG_PROVE_LOCKING */
  35. /**
  36. * rcu_dereference_rtnl - rcu_dereference with debug checking
  37. * @p: The pointer to read, prior to dereferencing
  38. *
  39. * Do an rcu_dereference(p), but check caller either holds rcu_read_lock()
  40. * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference()
  41. */
  42. #define rcu_dereference_rtnl(p) \
  43. rcu_dereference_check(p, lockdep_rtnl_is_held())
  44. /**
  45. * rcu_dereference_bh_rtnl - rcu_dereference_bh with debug checking
  46. * @p: The pointer to read, prior to dereference
  47. *
  48. * Do an rcu_dereference_bh(p), but check caller either holds rcu_read_lock_bh()
  49. * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference_bh()
  50. */
  51. #define rcu_dereference_bh_rtnl(p) \
  52. rcu_dereference_bh_check(p, lockdep_rtnl_is_held())
  53. /**
  54. * rtnl_dereference - fetch RCU pointer when updates are prevented by RTNL
  55. * @p: The pointer to read, prior to dereferencing
  56. *
  57. * Return the value of the specified RCU-protected pointer, but omit
  58. * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because
  59. * caller holds RTNL.
  60. */
  61. #define rtnl_dereference(p) \
  62. rcu_dereference_protected(p, lockdep_rtnl_is_held())
  63. static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
  64. {
  65. return rtnl_dereference(dev->ingress_queue);
  66. }
  67. struct netdev_queue *dev_ingress_queue_create(struct net_device *dev);
  68. #ifdef CONFIG_NET_INGRESS
  69. void net_inc_ingress_queue(void);
  70. void net_dec_ingress_queue(void);
  71. #endif
  72. extern void rtnetlink_init(void);
  73. extern void __rtnl_unlock(void);
  74. #define ASSERT_RTNL() do { \
  75. if (unlikely(!rtnl_is_locked())) { \
  76. printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
  77. __FILE__, __LINE__); \
  78. dump_stack(); \
  79. } \
  80. } while(0)
  81. extern int ndo_dflt_fdb_dump(struct sk_buff *skb,
  82. struct netlink_callback *cb,
  83. struct net_device *dev,
  84. struct net_device *filter_dev,
  85. int idx);
  86. extern int ndo_dflt_fdb_add(struct ndmsg *ndm,
  87. struct nlattr *tb[],
  88. struct net_device *dev,
  89. const unsigned char *addr,
  90. u16 vid,
  91. u16 flags);
  92. extern int ndo_dflt_fdb_del(struct ndmsg *ndm,
  93. struct nlattr *tb[],
  94. struct net_device *dev,
  95. const unsigned char *addr,
  96. u16 vid);
  97. extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  98. struct net_device *dev, u16 mode,
  99. u32 flags, u32 mask, int nlflags,
  100. u32 filter_mask,
  101. int (*vlan_fill)(struct sk_buff *skb,
  102. struct net_device *dev,
  103. u32 filter_mask));
  104. #endif /* __LINUX_RTNETLINK_H */