]>
git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/rfapi_nve_addr.c
3 * Copyright 2009-2016, LabN Consulting, L.L.C.
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.
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.
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
22 #include "lib/zebra.h"
23 #include "lib/prefix.h"
24 #include "lib/agg_table.h"
26 #include "lib/memory.h"
27 #include "lib/skiplist.h"
30 #include "bgpd/bgpd.h"
32 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
33 #include "bgpd/rfapi/rfapi.h"
34 #include "bgpd/rfapi/rfapi_backend.h"
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"
42 #define DEBUG_NVE_ADDR 0
44 void rfapiNveAddr2Str(struct rfapi_nve_addr
*, char *, int);
48 static void logdifferent(const char *tag
, struct rfapi_nve_addr
*a
,
49 struct rfapi_nve_addr
*b
)
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
);
61 int rfapi_nve_addr_cmp(const void *k1
, const void *k2
)
63 const struct rfapi_nve_addr
*a
= (struct rfapi_nve_addr
*)k1
;
64 const struct rfapi_nve_addr
*b
= (struct rfapi_nve_addr
*)k2
;
69 vnc_zlog_debug_verbose("%s: missing address a=%p b=%p",
74 if (a
->un
.addr_family
!= b
->un
.addr_family
) {
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
);
80 return (a
->un
.addr_family
- b
->un
.addr_family
);
82 if (a
->un
.addr_family
== AF_INET
) {
83 ret
= IPV4_ADDR_CMP(&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
86 logdifferent("diff: UN addr", a
, b
);
90 } else if (a
->un
.addr_family
== AF_INET6
) {
91 ret
= IPV6_ADDR_CMP(&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
94 logdifferent("diff: UN addr", a
, b
);
101 if (a
->vn
.addr_family
!= b
->vn
.addr_family
) {
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
);
107 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
109 if (a
->vn
.addr_family
== AF_INET
) {
110 ret
= IPV4_ADDR_CMP(&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
113 logdifferent("diff: VN addr", a
, b
);
117 } else if (a
->vn
.addr_family
== AF_INET6
) {
118 ret
= IPV6_ADDR_CMP(&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
121 logdifferent("diff: VN addr", a
, b
);
131 void rfapiNveAddr2Str(struct rfapi_nve_addr
*na
, char *buf
, int bufsize
)
136 #define REMAIN (bufsize - (p-buf))
137 #define INCP {p += (r > REMAIN)? REMAIN: r;}
142 r
= snprintf(p
, REMAIN
, "VN=");
145 if (!rfapiRfapiIpAddr2Str(&na
->vn
, p
, REMAIN
))
148 buf
[bufsize
- 1] = 0;
149 p
= buf
+ strlen(buf
);
151 r
= snprintf(p
, REMAIN
, ", UN=");
154 rfapiRfapiIpAddr2Str(&na
->un
, p
, REMAIN
);
157 buf
[bufsize
- 1] = 0;