route.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * netlink/route/route.h Routes
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation version 2.1
  7. * of the License.
  8. *
  9. * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_ROUTE_H_
  12. #define NETLINK_ROUTE_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/cache.h>
  15. #include <netlink/addr.h>
  16. #include <netlink/data.h>
  17. #include <netlink/route/nexthop.h>
  18. #include <netlink/route/rtnl.h>
  19. #include <linux/in_route.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * @ingroup route
  25. * When passed to rtnl_route_alloc_cache() the cache will
  26. * correspond to the contents of the routing cache instead
  27. * of the actual routes.
  28. */
  29. #define ROUTE_CACHE_CONTENT 1
  30. struct rtnl_route;
  31. struct rtnl_rtcacheinfo
  32. {
  33. uint32_t rtci_clntref;
  34. uint32_t rtci_last_use;
  35. uint32_t rtci_expires;
  36. int32_t rtci_error;
  37. uint32_t rtci_used;
  38. uint32_t rtci_id;
  39. uint32_t rtci_ts;
  40. uint32_t rtci_tsage;
  41. };
  42. extern struct nl_object_ops route_obj_ops;
  43. extern struct rtnl_route * rtnl_route_alloc(void);
  44. extern void rtnl_route_put(struct rtnl_route *);
  45. extern int rtnl_route_alloc_cache(struct nl_sock *, int, int,
  46. struct nl_cache **);
  47. extern void rtnl_route_get(struct rtnl_route *);
  48. extern int rtnl_route_parse(struct nlmsghdr *, struct rtnl_route **);
  49. extern int rtnl_route_build_msg(struct nl_msg *, struct rtnl_route *);
  50. extern int rtnl_route_build_add_request(struct rtnl_route *, int,
  51. struct nl_msg **);
  52. extern int rtnl_route_add(struct nl_sock *, struct rtnl_route *, int);
  53. extern int rtnl_route_build_del_request(struct rtnl_route *, int,
  54. struct nl_msg **);
  55. extern int rtnl_route_delete(struct nl_sock *, struct rtnl_route *, int);
  56. extern void rtnl_route_set_table(struct rtnl_route *, uint32_t);
  57. extern uint32_t rtnl_route_get_table(struct rtnl_route *);
  58. extern void rtnl_route_set_scope(struct rtnl_route *, uint8_t);
  59. extern uint8_t rtnl_route_get_scope(struct rtnl_route *);
  60. extern void rtnl_route_set_tos(struct rtnl_route *, uint8_t);
  61. extern uint8_t rtnl_route_get_tos(struct rtnl_route *);
  62. extern void rtnl_route_set_protocol(struct rtnl_route *, uint8_t);
  63. extern uint8_t rtnl_route_get_protocol(struct rtnl_route *);
  64. extern void rtnl_route_set_priority(struct rtnl_route *, uint32_t);
  65. extern uint32_t rtnl_route_get_priority(struct rtnl_route *);
  66. extern int rtnl_route_set_family(struct rtnl_route *, uint8_t);
  67. extern uint8_t rtnl_route_get_family(struct rtnl_route *);
  68. extern int rtnl_route_set_type(struct rtnl_route *, uint8_t);
  69. extern uint8_t rtnl_route_get_type(struct rtnl_route *);
  70. extern void rtnl_route_set_flags(struct rtnl_route *, uint32_t);
  71. extern void rtnl_route_unset_flags(struct rtnl_route *, uint32_t);
  72. extern uint32_t rtnl_route_get_flags(struct rtnl_route *);
  73. extern int rtnl_route_set_metric(struct rtnl_route *, int, unsigned int);
  74. extern int rtnl_route_unset_metric(struct rtnl_route *, int);
  75. extern int rtnl_route_get_metric(struct rtnl_route *, int, uint32_t *);
  76. extern int rtnl_route_set_dst(struct rtnl_route *, struct nl_addr *);
  77. extern struct nl_addr *rtnl_route_get_dst(struct rtnl_route *);
  78. extern int rtnl_route_set_src(struct rtnl_route *, struct nl_addr *);
  79. extern struct nl_addr *rtnl_route_get_src(struct rtnl_route *);
  80. extern int rtnl_route_set_pref_src(struct rtnl_route *, struct nl_addr *);
  81. extern struct nl_addr *rtnl_route_get_pref_src(struct rtnl_route *);
  82. extern void rtnl_route_set_iif(struct rtnl_route *, int);
  83. extern int rtnl_route_get_iif(struct rtnl_route *);
  84. extern int rtnl_route_get_src_len(struct rtnl_route *);
  85. extern void rtnl_route_add_nexthop(struct rtnl_route *,
  86. struct rtnl_nexthop *);
  87. extern void rtnl_route_remove_nexthop(struct rtnl_route *,
  88. struct rtnl_nexthop *);
  89. extern struct nl_list_head *rtnl_route_get_nexthops(struct rtnl_route *);
  90. extern int rtnl_route_get_nnexthops(struct rtnl_route *);
  91. extern void rtnl_route_foreach_nexthop(struct rtnl_route *r,
  92. void (*cb)(struct rtnl_nexthop *, void *),
  93. void *arg);
  94. extern struct rtnl_nexthop * rtnl_route_nexthop_n(struct rtnl_route *r, int n);
  95. extern int rtnl_route_guess_scope(struct rtnl_route *);
  96. extern char * rtnl_route_table2str(int, char *, size_t);
  97. extern int rtnl_route_str2table(const char *);
  98. extern int rtnl_route_read_table_names(const char *);
  99. extern char * rtnl_route_proto2str(int, char *, size_t);
  100. extern int rtnl_route_str2proto(const char *);
  101. extern int rtnl_route_read_protocol_names(const char *);
  102. extern char * rtnl_route_metric2str(int, char *, size_t);
  103. extern int rtnl_route_str2metric(const char *);
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif