rtnetlink.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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(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_device *dev,
  50. struct nlattr *tb[],
  51. struct nlattr *data[]);
  52. int (*changelink)(struct net_device *dev,
  53. struct nlattr *tb[],
  54. struct nlattr *data[]);
  55. void (*dellink)(struct net_device *dev);
  56. size_t (*get_size)(const struct net_device *dev);
  57. int (*fill_info)(struct sk_buff *skb,
  58. const struct net_device *dev);
  59. size_t (*get_xstats_size)(const struct net_device *dev);
  60. int (*fill_xstats)(struct sk_buff *skb,
  61. const struct net_device *dev);
  62. };
  63. extern int __rtnl_link_register(struct rtnl_link_ops *ops);
  64. extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
  65. extern void rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops);
  66. extern int rtnl_link_register(struct rtnl_link_ops *ops);
  67. extern void rtnl_link_unregister(struct rtnl_link_ops *ops);
  68. extern struct net_device *rtnl_create_link(struct net *net, char *ifname,
  69. const struct rtnl_link_ops *ops, struct nlattr *tb[]);
  70. extern const struct nla_policy ifla_policy[IFLA_MAX+1];
  71. #define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
  72. #endif