3
0

libnetlink.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* vi: set sw=4 ts=4: */
  2. #ifndef LIBNETLINK_H
  3. #define LIBNETLINK_H 1
  4. #include <linux/types.h>
  5. /* We need linux/types.h because older kernels use __u32 etc
  6. * in linux/[rt]netlink.h. 2.6.19 seems to be ok, though */
  7. #include <linux/netlink.h>
  8. #include <linux/rtnetlink.h>
  9. PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  10. struct rtnl_handle {
  11. int fd;
  12. struct sockaddr_nl local;
  13. struct sockaddr_nl peer;
  14. uint32_t seq;
  15. uint32_t dump;
  16. };
  17. extern void xrtnl_open(struct rtnl_handle *rth) FAST_FUNC;
  18. #define rtnl_close(rth) (close((rth)->fd))
  19. extern void xrtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) FAST_FUNC;
  20. extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) FAST_FUNC;
  21. extern int xrtnl_dump_filter(struct rtnl_handle *rth,
  22. int (*filter)(const struct sockaddr_nl*, struct nlmsghdr *n, void*) FAST_FUNC,
  23. void *arg1) FAST_FUNC;
  24. /* bbox doesn't use parameters no. 3, 4, 6, 7, stub them out */
  25. #define rtnl_talk(rtnl, n, peer, groups, answer, junk, jarg) \
  26. rtnl_talk(rtnl, n, answer)
  27. extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
  28. unsigned groups, struct nlmsghdr *answer,
  29. int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
  30. void *jarg) FAST_FUNC;
  31. int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len) FAST_FUNC;
  32. //TODO: pass rth->fd instead of full rth?
  33. static ALWAYS_INLINE void rtnl_send(struct rtnl_handle *rth, const void *buf, int len)
  34. {
  35. // Used to be:
  36. //struct sockaddr_nl nladdr;
  37. //memset(&nladdr, 0, sizeof(nladdr));
  38. //nladdr.nl_family = AF_NETLINK;
  39. //return xsendto(rth->fd, buf, len, (struct sockaddr*)&nladdr, sizeof(nladdr));
  40. // iproute2-4.2.0 simplified the above to:
  41. //return send(rth->fd, buf, len, 0);
  42. // We are using even shorter:
  43. xwrite(rth->fd, buf, len);
  44. // and convert to void, inline.
  45. }
  46. extern int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) FAST_FUNC;
  47. extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) FAST_FUNC;
  48. extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data) FAST_FUNC;
  49. extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen) FAST_FUNC;
  50. extern void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) FAST_FUNC;
  51. POP_SAVED_FUNCTION_VISIBILITY
  52. #endif