]>
Commit | Line | Data |
---|---|---|
d62a17ae | 1 | /* |
65efcfce LB |
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 | * | |
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 | |
65efcfce LB |
19 | */ |
20 | ||
21 | ||
22 | #include <errno.h> | |
23 | ||
f8b6f499 LB |
24 | #include "lib/zebra.h" |
25 | #include "lib/prefix.h" | |
26 | #include "lib/table.h" | |
27 | #include "lib/vty.h" | |
28 | #include "lib/memory.h" | |
29 | #include "lib/log.h" | |
30 | ||
31 | #include "bgpd/bgpd.h" | |
32 | ||
33 | #include "bgpd/rfapi/rfapi.h" | |
34 | #include "bgpd/rfapi/rfapi_private.h" | |
35 | #include "bgpd/rfapi/rfapi_descriptor_rfp_utils.h" | |
a3b55c25 | 36 | #include "bgpd/rfapi/vnc_debug.h" |
65efcfce LB |
37 | |
38 | ||
d62a17ae | 39 | void *rfapi_create_generic(struct rfapi_ip_addr *vn, struct rfapi_ip_addr *un) |
65efcfce | 40 | { |
d62a17ae | 41 | struct rfapi_descriptor *rfd; |
42 | rfd = XCALLOC(MTYPE_RFAPI_DESC, sizeof(struct rfapi_descriptor)); | |
43 | vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd); | |
44 | rfd->vn_addr = *vn; | |
45 | rfd->un_addr = *un; | |
46 | return (void *)rfd; | |
65efcfce LB |
47 | } |
48 | ||
49 | /*------------------------------------------ | |
50 | * rfapi_free_generic | |
51 | * | |
52 | * Compare two generic rfapi descriptors. | |
53 | * | |
d62a17ae | 54 | * input: |
65efcfce LB |
55 | * grfd: rfapi descriptor returned by rfapi_open or rfapi_create_generic |
56 | * | |
57 | * output: | |
58 | * | |
d62a17ae | 59 | * return value: |
65efcfce LB |
60 | * |
61 | *------------------------------------------*/ | |
d62a17ae | 62 | void rfapi_free_generic(void *grfd) |
65efcfce | 63 | { |
d62a17ae | 64 | struct rfapi_descriptor *rfd; |
65 | rfd = (struct rfapi_descriptor *)grfd; | |
66 | XFREE(MTYPE_RFAPI_DESC, rfd); | |
65efcfce LB |
67 | } |
68 | ||
69 | ||
70 | /*------------------------------------------ | |
71 | * rfapi_compare_rfds | |
72 | * | |
73 | * Compare two generic rfapi descriptors. | |
74 | * | |
d62a17ae | 75 | * input: |
65efcfce LB |
76 | * rfd1: rfapi descriptor returned by rfapi_open or rfapi_create_generic |
77 | * rfd2: rfapi descriptor returned by rfapi_open or rfapi_create_generic | |
78 | * | |
79 | * output: | |
80 | * | |
81 | * return value: | |
82 | * 0 Mismatch | |
83 | * 1 Match | |
84 | *------------------------------------------*/ | |
d62a17ae | 85 | int rfapi_compare_rfds(void *rfd1, void *rfd2) |
65efcfce | 86 | { |
d62a17ae | 87 | struct rfapi_descriptor *rrfd1, *rrfd2; |
88 | int match = 0; | |
65efcfce | 89 | |
d62a17ae | 90 | rrfd1 = (struct rfapi_descriptor *)rfd1; |
91 | rrfd2 = (struct rfapi_descriptor *)rfd2; | |
65efcfce | 92 | |
d62a17ae | 93 | if (rrfd1->vn_addr.addr_family == rrfd2->vn_addr.addr_family) { |
94 | if (rrfd1->vn_addr.addr_family == AF_INET) | |
95 | match = IPV4_ADDR_SAME(&(rrfd1->vn_addr.addr.v4), | |
96 | &(rrfd2->vn_addr.addr.v4)); | |
97 | else | |
98 | match = IPV6_ADDR_SAME(&(rrfd1->vn_addr.addr.v6), | |
99 | &(rrfd2->vn_addr.addr.v6)); | |
100 | } | |
65efcfce | 101 | |
d62a17ae | 102 | /* |
103 | * If the VN addresses don't match in all forms, | |
104 | * give up. | |
105 | */ | |
106 | if (!match) | |
107 | return 0; | |
65efcfce | 108 | |
d62a17ae | 109 | /* |
110 | * do the process again for the UN addresses. | |
111 | */ | |
112 | match = 0; | |
113 | if (rrfd1->un_addr.addr_family == rrfd2->un_addr.addr_family) { | |
114 | /* VN addresses match | |
115 | * UN address families match | |
116 | * now check the actual UN addresses | |
117 | */ | |
118 | if (rrfd1->un_addr.addr_family == AF_INET) | |
119 | match = IPV4_ADDR_SAME(&(rrfd1->un_addr.addr.v4), | |
120 | &(rrfd2->un_addr.addr.v4)); | |
121 | else | |
122 | match = IPV6_ADDR_SAME(&(rrfd1->un_addr.addr.v6), | |
123 | &(rrfd2->un_addr.addr.v6)); | |
124 | } | |
125 | return match; | |
65efcfce | 126 | } |