]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/rfapi_nve_addr.c
bgpd: Adding BGP GR Global & Per Neighbour FSM changes
[mirror_frr.git] / bgpd / rfapi / rfapi_nve_addr.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
22 #include "lib/zebra.h"
23 #include "lib/prefix.h"
24 #include "lib/agg_table.h"
25 #include "lib/vty.h"
26 #include "lib/memory.h"
27 #include "lib/skiplist.h"
28
29
30 #include "bgpd/bgpd.h"
31
32 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
33 #include "bgpd/rfapi/rfapi.h"
34 #include "bgpd/rfapi/rfapi_backend.h"
35
36 #include "bgpd/rfapi/rfapi_import.h"
37 #include "bgpd/rfapi/rfapi_private.h"
38 #include "bgpd/rfapi/rfapi_nve_addr.h"
39 #include "bgpd/rfapi/rfapi_vty.h"
40 #include "bgpd/rfapi/vnc_debug.h"
41
42 #define DEBUG_NVE_ADDR 0
43
44 void rfapiNveAddr2Str(struct rfapi_nve_addr *, char *, int);
45
46
47 #if DEBUG_NVE_ADDR
48 static void logdifferent(const char *tag, struct rfapi_nve_addr *a,
49 struct rfapi_nve_addr *b)
50 {
51 char a_str[BUFSIZ];
52 char b_str[BUFSIZ];
53
54 rfapiNveAddr2Str(a, a_str, BUFSIZ);
55 rfapiNveAddr2Str(b, b_str, BUFSIZ);
56 vnc_zlog_debug_verbose("%s: [%s] [%s]", tag, a_str, b_str);
57 }
58 #endif
59
60
61 int rfapi_nve_addr_cmp(void *k1, void *k2)
62 {
63 struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1;
64 struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2;
65 int ret = 0;
66
67 if (!a || !b) {
68 #if DEBUG_NVE_ADDR
69 vnc_zlog_debug_verbose("%s: missing address a=%p b=%p",
70 __func__, a, b);
71 #endif
72 return (a - b);
73 }
74 if (a->un.addr_family != b->un.addr_family) {
75 #if DEBUG_NVE_ADDR
76 vnc_zlog_debug_verbose(
77 "diff: UN addr fam a->un.af=%d, b->un.af=%d",
78 a->un.addr_family, b->un.addr_family);
79 #endif
80 return (a->un.addr_family - b->un.addr_family);
81 }
82 if (a->un.addr_family == AF_INET) {
83 ret = IPV4_ADDR_CMP(&a->un.addr.v4, &b->un.addr.v4);
84 if (ret != 0) {
85 #if DEBUG_NVE_ADDR
86 logdifferent("diff: UN addr", a, b);
87 #endif
88 return ret;
89 }
90 } else if (a->un.addr_family == AF_INET6) {
91 ret = IPV6_ADDR_CMP(&a->un.addr.v6, &b->un.addr.v6);
92 if (ret == 0) {
93 #if DEBUG_NVE_ADDR
94 logdifferent("diff: UN addr", a, b);
95 #endif
96 return ret;
97 }
98 } else {
99 assert(0);
100 }
101 if (a->vn.addr_family != b->vn.addr_family) {
102 #if DEBUG_NVE_ADDR
103 vnc_zlog_debug_verbose(
104 "diff: pT addr fam a->vn.af=%d, b->vn.af=%d",
105 a->vn.addr_family, b->vn.addr_family);
106 #endif
107 return (a->vn.addr_family - b->vn.addr_family);
108 }
109 if (a->vn.addr_family == AF_INET) {
110 ret = IPV4_ADDR_CMP(&a->vn.addr.v4, &b->vn.addr.v4);
111 if (ret != 0) {
112 #if DEBUG_NVE_ADDR
113 logdifferent("diff: VN addr", a, b);
114 #endif
115 return ret;
116 }
117 } else if (a->vn.addr_family == AF_INET6) {
118 ret = IPV6_ADDR_CMP(&a->vn.addr.v6, &b->vn.addr.v6);
119 if (ret == 0) {
120 #if DEBUG_NVE_ADDR
121 logdifferent("diff: VN addr", a, b);
122 #endif
123 return ret;
124 }
125 } else {
126 assert(0);
127 }
128 return 0;
129 }
130
131 void rfapiNveAddr2Str(struct rfapi_nve_addr *na, char *buf, int bufsize)
132 {
133 char *p = buf;
134 int r;
135
136 #define REMAIN (bufsize - (p-buf))
137 #define INCP {p += (r > REMAIN)? REMAIN: r;}
138
139 if (bufsize < 1)
140 return;
141
142 r = snprintf(p, REMAIN, "VN=");
143 INCP;
144
145 if (!rfapiRfapiIpAddr2Str(&na->vn, p, REMAIN))
146 goto done;
147
148 buf[bufsize - 1] = 0;
149 p = buf + strlen(buf);
150
151 r = snprintf(p, REMAIN, ", UN=");
152 INCP;
153
154 rfapiRfapiIpAddr2Str(&na->un, p, REMAIN);
155
156 done:
157 buf[bufsize - 1] = 0;
158 }