]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_br.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / pimd / pim_br.c
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 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 "memory.h"
23 #include "log.h"
24 #include "if.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 prefix_sg sg;
33 struct in_addr pmbr;
34 };
35
36 struct in_addr pim_br_unknown = { .s_addr = 0 };
37
38 static struct list *pim_br_list = NULL;
39
40 struct in_addr
41 pim_br_get_pmbr (struct prefix_sg *sg)
42 {
43 struct listnode *node;
44 struct pim_br *pim_br;
45
46 for (ALL_LIST_ELEMENTS_RO (pim_br_list, node, pim_br)) {
47 if (sg->src.s_addr == pim_br->sg.src.s_addr &&
48 sg->grp.s_addr == pim_br->sg.grp.s_addr)
49 return pim_br->pmbr;
50 }
51
52 return pim_br_unknown;
53 }
54
55 void
56 pim_br_set_pmbr (struct prefix_sg *sg, struct in_addr br)
57 {
58 struct listnode *node, *next;
59 struct pim_br *pim_br;
60
61 for (ALL_LIST_ELEMENTS (pim_br_list, node, next, pim_br)) {
62 if (sg->src.s_addr == pim_br->sg.src.s_addr &&
63 sg->grp.s_addr == pim_br->sg.grp.s_addr)
64 break;
65 }
66
67 if (!pim_br) {
68 pim_br = XCALLOC(MTYPE_PIM_BR, sizeof (*pim_br));
69 if (!pim_br) {
70 zlog_err("PIM XCALLOC(%zu) failure", sizeof(*pim_br));
71 return;
72 }
73
74 pim_br->sg = *sg;
75
76 listnode_add(pim_br_list, pim_br);
77 }
78
79 pim_br->pmbr = br;
80 }
81
82 /*
83 * Remove the (S,G) from the stored values
84 */
85 void
86 pim_br_clear_pmbr (struct prefix_sg *sg)
87 {
88 struct listnode *node, *next;
89 struct pim_br *pim_br;
90
91 for (ALL_LIST_ELEMENTS (pim_br_list, node, next, pim_br)) {
92 if (sg->src.s_addr == pim_br->sg.src.s_addr &&
93 sg->grp.s_addr == pim_br->sg.grp.s_addr)
94 break;
95 }
96
97 if (!pim_br)
98 return;
99
100 listnode_delete (pim_br_list, pim_br);
101 }
102
103 void pim_br_init (void)
104 {
105 pim_br_list = list_new();
106 if (!pim_br_list) {
107 zlog_err("%s: Failure to create pim_br_list",
108 __PRETTY_FUNCTION__);
109 return;
110 }
111 }