]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_updgrp_packet.c
Merge pull request #12235 from anlancs/fix/cleanup-22
[mirror_frr.git] / bgpd / bgp_updgrp_packet.c
1 /**
2 * bgp_updgrp_packet.c: BGP update group packet handling routines
3 *
4 * @copyright Copyright (C) 2014 Cumulus Networks, Inc.
5 *
6 * @author Avneesh Sachdev <avneesh@sproute.net>
7 * @author Rajesh Varadarajan <rajesh@sproute.net>
8 * @author Pradosh Mohapatra <pradosh@sproute.net>
9 *
10 * This file is part of GNU Zebra.
11 *
12 * GNU Zebra is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
16 *
17 * GNU Zebra is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; see the file COPYING; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include <zebra.h>
28
29 #include "prefix.h"
30 #include "thread.h"
31 #include "buffer.h"
32 #include "stream.h"
33 #include "command.h"
34 #include "sockunion.h"
35 #include "network.h"
36 #include "memory.h"
37 #include "filter.h"
38 #include "routemap.h"
39 #include "log.h"
40 #include "plist.h"
41 #include "linklist.h"
42 #include "workqueue.h"
43 #include "hash.h"
44 #include "queue.h"
45 #include "mpls.h"
46
47 #include "bgpd/bgpd.h"
48 #include "bgpd/bgp_debug.h"
49 #include "bgpd/bgp_errors.h"
50 #include "bgpd/bgp_fsm.h"
51 #include "bgpd/bgp_route.h"
52 #include "bgpd/bgp_packet.h"
53 #include "bgpd/bgp_advertise.h"
54 #include "bgpd/bgp_updgrp.h"
55 #include "bgpd/bgp_nexthop.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_mplsvpn.h"
58 #include "bgpd/bgp_label.h"
59 #include "bgpd/bgp_addpath.h"
60
61 /********************
62 * PRIVATE FUNCTIONS
63 ********************/
64
65 /********************
66 * PUBLIC FUNCTIONS
67 ********************/
68 struct bpacket *bpacket_alloc(void)
69 {
70 struct bpacket *pkt;
71
72 pkt = XCALLOC(MTYPE_BGP_PACKET, sizeof(struct bpacket));
73
74 return pkt;
75 }
76
77 void bpacket_free(struct bpacket *pkt)
78 {
79 if (pkt->buffer)
80 stream_free(pkt->buffer);
81 pkt->buffer = NULL;
82 XFREE(MTYPE_BGP_PACKET, pkt);
83 }
84
85 void bpacket_queue_init(struct bpacket_queue *q)
86 {
87 TAILQ_INIT(&(q->pkts));
88 }
89
90 /*
91 * bpacket_queue_add_packet
92 *
93 * Internal function of bpacket_queue - and adds a
94 * packet entry to the end of the list.
95 *
96 * Users of bpacket_queue should use bpacket_queue_add instead.
97 */
98 static void bpacket_queue_add_packet(struct bpacket_queue *q,
99 struct bpacket *pkt)
100 {
101 struct bpacket *last_pkt;
102
103 if (TAILQ_EMPTY(&(q->pkts)))
104 TAILQ_INSERT_TAIL(&(q->pkts), pkt, pkt_train);
105 else {
106 last_pkt = bpacket_queue_last(q);
107 TAILQ_INSERT_AFTER(&(q->pkts), last_pkt, pkt, pkt_train);
108 }
109 q->curr_count++;
110 if (q->hwm_count < q->curr_count)
111 q->hwm_count = q->curr_count;
112 }
113
114 /*
115 * Adds a packet to the bpacket_queue.
116 *
117 * The stream passed is consumed by this function. So, the caller should
118 * not free or use the stream after
119 * invoking this function.
120 */
121 struct bpacket *bpacket_queue_add(struct bpacket_queue *q, struct stream *s,
122 struct bpacket_attr_vec_arr *vecarrp)
123 {
124 struct bpacket *pkt;
125 struct bpacket *last_pkt;
126
127
128 pkt = bpacket_alloc();
129 if (TAILQ_EMPTY(&(q->pkts))) {
130 pkt->ver = 1;
131 pkt->buffer = s;
132 if (vecarrp)
133 memcpy(&pkt->arr, vecarrp,
134 sizeof(struct bpacket_attr_vec_arr));
135 else
136 bpacket_attr_vec_arr_reset(&pkt->arr);
137 bpacket_queue_add_packet(q, pkt);
138 return pkt;
139 }
140
141 /*
142 * Fill in the new information into the current sentinel and create a
143 * new sentinel.
144 */
145 last_pkt = bpacket_queue_last(q);
146 assert(last_pkt->buffer == NULL);
147 last_pkt->buffer = s;
148 if (vecarrp)
149 memcpy(&last_pkt->arr, vecarrp,
150 sizeof(struct bpacket_attr_vec_arr));
151 else
152 bpacket_attr_vec_arr_reset(&last_pkt->arr);
153
154 pkt->ver = last_pkt->ver;
155 pkt->ver++;
156 bpacket_queue_add_packet(q, pkt);
157
158 return last_pkt;
159 }
160
161 struct bpacket *bpacket_queue_first(struct bpacket_queue *q)
162 {
163 return (TAILQ_FIRST(&(q->pkts)));
164 }
165
166 struct bpacket *bpacket_queue_last(struct bpacket_queue *q)
167 {
168 return TAILQ_LAST(&(q->pkts), pkt_queue);
169 }
170
171 struct bpacket *bpacket_queue_remove(struct bpacket_queue *q)
172 {
173 struct bpacket *first;
174
175 first = bpacket_queue_first(q);
176 if (first) {
177 TAILQ_REMOVE(&(q->pkts), first, pkt_train);
178 q->curr_count--;
179 }
180 return first;
181 }
182
183 unsigned int bpacket_queue_length(struct bpacket_queue *q)
184 {
185 return q->curr_count - 1;
186 }
187
188 unsigned int bpacket_queue_hwm_length(struct bpacket_queue *q)
189 {
190 return q->hwm_count - 1;
191 }
192
193 bool bpacket_queue_is_full(struct bgp *bgp, struct bpacket_queue *q)
194 {
195 if (q->curr_count >= bgp->default_subgroup_pkt_queue_max)
196 return true;
197 return false;
198 }
199
200 void bpacket_add_peer(struct bpacket *pkt, struct peer_af *paf)
201 {
202 if (!pkt || !paf)
203 return;
204
205 LIST_INSERT_HEAD(&(pkt->peers), paf, pkt_train);
206 paf->next_pkt_to_send = pkt;
207 }
208
209 /*
210 * bpacket_queue_cleanup
211 */
212 void bpacket_queue_cleanup(struct bpacket_queue *q)
213 {
214 struct bpacket *pkt;
215
216 while ((pkt = bpacket_queue_remove(q))) {
217 bpacket_free(pkt);
218 }
219 }
220
221 /*
222 * bpacket_queue_compact
223 *
224 * Delete packets that do not need to be transmitted to any peer from
225 * the queue.
226 *
227 * @return the number of packets deleted.
228 */
229 static int bpacket_queue_compact(struct bpacket_queue *q)
230 {
231 int num_deleted;
232 struct bpacket *pkt, *removed_pkt;
233
234 num_deleted = 0;
235
236 while (1) {
237 pkt = bpacket_queue_first(q);
238 if (!pkt)
239 break;
240
241 /*
242 * Don't delete the sentinel.
243 */
244 if (!pkt->buffer)
245 break;
246
247 if (!LIST_EMPTY(&(pkt->peers)))
248 break;
249
250 removed_pkt = bpacket_queue_remove(q);
251 assert(pkt == removed_pkt);
252 bpacket_free(removed_pkt);
253
254 num_deleted++;
255 }
256
257 return num_deleted;
258 }
259
260 void bpacket_queue_advance_peer(struct peer_af *paf)
261 {
262 struct bpacket *pkt;
263 struct bpacket *old_pkt;
264
265 old_pkt = paf->next_pkt_to_send;
266 if (old_pkt->buffer == NULL)
267 /* Already at end of list */
268 return;
269
270 LIST_REMOVE(paf, pkt_train);
271 pkt = TAILQ_NEXT(old_pkt, pkt_train);
272 bpacket_add_peer(pkt, paf);
273
274 if (!bpacket_queue_compact(PAF_PKTQ(paf)))
275 return;
276
277 /*
278 * Deleted one or more packets. Check if we can now merge this
279 * peer's subgroup into another subgroup.
280 */
281 update_subgroup_check_merge(paf->subgroup, "advanced peer in queue");
282 }
283
284 /*
285 * bpacket_queue_remove_peer
286 *
287 * Remove the peer from the packet queue of the subgroup it belongs
288 * to.
289 */
290 void bpacket_queue_remove_peer(struct peer_af *paf)
291 {
292 struct bpacket_queue *q;
293
294 q = PAF_PKTQ(paf);
295 assert(q);
296
297 LIST_REMOVE(paf, pkt_train);
298 paf->next_pkt_to_send = NULL;
299
300 bpacket_queue_compact(q);
301 }
302
303 unsigned int bpacket_queue_virtual_length(struct peer_af *paf)
304 {
305 struct bpacket *pkt;
306 struct bpacket *last;
307 struct bpacket_queue *q;
308
309 pkt = paf->next_pkt_to_send;
310 if (!pkt || (pkt->buffer == NULL))
311 /* Already at end of list */
312 return 0;
313
314 q = PAF_PKTQ(paf);
315 if (TAILQ_EMPTY(&(q->pkts)))
316 return 0;
317
318 last = TAILQ_LAST(&(q->pkts), pkt_queue);
319 if (last->ver >= pkt->ver)
320 return last->ver - pkt->ver;
321
322 /* sequence # rolled over */
323 return (UINT_MAX - pkt->ver + 1) + last->ver;
324 }
325
326 /*
327 * Dump the bpacket queue
328 */
329 void bpacket_queue_show_vty(struct bpacket_queue *q, struct vty *vty)
330 {
331 struct bpacket *pkt;
332 struct peer_af *paf;
333
334 pkt = bpacket_queue_first(q);
335 while (pkt) {
336 vty_out(vty, " Packet %p ver %u buffer %p\n", pkt, pkt->ver,
337 pkt->buffer);
338
339 LIST_FOREACH (paf, &(pkt->peers), pkt_train) {
340 vty_out(vty, " - %s\n", paf->peer->host);
341 }
342 pkt = bpacket_next(pkt);
343 }
344 return;
345 }
346
347 struct stream *bpacket_reformat_for_peer(struct bpacket *pkt,
348 struct peer_af *paf)
349 {
350 struct stream *s = NULL;
351 bpacket_attr_vec *vec;
352 struct peer *peer;
353 struct bgp_filter *filter;
354
355 s = stream_dup(pkt->buffer);
356 peer = PAF_PEER(paf);
357
358 vec = &pkt->arr.entries[BGP_ATTR_VEC_NH];
359
360 if (!CHECK_FLAG(vec->flags, BPKT_ATTRVEC_FLAGS_UPDATED))
361 return s;
362
363 uint8_t nhlen;
364 afi_t nhafi;
365 int route_map_sets_nh;
366
367 nhlen = stream_getc_from(s, vec->offset);
368 filter = &peer->filter[paf->afi][paf->safi];
369
370 if (peer_cap_enhe(peer, paf->afi, paf->safi))
371 nhafi = AFI_IP6;
372 else
373 nhafi = BGP_NEXTHOP_AFI_FROM_NHLEN(nhlen);
374
375 if (nhafi == AFI_IP) {
376 struct in_addr v4nh, *mod_v4nh;
377 int nh_modified = 0;
378 size_t offset_nh = vec->offset + 1;
379
380 route_map_sets_nh =
381 (CHECK_FLAG(vec->flags,
382 BPKT_ATTRVEC_FLAGS_RMAP_IPV4_NH_CHANGED)
383 || CHECK_FLAG(
384 vec->flags,
385 BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS));
386
387 switch (nhlen) {
388 case BGP_ATTR_NHLEN_IPV4:
389 break;
390 case BGP_ATTR_NHLEN_VPNV4:
391 offset_nh += 8;
392 break;
393 default:
394 /* TODO: handle IPv6 nexthops */
395 flog_warn(
396 EC_BGP_INVALID_NEXTHOP_LENGTH,
397 "%s: %s: invalid MP nexthop length (AFI IP): %u",
398 __func__, peer->host, nhlen);
399 stream_free(s);
400 return NULL;
401 }
402
403 stream_get_from(&v4nh, s, offset_nh, IPV4_MAX_BYTELEN);
404 mod_v4nh = &v4nh;
405
406 /*
407 * If route-map has set the nexthop, that is normally
408 * used; if it is specified as peer-address, the peering
409 * address is picked up. Otherwise, if NH is unavailable
410 * from attribute, the peering addr is picked up; the
411 * "NH unavailable" case also covers next-hop-self and
412 * some other scenarios - see subgroup_announce_check().
413 * In all other cases, use the nexthop carried in the
414 * attribute unless it is EBGP non-multiaccess and there
415 * is no next-hop-unchanged setting or the peer is EBGP
416 * and the route-map that changed the next-hop value
417 * was applied inbound rather than outbound. Updates to
418 * an EBGP peer should only modify the next-hop if it
419 * was set in an outbound route-map to that peer.
420 * Note: It is assumed route-map cannot set the nexthop
421 * to an invalid value.
422 */
423 if (route_map_sets_nh
424 && ((peer->sort != BGP_PEER_EBGP)
425 || ROUTE_MAP_OUT(filter))) {
426 if (CHECK_FLAG(
427 vec->flags,
428 BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS)) {
429 mod_v4nh = &peer->nexthop.v4;
430 nh_modified = 1;
431 }
432 } else if (v4nh.s_addr == INADDR_ANY) {
433 mod_v4nh = &peer->nexthop.v4;
434 nh_modified = 1;
435 } else if (peer->sort == BGP_PEER_EBGP
436 && (bgp_multiaccess_check_v4(v4nh, peer) == 0)
437 && !CHECK_FLAG(vec->flags,
438 BPKT_ATTRVEC_FLAGS_RMAP_NH_UNCHANGED)
439 && !peer_af_flag_check(
440 peer, paf->afi, paf->safi,
441 PEER_FLAG_NEXTHOP_UNCHANGED)) {
442 /* NOTE: not handling case where NH has new AFI
443 */
444 mod_v4nh = &peer->nexthop.v4;
445 nh_modified = 1;
446 }
447
448 if (nh_modified) /* allow for VPN RD */
449 stream_put_in_addr_at(s, offset_nh, mod_v4nh);
450
451 if (bgp_debug_update(peer, NULL, NULL, 0))
452 zlog_debug("u%" PRIu64 ":s%" PRIu64
453 " %s send UPDATE w/ nexthop %pI4%s",
454 PAF_SUBGRP(paf)->update_group->id,
455 PAF_SUBGRP(paf)->id, peer->host, mod_v4nh,
456 (nhlen == BGP_ATTR_NHLEN_VPNV4 ? " and RD"
457 : ""));
458 } else if (nhafi == AFI_IP6) {
459 struct in6_addr v6nhglobal, *mod_v6nhg;
460 struct in6_addr v6nhlocal, *mod_v6nhl;
461 int gnh_modified, lnh_modified;
462 size_t offset_nhglobal = vec->offset + 1;
463 size_t offset_nhlocal = vec->offset + 1;
464
465 gnh_modified = lnh_modified = 0;
466 mod_v6nhg = &v6nhglobal;
467 mod_v6nhl = &v6nhlocal;
468
469 route_map_sets_nh =
470 (CHECK_FLAG(vec->flags,
471 BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED)
472 || CHECK_FLAG(
473 vec->flags,
474 BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS));
475
476 /*
477 * The logic here is rather similar to that for IPv4, the
478 * additional work being to handle 1 or 2 nexthops.
479 * Also, 3rd party nexthop is not propagated for EBGP
480 * right now.
481 */
482 switch (nhlen) {
483 case BGP_ATTR_NHLEN_IPV6_GLOBAL:
484 break;
485 case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
486 offset_nhlocal += IPV6_MAX_BYTELEN;
487 break;
488 case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
489 offset_nhglobal += 8;
490 break;
491 case BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL:
492 offset_nhglobal += 8;
493 offset_nhlocal += 8 * 2 + IPV6_MAX_BYTELEN;
494 break;
495 default:
496 /* TODO: handle IPv4 nexthops */
497 flog_warn(
498 EC_BGP_INVALID_NEXTHOP_LENGTH,
499 "%s: %s: invalid MP nexthop length (AFI IP6): %u",
500 __func__, peer->host, nhlen);
501 stream_free(s);
502 return NULL;
503 }
504
505 stream_get_from(&v6nhglobal, s, offset_nhglobal,
506 IPV6_MAX_BYTELEN);
507
508 /*
509 * Updates to an EBGP peer should only modify the
510 * next-hop if it was set in an outbound route-map
511 * to that peer.
512 */
513 if (route_map_sets_nh
514 && ((peer->sort != BGP_PEER_EBGP)
515 || ROUTE_MAP_OUT(filter))) {
516 if (CHECK_FLAG(
517 vec->flags,
518 BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS)) {
519 mod_v6nhg = &peer->nexthop.v6_global;
520 gnh_modified = 1;
521 }
522 } else if (IN6_IS_ADDR_UNSPECIFIED(&v6nhglobal)) {
523 mod_v6nhg = &peer->nexthop.v6_global;
524 gnh_modified = 1;
525 } else if ((peer->sort == BGP_PEER_EBGP)
526 && (!bgp_multiaccess_check_v6(v6nhglobal, peer))
527 && !CHECK_FLAG(vec->flags,
528 BPKT_ATTRVEC_FLAGS_RMAP_NH_UNCHANGED)
529 && !peer_af_flag_check(
530 peer, paf->afi, paf->safi,
531 PEER_FLAG_NEXTHOP_UNCHANGED)) {
532 /* NOTE: not handling case where NH has new AFI
533 */
534 mod_v6nhg = &peer->nexthop.v6_global;
535 gnh_modified = 1;
536 }
537
538 if (IN6_IS_ADDR_UNSPECIFIED(mod_v6nhg)) {
539 if (peer->nexthop.v4.s_addr != INADDR_ANY) {
540 ipv4_to_ipv4_mapped_ipv6(mod_v6nhg,
541 peer->nexthop.v4);
542 }
543 }
544
545 if (IS_MAPPED_IPV6(&peer->nexthop.v6_global)) {
546 mod_v6nhg = &peer->nexthop.v6_global;
547 gnh_modified = 1;
548 }
549
550 if (nhlen == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
551 || nhlen == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) {
552 stream_get_from(&v6nhlocal, s, offset_nhlocal,
553 IPV6_MAX_BYTELEN);
554 if (IN6_IS_ADDR_UNSPECIFIED(&v6nhlocal)) {
555 mod_v6nhl = &peer->nexthop.v6_local;
556 lnh_modified = 1;
557 }
558 }
559
560 if (gnh_modified)
561 stream_put_in6_addr_at(s, offset_nhglobal, mod_v6nhg);
562 if (lnh_modified)
563 stream_put_in6_addr_at(s, offset_nhlocal, mod_v6nhl);
564
565 if (bgp_debug_update(peer, NULL, NULL, 0)) {
566 if (nhlen == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
567 || nhlen == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)
568 zlog_debug(
569 "u%" PRIu64 ":s%" PRIu64
570 " %s send UPDATE w/ mp_nexthops %pI6, %pI6%s",
571 PAF_SUBGRP(paf)->update_group->id,
572 PAF_SUBGRP(paf)->id, peer->host,
573 mod_v6nhg, mod_v6nhl,
574 (nhlen == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL
575 ? " and RD"
576 : ""));
577 else
578 zlog_debug(
579 "u%" PRIu64 ":s%" PRIu64
580 " %s send UPDATE w/ mp_nexthop %pI6%s",
581 PAF_SUBGRP(paf)->update_group->id,
582 PAF_SUBGRP(paf)->id, peer->host,
583 mod_v6nhg,
584 (nhlen == BGP_ATTR_NHLEN_VPNV6_GLOBAL
585 ? " and RD"
586 : ""));
587 }
588 } else if (paf->afi == AFI_L2VPN) {
589 struct in_addr v4nh, *mod_v4nh;
590 int nh_modified = 0;
591
592 stream_get_from(&v4nh, s, vec->offset + 1, 4);
593 mod_v4nh = &v4nh;
594
595 /* No route-map changes allowed for EVPN nexthops. */
596 if (v4nh.s_addr == INADDR_ANY) {
597 mod_v4nh = &peer->nexthop.v4;
598 nh_modified = 1;
599 }
600
601 if (nh_modified)
602 stream_put_in_addr_at(s, vec->offset + 1, mod_v4nh);
603
604 if (bgp_debug_update(peer, NULL, NULL, 0))
605 zlog_debug("u%" PRIu64 ":s%" PRIu64
606 " %s send UPDATE w/ nexthop %pI4",
607 PAF_SUBGRP(paf)->update_group->id,
608 PAF_SUBGRP(paf)->id, peer->host, mod_v4nh);
609 }
610
611 return s;
612 }
613
614 /*
615 * Update the vecarr offsets to go beyond 'pos' bytes, i.e. add 'pos'
616 * to each offset.
617 */
618 static void bpacket_attr_vec_arr_update(struct bpacket_attr_vec_arr *vecarr,
619 size_t pos)
620 {
621 int i;
622
623 if (!vecarr)
624 return;
625
626 for (i = 0; i < BGP_ATTR_VEC_MAX; i++)
627 vecarr->entries[i].offset += pos;
628 }
629
630 /*
631 * Return if there are packets to build for this subgroup.
632 */
633 bool subgroup_packets_to_build(struct update_subgroup *subgrp)
634 {
635 struct bgp_advertise *adv;
636
637 if (!subgrp)
638 return false;
639
640 adv = bgp_adv_fifo_first(&subgrp->sync->withdraw);
641 if (adv)
642 return true;
643
644 adv = bgp_adv_fifo_first(&subgrp->sync->update);
645 if (adv)
646 return true;
647
648 return false;
649 }
650
651 /* Make BGP update packet. */
652 struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp)
653 {
654 struct bpacket_attr_vec_arr vecarr;
655 struct bpacket *pkt;
656 struct peer *peer;
657 struct stream *s;
658 struct stream *snlri;
659 struct stream *packet;
660 struct bgp_adj_out *adj;
661 struct bgp_advertise *adv;
662 struct bgp_dest *dest = NULL;
663 struct bgp_path_info *path = NULL;
664 bgp_size_t total_attr_len = 0;
665 unsigned long attrlen_pos = 0;
666 size_t mpattrlen_pos = 0;
667 size_t mpattr_pos = 0;
668 afi_t afi;
669 safi_t safi;
670 int space_remaining = 0;
671 int space_needed = 0;
672 char send_attr_str[BUFSIZ];
673 int send_attr_printed = 0;
674 int num_pfx = 0;
675 bool addpath_capable = false;
676 int addpath_overhead = 0;
677 uint32_t addpath_tx_id = 0;
678 struct prefix_rd *prd = NULL;
679 mpls_label_t label = MPLS_INVALID_LABEL, *label_pnt = NULL;
680 uint32_t num_labels = 0;
681
682 if (!subgrp)
683 return NULL;
684
685 if (bpacket_queue_is_full(SUBGRP_INST(subgrp), SUBGRP_PKTQ(subgrp)))
686 return NULL;
687
688 peer = SUBGRP_PEER(subgrp);
689 afi = SUBGRP_AFI(subgrp);
690 safi = SUBGRP_SAFI(subgrp);
691 s = subgrp->work;
692 stream_reset(s);
693 snlri = subgrp->scratch;
694 stream_reset(snlri);
695
696 bpacket_attr_vec_arr_reset(&vecarr);
697
698 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
699 addpath_overhead = addpath_capable ? BGP_ADDPATH_ID_LEN : 0;
700
701 adv = bgp_adv_fifo_first(&subgrp->sync->update);
702 while (adv) {
703 const struct prefix *dest_p;
704
705 assert(adv->dest);
706 dest = adv->dest;
707 dest_p = bgp_dest_get_prefix(dest);
708 adj = adv->adj;
709 addpath_tx_id = adj->addpath_tx_id;
710 path = adv->pathi;
711
712 space_remaining = STREAM_CONCAT_REMAIN(s, snlri, STREAM_SIZE(s))
713 - BGP_MAX_PACKET_SIZE_OVERFLOW;
714 space_needed =
715 BGP_NLRI_LENGTH + addpath_overhead
716 + bgp_packet_mpattr_prefix_size(afi, safi, dest_p);
717
718 /* When remaining space can't include NLRI and it's length. */
719 if (space_remaining < space_needed)
720 break;
721
722 /* If packet is empty, set attribute. */
723 if (stream_empty(s)) {
724 struct peer *from = NULL;
725
726 if (path)
727 from = path->peer;
728
729 /* 1: Write the BGP message header - 16 bytes marker, 2
730 * bytes length,
731 * one byte message type.
732 */
733 bgp_packet_set_marker(s, BGP_MSG_UPDATE);
734
735 /* 2: withdrawn routes length */
736 stream_putw(s, 0);
737
738 /* 3: total attributes length - attrlen_pos stores the
739 * position */
740 attrlen_pos = stream_get_endp(s);
741 stream_putw(s, 0);
742
743 /* 4: if there is MP_REACH_NLRI attribute, that should
744 * be the first
745 * attribute, according to
746 * draft-ietf-idr-error-handling. Save the
747 * position.
748 */
749 mpattr_pos = stream_get_endp(s);
750
751 /* 5: Encode all the attributes, except MP_REACH_NLRI
752 * attr. */
753 total_attr_len = bgp_packet_attribute(
754 NULL, peer, s, adv->baa->attr, &vecarr, NULL,
755 afi, safi, from, NULL, NULL, 0, 0, 0, path);
756
757 space_remaining =
758 STREAM_CONCAT_REMAIN(s, snlri, STREAM_SIZE(s))
759 - BGP_MAX_PACKET_SIZE_OVERFLOW;
760 space_needed = BGP_NLRI_LENGTH + addpath_overhead
761 + bgp_packet_mpattr_prefix_size(
762 afi, safi, dest_p);
763
764 /* If the attributes alone do not leave any room for
765 * NLRI then
766 * return */
767 if (space_remaining < space_needed) {
768 flog_err(
769 EC_BGP_UPDGRP_ATTR_LEN,
770 "u%" PRIu64 ":s%" PRIu64" attributes too long, cannot send UPDATE",
771 subgrp->update_group->id, subgrp->id);
772
773 /* Flush the FIFO update queue */
774 while (adv)
775 adv = bgp_advertise_clean_subgroup(
776 subgrp, adj);
777 return NULL;
778 }
779
780 if (BGP_DEBUG(update, UPDATE_OUT)
781 || BGP_DEBUG(update, UPDATE_PREFIX)) {
782 memset(send_attr_str, 0, BUFSIZ);
783 send_attr_printed = 0;
784 bgp_dump_attr(adv->baa->attr, send_attr_str,
785 sizeof(send_attr_str));
786 }
787 }
788
789 if ((afi == AFI_IP && safi == SAFI_UNICAST)
790 && !peer_cap_enhe(peer, afi, safi))
791 stream_put_prefix_addpath(s, dest_p, addpath_capable,
792 addpath_tx_id);
793 else {
794 /* Encode the prefix in MP_REACH_NLRI attribute */
795 if (dest->pdest)
796 prd = (struct prefix_rd *)bgp_dest_get_prefix(
797 dest->pdest);
798
799 if (safi == SAFI_LABELED_UNICAST) {
800 label = bgp_adv_label(dest, path, peer, afi,
801 safi);
802 label_pnt = &label;
803 num_labels = 1;
804 } else if (path && path->extra) {
805 label_pnt = &path->extra->label[0];
806 num_labels = path->extra->num_labels;
807 }
808
809 if (stream_empty(snlri))
810 mpattrlen_pos = bgp_packet_mpattr_start(
811 snlri, peer, afi, safi, &vecarr,
812 adv->baa->attr);
813
814 bgp_packet_mpattr_prefix(snlri, afi, safi, dest_p, prd,
815 label_pnt, num_labels,
816 addpath_capable, addpath_tx_id,
817 adv->baa->attr);
818 }
819
820 num_pfx++;
821
822 if (bgp_debug_update(NULL, dest_p, subgrp->update_group, 0)) {
823 char pfx_buf[BGP_PRD_PATH_STRLEN];
824
825 if (!send_attr_printed) {
826 zlog_debug("u%" PRIu64 ":s%" PRIu64" send UPDATE w/ attr: %s",
827 subgrp->update_group->id, subgrp->id,
828 send_attr_str);
829 if (!stream_empty(snlri)) {
830 iana_afi_t pkt_afi;
831 iana_safi_t pkt_safi;
832
833 pkt_afi = afi_int2iana(afi);
834 pkt_safi = safi_int2iana(safi);
835 zlog_debug(
836 "u%" PRIu64 ":s%" PRIu64
837 " send MP_REACH for afi/safi %s/%s",
838 subgrp->update_group->id,
839 subgrp->id,
840 iana_afi2str(pkt_afi),
841 iana_safi2str(pkt_safi));
842 }
843
844 send_attr_printed = 1;
845 }
846
847 bgp_debug_rdpfxpath2str(afi, safi, prd, dest_p,
848 label_pnt, num_labels,
849 addpath_capable, addpath_tx_id,
850 &adv->baa->attr->evpn_overlay,
851 pfx_buf, sizeof(pfx_buf));
852 zlog_debug("u%" PRIu64 ":s%" PRIu64 " send UPDATE %s",
853 subgrp->update_group->id, subgrp->id,
854 pfx_buf);
855 }
856
857 /* Synchnorize attribute. */
858 if (adj->attr)
859 bgp_attr_unintern(&adj->attr);
860 else
861 subgrp->scount++;
862
863 adj->attr = bgp_attr_intern(adv->baa->attr);
864 adv = bgp_advertise_clean_subgroup(subgrp, adj);
865 }
866
867 if (!stream_empty(s)) {
868 if (!stream_empty(snlri)) {
869 bgp_packet_mpattr_end(snlri, mpattrlen_pos);
870 total_attr_len += stream_get_endp(snlri);
871 }
872
873 /* set the total attribute length correctly */
874 stream_putw_at(s, attrlen_pos, total_attr_len);
875
876 if (!stream_empty(snlri)) {
877 packet = stream_dupcat(s, snlri, mpattr_pos);
878 bpacket_attr_vec_arr_update(&vecarr, mpattr_pos);
879 } else
880 packet = stream_dup(s);
881 bgp_packet_set_size(packet);
882 if (bgp_debug_update(NULL, NULL, subgrp->update_group, 0))
883 zlog_debug(
884 "u%" PRIu64 ":s%" PRIu64
885 " send UPDATE len %zd (max message len: %hu) numpfx %d",
886 subgrp->update_group->id, subgrp->id,
887 (stream_get_endp(packet)
888 - stream_get_getp(packet)),
889 peer->max_packet_size, num_pfx);
890 pkt = bpacket_queue_add(SUBGRP_PKTQ(subgrp), packet, &vecarr);
891 stream_reset(s);
892 stream_reset(snlri);
893 return pkt;
894 }
895 return NULL;
896 }
897
898 /* Make BGP withdraw packet. */
899 /* For ipv4 unicast:
900 16-octet marker | 2-octet length | 1-octet type |
901 2-octet withdrawn route length | withdrawn prefixes | 2-octet attrlen (=0)
902 */
903 /* For other afi/safis:
904 16-octet marker | 2-octet length | 1-octet type |
905 2-octet withdrawn route length (=0) | 2-octet attrlen |
906 mp_unreach attr type | attr len | afi | safi | withdrawn prefixes
907 */
908 struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp)
909 {
910 struct bpacket *pkt;
911 struct stream *s;
912 struct bgp_adj_out *adj;
913 struct bgp_advertise *adv;
914 struct peer *peer;
915 struct bgp_dest *dest;
916 bgp_size_t unfeasible_len;
917 bgp_size_t total_attr_len;
918 size_t mp_start = 0;
919 size_t attrlen_pos = 0;
920 size_t mplen_pos = 0;
921 uint8_t first_time = 1;
922 afi_t afi;
923 safi_t safi;
924 int space_remaining = 0;
925 int space_needed = 0;
926 int num_pfx = 0;
927 bool addpath_capable = false;
928 int addpath_overhead = 0;
929 uint32_t addpath_tx_id = 0;
930 const struct prefix_rd *prd = NULL;
931
932
933 if (!subgrp)
934 return NULL;
935
936 if (bpacket_queue_is_full(SUBGRP_INST(subgrp), SUBGRP_PKTQ(subgrp)))
937 return NULL;
938
939 peer = SUBGRP_PEER(subgrp);
940 afi = SUBGRP_AFI(subgrp);
941 safi = SUBGRP_SAFI(subgrp);
942 s = subgrp->work;
943 stream_reset(s);
944 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
945 addpath_overhead = addpath_capable ? BGP_ADDPATH_ID_LEN : 0;
946
947 while ((adv = bgp_adv_fifo_first(&subgrp->sync->withdraw)) != NULL) {
948 const struct prefix *dest_p;
949
950 assert(adv->dest);
951 adj = adv->adj;
952 dest = adv->dest;
953 dest_p = bgp_dest_get_prefix(dest);
954 addpath_tx_id = adj->addpath_tx_id;
955
956 space_remaining =
957 STREAM_WRITEABLE(s) - BGP_MAX_PACKET_SIZE_OVERFLOW;
958 space_needed =
959 BGP_NLRI_LENGTH + addpath_overhead + BGP_TOTAL_ATTR_LEN
960 + bgp_packet_mpattr_prefix_size(afi, safi, dest_p);
961
962 if (space_remaining < space_needed)
963 break;
964
965 if (stream_empty(s)) {
966 bgp_packet_set_marker(s, BGP_MSG_UPDATE);
967 stream_putw(s, 0); /* unfeasible routes length */
968 } else
969 first_time = 0;
970
971 if (afi == AFI_IP && safi == SAFI_UNICAST
972 && !peer_cap_enhe(peer, afi, safi))
973 stream_put_prefix_addpath(s, dest_p, addpath_capable,
974 addpath_tx_id);
975 else {
976 if (dest->pdest)
977 prd = (struct prefix_rd *)bgp_dest_get_prefix(
978 dest->pdest);
979
980 /* If first time, format the MP_UNREACH header
981 */
982 if (first_time) {
983 iana_afi_t pkt_afi;
984 iana_safi_t pkt_safi;
985
986 pkt_afi = afi_int2iana(afi);
987 pkt_safi = safi_int2iana(safi);
988
989 attrlen_pos = stream_get_endp(s);
990 /* total attr length = 0 for now.
991 * reevaluate later */
992 stream_putw(s, 0);
993 mp_start = stream_get_endp(s);
994 mplen_pos = bgp_packet_mpunreach_start(s, afi,
995 safi);
996 if (bgp_debug_update(NULL, NULL,
997 subgrp->update_group, 0))
998 zlog_debug(
999 "u%" PRIu64 ":s%" PRIu64
1000 " send MP_UNREACH for afi/safi %s/%s",
1001 subgrp->update_group->id,
1002 subgrp->id,
1003 iana_afi2str(pkt_afi),
1004 iana_safi2str(pkt_safi));
1005 }
1006
1007 bgp_packet_mpunreach_prefix(s, dest_p, afi, safi, prd,
1008 NULL, 0, addpath_capable,
1009 addpath_tx_id, NULL);
1010 }
1011
1012 num_pfx++;
1013
1014 if (bgp_debug_update(NULL, dest_p, subgrp->update_group, 0)) {
1015 char pfx_buf[BGP_PRD_PATH_STRLEN];
1016
1017 bgp_debug_rdpfxpath2str(afi, safi, prd, dest_p, NULL, 0,
1018 addpath_capable, addpath_tx_id,
1019 NULL, pfx_buf, sizeof(pfx_buf));
1020 zlog_debug("u%" PRIu64 ":s%" PRIu64" send UPDATE %s -- unreachable",
1021 subgrp->update_group->id, subgrp->id,
1022 pfx_buf);
1023 }
1024
1025 subgrp->scount--;
1026
1027 bgp_adj_out_remove_subgroup(dest, adj, subgrp);
1028 }
1029
1030 if (!stream_empty(s)) {
1031 if (afi == AFI_IP && safi == SAFI_UNICAST
1032 && !peer_cap_enhe(peer, afi, safi)) {
1033 unfeasible_len = stream_get_endp(s) - BGP_HEADER_SIZE
1034 - BGP_UNFEASIBLE_LEN;
1035 stream_putw_at(s, BGP_HEADER_SIZE, unfeasible_len);
1036 stream_putw(s, 0);
1037 } else {
1038 /* Set the mp_unreach attr's length */
1039 bgp_packet_mpunreach_end(s, mplen_pos);
1040
1041 /* Set total path attribute length. */
1042 total_attr_len = stream_get_endp(s) - mp_start;
1043 stream_putw_at(s, attrlen_pos, total_attr_len);
1044 }
1045 bgp_packet_set_size(s);
1046 if (bgp_debug_update(NULL, NULL, subgrp->update_group, 0))
1047 zlog_debug("u%" PRIu64 ":s%" PRIu64" send UPDATE (withdraw) len %zd numpfx %d",
1048 subgrp->update_group->id, subgrp->id,
1049 (stream_get_endp(s) - stream_get_getp(s)),
1050 num_pfx);
1051 pkt = bpacket_queue_add(SUBGRP_PKTQ(subgrp), stream_dup(s),
1052 NULL);
1053 stream_reset(s);
1054 return pkt;
1055 }
1056
1057 return NULL;
1058 }
1059
1060 void subgroup_default_update_packet(struct update_subgroup *subgrp,
1061 struct attr *attr, struct peer *from)
1062 {
1063 struct stream *s;
1064 struct peer *peer;
1065 struct prefix p;
1066 unsigned long pos;
1067 bgp_size_t total_attr_len;
1068 afi_t afi;
1069 safi_t safi;
1070 struct bpacket_attr_vec_arr vecarr;
1071 bool addpath_capable = false;
1072
1073 if (DISABLE_BGP_ANNOUNCE)
1074 return;
1075
1076 if (!subgrp)
1077 return;
1078
1079 peer = SUBGRP_PEER(subgrp);
1080 afi = SUBGRP_AFI(subgrp);
1081 safi = SUBGRP_SAFI(subgrp);
1082 bpacket_attr_vec_arr_reset(&vecarr);
1083 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
1084
1085 memset(&p, 0, sizeof(p));
1086 p.family = afi2family(afi);
1087 p.prefixlen = 0;
1088
1089 /* Logging the attribute. */
1090 if (bgp_debug_update(NULL, &p, subgrp->update_group, 0)) {
1091 char attrstr[BUFSIZ];
1092 /* ' with addpath ID ' 17
1093 * max strlen of uint32 + 10
1094 * +/- (just in case) + 1
1095 * null terminator + 1
1096 * ============================ 29 */
1097 char tx_id_buf[30];
1098
1099 attrstr[0] = '\0';
1100
1101 bgp_dump_attr(attr, attrstr, sizeof(attrstr));
1102
1103 if (addpath_capable)
1104 snprintf(tx_id_buf, sizeof(tx_id_buf),
1105 " with addpath ID %u",
1106 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
1107 else
1108 tx_id_buf[0] = '\0';
1109
1110 zlog_debug("u%" PRIu64 ":s%" PRIu64 " send UPDATE %pFX%s %s",
1111 (SUBGRP_UPDGRP(subgrp))->id, subgrp->id, &p,
1112 tx_id_buf, attrstr);
1113 }
1114
1115 s = stream_new(peer->max_packet_size);
1116
1117 /* Make BGP update packet. */
1118 bgp_packet_set_marker(s, BGP_MSG_UPDATE);
1119
1120 /* Unfeasible Routes Length. */
1121 stream_putw(s, 0);
1122
1123 /* Make place for total attribute length. */
1124 pos = stream_get_endp(s);
1125 stream_putw(s, 0);
1126 total_attr_len = bgp_packet_attribute(
1127 NULL, peer, s, attr, &vecarr, &p, afi, safi, from, NULL, NULL,
1128 0, addpath_capable, BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE,
1129 NULL);
1130
1131 /* Set Total Path Attribute Length. */
1132 stream_putw_at(s, pos, total_attr_len);
1133
1134 /* NLRI set. */
1135 if (p.family == AF_INET && safi == SAFI_UNICAST
1136 && !peer_cap_enhe(peer, afi, safi))
1137 stream_put_prefix_addpath(
1138 s, &p, addpath_capable,
1139 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
1140
1141 /* Set size. */
1142 bgp_packet_set_size(s);
1143
1144 (void)bpacket_queue_add(SUBGRP_PKTQ(subgrp), s, &vecarr);
1145 subgroup_trigger_write(subgrp);
1146
1147 if (!CHECK_FLAG(subgrp->sflags,
1148 SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED)) {
1149 subgrp->scount++;
1150 SET_FLAG(subgrp->sflags, SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED);
1151 }
1152 }
1153
1154 void subgroup_default_withdraw_packet(struct update_subgroup *subgrp)
1155 {
1156 struct peer *peer;
1157 struct stream *s;
1158 struct prefix p;
1159 unsigned long attrlen_pos = 0;
1160 unsigned long cp;
1161 bgp_size_t unfeasible_len;
1162 bgp_size_t total_attr_len = 0;
1163 size_t mp_start = 0;
1164 size_t mplen_pos = 0;
1165 afi_t afi;
1166 safi_t safi;
1167 bool addpath_capable = false;
1168
1169 if (DISABLE_BGP_ANNOUNCE)
1170 return;
1171
1172 peer = SUBGRP_PEER(subgrp);
1173 afi = SUBGRP_AFI(subgrp);
1174 safi = SUBGRP_SAFI(subgrp);
1175 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
1176
1177 memset(&p, 0, sizeof(p));
1178 p.family = afi2family(afi);
1179 p.prefixlen = 0;
1180
1181 if (bgp_debug_update(NULL, &p, subgrp->update_group, 0)) {
1182 /* ' with addpath ID ' 17
1183 * max strlen of uint32 + 10
1184 * +/- (just in case) + 1
1185 * null terminator + 1
1186 * ============================ 29 */
1187 char tx_id_buf[30];
1188
1189 if (addpath_capable)
1190 snprintf(tx_id_buf, sizeof(tx_id_buf),
1191 " with addpath ID %u",
1192 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
1193
1194 zlog_debug("u%" PRIu64 ":s%" PRIu64
1195 " send UPDATE %pFX%s -- unreachable",
1196 (SUBGRP_UPDGRP(subgrp))->id, subgrp->id, &p,
1197 tx_id_buf);
1198 }
1199
1200 s = stream_new(peer->max_packet_size);
1201
1202 /* Make BGP update packet. */
1203 bgp_packet_set_marker(s, BGP_MSG_UPDATE);
1204
1205 /* Unfeasible Routes Length. */;
1206 cp = stream_get_endp(s);
1207 stream_putw(s, 0);
1208
1209 /* Withdrawn Routes. */
1210 if (p.family == AF_INET && safi == SAFI_UNICAST
1211 && !peer_cap_enhe(peer, afi, safi)) {
1212 stream_put_prefix_addpath(
1213 s, &p, addpath_capable,
1214 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
1215
1216 unfeasible_len = stream_get_endp(s) - cp - 2;
1217
1218 /* Set unfeasible len. */
1219 stream_putw_at(s, cp, unfeasible_len);
1220
1221 /* Set total path attribute length. */
1222 stream_putw(s, 0);
1223 } else {
1224 attrlen_pos = stream_get_endp(s);
1225 stream_putw(s, 0);
1226 mp_start = stream_get_endp(s);
1227 mplen_pos = bgp_packet_mpunreach_start(s, afi, safi);
1228 bgp_packet_mpunreach_prefix(
1229 s, &p, afi, safi, NULL, NULL, 0, addpath_capable,
1230 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE, NULL);
1231
1232 /* Set the mp_unreach attr's length */
1233 bgp_packet_mpunreach_end(s, mplen_pos);
1234
1235 /* Set total path attribute length. */
1236 total_attr_len = stream_get_endp(s) - mp_start;
1237 stream_putw_at(s, attrlen_pos, total_attr_len);
1238 }
1239
1240 bgp_packet_set_size(s);
1241
1242 (void)bpacket_queue_add(SUBGRP_PKTQ(subgrp), s, NULL);
1243 subgroup_trigger_write(subgrp);
1244
1245 if (CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED)) {
1246 subgrp->scount--;
1247 UNSET_FLAG(subgrp->sflags,
1248 SUBGRP_STATUS_PEER_DEFAULT_ORIGINATED);
1249 }
1250 }
1251
1252 static void
1253 bpacket_vec_arr_inherit_attr_flags(struct bpacket_attr_vec_arr *vecarr,
1254 enum bpacket_attr_vec_type type,
1255 struct attr *attr)
1256 {
1257 if (CHECK_FLAG(attr->rmap_change_flags,
1258 BATTR_RMAP_NEXTHOP_PEER_ADDRESS))
1259 SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags,
1260 BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS);
1261
1262 if (CHECK_FLAG(attr->rmap_change_flags, BATTR_REFLECTED))
1263 SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags,
1264 BPKT_ATTRVEC_FLAGS_REFLECTED);
1265
1266 if (CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_NEXTHOP_UNCHANGED))
1267 SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags,
1268 BPKT_ATTRVEC_FLAGS_RMAP_NH_UNCHANGED);
1269
1270 if (CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_IPV4_NHOP_CHANGED))
1271 SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags,
1272 BPKT_ATTRVEC_FLAGS_RMAP_IPV4_NH_CHANGED);
1273
1274 if (CHECK_FLAG(attr->rmap_change_flags,
1275 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED))
1276 SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags,
1277 BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED);
1278
1279 if (CHECK_FLAG(attr->rmap_change_flags,
1280 BATTR_RMAP_IPV6_LL_NHOP_CHANGED))
1281 SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags,
1282 BPKT_ATTRVEC_FLAGS_RMAP_IPV6_LNH_CHANGED);
1283 }
1284
1285 /* Reset the Attributes vector array. The vector array is used to override
1286 * certain output parameters in the packet for a particular peer
1287 */
1288 void bpacket_attr_vec_arr_reset(struct bpacket_attr_vec_arr *vecarr)
1289 {
1290 int i;
1291
1292 if (!vecarr)
1293 return;
1294
1295 i = 0;
1296 while (i < BGP_ATTR_VEC_MAX) {
1297 vecarr->entries[i].flags = 0;
1298 vecarr->entries[i].offset = 0;
1299 i++;
1300 }
1301 }
1302
1303 /* Setup a particular node entry in the vecarr */
1304 void bpacket_attr_vec_arr_set_vec(struct bpacket_attr_vec_arr *vecarr,
1305 enum bpacket_attr_vec_type type,
1306 struct stream *s, struct attr *attr)
1307 {
1308 if (!vecarr)
1309 return;
1310 assert(type < BGP_ATTR_VEC_MAX);
1311
1312 SET_FLAG(vecarr->entries[type].flags, BPKT_ATTRVEC_FLAGS_UPDATED);
1313 vecarr->entries[type].offset = stream_get_endp(s);
1314 if (attr)
1315 bpacket_vec_arr_inherit_attr_flags(vecarr, type, attr);
1316 }