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 if (safi
== SAFI_MPLS_VPN
|| safi
== SAFI_ENCAP
)
497 vty_out (vty
, " life=none");
502 vty_out (vty
, " life=%d", lifetime
);
505 vty_out (vty
, " type=%s, subtype=%d",
506 zebra_route_string (bi
->type
), bi
->sub_type
);
508 vty_out (vty
, "%s", HVTY_NEWLINE
);
512 rfapiPrintAttrPtrs (void *stream
, struct attr
*attr
)
514 int (*fp
) (void *, const char *, ...);
517 const char *vty_newline
;
519 struct attr_extra
*ae
;
522 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
525 fp (out
, "Attr[%p]:%s", attr
, HVTY_NEWLINE
);
530 inet_ntop (AF_INET
, &attr
->nexthop
, buf
, BUFSIZ
);
531 fp (out
, " nexthop=%s%s", buf
, HVTY_NEWLINE
);
533 fp (out
, " aspath=%p, refcnt=%d%s", attr
->aspath
,
534 (attr
->aspath
? attr
->aspath
->refcnt
: 0), HVTY_NEWLINE
);
535 fp (out
, " community=%p, refcnt=%d%s", attr
->community
,
536 (attr
->community
? attr
->community
->refcnt
: 0), HVTY_NEWLINE
);
538 if ((ae
= attr
->extra
))
540 fp (out
, " ecommunity=%p, refcnt=%d%s", ae
->ecommunity
,
541 (ae
->ecommunity
? ae
->ecommunity
->refcnt
: 0), HVTY_NEWLINE
);
542 fp (out
, " cluster=%p, refcnt=%d%s", ae
->cluster
,
543 (ae
->cluster
? ae
->cluster
->refcnt
: 0), HVTY_NEWLINE
);
544 fp (out
, " transit=%p, refcnt=%d%s", ae
->transit
,
545 (ae
->transit
? ae
->transit
->refcnt
: 0), HVTY_NEWLINE
);
550 * Print BI in an Import Table
553 rfapiPrintBi (void *stream
, struct bgp_info
*bi
)
558 int (*fp
) (void *, const char *, ...);
561 const char *vty_newline
;
567 struct ethaddr macaddr
;
568 struct rfapi_l2address_option l2o_buf
;
569 uint8_t l2hid
=0; /* valid if has_macaddr */
571 #define REMAIN (BUFSIZ - (p-line))
572 #define INCP {p += (r > REMAIN)? REMAIN: r;}
574 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
580 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) && bi
->extra
581 && bi
->extra
->vnc
.import
.timer
)
583 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
584 r
= snprintf (p
, REMAIN
, " [%4lu] ", thread_timer_remain_second (t
));
590 r
= snprintf (p
, REMAIN
, " ");
596 /* TBD This valid only for SAFI_MPLS_VPN, but not for encap */
597 if (decode_rd_type(bi
->extra
->vnc
.import
.rd
.val
) == RD_TYPE_VNC_ETH
)
600 memcpy (macaddr
.octet
, bi
->extra
->vnc
.import
.rd
.val
+ 2, 6);
601 l2hid
= bi
->extra
->vnc
.import
.rd
.val
[1];
610 * RFP option sizes (they are opaque values)
611 * extended communities (RTs)
613 if (bi
->attr
&& bi
->attr
->extra
)
616 int printed_1st_gol
= 0;
617 struct bgp_attr_encap_subtlv
*pEncap
;
618 struct prefix pfx_un
;
619 int af
= BGP_MP_NEXTHOP_FAMILY (bi
->attr
->extra
->mp_nexthop_len
);
624 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET
,
625 &bi
->attr
->extra
->mp_nexthop_global_in
,
629 else if (af
== AF_INET6
)
631 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET6
,
632 &bi
->attr
->extra
->mp_nexthop_global
,
638 r
= snprintf (p
, REMAIN
, "?");
643 * VNC tunnel subtlv, if present, contains UN address
645 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
647 r
= snprintf (p
, REMAIN
, " un=%s", inet_ntop (pfx_un
.family
,
655 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
))
657 r
= snprintf (p
, REMAIN
, " nolife");
662 if (lifetime
== 0xffffffff)
663 r
= snprintf (p
, REMAIN
, " %6s", "infini");
665 r
= snprintf (p
, REMAIN
, " %6u", lifetime
);
669 /* RFP option lengths */
670 for (pEncap
= bi
->attr
->extra
->vnc_subtlvs
; pEncap
;
671 pEncap
= pEncap
->next
)
674 if (pEncap
->type
== BGP_VNC_SUBTLV_TYPE_RFPOPTION
)
678 r
= snprintf (p
, REMAIN
, ",");
683 r
= snprintf (p
, REMAIN
, " "); /* leading space */
686 r
= snprintf (p
, REMAIN
, "%d", pEncap
->length
);
693 if (bi
->attr
->extra
->ecommunity
)
695 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
696 ECOMMUNITY_FORMAT_ROUTE_MAP
);
697 r
= snprintf (p
, REMAIN
, " %s", s
);
699 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
704 r
= snprintf (p
, REMAIN
, " bi@%p", bi
);
707 r
= snprintf (p
, REMAIN
, " p@%p", bi
->peer
);
710 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
712 r
= snprintf (p
, REMAIN
, " HD=yes");
717 r
= snprintf (p
, REMAIN
, " HD=no");
726 r
= snprintf (p
, REMAIN
, " W=%d", bi
->attr
->extra
->weight
);
730 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
732 r
= snprintf (p
, REMAIN
, " LP=%d", bi
->attr
->local_pref
);
737 r
= snprintf (p
, REMAIN
, " LP=unset");
743 snprintf (p
, REMAIN
, " %c:%u", zebra_route_char (bi
->type
), bi
->sub_type
);
746 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
750 fp (out
, " RD HID=%d ETH=%02x:%02x:%02x:%02x:%02x:%02x%s",
755 macaddr
.octet
[3], macaddr
.octet
[4], macaddr
.octet
[5], HVTY_NEWLINE
);
758 if (!rfapiGetL2o (bi
->attr
, &l2o_buf
))
761 " L2O ETH=%02x:%02x:%02x:%02x:%02x:%02x LBL=%d LNI=%d LHI=%hhu%s",
762 l2o_buf
.macaddr
.octet
[0], l2o_buf
.macaddr
.octet
[1],
763 l2o_buf
.macaddr
.octet
[2], l2o_buf
.macaddr
.octet
[3],
764 l2o_buf
.macaddr
.octet
[4], l2o_buf
.macaddr
.octet
[5], l2o_buf
.label
,
765 l2o_buf
.logical_net_id
, l2o_buf
.local_nve_id
, HVTY_NEWLINE
);
767 if (bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
772 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
773 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
778 fp (out
, " IP: %s%s", sp
, HVTY_NEWLINE
);
782 struct rfapi_un_option
*uo
= rfapi_encap_tlv_to_un_option (bi
->attr
);
785 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
786 rfapi_un_options_free (uo
);
792 rfapiMonitorVpn2Str (struct rfapi_monitor_vpn
*m
, char *buf
, int size
)
794 char buf_pfx
[BUFSIZ
];
799 rfapiRfapiIpAddr2Str (&m
->rfd
->un_addr
, buf_vn
, BUFSIZ
);
800 rfapiRfapiIpAddr2Str (&m
->rfd
->vn_addr
, buf_un
, BUFSIZ
);
802 rc
= snprintf (buf
, size
,
803 "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p",
804 m
, m
->next
, m
->rfd
, buf_vn
, buf_un
,
805 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
806 m
->p
.prefixlen
, m
->node
);
814 rfapiDebugPrintMonitorVpn (void *stream
, struct rfapi_monitor_vpn
*m
)
818 int (*fp
) (void *, const char *, ...);
821 const char *vty_newline
;
823 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
826 rfapiMonitorVpn2Str (m
, buf
, BUFSIZ
);
827 fp (out
, " Mon %s%s", buf
, HVTY_NEWLINE
);
831 rfapiDebugPrintMonitorEncap (void *stream
, struct rfapi_monitor_encap
*m
)
833 int (*fp
) (void *, const char *, ...);
836 const char *vty_newline
;
838 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
841 fp (out
, " Mon m=%p, next=%p, node=%p, bi=%p%s",
842 m
, m
->next
, m
->node
, m
->bi
, HVTY_NEWLINE
);
846 rfapiShowItNode (void *stream
, struct route_node
*rn
)
851 int (*fp
) (void *, const char *, ...);
854 const char *vty_newline
;
856 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
859 fp (out
, "%s/%d @%p #%d%s",
860 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
861 rn
->p
.prefixlen
, rn
, rn
->lock
, HVTY_NEWLINE
);
863 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
865 rfapiPrintBi (stream
, bi
);
868 /* doesn't show montors */
872 rfapiShowImportTable (
875 struct route_table
*rt
,
878 struct route_node
*rn
;
881 int (*fp
) (void *, const char *, ...);
884 const char *vty_newline
;
886 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
889 fp (out
, "Import Table [%s]%s", label
, HVTY_NEWLINE
);
891 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
895 if (rn
->p
.family
== AF_ETHERNET
)
897 rfapiEthAddr2Str (&rn
->p
.u
.prefix_eth
, buf
, BUFSIZ
);
901 inet_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
);
904 fp (out
, "%s/%d @%p #%d%s", buf
, rn
->p
.prefixlen
, rn
, rn
->lock
- 1, /* account for loop iterator locking */
907 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
909 rfapiPrintBi (stream
, bi
);
914 struct rfapi_monitor_vpn
*m
;
915 for (m
= RFAPI_MONITOR_VPN (rn
); m
; m
= m
->next
)
917 rfapiDebugPrintMonitorVpn (stream
, m
);
922 struct rfapi_monitor_encap
*m
;
923 for (m
= RFAPI_MONITOR_ENCAP (rn
); m
; m
= m
->next
)
925 rfapiDebugPrintMonitorEncap (stream
, m
);
932 rfapiShowVncQueries (void *stream
, struct prefix
*pfx_match
)
936 struct listnode
*node
;
937 struct rfapi_descriptor
*rfd
;
939 int (*fp
) (void *, const char *, ...);
942 const char *vty_newline
;
944 int printedheader
= 0;
947 int nves_with_queries
= 0;
948 int nves_displayed
= 0;
950 int queries_total
= 0;
951 int queries_displayed
= 0;
953 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
956 bgp
= bgp_get_default (); /* assume 1 instance for now */
959 vty_out (vty
, "No BGP instance%s", VTY_NEWLINE
);
966 vty_out (vty
, "No RFAPI instance%s", VTY_NEWLINE
);
970 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
973 struct route_node
*rn
;
974 int printedquerier
= 0;
979 if (rfd
->mon
|| (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
)))
993 for (rn
= route_top (rfd
->mon
); rn
; rn
= route_next (rn
))
995 struct rfapi_monitor_vpn
*m
;
996 char buf_remain
[BUFSIZ
];
997 char buf_pfx
[BUFSIZ
];
1006 if (pfx_match
&& !prefix_match (pfx_match
, &rn
->p
) &&
1007 !prefix_match (&rn
->p
, pfx_match
))
1010 ++queries_displayed
;
1015 fp (out
, "%s", VTY_NEWLINE
);
1016 fp (out
, "%-15s %-15s %-15s %-10s%s",
1017 "VN Address", "UN Address",
1018 "Target", "Remaining", VTY_NEWLINE
);
1021 if (!printedquerier
)
1023 char buf_vn
[BUFSIZ
];
1024 char buf_un
[BUFSIZ
];
1026 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1027 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1029 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1035 fp (out
, "%-15s %-15s", "", "");
1039 rfapiFormatSeconds (thread_timer_remain_second (m
->timer
),
1040 buf_remain
, BUFSIZ
);
1042 fp (out
, " %-15s %-10s%s",
1043 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
1044 buf_remain
, VTY_NEWLINE
);
1051 if (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
))
1056 struct rfapi_monitor_eth
*mon_eth
;
1060 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1063 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1067 char buf_remain
[BUFSIZ
];
1068 char buf_pfx
[BUFSIZ
];
1069 struct prefix pfx_mac
;
1073 zlog_debug ("%s: checking rfd=%p mon_eth=%p", __func__
, rfd
,
1076 memset ((void *) &pfx_mac
, 0, sizeof (struct prefix
));
1077 pfx_mac
.family
= AF_ETHERNET
;
1078 pfx_mac
.prefixlen
= 48;
1079 pfx_mac
.u
.prefix_eth
= mon_eth
->macaddr
;
1081 if (pfx_match
&& !prefix_match (pfx_match
, &pfx_mac
) &&
1082 !prefix_match (&pfx_mac
, pfx_match
))
1085 ++queries_displayed
;
1090 fp (out
, "%s", VTY_NEWLINE
);
1091 fp (out
, "%-15s %-15s %-17s %10s %-10s%s",
1092 "VN Address", "UN Address",
1093 "Target", "LNI", "Remaining", VTY_NEWLINE
);
1096 if (!printedquerier
)
1098 char buf_vn
[BUFSIZ
];
1099 char buf_un
[BUFSIZ
];
1101 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1102 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1104 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1110 fp (out
, "%-15s %-15s", "", "");
1114 rfapiFormatSeconds (thread_timer_remain_second
1115 (mon_eth
->timer
), buf_remain
, BUFSIZ
);
1117 fp (out
, " %-17s %10d %-10s%s",
1118 rfapi_ntop (pfx_mac
.family
, &pfx_mac
.u
.prefix
, buf_pfx
,
1119 BUFSIZ
), mon_eth
->logical_net_id
, buf_remain
,
1127 fp (out
, "%s", VTY_NEWLINE
);
1128 fp (out
, "Displayed %d out of %d total queries%s",
1129 queries_displayed
, queries_total
, VTY_NEWLINE
);
1135 rfapiPrintRemoteRegBi (
1138 struct route_node
*rn
,
1139 struct bgp_info
*bi
)
1141 int (*fp
) (void *, const char *, ...);
1144 const char *vty_newline
;
1145 struct prefix pfx_un
;
1146 struct prefix pfx_vn
;
1149 bgp_encap_types tun_type
;
1151 char buf_pfx
[BUFSIZ
];
1152 char buf_ntop
[BUFSIZ
];
1153 char buf_un
[BUFSIZ
];
1154 char buf_vn
[BUFSIZ
];
1155 char buf_lifetime
[BUFSIZ
];
1159 return 0; /* for debug log, print into buf & call output once */
1161 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1168 snprintf (buf_pfx
, BUFSIZ
, "%s/%d",
1169 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf_ntop
, BUFSIZ
),
1171 buf_pfx
[BUFSIZ
- 1] = 0;
1178 if (!rfapiGetUnAddrOfVpnBi (bi
, &pfx_un
))
1180 snprintf (buf_un
, BUFSIZ
, "%s",
1181 inet_ntop (pfx_un
.family
, &pfx_un
.u
.prefix
, buf_ntop
,
1184 buf_un
[BUFSIZ
- 1] = 0;
1186 rfapiGetTunnelType(bi
->attr
,&tun_type
);
1191 if (tun_type
== BGP_ENCAP_TYPE_MPLS
)
1193 /* MPLS carries un in nrli next hop (same as vn for IP tunnels) */
1196 u_int32_t l
= decode_label (bi
->extra
->tag
);
1197 snprintf (buf_vn
, BUFSIZ
, "Label: %d", l
);
1199 else /* should never happen */
1201 snprintf (buf_vn
, BUFSIZ
, "Label: N/A");
1206 rfapiNexthop2Prefix (bi
->attr
, &pfx_vn
);
1207 snprintf (buf_vn
, BUFSIZ
, "%s",
1208 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1210 buf_vn
[BUFSIZ
- 1] = 0;
1214 * Cost is encoded in local_pref as (255-cost)
1215 * See rfapi_import.c'rfapiRouteInfo2NextHopEntry() for conversion
1220 uint32_t local_pref
;
1221 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1222 local_pref
= bi
->attr
->local_pref
;
1225 cost
= (local_pref
> 255) ? 0 : 255 - local_pref
;
1232 fp (out
, "%-20s ", buf_pfx
);
1233 fp (out
, "%-15s ", buf_vn
);
1234 fp (out
, "%-15s ", buf_un
);
1235 fp (out
, "%-4d ", cost
);
1238 /* NB rfapiGetVncLifetime sets infinite value when returning !0 */
1239 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
) ||
1240 (lifetime
== RFAPI_INFINITE_LIFETIME
))
1243 fp (out
, "%-10s ", "infinite");
1247 time_t t_lifetime
= lifetime
;
1248 rfapiFormatSeconds (t_lifetime
, buf_lifetime
, BUFSIZ
);
1249 fp (out
, "%-10s ", buf_lifetime
);
1252 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) &&
1253 bi
->extra
&& bi
->extra
->vnc
.import
.timer
)
1258 char buf_age
[BUFSIZ
];
1260 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
1261 remaining
= thread_timer_remain_second (t
);
1263 #if RFAPI_REGISTRATIONS_REPORT_AGE
1265 * Calculate when the timer started. Doing so here saves
1266 * us a timestamp field in "struct bgp_info".
1268 * See rfapi_import.c'rfapiBiStartWithdrawTimer() for the
1269 * original calculation.
1271 age
= rfapiGetHolddownFromLifetime (lifetime
, factor
) - remaining
;
1272 #else /* report remaining time */
1275 rfapiFormatSeconds (age
, buf_age
, BUFSIZ
);
1277 fp (out
, "%-10s ", buf_age
);
1280 else if (RFAPI_LOCAL_BI (bi
))
1283 char buf_age
[BUFSIZ
];
1285 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.create_time
)
1287 rfapiFormatAge (bi
->extra
->vnc
.import
.create_time
, buf_age
, BUFSIZ
);
1294 fp (out
, "%-10s ", buf_age
);
1296 fp (out
, "%s", HVTY_NEWLINE
);
1298 if (rn
->p
.family
== AF_ETHERNET
)
1301 * If there is a corresponding IP address && != VN address,
1302 * print that on the next line
1305 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
1309 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
1310 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
1312 buf_ntop
[BUFSIZ
- 1] = 0;
1314 if (sp
&& strcmp (buf_vn
, sp
) != 0)
1316 fp (out
, " IP: %s", sp
);
1322 if (tun_type
!= BGP_ENCAP_TYPE_MPLS
&& bi
->extra
)
1324 u_int32_t l
= decode_label (bi
->extra
->tag
);
1325 if (!MPLS_LABEL_IS_NULL (l
))
1327 fp (out
, " Label: %d", l
);
1333 fp (out
, "%s", HVTY_NEWLINE
);
1339 rfapiShowRemoteRegistrationsIt (
1342 struct rfapi_import_table
*it
,
1343 struct prefix
*prefix_only
,
1344 int show_expiring
, /* either/or */
1347 int show_imported
, /* either/or */
1348 uint32_t *pLni
) /* AFI_ETHER only */
1351 int printed_rtlist_hdr
= 0;
1353 int (*fp
) (void *, const char *, ...);
1356 const char *vty_newline
;
1360 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1363 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1366 struct route_node
*rn
;
1368 if (!it
->imported_vpn
[afi
])
1371 for (rn
= route_top (it
->imported_vpn
[afi
]); rn
; rn
= route_next (rn
))
1374 struct bgp_info
*bi
;
1377 /* allow for wider or more narrow mask from user */
1379 !prefix_match (prefix_only
, &rn
->p
) &&
1380 !prefix_match (&rn
->p
, prefix_only
))
1385 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
1388 if (!show_local
&& RFAPI_LOCAL_BI (bi
))
1391 /* local route from RFP */
1395 if (!show_remote
&& !RFAPI_LOCAL_BI (bi
))
1402 if (show_expiring
&& !CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1405 if (!show_expiring
&& CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1408 if (bi
->type
== ZEBRA_ROUTE_BGP_DIRECT
||
1409 bi
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
)
1421 if (count_only
== 1)
1423 if (!printed_rtlist_hdr
)
1425 const char *agetype
= "";
1427 const char *type
= "";
1440 if (RFAPI_LOCAL_BI (bi
))
1451 s
= ecommunity_ecom2str (it
->rt_import_list
,
1452 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1456 fp (out
, "%s[%s] L2VPN Network 0x%x (%u) RT={%s}%s",
1457 HVTY_NEWLINE
, type
, *pLni
, (*pLni
& 0xfff), s
,
1462 fp (out
, "%s[%s] Prefix RT={%s}%s",
1463 HVTY_NEWLINE
, type
, s
, HVTY_NEWLINE
);
1465 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1469 #if RFAPI_REGISTRATIONS_REPORT_AGE
1472 agetype
= "Remaining";
1475 else if (show_local
)
1480 printed_rtlist_hdr
= 1;
1482 fp (out
, "%-20s %-15s %-15s %4s %-10s %-10s%s",
1483 (pLni
? "L2 Address/IP" : "Prefix"),
1484 "VN Address", "UN Address", "Cost",
1485 "Lifetime", agetype
, HVTY_NEWLINE
);
1487 printed
+= rfapiPrintRemoteRegBi (bgp
, stream
, rn
, bi
);
1495 const char *type
= "prefixes";
1499 type
= "imported prefixes";
1505 type
= "prefixes in holddown";
1509 if (show_local
&& !show_remote
)
1511 type
= "locally registered prefixes";
1513 else if (!show_local
&& show_remote
)
1515 type
= "remotely registered prefixes";
1520 fp (out
, "Displayed %d out of %d %s%s",
1521 printed
, total
, type
, HVTY_NEWLINE
);
1529 * rfapiShowRemoteRegistrations
1531 * Similar to rfapiShowImportTable() above. This function
1532 * is mean to produce the "remote" portion of the output
1533 * of "show vnc registrations".
1536 rfapiShowRemoteRegistrations (
1538 struct prefix
*prefix_only
,
1546 struct rfapi_import_table
*it
;
1549 bgp
= bgp_get_default ();
1561 for (it
= h
->imports
; it
; it
= it
->next
)
1564 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1565 show_expiring
, show_local
,
1566 show_remote
, show_imported
, NULL
);
1571 void *cursor
= NULL
;
1573 uintptr_t lni_as_ptr
;
1578 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1581 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1585 if ((lni_as_ptr
& 0xffffffff) == lni_as_ptr
)
1587 lni
= (uint32_t) (lni_as_ptr
& 0xffffffff);
1592 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1593 show_expiring
, show_local
,
1594 show_remote
, show_imported
, pLni
);
1601 /*------------------------------------------
1602 * rfapiRfapiIpAddr2Str
1604 * UI helper: generate string from rfapi_ip_addr
1607 * a IP v4/v6 address
1610 * buf put string here
1611 * bufsize max space to write
1614 * NULL conversion failed
1615 * non-NULL pointer to buf
1616 --------------------------------------------*/
1618 rfapiRfapiIpAddr2Str (struct rfapi_ip_addr
*a
, char *buf
, int bufsize
)
1620 const char *rc
= NULL
;
1622 switch (a
->addr_family
)
1625 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1628 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1635 rfapiPrintRfapiIpAddr (void *stream
, struct rfapi_ip_addr
*a
)
1638 const char *rc
= NULL
;
1640 int (*fp
) (void *, const char *, ...);
1643 const char *vty_newline
;
1645 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1648 rc
= rfapiRfapiIpAddr2Str (a
, buf
, BUFSIZ
);
1651 fp (out
, "%s", buf
);
1655 rfapiRfapiIpPrefix2Str (struct rfapi_ip_prefix
*p
, char *buf
, int bufsize
)
1657 struct rfapi_ip_addr
*a
= &p
->prefix
;
1658 const char *rc
= NULL
;
1660 switch (a
->addr_family
)
1663 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1666 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1672 int alen
= strlen (buf
);
1673 int remaining
= bufsize
- alen
- 1;
1678 slen
= snprintf (buf
+ alen
, remaining
, "/%u", p
->length
);
1679 if (slen
< remaining
) /* see man page for snprintf(3) */
1688 rfapiPrintRfapiIpPrefix (void *stream
, struct rfapi_ip_prefix
*p
)
1693 int (*fp
) (void *, const char *, ...);
1696 const char *vty_newline
;
1698 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1701 rc
= rfapiRfapiIpPrefix2Str (p
, buf
, BUFSIZ
);
1704 fp (out
, "%s:%u", buf
, p
->cost
);
1710 rfapiPrintRd (struct vty
*vty
, struct prefix_rd
*prd
)
1715 prefix_rd2str (prd
, buf
, BUFSIZ
);
1716 buf
[BUFSIZ
- 1] = 0;
1717 vty_out (vty
, "%s", buf
);
1721 rfapiPrintAdvertisedInfo (
1723 struct rfapi_descriptor
*rfd
,
1727 afi_t afi
; /* of the VN address */
1728 struct bgp_node
*bn
;
1729 struct bgp_info
*bi
;
1730 uint8_t type
= ZEBRA_ROUTE_BGP
;
1733 struct prefix_rd prd0
;
1734 struct prefix_rd
*prd
;
1737 * Find the bgp_info in the RIB corresponding to this
1741 afi
= family2afi (p
->family
);
1742 assert (afi
== AFI_IP
|| afi
== AFI_IP6
);
1744 bgp
= bgp_get_default (); /* assume 1 instance for now */
1747 if (safi
== SAFI_ENCAP
)
1749 memset (&prd0
, 0, sizeof (prd0
));
1750 prd0
.family
= AF_UNSPEC
;
1751 prd0
.prefixlen
= 64;
1758 bn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
1760 vty_out (vty
, " bn=%p%s", bn
, HVTY_NEWLINE
);
1762 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
1764 if (bi
->peer
== rfd
->peer
&&
1766 bi
->sub_type
== BGP_ROUTE_RFP
&&
1767 bi
->extra
&& bi
->extra
->vnc
.export
.rfapi_handle
== (void *) rfd
)
1770 rfapiPrintBi (vty
, bi
);
1777 vty_out (vty
, " --?--%s", HVTY_NEWLINE
);
1784 rfapiPrintDescriptor (struct vty
*vty
, struct rfapi_descriptor
*rfd
)
1786 /* pHD un-addr vn-addr pCB cookie rd lifetime */
1787 /* RT export list */
1788 /* RT import list */
1789 /* list of advertised prefixes */
1790 /* dump import table */
1796 struct rfapi_adb
*adb
;
1799 vty_out (vty
, "%-10p ", rfd
);
1800 rfapiPrintRfapiIpAddr (vty
, &rfd
->un_addr
);
1802 rfapiPrintRfapiIpAddr (vty
, &rfd
->vn_addr
);
1803 vty_out (vty
, " %p %p ", rfd
->response_cb
, rfd
->cookie
);
1804 rfapiPrintRd (vty
, &rfd
->rd
);
1805 vty_out (vty
, " %d", rfd
->response_lifetime
);
1806 vty_out (vty
, " %s", (rfd
->rfg
? rfd
->rfg
->name
: "<orphaned>"));
1807 vty_out (vty
, "%s", HVTY_NEWLINE
);
1809 vty_out (vty
, " Peer %p #%d%s", rfd
->peer
, rfd
->peer
->lock
, HVTY_NEWLINE
);
1811 /* export RT list */
1812 if (rfd
->rt_export_list
)
1815 ecommunity_ecom2str (rfd
->rt_export_list
,
1816 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1817 vty_out (vty
, " Export %s%s", s
, HVTY_NEWLINE
);
1818 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1822 vty_out (vty
, " Export (nil)%s", HVTY_NEWLINE
);
1825 /* import RT list */
1826 if (rfd
->import_table
)
1828 s
= ecommunity_ecom2str (rfd
->import_table
->rt_import_list
,
1829 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1830 vty_out (vty
, " Import %s%s", s
, HVTY_NEWLINE
);
1831 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1835 vty_out (vty
, " Import (nil)%s", HVTY_NEWLINE
);
1838 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1842 family
= afi2family (afi
);
1848 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1851 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1855 /* group like family prefixes together in output */
1856 if (family
!= adb
->prefix_ip
.family
)
1859 prefix2str (&adb
->prefix_ip
, buf
, BUFSIZ
);
1860 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1862 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1863 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->prefix_ip
);
1867 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1870 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1874 prefix2str (&adb
->prefix_eth
, buf
, BUFSIZ
);
1875 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1877 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1879 /* TBD update the following function to print ethernet info */
1880 /* Also need to pass/use rd */
1881 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->prefix_ip
);
1883 vty_out (vty
, "%s", HVTY_NEWLINE
);
1887 * test scripts rely on first line for each nve starting in 1st column,
1888 * leading whitespace for additional detail of that nve
1891 rfapiPrintMatchingDescriptors (struct vty
*vty
,
1892 struct prefix
*vn_prefix
,
1893 struct prefix
*un_prefix
)
1897 struct listnode
*ln
;
1898 struct rfapi_descriptor
*rfd
;
1901 bgp
= bgp_get_default (); /* assume 1 instance for now */
1908 for (ln
= listhead (&h
->descriptors
); ln
; ln
= listnextnode (ln
))
1910 rfd
= listgetdata (ln
);
1916 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
1917 if (!prefix_match (vn_prefix
, &pfx
))
1923 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
1924 if (!prefix_match (un_prefix
, &pfx
))
1930 /* print column header */
1932 "%s %s %s %s %s %s %s %s%s",
1933 "descriptor", "un-addr", "vn-addr", "callback", "cookie",
1934 "RD", "lifetime", "group", HVTY_NEWLINE
);
1936 rfapiPrintDescriptor (vty
, rfd
);
1943 * Parse an address and put into a struct prefix
1946 rfapiCliGetPrefixAddr (struct vty
*vty
, const char *str
, struct prefix
*p
)
1948 if (!str2prefix (str
, p
))
1950 vty_out (vty
, "Malformed address \"%s\"%s", str
, HVTY_NEWLINE
);
1956 if (p
->prefixlen
!= 32)
1958 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1963 if (p
->prefixlen
!= 128)
1965 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1970 vty_out (vty
, "Invalid address \"%s\"%s", str
, HVTY_NEWLINE
);
1977 rfapiCliGetRfapiIpAddr (
1980 struct rfapi_ip_addr
*hai
)
1985 rc
= rfapiCliGetPrefixAddr (vty
, str
, &pfx
);
1989 hai
->addr_family
= pfx
.family
;
1990 if (pfx
.family
== AF_INET
)
1991 hai
->addr
.v4
= pfx
.u
.prefix4
;
1993 hai
->addr
.v6
= pfx
.u
.prefix6
;
1999 * Note: this function does not flush vty output, so if it is called
2000 * with a stream pointing to a vty, the user will have to type something
2001 * before the callback output shows up
2004 rfapiPrintNhl (void *stream
, struct rfapi_next_hop_entry
*next_hops
)
2006 struct rfapi_next_hop_entry
*nh
;
2009 int (*fp
) (void *, const char *, ...);
2012 const char *vty_newline
;
2014 #define REMAIN (BUFSIZ - (p-line))
2015 #define INCP {p += (r > REMAIN)? REMAIN: r;}
2018 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
2021 for (nh
= next_hops
, count
= 1; nh
; nh
= nh
->next
, ++count
)
2028 r
= snprintf (p
, REMAIN
, "%3d pfx=", count
);
2031 if (rfapiRfapiIpPrefix2Str (&nh
->prefix
, p
, REMAIN
))
2033 /* it fit, so count length */
2043 r
= snprintf (p
, REMAIN
, ", un=");
2046 if (rfapiRfapiIpAddr2Str (&nh
->un_address
, p
, REMAIN
))
2048 /* it fit, so count length */
2058 r
= snprintf (p
, REMAIN
, ", vn=");
2061 if (rfapiRfapiIpAddr2Str (&nh
->vn_address
, p
, REMAIN
))
2063 /* it fit, so count length */
2074 line
[BUFSIZ
- 1] = 0;
2075 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
2082 struct rfapi_vn_option
*vo
;
2083 char offset
[] = " ";
2085 for (vo
= nh
->vn_options
; vo
; vo
= vo
->next
)
2091 case RFAPI_VN_OPTION_TYPE_L2ADDR
:
2092 rfapiEthAddr2Str (&vo
->v
.l2addr
.macaddr
, pbuf
,
2094 fp (out
, "%sL2 %s LBL=0x%06x NETID=0x%06x NVEID=%d%s",
2095 offset
, pbuf
, (vo
->v
.l2addr
.label
& 0x00ffffff),
2096 (vo
->v
.l2addr
.logical_net_id
& 0x00ffffff),
2097 vo
->v
.l2addr
.local_nve_id
, HVTY_NEWLINE
);
2100 case RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
:
2101 prefix2str (&vo
->v
.local_nexthop
.addr
, pbuf
, sizeof (pbuf
));
2102 fp (out
, "%sLNH %s cost=%d%s",
2103 offset
, pbuf
, vo
->v
.local_nexthop
.cost
, HVTY_NEWLINE
);
2107 fp (out
, "%svn option type %d (unknown)%s",
2108 offset
, vo
->type
, HVTY_NEWLINE
);
2115 struct rfapi_un_option
*uo
;
2116 char offset
[] = " ";
2118 for (uo
= nh
->un_options
; uo
; uo
= uo
->next
)
2122 case RFAPI_UN_OPTION_TYPE_TUNNELTYPE
:
2123 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
2126 fp (out
, "%sUN Option type %d%s",
2127 offset
, uo
->type
, vty_newline
);
2136 /***********************************************************************
2138 ***********************************************************************/
2141 * Add another nexthop to the NHL
2144 rfapiAddDeleteLocalRfpPrefix (
2145 struct rfapi_ip_addr
*un_addr
,
2146 struct rfapi_ip_addr
*vn_addr
,
2147 struct rfapi_ip_prefix
*rprefix
,
2149 uint32_t lifetime
, /* add only */
2150 struct rfapi_vn_option
*vn_options
,
2151 struct rfapi_next_hop_entry
**head
,
2152 struct rfapi_next_hop_entry
**tail
)
2154 struct rfapi_next_hop_entry
*new;
2160 new = XCALLOC (MTYPE_RFAPI_NEXTHOP
, sizeof (struct rfapi_next_hop_entry
));
2161 new->prefix
= *rprefix
;
2162 new->un_address
= *un_addr
;
2163 new->vn_address
= *vn_addr
;
2165 new->vn_options
= vn_options
;
2168 new->lifetime
= lifetime
;
2172 new->lifetime
= RFAPI_REMOVE_RESPONSE_LIFETIME
;
2176 (*tail
)->next
= new;
2188 const char *arg_prefix
,
2191 const char *arg_cost
, /* optional */
2192 const char *arg_lifetime
, /* optional */
2193 const char *arg_macaddr
, /* optional */
2194 const char *arg_vni
, /* mac present=>mandatory Virtual Network ID */
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
, "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",
2255 if (!strcmp (*argv
, "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
;
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
;
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 zlog_debug ("%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 zlog_debug ("%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 zlog_debug ("%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 infomation\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
[0], argv
[1], argv
[2], argv
[3], argv
[4],
2567 NULL
, NULL
, argc
, argv
);
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 infomation\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
[0], argv
[1], argv
[2], argv
[4], argv
[3],
2593 NULL
, NULL
, argc
, argv
);
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 infomation\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
[0], argv
[1], argv
[2], argv
[3], NULL
,
2617 NULL
, NULL
, argc
, argv
);
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 infomation\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
[0], argv
[1], argv
[2], NULL
, argv
[3],
2641 NULL
, NULL
, argc
, argv
);
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 infomation\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
[0], argv
[1], argv
[2], NULL
, NULL
,
2663 NULL
, NULL
, argc
, argv
);
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 infomation\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
[0], argv
[1], argv
[2], argv
[3], argv
[4],
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 infomation\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
[0], argv
[1], argv
[2], argv
[4], argv
[3],
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 infomation\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
[0], argv
[1], argv
[2], argv
[3], 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 infomation\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
[0], argv
[1], argv
[2], NULL
, argv
[3],
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 infomation\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
[0], argv
[1], argv
[2], 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 infomation\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 infomation\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
[4], argv
[2], argv
[3], argv
[5], argv
[6],
2820 argv
[0], argv
[1], 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 infomation\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 infomation\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
[4], argv
[2], argv
[3], NULL
, argv
[5],
2848 argv
[0], argv
[1], 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 infomation\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 infomation\n"
2869 "Administrative cost [default: 255]\n" "Administrative cost\n")
2871 /* pfx vn un cost life */
2872 return register_add (vty
, argv
[4], argv
[2], argv
[3], argv
[5], NULL
,
2874 argv
[0], argv
[1], 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 infomation\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 infomation\n"
2893 "IPv4 prefix\n" "IPv6 prefix\n")
2895 /* pfx vn un cost life */
2896 return register_add (vty
, argv
[4], argv
[2], argv
[3], NULL
, NULL
,
2898 argv
[0], argv
[1], 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 infomation\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
[2], argv
[3], argv
[4], argv
[5],
2924 argv
[0], argv
[1], 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 infomation\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
[2], argv
[3], argv
[4], NULL
,
2948 argv
[0], argv
[1], 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 infomation\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
[2], argv
[3], NULL
, argv
[4],
2973 argv
[0], argv
[1], 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 infomation\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
[2], argv
[3], NULL
, NULL
,
2995 argv
[0], argv
[1], 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 const char *arg_prefix
,
3113 const char *arg_l2addr
,
3114 const char *arg_vni
,
3115 struct rfapi_local_reg_delete_arg
*rcdarg
)
3117 int rc
= CMD_WARNING
;
3119 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3121 if (arg_vn
&& strcmp (arg_vn
, "*"))
3123 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3126 if (arg_un
&& strcmp (arg_un
, "*"))
3128 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3131 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3134 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3136 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
, VTY_NEWLINE
);
3145 vty_out (vty
, "Missing VNI%s", VTY_NEWLINE
);
3148 if (strcmp (arg_l2addr
, "*"))
3150 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3152 vty_out (vty
, "Malformed L2 Address \"%s\"%s",
3153 arg_l2addr
, VTY_NEWLINE
);
3156 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3158 if (strcmp (arg_vni
, "*"))
3160 VTY_GET_INTEGER ("Logical Network ID",
3161 rcdarg
->l2o
.o
.logical_net_id
, arg_vni
);
3162 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3169 record_nve_in_cda_list (
3170 struct rfapi_local_reg_delete_arg
*cda
,
3171 struct rfapi_ip_addr
*un_address
,
3172 struct rfapi_ip_addr
*vn_address
,
3173 struct rfapi_descriptor
*rfd
)
3176 struct nve_addr
*hap
;
3178 memset (&ha
, 0, sizeof (ha
));
3179 ha
.un
= *un_address
;
3180 ha
.vn
= *vn_address
;
3184 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3186 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3188 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3192 skiplist_insert (cda
->nves
, hap
, hap
);
3197 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3200 struct rfapi_descriptor
*rfd
;
3201 int query_count
= 0;
3202 struct listnode
*node
;
3203 struct bgp
*bgp_default
= bgp_get_default ();
3205 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3211 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3214 rfapiRibClear (rfd
);
3215 rfapi_query_done_all (rfd
, &query_count
);
3216 cda
->query_count
+= query_count
;
3219 * Track unique nves seen
3221 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3232 h
= bgp_default
->rfapi
;
3237 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3240 * match un, vn addresses of NVEs
3242 if (cda
->un_address
.addr_family
&&
3243 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3247 if (cda
->vn_address
.addr_family
&&
3248 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3253 rfapiRibClear (rfd
);
3255 rfapi_query_done_all (rfd
, &query_count
);
3256 cda
->query_count
+= query_count
;
3259 * Track unique nves seen
3261 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3266 * TBD need to count deleted prefixes and nves?
3268 * ENXIO BGP or VNC not configured
3271 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3273 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3274 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3275 struct prefix
*pPrefix
; /* NULL = wildcard */
3278 struct listnode
*node
;
3279 struct rfapi_descriptor
*rfd
;
3280 struct rfapi_ip_prefix rprefix
;
3281 struct bgp
*bgp_default
= bgp_get_default ();
3282 struct rfapi_next_hop_entry
*head
= NULL
;
3283 struct rfapi_next_hop_entry
*tail
= NULL
;
3284 struct rfapi_cfg
*rfapi_cfg
;
3287 zlog_debug ("%s: entry", __func__
);
3293 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3294 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3295 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3297 h
= bgp_default
->rfapi
;
3298 rfapi_cfg
= bgp_default
->rfapi_cfg
;
3300 if (!h
|| !rfapi_cfg
)
3305 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3309 zlog_debug ("%s: starting descriptor loop", __func__
);
3312 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3314 struct rfapi_adb
*adb
;
3316 int deleted_from_this_nve
;
3318 struct nve_addr
*hap
;
3321 zlog_debug ("%s: rfd=%p", __func__
, rfd
);
3325 * match un, vn addresses of NVEs
3327 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3329 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3333 zlog_debug ("%s: un, vn match", __func__
);
3340 deleted_from_this_nve
= 0;
3343 struct skiplist
*sl
;
3344 struct rfapi_ip_prefix rp
;
3346 struct list
*adb_delete_list
;
3349 * The advertisements are stored in a skiplist. Withdrawing
3350 * the registration deletes the advertisement from the
3351 * skiplist, which we can't do while iterating over that
3352 * same skiplist using the current skiplist API.
3354 * Strategy: iterate over the skiplist and build another
3355 * list containing only the matching ADBs. Then delete
3356 * _everything_ in that second list (which can be done
3357 * using either skiplists or quagga linklists).
3359 adb_delete_list
= list_new ();
3362 * Advertised IP prefixes (not 0/32 or 0/128)
3364 sl
= rfd
->advertised
.ipN_by_prefix
;
3367 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3368 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3373 if (!prefix_same (pPrefix
, &adb
->prefix_ip
))
3376 zlog_debug ("%s: adb=%p, prefix doesn't match, skipping",
3382 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3385 (cda
->l2o
.o
.macaddr
.octet
,
3386 adb
->prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3389 zlog_debug ("%s: adb=%p, macaddr doesn't match, skipping",
3396 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3398 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3401 zlog_debug ("%s: adb=%p, LNI doesn't match, skipping",
3409 zlog_debug ("%s: ipN adding adb %p to delete list", __func__
,
3413 listnode_add (adb_delete_list
, adb
);
3416 struct listnode
*node
;
3418 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3421 struct rfapi_vn_option vn1
;
3422 struct rfapi_vn_option vn2
;
3423 struct rfapi_vn_option
*pVn
;
3424 int this_advertisement_prefix_count
;
3426 this_advertisement_prefix_count
= 1;
3428 rfapiQprefix2Rprefix (&adb
->prefix_ip
, &rp
);
3430 /* if mac addr present in advert, make l2o vn option */
3431 if (adb
->prefix_eth
.family
== AF_ETHERNET
)
3434 memset (&vn1
, 0, sizeof (vn1
));
3435 memset (&vn2
, 0, sizeof (vn2
));
3437 vn1
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3438 vn1
.v
.l2addr
.macaddr
= adb
->prefix_eth
.u
.prefix_eth
;
3441 * use saved RD value instead of trying to invert
3442 * complex L2-style RD computation in rfapi_register()
3444 vn2
.type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3445 vn2
.v
.internal_rd
= adb
->prd
;
3450 ++this_advertisement_prefix_count
;
3458 zlog_debug ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3461 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, pVn
, RFAPI_REGISTER_KILL
);
3464 cda
->pfx_count
+= this_advertisement_prefix_count
;
3465 cda
->reg_count
+= 1;
3466 deleted_from_this_nve
= 1;
3468 if (h
->rfp_methods
.local_cb
)
3470 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3471 &rp
, 0, 0, NULL
, &head
, &tail
);
3474 list_delete_all_node (adb_delete_list
);
3476 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3481 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3485 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3487 sl
= rfd
->advertised
.ip0_by_ether
;
3490 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3491 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3494 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3496 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3497 adb
->prefix_eth
.u
.prefix_eth
.octet
,
3504 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3506 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3512 zlog_debug ("%s: ip0 adding adb %p to delete list",
3515 listnode_add (adb_delete_list
, adb
);
3519 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3522 struct rfapi_vn_option vn
;
3524 rfapiQprefix2Rprefix (&adb
->prefix_ip
, &rp
);
3526 memset (&vn
, 0, sizeof (vn
));
3527 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3528 vn
.v
.l2addr
= adb
->l2o
;
3531 zlog_debug ("%s: ip0 killing reg from adb %p ",
3535 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3536 RFAPI_REGISTER_KILL
);
3539 cda
->pfx_count
+= 1;
3540 cda
->reg_count
+= 1;
3541 deleted_from_this_nve
= 1;
3543 if (h
->rfp_methods
.local_cb
)
3545 struct rfapi_vn_option
*vn_opt_new
;
3547 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3548 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3549 &rfd
->vn_addr
, &rp
, 0, 0,
3550 vn_opt_new
, &head
, &tail
);
3553 list_delete_all_node (adb_delete_list
);
3555 list_delete (adb_delete_list
);
3560 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3561 h
->flags
|= RFAPI_INCALLBACK
;
3562 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3563 h
->flags
&= ~RFAPI_INCALLBACK
;
3567 if (deleted_from_this_nve
)
3570 * track unique NVEs seen
3572 memset (&ha
, 0, sizeof (ha
));
3573 ha
.un
= rfd
->un_addr
;
3574 ha
.vn
= rfd
->vn_addr
;
3577 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3578 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3580 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3584 skiplist_insert (cda
->nves
, hap
, hap
);
3595 * Deletes local and remote prefixes that match
3598 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3600 struct prefix pfx_un
;
3601 struct prefix pfx_vn
;
3603 struct prefix
*pUN
= NULL
;
3604 struct prefix
*pVN
= NULL
;
3605 struct prefix
*pPrefix
= NULL
;
3608 * Delete matching remote prefixes in holddown
3610 if (cda
->vn_address
.addr_family
)
3612 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3615 if (cda
->un_address
.addr_family
)
3617 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3620 if (cda
->prefix
.family
)
3622 pPrefix
= &cda
->prefix
;
3624 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
,
3625 0, 1, &cda
->remote_active_pfx_count
,
3626 &cda
->remote_active_nve_count
,
3627 &cda
->remote_holddown_pfx_count
,
3628 &cda
->remote_holddown_nve_count
);
3631 * Now do local prefixes
3633 rfapiDeleteLocalPrefixes (cda
);
3637 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3639 struct vty
*vty
= cda
->vty
; /* for benefit of VTY_NEWLINE */
3641 /* Our special element-deleting function counts nves */
3644 skiplist_free (cda
->nves
);
3647 if (cda
->failed_pfx_count
)
3648 vty_out (vty
, "Failed to delete %d prefixes%s",
3649 cda
->failed_pfx_count
, VTY_NEWLINE
);
3651 /* left as "prefixes" even in single case for ease of machine parsing */
3653 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs%s",
3654 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
, cda
->nve_count
,
3658 * We don't currently allow deletion of active remote prefixes from
3662 vty_out (vty
, "[Holddown] Cleared %u prefixes from %u NVEs%s",
3663 cda
->remote_holddown_pfx_count
, cda
->remote_holddown_nve_count
,
3668 * Caller has already deleted registrations and queries for this/these
3669 * NVEs. Now we just have to close their descriptors.
3672 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3674 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3675 struct nve_addr
*pKey
;
3676 struct nve_addr
*pValue
;
3677 void *cursor
= NULL
;
3683 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3685 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3690 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3691 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3692 rfapi_close (pValue
->rfd
);
3697 DEFUN (clear_vnc_nve_all
,
3698 clear_vnc_nve_all_cmd
,
3701 "VNC Information\n" "Clear per NVE information\n" "For all NVEs\n")
3704 struct rfapi_local_reg_delete_arg cda
;
3707 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3712 clear_vnc_responses (&cda
);
3713 clear_vnc_prefix (&cda
);
3714 clear_vnc_nve_closer (&cda
);
3716 print_cleared_stats (&cda
);
3721 DEFUN (clear_vnc_nve_vn_un
,
3722 clear_vnc_nve_vn_un_cmd
,
3723 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3726 "Clear prefix registration infomation\n"
3727 "VN address of NVE\n"
3728 "VN IPv4 interface address\n"
3729 "VN IPv6 interface address\n"
3730 "UN address of NVE\n"
3731 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
3733 struct rfapi_local_reg_delete_arg cda
;
3737 parse_deleter_args (vty
, NULL
, argv
[0], argv
[1], NULL
, NULL
, &cda
)))
3742 clear_vnc_responses (&cda
);
3743 clear_vnc_prefix (&cda
);
3744 clear_vnc_nve_closer (&cda
);
3746 print_cleared_stats (&cda
);
3751 DEFUN (clear_vnc_nve_un_vn
,
3752 clear_vnc_nve_un_vn_cmd
,
3753 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3756 "Clear prefix registration infomation\n"
3757 "UN address of NVE\n"
3758 "UN IPv4 interface address\n"
3759 "UN IPv6 interface address\n"
3760 "VN address of NVE\n"
3761 "VN IPv4 interface address\n" "VN IPv6 interface address\n")
3763 struct rfapi_local_reg_delete_arg cda
;
3767 parse_deleter_args (vty
, NULL
, argv
[1], argv
[0], NULL
, NULL
, &cda
)))
3772 clear_vnc_responses (&cda
);
3773 clear_vnc_prefix (&cda
);
3774 clear_vnc_nve_closer (&cda
);
3776 print_cleared_stats (&cda
);
3781 DEFUN (clear_vnc_nve_vn
,
3782 clear_vnc_nve_vn_cmd
,
3783 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3786 "Clear prefix registration infomation\n"
3787 "VN address of NVE\n"
3788 "VN IPv4 interface address\n" "VN IPv6 interface address\n")
3790 struct rfapi_local_reg_delete_arg cda
;
3793 if ((rc
= parse_deleter_args (vty
, NULL
, argv
[0], NULL
, NULL
, NULL
, &cda
)))
3798 clear_vnc_responses (&cda
);
3799 clear_vnc_prefix (&cda
);
3800 clear_vnc_nve_closer (&cda
);
3802 print_cleared_stats (&cda
);
3806 DEFUN (clear_vnc_nve_un
,
3807 clear_vnc_nve_un_cmd
,
3808 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3811 "Clear prefix registration infomation\n"
3812 "UN address of NVE\n"
3813 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
3815 struct rfapi_local_reg_delete_arg cda
;
3818 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, argv
[0], NULL
, NULL
, &cda
)))
3823 clear_vnc_responses (&cda
);
3824 clear_vnc_prefix (&cda
);
3825 clear_vnc_nve_closer (&cda
);
3827 print_cleared_stats (&cda
);
3831 /*-------------------------------------------------
3833 *-------------------------------------------------*/
3836 * This function is defined in this file (rather than in rfp_registration.c)
3837 * because here we have access to all the task handles.
3839 DEFUN (clear_vnc_prefix_vn_un
,
3840 clear_vnc_prefix_vn_un_cmd
,
3841 "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>",
3844 "Clear prefix registration infomation\n"
3848 "VN address of NVE\n"
3849 "All VN addresses\n"
3850 "VN IPv4 interface address\n"
3851 "VN IPv6 interface address\n"
3852 "UN address of NVE\n"
3853 "All UN addresses\n"
3854 "UN IPv4 interface address\n"
3855 "UN IPv6 interface address\n")
3857 struct rfapi_local_reg_delete_arg cda
;
3861 parse_deleter_args (vty
, argv
[0], argv
[1], argv
[2], NULL
, NULL
, &cda
)))
3864 clear_vnc_prefix (&cda
);
3865 print_cleared_stats (&cda
);
3869 DEFUN (clear_vnc_prefix_un_vn
,
3870 clear_vnc_prefix_un_vn_cmd
,
3871 "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>",
3874 "Clear prefix registration infomation\n"
3878 "UN address of NVE\n"
3879 "All UN addresses\n"
3880 "UN IPv4 interface address\n"
3881 "UN IPv6 interface address\n"
3882 "VN address of NVE\n"
3883 "All VN addresses\n"
3884 "VN IPv4 interface address\n"
3885 "VN IPv6 interface address\n")
3887 struct rfapi_local_reg_delete_arg cda
;
3891 parse_deleter_args (vty
, argv
[0], argv
[2], argv
[1], NULL
, NULL
, &cda
)))
3894 clear_vnc_prefix (&cda
);
3895 print_cleared_stats (&cda
);
3899 DEFUN (clear_vnc_prefix_un
,
3900 clear_vnc_prefix_un_cmd
,
3901 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3904 "Clear prefix registration infomation\n"
3908 "UN address of NVE\n"
3909 "All UN addresses\n"
3910 "UN IPv4 interface address\n"
3911 "UN IPv6 interface address\n")
3913 struct rfapi_local_reg_delete_arg cda
;
3917 parse_deleter_args (vty
, argv
[0], NULL
, argv
[1], NULL
, NULL
, &cda
)))
3920 clear_vnc_prefix (&cda
);
3921 print_cleared_stats (&cda
);
3925 DEFUN (clear_vnc_prefix_vn
,
3926 clear_vnc_prefix_vn_cmd
,
3927 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
3930 "Clear prefix registration infomation\n"
3934 "UN address of NVE\n"
3935 "All VN addresses\n"
3936 "VN IPv4 interface address\n"
3937 "VN IPv6 interface address\n")
3939 struct rfapi_local_reg_delete_arg cda
;
3943 parse_deleter_args (vty
, argv
[0], argv
[1], NULL
, NULL
, NULL
, &cda
)))
3946 clear_vnc_prefix (&cda
);
3947 print_cleared_stats (&cda
);
3951 DEFUN (clear_vnc_prefix_all
,
3952 clear_vnc_prefix_all_cmd
,
3953 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
3956 "Clear prefix registration infomation\n"
3962 struct rfapi_local_reg_delete_arg cda
;
3965 if ((rc
= parse_deleter_args (vty
, argv
[0], NULL
, NULL
, NULL
, NULL
, &cda
)))
3968 clear_vnc_prefix (&cda
);
3969 print_cleared_stats (&cda
);
3973 /*-------------------------------------------------
3975 *-------------------------------------------------*/
3978 * This function is defined in this file (rather than in rfp_registration.c)
3979 * because here we have access to all the task handles.
3981 DEFUN (clear_vnc_mac_vn_un
,
3982 clear_vnc_mac_vn_un_cmd
,
3983 "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>",
3986 "Clear mac registration infomation\n"
3990 "Any virtual network identifier\n"
3991 "Virtual network identifier\n"
3992 "Virtual network identifier\n"
3993 "VN address of NVE\n"
3994 "All VN addresses\n"
3995 "VN IPv4 interface address\n"
3996 "VN IPv6 interface address\n"
3997 "UN address of NVE\n"
3998 "All UN addresses\n"
3999 "UN IPv4 interface address\n"
4000 "UN IPv6 interface address\n")
4002 struct rfapi_local_reg_delete_arg cda
;
4005 /* pfx vn un L2 VNI */
4007 parse_deleter_args (vty
, NULL
, argv
[2], argv
[3], argv
[0], argv
[1],
4011 clear_vnc_prefix (&cda
);
4012 print_cleared_stats (&cda
);
4016 DEFUN (clear_vnc_mac_un_vn
,
4017 clear_vnc_mac_un_vn_cmd
,
4018 "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>",
4021 "Clear mac registration infomation\n"
4025 "Any virtual network identifier\n"
4026 "Virtual network identifier\n"
4027 "UN address of NVE\n"
4028 "All UN addresses\n"
4029 "UN IPv4 interface address\n"
4030 "UN IPv6 interface address\n"
4031 "VN address of NVE\n"
4032 "All VN addresses\n"
4033 "VN IPv4 interface address\n"
4034 "VN IPv6 interface address\n")
4036 struct rfapi_local_reg_delete_arg cda
;
4039 /* pfx vn un L2 VNI */
4041 parse_deleter_args (vty
, NULL
, argv
[3], argv
[2], argv
[0], argv
[1],
4045 clear_vnc_prefix (&cda
);
4046 print_cleared_stats (&cda
);
4050 DEFUN (clear_vnc_mac_un
,
4051 clear_vnc_mac_un_cmd
,
4052 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4055 "Clear mac registration infomation\n"
4059 "Any virtual network identifier\n"
4060 "Virtual network identifier\n"
4061 "UN address of NVE\n"
4062 "All UN addresses\n"
4063 "UN IPv4 interface address\n"
4064 "UN IPv6 interface address\n")
4066 struct rfapi_local_reg_delete_arg cda
;
4069 /* pfx vn un L2 VNI */
4071 parse_deleter_args (vty
, NULL
, NULL
, argv
[2], argv
[0], argv
[1], &cda
)))
4074 clear_vnc_prefix (&cda
);
4075 print_cleared_stats (&cda
);
4079 DEFUN (clear_vnc_mac_vn
,
4080 clear_vnc_mac_vn_cmd
,
4081 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4084 "Clear mac registration infomation\n"
4088 "Any virtual network identifier\n"
4089 "Virtual network identifier\n"
4090 "UN address of NVE\n"
4091 "All VN addresses\n"
4092 "VN IPv4 interface address\n"
4093 "VN IPv6 interface address\n")
4095 struct rfapi_local_reg_delete_arg cda
;
4098 /* pfx vn un L2 VNI */
4100 parse_deleter_args (vty
, NULL
, argv
[2], NULL
, argv
[0], argv
[1], &cda
)))
4103 clear_vnc_prefix (&cda
);
4104 print_cleared_stats (&cda
);
4108 DEFUN (clear_vnc_mac_all
,
4109 clear_vnc_mac_all_cmd
,
4110 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4113 "Clear mac registration infomation\n"
4117 "Any virtual network identifier\n"
4118 "Virtual network identifier\n"
4121 struct rfapi_local_reg_delete_arg cda
;
4124 /* pfx vn un L2 VNI */
4126 parse_deleter_args (vty
, NULL
, NULL
, NULL
, argv
[0], argv
[1], &cda
)))
4129 clear_vnc_prefix (&cda
);
4130 print_cleared_stats (&cda
);
4134 /*-------------------------------------------------
4135 * Clear VNC MAC PREFIX
4136 *-------------------------------------------------*/
4138 DEFUN (clear_vnc_mac_vn_un_prefix
,
4139 clear_vnc_mac_vn_un_prefix_cmd
,
4140 "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>",
4143 "Clear mac registration infomation\n"
4147 "Any virtual network identifier\n"
4148 "Virtual network identifier\n"
4149 "Virtual network identifier\n"
4150 "VN address of NVE\n"
4151 "All VN addresses\n"
4152 "VN IPv4 interface address\n"
4153 "VN IPv6 interface address\n"
4154 "UN address of NVE\n"
4155 "All UN addresses\n"
4156 "UN IPv4 interface address\n"
4157 "UN IPv6 interface address\n"
4158 "Clear prefix registration infomation\n"
4163 struct rfapi_local_reg_delete_arg cda
;
4166 /* pfx vn un L2 VNI */
4168 parse_deleter_args (vty
, argv
[4], argv
[2], argv
[3], argv
[0], argv
[1],
4172 clear_vnc_prefix (&cda
);
4173 print_cleared_stats (&cda
);
4177 DEFUN (clear_vnc_mac_un_vn_prefix
,
4178 clear_vnc_mac_un_vn_prefix_cmd
,
4179 "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>",
4182 "Clear mac registration infomation\n"
4186 "Any virtual network identifier\n"
4187 "Virtual network identifier\n"
4188 "UN address of NVE\n"
4189 "All UN addresses\n"
4190 "UN IPv4 interface address\n"
4191 "UN IPv6 interface address\n"
4192 "VN address of NVE\n"
4193 "All VN addresses\n"
4194 "VN IPv4 interface address\n"
4195 "VN IPv6 interface address\n")
4197 struct rfapi_local_reg_delete_arg cda
;
4200 /* pfx vn un L2 VNI */
4202 parse_deleter_args (vty
, argv
[4], argv
[3], argv
[2], argv
[0], argv
[1],
4206 clear_vnc_prefix (&cda
);
4207 print_cleared_stats (&cda
);
4211 DEFUN (clear_vnc_mac_un_prefix
,
4212 clear_vnc_mac_un_prefix_cmd
,
4213 "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>",
4216 "Clear mac registration infomation\n"
4220 "Any virtual network identifier\n"
4221 "Virtual network identifier\n"
4222 "UN address of NVE\n"
4223 "All UN addresses\n"
4224 "UN IPv4 interface address\n"
4225 "UN IPv6 interface address\n")
4227 struct rfapi_local_reg_delete_arg cda
;
4230 /* pfx vn un L2 VNI */
4232 parse_deleter_args (vty
, argv
[3], NULL
, argv
[2], argv
[0], argv
[1],
4236 clear_vnc_prefix (&cda
);
4237 print_cleared_stats (&cda
);
4241 DEFUN (clear_vnc_mac_vn_prefix
,
4242 clear_vnc_mac_vn_prefix_cmd
,
4243 "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>",
4246 "Clear mac registration infomation\n"
4250 "Any virtual network identifier\n"
4251 "Virtual network identifier\n"
4252 "UN address of NVE\n"
4253 "All VN addresses\n"
4254 "VN IPv4 interface address\n"
4255 "VN IPv6 interface address\n")
4257 struct rfapi_local_reg_delete_arg cda
;
4260 /* pfx vn un L2 VNI */
4262 parse_deleter_args (vty
, argv
[3], argv
[2], NULL
, argv
[0], argv
[1],
4266 clear_vnc_prefix (&cda
);
4267 print_cleared_stats (&cda
);
4271 DEFUN (clear_vnc_mac_all_prefix
,
4272 clear_vnc_mac_all_prefix_cmd
,
4273 "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>",
4276 "Clear mac registration infomation\n"
4280 "Any virtual network identifier\n"
4281 "Virtual network identifier\n"
4282 "UN address of NVE\n"
4283 "All VN addresses\n"
4284 "VN IPv4 interface address\n"
4285 "VN IPv6 interface address\n")
4287 struct rfapi_local_reg_delete_arg cda
;
4290 /* pfx vn un L2 VNI */
4292 parse_deleter_args (vty
, argv
[2], NULL
, NULL
, argv
[0], argv
[1], &cda
)))
4295 clear_vnc_prefix (&cda
);
4296 print_cleared_stats (&cda
);
4300 /************************************************************************
4302 ************************************************************************/
4305 /* copied from rfp_vty.c */
4307 check_and_display_is_vnc_running (struct vty
*vty
)
4309 if (!bgp_rfapi_is_vnc_configured (NULL
))
4310 return 1; /* is running */
4315 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)%s",
4318 return 0; /* not running */
4322 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4324 struct bgp
*bgp_default
= bgp_get_default ();
4326 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4328 int active_local_routes
;
4329 int active_remote_routes
;
4330 int holddown_remote_routes
;
4331 int imported_remote_routes
;
4336 h
= bgp_default
->rfapi
;
4341 /* don't show local info if not running RFP */
4342 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4348 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4349 vty_out (vty
, "%-24s ", "NVEs:");
4350 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4351 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4352 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4355 case SHOW_NVE_SUMMARY_REGISTERED
:
4357 * NB: With the introduction of L2 route support, we no
4358 * longer have a one-to-one correspondence between
4359 * locally-originated route advertisements and routes in
4360 * the import tables that have local origin. This
4361 * discrepancy arises because a single advertisement
4362 * may contain both an IP prefix and a MAC address.
4363 * Such an advertisement results in two import table
4364 * entries: one indexed by IP prefix, the other indexed
4367 * TBD: update computation and display of registration
4368 * statistics to reflect the underlying semantics.
4372 vty_out (vty
, "%-24s ", "Registrations:");
4373 vty_out (vty
, "%-8s %-8u ", "Active:",
4374 rfapiApCountAll (bgp_default
));
4375 vty_out (vty
, "%-8s %-8u ", "Failed:",
4376 h
->stat
.count_registrations_failed
);
4377 vty_out (vty
, "%-8s %-8u", "Total:",
4378 h
->stat
.count_registrations
);
4379 vty_out (vty
, "%s", VTY_NEWLINE
);
4381 vty_out (vty
, "%-24s ", "Prefixes registered:");
4382 vty_out (vty
, "%s", VTY_NEWLINE
);
4384 rfapiCountAllItRoutes (&active_local_routes
,
4385 &active_remote_routes
,
4386 &holddown_remote_routes
,
4387 &imported_remote_routes
);
4392 vty_out (vty
, " %-20s ", "Locally:");
4393 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4394 vty_out (vty
, "%s", VTY_NEWLINE
);
4398 vty_out (vty
, " %-20s ", "Remotely:");
4399 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4400 vty_out (vty
, "%s", VTY_NEWLINE
);
4401 vty_out (vty
, " %-20s ", "In Holddown:");
4402 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4403 vty_out (vty
, "%s", VTY_NEWLINE
);
4404 vty_out (vty
, " %-20s ", "Imported:");
4405 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4408 case SHOW_NVE_SUMMARY_QUERIES
:
4409 vty_out (vty
, "%-24s ", "Queries:");
4410 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4411 vty_out (vty
, "%-8s %-8u ", "Failed:",
4412 h
->stat
.count_queries_failed
);
4413 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4416 case SHOW_NVE_SUMMARY_RESPONSES
:
4417 rfapiRibShowResponsesSummary (vty
);
4422 vty_out (vty
, "%s", VTY_NEWLINE
);
4427 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4434 struct prefix
*vn_prefix
,
4435 struct prefix
*un_prefix
)
4437 //struct hash *rfds;
4438 //struct rfp_rfapi_descriptor_param param;
4440 struct bgp
*bgp_default
= bgp_get_default ();
4442 struct listnode
*node
;
4443 struct rfapi_descriptor
*rfd
;
4452 h
= bgp_default
->rfapi
;
4457 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4461 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4464 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4467 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4476 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4477 if (!prefix_match (vn_prefix
, &pfx
))
4483 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4484 if (!prefix_match (un_prefix
, &pfx
))
4488 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4489 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4493 /* print out a header */
4495 "Active Next Hops%s", VTY_NEWLINE
);
4496 vty_out (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s%s",
4499 "Regis", "Resps", "Reach", "Remove", "Age", VTY_NEWLINE
);
4504 vty_out (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s%s",
4508 rfapi_monitor_count (rfd
),
4509 rfd
->stat_count_nh_reachable
,
4510 rfd
->stat_count_nh_removal
,
4511 rfapiFormatAge (rfd
->open_time
, age
, 10), VTY_NEWLINE
);
4514 if (printed
> 0 || vn_prefix
|| un_prefix
)
4515 vty_out (vty
, "Displayed %d out of %d active NVEs%s",
4516 printed
, total
, VTY_NEWLINE
);
4521 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4526 DEFUN (vnc_show_summary
,
4527 vnc_show_summary_cmd
,
4531 "Display VNC status summary\n")
4533 if (!check_and_display_is_vnc_running (vty
))
4535 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4536 vty_out (vty
, "%s", VTY_NEWLINE
);
4537 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4538 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4539 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4540 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4544 DEFUN (vnc_show_nves
,
4549 "List known NVEs\n")
4551 rfapi_show_nves (vty
, NULL
, NULL
);
4555 DEFUN (vnc_show_nves_ptct
,
4556 vnc_show_nves_ptct_cmd
,
4557 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4561 "VN address of NVE\n"
4562 "UN address of NVE\n"
4563 "IPv4 interface address\n"
4564 "IPv6 interface address\n")
4568 if (!check_and_display_is_vnc_running (vty
))
4571 if (!str2prefix (argv
[1], &pfx
))
4573 vty_out (vty
, "Malformed address \"%s\"%s", argv
[1], VTY_NEWLINE
);
4576 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4578 vty_out (vty
, "Invalid address \"%s\"%s", argv
[1], VTY_NEWLINE
);
4582 if (*(argv
[0]) == 'u')
4584 rfapi_show_nves (vty
, NULL
, &pfx
);
4588 rfapi_show_nves (vty
, &pfx
, NULL
);
4594 /* adapted from rfp_registration_cache_log() */
4596 rfapi_show_registrations (
4598 struct prefix
*restrict_to
,
4609 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4613 /* non-expiring, local */
4614 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4618 /* non-expiring, non-local */
4619 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4623 /* expiring, including local */
4624 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4628 /* non-expiring, non-local */
4629 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4633 vty_out (vty
, "%s", VTY_NEWLINE
);
4637 DEFUN (vnc_show_registrations_pfx
,
4638 vnc_show_registrations_pfx_cmd
,
4639 "show vnc registrations <[A.B.C.D/M]|[X:X::X:X/M]|[YY:YY:YY:YY:YY:YY]>",
4642 "List active prefix registrations\n"
4643 "Limit output to a particular prefix or address\n"
4644 "Limit output to a particular prefix or address\n")
4647 struct prefix
*p_addr
= NULL
;
4651 if (!str2prefix (argv
[0], &p
))
4653 vty_out (vty
, "Invalid prefix: %s%s", argv
[0], VTY_NEWLINE
);
4662 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4666 ALIAS (vnc_show_registrations_pfx
,
4667 vnc_show_registrations_cmd
,
4668 "show vnc registrations",
4671 "List active prefix registrations\n")
4672 DEFUN (vnc_show_registrations_some_pfx
,
4673 vnc_show_registrations_some_pfx_cmd
,
4674 "show vnc registrations (all|holddown|imported|local|remote) ([A.B.C.D/M]|[X:X::X:X/M]|[YY:YY:YY:YY:YY:YY])",
4677 "List active prefix registrations\n"
4678 "show all registrations\n"
4679 "show only registrations in holddown\n"
4680 "show only imported prefixes\n"
4681 "show only local registrations\n"
4682 "show only remote registrations\n"
4683 "Limit output to a particular prefix or address\n"
4684 "Limit output to a particular prefix or address\n")
4687 struct prefix
*p_addr
= NULL
;
4690 int show_remote
= 0;
4691 int show_holddown
= 0;
4692 int show_imported
= 0;
4696 if (!str2prefix (argv
[1], &p
))
4698 vty_out (vty
, "Invalid prefix: %s%s", argv
[1], VTY_NEWLINE
);
4732 rfapi_show_registrations (vty
, p_addr
,
4733 show_local
, show_remote
, show_holddown
,
4738 ALIAS (vnc_show_registrations_some_pfx
,
4739 vnc_show_registrations_some_cmd
,
4740 "show vnc registrations (all|holddown|imported|local|remote)",
4743 "List active prefix registrations\n"
4744 "show all registrations\n"
4745 "show only registrations in holddown\n"
4746 "show only imported prefixes\n"
4747 "show only local registrations\n"
4748 "show only remote registrations\n")
4750 DEFUN (vnc_show_responses_pfx
,
4751 vnc_show_responses_pfx_cmd
,
4752 "show vnc responses <[A.B.C.D/M]|[X:X::X:X/M]|[YY:YY:YY:YY:YY:YY]>",
4755 "List recent query responses\n"
4756 "Limit output to a particular prefix or address\n"
4757 "Limit output to a particular prefix or address\n")
4760 struct prefix
*p_addr
= NULL
;
4764 if (!str2prefix (argv
[0], &p
))
4766 vty_out (vty
, "Invalid prefix: %s%s", argv
[0], VTY_NEWLINE
);
4774 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4776 rfapiRibShowResponsesSummary (vty
);
4778 rfapiRibShowResponses (vty
, p_addr
, 0);
4779 rfapiRibShowResponses (vty
, p_addr
, 1);
4784 ALIAS (vnc_show_responses_pfx
,
4785 vnc_show_responses_cmd
,
4786 "show vnc responses",
4789 "List recent query responses\n")
4791 DEFUN (vnc_show_responses_some_pfx
,
4792 vnc_show_responses_some_pfx_cmd
,
4793 "show vnc responses <active|removed> <[A.B.C.D/M]|[X:X::X:X/M]|[YY:YY:YY:YY:YY:YY]>",
4796 "List recent query responses\n"
4797 "show only active query responses\n"
4798 "show only removed query responses\n"
4799 "Limit output to a particular prefix or address\n"
4800 "Limit output to a particular prefix or address\n")
4803 struct prefix
*p_addr
= NULL
;
4805 int show_active
= 0;
4806 int show_removed
= 0;
4808 if (!check_and_display_is_vnc_running (vty
))
4813 if (!str2prefix (argv
[1], &p
))
4815 vty_out (vty
, "Invalid prefix: %s%s", argv
[1], VTY_NEWLINE
);
4835 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4837 rfapiRibShowResponsesSummary (vty
);
4840 rfapiRibShowResponses (vty
, p_addr
, 0);
4842 rfapiRibShowResponses (vty
, p_addr
, 1);
4847 ALIAS (vnc_show_responses_some_pfx
,
4848 vnc_show_responses_some_cmd
,
4849 "show vnc responses (active|removed)",
4852 "List recent query responses\n"
4853 "show only active query responses\n"
4854 "show only removed query responses\n")
4856 DEFUN (show_vnc_queries_pfx
,
4857 show_vnc_queries_pfx_cmd
,
4858 "show vnc queries <[A.B.C.D/M]|[X:X::X:X/M]|[YY:YY:YY:YY:YY:YY]>",
4861 "List active queries\n"
4862 "Limit output to a particular IPv4 prefix or address\n"
4863 "Limit output to a particular IPv6 prefix or address\n")
4866 struct prefix
*p
= NULL
;
4870 if (!str2prefix (argv
[0], &pfx
))
4872 vty_out (vty
, "Invalid prefix: %s%s", argv
[0], VTY_NEWLINE
);
4878 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4880 return rfapiShowVncQueries (vty
, p
);
4883 ALIAS (show_vnc_queries_pfx
,
4884 show_vnc_queries_cmd
,
4888 "List active queries\n")
4890 DEFUN (vnc_clear_counters
,
4891 vnc_clear_counters_cmd
,
4892 "clear vnc counters",
4895 "Reset VNC counters\n")
4897 struct bgp
*bgp_default
= bgp_get_default ();
4899 struct listnode
*node
;
4900 struct rfapi_descriptor
*rfd
;
4905 h
= bgp_default
->rfapi
;
4911 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4913 rfd
->stat_count_nh_reachable
= 0;
4914 rfd
->stat_count_nh_removal
= 0;
4918 memset (&h
->stat
, 0, sizeof (h
->stat
));
4921 * 151122 per bug 103, set count_registrations = number active.
4922 * Do same for queries
4924 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4925 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4927 rfapiRibShowResponsesSummaryClear ();
4932 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4936 void rfapi_vty_init ()
4938 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
4939 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
4940 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
4941 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
4942 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
4944 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
4945 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
4946 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
4947 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
4948 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
4950 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
4951 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
4952 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
4953 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
4954 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
4955 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
4956 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
4957 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
4959 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
4960 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
4961 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
4962 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
4963 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
4965 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
4966 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
4967 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
4968 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
4969 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
4971 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
4972 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
4973 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
4974 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
4975 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
4977 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
4978 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
4979 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
4980 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
4981 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
4983 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
4985 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
4986 install_element (ENABLE_NODE
, &vnc_show_summary_cmd
);
4987 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
4988 install_element (ENABLE_NODE
, &vnc_show_nves_cmd
);
4989 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
4990 install_element (ENABLE_NODE
, &vnc_show_nves_ptct_cmd
);
4992 install_element (VIEW_NODE
, &vnc_show_registrations_cmd
);
4993 install_element (ENABLE_NODE
, &vnc_show_registrations_cmd
);
4994 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
4995 install_element (ENABLE_NODE
, &vnc_show_registrations_pfx_cmd
);
4997 install_element (VIEW_NODE
, &vnc_show_registrations_some_cmd
);
4998 install_element (ENABLE_NODE
, &vnc_show_registrations_some_cmd
);
4999 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
5000 install_element (ENABLE_NODE
, &vnc_show_registrations_some_pfx_cmd
);
5002 install_element (VIEW_NODE
, &vnc_show_responses_cmd
);
5003 install_element (ENABLE_NODE
, &vnc_show_responses_cmd
);
5004 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
5005 install_element (ENABLE_NODE
, &vnc_show_responses_pfx_cmd
);
5007 install_element (VIEW_NODE
, &vnc_show_responses_some_cmd
);
5008 install_element (ENABLE_NODE
, &vnc_show_responses_some_cmd
);
5009 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
5010 install_element (ENABLE_NODE
, &vnc_show_responses_some_pfx_cmd
);
5012 install_element (ENABLE_NODE
, &show_vnc_queries_cmd
);
5013 install_element (VIEW_NODE
, &show_vnc_queries_cmd
);
5014 install_element (ENABLE_NODE
, &show_vnc_queries_pfx_cmd
);
5015 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);