rtnetlink.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. */
  46. struct rtnl_link_ops {
  47. struct list_head list;
  48. const char *kind;
  49. size_t priv_size;
  50. void (*setup)(struct net_device *dev);
  51. int maxtype;
  52. const struct nla_policy *policy;
  53. int (*validate)(struct nlattr *tb[],
  54. struct nlattr *data[]);
  55. int (*newlink)(struct net *src_net,
  56. struct net_device *dev,
  57. struct nlattr *tb[],
  58. struct nlattr *data[]);
  59. int (*changelink)(struct net_device *dev,
  60. struct nlattr *tb[],
  61. struct nlattr *data[]);
  62. void (*dellink)(struct net_device *dev,
  63. struct list_head *head);
  64. size_t (*get_size)(const struct net_device *dev);
  65. int (*fill_info)(struct sk_buff *skb,
  66. const struct net_device *dev);
  67. size_t (*get_xstats_size)(const struct net_device *dev);
  68. int (*fill_xstats)(struct sk_buff *skb,
  69. const struct net_device *dev);
  70. unsigned int (*get_num_tx_queues)(void);
  71. unsigned int (*get_num_rx_queues)(void);
  72. int slave_maxtype;
  73. const struct nla_policy *slave_policy;
  74. int (*slave_validate)(struct nlattr *tb[],
  75. struct nlattr *data[]);
  76. int (*slave_changelink)(struct net_device *dev,
  77. struct net_device *slave_dev,
  78. struct nlattr *tb[],
  79. struct nlattr *data[]);
  80. size_t (*get_slave_size)(const struct net_device *dev,
  81. const struct net_device *slave_dev);
  82. int (*fill_slave_info)(struct sk_buff *skb,
  83. const struct net_device *dev,
  84. const struct net_device *slave_dev);
  85. struct net *(*get_link_net)(const struct net_device *dev);
  86. };
  87. int __rtnl_link_register(struct rtnl_link_ops *ops);
  88. void __rtnl_link_unregister(struct rtnl_link_ops *ops);
  89. int rtnl_link_register(struct rtnl_link_ops *ops);
  90. void rtnl_link_unregister(struct rtnl_link_ops *ops);
  91. /**
  92. * struct rtnl_af_ops - rtnetlink address family operations
  93. *
  94. * @list: Used internally
  95. * @family: Address family
  96. * @fill_link_af: Function to fill IFLA_AF_SPEC with address family
  97. * specific netlink attributes.
  98. * @get_link_af_size: Function to calculate size of address family specific
  99. * netlink attributes.
  100. * @validate_link_af: Validate a IFLA_AF_SPEC attribute, must check attr
  101. * for invalid configuration settings.
  102. * @set_link_af: Function to parse a IFLA_AF_SPEC attribute and modify
  103. * net_device accordingly.
  104. */
  105. struct rtnl_af_ops {
  106. struct list_head list;
  107. int family;
  108. int (*fill_link_af)(struct sk_buff *skb,
  109. const struct net_device *dev,
  110. u32 ext_filter_mask);
  111. size_t (*get_link_af_size)(const struct net_device *dev,
  112. u32 ext_filter_mask);
  113. int (*validate_link_af)(const struct net_device *dev,
  114. const struct nlattr *attr);
  115. int (*set_link_af)(struct net_device *dev,
  116. const struct nlattr *attr);
  117. };
  118. void __rtnl_af_unregister(struct rtnl_af_ops *ops);
  119. void rtnl_af_register(struct rtnl_af_ops *ops);
  120. void rtnl_af_unregister(struct rtnl_af_ops *ops);
  121. struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
  122. struct net_device *rtnl_create_link(struct net *net, const char *ifname,
  123. unsigned char name_assign_type,
  124. const struct rtnl_link_ops *ops,
  125. struct nlattr *tb[]);
  126. int rtnl_delete_link(struct net_device *dev);
  127. int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
  128. int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len);
  129. #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
  130. #endif