]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_rp.c
ospfd: Don't leave stale RouterLSA's when changing areaID
[mirror_frr.git] / pimd / pim_rp.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
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 "log.h"
24 #include "network.h"
25
26 #include "pimd.h"
27 #include "pim_str.h"
28 #include "pim_rp.h"
29 #include "pim_str.h"
30 #include "pim_rpf.h"
31
32 static int i_am_rp = 0;
33
34 /*
35 * Checks to see if we should elect ourself the actual RP
36 */
37 void
38 pim_rp_check_rp (struct in_addr old, struct in_addr new)
39 {
40 if (PIM_DEBUG_ZEBRA) {
41 char sold[100];
42 char snew[100];
43 char rp[100];
44 pim_inet4_dump("<rp?>", qpim_rp.rpf_addr, rp, sizeof(rp));
45 pim_inet4_dump("<old?>", old, sold, sizeof(sold));
46 pim_inet4_dump("<new?>", new, snew, sizeof(snew));
47 zlog_debug("%s: %s for old %s new %s", __func__, rp, sold, snew );
48 }
49
50 if (qpim_rp.rpf_addr.s_addr == INADDR_NONE)
51 return;
52
53 if (new.s_addr == qpim_rp.rpf_addr.s_addr)
54 {
55 i_am_rp = 1;
56 return;
57 }
58
59 if (old.s_addr == qpim_rp.rpf_addr.s_addr)
60 {
61 i_am_rp = 0;
62 return;
63 }
64 }
65
66 /*
67 * I_am_RP(G) is true if the group-to-RP mapping indicates that
68 * this router is the RP for the group.
69 *
70 * Since we only have static RP, all groups are part of this RP
71 */
72 int
73 pim_rp_i_am_rp (struct in_addr group)
74 {
75 return i_am_rp;
76 }
77
78 /*
79 * RP(G)
80 *
81 * Return the RP that the Group belongs too.
82 */
83 struct pim_rpf *
84 pim_rp_g (struct in_addr group)
85 {
86 /*
87 * For staticly configured RP, it is always the qpim_rp
88 */
89 pim_nexthop_lookup(&qpim_rp.source_nexthop, qpim_rp.rpf_addr);
90 return(&qpim_rp);
91 }
92
93 /*
94 * Set the upstream IP address we want to talk to based upon
95 * the rp configured and the source address
96 *
97 * If we have don't have a RP configured and the source address is *
98 * then return failure.
99 *
100 */
101 int
102 pim_rp_set_upstream_addr (struct in_addr *up, struct in_addr source)
103 {
104 if ((qpim_rp.rpf_addr.s_addr == INADDR_NONE) && (source.s_addr == INADDR_ANY))
105 {
106 if (PIM_DEBUG_PIM_TRACE)
107 zlog_debug("%s: Received a (*,G) with no RP configured", __PRETTY_FUNCTION__);
108 return 0;
109 }
110
111 *up = (source.s_addr == INADDR_ANY) ? qpim_rp.rpf_addr : source;
112
113 return 1;
114 }