]> git.proxmox.com Git - mirror_frr.git/blob - babeld/route.h
Merge pull request #13376 from louis-6wind/fix-flex-algo-mem-leak
[mirror_frr.git] / babeld / route.h
1 // SPDX-License-Identifier: MIT
2 /*
3 Copyright (c) 2007, 2008 by Juliusz Chroboczek
4 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
5 */
6
7 #ifndef BABEL_ROUTE_H
8 #define BABEL_ROUTE_H
9
10 #include "babel_interface.h"
11 #include "source.h"
12
13 enum babel_diversity {
14 DIVERSITY_NONE,
15 DIVERSITY_INTERFACE_1,
16 DIVERSITY_CHANNEL_1,
17 DIVERSITY_CHANNEL,
18 };
19
20 #define DIVERSITY_HOPS 8
21
22 struct babel_route {
23 struct source *src;
24 unsigned short refmetric;
25 unsigned short cost;
26 unsigned short add_metric;
27 unsigned short seqno;
28 struct neighbour *neigh;
29 unsigned char nexthop[16];
30 time_t time;
31 unsigned short hold_time; /* in seconds */
32 unsigned short smoothed_metric; /* for route selection */
33 time_t smoothed_metric_time;
34 short installed;
35 unsigned char channels[DIVERSITY_HOPS];
36 struct babel_route *next;
37 };
38
39 struct route_stream;
40
41 extern struct babel_route **routes;
42 extern int kernel_metric;
43 extern enum babel_diversity diversity_kind;
44 extern int diversity_factor;
45 extern int keep_unfeasible;
46 extern int smoothing_half_life;
47
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
55 static inline int
56 route_metric_noninterfering(const struct babel_route *route)
57 {
58 int m =
59 (int)route->refmetric +
60 (diversity_factor * route->cost + 128) / 256 +
61 route->add_metric;
62 m = MAX(m, route->refmetric + 1);
63 return MIN(m, INFINITY);
64 }
65
66 struct babel_route *find_route(const unsigned char *prefix, unsigned char plen,
67 struct neighbour *neigh, const unsigned char *nexthop);
68 struct babel_route *find_installed_route(const unsigned char *prefix,
69 unsigned char plen);
70 int installed_routes_estimate(void);
71 void flush_route(struct babel_route *route);
72 void flush_all_routes(void);
73 void flush_neighbour_routes(struct neighbour *neigh);
74 void flush_interface_routes(struct interface *ifp, int v4only);
75 struct route_stream *route_stream(int installed);
76 struct babel_route *route_stream_next(struct route_stream *stream);
77 void route_stream_done(struct route_stream *stream);
78 void install_route(struct babel_route *route);
79 void uninstall_route(struct babel_route *route);
80 int route_feasible(struct babel_route *route);
81 int route_old(struct babel_route *route);
82 int route_expired(struct babel_route *route);
83 int route_interferes(struct babel_route *route, struct interface *ifp);
84 int update_feasible(struct source *src,
85 unsigned short seqno, unsigned short refmetric);
86 void change_smoothing_half_life(int half_life);
87 int route_smoothed_metric(struct babel_route *route);
88 struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen,
89 int feasible, struct neighbour *exclude);
90 struct babel_route *install_best_route(const unsigned char prefix[16],
91 unsigned char plen);
92 void update_neighbour_metric(struct neighbour *neigh, int change);
93 void update_interface_metric(struct interface *ifp);
94 void update_route_metric(struct babel_route *route);
95 struct babel_route *update_route(const unsigned char *id,
96 const unsigned char *prefix, unsigned char plen,
97 unsigned short seqno, unsigned short refmetric,
98 unsigned short interval, struct neighbour *neigh,
99 const unsigned char *nexthop,
100 const unsigned char *channels, int channels_len);
101 void retract_neighbour_routes(struct neighbour *neigh);
102 void send_unfeasible_request(struct neighbour *neigh, int force,
103 unsigned short seqno, unsigned short metric,
104 struct source *src);
105 void send_triggered_update(struct babel_route *route,
106 struct source *oldsrc, unsigned oldmetric);
107 void route_changed(struct babel_route *route,
108 struct source *oldsrc, unsigned short oldmetric);
109 void route_lost(struct source *src, unsigned oldmetric);
110 void expire_routes(void);
111
112 #endif