rtnetlink.h 4.6 KB

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