]> git.proxmox.com Git - mirror_frr.git/blob - pbrd/pbr_nht.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pbrd / pbr_nht.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * PBR-nht Header
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Donald Sharp
6 */
7 #ifndef __PBR_NHT_H__
8 #define __PBR_NHT_H__
9
10 #include <lib/zclient.h>
11 #include <lib/nexthop_group.h>
12
13 #include "pbr_map.h"
14 #include "json.h"
15
16 #define PBR_NHC_NAMELEN PBR_MAP_NAMELEN + 10
17
18 extern struct hash *pbr_nhg_hash;
19
20 struct pbr_nexthop_group_cache {
21 char name[PBR_NHC_NAMELEN];
22
23 uint32_t table_id;
24
25 struct hash *nhh;
26
27 /*
28 * If all nexthops are considered valid
29 */
30 bool valid;
31
32 bool installed;
33 };
34
35 struct pbr_nexthop_cache {
36 struct pbr_nexthop_group_cache *parent;
37
38 char vrf_name[VRF_NAMSIZ + 1];
39 char intf_name[INTERFACE_NAMSIZ + 1];
40
41 struct nexthop nexthop;
42
43 bool looked_at;
44 bool valid;
45 bool nhr_matched;
46 };
47
48 extern void pbr_nht_write_table_range(struct vty *vty);
49 #define PBR_NHT_DEFAULT_LOW_TABLEID 10000
50 #define PBR_NHT_DEFAULT_HIGH_TABLEID 11000
51 extern void pbr_nht_set_tableid_range(uint32_t low, uint32_t high);
52
53 /*
54 * Find and reserve the next available table for installation;
55 * Sequential calls to this function will reserve sequential table numbers
56 * until the configured range is exhausted; calls made after exhaustion always
57 * return 0
58 */
59 extern uint32_t
60 pbr_nht_reserve_next_table_id(struct pbr_nexthop_group_cache *nhgc);
61 /*
62 * Get the next tableid to use for installation to kernel
63 */
64 extern uint32_t pbr_nht_find_next_unallocated_table_id(void);
65 /*
66 * Calculate where the next table representing a nhg will go in kernel
67 */
68 extern void pbr_nht_update_next_unallocated_table_id(void);
69 /*
70 * Indicate if there are free spots to install a table to kernel within the
71 * configured PBR table range
72 */
73 extern bool pbr_nht_has_unallocated_table(void);
74 /*
75 * Get the next rule number to use for installation
76 */
77 extern void pbr_nht_write_rule_range(struct vty *vty);
78
79 #define PBR_NHT_DEFAULT_LOW_RULE 300
80 #define PBR_NHT_DEFAULT_HIGH_RULE 1300
81 extern void pbr_nht_set_rule_range(uint32_t low, uint32_t high);
82
83 extern uint32_t pbr_nht_get_next_rule(uint32_t seqno);
84
85 extern void pbr_nhgroup_add_cb(const char *name);
86 extern void pbr_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc);
87 extern void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhg,
88 const struct nexthop *nhop);
89 extern void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhg,
90 const struct nexthop *nhop);
91 extern void pbr_nhgroup_delete_cb(const char *name);
92
93 extern bool pbr_nht_nexthop_valid(struct nexthop_group *nhg);
94 extern bool pbr_nht_nexthop_group_valid(const char *name);
95
96 extern struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name);
97 extern void pbr_nht_change_group(const char *name);
98 extern void pbr_nht_delete_group(const char *name);
99
100 extern void pbr_nht_set_seq_nhg_data(struct pbr_map_sequence *pbrms,
101 const struct nexthop_group_cmd *nhgc);
102 extern void pbr_nht_set_seq_nhg(struct pbr_map_sequence *pbrms,
103 const char *name);
104
105 extern void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms,
106 const struct nexthop *nhop);
107 extern void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms);
108 /*
109 * Given the tableid of the installed default
110 * route, find the nexthop-group associated with
111 * it, then find all pbr-maps that use it and
112 * install/delete them as well.
113 */
114 extern void pbr_nht_route_installed_for_table(uint32_t table_id);
115 extern void pbr_nht_route_removed_for_table(uint32_t table_id);
116
117 /*
118 * Given the nexthop group name, lookup the associated
119 * tableid with it
120 */
121 extern uint32_t pbr_nht_get_table(const char *name);
122
123 extern bool pbr_nht_get_installed(const char *name);
124
125 extern char *pbr_nht_nexthop_make_name(char *name, size_t l, uint32_t seqno,
126 char *buffer);
127
128 extern void pbr_nht_show_nexthop_group(struct vty *vty, const char *name);
129 extern void pbr_nht_json_nexthop_group(json_object *j, const char *name);
130
131 /*
132 * When we get a callback from zebra about a nexthop changing
133 */
134 extern void pbr_nht_nexthop_update(struct zapi_route *nhr);
135
136 /*
137 * When we get a callback from zebra about an interface status update.
138 */
139 extern void pbr_nht_nexthop_interface_update(struct interface *ifp);
140
141 extern void pbr_nht_init(void);
142
143 extern void pbr_nht_vrf_update(struct pbr_vrf *pbr_vrf);
144 extern void pbr_nht_interface_update(struct interface *ifp);
145 #endif