]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop_group.c
lib: Isolate nexthop_group functions to nexthop_group.c
[mirror_frr.git] / lib / nexthop_group.c
1 /*
2 * Nexthop Group structure definition.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This program 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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * 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 <nexthop.h>
23 #include <nexthop_group.h>
24
25 /* Add nexthop to the end of a nexthop list. */
26 void nexthop_add(struct nexthop **target, struct nexthop *nexthop)
27 {
28 struct nexthop *last;
29
30 for (last = *target; last && last->next; last = last->next)
31 ;
32 if (last)
33 last->next = nexthop;
34 else
35 *target = nexthop;
36 nexthop->prev = last;
37 }
38
39 void copy_nexthops(struct nexthop **tnh, struct nexthop *nh,
40 struct nexthop *rparent)
41 {
42 struct nexthop *nexthop;
43 struct nexthop *nh1;
44
45 for (nh1 = nh; nh1; nh1 = nh1->next) {
46 nexthop = nexthop_new();
47 nexthop->vrf_id = nh1->vrf_id;
48 nexthop->ifindex = nh1->ifindex;
49 nexthop->type = nh1->type;
50 nexthop->flags = nh1->flags;
51 memcpy(&nexthop->gate, &nh1->gate, sizeof(nh1->gate));
52 memcpy(&nexthop->src, &nh1->src, sizeof(nh1->src));
53 memcpy(&nexthop->rmap_src, &nh1->rmap_src,
54 sizeof(nh1->rmap_src));
55 nexthop->rparent = rparent;
56 if (nh1->nh_label)
57 nexthop_add_labels(nexthop, nh1->nh_label_type,
58 nh1->nh_label->num_labels,
59 &nh1->nh_label->label[0]);
60 nexthop_add(tnh, nexthop);
61
62 if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE))
63 copy_nexthops(&nexthop->resolved, nh1->resolved,
64 nexthop);
65 }
66 }