]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
e5c83d9b DS |
2 | /* |
3 | * PBR-nht Header | |
4 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
5 | * Donald Sharp | |
e5c83d9b DS |
6 | */ |
7 | #ifndef __PBR_NHT_H__ | |
8 | #define __PBR_NHT_H__ | |
9 | ||
10 | #include <lib/zclient.h> | |
11 | #include <lib/nexthop_group.h> | |
12 | ||
b13e5ad6 | 13 | #include "pbr_map.h" |
010dd8ed | 14 | #include "json.h" |
b13e5ad6 | 15 | |
06210d1f DS |
16 | #define PBR_NHC_NAMELEN PBR_MAP_NAMELEN + 10 |
17 | ||
fcf29c69 DS |
18 | extern struct hash *pbr_nhg_hash; |
19 | ||
e5c83d9b | 20 | struct pbr_nexthop_group_cache { |
06210d1f | 21 | char name[PBR_NHC_NAMELEN]; |
e5c83d9b DS |
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 | ||
fcf29c69 | 38 | char vrf_name[VRF_NAMSIZ + 1]; |
7cbdabff | 39 | char intf_name[INTERFACE_NAMSIZ + 1]; |
fcf29c69 | 40 | |
734bf907 | 41 | struct nexthop nexthop; |
e5c83d9b | 42 | |
9d961247 | 43 | bool looked_at; |
e5c83d9b | 44 | bool valid; |
c59f754d | 45 | bool nhr_matched; |
e5c83d9b DS |
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 | /* | |
389571aa WC |
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 | |
e5c83d9b | 72 | */ |
389571aa | 73 | extern bool pbr_nht_has_unallocated_table(void); |
e5c83d9b DS |
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); | |
f3c6dd49 | 86 | extern void pbr_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc); |
e5c83d9b DS |
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 | ||
b13e5ad6 | 96 | extern struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name); |
e5c83d9b DS |
97 | extern void pbr_nht_change_group(const char *name); |
98 | extern void pbr_nht_delete_group(const char *name); | |
99 | ||
9a7ea213 SW |
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 | ||
f143cffa SW |
105 | extern void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms, |
106 | const struct nexthop *nhop); | |
b13e5ad6 | 107 | extern void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms); |
e5c83d9b DS |
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); | |
010dd8ed | 129 | extern void pbr_nht_json_nexthop_group(json_object *j, const char *name); |
e5c83d9b DS |
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 | ||
a106a408 RW |
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 | ||
e5c83d9b | 141 | extern void pbr_nht_init(void); |
fcf29c69 DS |
142 | |
143 | extern void pbr_nht_vrf_update(struct pbr_vrf *pbr_vrf); | |
7cbdabff | 144 | extern void pbr_nht_interface_update(struct interface *ifp); |
e5c83d9b | 145 | #endif |