rtnetlink.h 4.8 KB

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