rtnetlink.h 4.5 KB

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