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
30#include "pib.h"
31
32#include <stddef.h>
33#include <time.h>
34
35#define ATTR_USED_NEXTHOP 0b1
36#define ATTR_USED_ADVERTPATH 0b10
37#define ATTR_USED_ROUTEDPATH 0b100
38#define ATTR_USED_LOCALPREF 0b1000
39#define ATTR_USED_METRIC 0b10000
40#define ATTR_USED_COMMUNITIES 0b100000
41
42#define ATTR_IS_USED_NEXTHOP(x) (((x) >> 0) & 1)
43#define ATTR_IS_USED_ADVERTPATH(x) (((x) >> 1) & 1)
44#define ATTR_IS_USED_ROUTEDPATH(x) (((x) >> 2) & 1)
45#define ATTR_IS_USED_LOCALPREF(x) (((x) >> 3) & 1)
46#define ATTR_IS_USED_METRIC(x) (((x) >> 4) & 1)
47#define ATTR_IS_USED_COMMUNITIES(x) (((x) >> 5) & 1)
48
49
51typedef struct {
52 uint32_t use;
54 uint32_t nextitad;
55 char *nexthop;
56 uint32_t *advertpath;
57 size_t advertpath_size;
58 uint32_t *routedpath;
59 size_t routedpath_size;
61 uint32_t local_pref;
62 uint32_t metric;
63 community_t*communities;
64 size_t communities_size;
67
68typedef enum {
69 ENTRY_TYPE_TRIP,
70 ENTRY_TYPE_CONNECTED,
71 ENTRY_TYPE_STATIC
72} entry_type_t;
73
75typedef struct {
76 /* route */
77 uint16_t af;
78 uint16_t app_proto;
79 char *prefix;
80
81 entry_type_t type;
82
83 uint32_t origin_itad;
84
85 /* learned from */
86 uint32_t learn_itad;
88 uint32_t learn_lsid;
89
90 int32_t seq;
91 time_t time;
92
94
95 int sent;
96} entry_t;
97
99typedef struct {
100 uint32_t peer_itad;
101 entry_t **table;
102 size_t size, capacity;
104} table_t;
105
106
107typedef struct {
110 size_t size, capacity;
112
136typedef struct {
137 uint32_t local_itad;
138
139 table_t loc_trib, optimized_loc_trib;
140
141 table_t **adj_tribs_in, **adj_tribs_out;
142 size_t adj_tribs_capacity, adj_tribs_size;
143
144 table_t ext_trib;
145
146 table_t local_routes;
147} trib_t;
148
149
151void entry_destroy(entry_t *entry);
152
153
156
158trib_t *trib_new(uint32_t local_itad);
160void trib_adj_pair_add(trib_t *trib, table_t *in, table_t *out);
161void trib_adj_pair_remove(trib_t *trib, table_t *in, table_t *out);
163void trib_destroy(trib_t *trib);
164
166void trib_table_insert(table_t *table, entry_t *route);
167
169void trib_table_clear(table_t *table);
170
171
173void trib_update_local(trib_t *trib);
174
180void trib_update_adj_out(trib_t *trib, table_t *adj_trib_out);
181
187void trib_update_full(trib_t *trib);
188
197size_t get_new_entries(const table_t *table, entry_t ***new_ents_out);
198
206size_t group_entries_by_attrs(entry_t **entries, size_t entries_size,
207 entry_group_t **groups_out);
208
209#endif /* _TRIB_H */
210
Policy Information Base.
Protocol definition header.
Groupable attributes that are related to a route.
Definition trib.h:51
char * nexthop
Definition trib.h:55
uint32_t local_pref
Definition trib.h:61
int atomicaggregate
Definition trib.h:60
uint32_t nextitad
Definition trib.h:54
community_t * communities
Definition trib.h:63
uint32_t use
Definition trib.h:52
int convertedroute
Definition trib.h:65
uint32_t * advertpath
Definition trib.h:56
int withdrawn
Definition trib.h:53
uint32_t metric
Definition trib.h:62
uint32_t * routedpath
Definition trib.h:58
Definition trib.h:107
entry_t ** entries
Definition trib.h:109
entry_attrs_t attrs
Definition trib.h:108
Route Entry.
Definition trib.h:75
int sent
Definition trib.h:95
uint16_t af
Definition trib.h:77
entry_type_t type
Definition trib.h:81
uint32_t origin_itad
Definition trib.h:83
uint32_t learn_lsid
Definition trib.h:88
int32_t seq
Definition trib.h:90
uint32_t learn_itad
Definition trib.h:86
entry_attrs_t attrs
Definition trib.h:93
time_t time
Definition trib.h:91
uint16_t app_proto
Definition trib.h:78
char * prefix
Definition trib.h:79
Route map.
Definition pib.h:79
Route Table.
Definition trib.h:99
uint32_t peer_itad
Definition trib.h:100
routemap_t * routemap
Definition trib.h:103
Telephony Routing Information Base.
Definition trib.h:136
uint32_t local_itad
Definition trib.h:137
table_t ** adj_tribs_out
Definition trib.h:141
void trib_update_local(trib_t *trib)
Update local routes when ITAD is defined.
Definition trib.c:325
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:397
void trib_destroy(trib_t *trib)
Deinit TRIB structure.
Definition trib.c:174
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:138
void trib_table_deinit(table_t *t)
Deinitialize table.
Definition trib.c:107
void entry_destroy(entry_t *entry)
Destroy entry.
Definition trib.c:77
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:485
void trib_update_adj_out(trib_t *trib, table_t *adj_trib_out)
Update an Adj-TRIB-Out.
Definition trib.c:339
trib_t * trib_new(uint32_t local_itad)
Initialize TRIB structure.
Definition trib.c:115
void trib_table_insert(table_t *table, entry_t *route)
Add route to table.
Definition trib.c:186
void trib_update_full(trib_t *trib)
Execute route selection.
Definition trib.c:351
void trib_table_clear(table_t *table)
Destroy all entries and clear table.
Definition trib.c:198