]>
Commit | Line | Data |
---|---|---|
2bd9e1bc DS |
1 | /* |
2 | * PIM for Quagga | |
3 | * Copyright (C) 2015 Cumulus Networks, Inc. | |
4 | * Donald Sharp | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program 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 | |
17 | * along with this program; see the file COPYING; if not, write to the | |
18 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
19 | * MA 02110-1301 USA | |
20 | */ | |
21 | #include <zebra.h> | |
22 | ||
23 | #include "memory.h" | |
24 | #include "log.h" | |
25 | ||
26 | #include "pimd.h" | |
27 | #include "pim_str.h" | |
28 | #include "pim_br.h" | |
29 | #include "linklist.h" | |
30 | ||
31 | struct pim_br { | |
32 | struct in_addr source; | |
33 | struct in_addr group; | |
34 | struct in_addr pmbr; | |
35 | }; | |
36 | ||
37 | struct in_addr pim_br_unknown = { .s_addr = 0 }; | |
38 | ||
39 | static struct list *pim_br_list = NULL; | |
40 | ||
41 | struct in_addr | |
42 | pim_br_get_pmbr (struct in_addr source, struct in_addr group) | |
43 | { | |
44 | struct listnode *node; | |
45 | struct pim_br *pim_br; | |
46 | ||
47 | for (ALL_LIST_ELEMENTS_RO (pim_br_list, node, pim_br)) { | |
48 | if (source.s_addr == pim_br->source.s_addr && | |
49 | group.s_addr == pim_br->group.s_addr) | |
50 | return pim_br->pmbr; | |
51 | } | |
52 | ||
53 | return pim_br_unknown; | |
54 | } | |
55 | ||
56 | void | |
57 | pim_br_set_pmbr (struct in_addr source, struct in_addr group, struct in_addr br) | |
58 | { | |
59 | struct listnode *node, *next; | |
60 | struct pim_br *pim_br; | |
61 | ||
62 | for (ALL_LIST_ELEMENTS (pim_br_list, node, next, pim_br)) { | |
63 | if (source.s_addr == pim_br->source.s_addr && | |
64 | group.s_addr == pim_br->group.s_addr) | |
65 | break; | |
66 | } | |
67 | ||
68 | if (!pim_br) { | |
69 | pim_br = XCALLOC(MTYPE_PIM_BR, sizeof (*pim_br)); | |
70 | if (!pim_br) { | |
71 | zlog_err("PIM XCALLOC(%zu) failure", sizeof(*pim_br)); | |
72 | return; | |
73 | } | |
74 | ||
75 | pim_br->source = source; | |
76 | pim_br->group = group; | |
77 | ||
78 | listnode_add(pim_br_list, pim_br); | |
79 | } | |
80 | ||
81 | pim_br->pmbr = br; | |
82 | } | |
83 | ||
f14248dd DS |
84 | /* |
85 | * Remove the (S,G) from the stored values | |
86 | */ | |
87 | void | |
88 | pim_br_clear_pmbr (struct in_addr source, struct in_addr group) | |
89 | { | |
90 | struct listnode *node, *next; | |
91 | struct pim_br *pim_br; | |
92 | ||
93 | for (ALL_LIST_ELEMENTS (pim_br_list, node, next, pim_br)) { | |
94 | if (source.s_addr == pim_br->source.s_addr && | |
95 | group.s_addr == pim_br->group.s_addr) | |
96 | break; | |
97 | } | |
98 | ||
99 | if (!pim_br) | |
100 | return; | |
101 | ||
102 | listnode_delete (pim_br_list, pim_br); | |
103 | } | |
2bd9e1bc DS |
104 | |
105 | void pim_br_init (void) | |
106 | { | |
107 | pim_br_list = list_new(); | |
108 | if (!pim_br_list) { | |
109 | zlog_err("%s: Failure to create pim_br_list", | |
110 | __PRETTY_FUNCTION__); | |
111 | return; | |
112 | } | |
113 | } |