TRIP Routing Daemon
TRIP (RFC 3219) Location Server Implementation
Loading...
Searching...
No Matches
trib.h
Go to the documentation of this file.
1/*
2
3 trip: Modern TRIP LS implementation
4 Copyright (C) 2025 arf20 (Ángel Ruiz Fernandez)
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19*/
20
24
25#ifndef _TRIB_H
26#define _TRIB_H
27
28#include <protocol/protocol.h>
29#include <functions/locator.h>
30
31#include "pib.h"
32
33#include <stddef.h>
34#include <time.h>
35
36#define ATTR_USED_NEXTHOP 0b1
37#define ATTR_USED_ADVERTPATH 0b10
38#define ATTR_USED_ROUTEDPATH 0b100
39#define ATTR_USED_LOCALPREF 0b1000
40#define ATTR_USED_METRIC 0b10000
41#define ATTR_USED_COMMUNITIES 0b100000
42
43#define ATTR_IS_USED_NEXTHOP(x) (((x) >> 0) & 1)
44#define ATTR_IS_USED_ADVERTPATH(x) (((x) >> 1) & 1)
45#define ATTR_IS_USED_ROUTEDPATH(x) (((x) >> 2) & 1)
46#define ATTR_IS_USED_LOCALPREF(x) (((x) >> 3) & 1)
47#define ATTR_IS_USED_METRIC(x) (((x) >> 4) & 1)
48#define ATTR_IS_USED_COMMUNITIES(x) (((x) >> 5) & 1)
49
50
52typedef struct {
53 uint32_t use;
55 uint32_t nextitad;
56 char *nexthop;
57 uint32_t *advertpath;
58 size_t advertpath_size;
59 uint32_t *routedpath;
60 size_t routedpath_size;
62 uint32_t local_pref;
63 uint32_t metric;
64 community_t*communities;
65 size_t communities_size;
68
69typedef enum {
70 ENTRY_TYPE_TRIP,
71 ENTRY_TYPE_CONNECTED,
72 ENTRY_TYPE_STATIC
73} entry_type_t;
74
75extern const char *entry_type_strs[];
76
78typedef struct {
79 /* route */
80 uint16_t af;
81 uint16_t app_proto;
82 char *prefix;
83
84 entry_type_t type;
85
86 uint32_t origin_itad;
87
88 /* learned from */
89 uint32_t learn_itad;
91 uint32_t learn_lsid;
93
94 int32_t seq;
95 time_t time;
96
98
99 int sent;
100} entry_t;
101
103typedef struct {
104 uint32_t peer_itad, peer_id;
105 entry_t **table;
106 size_t size, capacity;
108} table_t;
109
110
111typedef struct {
114 size_t size, capacity;
116
140typedef struct {
141 uint32_t local_itad;
142
143 table_t loc_trib, optimized_loc_trib;
144
145 table_t **adj_tribs_in, **adj_tribs_out;
146 size_t adj_tribs_capacity, adj_tribs_size;
147
148 table_t ext_trib;
149
150 table_t local_routes;
151} trib_t;
152
153
155entry_t *entry_clone(const entry_t *entry);
157void entry_destroy(entry_t *entry);
158
161
163trib_t *trib_new(uint32_t local_itad);
165void trib_adj_pair_add(trib_t *trib, table_t *in, table_t *out);
166void trib_adj_pair_remove(trib_t *trib, table_t *in, table_t *out);
168void trib_destroy(trib_t *trib);
169
171entry_t **trib_table_find(table_t *t, uint16_t af, const char *prefix);
172
178const entry_t *trib_table_lookup(const table_t *table, uint16_t af,
179 uint16_t app_proto, const char *address);
180
182void trib_table_insert(table_t *table, entry_t *route);
183
184void trib_table_insert_or_replace(table_t *table, entry_t *route);
185
187void trib_table_clear(table_t *table);
188
189
191void trib_update_local(trib_t *trib);
192
198void trib_update_adj_out(trib_t *trib, table_t *adj_trib_out);
199
205void trib_update_full(trib_t *trib);
206
215size_t get_new_entries(const table_t *table, entry_t ***new_ents_out);
216
224size_t group_entries_by_attrs(entry_t **entries, size_t entries_size,
225 entry_group_t **groups_out);
226
227#endif /* _TRIB_H */
228
Peer locator.
Policy Information Base.
Protocol definition header.
af
Address families.
Definition protocol.h:211
app_proto
Application protocols.
Definition protocol.h:225
Groupable attributes that are related to a route.
Definition trib.h:52
char * nexthop
Definition trib.h:56
uint32_t local_pref
Definition trib.h:62
int atomicaggregate
Definition trib.h:61
uint32_t nextitad
Definition trib.h:55
community_t * communities
Definition trib.h:64
uint32_t use
Definition trib.h:53
int convertedroute
Definition trib.h:66
uint32_t * advertpath
Definition trib.h:57
int withdrawn
Definition trib.h:54
uint32_t metric
Definition trib.h:63
uint32_t * routedpath
Definition trib.h:59
Definition trib.h:111
entry_t ** entries
Definition trib.h:113
entry_attrs_t attrs
Definition trib.h:112
Route Entry.
Definition trib.h:78
int sent
Definition trib.h:99
uint16_t af
Definition trib.h:80
entry_type_t type
Definition trib.h:84
uint32_t origin_itad
Definition trib.h:86
uint32_t learn_lsid
Definition trib.h:91
int32_t seq
Definition trib.h:94
uint32_t learn_itad
Definition trib.h:89
const peer_t * learn_peer
Definition trib.h:92
entry_attrs_t attrs
Definition trib.h:97
time_t time
Definition trib.h:95
uint16_t app_proto
Definition trib.h:81
char * prefix
Definition trib.h:82
Known peer info object.
Definition locator.h:37
Route map.
Definition pib.h:79
Route Table.
Definition trib.h:103
uint32_t peer_id
Definition trib.h:104
routemap_t * routemap
Definition trib.h:107
Telephony Routing Information Base.
Definition trib.h:140
uint32_t local_itad
Definition trib.h:141
table_t ** adj_tribs_out
Definition trib.h:145
void trib_update_local(trib_t *trib)
Update local routes when ITAD is defined.
Definition trib.c:420
size_t get_new_entries(const table_t *table, entry_t ***new_ents_out)
Return array of new entry references to new.
Definition trib.c:537
entry_t ** trib_table_find(table_t *t, uint16_t af, const char *prefix)
Find exact route in table.
Definition trib.c:192
void trib_destroy(trib_t *trib)
Deinit TRIB structure.
Definition trib.c:180
void trib_adj_pair_add(trib_t *trib, table_t *in, table_t *out)
Add and init pair of tables owned by caller.
Definition trib.c:144
void trib_table_deinit(table_t *t)
Deinitialize table.
Definition trib.c:113
void entry_destroy(entry_t *entry)
Destroy entry.
Definition trib.c:83
size_t group_entries_by_attrs(entry_t **entries, size_t entries_size, entry_group_t **groups_out)
Group array of entry references by attributes.
Definition trib.c:625
void trib_update_adj_out(trib_t *trib, table_t *adj_trib_out)
Update an Adj-TRIB-Out.
Definition trib.c:458
trib_t * trib_new(uint32_t local_itad)
Initialize TRIB structure.
Definition trib.c:121
void trib_table_insert(table_t *table, entry_t *route)
Add route to table.
Definition trib.c:224
void trib_update_full(trib_t *trib)
Execute route selection.
Definition trib.c:484
entry_t * entry_clone(const entry_t *entry)
Clone entry.
Definition trib.c:52
const entry_t * trib_table_lookup(const table_t *table, uint16_t af, uint16_t app_proto, const char *address)
Lookup address in table.
Definition trib.c:201
void trib_table_clear(table_t *table)
Destroy all entries and clear table.
Definition trib.c:296