]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/rfapi_descriptor_rfp_utils.c
bgpd: Adding BGP GR Global & Per Neighbour FSM changes
[mirror_frr.git] / bgpd / rfapi / rfapi_descriptor_rfp_utils.c
1 /*
2 *
3 * Copyright 2009-2016, LabN Consulting, L.L.C.
4 *
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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
21 #include "lib/zebra.h"
22 #include "lib/prefix.h"
23 #include "lib/table.h"
24 #include "lib/vty.h"
25 #include "lib/memory.h"
26 #include "lib/log.h"
27
28 #include "bgpd/bgpd.h"
29
30 #include "bgpd/rfapi/rfapi.h"
31 #include "bgpd/rfapi/rfapi_private.h"
32 #include "bgpd/rfapi/rfapi_descriptor_rfp_utils.h"
33 #include "bgpd/rfapi/vnc_debug.h"
34
35
36 void *rfapi_create_generic(struct rfapi_ip_addr *vn, struct rfapi_ip_addr *un)
37 {
38 struct rfapi_descriptor *rfd;
39 rfd = XCALLOC(MTYPE_RFAPI_DESC, sizeof(struct rfapi_descriptor));
40 vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd);
41 rfd->vn_addr = *vn;
42 rfd->un_addr = *un;
43 return (void *)rfd;
44 }
45
46 /*------------------------------------------
47 * rfapi_free_generic
48 *
49 * Compare two generic rfapi descriptors.
50 *
51 * input:
52 * grfd: rfapi descriptor returned by rfapi_open or rfapi_create_generic
53 *
54 * output:
55 *
56 * return value:
57 *
58 *------------------------------------------*/
59 void rfapi_free_generic(void *grfd)
60 {
61 struct rfapi_descriptor *rfd;
62 rfd = (struct rfapi_descriptor *)grfd;
63 XFREE(MTYPE_RFAPI_DESC, rfd);
64 }
65
66
67 /*------------------------------------------
68 * rfapi_compare_rfds
69 *
70 * Compare two generic rfapi descriptors.
71 *
72 * input:
73 * rfd1: rfapi descriptor returned by rfapi_open or rfapi_create_generic
74 * rfd2: rfapi descriptor returned by rfapi_open or rfapi_create_generic
75 *
76 * output:
77 *
78 * return value:
79 * 0 Mismatch
80 * 1 Match
81 *------------------------------------------*/
82 int rfapi_compare_rfds(void *rfd1, void *rfd2)
83 {
84 struct rfapi_descriptor *rrfd1, *rrfd2;
85 int match = 0;
86
87 rrfd1 = (struct rfapi_descriptor *)rfd1;
88 rrfd2 = (struct rfapi_descriptor *)rfd2;
89
90 if (rrfd1->vn_addr.addr_family == rrfd2->vn_addr.addr_family) {
91 if (rrfd1->vn_addr.addr_family == AF_INET)
92 match = IPV4_ADDR_SAME(&(rrfd1->vn_addr.addr.v4),
93 &(rrfd2->vn_addr.addr.v4));
94 else
95 match = IPV6_ADDR_SAME(&(rrfd1->vn_addr.addr.v6),
96 &(rrfd2->vn_addr.addr.v6));
97 }
98
99 /*
100 * If the VN addresses don't match in all forms,
101 * give up.
102 */
103 if (!match)
104 return 0;
105
106 /*
107 * do the process again for the UN addresses.
108 */
109 match = 0;
110 if (rrfd1->un_addr.addr_family == rrfd2->un_addr.addr_family) {
111 /* VN addresses match
112 * UN address families match
113 * now check the actual UN addresses
114 */
115 if (rrfd1->un_addr.addr_family == AF_INET)
116 match = IPV4_ADDR_SAME(&(rrfd1->un_addr.addr.v4),
117 &(rrfd2->un_addr.addr.v4));
118 else
119 match = IPV6_ADDR_SAME(&(rrfd1->un_addr.addr.v6),
120 &(rrfd2->un_addr.addr.v6));
121 }
122 return match;
123 }