]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_br.c
Merge pull request #2665 from chiragshah6/evpn_dev
[mirror_frr.git] / pimd / pim_br.c
CommitLineData
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 *
896014f4
DL
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
2bd9e1bc
DS
19 */
20#include <zebra.h>
21
22#include "memory.h"
23#include "log.h"
744d91b3 24#include "if.h"
2bd9e1bc
DS
25
26#include "pimd.h"
27#include "pim_str.h"
28#include "pim_br.h"
29#include "linklist.h"
30
31struct pim_br {
d62a17ae 32 struct prefix_sg sg;
33 struct in_addr pmbr;
2bd9e1bc
DS
34};
35
d62a17ae 36struct in_addr pim_br_unknown = {.s_addr = 0};
2bd9e1bc
DS
37
38static struct list *pim_br_list = NULL;
39
d62a17ae 40struct in_addr pim_br_get_pmbr(struct prefix_sg *sg)
2bd9e1bc 41{
d62a17ae 42 struct listnode *node;
43 struct pim_br *pim_br;
2bd9e1bc 44
d62a17ae 45 for (ALL_LIST_ELEMENTS_RO(pim_br_list, node, pim_br)) {
46 if (sg->src.s_addr == pim_br->sg.src.s_addr
47 && sg->grp.s_addr == pim_br->sg.grp.s_addr)
48 return pim_br->pmbr;
49 }
2bd9e1bc 50
d62a17ae 51 return pim_br_unknown;
2bd9e1bc
DS
52}
53
d62a17ae 54void pim_br_set_pmbr(struct prefix_sg *sg, struct in_addr br)
2bd9e1bc 55{
d62a17ae 56 struct listnode *node, *next;
57 struct pim_br *pim_br;
2bd9e1bc 58
d62a17ae 59 for (ALL_LIST_ELEMENTS(pim_br_list, node, next, pim_br)) {
60 if (sg->src.s_addr == pim_br->sg.src.s_addr
61 && sg->grp.s_addr == pim_br->sg.grp.s_addr)
62 break;
63 }
2bd9e1bc 64
d62a17ae 65 if (!pim_br) {
66 pim_br = XCALLOC(MTYPE_PIM_BR, sizeof(*pim_br));
2bd9e1bc 67
d62a17ae 68 pim_br->sg = *sg;
2bd9e1bc 69
d62a17ae 70 listnode_add(pim_br_list, pim_br);
71 }
2bd9e1bc 72
d62a17ae 73 pim_br->pmbr = br;
2bd9e1bc
DS
74}
75
f14248dd
DS
76/*
77 * Remove the (S,G) from the stored values
78 */
d62a17ae 79void pim_br_clear_pmbr(struct prefix_sg *sg)
f14248dd 80{
d62a17ae 81 struct listnode *node, *next;
82 struct pim_br *pim_br;
f14248dd 83
d62a17ae 84 for (ALL_LIST_ELEMENTS(pim_br_list, node, next, pim_br)) {
85 if (sg->src.s_addr == pim_br->sg.src.s_addr
86 && sg->grp.s_addr == pim_br->sg.grp.s_addr)
87 break;
88 }
f14248dd 89
d62a17ae 90 if (!pim_br)
91 return;
f14248dd 92
d62a17ae 93 listnode_delete(pim_br_list, pim_br);
f14248dd 94}
2bd9e1bc 95
d62a17ae 96void pim_br_init(void)
2bd9e1bc 97{
d62a17ae 98 pim_br_list = list_new();
2bd9e1bc 99}