]> git.proxmox.com Git - mirror_frr.git/blob - pbrd/pbr_nht.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / pbrd / pbr_nht.h
1 /*
2 * PBR-nht Header
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #ifndef __PBR_NHT_H__
21 #define __PBR_NHT_H__
22
23 #include <lib/zclient.h>
24 #include <lib/nexthop_group.h>
25
26 #include "pbr_map.h"
27 #include "json.h"
28
29 #define PBR_NHC_NAMELEN PBR_MAP_NAMELEN + 10
30
31 extern struct hash *pbr_nhg_hash;
32
33 struct pbr_nexthop_group_cache {
34 char name[PBR_NHC_NAMELEN];
35
36 uint32_t table_id;
37
38 struct hash *nhh;
39
40 /*
41 * If all nexthops are considered valid
42 */
43 bool valid;
44
45 bool installed;
46 };
47
48 struct pbr_nexthop_cache {
49 struct pbr_nexthop_group_cache *parent;
50
51 char vrf_name[VRF_NAMSIZ + 1];
52 char intf_name[INTERFACE_NAMSIZ + 1];
53
54 struct nexthop nexthop;
55
56 bool looked_at;
57 bool valid;
58 bool nhr_matched;
59 };
60
61 extern void pbr_nht_write_table_range(struct vty *vty);
62 #define PBR_NHT_DEFAULT_LOW_TABLEID 10000
63 #define PBR_NHT_DEFAULT_HIGH_TABLEID 11000
64 extern void pbr_nht_set_tableid_range(uint32_t low, uint32_t high);
65
66 /*
67 * Find and reserve the next available table for installation;
68 * Sequential calls to this function will reserve sequential table numbers
69 * until the configured range is exhausted; calls made after exhaustion always
70 * return 0
71 */
72 extern uint32_t
73 pbr_nht_reserve_next_table_id(struct pbr_nexthop_group_cache *nhgc);
74 /*
75 * Get the next tableid to use for installation to kernel
76 */
77 extern uint32_t pbr_nht_find_next_unallocated_table_id(void);
78 /*
79 * Calculate where the next table representing a nhg will go in kernel
80 */
81 extern void pbr_nht_update_next_unallocated_table_id(void);
82 /*
83 * Indicate if there are free spots to install a table to kernel within the
84 * configured PBR table range
85 */
86 extern bool pbr_nht_has_unallocated_table(void);
87 /*
88 * Get the next rule number to use for installation
89 */
90 extern void pbr_nht_write_rule_range(struct vty *vty);
91
92 #define PBR_NHT_DEFAULT_LOW_RULE 300
93 #define PBR_NHT_DEFAULT_HIGH_RULE 1300
94 extern void pbr_nht_set_rule_range(uint32_t low, uint32_t high);
95
96 extern uint32_t pbr_nht_get_next_rule(uint32_t seqno);
97
98 extern void pbr_nhgroup_add_cb(const char *name);
99 extern void pbr_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc);
100 extern void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhg,
101 const struct nexthop *nhop);
102 extern void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhg,
103 const struct nexthop *nhop);
104 extern void pbr_nhgroup_delete_cb(const char *name);
105
106 extern bool pbr_nht_nexthop_valid(struct nexthop_group *nhg);
107 extern bool pbr_nht_nexthop_group_valid(const char *name);
108
109 extern struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name);
110 extern void pbr_nht_change_group(const char *name);
111 extern void pbr_nht_delete_group(const char *name);
112
113 extern void pbr_nht_set_seq_nhg_data(struct pbr_map_sequence *pbrms,
114 const struct nexthop_group_cmd *nhgc);
115 extern void pbr_nht_set_seq_nhg(struct pbr_map_sequence *pbrms,
116 const char *name);
117
118 extern void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms,
119 const struct nexthop *nhop);
120 extern void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms);
121 /*
122 * Given the tableid of the installed default
123 * route, find the nexthop-group associated with
124 * it, then find all pbr-maps that use it and
125 * install/delete them as well.
126 */
127 extern void pbr_nht_route_installed_for_table(uint32_t table_id);
128 extern void pbr_nht_route_removed_for_table(uint32_t table_id);
129
130 /*
131 * Given the nexthop group name, lookup the associated
132 * tableid with it
133 */
134 extern uint32_t pbr_nht_get_table(const char *name);
135
136 extern bool pbr_nht_get_installed(const char *name);
137
138 extern char *pbr_nht_nexthop_make_name(char *name, size_t l, uint32_t seqno,
139 char *buffer);
140
141 extern void pbr_nht_show_nexthop_group(struct vty *vty, const char *name);
142 extern void pbr_nht_json_nexthop_group(json_object *j, const char *name);
143
144 /*
145 * When we get a callback from zebra about a nexthop changing
146 */
147 extern void pbr_nht_nexthop_update(struct zapi_route *nhr);
148
149 /*
150 * When we get a callback from zebra about an interface status update.
151 */
152 extern void pbr_nht_nexthop_interface_update(struct interface *ifp);
153
154 extern void pbr_nht_init(void);
155
156 extern void pbr_nht_vrf_update(struct pbr_vrf *pbr_vrf);
157 extern void pbr_nht_interface_update(struct interface *ifp);
158 #endif