]> git.proxmox.com Git - mirror_frr.git/blame - pbrd/pbr_zebra.c
*: convert zclient callbacks to table
[mirror_frr.git] / pbrd / pbr_zebra.c
CommitLineData
e5c83d9b
DS
1/*
2 * Zebra connect code.
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#include <zebra.h>
21
22#include "thread.h"
23#include "command.h"
24#include "network.h"
25#include "prefix.h"
26#include "routemap.h"
27#include "table.h"
28#include "stream.h"
29#include "memory.h"
30#include "zclient.h"
31#include "filter.h"
32#include "plist.h"
33#include "log.h"
34#include "nexthop.h"
35#include "nexthop_group.h"
36
37#include "pbr_nht.h"
38#include "pbr_map.h"
39#include "pbr_memory.h"
40#include "pbr_zebra.h"
41#include "pbr_debug.h"
be3b67b5 42#include "pbr_vrf.h"
e5c83d9b 43
bf8d3d6a 44DEFINE_MTYPE_STATIC(PBRD, PBR_INTERFACE, "PBR Interface");
e5c83d9b
DS
45
46/* Zebra structure to hold current status. */
d3765386 47struct zclient *zclient;
e5c83d9b 48
b13e5ad6 49struct pbr_interface *pbr_if_new(struct interface *ifp)
e5c83d9b
DS
50{
51 struct pbr_interface *pbr_ifp;
52
642ac49d
DL
53 assert(ifp);
54 assert(!ifp->info);
e5c83d9b
DS
55
56 pbr_ifp = XCALLOC(MTYPE_PBR_INTERFACE, sizeof(*pbr_ifp));
57
10a00758
DS
58 ifp->info = pbr_ifp;
59 return pbr_ifp;
e5c83d9b
DS
60}
61
0e7d7358
DS
62void pbr_if_del(struct interface *ifp)
63{
64 XFREE(MTYPE_PBR_INTERFACE, ifp->info);
65}
66
e5c83d9b 67/* Inteface addition message from zebra. */
ef7bd2a3 68int pbr_ifp_create(struct interface *ifp)
e5c83d9b 69{
15569c58 70 DEBUGD(&pbr_dbg_zebra, "%s: %s", __func__, ifp->name);
2f61710b 71
10a00758
DS
72 if (!ifp->info)
73 pbr_if_new(ifp);
e5c83d9b 74
7cbdabff 75 pbr_nht_interface_update(ifp);
be3b67b5 76 /* Update nexthops tracked from a `set nexthop` command */
a106a408
RW
77 pbr_nht_nexthop_interface_update(ifp);
78
be3b67b5
SW
79 pbr_map_policy_interface_update(ifp, true);
80
e5c83d9b
DS
81 return 0;
82}
83
3c3c3252 84int pbr_ifp_destroy(struct interface *ifp)
e5c83d9b 85{
15569c58 86 DEBUGD(&pbr_dbg_zebra, "%s: %s", __func__, ifp->name);
2f61710b 87
be3b67b5
SW
88 pbr_map_policy_interface_update(ifp, false);
89
e5c83d9b
DS
90 return 0;
91}
92
121f9dee 93static int interface_address_add(ZAPI_CALLBACK_ARGS)
e5c83d9b 94{
2f61710b
DS
95 struct connected *c;
96 char buf[PREFIX_STRLEN];
97
121f9dee 98 c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
2f61710b 99
15569c58 100 DEBUGD(&pbr_dbg_zebra, "%s: %s added %s", __func__,
964c3dba
DS
101 c ? c->ifp->name : "Unknown",
102 c ? prefix2str(c->address, buf, sizeof(buf)) : "Unknown");
e5c83d9b
DS
103
104 return 0;
105}
106
121f9dee 107static int interface_address_delete(ZAPI_CALLBACK_ARGS)
e5c83d9b
DS
108{
109 struct connected *c;
110
121f9dee 111 c = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
e5c83d9b
DS
112
113 if (!c)
114 return 0;
115
2dbe669b
DA
116 DEBUGD(&pbr_dbg_zebra, "%s: %s deleted %pFX", __func__, c->ifp->name,
117 c->address);
2f61710b 118
721c0857 119 connected_free(&c);
e5c83d9b
DS
120 return 0;
121}
122
ddbf3e60 123int pbr_ifp_up(struct interface *ifp)
e5c83d9b 124{
15569c58 125 DEBUGD(&pbr_dbg_zebra, "%s: %s is up", __func__, ifp->name);
e5c83d9b 126
a106a408
RW
127 pbr_nht_nexthop_interface_update(ifp);
128
e5c83d9b
DS
129 return 0;
130}
131
b0b69e59 132int pbr_ifp_down(struct interface *ifp)
e5c83d9b 133{
15569c58 134 DEBUGD(&pbr_dbg_zebra, "%s: %s is down", __func__, ifp->name);
e5c83d9b 135
a106a408
RW
136 pbr_nht_nexthop_interface_update(ifp);
137
e5c83d9b
DS
138 return 0;
139}
140
be3b67b5
SW
141static int interface_vrf_update(ZAPI_CALLBACK_ARGS)
142{
143 struct interface *ifp;
144 vrf_id_t new_vrf_id;
145
146 ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
147 &new_vrf_id);
148
149 if (!ifp) {
150 DEBUGD(&pbr_dbg_zebra, "%s: VRF change interface not found",
151 __func__);
152
153 return 0;
154 }
155
156 DEBUGD(&pbr_dbg_zebra, "%s: %s VRF change %u -> %u", __func__,
157 ifp->name, vrf_id, new_vrf_id);
158
159 if_update_to_new_vrf(ifp, new_vrf_id);
160
161 return 0;
162}
163
121f9dee 164static int route_notify_owner(ZAPI_CALLBACK_ARGS)
e5c83d9b
DS
165{
166 struct prefix p;
167 enum zapi_route_notify_owner note;
168 uint32_t table_id;
e5c83d9b 169
77b38a4a
S
170 if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, &note,
171 NULL, NULL))
e5c83d9b
DS
172 return -1;
173
174 switch (note) {
175 case ZAPI_ROUTE_FAIL_INSTALL:
176 DEBUGD(&pbr_dbg_zebra,
2dbe669b
DA
177 "%s: [%pFX] Route install failure for table: %u",
178 __func__, &p, table_id);
e5c83d9b
DS
179 break;
180 case ZAPI_ROUTE_BETTER_ADMIN_WON:
181 DEBUGD(&pbr_dbg_zebra,
2dbe669b
DA
182 "%s: [%pFX] Route better admin distance won for table: %u",
183 __func__, &p, table_id);
e5c83d9b
DS
184 break;
185 case ZAPI_ROUTE_INSTALLED:
186 DEBUGD(&pbr_dbg_zebra,
2dbe669b
DA
187 "%s: [%pFX] Route installed succeeded for table: %u",
188 __func__, &p, table_id);
e5c83d9b
DS
189 pbr_nht_route_installed_for_table(table_id);
190 break;
191 case ZAPI_ROUTE_REMOVED:
192 DEBUGD(&pbr_dbg_zebra,
2dbe669b
DA
193 "%s: [%pFX] Route Removed succeeded for table: %u",
194 __func__, &p, table_id);
e5c83d9b
DS
195 pbr_nht_route_removed_for_table(table_id);
196 break;
197 case ZAPI_ROUTE_REMOVE_FAIL:
198 DEBUGD(&pbr_dbg_zebra,
2dbe669b
DA
199 "%s: [%pFX] Route remove fail for table: %u", __func__,
200 &p, table_id);
e5c83d9b
DS
201 break;
202 }
203
204 return 0;
205}
206
121f9dee 207static int rule_notify_owner(ZAPI_CALLBACK_ARGS)
e5c83d9b
DS
208{
209 uint32_t seqno, priority, unique;
210 enum zapi_rule_notify_owner note;
211 struct pbr_map_sequence *pbrms;
37c606ff 212 struct pbr_map_interface *pmi;
58a1d249 213 char ifname[INTERFACE_NAMSIZ + 1];
37c606ff 214 uint64_t installed;
e5c83d9b
DS
215
216 if (!zapi_rule_notify_decode(zclient->ibuf, &seqno, &priority, &unique,
58a1d249 217 ifname, &note))
e5c83d9b
DS
218 return -1;
219
37c606ff 220 pmi = NULL;
58a1d249 221 pbrms = pbrms_lookup_unique(unique, ifname, &pmi);
e5c83d9b
DS
222 if (!pbrms) {
223 DEBUGD(&pbr_dbg_zebra,
15569c58
DA
224 "%s: Failure to lookup pbrms based upon %u", __func__,
225 unique);
e5c83d9b
DS
226 return 0;
227 }
228
37c606ff
DS
229 installed = 1 << pmi->install_bit;
230
e5c83d9b
DS
231 switch (note) {
232 case ZAPI_RULE_FAIL_INSTALL:
37c606ff 233 pbrms->installed &= ~installed;
e5c83d9b
DS
234 break;
235 case ZAPI_RULE_INSTALLED:
37c606ff 236 pbrms->installed |= installed;
e5c83d9b 237 break;
373dd3b5 238 case ZAPI_RULE_FAIL_REMOVE:
fde8af8d 239 /* Don't change state on rule removal failure */
fde8af8d 240 break;
e5c83d9b 241 case ZAPI_RULE_REMOVED:
0f03639d 242 pbrms->installed &= ~installed;
e5c83d9b
DS
243 break;
244 }
245
23e8679f
SW
246 DEBUGD(&pbr_dbg_zebra, "%s: Received %s: %" PRIu64, __func__,
247 zapi_rule_notify_owner2str(note), pbrms->installed);
248
38e9ccde
DS
249 pbr_map_final_interface_deletion(pbrms->parent, pmi);
250
e5c83d9b
DS
251 return 0;
252}
253
254static void zebra_connected(struct zclient *zclient)
255{
15569c58 256 DEBUGD(&pbr_dbg_zebra, "%s: Registering for fun and profit", __func__);
e5c83d9b
DS
257 zclient_send_reg_requests(zclient, VRF_DEFAULT);
258}
259
260static void route_add_helper(struct zapi_route *api, struct nexthop_group nhg,
261 uint8_t install_afi)
262{
263 struct zapi_nexthop *api_nh;
264 struct nexthop *nhop;
265 int i;
266
267 api->prefix.family = install_afi;
268
1d5453d6 269 DEBUGD(&pbr_dbg_zebra, " Encoding %pFX", &api->prefix);
2f61710b 270
e5c83d9b
DS
271 i = 0;
272 for (ALL_NEXTHOPS(nhg, nhop)) {
273 api_nh = &api->nexthops[i];
274 api_nh->vrf_id = nhop->vrf_id;
275 api_nh->type = nhop->type;
bd054c1a 276 api_nh->weight = nhop->weight;
e5c83d9b
DS
277 switch (nhop->type) {
278 case NEXTHOP_TYPE_IPV4:
279 api_nh->gate.ipv4 = nhop->gate.ipv4;
280 break;
281 case NEXTHOP_TYPE_IPV4_IFINDEX:
282 api_nh->gate.ipv4 = nhop->gate.ipv4;
283 api_nh->ifindex = nhop->ifindex;
284 break;
285 case NEXTHOP_TYPE_IFINDEX:
286 api_nh->ifindex = nhop->ifindex;
287 break;
288 case NEXTHOP_TYPE_IPV6:
8643c2e5
DA
289 memcpy(&api_nh->gate.ipv6, &nhop->gate.ipv6,
290 IPV6_MAX_BYTELEN);
e5c83d9b
DS
291 break;
292 case NEXTHOP_TYPE_IPV6_IFINDEX:
293 api_nh->ifindex = nhop->ifindex;
8643c2e5
DA
294 memcpy(&api_nh->gate.ipv6, &nhop->gate.ipv6,
295 IPV6_MAX_BYTELEN);
e5c83d9b
DS
296 break;
297 case NEXTHOP_TYPE_BLACKHOLE:
298 api_nh->bh_type = nhop->bh_type;
299 break;
300 }
301 i++;
302 }
303 api->nexthop_num = i;
304
305 zclient_route_send(ZEBRA_ROUTE_ADD, zclient, api);
306}
307
308/*
309 * This function assumes a default route is being
310 * installed into the appropriate tableid
311 */
312void route_add(struct pbr_nexthop_group_cache *pnhgc, struct nexthop_group nhg,
313 afi_t install_afi)
314{
315 struct zapi_route api;
316
15569c58 317 DEBUGD(&pbr_dbg_zebra, "%s for Table: %d", __func__, pnhgc->table_id);
2f61710b 318
e5c83d9b
DS
319 memset(&api, 0, sizeof(api));
320
321 api.vrf_id = VRF_DEFAULT;
322 api.type = ZEBRA_ROUTE_PBR;
323 api.safi = SAFI_UNICAST;
324 /*
325 * Sending a default route
326 */
327 api.tableid = pnhgc->table_id;
328 SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
329 SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID);
330 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
331 switch (install_afi) {
332 case AFI_MAX:
333 route_add_helper(&api, nhg, AF_INET);
334 route_add_helper(&api, nhg, AF_INET6);
335 break;
336 case AFI_IP:
337 route_add_helper(&api, nhg, AF_INET);
338 break;
339 case AFI_IP6:
340 route_add_helper(&api, nhg, AF_INET6);
341 break;
342 case AFI_L2VPN:
343 DEBUGD(&pbr_dbg_zebra,
344 "%s: Asked to install unsupported route type: L2VPN",
15569c58 345 __func__);
e5c83d9b 346 break;
b26f891d
SW
347 case AFI_UNSPEC:
348 DEBUGD(&pbr_dbg_zebra,
15569c58 349 "%s: Asked to install unspecified route type", __func__);
b26f891d 350 break;
e5c83d9b
DS
351 }
352}
353
354/*
355 * This function assumes a default route is being
356 * removed from the appropriate tableid
357 */
358void route_delete(struct pbr_nexthop_group_cache *pnhgc, afi_t afi)
359{
360 struct zapi_route api;
361
15569c58 362 DEBUGD(&pbr_dbg_zebra, "%s for Table: %d", __func__, pnhgc->table_id);
2f61710b 363
e5c83d9b
DS
364 memset(&api, 0, sizeof(api));
365 api.vrf_id = VRF_DEFAULT;
366 api.type = ZEBRA_ROUTE_PBR;
367 api.safi = SAFI_UNICAST;
368
369 api.tableid = pnhgc->table_id;
370 SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID);
371
372 switch (afi) {
373 case AFI_IP:
374 api.prefix.family = AF_INET;
375 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
376 break;
377 case AFI_IP6:
378 api.prefix.family = AF_INET6;
379 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
380 break;
381 case AFI_MAX:
382 api.prefix.family = AF_INET;
383 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
384 api.prefix.family = AF_INET6;
385 zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
386 break;
387 case AFI_L2VPN:
388 DEBUGD(&pbr_dbg_zebra,
389 "%s: Asked to delete unsupported route type: L2VPN",
15569c58 390 __func__);
e5c83d9b 391 break;
b26f891d
SW
392 case AFI_UNSPEC:
393 DEBUGD(&pbr_dbg_zebra,
15569c58 394 "%s: Asked to delete unspecified route type", __func__);
b26f891d 395 break;
e5c83d9b 396 }
e5c83d9b
DS
397}
398
121f9dee 399static int pbr_zebra_nexthop_update(ZAPI_CALLBACK_ARGS)
e5c83d9b
DS
400{
401 struct zapi_route nhr;
e5c83d9b
DS
402 uint32_t i;
403
54317f2c 404 if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) {
6c83dded 405 zlog_err("Failure to decode Nexthop update message");
54317f2c
A
406 return 0;
407 }
e5c83d9b
DS
408
409 if (DEBUG_MODE_CHECK(&pbr_dbg_zebra, DEBUG_MODE_ALL)) {
410
2dbe669b
DA
411 DEBUGD(&pbr_dbg_zebra, "%s: Received Nexthop update: %pFX",
412 __func__, &nhr.prefix);
e5c83d9b 413
1d5453d6 414 DEBUGD(&pbr_dbg_zebra, "%s: (Nexthops(%u)", __func__,
15569c58 415 nhr.nexthop_num);
e5c83d9b
DS
416
417 for (i = 0; i < nhr.nexthop_num; i++) {
418 DEBUGD(&pbr_dbg_zebra,
1d5453d6 419 "%s: Type: %d: vrf: %d, ifindex: %d gate: %pI4",
15569c58 420 __func__, nhr.nexthops[i].type,
e5c83d9b 421 nhr.nexthops[i].vrf_id, nhr.nexthops[i].ifindex,
9904db41 422 &nhr.nexthops[i].gate.ipv4);
e5c83d9b
DS
423 }
424 }
425
426 pbr_nht_nexthop_update(&nhr);
427 return 1;
428}
429
430extern struct zebra_privs_t pbr_privs;
431
a243d1db
DL
432static zclient_handler *const pbr_handlers[] = {
433 [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add,
434 [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete,
435 [ZEBRA_INTERFACE_VRF_UPDATE] = interface_vrf_update,
436 [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner,
437 [ZEBRA_RULE_NOTIFY_OWNER] = rule_notify_owner,
438 [ZEBRA_NEXTHOP_UPDATE] = pbr_zebra_nexthop_update,
439};
440
e5c83d9b
DS
441void pbr_zebra_init(void)
442{
443 struct zclient_options opt = { .receive_notify = true };
444
a243d1db
DL
445 zclient = zclient_new(master, &opt, pbr_handlers,
446 array_size(pbr_handlers));
e5c83d9b
DS
447
448 zclient_init(zclient, ZEBRA_ROUTE_PBR, 0, &pbr_privs);
449 zclient->zebra_connected = zebra_connected;
e5c83d9b
DS
450}
451
452void pbr_send_rnh(struct nexthop *nhop, bool reg)
453{
454 uint32_t command;
455 struct prefix p;
456
457 command = (reg) ?
458 ZEBRA_NEXTHOP_REGISTER : ZEBRA_NEXTHOP_UNREGISTER;
459
460 memset(&p, 0, sizeof(p));
d3765386 461 switch (nhop->type) {
e5c83d9b
DS
462 case NEXTHOP_TYPE_IFINDEX:
463 case NEXTHOP_TYPE_BLACKHOLE:
464 return;
465 case NEXTHOP_TYPE_IPV4:
466 case NEXTHOP_TYPE_IPV4_IFINDEX:
467 p.family = AF_INET;
468 p.u.prefix4.s_addr = nhop->gate.ipv4.s_addr;
12256b84 469 p.prefixlen = IPV4_MAX_BITLEN;
e5c83d9b
DS
470 break;
471 case NEXTHOP_TYPE_IPV6:
472 case NEXTHOP_TYPE_IPV6_IFINDEX:
473 p.family = AF_INET6;
8643c2e5 474 memcpy(&p.u.prefix6, &nhop->gate.ipv6, IPV6_MAX_BYTELEN);
13ccce6e 475 p.prefixlen = IPV6_MAX_BITLEN;
cb254f41
SW
476 if (IN6_IS_ADDR_LINKLOCAL(&nhop->gate.ipv6))
477 /*
478 * Don't bother tracking link locals, just track their
479 * interface state.
480 */
481 return;
e5c83d9b
DS
482 break;
483 }
484
ed6cec97 485 if (zclient_send_rnh(zclient, command, &p, false, false, nhop->vrf_id)
7cfdb485 486 == ZCLIENT_SEND_FAILURE) {
15569c58 487 zlog_warn("%s: Failure to send nexthop to zebra", __func__);
e5c83d9b
DS
488 }
489}
490
491static void pbr_encode_pbr_map_sequence_prefix(struct stream *s,
492 struct prefix *p,
49027ce8 493 unsigned char family)
e5c83d9b
DS
494{
495 struct prefix any;
496
497 if (!p) {
498 memset(&any, 0, sizeof(any));
499 any.family = family;
500 p = &any;
501 }
502
503 stream_putc(s, p->family);
504 stream_putc(s, p->prefixlen);
505 stream_put(s, &p->u.prefix, prefix_blen(p));
506}
507
be3b67b5
SW
508static void
509pbr_encode_pbr_map_sequence_vrf(struct stream *s,
510 const struct pbr_map_sequence *pbrms,
511 const struct interface *ifp)
512{
513 struct pbr_vrf *pbr_vrf;
514
515 if (pbrms->vrf_unchanged)
516 pbr_vrf = pbr_vrf_lookup_by_id(ifp->vrf_id);
517 else
518 pbr_vrf = pbr_vrf_lookup_by_name(pbrms->vrf_name);
519
520 if (!pbr_vrf) {
521 DEBUGD(&pbr_dbg_zebra, "%s: VRF not found", __func__);
522 return;
523 }
524
525 stream_putl(s, pbr_vrf->vrf->data.l.table_id);
526}
527
e5c83d9b
DS
528static void pbr_encode_pbr_map_sequence(struct stream *s,
529 struct pbr_map_sequence *pbrms,
530 struct interface *ifp)
531{
49027ce8 532 unsigned char family;
e5c83d9b
DS
533
534 family = AF_INET;
49027ce8
DS
535 if (pbrms->family)
536 family = pbrms->family;
e5c83d9b
DS
537
538 stream_putl(s, pbrms->seqno);
539 stream_putl(s, pbrms->ruleno);
540 stream_putl(s, pbrms->unique);
5e732768 541 stream_putc(s, pbrms->ip_proto); /* The ip_proto */
e5c83d9b 542 pbr_encode_pbr_map_sequence_prefix(s, pbrms->src, family);
0d7b939f 543 stream_putw(s, pbrms->src_prt);
e5c83d9b 544 pbr_encode_pbr_map_sequence_prefix(s, pbrms->dst, family);
0d7b939f 545 stream_putw(s, pbrms->dst_prt);
01f23aff 546 stream_putc(s, pbrms->dsfield);
95a9fe02 547 stream_putl(s, pbrms->mark);
be3b67b5
SW
548
549 if (pbrms->vrf_unchanged || pbrms->vrf_lookup)
550 pbr_encode_pbr_map_sequence_vrf(s, pbrms, ifp);
551 else if (pbrms->nhgrp_name)
e5c83d9b
DS
552 stream_putl(s, pbr_nht_get_table(pbrms->nhgrp_name));
553 else if (pbrms->nhg)
554 stream_putl(s, pbr_nht_get_table(pbrms->internal_nhg_name));
58a1d249 555 stream_put(s, ifp->name, INTERFACE_NAMSIZ);
e5c83d9b
DS
556}
557
5d06c5d5
SW
558bool pbr_send_pbr_map(struct pbr_map_sequence *pbrms,
559 struct pbr_map_interface *pmi, bool install, bool changed)
e5c83d9b 560{
b13e5ad6 561 struct pbr_map *pbrm = pbrms->parent;
e5c83d9b 562 struct stream *s;
10a00758 563 uint64_t is_installed = (uint64_t)1 << pmi->install_bit;
37c606ff
DS
564
565 is_installed &= pbrms->installed;
e5c83d9b 566
15569c58
DA
567 DEBUGD(&pbr_dbg_zebra, "%s: for %s %d(%" PRIu64 ")", __func__,
568 pbrm->name, install, is_installed);
9b71ea4b
DS
569
570 /*
f143cffa
SW
571 * If we are installed and asked to do so again and the config
572 * has not changed, just return.
573 *
574 * If we are not installed and asked
f732636d 575 * to delete just return.
9b71ea4b 576 */
f143cffa 577 if (install && is_installed && !changed)
5d06c5d5 578 return false;
9b71ea4b 579
37c606ff 580 if (!install && !is_installed)
5d06c5d5 581 return false;
e5c83d9b
DS
582
583 s = zclient->obuf;
584 stream_reset(s);
585
586 zclient_create_header(s,
587 install ? ZEBRA_RULE_ADD : ZEBRA_RULE_DELETE,
588 VRF_DEFAULT);
589
b13e5ad6
DS
590 /*
591 * We are sending one item at a time at the moment
592 */
593 stream_putl(s, 1);
e5c83d9b 594
1d5453d6 595 DEBUGD(&pbr_dbg_zebra, "%s: %s %s seq %u %d %s %u", __func__,
b21d3042
SW
596 install ? "Installing" : "Deleting", pbrm->name, pbrms->seqno,
597 install, pmi->ifp->name, pmi->delete);
e5c83d9b 598
b13e5ad6 599 pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp);
e5c83d9b 600
e5c83d9b
DS
601 stream_putw_at(s, 0, stream_get_endp(s));
602
e5c83d9b 603 zclient_send_message(zclient);
f08966a5 604
5d06c5d5 605 return true;
e5c83d9b 606}