]> git.proxmox.com Git - mirror_frr.git/blob - lib/srcdest_table.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / lib / srcdest_table.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * SRC-DEST Routing Table
4 *
5 * Copyright (C) 2017 by David Lamparter & Christian Franke,
6 * Open Source Routing / NetDEF Inc.
7 *
8 * This file is part of FRRouting (FRR)
9 */
10
11 #ifndef _ZEBRA_SRC_DEST_TABLE_H
12 #define _ZEBRA_SRC_DEST_TABLE_H
13
14 /* old/IPv4/non-srcdest:
15 * table -> route_node .info -> [obj]
16 *
17 * new/IPv6/srcdest:
18 * table -...-> srcdest_rnode [prefix = dest] .info -> [obj]
19 * .src_table ->
20 * srcdest table -...-> route_node [prefix = src] .info -> [obj]
21 *
22 * non-srcdest routes (src = ::/0) are treated just like before, their
23 * information being directly there in the info pointer.
24 *
25 * srcdest routes are found by looking up destination first, then looking
26 * up the source in the "src_table". src_table contains normal route_nodes,
27 * whose prefix is the _source_ prefix.
28 *
29 * NB: info can be NULL on the destination rnode, if there are only srcdest
30 * routes for a particular destination prefix.
31 */
32
33 #include "prefix.h"
34 #include "table.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #define SRCDEST2STR_BUFFER (2*PREFIX2STR_BUFFER + sizeof(" from "))
41
42 /* extended route node for IPv6 srcdest routing */
43 struct srcdest_rnode;
44
45 extern route_table_delegate_t _srcdest_dstnode_delegate;
46 extern route_table_delegate_t _srcdest_srcnode_delegate;
47
48 extern struct route_table *srcdest_table_init(void);
49 extern struct route_node *srcdest_rnode_get(struct route_table *table,
50 union prefixconstptr dst_pu,
51 const struct prefix_ipv6 *src_p);
52 extern struct route_node *srcdest_rnode_lookup(struct route_table *table,
53 union prefixconstptr dst_pu,
54 const struct prefix_ipv6 *src_p);
55 extern void srcdest_rnode_prefixes(const struct route_node *rn,
56 const struct prefix **p,
57 const struct prefix **src_p);
58 extern const char *srcdest2str(const struct prefix *dst_p,
59 const struct prefix_ipv6 *src_p,
60 char *str, int size);
61 extern const char *srcdest_rnode2str(const struct route_node *rn, char *str,
62 int size);
63 extern struct route_node *srcdest_route_next(struct route_node *rn);
64
65 static inline int rnode_is_dstnode(const struct route_node *rn)
66 {
67 return rn->table->delegate == &_srcdest_dstnode_delegate;
68 }
69
70 static inline int rnode_is_srcnode(const struct route_node *rn)
71 {
72 return rn->table->delegate == &_srcdest_srcnode_delegate;
73 }
74
75 static inline struct route_table *srcdest_rnode_table(struct route_node *rn)
76 {
77 if (rnode_is_srcnode(rn)) {
78 struct route_node *dst_rn =
79 (struct route_node *)route_table_get_info(rn->table);
80 return dst_rn->table;
81 } else {
82 return rn->table;
83 }
84 }
85 static inline void *srcdest_rnode_table_info(struct route_node *rn)
86 {
87 return route_table_get_info(srcdest_rnode_table(rn));
88 }
89
90 extern struct route_table *srcdest_srcnode_table(struct route_node *rn);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif /* _ZEBRA_SRC_DEST_TABLE_H */