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