rtnetlink.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 void rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops);
  71. extern int rtnl_link_register(struct rtnl_link_ops *ops);
  72. extern void rtnl_link_unregister(struct rtnl_link_ops *ops);
  73. extern struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
  74. extern struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
  75. char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[]);
  76. extern int rtnl_configure_link(struct net_device *dev,
  77. const struct ifinfomsg *ifm);
  78. extern const struct nla_policy ifla_policy[IFLA_MAX+1];
  79. #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
  80. #endif