rtnetlink.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef __NET_RTNETLINK_H
  2. #define __NET_RTNETLINK_H
  3. #include <linux/rtnetlink.h>
  4. #include <net/netlink.h>
  5. typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
  6. struct netlink_ext_ack *);
  7. typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
  8. typedef u16 (*rtnl_calcit_func)(struct sk_buff *, struct nlmsghdr *);
  9. int __rtnl_register(int protocol, int msgtype,
  10. rtnl_doit_func, rtnl_dumpit_func, rtnl_calcit_func);
  11. void rtnl_register(int protocol, int msgtype,
  12. rtnl_doit_func, rtnl_dumpit_func, rtnl_calcit_func);
  13. int rtnl_unregister(int protocol, int msgtype);
  14. void rtnl_unregister_all(int protocol);
  15. static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
  16. {
  17. if (nlmsg_len(nlh) >= sizeof(struct rtgenmsg))
  18. return ((struct rtgenmsg *) nlmsg_data(nlh))->rtgen_family;
  19. else
  20. return AF_UNSPEC;
  21. }
  22. /**
  23. * struct rtnl_link_ops - rtnetlink link operations
  24. *
  25. * @list: Used internally
  26. * @kind: Identifier
  27. * @maxtype: Highest device specific netlink attribute number
  28. * @policy: Netlink policy for device specific attribute validation
  29. * @validate: Optional validation function for netlink/changelink parameters
  30. * @priv_size: sizeof net_device private space
  31. * @setup: net_device setup function
  32. * @newlink: Function for configuring and registering a new device
  33. * @changelink: Function for changing parameters of an existing device
  34. * @dellink: Function to remove a device
  35. * @get_size: Function to calculate required room for dumping device
  36. * specific netlink attributes
  37. * @fill_info: Function to dump device specific netlink attributes
  38. * @get_xstats_size: Function to calculate required room for dumping device
  39. * specific statistics
  40. * @fill_xstats: Function to dump device specific statistics
  41. * @get_num_tx_queues: Function to determine number of transmit queues
  42. * to create when creating a new device.
  43. * @get_num_rx_queues: Function to determine number of receive queues
  44. * to create when creating a new device.
  45. * @get_link_net: Function to get the i/o netns of the device
  46. * @get_linkxstats_size: Function to calculate the required room for
  47. * dumping device-specific extended link stats
  48. * @fill_linkxstats: Function to dump device-specific extended link stats
  49. */
  50. struct rtnl_link_ops {
  51. struct list_head list;
  52. const char *kind;
  53. size_t priv_size;
  54. void (*setup)(struct net_device *dev);
  55. int maxtype;
  56. const struct nla_policy *policy;
  57. int (*validate)(struct nlattr *tb[],
  58. struct nlattr *data[]);
  59. int (*newlink)(struct net *src_net,
  60. struct net_device *dev,
  61. struct nlattr *tb[],
  62. struct nlattr *data[]);
  63. int (*changelink)(struct net_device *dev,
  64. struct nlattr *tb[],
  65. struct nlattr *data[]);
  66. void (*dellink)(struct net_device *dev,
  67. struct list_head *head);
  68. size_t (*get_size)(const struct net_device *dev);
  69. int (*fill_info)(struct sk_buff *skb,
  70. const struct net_device *dev);
  71. size_t (*get_xstats_size)(const struct net_device *dev);
  72. int (*fill_xstats)(struct sk_buff *skb,
  73. const struct net_device *dev);
  74. unsigned int (*get_num_tx_queues)(void);
  75. unsigned int (*get_num_rx_queues)(void);
  76. int slave_maxtype;
  77. const struct nla_policy *slave_policy;
  78. int (*slave_validate)(struct nlattr *tb[],
  79. struct nlattr *data[]);
  80. int (*slave_changelink)(struct net_device *dev,
  81. struct net_device *slave_dev,
  82. struct nlattr *tb[],
  83. struct nlattr *data[]);
  84. size_t (*get_slave_size)(const struct net_device *dev,
  85. const struct net_device *slave_dev);
  86. int (*fill_slave_info)(struct sk_buff *skb,
  87. const struct net_device *dev,
  88. const struct net_device *slave_dev);
  89. struct net *(*get_link_net)(const struct net_device *dev);
  90. size_t (*get_linkxstats_size)(const struct net_device *dev,
  91. int attr);
  92. int (*fill_linkxstats)(struct sk_buff *skb,
  93. const struct net_device *dev,
  94. int *prividx, int attr);
  95. };
  96. int __rtnl_link_register(struct rtnl_link_ops *ops);
  97. void __rtnl_link_unregister(struct rtnl_link_ops *ops);
  98. int rtnl_link_register(struct rtnl_link_ops *ops);
  99. void rtnl_link_unregister(struct rtnl_link_ops *ops);
  100. /**
  101. * struct rtnl_af_ops - rtnetlink address family operations
  102. *
  103. * @list: Used internally
  104. * @family: Address family
  105. * @fill_link_af: Function to fill IFLA_AF_SPEC with address family
  106. * specific netlink attributes.
  107. * @get_link_af_size: Function to calculate size of address family specific
  108. * netlink attributes.
  109. * @validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
  110. * for invalid configuration settings.
  111. * @set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
  112. * net_device accordingly.
  113. */
  114. struct rtnl_af_ops {
  115. struct list_head list;
  116. int family;
  117. int (*fill_link_af)(struct sk_buff *skb,
  118. const struct net_device *dev,
  119. u32 ext_filter_mask);
  120. size_t (*get_link_af_size)(const struct net_device *dev,
  121. u32 ext_filter_mask);
  122. int (*validate_link_af)(const struct net_device *dev,
  123. const struct nlattr *attr);
  124. int (*set_link_af)(struct net_device *dev,
  125. const struct nlattr *attr);
  126. int (*fill_stats_af)(struct sk_buff *skb,
  127. const struct net_device *dev);
  128. size_t (*get_stats_af_size)(const struct net_device *dev);
  129. };
  130. void __rtnl_af_unregister(struct rtnl_af_ops *ops);
  131. void rtnl_af_register(struct rtnl_af_ops *ops);
  132. void rtnl_af_unregister(struct rtnl_af_ops *ops);
  133. struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
  134. struct net_device *rtnl_create_link(struct net *net, const char *ifname,
  135. unsigned char name_assign_type,
  136. const struct rtnl_link_ops *ops,
  137. struct nlattr *tb[]);
  138. int rtnl_delete_link(struct net_device *dev);
  139. int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
  140. int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
  141. struct netlink_ext_ack *exterr);
  142. #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
  143. #endif