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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "lib/zebra.h"
26 #include "lib/prefix.h"
27 #include "lib/table.h"
29 #include "lib/memory.h"
30 #include "lib/routemap.h"
32 #include "lib/linklist.h"
33 #include "lib/command.h"
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_ecommunity.h"
37 #include "bgpd/bgp_attr.h"
38 #include "bgpd/bgp_mplsvpn.h"
40 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
41 #include "bgpd/rfapi/rfapi.h"
42 #include "bgpd/rfapi/rfapi_backend.h"
44 #include "bgpd/bgp_route.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_community.h"
47 #include "bgpd/bgp_vnc_types.h"
49 #include "bgpd/rfapi/rfapi_import.h"
50 #include "bgpd/rfapi/rfapi_private.h"
51 #include "bgpd/rfapi/rfapi_monitor.h"
52 #include "bgpd/rfapi/rfapi_rib.h"
53 #include "bgpd/rfapi/rfapi_vty.h"
54 #include "bgpd/rfapi/rfapi_ap.h"
55 #include "bgpd/rfapi/rfapi_encap_tlv.h"
56 #include "bgpd/rfapi/vnc_debug.h"
58 #define DEBUG_L2_EXTRA 0
60 #define VNC_SHOW_STR "VNC information\n"
62 /* format related utilies */
65 #define FMT_MIN 60 /* seconds */
66 #define FMT_HOUR (60 * FMT_MIN)
67 #define FMT_DAY (24 * FMT_HOUR)
68 #define FMT_YEAR (365 * FMT_DAY)
71 rfapiFormatSeconds (uint32_t seconds
, char *buf
, size_t len
)
73 int year
, day
, hour
, min
;
75 if (seconds
>= FMT_YEAR
)
77 year
= seconds
/ FMT_YEAR
;
78 seconds
-= year
* FMT_YEAR
;
83 if (seconds
>= FMT_DAY
)
85 day
= seconds
/ FMT_DAY
;
86 seconds
-= day
* FMT_DAY
;
91 if (seconds
>= FMT_HOUR
)
93 hour
= seconds
/ FMT_HOUR
;
94 seconds
-= hour
* FMT_HOUR
;
99 if (seconds
>= FMT_MIN
)
101 min
= seconds
/ FMT_MIN
;
102 seconds
-= min
* FMT_MIN
;
109 snprintf (buf
, len
, "%dy%dd%dh", year
, day
, hour
);
113 snprintf (buf
, len
, "%dd%dh%dm", day
, hour
, min
);
117 snprintf (buf
, len
, "%02d:%02d:%02d", hour
, min
, seconds
);
124 rfapiFormatAge (time_t age
, char *buf
, size_t len
)
126 time_t now
, age_adjusted
;
128 now
= rfapi_time (NULL
);
129 age_adjusted
= now
- age
;
131 return rfapiFormatSeconds (age_adjusted
, buf
, len
);
136 * Reimplementation of quagga/lib/prefix.c function, but
137 * for RFAPI-style prefixes
140 rfapiRprefixApplyMask (struct rfapi_ip_prefix
*rprefix
)
146 static uint8_t maskbit
[] =
147 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
149 switch (rprefix
->prefix
.addr_family
)
152 index
= rprefix
->length
/ 8;
155 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v4
;
156 offset
= rprefix
->length
% 8;
157 pnt
[index
] &= maskbit
[offset
];
165 index
= rprefix
->length
/ 8;
168 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v6
;
169 offset
= rprefix
->length
% 8;
170 pnt
[index
] &= maskbit
[offset
];
183 * translate a quagga prefix into a rfapi IP address. The
184 * prefix is REQUIRED to be 32 bits for IPv4 and 128 bits for IPv6
192 rfapiQprefix2Raddr (struct prefix
*qprefix
, struct rfapi_ip_addr
*raddr
)
194 memset (raddr
, 0, sizeof (struct rfapi_ip_addr
));
195 raddr
->addr_family
= qprefix
->family
;
196 switch (qprefix
->family
)
199 if (qprefix
->prefixlen
!= 32)
201 raddr
->addr
.v4
= qprefix
->u
.prefix4
;
204 if (qprefix
->prefixlen
!= 128)
206 raddr
->addr
.v6
= qprefix
->u
.prefix6
;
215 * Translate Quagga prefix to RFAPI prefix
217 /* rprefix->cost set to 0 */
219 rfapiQprefix2Rprefix (struct prefix
*qprefix
, struct rfapi_ip_prefix
*rprefix
)
221 memset (rprefix
, 0, sizeof (struct rfapi_ip_prefix
));
222 rprefix
->length
= qprefix
->prefixlen
;
223 rprefix
->prefix
.addr_family
= qprefix
->family
;
224 switch (qprefix
->family
)
227 rprefix
->prefix
.addr
.v4
= qprefix
->u
.prefix4
;
230 rprefix
->prefix
.addr
.v6
= qprefix
->u
.prefix6
;
238 rfapiRprefix2Qprefix (struct rfapi_ip_prefix
*rprefix
, struct prefix
*qprefix
)
240 memset (qprefix
, 0, sizeof (struct prefix
));
241 qprefix
->prefixlen
= rprefix
->length
;
242 qprefix
->family
= rprefix
->prefix
.addr_family
;
244 switch (rprefix
->prefix
.addr_family
)
247 qprefix
->u
.prefix4
= rprefix
->prefix
.addr
.v4
;
250 qprefix
->u
.prefix6
= rprefix
->prefix
.addr
.v6
;
259 * returns 1 if prefixes have same addr family, prefix len, and address
260 * Note that host bits matter in this comparison!
262 * For paralellism with quagga/lib/prefix.c. if we need a comparison
263 * where host bits are ignored, call that function rfapiRprefixCmp.
266 rfapiRprefixSame (struct rfapi_ip_prefix
*hp1
, struct rfapi_ip_prefix
*hp2
)
268 if (hp1
->prefix
.addr_family
!= hp2
->prefix
.addr_family
)
270 if (hp1
->length
!= hp2
->length
)
272 if (hp1
->prefix
.addr_family
== AF_INET
)
273 if (IPV4_ADDR_SAME (&hp1
->prefix
.addr
.v4
, &hp2
->prefix
.addr
.v4
))
275 if (hp1
->prefix
.addr_family
== AF_INET6
)
276 if (IPV6_ADDR_SAME (&hp1
->prefix
.addr
.v6
, &hp2
->prefix
.addr
.v6
))
282 rfapiRaddr2Qprefix (struct rfapi_ip_addr
*hia
, struct prefix
*pfx
)
284 memset (pfx
, 0, sizeof (struct prefix
));
285 pfx
->family
= hia
->addr_family
;
287 switch (hia
->addr_family
)
291 pfx
->u
.prefix4
= hia
->addr
.v4
;
294 pfx
->prefixlen
= 128;
295 pfx
->u
.prefix6
= hia
->addr
.v6
;
304 rfapiL2o2Qprefix (struct rfapi_l2address_option
*l2o
, struct prefix
*pfx
)
306 memset (pfx
, 0, sizeof (struct prefix
));
307 pfx
->family
= AF_ETHERNET
;
309 pfx
->u
.prefix_eth
= l2o
->macaddr
;
313 rfapiEthAddr2Str (const struct ethaddr
*ea
, char *buf
, int bufsize
)
318 assert (bufsize
> (3 * ETHER_ADDR_LEN
));
320 for (i
= 0; i
<= ETHER_ADDR_LEN
; ++i
)
322 sprintf (p
, "%02x", ea
->octet
[i
]);
323 if (i
< (ETHER_ADDR_LEN
- 1))
331 rfapiStr2EthAddr (const char *str
, struct ethaddr
*ea
)
336 if (sscanf (str
, "%2x:%2x:%2x:%2x:%2x:%2x",
337 a
+ 0, a
+ 1, a
+ 2, a
+ 3, a
+ 4, a
+ 5) != 6)
343 for (i
= 0; i
< 6; ++i
)
344 ea
->octet
[i
] = a
[i
] & 0xff;
350 rfapi_ntop (int af
, const void *src
, char *buf
, socklen_t size
)
352 if (af
== AF_ETHERNET
)
354 return rfapiEthAddr2Str ((const struct ethaddr
*) src
, buf
, size
);
357 return inet_ntop (af
, src
, buf
, size
);
361 rfapiDebugPrintf (void *dummy
, const char *format
, ...)
364 va_start (args
, format
);
365 vzlog (NULL
, LOG_DEBUG
, format
, args
);
371 rfapiStdioPrintf (void *stream
, const char *format
, ...)
376 va_start (args
, format
);
378 switch ((uintptr_t) stream
)
390 vfprintf (file
, format
, args
);
395 /* Fake out for debug logging */
396 static struct vty vty_dummy_zlog
;
397 static struct vty vty_dummy_stdio
;
398 #define HVTY_NEWLINE ((vty == &vty_dummy_zlog)? "": VTY_NEWLINE)
401 str_vty_newline (struct vty
*vty
)
403 if (vty
== &vty_dummy_zlog
)
410 void *stream
, /* input */
411 int (**fp
) (void *, const char *, ...), /* output */
412 struct vty
**vty
, /* output */
413 void **outstream
, /* output */
414 const char **vty_newline
) /* output */
419 vty_dummy_zlog
.type
= VTY_SHELL
; /* for VTY_NEWLINE */
420 *vty
= &vty_dummy_zlog
;
421 *fp
= (int (*)(void *, const char *,...)) rfapiDebugPrintf
;
423 *vty_newline
= str_vty_newline (*vty
);
424 return (vzlog_test (NULL
, LOG_DEBUG
));
427 if (((uintptr_t) stream
== (uintptr_t) 1) ||
428 ((uintptr_t) stream
== (uintptr_t) 2))
431 vty_dummy_stdio
.type
= VTY_SHELL
; /* for VTY_NEWLINE */
432 *vty
= &vty_dummy_stdio
;
433 *fp
= (int (*)(void *, const char *,...)) rfapiStdioPrintf
;
435 *vty_newline
= str_vty_newline (*vty
);
441 *vty
= stream
; /* VTY_NEWLINE requires vty to be legit */
442 *fp
= (int (*)(void *, const char *,...)) vty_out
;
444 *vty_newline
= str_vty_newline (*vty
);
451 /* called from bgpd/bgp_vty.c'route_vty_out() */
453 rfapi_vty_out_vncinfo (
463 * Print, on an indented line:
464 * UN address [if VPN route and VNC UN addr subtlv]
470 if (safi
== SAFI_MPLS_VPN
)
472 struct prefix pfx_un
;
474 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
477 vty_out (vty
, "UN=%s", inet_ntop (pfx_un
.family
,
478 pfx_un
.u
.val
, buf
, BUFSIZ
));
482 if (bi
->attr
&& bi
->attr
->extra
&& bi
->attr
->extra
->ecommunity
)
484 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
485 ECOMMUNITY_FORMAT_ROUTE_MAP
);
486 vty_out (vty
, " EC{%s}", s
);
487 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
490 if (bi
->extra
!= NULL
)
491 vty_out (vty
, " label=%u", decode_label (bi
->extra
->tag
));
493 if (!rfapiGetVncLifetime (bi
->attr
, &lifetime
))
495 vty_out (vty
, " life=%d", lifetime
);
498 vty_out (vty
, " type=%s, subtype=%d",
499 zebra_route_string (bi
->type
), bi
->sub_type
);
501 vty_out (vty
, "%s", HVTY_NEWLINE
);
505 rfapiPrintAttrPtrs (void *stream
, struct attr
*attr
)
507 int (*fp
) (void *, const char *, ...);
510 const char *vty_newline
;
512 struct attr_extra
*ae
;
515 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
518 fp (out
, "Attr[%p]:%s", attr
, HVTY_NEWLINE
);
523 inet_ntop (AF_INET
, &attr
->nexthop
, buf
, BUFSIZ
);
524 fp (out
, " nexthop=%s%s", buf
, HVTY_NEWLINE
);
526 fp (out
, " aspath=%p, refcnt=%d%s", attr
->aspath
,
527 (attr
->aspath
? attr
->aspath
->refcnt
: 0), HVTY_NEWLINE
);
528 fp (out
, " community=%p, refcnt=%d%s", attr
->community
,
529 (attr
->community
? attr
->community
->refcnt
: 0), HVTY_NEWLINE
);
531 if ((ae
= attr
->extra
))
533 fp (out
, " ecommunity=%p, refcnt=%d%s", ae
->ecommunity
,
534 (ae
->ecommunity
? ae
->ecommunity
->refcnt
: 0), HVTY_NEWLINE
);
535 fp (out
, " cluster=%p, refcnt=%d%s", ae
->cluster
,
536 (ae
->cluster
? ae
->cluster
->refcnt
: 0), HVTY_NEWLINE
);
537 fp (out
, " transit=%p, refcnt=%d%s", ae
->transit
,
538 (ae
->transit
? ae
->transit
->refcnt
: 0), HVTY_NEWLINE
);
543 * Print BI in an Import Table
546 rfapiPrintBi (void *stream
, struct bgp_info
*bi
)
551 int (*fp
) (void *, const char *, ...);
554 const char *vty_newline
;
560 struct ethaddr macaddr
;
561 struct rfapi_l2address_option l2o_buf
;
562 uint8_t l2hid
=0; /* valid if has_macaddr */
564 #define REMAIN (BUFSIZ - (p-line))
565 #define INCP {p += (r > REMAIN)? REMAIN: r;}
567 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
573 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) && bi
->extra
574 && bi
->extra
->vnc
.import
.timer
)
576 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
577 r
= snprintf (p
, REMAIN
, " [%4lu] ", thread_timer_remain_second (t
));
583 r
= snprintf (p
, REMAIN
, " ");
589 /* TBD This valid only for SAFI_MPLS_VPN, but not for encap */
590 if (decode_rd_type(bi
->extra
->vnc
.import
.rd
.val
) == RD_TYPE_VNC_ETH
)
593 memcpy (macaddr
.octet
, bi
->extra
->vnc
.import
.rd
.val
+ 2, 6);
594 l2hid
= bi
->extra
->vnc
.import
.rd
.val
[1];
603 * RFP option sizes (they are opaque values)
604 * extended communities (RTs)
606 if (bi
->attr
&& bi
->attr
->extra
)
609 int printed_1st_gol
= 0;
610 struct bgp_attr_encap_subtlv
*pEncap
;
611 struct prefix pfx_un
;
612 int af
= BGP_MP_NEXTHOP_FAMILY (bi
->attr
->extra
->mp_nexthop_len
);
617 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET
,
618 &bi
->attr
->extra
->mp_nexthop_global_in
,
622 else if (af
== AF_INET6
)
624 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET6
,
625 &bi
->attr
->extra
->mp_nexthop_global
,
631 r
= snprintf (p
, REMAIN
, "?");
636 * VNC tunnel subtlv, if present, contains UN address
638 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
640 r
= snprintf (p
, REMAIN
, " un=%s", inet_ntop (pfx_un
.family
,
648 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
))
650 r
= snprintf (p
, REMAIN
, " nolife");
655 if (lifetime
== 0xffffffff)
656 r
= snprintf (p
, REMAIN
, " %6s", "infini");
658 r
= snprintf (p
, REMAIN
, " %6u", lifetime
);
662 /* RFP option lengths */
663 for (pEncap
= bi
->attr
->extra
->vnc_subtlvs
; pEncap
;
664 pEncap
= pEncap
->next
)
667 if (pEncap
->type
== BGP_VNC_SUBTLV_TYPE_RFPOPTION
)
671 r
= snprintf (p
, REMAIN
, ",");
676 r
= snprintf (p
, REMAIN
, " "); /* leading space */
679 r
= snprintf (p
, REMAIN
, "%d", pEncap
->length
);
686 if (bi
->attr
->extra
->ecommunity
)
688 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
689 ECOMMUNITY_FORMAT_ROUTE_MAP
);
690 r
= snprintf (p
, REMAIN
, " %s", s
);
692 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
697 r
= snprintf (p
, REMAIN
, " bi@%p", bi
);
700 r
= snprintf (p
, REMAIN
, " p@%p", bi
->peer
);
703 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
705 r
= snprintf (p
, REMAIN
, " HD=yes");
710 r
= snprintf (p
, REMAIN
, " HD=no");
719 r
= snprintf (p
, REMAIN
, " W=%d", bi
->attr
->extra
->weight
);
723 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
725 r
= snprintf (p
, REMAIN
, " LP=%d", bi
->attr
->local_pref
);
730 r
= snprintf (p
, REMAIN
, " LP=unset");
736 snprintf (p
, REMAIN
, " %c:%u", zebra_route_char (bi
->type
), bi
->sub_type
);
739 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
743 fp (out
, " RD HID=%d ETH=%02x:%02x:%02x:%02x:%02x:%02x%s",
748 macaddr
.octet
[3], macaddr
.octet
[4], macaddr
.octet
[5], HVTY_NEWLINE
);
751 if (!rfapiGetL2o (bi
->attr
, &l2o_buf
))
754 " L2O ETH=%02x:%02x:%02x:%02x:%02x:%02x LBL=%d LNI=%d LHI=%hhu%s",
755 l2o_buf
.macaddr
.octet
[0], l2o_buf
.macaddr
.octet
[1],
756 l2o_buf
.macaddr
.octet
[2], l2o_buf
.macaddr
.octet
[3],
757 l2o_buf
.macaddr
.octet
[4], l2o_buf
.macaddr
.octet
[5], l2o_buf
.label
,
758 l2o_buf
.logical_net_id
, l2o_buf
.local_nve_id
, HVTY_NEWLINE
);
760 if (bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
765 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
766 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
771 fp (out
, " IP: %s%s", sp
, HVTY_NEWLINE
);
775 struct rfapi_un_option
*uo
= rfapi_encap_tlv_to_un_option (bi
->attr
);
778 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
779 rfapi_un_options_free (uo
);
785 rfapiMonitorVpn2Str (struct rfapi_monitor_vpn
*m
, char *buf
, int size
)
787 char buf_pfx
[BUFSIZ
];
792 rfapiRfapiIpAddr2Str (&m
->rfd
->un_addr
, buf_vn
, BUFSIZ
);
793 rfapiRfapiIpAddr2Str (&m
->rfd
->vn_addr
, buf_un
, BUFSIZ
);
795 rc
= snprintf (buf
, size
,
796 "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p",
797 m
, m
->next
, m
->rfd
, buf_vn
, buf_un
,
798 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
799 m
->p
.prefixlen
, m
->node
);
807 rfapiDebugPrintMonitorVpn (void *stream
, struct rfapi_monitor_vpn
*m
)
811 int (*fp
) (void *, const char *, ...);
814 const char *vty_newline
;
816 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
819 rfapiMonitorVpn2Str (m
, buf
, BUFSIZ
);
820 fp (out
, " Mon %s%s", buf
, HVTY_NEWLINE
);
824 rfapiDebugPrintMonitorEncap (void *stream
, struct rfapi_monitor_encap
*m
)
826 int (*fp
) (void *, const char *, ...);
829 const char *vty_newline
;
831 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
834 fp (out
, " Mon m=%p, next=%p, node=%p, bi=%p%s",
835 m
, m
->next
, m
->node
, m
->bi
, HVTY_NEWLINE
);
839 rfapiShowItNode (void *stream
, struct route_node
*rn
)
844 int (*fp
) (void *, const char *, ...);
847 const char *vty_newline
;
849 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
852 fp (out
, "%s/%d @%p #%d%s",
853 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
854 rn
->p
.prefixlen
, rn
, rn
->lock
, HVTY_NEWLINE
);
856 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
858 rfapiPrintBi (stream
, bi
);
861 /* doesn't show montors */
865 rfapiShowImportTable (
868 struct route_table
*rt
,
871 struct route_node
*rn
;
874 int (*fp
) (void *, const char *, ...);
877 const char *vty_newline
;
879 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
882 fp (out
, "Import Table [%s]%s", label
, HVTY_NEWLINE
);
884 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
888 if (rn
->p
.family
== AF_ETHERNET
)
890 rfapiEthAddr2Str (&rn
->p
.u
.prefix_eth
, buf
, BUFSIZ
);
894 inet_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
);
897 fp (out
, "%s/%d @%p #%d%s", buf
, rn
->p
.prefixlen
, rn
, rn
->lock
- 1, /* account for loop iterator locking */
900 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
902 rfapiPrintBi (stream
, bi
);
907 struct rfapi_monitor_vpn
*m
;
908 for (m
= RFAPI_MONITOR_VPN (rn
); m
; m
= m
->next
)
910 rfapiDebugPrintMonitorVpn (stream
, m
);
915 struct rfapi_monitor_encap
*m
;
916 for (m
= RFAPI_MONITOR_ENCAP (rn
); m
; m
= m
->next
)
918 rfapiDebugPrintMonitorEncap (stream
, m
);
925 rfapiShowVncQueries (void *stream
, struct prefix
*pfx_match
)
929 struct listnode
*node
;
930 struct rfapi_descriptor
*rfd
;
932 int (*fp
) (void *, const char *, ...);
935 const char *vty_newline
;
937 int printedheader
= 0;
940 int nves_with_queries
= 0;
941 int nves_displayed
= 0;
943 int queries_total
= 0;
944 int queries_displayed
= 0;
946 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
949 bgp
= bgp_get_default (); /* assume 1 instance for now */
952 vty_out (vty
, "No BGP instance%s", VTY_NEWLINE
);
959 vty_out (vty
, "No RFAPI instance%s", VTY_NEWLINE
);
963 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
966 struct route_node
*rn
;
967 int printedquerier
= 0;
972 if (rfd
->mon
|| (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
)))
986 for (rn
= route_top (rfd
->mon
); rn
; rn
= route_next (rn
))
988 struct rfapi_monitor_vpn
*m
;
989 char buf_remain
[BUFSIZ
];
990 char buf_pfx
[BUFSIZ
];
999 if (pfx_match
&& !prefix_match (pfx_match
, &rn
->p
) &&
1000 !prefix_match (&rn
->p
, pfx_match
))
1003 ++queries_displayed
;
1008 fp (out
, "%s", VTY_NEWLINE
);
1009 fp (out
, "%-15s %-15s %-15s %-10s%s",
1010 "VN Address", "UN Address",
1011 "Target", "Remaining", VTY_NEWLINE
);
1014 if (!printedquerier
)
1016 char buf_vn
[BUFSIZ
];
1017 char buf_un
[BUFSIZ
];
1019 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1020 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1022 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1028 fp (out
, "%-15s %-15s", "", "");
1032 rfapiFormatSeconds (thread_timer_remain_second (m
->timer
),
1033 buf_remain
, BUFSIZ
);
1035 fp (out
, " %-15s %-10s%s",
1036 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
1037 buf_remain
, VTY_NEWLINE
);
1044 if (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
))
1049 struct rfapi_monitor_eth
*mon_eth
;
1053 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1056 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1060 char buf_remain
[BUFSIZ
];
1061 char buf_pfx
[BUFSIZ
];
1062 struct prefix pfx_mac
;
1066 vnc_zlog_debug_verbose ("%s: checking rfd=%p mon_eth=%p", __func__
, rfd
,
1069 memset ((void *) &pfx_mac
, 0, sizeof (struct prefix
));
1070 pfx_mac
.family
= AF_ETHERNET
;
1071 pfx_mac
.prefixlen
= 48;
1072 pfx_mac
.u
.prefix_eth
= mon_eth
->macaddr
;
1074 if (pfx_match
&& !prefix_match (pfx_match
, &pfx_mac
) &&
1075 !prefix_match (&pfx_mac
, pfx_match
))
1078 ++queries_displayed
;
1083 fp (out
, "%s", VTY_NEWLINE
);
1084 fp (out
, "%-15s %-15s %-17s %10s %-10s%s",
1085 "VN Address", "UN Address",
1086 "Target", "LNI", "Remaining", VTY_NEWLINE
);
1089 if (!printedquerier
)
1091 char buf_vn
[BUFSIZ
];
1092 char buf_un
[BUFSIZ
];
1094 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1095 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1097 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1103 fp (out
, "%-15s %-15s", "", "");
1107 rfapiFormatSeconds (thread_timer_remain_second
1108 (mon_eth
->timer
), buf_remain
, BUFSIZ
);
1110 fp (out
, " %-17s %10d %-10s%s",
1111 rfapi_ntop (pfx_mac
.family
, &pfx_mac
.u
.prefix
, buf_pfx
,
1112 BUFSIZ
), mon_eth
->logical_net_id
, buf_remain
,
1120 fp (out
, "%s", VTY_NEWLINE
);
1121 fp (out
, "Displayed %d out of %d total queries%s",
1122 queries_displayed
, queries_total
, VTY_NEWLINE
);
1128 rfapiPrintRemoteRegBi (
1131 struct route_node
*rn
,
1132 struct bgp_info
*bi
)
1134 int (*fp
) (void *, const char *, ...);
1137 const char *vty_newline
;
1138 struct prefix pfx_un
;
1139 struct prefix pfx_vn
;
1142 bgp_encap_types tun_type
;
1144 char buf_pfx
[BUFSIZ
];
1145 char buf_ntop
[BUFSIZ
];
1146 char buf_un
[BUFSIZ
];
1147 char buf_vn
[BUFSIZ
];
1148 char buf_lifetime
[BUFSIZ
];
1152 return 0; /* for debug log, print into buf & call output once */
1154 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1161 snprintf (buf_pfx
, BUFSIZ
, "%s/%d",
1162 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf_ntop
, BUFSIZ
),
1164 buf_pfx
[BUFSIZ
- 1] = 0;
1171 if (!rfapiGetUnAddrOfVpnBi (bi
, &pfx_un
))
1173 snprintf (buf_un
, BUFSIZ
, "%s",
1174 inet_ntop (pfx_un
.family
, &pfx_un
.u
.prefix
, buf_ntop
,
1177 buf_un
[BUFSIZ
- 1] = 0;
1179 rfapiGetTunnelType(bi
->attr
,&tun_type
);
1184 if (tun_type
== BGP_ENCAP_TYPE_MPLS
)
1186 /* MPLS carries un in nrli next hop (same as vn for IP tunnels) */
1189 u_int32_t l
= decode_label (bi
->extra
->tag
);
1190 snprintf (buf_vn
, BUFSIZ
, "Label: %d", l
);
1192 else /* should never happen */
1194 snprintf (buf_vn
, BUFSIZ
, "Label: N/A");
1199 rfapiNexthop2Prefix (bi
->attr
, &pfx_vn
);
1200 snprintf (buf_vn
, BUFSIZ
, "%s",
1201 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1203 buf_vn
[BUFSIZ
- 1] = 0;
1207 * Cost is encoded in local_pref as (255-cost)
1208 * See rfapi_import.c'rfapiRouteInfo2NextHopEntry() for conversion
1213 uint32_t local_pref
;
1214 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1215 local_pref
= bi
->attr
->local_pref
;
1218 cost
= (local_pref
> 255) ? 0 : 255 - local_pref
;
1225 fp (out
, "%-20s ", buf_pfx
);
1226 fp (out
, "%-15s ", buf_vn
);
1227 fp (out
, "%-15s ", buf_un
);
1228 fp (out
, "%-4d ", cost
);
1231 /* NB rfapiGetVncLifetime sets infinite value when returning !0 */
1232 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
) ||
1233 (lifetime
== RFAPI_INFINITE_LIFETIME
))
1236 fp (out
, "%-10s ", "infinite");
1240 time_t t_lifetime
= lifetime
;
1241 rfapiFormatSeconds (t_lifetime
, buf_lifetime
, BUFSIZ
);
1242 fp (out
, "%-10s ", buf_lifetime
);
1245 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) &&
1246 bi
->extra
&& bi
->extra
->vnc
.import
.timer
)
1251 char buf_age
[BUFSIZ
];
1253 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
1254 remaining
= thread_timer_remain_second (t
);
1256 #if RFAPI_REGISTRATIONS_REPORT_AGE
1258 * Calculate when the timer started. Doing so here saves
1259 * us a timestamp field in "struct bgp_info".
1261 * See rfapi_import.c'rfapiBiStartWithdrawTimer() for the
1262 * original calculation.
1264 age
= rfapiGetHolddownFromLifetime (lifetime
, factor
) - remaining
;
1265 #else /* report remaining time */
1268 rfapiFormatSeconds (age
, buf_age
, BUFSIZ
);
1270 fp (out
, "%-10s ", buf_age
);
1273 else if (RFAPI_LOCAL_BI (bi
))
1276 char buf_age
[BUFSIZ
];
1278 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.create_time
)
1280 rfapiFormatAge (bi
->extra
->vnc
.import
.create_time
, buf_age
, BUFSIZ
);
1287 fp (out
, "%-10s ", buf_age
);
1289 fp (out
, "%s", HVTY_NEWLINE
);
1291 if (rn
->p
.family
== AF_ETHERNET
)
1294 * If there is a corresponding IP address && != VN address,
1295 * print that on the next line
1298 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
1302 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
1303 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
1305 buf_ntop
[BUFSIZ
- 1] = 0;
1307 if (sp
&& strcmp (buf_vn
, sp
) != 0)
1309 fp (out
, " IP: %s", sp
);
1315 if (tun_type
!= BGP_ENCAP_TYPE_MPLS
&& bi
->extra
)
1317 u_int32_t l
= decode_label (bi
->extra
->tag
);
1318 if (!MPLS_LABEL_IS_NULL (l
))
1320 fp (out
, " Label: %d", l
);
1326 fp (out
, "%s", HVTY_NEWLINE
);
1332 rfapiShowRemoteRegistrationsIt (
1335 struct rfapi_import_table
*it
,
1336 struct prefix
*prefix_only
,
1337 int show_expiring
, /* either/or */
1340 int show_imported
, /* either/or */
1341 uint32_t *pLni
) /* AFI_ETHER only */
1344 int printed_rtlist_hdr
= 0;
1346 int (*fp
) (void *, const char *, ...);
1349 const char *vty_newline
;
1353 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1356 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1359 struct route_node
*rn
;
1361 if (!it
->imported_vpn
[afi
])
1364 for (rn
= route_top (it
->imported_vpn
[afi
]); rn
; rn
= route_next (rn
))
1367 struct bgp_info
*bi
;
1370 /* allow for wider or more narrow mask from user */
1372 !prefix_match (prefix_only
, &rn
->p
) &&
1373 !prefix_match (&rn
->p
, prefix_only
))
1378 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
1381 if (!show_local
&& RFAPI_LOCAL_BI (bi
))
1384 /* local route from RFP */
1388 if (!show_remote
&& !RFAPI_LOCAL_BI (bi
))
1395 if (show_expiring
&& !CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1398 if (!show_expiring
&& CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1401 if (bi
->type
== ZEBRA_ROUTE_BGP_DIRECT
||
1402 bi
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
)
1414 if (count_only
== 1)
1416 if (!printed_rtlist_hdr
)
1418 const char *agetype
= "";
1420 const char *type
= "";
1433 if (RFAPI_LOCAL_BI (bi
))
1444 s
= ecommunity_ecom2str (it
->rt_import_list
,
1445 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1449 fp (out
, "%s[%s] L2VPN Network 0x%x (%u) RT={%s}%s",
1450 HVTY_NEWLINE
, type
, *pLni
, (*pLni
& 0xfff), s
,
1455 fp (out
, "%s[%s] Prefix RT={%s}%s",
1456 HVTY_NEWLINE
, type
, s
, HVTY_NEWLINE
);
1458 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1462 #if RFAPI_REGISTRATIONS_REPORT_AGE
1465 agetype
= "Remaining";
1468 else if (show_local
)
1473 printed_rtlist_hdr
= 1;
1475 fp (out
, "%-20s %-15s %-15s %4s %-10s %-10s%s",
1476 (pLni
? "L2 Address/IP" : "Prefix"),
1477 "VN Address", "UN Address", "Cost",
1478 "Lifetime", agetype
, HVTY_NEWLINE
);
1480 printed
+= rfapiPrintRemoteRegBi (bgp
, stream
, rn
, bi
);
1488 const char *type
= "prefixes";
1492 type
= "imported prefixes";
1498 type
= "prefixes in holddown";
1502 if (show_local
&& !show_remote
)
1504 type
= "locally registered prefixes";
1506 else if (!show_local
&& show_remote
)
1508 type
= "remotely registered prefixes";
1513 fp (out
, "Displayed %d out of %d %s%s",
1514 printed
, total
, type
, HVTY_NEWLINE
);
1522 * rfapiShowRemoteRegistrations
1524 * Similar to rfapiShowImportTable() above. This function
1525 * is mean to produce the "remote" portion of the output
1526 * of "show vnc registrations".
1529 rfapiShowRemoteRegistrations (
1531 struct prefix
*prefix_only
,
1539 struct rfapi_import_table
*it
;
1542 bgp
= bgp_get_default ();
1554 for (it
= h
->imports
; it
; it
= it
->next
)
1557 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1558 show_expiring
, show_local
,
1559 show_remote
, show_imported
, NULL
);
1564 void *cursor
= NULL
;
1566 uintptr_t lni_as_ptr
;
1571 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1574 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1578 if ((lni_as_ptr
& 0xffffffff) == lni_as_ptr
)
1580 lni
= (uint32_t) (lni_as_ptr
& 0xffffffff);
1585 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1586 show_expiring
, show_local
,
1587 show_remote
, show_imported
, pLni
);
1594 /*------------------------------------------
1595 * rfapiRfapiIpAddr2Str
1597 * UI helper: generate string from rfapi_ip_addr
1600 * a IP v4/v6 address
1603 * buf put string here
1604 * bufsize max space to write
1607 * NULL conversion failed
1608 * non-NULL pointer to buf
1609 --------------------------------------------*/
1611 rfapiRfapiIpAddr2Str (struct rfapi_ip_addr
*a
, char *buf
, int bufsize
)
1613 const char *rc
= NULL
;
1615 switch (a
->addr_family
)
1618 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1621 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1628 rfapiPrintRfapiIpAddr (void *stream
, struct rfapi_ip_addr
*a
)
1631 const char *rc
= NULL
;
1633 int (*fp
) (void *, const char *, ...);
1636 const char *vty_newline
;
1638 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1641 rc
= rfapiRfapiIpAddr2Str (a
, buf
, BUFSIZ
);
1644 fp (out
, "%s", buf
);
1648 rfapiRfapiIpPrefix2Str (struct rfapi_ip_prefix
*p
, char *buf
, int bufsize
)
1650 struct rfapi_ip_addr
*a
= &p
->prefix
;
1651 const char *rc
= NULL
;
1653 switch (a
->addr_family
)
1656 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1659 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1665 int alen
= strlen (buf
);
1666 int remaining
= bufsize
- alen
- 1;
1671 slen
= snprintf (buf
+ alen
, remaining
, "/%u", p
->length
);
1672 if (slen
< remaining
) /* see man page for snprintf(3) */
1681 rfapiPrintRfapiIpPrefix (void *stream
, struct rfapi_ip_prefix
*p
)
1686 int (*fp
) (void *, const char *, ...);
1689 const char *vty_newline
;
1691 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1694 rc
= rfapiRfapiIpPrefix2Str (p
, buf
, BUFSIZ
);
1697 fp (out
, "%s:%u", buf
, p
->cost
);
1703 rfapiPrintRd (struct vty
*vty
, struct prefix_rd
*prd
)
1708 prefix_rd2str (prd
, buf
, BUFSIZ
);
1709 buf
[BUFSIZ
- 1] = 0;
1710 vty_out (vty
, "%s", buf
);
1714 rfapiPrintAdvertisedInfo (
1716 struct rfapi_descriptor
*rfd
,
1720 afi_t afi
; /* of the VN address */
1721 struct bgp_node
*bn
;
1722 struct bgp_info
*bi
;
1723 uint8_t type
= ZEBRA_ROUTE_BGP
;
1726 struct prefix_rd prd0
;
1727 struct prefix_rd
*prd
;
1730 * Find the bgp_info in the RIB corresponding to this
1734 afi
= family2afi (p
->family
);
1735 assert (afi
== AFI_IP
|| afi
== AFI_IP6
);
1737 bgp
= bgp_get_default (); /* assume 1 instance for now */
1740 if (safi
== SAFI_ENCAP
)
1742 memset (&prd0
, 0, sizeof (prd0
));
1743 prd0
.family
= AF_UNSPEC
;
1744 prd0
.prefixlen
= 64;
1751 bn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
1753 vty_out (vty
, " bn=%p%s", bn
, HVTY_NEWLINE
);
1755 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
1757 if (bi
->peer
== rfd
->peer
&&
1759 bi
->sub_type
== BGP_ROUTE_RFP
&&
1760 bi
->extra
&& bi
->extra
->vnc
.export
.rfapi_handle
== (void *) rfd
)
1763 rfapiPrintBi (vty
, bi
);
1770 vty_out (vty
, " --?--%s", HVTY_NEWLINE
);
1777 rfapiPrintDescriptor (struct vty
*vty
, struct rfapi_descriptor
*rfd
)
1779 /* pHD un-addr vn-addr pCB cookie rd lifetime */
1780 /* RT export list */
1781 /* RT import list */
1782 /* list of advertised prefixes */
1783 /* dump import table */
1789 struct rfapi_adb
*adb
;
1792 vty_out (vty
, "%-10p ", rfd
);
1793 rfapiPrintRfapiIpAddr (vty
, &rfd
->un_addr
);
1795 rfapiPrintRfapiIpAddr (vty
, &rfd
->vn_addr
);
1796 vty_out (vty
, " %p %p ", rfd
->response_cb
, rfd
->cookie
);
1797 rfapiPrintRd (vty
, &rfd
->rd
);
1798 vty_out (vty
, " %d", rfd
->response_lifetime
);
1799 vty_out (vty
, " %s", (rfd
->rfg
? rfd
->rfg
->name
: "<orphaned>"));
1800 vty_out (vty
, "%s", HVTY_NEWLINE
);
1802 vty_out (vty
, " Peer %p #%d%s", rfd
->peer
, rfd
->peer
->lock
, HVTY_NEWLINE
);
1804 /* export RT list */
1805 if (rfd
->rt_export_list
)
1808 ecommunity_ecom2str (rfd
->rt_export_list
,
1809 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1810 vty_out (vty
, " Export %s%s", s
, HVTY_NEWLINE
);
1811 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1815 vty_out (vty
, " Export (nil)%s", HVTY_NEWLINE
);
1818 /* import RT list */
1819 if (rfd
->import_table
)
1821 s
= ecommunity_ecom2str (rfd
->import_table
->rt_import_list
,
1822 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1823 vty_out (vty
, " Import %s%s", s
, HVTY_NEWLINE
);
1824 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1828 vty_out (vty
, " Import (nil)%s", HVTY_NEWLINE
);
1831 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1835 family
= afi2family (afi
);
1841 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1844 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1848 /* group like family prefixes together in output */
1849 if (family
!= adb
->prefix_ip
.family
)
1852 prefix2str (&adb
->prefix_ip
, buf
, BUFSIZ
);
1853 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1855 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1856 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->prefix_ip
);
1860 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1863 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1867 prefix2str (&adb
->prefix_eth
, buf
, BUFSIZ
);
1868 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1870 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1872 /* TBD update the following function to print ethernet info */
1873 /* Also need to pass/use rd */
1874 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->prefix_ip
);
1876 vty_out (vty
, "%s", HVTY_NEWLINE
);
1880 * test scripts rely on first line for each nve starting in 1st column,
1881 * leading whitespace for additional detail of that nve
1884 rfapiPrintMatchingDescriptors (struct vty
*vty
,
1885 struct prefix
*vn_prefix
,
1886 struct prefix
*un_prefix
)
1890 struct listnode
*ln
;
1891 struct rfapi_descriptor
*rfd
;
1894 bgp
= bgp_get_default (); /* assume 1 instance for now */
1901 for (ln
= listhead (&h
->descriptors
); ln
; ln
= listnextnode (ln
))
1903 rfd
= listgetdata (ln
);
1909 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
1910 if (!prefix_match (vn_prefix
, &pfx
))
1916 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
1917 if (!prefix_match (un_prefix
, &pfx
))
1923 /* print column header */
1925 "%s %s %s %s %s %s %s %s%s",
1926 "descriptor", "un-addr", "vn-addr", "callback", "cookie",
1927 "RD", "lifetime", "group", HVTY_NEWLINE
);
1929 rfapiPrintDescriptor (vty
, rfd
);
1936 * Parse an address and put into a struct prefix
1939 rfapiCliGetPrefixAddr (struct vty
*vty
, const char *str
, struct prefix
*p
)
1941 if (!str2prefix (str
, p
))
1943 vty_out (vty
, "Malformed address \"%s\"%s", str
, HVTY_NEWLINE
);
1949 if (p
->prefixlen
!= 32)
1951 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1956 if (p
->prefixlen
!= 128)
1958 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1963 vty_out (vty
, "Invalid address \"%s\"%s", str
, HVTY_NEWLINE
);
1970 rfapiCliGetRfapiIpAddr (
1973 struct rfapi_ip_addr
*hai
)
1978 rc
= rfapiCliGetPrefixAddr (vty
, str
, &pfx
);
1982 hai
->addr_family
= pfx
.family
;
1983 if (pfx
.family
== AF_INET
)
1984 hai
->addr
.v4
= pfx
.u
.prefix4
;
1986 hai
->addr
.v6
= pfx
.u
.prefix6
;
1992 * Note: this function does not flush vty output, so if it is called
1993 * with a stream pointing to a vty, the user will have to type something
1994 * before the callback output shows up
1997 rfapiPrintNhl (void *stream
, struct rfapi_next_hop_entry
*next_hops
)
1999 struct rfapi_next_hop_entry
*nh
;
2002 int (*fp
) (void *, const char *, ...);
2005 const char *vty_newline
;
2007 #define REMAIN (BUFSIZ - (p-line))
2008 #define INCP {p += (r > REMAIN)? REMAIN: r;}
2011 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
2014 for (nh
= next_hops
, count
= 1; nh
; nh
= nh
->next
, ++count
)
2021 r
= snprintf (p
, REMAIN
, "%3d pfx=", count
);
2024 if (rfapiRfapiIpPrefix2Str (&nh
->prefix
, p
, REMAIN
))
2026 /* it fit, so count length */
2036 r
= snprintf (p
, REMAIN
, ", un=");
2039 if (rfapiRfapiIpAddr2Str (&nh
->un_address
, p
, REMAIN
))
2041 /* it fit, so count length */
2051 r
= snprintf (p
, REMAIN
, ", vn=");
2054 if (rfapiRfapiIpAddr2Str (&nh
->vn_address
, p
, REMAIN
))
2056 /* it fit, so count length */
2067 line
[BUFSIZ
- 1] = 0;
2068 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
2075 struct rfapi_vn_option
*vo
;
2076 char offset
[] = " ";
2078 for (vo
= nh
->vn_options
; vo
; vo
= vo
->next
)
2084 case RFAPI_VN_OPTION_TYPE_L2ADDR
:
2085 rfapiEthAddr2Str (&vo
->v
.l2addr
.macaddr
, pbuf
,
2087 fp (out
, "%sL2 %s LBL=0x%06x NETID=0x%06x NVEID=%d%s",
2088 offset
, pbuf
, (vo
->v
.l2addr
.label
& 0x00ffffff),
2089 (vo
->v
.l2addr
.logical_net_id
& 0x00ffffff),
2090 vo
->v
.l2addr
.local_nve_id
, HVTY_NEWLINE
);
2093 case RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
:
2094 prefix2str (&vo
->v
.local_nexthop
.addr
, pbuf
, sizeof (pbuf
));
2095 fp (out
, "%sLNH %s cost=%d%s",
2096 offset
, pbuf
, vo
->v
.local_nexthop
.cost
, HVTY_NEWLINE
);
2100 fp (out
, "%svn option type %d (unknown)%s",
2101 offset
, vo
->type
, HVTY_NEWLINE
);
2108 struct rfapi_un_option
*uo
;
2109 char offset
[] = " ";
2111 for (uo
= nh
->un_options
; uo
; uo
= uo
->next
)
2115 case RFAPI_UN_OPTION_TYPE_TUNNELTYPE
:
2116 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
2119 fp (out
, "%sUN Option type %d%s",
2120 offset
, uo
->type
, vty_newline
);
2129 /***********************************************************************
2131 ***********************************************************************/
2134 * Add another nexthop to the NHL
2137 rfapiAddDeleteLocalRfpPrefix (
2138 struct rfapi_ip_addr
*un_addr
,
2139 struct rfapi_ip_addr
*vn_addr
,
2140 struct rfapi_ip_prefix
*rprefix
,
2142 uint32_t lifetime
, /* add only */
2143 struct rfapi_vn_option
*vn_options
,
2144 struct rfapi_next_hop_entry
**head
,
2145 struct rfapi_next_hop_entry
**tail
)
2147 struct rfapi_next_hop_entry
*new;
2153 new = XCALLOC (MTYPE_RFAPI_NEXTHOP
, sizeof (struct rfapi_next_hop_entry
));
2154 new->prefix
= *rprefix
;
2155 new->un_address
= *un_addr
;
2156 new->vn_address
= *vn_addr
;
2158 new->vn_options
= vn_options
;
2161 new->lifetime
= lifetime
;
2165 new->lifetime
= RFAPI_REMOVE_RESPONSE_LIFETIME
;
2169 (*tail
)->next
= new;
2181 struct cmd_token
*carg_prefix
,
2182 struct cmd_token
*carg_vn
,
2183 struct cmd_token
*carg_un
,
2184 struct cmd_token
*carg_cost
, /* optional */
2185 struct cmd_token
*carg_lifetime
, /* optional */
2186 struct cmd_token
*carg_macaddr
, /* optional */
2187 struct cmd_token
*carg_vni
, /* mac present=>mandatory Virtual Network ID */
2189 struct cmd_token
**argv
)
2191 const char *arg_prefix
= carg_prefix
->arg
;
2192 const char *arg_vn
= carg_vn
->arg
;
2193 const char *arg_un
= carg_un
->arg
;
2194 const char *arg_cost
= carg_cost
? carg_cost
->arg
: NULL
;
2195 const char *arg_lifetime
= carg_lifetime
? carg_lifetime
->arg
: NULL
;
2196 const char *arg_macaddr
= carg_macaddr
? carg_macaddr
->arg
: NULL
;
2197 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
2198 struct rfapi_ip_addr vn_address
;
2199 struct rfapi_ip_addr un_address
;
2201 struct rfapi_ip_prefix rpfx
;
2206 struct rfapi_vn_option optary
[10]; /* XXX must be big enough */
2207 struct rfapi_vn_option
*opt
= NULL
;
2210 int rc
= CMD_WARNING
;
2214 struct rfapi_cfg
*rfapi_cfg
;
2216 const char *arg_lnh
= NULL
;
2217 const char *arg_lnh_cost
= NULL
;
2219 bgp
= bgp_get_default (); /* assume 1 instance for now */
2223 vty_out (vty
, "BGP not configured%s", VTY_NEWLINE
);
2228 rfapi_cfg
= bgp
->rfapi_cfg
;
2229 if (!h
|| !rfapi_cfg
)
2232 vty_out (vty
, "RFAPI not configured%s", VTY_NEWLINE
);
2236 for (; argc
; --argc
, ++argv
)
2238 if (!strcmp (argv
[0]->arg
, "local-next-hop"))
2242 vty_out (vty
, "local-next-hop specified more than once%s",
2248 vty_out (vty
, "Missing parameter for local-next-hop%s",
2253 arg_lnh
= argv
[0]->arg
;
2255 if (!strcmp (argv
[0]->arg
, "local-cost"))
2259 vty_out (vty
, "local-cost specified more than once%s",
2265 vty_out (vty
, "Missing parameter for local-cost%s",
2270 arg_lnh_cost
= argv
[0]->arg
;
2274 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &vn_address
)))
2276 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &un_address
)))
2279 /* arg_prefix is optional if mac address is given */
2280 if (arg_macaddr
&& !arg_prefix
)
2283 * fake up a 0/32 or 0/128 prefix
2285 switch (vn_address
.addr_family
)
2288 arg_prefix
= "0.0.0.0/32";
2291 arg_prefix
= "0::0/128";
2294 vty_out (vty
, "Internal error, unknown VN address family%s",
2301 if (!str2prefix (arg_prefix
, &pfx
))
2303 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
,
2307 if (pfx
.family
!= AF_INET
2308 && pfx
.family
!= AF_INET6
)
2310 vty_out (vty
, "prefix \"%s\" has invalid address family%s",
2311 arg_prefix
, VTY_NEWLINE
);
2316 memset (optary
, 0, sizeof (optary
));
2321 cost
= strtoul (arg_cost
, &endptr
, 10);
2322 if (*endptr
!= '\0' || cost
> 255)
2324 vty_out (vty
, "%% Invalid %s value%s", "cost", VTY_NEWLINE
);
2335 if (!strcmp (arg_lifetime
, "infinite"))
2337 lifetime
= RFAPI_INFINITE_LIFETIME
;
2342 lifetime
= strtoul (arg_lifetime
, &endptr
, 10);
2343 if (*endptr
!= '\0')
2345 vty_out (vty
, "%% Invalid %s value%s", "lifetime",
2353 lifetime
= RFAPI_INFINITE_LIFETIME
; /* default infinite */
2361 "%% %s may only be specified with local-next-hop%s",
2362 "local-cost", VTY_NEWLINE
);
2366 lnh_cost
= strtoul (arg_lnh_cost
, &endptr
, 10);
2367 if (*endptr
!= '\0' || lnh_cost
> 255)
2369 vty_out (vty
, "%% Invalid %s value%s", "local-cost",
2383 vty_out (vty
, "%% %s may only be specified with prefix%s",
2384 "local-next-hop", VTY_NEWLINE
);
2387 if ((rc
= rfapiCliGetPrefixAddr (vty
, arg_lnh
,
2388 &optary
[opt_next
].v
.
2389 local_nexthop
.addr
)))
2395 optary
[opt_next
].v
.local_nexthop
.cost
= lnh_cost
;
2396 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
;
2400 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2409 if (arg_vni
&& !arg_macaddr
)
2411 vty_out (vty
, "%% %s may only be specified with mac address%s",
2412 "virtual-network-identifier", VTY_NEWLINE
);
2421 "Missing \"vni\" parameter (mandatory with mac)%s",
2425 VTY_GET_INTEGER ("Logical Network ID",
2426 optary
[opt_next
].v
.l2addr
.logical_net_id
,
2429 if ((rc
= rfapiStr2EthAddr (arg_macaddr
,
2430 &optary
[opt_next
].v
.l2addr
.macaddr
)))
2432 vty_out (vty
, "Invalid %s value%s", "mac address",
2436 /* TBD label, NVE ID */
2438 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
2442 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2451 vnc_zlog_debug_verbose
2452 ("%s: vn=%s, un=%s, prefix=%s, cost=%s, lifetime=%s, lnh=%s",
2453 __func__
, arg_vn
, arg_un
, arg_prefix
,
2454 (arg_cost
? arg_cost
: "NULL"),
2455 (arg_lifetime
? arg_lifetime
: "NULL"),
2456 (arg_lnh
? arg_lnh
: "NULL"));
2458 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
2460 rpfx
.cost
= cost
& 255;
2462 /* look up rf descriptor, call open if it doesn't exist */
2464 rfapi_find_rfd (bgp
, &vn_address
, &un_address
,
2465 (struct rfapi_descriptor
**) &rfd
);
2470 struct rfapi_un_option uo
;
2473 * flag descriptor as provisionally opened for static route
2474 * registration so that we can fix up the other parameters
2475 * when the real open comes along
2477 memset (&uo
, 0, sizeof (uo
));
2478 uo
.type
= RFAPI_UN_OPTION_TYPE_PROVISIONAL
;
2480 rc
= rfapi_open (rfapi_get_rfp_start_val_by_bgp (bgp
), &vn_address
, &un_address
, &uo
, /* flags */
2481 NULL
, NULL
, /* no userdata */
2485 vty_out (vty
, "Can't open session for this NVE: %s%s",
2486 rfapi_error_str (rc
), VTY_NEWLINE
);
2493 vty_out (vty
, "Can't find session for this NVE: %s%s",
2494 rfapi_error_str (rc
), VTY_NEWLINE
);
2500 rfapi_register (rfd
, &rpfx
, lifetime
, NULL
, opt
, RFAPI_REGISTER_ADD
);
2503 struct rfapi_next_hop_entry
*head
= NULL
;
2504 struct rfapi_next_hop_entry
*tail
= NULL
;
2505 struct rfapi_vn_option
*vn_opt_new
;
2507 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded, returning 0", __func__
);
2509 if (h
->rfp_methods
.local_cb
)
2511 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfd
;
2512 vn_opt_new
= rfapi_vn_options_dup (opt
);
2514 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
2515 1, lifetime
, vn_opt_new
, &head
,
2519 h
->flags
|= RFAPI_INCALLBACK
;
2520 (*h
->rfp_methods
.local_cb
) (head
, r
->cookie
);
2521 h
->flags
&= ~RFAPI_INCALLBACK
;
2528 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
2529 vty_out (vty
, "%s", VTY_NEWLINE
);
2530 vty_out (vty
, "Registration failed.%s", VTY_NEWLINE
);
2532 "Confirm that either the VN or UN address matches a configured NVE group.%s",
2537 vnc_zlog_debug_verbose ("%s: fail, rc=%d", __func__
, rc
);
2541 /************************************************************************
2542 * Add prefix With LNH_OPTIONS...
2543 ************************************************************************/
2544 DEFUN (add_vnc_prefix_cost_life_lnh
,
2545 add_vnc_prefix_cost_life_lnh_cmd
,
2546 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) lifetime (1-4294967295) LNH_OPTIONS...",
2547 "Add registration\n"
2549 "Add/modify prefix related information\n"
2552 "VN address of NVE\n"
2553 "VN IPv4 interface address\n"
2554 "VN IPv6 interface address\n"
2555 "UN address of NVE\n"
2556 "UN IPv4 interface address\n"
2557 "UN IPv6 interface address\n"
2558 "Administrative cost [default: 255]\n"
2559 "Administrative cost\n"
2560 "Registration lifetime [default: infinite]\n"
2561 "Lifetime value in seconds\n"
2562 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2564 /* pfx vn un cost life */
2565 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2567 NULL
, NULL
, argc
- 12, argv
+ 12);
2570 DEFUN (add_vnc_prefix_life_cost_lnh
,
2571 add_vnc_prefix_life_cost_lnh_cmd
,
2572 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295) cost (0-255) LNH_OPTIONS...",
2573 "Add registration\n"
2575 "Add/modify prefix related information\n"
2578 "VN address of NVE\n"
2579 "VN IPv4 interface address\n"
2580 "VN IPv6 interface address\n"
2581 "UN address of NVE\n"
2582 "UN IPv4 interface address\n"
2583 "UN IPv6 interface address\n"
2584 "Registration lifetime [default: infinite]\n"
2585 "Lifetime value in seconds\n"
2586 "Administrative cost [default: 255]\n"
2587 "Administrative cost\n"
2588 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2590 /* pfx vn un cost life */
2591 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2593 NULL
, NULL
, argc
- 12, argv
+ 12);
2596 DEFUN (add_vnc_prefix_cost_lnh
,
2597 add_vnc_prefix_cost_lnh_cmd
,
2598 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) LNH_OPTIONS...",
2599 "Add registration\n"
2601 "Add/modify prefix related information\n"
2604 "VN address of NVE\n"
2605 "VN IPv4 interface address\n"
2606 "VN IPv6 interface address\n"
2607 "UN address of NVE\n"
2608 "UN IPv4 interface address\n"
2609 "UN IPv6 interface address\n"
2610 "Administrative cost [default: 255]\n"
2611 "Administrative cost\n"
2612 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2614 /* pfx vn un cost life */
2615 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2617 NULL
, NULL
, argc
- 10, argv
+ 10);
2620 DEFUN (add_vnc_prefix_life_lnh
,
2621 add_vnc_prefix_life_lnh_cmd
,
2622 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295) LNH_OPTIONS...",
2623 "Add registration\n"
2625 "Add/modify prefix related information\n"
2628 "VN address of NVE\n"
2629 "VN IPv4 interface address\n"
2630 "VN IPv6 interface address\n"
2631 "UN address of NVE\n"
2632 "UN IPv4 interface address\n"
2633 "UN IPv6 interface address\n"
2634 "Registration lifetime [default: infinite]\n"
2635 "Lifetime value in seconds\n"
2636 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2638 /* pfx vn un cost life */
2639 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2641 NULL
, NULL
, argc
- 10, argv
+ 10);
2644 DEFUN (add_vnc_prefix_lnh
,
2645 add_vnc_prefix_lnh_cmd
,
2646 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> LNH_OPTIONS...",
2647 "Add registration\n"
2649 "Add/modify prefix related information\n"
2652 "VN address of NVE\n"
2653 "VN IPv4 interface address\n"
2654 "VN IPv6 interface address\n"
2655 "UN address of NVE\n"
2656 "UN IPv4 interface address\n"
2657 "UN IPv6 interface address\n"
2658 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2660 /* pfx vn un cost life */
2661 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2663 NULL
, NULL
, argc
- 8, argv
+ 8);
2666 /************************************************************************
2667 * Add prefix Without LNH_OPTIONS...
2668 ************************************************************************/
2669 DEFUN (add_vnc_prefix_cost_life
,
2670 add_vnc_prefix_cost_life_cmd
,
2671 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) lifetime (1-4294967295)",
2672 "Add registration\n"
2674 "Add/modify prefix related information\n"
2677 "VN address of NVE\n"
2678 "VN IPv4 interface address\n"
2679 "VN IPv6 interface address\n"
2680 "UN address of NVE\n"
2681 "UN IPv4 interface address\n"
2682 "UN IPv6 interface address\n"
2683 "Administrative cost [default: 255]\n"
2684 "Administrative cost\n"
2685 "Registration lifetime [default: infinite]\n"
2686 "Lifetime value in seconds\n"
2687 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2689 /* pfx vn un cost life */
2690 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2692 NULL
, NULL
, 0, NULL
);
2695 DEFUN (add_vnc_prefix_life_cost
,
2696 add_vnc_prefix_life_cost_cmd
,
2697 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295) cost (0-255)",
2698 "Add registration\n"
2700 "Add/modify prefix related information\n"
2703 "VN address of NVE\n"
2704 "VN IPv4 interface address\n"
2705 "VN IPv6 interface address\n"
2706 "UN address of NVE\n"
2707 "UN IPv4 interface address\n"
2708 "UN IPv6 interface address\n"
2709 "Registration lifetime [default: infinite]\n"
2710 "Lifetime value in seconds\n"
2711 "Administrative cost [default: 255]\n"
2712 "Administrative cost\n"
2713 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2715 /* pfx vn un cost life */
2716 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2718 NULL
, NULL
, 0, NULL
);
2721 DEFUN (add_vnc_prefix_cost
,
2722 add_vnc_prefix_cost_cmd
,
2723 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255)",
2724 "Add registration\n"
2726 "Add/modify prefix related information\n"
2729 "VN address of NVE\n"
2730 "VN IPv4 interface address\n"
2731 "VN IPv6 interface address\n"
2732 "UN address of NVE\n"
2733 "UN IPv4 interface address\n"
2734 "UN IPv6 interface address\n"
2735 "Administrative cost [default: 255]\n"
2736 "Administrative cost\n"
2737 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2739 /* pfx vn un cost life */
2740 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2742 NULL
, NULL
, 0, NULL
);
2745 DEFUN (add_vnc_prefix_life
,
2746 add_vnc_prefix_life_cmd
,
2747 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295)",
2748 "Add registration\n"
2750 "Add/modify prefix related information\n"
2753 "VN address of NVE\n"
2754 "VN IPv4 interface address\n"
2755 "VN IPv6 interface address\n"
2756 "UN address of NVE\n"
2757 "UN IPv4 interface address\n"
2758 "UN IPv6 interface address\n"
2759 "Registration lifetime [default: infinite]\n"
2760 "Lifetime value in seconds\n"
2761 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2763 /* pfx vn un cost life */
2764 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2766 NULL
, NULL
, 0, NULL
);
2769 DEFUN (add_vnc_prefix
,
2771 "add vnc prefix <A.B.C.D/M|X:X::X:X/M> vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X>",
2772 "Add registration\n"
2774 "Add/modify prefix related information\n"
2777 "VN address of NVE\n"
2778 "VN IPv4 interface address\n"
2779 "VN IPv6 interface address\n"
2780 "UN address of NVE\n"
2781 "UN IPv4 interface address\n"
2782 "UN IPv6 interface address\n"
2783 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2785 /* pfx vn un cost life */
2786 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2788 NULL
, NULL
, 0, NULL
);
2791 /************************************************************************
2792 * Mac address registrations
2793 ************************************************************************/
2794 DEFUN (add_vnc_mac_vni_prefix_cost_life
,
2795 add_vnc_mac_vni_prefix_cost_life_cmd
,
2796 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M> cost (0-255) lifetime (1-4294967295)",
2797 "Add registration\n"
2799 "Add/modify mac address information\n"
2801 "Virtual Network Identifier follows\n"
2802 "Virtual Network Identifier\n"
2803 "VN address of NVE\n"
2804 "VN IPv4 interface address\n"
2805 "VN IPv6 interface address\n"
2806 "UN address of NVE\n"
2807 "UN IPv4 interface address\n"
2808 "UN IPv6 interface address\n"
2809 "Add/modify prefix related information\n"
2812 "Administrative cost [default: 255]\n"
2813 "Administrative cost\n"
2814 "Registration lifetime [default: infinite]\n"
2815 "Lifetime value in seconds\n")
2817 /* pfx vn un cost life */
2818 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], argv
[15],
2820 argv
[3], argv
[5], 0, NULL
);
2824 DEFUN (add_vnc_mac_vni_prefix_life
,
2825 add_vnc_mac_vni_prefix_life_cmd
,
2826 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M> lifetime (1-4294967295)",
2827 "Add registration\n"
2829 "Add/modify mac address information\n"
2831 "Virtual Network Identifier follows\n"
2832 "Virtual Network Identifier\n"
2833 "VN address of NVE\n"
2834 "VN IPv4 interface address\n"
2835 "VN IPv6 interface address\n"
2836 "UN address of NVE\n"
2837 "UN IPv4 interface address\n"
2838 "UN IPv6 interface address\n"
2839 "Add/modify prefix related information\n"
2842 "Registration lifetime [default: infinite]\n"
2843 "Lifetime value in seconds\n")
2845 /* pfx vn un cost life */
2846 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, argv
[13],
2848 argv
[3], argv
[5], 0, NULL
);
2851 DEFUN (add_vnc_mac_vni_prefix_cost
,
2852 add_vnc_mac_vni_prefix_cost_cmd
,
2853 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M> cost (0-255)",
2854 "Add registration\n"
2856 "Add/modify mac address information\n"
2858 "Virtual Network Identifier follows\n"
2859 "Virtual Network Identifier\n"
2860 "VN address of NVE\n"
2861 "VN IPv4 interface address\n"
2862 "VN IPv6 interface address\n"
2863 "UN address of NVE\n"
2864 "UN IPv4 interface address\n"
2865 "UN IPv6 interface address\n"
2866 "Add/modify prefix related information\n"
2869 "Administrative cost [default: 255]\n" "Administrative cost\n")
2871 /* pfx vn un cost life */
2872 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], NULL
,
2874 argv
[3], argv
[5], 0, NULL
);
2877 DEFUN (add_vnc_mac_vni_prefix
,
2878 add_vnc_mac_vni_prefix_cmd
,
2879 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> prefix <A.B.C.D/M|X:X::X:X/M>",
2880 "Add registration\n"
2882 "Add/modify mac address information\n"
2884 "Virtual Network Identifier follows\n"
2885 "Virtual Network Identifier\n"
2886 "VN address of NVE\n"
2887 "VN IPv4 interface address\n"
2888 "VN IPv6 interface address\n"
2889 "UN address of NVE\n"
2890 "UN IPv4 interface address\n"
2891 "UN IPv6 interface address\n"
2892 "Add/modify prefix related information\n"
2893 "IPv4 prefix\n" "IPv6 prefix\n")
2895 /* pfx vn un cost life */
2896 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, NULL
,
2898 argv
[3], argv
[5], 0, NULL
);
2901 DEFUN (add_vnc_mac_vni_cost_life
,
2902 add_vnc_mac_vni_cost_life_cmd
,
2903 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255) lifetime (1-4294967295)",
2904 "Add registration\n"
2906 "Add/modify mac address information\n"
2908 "Virtual Network Identifier follows\n"
2909 "Virtual Network Identifier\n"
2910 "VN address of NVE\n"
2911 "VN IPv4 interface address\n"
2912 "VN IPv6 interface address\n"
2913 "UN address of NVE\n"
2914 "UN IPv4 interface address\n"
2915 "UN IPv6 interface address\n"
2916 "Administrative cost [default: 255]\n"
2917 "Administrative cost\n"
2918 "Registration lifetime [default: infinite]\n"
2919 "Lifetime value in seconds\n")
2921 /* pfx vn un cost life */
2922 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], argv
[13],
2924 argv
[3], argv
[5], 0, NULL
);
2928 DEFUN (add_vnc_mac_vni_cost
,
2929 add_vnc_mac_vni_cost_cmd
,
2930 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> cost (0-255)",
2931 "Add registration\n"
2933 "Add/modify mac address information\n"
2935 "Virtual Network Identifier follows\n"
2936 "Virtual Network Identifier\n"
2937 "VN address of NVE\n"
2938 "VN IPv4 interface address\n"
2939 "VN IPv6 interface address\n"
2940 "UN address of NVE\n"
2941 "UN IPv4 interface address\n"
2942 "UN IPv6 interface address\n"
2943 "Administrative cost [default: 255]\n" "Administrative cost\n")
2945 /* pfx vn un cost life */
2946 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], NULL
,
2948 argv
[3], argv
[5], 0, NULL
);
2952 DEFUN (add_vnc_mac_vni_life
,
2953 add_vnc_mac_vni_life_cmd
,
2954 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X> lifetime (1-4294967295)",
2955 "Add registration\n"
2957 "Add/modify mac address information\n"
2959 "Virtual Network Identifier follows\n"
2960 "Virtual Network Identifier\n"
2961 "VN address of NVE\n"
2962 "VN IPv4 interface address\n"
2963 "VN IPv6 interface address\n"
2964 "UN address of NVE\n"
2965 "UN IPv4 interface address\n"
2966 "UN IPv6 interface address\n"
2967 "Registration lifetime [default: infinite]\n"
2968 "Lifetime value in seconds\n")
2970 /* pfx vn un cost life */
2971 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, argv
[11],
2973 argv
[3], argv
[5], 0, NULL
);
2977 DEFUN (add_vnc_mac_vni
,
2978 add_vnc_mac_vni_cmd
,
2979 "add vnc mac YY:YY:YY:YY:YY:YY virtual-network-identifier (1-4294967295) vn <A.B.C.D|X:X::X:X> un <A.B.C.D|X:X::X:X>",
2980 "Add registration\n"
2982 "Add/modify mac address information\n"
2984 "Virtual Network Identifier follows\n"
2985 "Virtual Network Identifier\n"
2986 "VN address of NVE\n"
2987 "VN IPv4 interface address\n"
2988 "VN IPv6 interface address\n"
2989 "UN address of NVE\n"
2990 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
2992 /* pfx vn un cost life */
2993 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, NULL
,
2995 argv
[3], argv
[5], 0, NULL
);
2998 /************************************************************************
3000 ************************************************************************/
3002 struct rfapi_local_reg_delete_arg
3007 struct rfapi_ip_addr un_address
; /* AF==0: wildcard */
3008 struct rfapi_ip_addr vn_address
; /* AF==0: wildcard */
3009 struct prefix prefix
; /* AF==0: wildcard */
3011 struct rfapi_l2address_option_match l2o
;
3019 uint32_t query_count
;
3021 uint32_t failed_pfx_count
;
3024 struct skiplist
*nves
;
3026 uint32_t remote_active_nve_count
;
3027 uint32_t remote_active_pfx_count
;
3028 uint32_t remote_holddown_nve_count
;
3029 uint32_t remote_holddown_pfx_count
;
3034 struct rfapi_ip_addr vn
;
3035 struct rfapi_ip_addr un
;
3036 struct rfapi_descriptor
*rfd
;
3037 struct rfapi_local_reg_delete_arg
*cda
;
3041 nve_addr_free (void *hap
)
3043 ((struct nve_addr
*) hap
)->cda
->nve_count
+= 1;
3044 XFREE (MTYPE_RFAPI_NVE_ADDR
, hap
);
3048 nve_addr_cmp (void *k1
, void *k2
)
3050 struct nve_addr
*a
= (struct nve_addr
*) k1
;
3051 struct nve_addr
*b
= (struct nve_addr
*) k2
;
3058 if (a
->un
.addr_family
!= b
->un
.addr_family
)
3060 return (a
->un
.addr_family
- b
->un
.addr_family
);
3062 if (a
->vn
.addr_family
!= b
->vn
.addr_family
)
3064 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
3066 if (a
->un
.addr_family
== AF_INET
)
3068 ret
= IPV4_ADDR_CMP (&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
3074 else if (a
->un
.addr_family
== AF_INET6
)
3076 ret
= IPV6_ADDR_CMP (&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
3086 if (a
->vn
.addr_family
== AF_INET
)
3088 ret
= IPV4_ADDR_CMP (&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
3092 else if (a
->vn
.addr_family
== AF_INET6
)
3094 ret
= IPV6_ADDR_CMP (&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
3108 parse_deleter_args (
3110 struct cmd_token
*carg_prefix
,
3111 struct cmd_token
*carg_vn
,
3112 struct cmd_token
*carg_un
,
3113 struct cmd_token
*carg_l2addr
,
3114 struct cmd_token
*carg_vni
,
3115 struct rfapi_local_reg_delete_arg
*rcdarg
)
3117 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
3118 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
3119 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
3120 const char *arg_l2addr
= carg_l2addr
? carg_l2addr
->arg
: NULL
;
3121 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
3122 int rc
= CMD_WARNING
;
3124 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3126 if (arg_vn
&& strcmp (arg_vn
, "*"))
3128 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3131 if (arg_un
&& strcmp (arg_un
, "*"))
3133 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3136 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3139 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3141 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
, VTY_NEWLINE
);
3150 vty_out (vty
, "Missing VNI%s", VTY_NEWLINE
);
3153 if (strcmp (arg_l2addr
, "*"))
3155 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3157 vty_out (vty
, "Malformed L2 Address \"%s\"%s",
3158 arg_l2addr
, VTY_NEWLINE
);
3161 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3163 if (strcmp (arg_vni
, "*"))
3165 VTY_GET_INTEGER ("Logical Network ID",
3166 rcdarg
->l2o
.o
.logical_net_id
, arg_vni
);
3167 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3174 record_nve_in_cda_list (
3175 struct rfapi_local_reg_delete_arg
*cda
,
3176 struct rfapi_ip_addr
*un_address
,
3177 struct rfapi_ip_addr
*vn_address
,
3178 struct rfapi_descriptor
*rfd
)
3181 struct nve_addr
*hap
;
3183 memset (&ha
, 0, sizeof (ha
));
3184 ha
.un
= *un_address
;
3185 ha
.vn
= *vn_address
;
3189 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3191 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3193 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3197 skiplist_insert (cda
->nves
, hap
, hap
);
3202 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3205 struct rfapi_descriptor
*rfd
;
3206 int query_count
= 0;
3207 struct listnode
*node
;
3208 struct bgp
*bgp_default
= bgp_get_default ();
3210 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3216 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3219 rfapiRibClear (rfd
);
3220 rfapi_query_done_all (rfd
, &query_count
);
3221 cda
->query_count
+= query_count
;
3224 * Track unique nves seen
3226 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3237 h
= bgp_default
->rfapi
;
3242 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3245 * match un, vn addresses of NVEs
3247 if (cda
->un_address
.addr_family
&&
3248 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3252 if (cda
->vn_address
.addr_family
&&
3253 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3258 rfapiRibClear (rfd
);
3260 rfapi_query_done_all (rfd
, &query_count
);
3261 cda
->query_count
+= query_count
;
3264 * Track unique nves seen
3266 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3271 * TBD need to count deleted prefixes and nves?
3273 * ENXIO BGP or VNC not configured
3276 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3278 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3279 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3280 struct prefix
*pPrefix
; /* NULL = wildcard */
3283 struct listnode
*node
;
3284 struct rfapi_descriptor
*rfd
;
3285 struct rfapi_ip_prefix rprefix
;
3286 struct bgp
*bgp_default
= bgp_get_default ();
3287 struct rfapi_next_hop_entry
*head
= NULL
;
3288 struct rfapi_next_hop_entry
*tail
= NULL
;
3289 struct rfapi_cfg
*rfapi_cfg
;
3292 vnc_zlog_debug_verbose ("%s: entry", __func__
);
3298 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3299 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3300 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3302 h
= bgp_default
->rfapi
;
3303 rfapi_cfg
= bgp_default
->rfapi_cfg
;
3305 if (!h
|| !rfapi_cfg
)
3310 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3314 vnc_zlog_debug_verbose ("%s: starting descriptor loop", __func__
);
3317 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3319 struct rfapi_adb
*adb
;
3321 int deleted_from_this_nve
;
3323 struct nve_addr
*hap
;
3326 vnc_zlog_debug_verbose ("%s: rfd=%p", __func__
, rfd
);
3330 * match un, vn addresses of NVEs
3332 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3334 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3338 vnc_zlog_debug_verbose ("%s: un, vn match", __func__
);
3345 deleted_from_this_nve
= 0;
3348 struct skiplist
*sl
;
3349 struct rfapi_ip_prefix rp
;
3351 struct list
*adb_delete_list
;
3354 * The advertisements are stored in a skiplist. Withdrawing
3355 * the registration deletes the advertisement from the
3356 * skiplist, which we can't do while iterating over that
3357 * same skiplist using the current skiplist API.
3359 * Strategy: iterate over the skiplist and build another
3360 * list containing only the matching ADBs. Then delete
3361 * _everything_ in that second list (which can be done
3362 * using either skiplists or quagga linklists).
3364 adb_delete_list
= list_new ();
3367 * Advertised IP prefixes (not 0/32 or 0/128)
3369 sl
= rfd
->advertised
.ipN_by_prefix
;
3372 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3373 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3378 if (!prefix_same (pPrefix
, &adb
->prefix_ip
))
3381 vnc_zlog_debug_verbose ("%s: adb=%p, prefix doesn't match, skipping",
3387 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3390 (cda
->l2o
.o
.macaddr
.octet
,
3391 adb
->prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3394 vnc_zlog_debug_verbose ("%s: adb=%p, macaddr doesn't match, skipping",
3401 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3403 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3406 vnc_zlog_debug_verbose ("%s: adb=%p, LNI doesn't match, skipping",
3414 vnc_zlog_debug_verbose ("%s: ipN adding adb %p to delete list", __func__
,
3418 listnode_add (adb_delete_list
, adb
);
3421 struct listnode
*node
;
3423 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3426 struct rfapi_vn_option vn1
;
3427 struct rfapi_vn_option vn2
;
3428 struct rfapi_vn_option
*pVn
;
3429 int this_advertisement_prefix_count
;
3431 this_advertisement_prefix_count
= 1;
3433 rfapiQprefix2Rprefix (&adb
->prefix_ip
, &rp
);
3435 /* if mac addr present in advert, make l2o vn option */
3436 if (adb
->prefix_eth
.family
== AF_ETHERNET
)
3439 memset (&vn1
, 0, sizeof (vn1
));
3440 memset (&vn2
, 0, sizeof (vn2
));
3442 vn1
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3443 vn1
.v
.l2addr
.macaddr
= adb
->prefix_eth
.u
.prefix_eth
;
3446 * use saved RD value instead of trying to invert
3447 * complex L2-style RD computation in rfapi_register()
3449 vn2
.type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3450 vn2
.v
.internal_rd
= adb
->prd
;
3455 ++this_advertisement_prefix_count
;
3463 vnc_zlog_debug_verbose ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3466 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, pVn
, RFAPI_REGISTER_KILL
);
3469 cda
->pfx_count
+= this_advertisement_prefix_count
;
3470 cda
->reg_count
+= 1;
3471 deleted_from_this_nve
= 1;
3473 if (h
->rfp_methods
.local_cb
)
3475 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3476 &rp
, 0, 0, NULL
, &head
, &tail
);
3479 list_delete_all_node (adb_delete_list
);
3481 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3486 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3490 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3492 sl
= rfd
->advertised
.ip0_by_ether
;
3495 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3496 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3499 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3501 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3502 adb
->prefix_eth
.u
.prefix_eth
.octet
,
3509 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3511 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3517 vnc_zlog_debug_verbose ("%s: ip0 adding adb %p to delete list",
3520 listnode_add (adb_delete_list
, adb
);
3524 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3527 struct rfapi_vn_option vn
;
3529 rfapiQprefix2Rprefix (&adb
->prefix_ip
, &rp
);
3531 memset (&vn
, 0, sizeof (vn
));
3532 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3533 vn
.v
.l2addr
= adb
->l2o
;
3536 vnc_zlog_debug_verbose ("%s: ip0 killing reg from adb %p ",
3540 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3541 RFAPI_REGISTER_KILL
);
3544 cda
->pfx_count
+= 1;
3545 cda
->reg_count
+= 1;
3546 deleted_from_this_nve
= 1;
3548 if (h
->rfp_methods
.local_cb
)
3550 struct rfapi_vn_option
*vn_opt_new
;
3552 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3553 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3554 &rfd
->vn_addr
, &rp
, 0, 0,
3555 vn_opt_new
, &head
, &tail
);
3558 list_delete_all_node (adb_delete_list
);
3560 list_delete (adb_delete_list
);
3565 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3566 h
->flags
|= RFAPI_INCALLBACK
;
3567 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3568 h
->flags
&= ~RFAPI_INCALLBACK
;
3572 if (deleted_from_this_nve
)
3575 * track unique NVEs seen
3577 memset (&ha
, 0, sizeof (ha
));
3578 ha
.un
= rfd
->un_addr
;
3579 ha
.vn
= rfd
->vn_addr
;
3582 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3583 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3585 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3589 skiplist_insert (cda
->nves
, hap
, hap
);
3600 * Deletes local and remote prefixes that match
3603 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3605 struct prefix pfx_un
;
3606 struct prefix pfx_vn
;
3608 struct prefix
*pUN
= NULL
;
3609 struct prefix
*pVN
= NULL
;
3610 struct prefix
*pPrefix
= NULL
;
3613 * Delete matching remote prefixes in holddown
3615 if (cda
->vn_address
.addr_family
)
3617 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3620 if (cda
->un_address
.addr_family
)
3622 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3625 if (cda
->prefix
.family
)
3627 pPrefix
= &cda
->prefix
;
3629 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
,
3630 0, 1, &cda
->remote_active_pfx_count
,
3631 &cda
->remote_active_nve_count
,
3632 &cda
->remote_holddown_pfx_count
,
3633 &cda
->remote_holddown_nve_count
);
3636 * Now do local prefixes
3638 rfapiDeleteLocalPrefixes (cda
);
3642 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3644 struct vty
*vty
= cda
->vty
; /* for benefit of VTY_NEWLINE */
3646 /* Our special element-deleting function counts nves */
3649 skiplist_free (cda
->nves
);
3652 if (cda
->failed_pfx_count
)
3653 vty_out (vty
, "Failed to delete %d prefixes%s",
3654 cda
->failed_pfx_count
, VTY_NEWLINE
);
3656 /* left as "prefixes" even in single case for ease of machine parsing */
3658 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs%s",
3659 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
, cda
->nve_count
,
3663 * We don't currently allow deletion of active remote prefixes from
3667 vty_out (vty
, "[Holddown] Cleared %u prefixes from %u NVEs%s",
3668 cda
->remote_holddown_pfx_count
, cda
->remote_holddown_nve_count
,
3673 * Caller has already deleted registrations and queries for this/these
3674 * NVEs. Now we just have to close their descriptors.
3677 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3679 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3680 struct nve_addr
*pKey
;
3681 struct nve_addr
*pValue
;
3682 void *cursor
= NULL
;
3688 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3690 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3695 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3696 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3697 rfapi_close (pValue
->rfd
);
3702 DEFUN (clear_vnc_nve_all
,
3703 clear_vnc_nve_all_cmd
,
3707 "Clear per NVE information\n"
3711 struct rfapi_local_reg_delete_arg cda
;
3714 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3719 clear_vnc_responses (&cda
);
3720 clear_vnc_prefix (&cda
);
3721 clear_vnc_nve_closer (&cda
);
3723 print_cleared_stats (&cda
);
3728 DEFUN (clear_vnc_nve_vn_un
,
3729 clear_vnc_nve_vn_un_cmd
,
3730 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3733 "Clear prefix registration information\n"
3734 "VN address of NVE\n"
3736 "VN IPv4 interface address\n"
3737 "VN IPv6 interface address\n"
3738 "UN address of NVE\n"
3739 "For all UN addresses\n"
3740 "UN IPv4 interface address\n"
3741 "UN IPv6 interface address\n")
3743 struct rfapi_local_reg_delete_arg cda
;
3747 parse_deleter_args (vty
, NULL
, argv
[4], argv
[6], NULL
, NULL
, &cda
)))
3752 clear_vnc_responses (&cda
);
3753 clear_vnc_prefix (&cda
);
3754 clear_vnc_nve_closer (&cda
);
3756 print_cleared_stats (&cda
);
3761 DEFUN (clear_vnc_nve_un_vn
,
3762 clear_vnc_nve_un_vn_cmd
,
3763 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3766 "Clear prefix registration information\n"
3767 "UN address of NVE\n"
3769 "UN IPv4 interface address\n"
3770 "UN IPv6 interface address\n"
3771 "VN address of NVE\n"
3773 "VN IPv4 interface address\n"
3774 "VN IPv6 interface address\n")
3776 struct rfapi_local_reg_delete_arg cda
;
3780 parse_deleter_args (vty
, NULL
, argv
[6], argv
[4], NULL
, NULL
, &cda
)))
3785 clear_vnc_responses (&cda
);
3786 clear_vnc_prefix (&cda
);
3787 clear_vnc_nve_closer (&cda
);
3789 print_cleared_stats (&cda
);
3794 DEFUN (clear_vnc_nve_vn
,
3795 clear_vnc_nve_vn_cmd
,
3796 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3799 "Clear prefix registration information\n"
3800 "VN address of NVE\n"
3802 "VN IPv4 interface address\n"
3803 "VN IPv6 interface address\n")
3805 struct rfapi_local_reg_delete_arg cda
;
3808 if ((rc
= parse_deleter_args (vty
, NULL
, argv
[4], NULL
, NULL
, NULL
, &cda
)))
3813 clear_vnc_responses (&cda
);
3814 clear_vnc_prefix (&cda
);
3815 clear_vnc_nve_closer (&cda
);
3817 print_cleared_stats (&cda
);
3821 DEFUN (clear_vnc_nve_un
,
3822 clear_vnc_nve_un_cmd
,
3823 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3826 "Clear prefix registration information\n"
3827 "UN address of NVE\n"
3829 "UN IPv4 interface address\n"
3830 "UN IPv6 interface address\n")
3832 struct rfapi_local_reg_delete_arg cda
;
3835 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, argv
[6], NULL
, NULL
, &cda
)))
3840 clear_vnc_responses (&cda
);
3841 clear_vnc_prefix (&cda
);
3842 clear_vnc_nve_closer (&cda
);
3844 print_cleared_stats (&cda
);
3848 /*-------------------------------------------------
3850 *-------------------------------------------------*/
3853 * This function is defined in this file (rather than in rfp_registration.c)
3854 * because here we have access to all the task handles.
3856 DEFUN (clear_vnc_prefix_vn_un
,
3857 clear_vnc_prefix_vn_un_cmd
,
3858 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3861 "Clear prefix registration information\n"
3865 "VN address of NVE\n"
3866 "All VN addresses\n"
3867 "VN IPv4 interface address\n"
3868 "VN IPv6 interface address\n"
3869 "UN address of NVE\n"
3870 "All UN addresses\n"
3871 "UN IPv4 interface address\n"
3872 "UN IPv6 interface address\n")
3874 struct rfapi_local_reg_delete_arg cda
;
3878 parse_deleter_args (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
, &cda
)))
3881 clear_vnc_prefix (&cda
);
3882 print_cleared_stats (&cda
);
3886 DEFUN (clear_vnc_prefix_un_vn
,
3887 clear_vnc_prefix_un_vn_cmd
,
3888 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3891 "Clear prefix registration information\n"
3895 "UN address of NVE\n"
3896 "All UN addresses\n"
3897 "UN IPv4 interface address\n"
3898 "UN IPv6 interface address\n"
3899 "VN address of NVE\n"
3900 "All VN addresses\n"
3901 "VN IPv4 interface address\n"
3902 "VN IPv6 interface address\n")
3904 struct rfapi_local_reg_delete_arg cda
;
3908 parse_deleter_args (vty
, argv
[3], argv
[7], argv
[5], NULL
, NULL
, &cda
)))
3911 clear_vnc_prefix (&cda
);
3912 print_cleared_stats (&cda
);
3916 DEFUN (clear_vnc_prefix_un
,
3917 clear_vnc_prefix_un_cmd
,
3918 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3921 "Clear prefix registration information\n"
3925 "UN address of NVE\n"
3926 "All UN addresses\n"
3927 "UN IPv4 interface address\n"
3928 "UN IPv6 interface address\n")
3930 struct rfapi_local_reg_delete_arg cda
;
3934 parse_deleter_args (vty
, argv
[3], NULL
, argv
[5], NULL
, NULL
, &cda
)))
3937 clear_vnc_prefix (&cda
);
3938 print_cleared_stats (&cda
);
3942 DEFUN (clear_vnc_prefix_vn
,
3943 clear_vnc_prefix_vn_cmd
,
3944 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
3947 "Clear prefix registration information\n"
3951 "UN address of NVE\n"
3952 "All VN addresses\n"
3953 "VN IPv4 interface address\n"
3954 "VN IPv6 interface address\n")
3956 struct rfapi_local_reg_delete_arg cda
;
3960 parse_deleter_args (vty
, argv
[3], argv
[5], NULL
, NULL
, NULL
, &cda
)))
3963 clear_vnc_prefix (&cda
);
3964 print_cleared_stats (&cda
);
3968 DEFUN (clear_vnc_prefix_all
,
3969 clear_vnc_prefix_all_cmd
,
3970 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
3973 "Clear prefix registration information\n"
3979 struct rfapi_local_reg_delete_arg cda
;
3982 if ((rc
= parse_deleter_args (vty
, argv
[3], NULL
, NULL
, NULL
, NULL
, &cda
)))
3985 clear_vnc_prefix (&cda
);
3986 print_cleared_stats (&cda
);
3990 /*-------------------------------------------------
3992 *-------------------------------------------------*/
3995 * This function is defined in this file (rather than in rfp_registration.c)
3996 * because here we have access to all the task handles.
3998 DEFUN (clear_vnc_mac_vn_un
,
3999 clear_vnc_mac_vn_un_cmd
,
4000 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
4003 "Clear mac registration information\n"
4007 "Any virtual network identifier\n"
4008 "Virtual network identifier\n"
4009 "Virtual network identifier\n"
4010 "VN address of NVE\n"
4011 "All VN addresses\n"
4012 "VN IPv4 interface address\n"
4013 "VN IPv6 interface address\n"
4014 "UN address of NVE\n"
4015 "All UN addresses\n"
4016 "UN IPv4 interface address\n"
4017 "UN IPv6 interface address\n")
4019 struct rfapi_local_reg_delete_arg cda
;
4022 /* pfx vn un L2 VNI */
4024 parse_deleter_args (vty
, NULL
, argv
[7], argv
[9], argv
[3], argv
[5],
4028 clear_vnc_prefix (&cda
);
4029 print_cleared_stats (&cda
);
4033 DEFUN (clear_vnc_mac_un_vn
,
4034 clear_vnc_mac_un_vn_cmd
,
4035 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
4038 "Clear mac registration information\n"
4042 "Any virtual network identifier\n"
4043 "Virtual network identifier\n"
4044 "UN address of NVE\n"
4045 "All UN addresses\n"
4046 "UN IPv4 interface address\n"
4047 "UN IPv6 interface address\n"
4048 "VN address of NVE\n"
4049 "All VN addresses\n"
4050 "VN IPv4 interface address\n"
4051 "VN IPv6 interface address\n")
4053 struct rfapi_local_reg_delete_arg cda
;
4056 /* pfx vn un L2 VNI */
4058 parse_deleter_args (vty
, NULL
, argv
[9], argv
[7], argv
[3], argv
[5],
4062 clear_vnc_prefix (&cda
);
4063 print_cleared_stats (&cda
);
4067 DEFUN (clear_vnc_mac_un
,
4068 clear_vnc_mac_un_cmd
,
4069 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4072 "Clear mac registration information\n"
4076 "Any virtual network identifier\n"
4077 "Virtual network identifier\n"
4078 "UN address of NVE\n"
4079 "All UN addresses\n"
4080 "UN IPv4 interface address\n"
4081 "UN IPv6 interface address\n")
4083 struct rfapi_local_reg_delete_arg cda
;
4086 /* pfx vn un L2 VNI */
4088 parse_deleter_args (vty
, NULL
, NULL
, argv
[7], argv
[3], argv
[5], &cda
)))
4091 clear_vnc_prefix (&cda
);
4092 print_cleared_stats (&cda
);
4096 DEFUN (clear_vnc_mac_vn
,
4097 clear_vnc_mac_vn_cmd
,
4098 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4101 "Clear mac registration information\n"
4105 "Any virtual network identifier\n"
4106 "Virtual network identifier\n"
4107 "UN address of NVE\n"
4108 "All VN addresses\n"
4109 "VN IPv4 interface address\n"
4110 "VN IPv6 interface address\n")
4112 struct rfapi_local_reg_delete_arg cda
;
4115 /* pfx vn un L2 VNI */
4117 parse_deleter_args (vty
, NULL
, argv
[7], NULL
, argv
[3], argv
[5], &cda
)))
4120 clear_vnc_prefix (&cda
);
4121 print_cleared_stats (&cda
);
4125 DEFUN (clear_vnc_mac_all
,
4126 clear_vnc_mac_all_cmd
,
4127 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4130 "Clear mac registration information\n"
4134 "Any virtual network identifier\n"
4135 "Virtual network identifier\n"
4138 struct rfapi_local_reg_delete_arg cda
;
4141 /* pfx vn un L2 VNI */
4143 parse_deleter_args (vty
, NULL
, NULL
, NULL
, argv
[3], argv
[5], &cda
)))
4146 clear_vnc_prefix (&cda
);
4147 print_cleared_stats (&cda
);
4151 /*-------------------------------------------------
4152 * Clear VNC MAC PREFIX
4153 *-------------------------------------------------*/
4155 DEFUN (clear_vnc_mac_vn_un_prefix
,
4156 clear_vnc_mac_vn_un_prefix_cmd
,
4157 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4160 "Clear mac registration information\n"
4164 "Any virtual network identifier\n"
4165 "Virtual network identifier\n"
4166 "VN address of NVE\n"
4167 "All VN addresses\n"
4168 "VN IPv4 interface address\n"
4169 "VN IPv6 interface address\n"
4170 "UN address of NVE\n"
4171 "All UN addresses\n"
4172 "UN IPv4 interface address\n"
4173 "UN IPv6 interface address\n"
4174 "Clear prefix registration information\n"
4179 struct rfapi_local_reg_delete_arg cda
;
4182 /* pfx vn un L2 VNI */
4184 parse_deleter_args (vty
, argv
[11], argv
[7], argv
[9], argv
[3], argv
[5],
4188 clear_vnc_prefix (&cda
);
4189 print_cleared_stats (&cda
);
4193 DEFUN (clear_vnc_mac_un_vn_prefix
,
4194 clear_vnc_mac_un_vn_prefix_cmd
,
4195 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4198 "Clear mac registration information\n"
4202 "Any virtual network identifier\n"
4203 "Virtual network identifier\n"
4204 "UN address of NVE\n"
4205 "All UN addresses\n"
4206 "UN IPv4 interface address\n"
4207 "UN IPv6 interface address\n"
4208 "VN address of NVE\n"
4209 "All VN addresses\n"
4210 "VN IPv4 interface address\n"
4211 "VN IPv6 interface address\n"
4212 "Clear prefix registration information\n"
4216 "Clear prefix registration information\n"
4221 struct rfapi_local_reg_delete_arg cda
;
4224 /* pfx vn un L2 VNI */
4226 parse_deleter_args (vty
, argv
[11], argv
[9], argv
[7], argv
[3], argv
[5],
4230 clear_vnc_prefix (&cda
);
4231 print_cleared_stats (&cda
);
4235 DEFUN (clear_vnc_mac_un_prefix
,
4236 clear_vnc_mac_un_prefix_cmd
,
4237 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4240 "Clear mac registration information\n"
4244 "Any virtual network identifier\n"
4245 "Virtual network identifier\n"
4246 "UN address of NVE\n"
4247 "All UN addresses\n"
4248 "UN IPv4 interface address\n"
4249 "UN IPv6 interface address\n"
4250 "Clear prefix registration information\n"
4255 struct rfapi_local_reg_delete_arg cda
;
4258 /* pfx vn un L2 VNI */
4260 parse_deleter_args (vty
, argv
[9], NULL
, argv
[7], argv
[3], argv
[5],
4264 clear_vnc_prefix (&cda
);
4265 print_cleared_stats (&cda
);
4269 DEFUN (clear_vnc_mac_vn_prefix
,
4270 clear_vnc_mac_vn_prefix_cmd
,
4271 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4274 "Clear mac registration information\n"
4278 "Any virtual network identifier\n"
4279 "Virtual network identifier\n"
4280 "UN address of NVE\n"
4281 "All VN addresses\n"
4282 "VN IPv4 interface address\n"
4283 "VN IPv6 interface address\n"
4284 "Clear prefix registration information\n"
4289 struct rfapi_local_reg_delete_arg cda
;
4292 /* pfx vn un L2 VNI */
4294 parse_deleter_args (vty
, argv
[9], argv
[7], NULL
, argv
[3], argv
[5],
4298 clear_vnc_prefix (&cda
);
4299 print_cleared_stats (&cda
);
4303 DEFUN (clear_vnc_mac_all_prefix
,
4304 clear_vnc_mac_all_prefix_cmd
,
4305 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> prefix <*|A.B.C.D/M|X:X::X:X/M>",
4308 "Clear mac registration information\n"
4312 "Any virtual network identifier\n"
4313 "Virtual network identifier\n"
4314 "UN address of NVE\n"
4315 "All VN addresses\n"
4316 "VN IPv4 interface address\n"
4317 "VN IPv6 interface address\n")
4319 struct rfapi_local_reg_delete_arg cda
;
4322 /* pfx vn un L2 VNI */
4324 parse_deleter_args (vty
, argv
[7], NULL
, NULL
, argv
[3], argv
[5], &cda
)))
4327 clear_vnc_prefix (&cda
);
4328 print_cleared_stats (&cda
);
4332 /************************************************************************
4334 ************************************************************************/
4337 /* copied from rfp_vty.c */
4339 check_and_display_is_vnc_running (struct vty
*vty
)
4341 if (!bgp_rfapi_is_vnc_configured (NULL
))
4342 return 1; /* is running */
4347 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)%s",
4350 return 0; /* not running */
4354 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4356 struct bgp
*bgp_default
= bgp_get_default ();
4358 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4360 int active_local_routes
;
4361 int active_remote_routes
;
4362 int holddown_remote_routes
;
4363 int imported_remote_routes
;
4368 h
= bgp_default
->rfapi
;
4373 /* don't show local info if not running RFP */
4374 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4380 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4381 vty_out (vty
, "%-24s ", "NVEs:");
4382 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4383 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4384 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4387 case SHOW_NVE_SUMMARY_REGISTERED
:
4389 * NB: With the introduction of L2 route support, we no
4390 * longer have a one-to-one correspondence between
4391 * locally-originated route advertisements and routes in
4392 * the import tables that have local origin. This
4393 * discrepancy arises because a single advertisement
4394 * may contain both an IP prefix and a MAC address.
4395 * Such an advertisement results in two import table
4396 * entries: one indexed by IP prefix, the other indexed
4399 * TBD: update computation and display of registration
4400 * statistics to reflect the underlying semantics.
4404 vty_out (vty
, "%-24s ", "Registrations:");
4405 vty_out (vty
, "%-8s %-8u ", "Active:",
4406 rfapiApCountAll (bgp_default
));
4407 vty_out (vty
, "%-8s %-8u ", "Failed:",
4408 h
->stat
.count_registrations_failed
);
4409 vty_out (vty
, "%-8s %-8u", "Total:",
4410 h
->stat
.count_registrations
);
4411 vty_out (vty
, "%s", VTY_NEWLINE
);
4413 vty_out (vty
, "%-24s ", "Prefixes registered:");
4414 vty_out (vty
, "%s", VTY_NEWLINE
);
4416 rfapiCountAllItRoutes (&active_local_routes
,
4417 &active_remote_routes
,
4418 &holddown_remote_routes
,
4419 &imported_remote_routes
);
4424 vty_out (vty
, " %-20s ", "Locally:");
4425 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4426 vty_out (vty
, "%s", VTY_NEWLINE
);
4430 vty_out (vty
, " %-20s ", "Remotely:");
4431 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4432 vty_out (vty
, "%s", VTY_NEWLINE
);
4433 vty_out (vty
, " %-20s ", "In Holddown:");
4434 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4435 vty_out (vty
, "%s", VTY_NEWLINE
);
4436 vty_out (vty
, " %-20s ", "Imported:");
4437 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4440 case SHOW_NVE_SUMMARY_QUERIES
:
4441 vty_out (vty
, "%-24s ", "Queries:");
4442 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4443 vty_out (vty
, "%-8s %-8u ", "Failed:",
4444 h
->stat
.count_queries_failed
);
4445 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4448 case SHOW_NVE_SUMMARY_RESPONSES
:
4449 rfapiRibShowResponsesSummary (vty
);
4454 vty_out (vty
, "%s", VTY_NEWLINE
);
4459 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4466 struct prefix
*vn_prefix
,
4467 struct prefix
*un_prefix
)
4469 //struct hash *rfds;
4470 //struct rfp_rfapi_descriptor_param param;
4472 struct bgp
*bgp_default
= bgp_get_default ();
4474 struct listnode
*node
;
4475 struct rfapi_descriptor
*rfd
;
4484 h
= bgp_default
->rfapi
;
4489 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4493 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4496 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4499 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4508 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4509 if (!prefix_match (vn_prefix
, &pfx
))
4515 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4516 if (!prefix_match (un_prefix
, &pfx
))
4520 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4521 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4525 /* print out a header */
4527 "Active Next Hops%s", VTY_NEWLINE
);
4528 vty_out (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s%s",
4531 "Regis", "Resps", "Reach", "Remove", "Age", VTY_NEWLINE
);
4536 vty_out (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s%s",
4540 rfapi_monitor_count (rfd
),
4541 rfd
->stat_count_nh_reachable
,
4542 rfd
->stat_count_nh_removal
,
4543 rfapiFormatAge (rfd
->open_time
, age
, 10), VTY_NEWLINE
);
4546 if (printed
> 0 || vn_prefix
|| un_prefix
)
4547 vty_out (vty
, "Displayed %d out of %d active NVEs%s",
4548 printed
, total
, VTY_NEWLINE
);
4553 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4558 DEFUN (vnc_show_summary
,
4559 vnc_show_summary_cmd
,
4563 "Display VNC status summary\n")
4565 if (!check_and_display_is_vnc_running (vty
))
4567 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4568 vty_out (vty
, "%s", VTY_NEWLINE
);
4569 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4570 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4571 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4572 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4576 DEFUN (vnc_show_nves
,
4581 "List known NVEs\n")
4583 rfapi_show_nves (vty
, NULL
, NULL
);
4587 DEFUN (vnc_show_nves_ptct
,
4588 vnc_show_nves_ptct_cmd
,
4589 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4593 "VN address of NVE\n"
4594 "UN address of NVE\n"
4595 "IPv4 interface address\n"
4596 "IPv6 interface address\n")
4600 if (!check_and_display_is_vnc_running (vty
))
4603 if (!str2prefix (argv
[4]->arg
, &pfx
))
4605 vty_out (vty
, "Malformed address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4608 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4610 vty_out (vty
, "Invalid address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4614 if (argv
[3]->arg
[0] == 'u')
4616 rfapi_show_nves (vty
, NULL
, &pfx
);
4620 rfapi_show_nves (vty
, &pfx
, NULL
);
4626 /* adapted from rfp_registration_cache_log() */
4628 rfapi_show_registrations (
4630 struct prefix
*restrict_to
,
4641 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4645 /* non-expiring, local */
4646 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4650 /* non-expiring, non-local */
4651 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4655 /* expiring, including local */
4656 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4660 /* non-expiring, non-local */
4661 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4665 vty_out (vty
, "%s", VTY_NEWLINE
);
4669 DEFUN (vnc_show_registrations_pfx
,
4670 vnc_show_registrations_pfx_cmd
,
4671 "show vnc registrations [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4674 "List active prefix registrations\n"
4675 "Limit output to a particular IPv4 prefix\n"
4676 "Limit output to a particular IPv6 prefix\n"
4677 "Limit output to a particular IPv6 address\n")
4680 struct prefix
*p_addr
= NULL
;
4684 if (!str2prefix (argv
[3]->arg
, &p
))
4686 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4695 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4699 DEFUN (vnc_show_registrations_some_pfx
,
4700 vnc_show_registrations_some_pfx_cmd
,
4701 "show vnc registrations <all|holddown|imported|local|remote> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4704 "List active prefix registrations\n"
4705 "show all registrations\n"
4706 "show only registrations in holddown\n"
4707 "show only imported prefixes\n"
4708 "show only local registrations\n"
4709 "show only remote registrations\n"
4710 "Limit output to a particular prefix or address\n"
4711 "Limit output to a particular prefix or address\n"
4712 "Limit output to a particular prefix or address\n")
4715 struct prefix
*p_addr
= NULL
;
4718 int show_remote
= 0;
4719 int show_holddown
= 0;
4720 int show_imported
= 0;
4724 if (!str2prefix (argv
[4]->arg
, &p
))
4726 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4734 switch (argv
[3]->arg
[0])
4760 rfapi_show_registrations (vty
, p_addr
,
4761 show_local
, show_remote
, show_holddown
,
4766 DEFUN (vnc_show_responses_pfx
,
4767 vnc_show_responses_pfx_cmd
,
4768 "show vnc responses [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4771 "List recent query responses\n"
4772 "Limit output to a particular IPv4 prefix\n"
4773 "Limit output to a particular IPv6 prefix\n"
4774 "Limit output to a particular IPv6 address\n" )
4777 struct prefix
*p_addr
= NULL
;
4781 if (!str2prefix (argv
[3]->arg
, &p
))
4783 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4791 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4793 rfapiRibShowResponsesSummary (vty
);
4795 rfapiRibShowResponses (vty
, p_addr
, 0);
4796 rfapiRibShowResponses (vty
, p_addr
, 1);
4801 DEFUN (vnc_show_responses_some_pfx
,
4802 vnc_show_responses_some_pfx_cmd
,
4803 "show vnc responses <active|removed> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4806 "List recent query responses\n"
4807 "show only active query responses\n"
4808 "show only removed query responses\n"
4809 "Limit output to a particular IPv4 prefix\n"
4810 "Limit output to a particular IPv6 prefix\n"
4811 "Limit output to a particular IPV6 address\n")
4814 struct prefix
*p_addr
= NULL
;
4816 int show_active
= 0;
4817 int show_removed
= 0;
4819 if (!check_and_display_is_vnc_running (vty
))
4824 if (!str2prefix (argv
[4]->arg
, &p
))
4826 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4835 switch (argv
[3]->arg
[0])
4846 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4848 rfapiRibShowResponsesSummary (vty
);
4851 rfapiRibShowResponses (vty
, p_addr
, 0);
4853 rfapiRibShowResponses (vty
, p_addr
, 1);
4858 DEFUN (show_vnc_queries_pfx
,
4859 show_vnc_queries_pfx_cmd
,
4860 "show vnc queries [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4863 "List active queries\n"
4864 "Limit output to a particular IPv4 prefix or address\n"
4865 "Limit output to a particular IPv6 prefix\n"
4866 "Limit output to a particualr IPV6 address\n")
4869 struct prefix
*p
= NULL
;
4873 if (!str2prefix (argv
[3]->arg
, &pfx
))
4875 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4881 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4883 return rfapiShowVncQueries (vty
, p
);
4886 DEFUN (vnc_clear_counters
,
4887 vnc_clear_counters_cmd
,
4888 "clear vnc counters",
4891 "Reset VNC counters\n")
4893 struct bgp
*bgp_default
= bgp_get_default ();
4895 struct listnode
*node
;
4896 struct rfapi_descriptor
*rfd
;
4901 h
= bgp_default
->rfapi
;
4907 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4909 rfd
->stat_count_nh_reachable
= 0;
4910 rfd
->stat_count_nh_removal
= 0;
4914 memset (&h
->stat
, 0, sizeof (h
->stat
));
4917 * 151122 per bug 103, set count_registrations = number active.
4918 * Do same for queries
4920 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4921 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4923 rfapiRibShowResponsesSummaryClear ();
4928 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4932 void rfapi_vty_init ()
4934 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
4935 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
4936 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
4937 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
4938 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
4940 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
4941 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
4942 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
4943 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
4944 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
4946 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
4947 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
4948 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
4949 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
4950 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
4951 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
4952 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
4953 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
4955 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
4956 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
4957 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
4958 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
4959 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
4961 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
4962 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
4963 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
4964 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
4965 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
4967 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
4968 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
4969 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
4970 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
4971 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
4973 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
4974 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
4975 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
4976 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
4977 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
4979 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
4981 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
4982 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
4983 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
4985 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
4986 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
4987 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
4988 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
4989 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);