route.h 4.6 KB
Newer Older
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
1
/*
2
Copyright (c) 2007-2011 by Juliusz Chroboczek
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

23 24 25 26 27 28 29
#define DIVERSITY_NONE 0
#define DIVERSITY_INTERFACE_1 1
#define DIVERSITY_CHANNEL_1 2
#define DIVERSITY_CHANNEL 3

#define DIVERSITY_HOPS 8

Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
30
struct route {
31
    struct source *src;
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
32
    unsigned short refmetric;
33 34
    unsigned short cost;
    unsigned short add_metric;
35
    unsigned short seqno;
36
    struct neighbour *neigh;
37
    unsigned char nexthop[16];
38
    time_t time;
39 40
    unsigned short hold_time;    /* in seconds */
    short installed;
41
    unsigned char channels[DIVERSITY_HOPS];
42
    struct route *next;
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
43 44
};

45
extern struct route **routes;
46 47 48 49
extern int kernel_metric, allow_duplicates;
extern int diversity_kind, diversity_factor;
extern int keep_unfeasible;

50 51 52
static inline int
route_metric(const struct route *route)
{
53
    int m = (int)route->refmetric + route->cost + route->add_metric;
54
    return MIN(m, INFINITY);
55 56
}

57 58 59 60 61 62 63 64 65 66
static inline int
route_metric_noninterfering(const struct route *route)
{
    int m =
        (int)route->refmetric +
        (diversity_factor * route->cost + 128) / 256 +
        route->add_metric;
    m = MAX(m, route->refmetric + 1);
    return MIN(m, INFINITY);
}
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
67

68
struct route *find_route(const unsigned char *prefix, unsigned char plen,
69
                         struct neighbour *neigh, const unsigned char *nexthop);
70 71
struct route *find_installed_route(const unsigned char *prefix,
                                   unsigned char plen);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
72
void flush_route(struct route *route);
73
void flush_all_routes(void);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
74
void flush_neighbour_routes(struct neighbour *neigh);
75
void flush_interface_routes(struct interface *ifp, int v4only);
76 77 78
void for_all_routes(void (*f)(struct route*, void*), void *closure);
void for_all_installed_routes(void (*f)(struct route*, void*), void *closure);
struct route *find_route_with_source(struct source *src);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
79 80
void install_route(struct route *route);
void uninstall_route(struct route *route);
81
void switch_route(struct route *old, struct route *new);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
82
int route_feasible(struct route *route);
83 84
int route_old(struct route *route);
int route_expired(struct route *route);
85
int route_interferes(struct route *route, struct interface *ifp);
86
int update_feasible(struct source *src,
87
                    unsigned short seqno, unsigned short refmetric);
88
struct route *find_best_route(const unsigned char *prefix, unsigned char plen,
89
                              int feasible, struct neighbour *exclude);
90 91
struct route *install_best_route(const unsigned char prefix[16],
                                 unsigned char plen);
92
void update_neighbour_metric(struct neighbour *neigh, int changed);
93
void update_interface_metric(struct interface *ifp);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
94
void update_route_metric(struct route *route);
95 96 97
struct route *update_route(const unsigned char *a,
                           const unsigned char *p, unsigned char plen,
                           unsigned short seqno, unsigned short refmetric,
98
                           unsigned short interval, struct neighbour *neigh,
99 100
                           const unsigned char *nexthop,
                           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);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
105
void consider_route(struct route *route);
106
void send_triggered_update(struct route *route,
107
                           struct source *oldsrc, unsigned oldmetric);
108 109
void route_changed(struct route *route,
                   struct source *oldsrc, unsigned short oldmetric);
110
void route_lost(struct source *src, unsigned oldmetric);
111
void expire_routes(void);