You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libnetlink.h 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* This file is part of Netsukuku
  2. *
  3. * This source code is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU General Public License as published
  5. * by the Free Software Foundation; either version 2 of the License,
  6. * or (at your option) any later version.
  7. *
  8. * This source code is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * Please refer to the GNU Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Public License along with
  14. * this source code; if not, write to:
  15. * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *
  17. */
  18. #ifndef __LIBNETLINK_H__
  19. #define __LIBNETLINK_H__ 1
  20. #include <asm/types.h>
  21. #include <linux/netlink.h>
  22. #include <linux/rtnetlink.h>
  23. struct rtnl_handle {
  24. int fd;
  25. struct sockaddr_nl local;
  26. struct sockaddr_nl peer;
  27. uint32_t seq;
  28. uint32_t dump;
  29. };
  30. extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions);
  31. extern int rtnl_open_byproto(struct rtnl_handle *rth,
  32. unsigned subscriptions, int protocol);
  33. extern void rtnl_close(struct rtnl_handle *rth);
  34. extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam,
  35. int type);
  36. extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req,
  37. int len);
  38. typedef int (*rtnl_filter_t) (const struct sockaddr_nl *,
  39. struct nlmsghdr * n, void *);
  40. extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
  41. void *arg1, rtnl_filter_t junk, void *arg2);
  42. extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
  43. pid_t peer, unsigned groups, struct nlmsghdr *answer,
  44. rtnl_filter_t junk, void *jarg);
  45. extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int);
  46. extern int addattr32(struct nlmsghdr *n, int maxlen, int type,
  47. uint32_t data);
  48. extern int addattr_l(struct nlmsghdr *n, int maxlen, int type,
  49. const void *data, int alen);
  50. extern int addraw_l(struct nlmsghdr *n, int maxlen, const void *data,
  51. int len);
  52. extern int rta_addattr32(struct rtattr *rta, int maxlen, int type,
  53. uint32_t data);
  54. extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
  55. const void *data, int alen);
  56. extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta,
  57. int len);
  58. extern int parse_rtattr_byindex(struct rtattr *tb[], int max,
  59. struct rtattr *rta, int len);
  60. #define parse_rtattr_nested(tb, max, rta) \
  61. (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
  62. extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler,
  63. void *jarg);
  64. extern int rtnl_from_file(FILE *, rtnl_filter_t handler, void *jarg);
  65. #define NLMSG_TAIL(nmsg) \
  66. ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
  67. #endif /* __LIBNETLINK_H__ */