]>
Commit | Line | Data |
---|---|---|
e5c83d9b DS |
1 | /* |
2 | * PBR-map 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_MAP_H__ | |
21 | #define __PBR_MAP_H__ | |
22 | ||
37c606ff DS |
23 | #include <bitfield.h> |
24 | ||
be3b67b5 SW |
25 | #include "pbr_vrf.h" |
26 | ||
e5c83d9b DS |
27 | struct pbr_map { |
28 | /* | |
29 | * RB Tree of the pbr_maps | |
30 | */ | |
31 | RB_ENTRY(pbr_map) pbr_map_entry; | |
32 | ||
33 | /* | |
34 | * The name of the PBR_MAP | |
35 | */ | |
36 | #define PBR_MAP_NAMELEN 100 | |
37 | char name[PBR_MAP_NAMELEN]; | |
38 | ||
39 | struct list *seqnumbers; | |
40 | ||
41 | /* | |
42 | * The list of incoming interfaces that | |
43 | * we will apply this policy map onto | |
44 | */ | |
45 | struct list *incoming; | |
46 | ||
37c606ff | 47 | bitfield_t ifi_bitfield; |
e5c83d9b DS |
48 | /* |
49 | * If valid is true we think the pbr_map is valid, | |
50 | * If false, look in individual pbrms to see | |
51 | * what we think is the invalid reason | |
52 | */ | |
53 | bool valid; | |
e5c83d9b DS |
54 | }; |
55 | ||
56 | RB_HEAD(pbr_map_entry_head, pbr_map); | |
57 | RB_PROTOTYPE(pbr_map_entry_head, pbr_map, pbr_map_entry, pbr_map_compare) | |
58 | ||
59 | struct pbr_map_interface { | |
37c606ff DS |
60 | uint32_t install_bit; |
61 | ||
e5c83d9b DS |
62 | struct interface *ifp; |
63 | ||
64 | struct pbr_map *pbrm; | |
65 | ||
66 | bool delete; | |
67 | }; | |
68 | ||
69 | struct pbr_map_sequence { | |
70 | struct pbr_map *parent; | |
71 | ||
72 | /* | |
73 | * The Unique identifier of this specific pbrms | |
74 | */ | |
75 | uint32_t unique; | |
76 | ||
77 | /* | |
78 | * The sequence of where we are for display | |
79 | */ | |
80 | uint32_t seqno; | |
81 | ||
82 | /* | |
83 | * The rule number to install into | |
84 | */ | |
85 | uint32_t ruleno; | |
86 | ||
0d7b939f DS |
87 | /* |
88 | * src and dst ports | |
89 | */ | |
90 | uint16_t src_prt; | |
91 | uint16_t dst_prt; | |
92 | ||
5e732768 DS |
93 | /* |
94 | * The ip protocol we want to match on | |
95 | */ | |
96 | uint8_t ip_proto; | |
97 | ||
e5c83d9b DS |
98 | /* |
99 | * Our policy Catchers | |
100 | */ | |
101 | struct prefix *src; | |
102 | struct prefix *dst; | |
01f23aff | 103 | uint8_t dsfield; |
95a9fe02 | 104 | uint32_t mark; |
e5c83d9b | 105 | |
d70a31a3 EB |
106 | /* |
107 | * Actions | |
108 | */ | |
109 | uint8_t action_pcp; | |
110 | uint8_t action_vlan_id; | |
111 | #define PBR_MAP_STRIP_INNER_ANY (1 << 0) | |
112 | uint8_t action_vlan_flags; | |
113 | ||
114 | #define PBR_MAP_UNDEFINED_QUEUE_ID 0 | |
115 | uint32_t action_queue_id; | |
116 | ||
49027ce8 DS |
117 | /* |
118 | * Family of the src/dst. Needed when deleting since we clear them | |
119 | */ | |
120 | unsigned char family; | |
121 | ||
be3b67b5 SW |
122 | /* |
123 | * Use interface's vrf. | |
124 | */ | |
125 | bool vrf_unchanged; | |
126 | ||
127 | /* | |
128 | * The vrf to lookup in was directly configured. | |
129 | */ | |
130 | bool vrf_lookup; | |
131 | ||
132 | /* | |
133 | * VRF to lookup. | |
134 | */ | |
135 | char vrf_name[VRF_NAMSIZ + 1]; | |
136 | ||
e5c83d9b DS |
137 | /* |
138 | * The nexthop group we auto create | |
139 | * for when the user specifies a individual | |
140 | * nexthop | |
141 | */ | |
142 | struct nexthop_group *nhg; | |
143 | char *internal_nhg_name; | |
144 | ||
145 | /* | |
146 | * The name of the nexthop group | |
147 | * configured in the pbr-map | |
148 | */ | |
149 | char *nhgrp_name; | |
150 | ||
151 | /* | |
152 | * Do we think are nexthops are installed | |
153 | */ | |
154 | bool nhs_installed; | |
155 | ||
b13e5ad6 DS |
156 | /* |
157 | * Are we installed | |
158 | */ | |
37c606ff | 159 | uint64_t installed; |
b13e5ad6 | 160 | |
e5c83d9b DS |
161 | /* |
162 | * A reason of 0 means we think the pbr_map_sequence is good to go | |
163 | * We can accumuluate multiple failure states | |
164 | */ | |
be3b67b5 SW |
165 | #define PBR_MAP_VALID_SEQUENCE_NUMBER 0 |
166 | #define PBR_MAP_INVALID_NEXTHOP_GROUP (1 << 0) | |
167 | #define PBR_MAP_INVALID_NEXTHOP (1 << 1) | |
168 | #define PBR_MAP_INVALID_NO_NEXTHOPS (1 << 2) | |
169 | #define PBR_MAP_INVALID_BOTH_NHANDGRP (1 << 3) | |
170 | #define PBR_MAP_INVALID_EMPTY (1 << 4) | |
171 | #define PBR_MAP_INVALID_VRF (1 << 5) | |
d70a31a3 | 172 | #define PBR_MAP_INVALID_SET_STRIP_VLAN (1 << 6) |
e5c83d9b DS |
173 | uint64_t reason; |
174 | ||
96244aca | 175 | QOBJ_FIELDS; |
e5c83d9b DS |
176 | }; |
177 | ||
96244aca | 178 | DECLARE_QOBJ_TYPE(pbr_map_sequence); |
e5c83d9b DS |
179 | |
180 | extern struct pbr_map_entry_head pbr_maps; | |
181 | ||
182 | extern struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno); | |
37c606ff | 183 | extern struct pbr_map_sequence * |
58a1d249 | 184 | pbrms_lookup_unique(uint32_t unique, char *ifname, |
37c606ff | 185 | struct pbr_map_interface **ppmi); |
e5c83d9b DS |
186 | |
187 | extern struct pbr_map *pbrm_find(const char *name); | |
b13e5ad6 | 188 | extern void pbr_map_delete(struct pbr_map_sequence *pbrms); |
be3b67b5 SW |
189 | extern void pbr_map_delete_nexthops(struct pbr_map_sequence *pbrms); |
190 | extern void pbr_map_delete_vrf(struct pbr_map_sequence *pbrms); | |
e5c83d9b DS |
191 | extern void pbr_map_add_interface(struct pbr_map *pbrm, struct interface *ifp); |
192 | extern void pbr_map_interface_delete(struct pbr_map *pbrm, | |
193 | struct interface *ifp); | |
be3b67b5 | 194 | |
116b86bd WC |
195 | extern uint8_t pbr_map_decode_dscp_enum(const char *name); |
196 | ||
be3b67b5 SW |
197 | /* Update maps installed on interface */ |
198 | extern void pbr_map_policy_interface_update(const struct interface *ifp, | |
199 | bool state_up); | |
200 | ||
38e9ccde DS |
201 | extern void pbr_map_final_interface_deletion(struct pbr_map *pbrm, |
202 | struct pbr_map_interface *pmi); | |
be3b67b5 SW |
203 | |
204 | extern void pbr_map_vrf_update(const struct pbr_vrf *pbr_vrf); | |
205 | ||
e5c83d9b DS |
206 | extern void pbr_map_write_interfaces(struct vty *vty, struct interface *ifp); |
207 | extern void pbr_map_init(void); | |
208 | ||
209 | extern bool pbr_map_check_valid(const char *name); | |
210 | ||
f143cffa SW |
211 | /** |
212 | * Re-check the pbr map for validity. | |
213 | * | |
214 | * Install if valid, remove if not. | |
215 | * | |
216 | * If changed is set, the config on the on the map has changed somewhere | |
217 | * and the rules need to be replaced if valid. | |
218 | */ | |
219 | extern void pbr_map_check(struct pbr_map_sequence *pbrms, bool changed); | |
e5c83d9b | 220 | extern void pbr_map_check_nh_group_change(const char *nh_group); |
e5c83d9b | 221 | extern void pbr_map_reason_string(unsigned int reason, char *buf, int size); |
e5c83d9b | 222 | |
09813729 SW |
223 | extern void pbr_map_schedule_policy_from_nhg(const char *nh_group, |
224 | bool installed); | |
e5c83d9b | 225 | |
b13e5ad6 | 226 | extern void pbr_map_install(struct pbr_map *pbrm); |
e5c83d9b DS |
227 | |
228 | extern void pbr_map_policy_install(const char *name); | |
b13e5ad6 DS |
229 | extern void pbr_map_policy_delete(struct pbr_map *pbrm, |
230 | struct pbr_map_interface *pmi); | |
fcf29c69 DS |
231 | |
232 | extern void pbr_map_check_vrf_nh_group_change(const char *nh_group, | |
233 | struct pbr_vrf *pbr_vrf, | |
234 | uint32_t old_vrf_id); | |
7cbdabff DS |
235 | extern void pbr_map_check_interface_nh_group_change(const char *nh_group, |
236 | struct interface *ifp, | |
237 | ifindex_t oldifindex); | |
e5c83d9b | 238 | #endif |