route.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. Copyright (c) 2007-2011 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #define DIVERSITY_NONE 0
  20. #define DIVERSITY_INTERFACE_1 1
  21. #define DIVERSITY_CHANNEL_1 2
  22. #define DIVERSITY_CHANNEL 3
  23. struct babel_route {
  24. struct source *src;
  25. unsigned short refmetric;
  26. unsigned short cost;
  27. unsigned short add_metric;
  28. unsigned short seqno;
  29. struct neighbour *neigh;
  30. unsigned char nexthop[16];
  31. time_t time;
  32. unsigned short hold_time; /* in seconds */
  33. unsigned short smoothed_metric; /* for route selection */
  34. time_t smoothed_metric_time;
  35. short installed;
  36. short channels_len;
  37. unsigned char *channels;
  38. struct babel_route *next;
  39. };
  40. #define ROUTE_ALL 0
  41. #define ROUTE_INSTALLED 1
  42. #define ROUTE_SS_INSTALLED 2
  43. struct route_stream;
  44. extern struct babel_route **routes;
  45. extern int kernel_metric, allow_duplicates, reflect_kernel_metric;
  46. extern int diversity_kind, diversity_factor;
  47. extern int keep_unfeasible;
  48. static inline int
  49. route_metric(const struct babel_route *route)
  50. {
  51. int m = (int)route->refmetric + route->cost + route->add_metric;
  52. return MIN(m, INFINITY);
  53. }
  54. static inline int
  55. route_metric_noninterfering(const struct babel_route *route)
  56. {
  57. int m =
  58. (int)route->refmetric +
  59. (diversity_factor * route->cost + 128) / 256 +
  60. route->add_metric;
  61. m = MAX(m, route->refmetric + 1);
  62. return MIN(m, INFINITY);
  63. }
  64. struct babel_route *find_route(const unsigned char *prefix, unsigned char plen,
  65. const unsigned char *src_prefix, unsigned char src_plen,
  66. struct neighbour *neigh, const unsigned char *nexthop);
  67. struct babel_route *find_installed_route(const unsigned char *prefix,
  68. unsigned char plen, const unsigned char *src_prefix,
  69. unsigned char src_plen);
  70. // -- lorauth --
  71. struct babel_route
  72. *find_auth_route(const unsigned char *prefix, unsigned char plen,
  73. const unsigned char *src_prefix, unsigned char src_plen,
  74. const unsigned short clen, unsigned char *cipher,
  75. struct neighbour *neigh, const unsigned char *nexthop);
  76. // ----
  77. int installed_routes_estimate(void);
  78. void flush_route(struct babel_route *route);
  79. void flush_all_routes(void);
  80. void flush_neighbour_routes(struct neighbour *neigh);
  81. void flush_interface_routes(struct interface *ifp, int v4only);
  82. struct route_stream *route_stream(int which);
  83. struct babel_route *route_stream_next(struct route_stream *stream);
  84. void route_stream_done(struct route_stream *stream);
  85. int metric_to_kernel(int metric);
  86. void install_route(struct babel_route *route);
  87. void uninstall_route(struct babel_route *route);
  88. int route_feasible(struct babel_route *route);
  89. int route_old(struct babel_route *route);
  90. int route_expired(struct babel_route *route);
  91. int route_interferes(struct babel_route *route, struct interface *ifp);
  92. int update_feasible(struct source *src,
  93. unsigned short seqno, unsigned short refmetric);
  94. void change_smoothing_half_life(int half_life);
  95. int route_smoothed_metric(struct babel_route *route);
  96. struct babel_route *find_best_route(const unsigned char *prefix,
  97. unsigned char plen,
  98. const unsigned char *src_prefix,
  99. unsigned char src_plen,
  100. int feasible, struct neighbour *exclude);
  101. struct babel_route *install_best_route(const unsigned char prefix[16],
  102. unsigned char plen);
  103. void update_neighbour_metric(struct neighbour *neigh, int changed);
  104. void update_interface_metric(struct interface *ifp);
  105. void update_route_metric(struct babel_route *route);
  106. struct babel_route *update_route(const unsigned char *id,
  107. const unsigned char *prefix, unsigned char plen,
  108. const unsigned char *src_prefix,
  109. unsigned char src_plen,
  110. const unsigned char *cipher,
  111. unsigned short clen,
  112. unsigned short seqno, unsigned short refmetric,
  113. unsigned short interval, struct neighbour *neigh,
  114. const unsigned char *nexthop,
  115. const unsigned char *channels, int channels_len);
  116. void retract_neighbour_routes(struct neighbour *neigh);
  117. void send_unfeasible_request(struct neighbour *neigh, int force,
  118. unsigned short seqno, unsigned short metric,
  119. struct source *src);
  120. void consider_route(struct babel_route *route);
  121. void send_triggered_update(struct babel_route *route,
  122. struct source *oldsrc, unsigned oldmetric);
  123. void route_changed(struct babel_route *route,
  124. struct source *oldsrc, unsigned short oldmetric);
  125. void route_lost(struct source *src, unsigned oldmetric);
  126. void expire_routes(void);