rtnetlink.h 5.8 KB

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