]> git.proxmox.com Git - mirror_frr.git/blame - lib/srcdest_table.h
Merge pull request #13278 from FRRouting/mergify/bp/stable/8.5/pr-13269
[mirror_frr.git] / lib / srcdest_table.h
CommitLineData
0964ad9c
DL
1/*
2 * SRC-DEST Routing Table
3 *
4 * Copyright (C) 2017 by David Lamparter & Christian Franke,
5 * Open Source Routing / NetDEF Inc.
6 *
8678d638 7 * This file is part of FRRouting (FRR)
0964ad9c
DL
8 *
9 * FRR is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * FRR is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
896014f4
DL
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0964ad9c
DL
22 */
23
24#ifndef _ZEBRA_SRC_DEST_TABLE_H
25#define _ZEBRA_SRC_DEST_TABLE_H
26
27/* old/IPv4/non-srcdest:
28 * table -> route_node .info -> [obj]
29 *
30 * new/IPv6/srcdest:
31 * table -...-> srcdest_rnode [prefix = dest] .info -> [obj]
32 * .src_table ->
33 * srcdest table -...-> route_node [prefix = src] .info -> [obj]
34 *
35 * non-srcdest routes (src = ::/0) are treated just like before, their
36 * information being directly there in the info pointer.
37 *
38 * srcdest routes are found by looking up destination first, then looking
39 * up the source in the "src_table". src_table contains normal route_nodes,
40 * whose prefix is the _source_ prefix.
41 *
42 * NB: info can be NULL on the destination rnode, if there are only srcdest
43 * routes for a particular destination prefix.
44 */
45
46#include "prefix.h"
47#include "table.h"
48
5e244469
RW
49#ifdef __cplusplus
50extern "C" {
51#endif
52
0964ad9c
DL
53#define SRCDEST2STR_BUFFER (2*PREFIX2STR_BUFFER + sizeof(" from "))
54
55/* extended route node for IPv6 srcdest routing */
56struct srcdest_rnode;
57
58extern route_table_delegate_t _srcdest_dstnode_delegate;
59extern route_table_delegate_t _srcdest_srcnode_delegate;
60
61extern struct route_table *srcdest_table_init(void);
62extern struct route_node *srcdest_rnode_get(struct route_table *table,
86391e56
MS
63 union prefixconstptr dst_pu,
64 const struct prefix_ipv6 *src_p);
0964ad9c 65extern struct route_node *srcdest_rnode_lookup(struct route_table *table,
86391e56
MS
66 union prefixconstptr dst_pu,
67 const struct prefix_ipv6 *src_p);
d52ec572 68extern void srcdest_rnode_prefixes(const struct route_node *rn,
86391e56
MS
69 const struct prefix **p,
70 const struct prefix **src_p);
321c1bbb
CF
71extern const char *srcdest2str(const struct prefix *dst_p,
72 const struct prefix_ipv6 *src_p,
73 char *str, int size);
d52ec572 74extern const char *srcdest_rnode2str(const struct route_node *rn, char *str,
d62a17ae 75 int size);
0964ad9c
DL
76extern struct route_node *srcdest_route_next(struct route_node *rn);
77
d52ec572 78static inline int rnode_is_dstnode(const struct route_node *rn)
0964ad9c 79{
d62a17ae 80 return rn->table->delegate == &_srcdest_dstnode_delegate;
0964ad9c
DL
81}
82
d52ec572 83static inline int rnode_is_srcnode(const struct route_node *rn)
0964ad9c 84{
d62a17ae 85 return rn->table->delegate == &_srcdest_srcnode_delegate;
0964ad9c
DL
86}
87
d62a17ae 88static inline struct route_table *srcdest_rnode_table(struct route_node *rn)
0964ad9c 89{
d62a17ae 90 if (rnode_is_srcnode(rn)) {
d01b92fd
MS
91 struct route_node *dst_rn =
92 (struct route_node *)route_table_get_info(rn->table);
d62a17ae 93 return dst_rn->table;
94 } else {
95 return rn->table;
96 }
0964ad9c 97}
d62a17ae 98static inline void *srcdest_rnode_table_info(struct route_node *rn)
0964ad9c 99{
6ca30e9e 100 return route_table_get_info(srcdest_rnode_table(rn));
0964ad9c
DL
101}
102
88fa5104 103extern struct route_table *srcdest_srcnode_table(struct route_node *rn);
104
5e244469
RW
105#ifdef __cplusplus
106}
107#endif
108
0964ad9c 109#endif /* _ZEBRA_SRC_DEST_TABLE_H */