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