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