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 vnc_zlog_debug_verbose ("%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 struct cmd_token
*carg_prefix
,
2189 struct cmd_token
*carg_vn
,
2190 struct cmd_token
*carg_un
,
2191 struct cmd_token
*carg_cost
, /* optional */
2192 struct cmd_token
*carg_lifetime
, /* optional */
2193 struct cmd_token
*carg_macaddr
, /* optional */
2194 struct cmd_token
*carg_vni
, /* mac present=>mandatory Virtual Network ID */
2196 struct cmd_token
**argv
)
2198 const char *arg_prefix
= carg_prefix
->arg
;
2199 const char *arg_vn
= carg_vn
->arg
;
2200 const char *arg_un
= carg_un
->arg
;
2201 const char *arg_cost
= carg_cost
? carg_cost
->arg
: NULL
;
2202 const char *arg_lifetime
= carg_lifetime
? carg_lifetime
->arg
: NULL
;
2203 const char *arg_macaddr
= carg_macaddr
? carg_macaddr
->arg
: NULL
;
2204 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
2205 struct rfapi_ip_addr vn_address
;
2206 struct rfapi_ip_addr un_address
;
2208 struct rfapi_ip_prefix rpfx
;
2213 struct rfapi_vn_option optary
[10]; /* XXX must be big enough */
2214 struct rfapi_vn_option
*opt
= NULL
;
2217 int rc
= CMD_WARNING
;
2221 struct rfapi_cfg
*rfapi_cfg
;
2223 const char *arg_lnh
= NULL
;
2224 const char *arg_lnh_cost
= NULL
;
2226 bgp
= bgp_get_default (); /* assume 1 instance for now */
2230 vty_out (vty
, "BGP not configured%s", VTY_NEWLINE
);
2235 rfapi_cfg
= bgp
->rfapi_cfg
;
2236 if (!h
|| !rfapi_cfg
)
2239 vty_out (vty
, "RFAPI not configured%s", VTY_NEWLINE
);
2243 for (; argc
; --argc
, ++argv
)
2245 if (!strcmp (argv
[0]->arg
, "local-next-hop"))
2249 vty_out (vty
, "local-next-hop specified more than once%s",
2255 vty_out (vty
, "Missing parameter for local-next-hop%s",
2260 arg_lnh
= argv
[0]->arg
;
2262 if (!strcmp (argv
[0]->arg
, "local-cost"))
2266 vty_out (vty
, "local-cost specified more than once%s",
2272 vty_out (vty
, "Missing parameter for local-cost%s",
2277 arg_lnh_cost
= argv
[0]->arg
;
2281 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &vn_address
)))
2283 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &un_address
)))
2286 /* arg_prefix is optional if mac address is given */
2287 if (arg_macaddr
&& !arg_prefix
)
2290 * fake up a 0/32 or 0/128 prefix
2292 switch (vn_address
.addr_family
)
2295 arg_prefix
= "0.0.0.0/32";
2298 arg_prefix
= "0::0/128";
2301 vty_out (vty
, "Internal error, unknown VN address family%s",
2308 if (!str2prefix (arg_prefix
, &pfx
))
2310 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
,
2314 if (pfx
.family
!= AF_INET
2315 && pfx
.family
!= AF_INET6
)
2317 vty_out (vty
, "prefix \"%s\" has invalid address family%s",
2318 arg_prefix
, VTY_NEWLINE
);
2323 memset (optary
, 0, sizeof (optary
));
2328 cost
= strtoul (arg_cost
, &endptr
, 10);
2329 if (*endptr
!= '\0' || cost
> 255)
2331 vty_out (vty
, "%% Invalid %s value%s", "cost", VTY_NEWLINE
);
2342 if (!strcmp (arg_lifetime
, "infinite"))
2344 lifetime
= RFAPI_INFINITE_LIFETIME
;
2349 lifetime
= strtoul (arg_lifetime
, &endptr
, 10);
2350 if (*endptr
!= '\0')
2352 vty_out (vty
, "%% Invalid %s value%s", "lifetime",
2360 lifetime
= RFAPI_INFINITE_LIFETIME
; /* default infinite */
2368 "%% %s may only be specified with local-next-hop%s",
2369 "local-cost", VTY_NEWLINE
);
2373 lnh_cost
= strtoul (arg_lnh_cost
, &endptr
, 10);
2374 if (*endptr
!= '\0' || lnh_cost
> 255)
2376 vty_out (vty
, "%% Invalid %s value%s", "local-cost",
2390 vty_out (vty
, "%% %s may only be specified with prefix%s",
2391 "local-next-hop", VTY_NEWLINE
);
2394 if ((rc
= rfapiCliGetPrefixAddr (vty
, arg_lnh
,
2395 &optary
[opt_next
].v
.
2396 local_nexthop
.addr
)))
2402 optary
[opt_next
].v
.local_nexthop
.cost
= lnh_cost
;
2403 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
;
2407 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2416 if (arg_vni
&& !arg_macaddr
)
2418 vty_out (vty
, "%% %s may only be specified with mac address%s",
2419 "virtual-network-identifier", VTY_NEWLINE
);
2428 "Missing \"vni\" parameter (mandatory with mac)%s",
2432 VTY_GET_INTEGER ("Logical Network ID",
2433 optary
[opt_next
].v
.l2addr
.logical_net_id
,
2436 if ((rc
= rfapiStr2EthAddr (arg_macaddr
,
2437 &optary
[opt_next
].v
.l2addr
.macaddr
)))
2439 vty_out (vty
, "Invalid %s value%s", "mac address",
2443 /* TBD label, NVE ID */
2445 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
2449 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2458 vnc_zlog_debug_verbose
2459 ("%s: vn=%s, un=%s, prefix=%s, cost=%s, lifetime=%s, lnh=%s",
2460 __func__
, arg_vn
, arg_un
, arg_prefix
,
2461 (arg_cost
? arg_cost
: "NULL"),
2462 (arg_lifetime
? arg_lifetime
: "NULL"),
2463 (arg_lnh
? arg_lnh
: "NULL"));
2465 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
2467 rpfx
.cost
= cost
& 255;
2469 /* look up rf descriptor, call open if it doesn't exist */
2471 rfapi_find_rfd (bgp
, &vn_address
, &un_address
,
2472 (struct rfapi_descriptor
**) &rfd
);
2477 struct rfapi_un_option uo
;
2480 * flag descriptor as provisionally opened for static route
2481 * registration so that we can fix up the other parameters
2482 * when the real open comes along
2484 memset (&uo
, 0, sizeof (uo
));
2485 uo
.type
= RFAPI_UN_OPTION_TYPE_PROVISIONAL
;
2487 rc
= rfapi_open (rfapi_get_rfp_start_val_by_bgp (bgp
), &vn_address
, &un_address
, &uo
, /* flags */
2488 NULL
, NULL
, /* no userdata */
2492 vty_out (vty
, "Can't open session for this NVE: %s%s",
2493 rfapi_error_str (rc
), VTY_NEWLINE
);
2500 vty_out (vty
, "Can't find session for this NVE: %s%s",
2501 rfapi_error_str (rc
), VTY_NEWLINE
);
2507 rfapi_register (rfd
, &rpfx
, lifetime
, NULL
, opt
, RFAPI_REGISTER_ADD
);
2510 struct rfapi_next_hop_entry
*head
= NULL
;
2511 struct rfapi_next_hop_entry
*tail
= NULL
;
2512 struct rfapi_vn_option
*vn_opt_new
;
2514 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded, returning 0", __func__
);
2516 if (h
->rfp_methods
.local_cb
)
2518 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfd
;
2519 vn_opt_new
= rfapi_vn_options_dup (opt
);
2521 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
2522 1, lifetime
, vn_opt_new
, &head
,
2526 h
->flags
|= RFAPI_INCALLBACK
;
2527 (*h
->rfp_methods
.local_cb
) (head
, r
->cookie
);
2528 h
->flags
&= ~RFAPI_INCALLBACK
;
2535 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
2536 vty_out (vty
, "%s", VTY_NEWLINE
);
2537 vty_out (vty
, "Registration failed.%s", VTY_NEWLINE
);
2539 "Confirm that either the VN or UN address matches a configured NVE group.%s",
2544 vnc_zlog_debug_verbose ("%s: fail, rc=%d", __func__
, rc
);
2548 /************************************************************************
2549 * Add prefix With .LNH_OPTIONS
2550 ************************************************************************/
2551 DEFUN (add_vnc_prefix_cost_life_lnh
,
2552 add_vnc_prefix_cost_life_lnh_cmd
,
2553 "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",
2554 "Add registration\n"
2556 "Add/modify prefix related infomation\n"
2559 "VN address of NVE\n"
2560 "VN IPv4 interface address\n"
2561 "VN IPv6 interface address\n"
2562 "UN address of NVE\n"
2563 "UN IPv4 interface address\n"
2564 "UN IPv6 interface address\n"
2565 "Administrative cost [default: 255]\n"
2566 "Administrative cost\n"
2567 "Registration lifetime [default: infinite]\n"
2568 "Lifetime value in seconds\n"
2569 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2571 /* pfx vn un cost life */
2572 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2574 NULL
, NULL
, argc
- 12, argv
+ 12);
2577 DEFUN (add_vnc_prefix_life_cost_lnh
,
2578 add_vnc_prefix_life_cost_lnh_cmd
,
2579 "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",
2580 "Add registration\n"
2582 "Add/modify prefix related infomation\n"
2585 "VN address of NVE\n"
2586 "VN IPv4 interface address\n"
2587 "VN IPv6 interface address\n"
2588 "UN address of NVE\n"
2589 "UN IPv4 interface address\n"
2590 "UN IPv6 interface address\n"
2591 "Registration lifetime [default: infinite]\n"
2592 "Lifetime value in seconds\n"
2593 "Administrative cost [default: 255]\n"
2594 "Administrative cost\n"
2595 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2597 /* pfx vn un cost life */
2598 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2600 NULL
, NULL
, argc
- 12, argv
+ 12);
2603 DEFUN (add_vnc_prefix_cost_lnh
,
2604 add_vnc_prefix_cost_lnh_cmd
,
2605 "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",
2606 "Add registration\n"
2608 "Add/modify prefix related infomation\n"
2611 "VN address of NVE\n"
2612 "VN IPv4 interface address\n"
2613 "VN IPv6 interface address\n"
2614 "UN address of NVE\n"
2615 "UN IPv4 interface address\n"
2616 "UN IPv6 interface address\n"
2617 "Administrative cost [default: 255]\n"
2618 "Administrative cost\n"
2619 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2621 /* pfx vn un cost life */
2622 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2624 NULL
, NULL
, argc
- 10, argv
+ 10);
2627 DEFUN (add_vnc_prefix_life_lnh
,
2628 add_vnc_prefix_life_lnh_cmd
,
2629 "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",
2630 "Add registration\n"
2632 "Add/modify prefix related infomation\n"
2635 "VN address of NVE\n"
2636 "VN IPv4 interface address\n"
2637 "VN IPv6 interface address\n"
2638 "UN address of NVE\n"
2639 "UN IPv4 interface address\n"
2640 "UN IPv6 interface address\n"
2641 "Registration lifetime [default: infinite]\n"
2642 "Lifetime value in seconds\n"
2643 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2645 /* pfx vn un cost life */
2646 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2648 NULL
, NULL
, argc
- 10, argv
+ 10);
2651 DEFUN (add_vnc_prefix_lnh
,
2652 add_vnc_prefix_lnh_cmd
,
2653 "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",
2654 "Add registration\n"
2656 "Add/modify prefix related infomation\n"
2659 "VN address of NVE\n"
2660 "VN IPv4 interface address\n"
2661 "VN IPv6 interface address\n"
2662 "UN address of NVE\n"
2663 "UN IPv4 interface address\n"
2664 "UN IPv6 interface address\n"
2665 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2667 /* pfx vn un cost life */
2668 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2670 NULL
, NULL
, argc
- 8, argv
+ 8);
2673 /************************************************************************
2674 * Add prefix Without .LNH_OPTIONS
2675 ************************************************************************/
2676 DEFUN (add_vnc_prefix_cost_life
,
2677 add_vnc_prefix_cost_life_cmd
,
2678 "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)",
2679 "Add registration\n"
2681 "Add/modify prefix related infomation\n"
2684 "VN address of NVE\n"
2685 "VN IPv4 interface address\n"
2686 "VN IPv6 interface address\n"
2687 "UN address of NVE\n"
2688 "UN IPv4 interface address\n"
2689 "UN IPv6 interface address\n"
2690 "Administrative cost [default: 255]\n"
2691 "Administrative cost\n"
2692 "Registration lifetime [default: infinite]\n"
2693 "Lifetime value in seconds\n"
2694 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2696 /* pfx vn un cost life */
2697 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2699 NULL
, NULL
, 0, NULL
);
2702 DEFUN (add_vnc_prefix_life_cost
,
2703 add_vnc_prefix_life_cost_cmd
,
2704 "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)",
2705 "Add registration\n"
2707 "Add/modify prefix related infomation\n"
2710 "VN address of NVE\n"
2711 "VN IPv4 interface address\n"
2712 "VN IPv6 interface address\n"
2713 "UN address of NVE\n"
2714 "UN IPv4 interface address\n"
2715 "UN IPv6 interface address\n"
2716 "Registration lifetime [default: infinite]\n"
2717 "Lifetime value in seconds\n"
2718 "Administrative cost [default: 255]\n"
2719 "Administrative cost\n"
2720 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2722 /* pfx vn un cost life */
2723 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2725 NULL
, NULL
, 0, NULL
);
2728 DEFUN (add_vnc_prefix_cost
,
2729 add_vnc_prefix_cost_cmd
,
2730 "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)",
2731 "Add registration\n"
2733 "Add/modify prefix related infomation\n"
2736 "VN address of NVE\n"
2737 "VN IPv4 interface address\n"
2738 "VN IPv6 interface address\n"
2739 "UN address of NVE\n"
2740 "UN IPv4 interface address\n"
2741 "UN IPv6 interface address\n"
2742 "Administrative cost [default: 255]\n"
2743 "Administrative cost\n"
2744 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2746 /* pfx vn un cost life */
2747 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2749 NULL
, NULL
, 0, NULL
);
2752 DEFUN (add_vnc_prefix_life
,
2753 add_vnc_prefix_life_cmd
,
2754 "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)",
2755 "Add registration\n"
2757 "Add/modify prefix related infomation\n"
2760 "VN address of NVE\n"
2761 "VN IPv4 interface address\n"
2762 "VN IPv6 interface address\n"
2763 "UN address of NVE\n"
2764 "UN IPv4 interface address\n"
2765 "UN IPv6 interface address\n"
2766 "Registration lifetime [default: infinite]\n"
2767 "Lifetime value in seconds\n"
2768 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2770 /* pfx vn un cost life */
2771 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2773 NULL
, NULL
, 0, NULL
);
2776 DEFUN (add_vnc_prefix
,
2778 "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>",
2779 "Add registration\n"
2781 "Add/modify prefix related infomation\n"
2784 "VN address of NVE\n"
2785 "VN IPv4 interface address\n"
2786 "VN IPv6 interface address\n"
2787 "UN address of NVE\n"
2788 "UN IPv4 interface address\n"
2789 "UN IPv6 interface address\n"
2790 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2792 /* pfx vn un cost life */
2793 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2795 NULL
, NULL
, 0, NULL
);
2798 /************************************************************************
2799 * Mac address registrations
2800 ************************************************************************/
2801 DEFUN (add_vnc_mac_vni_prefix_cost_life
,
2802 add_vnc_mac_vni_prefix_cost_life_cmd
,
2803 "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)",
2804 "Add registration\n"
2806 "Add/modify mac address infomation\n"
2808 "Virtual Network Identifier follows\n"
2809 "Virtual Network Identifier\n"
2810 "VN address of NVE\n"
2811 "VN IPv4 interface address\n"
2812 "VN IPv6 interface address\n"
2813 "UN address of NVE\n"
2814 "UN IPv4 interface address\n"
2815 "UN IPv6 interface address\n"
2816 "Add/modify prefix related infomation\n"
2819 "Administrative cost [default: 255]\n"
2820 "Administrative cost\n"
2821 "Registration lifetime [default: infinite]\n"
2822 "Lifetime value in seconds\n")
2824 /* pfx vn un cost life */
2825 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], argv
[15],
2827 argv
[3], argv
[5], 0, NULL
);
2831 DEFUN (add_vnc_mac_vni_prefix_life
,
2832 add_vnc_mac_vni_prefix_life_cmd
,
2833 "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)",
2834 "Add registration\n"
2836 "Add/modify mac address infomation\n"
2838 "Virtual Network Identifier follows\n"
2839 "Virtual Network Identifier\n"
2840 "VN address of NVE\n"
2841 "VN IPv4 interface address\n"
2842 "VN IPv6 interface address\n"
2843 "UN address of NVE\n"
2844 "UN IPv4 interface address\n"
2845 "UN IPv6 interface address\n"
2846 "Add/modify prefix related infomation\n"
2849 "Registration lifetime [default: infinite]\n"
2850 "Lifetime value in seconds\n")
2852 /* pfx vn un cost life */
2853 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, argv
[13],
2855 argv
[3], argv
[5], 0, NULL
);
2858 DEFUN (add_vnc_mac_vni_prefix_cost
,
2859 add_vnc_mac_vni_prefix_cost_cmd
,
2860 "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)",
2861 "Add registration\n"
2863 "Add/modify mac address infomation\n"
2865 "Virtual Network Identifier follows\n"
2866 "Virtual Network Identifier\n"
2867 "VN address of NVE\n"
2868 "VN IPv4 interface address\n"
2869 "VN IPv6 interface address\n"
2870 "UN address of NVE\n"
2871 "UN IPv4 interface address\n"
2872 "UN IPv6 interface address\n"
2873 "Add/modify prefix related infomation\n"
2876 "Administrative cost [default: 255]\n" "Administrative cost\n")
2878 /* pfx vn un cost life */
2879 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], NULL
,
2881 argv
[3], argv
[5], 0, NULL
);
2884 DEFUN (add_vnc_mac_vni_prefix
,
2885 add_vnc_mac_vni_prefix_cmd
,
2886 "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>",
2887 "Add registration\n"
2889 "Add/modify mac address infomation\n"
2891 "Virtual Network Identifier follows\n"
2892 "Virtual Network Identifier\n"
2893 "VN address of NVE\n"
2894 "VN IPv4 interface address\n"
2895 "VN IPv6 interface address\n"
2896 "UN address of NVE\n"
2897 "UN IPv4 interface address\n"
2898 "UN IPv6 interface address\n"
2899 "Add/modify prefix related infomation\n"
2900 "IPv4 prefix\n" "IPv6 prefix\n")
2902 /* pfx vn un cost life */
2903 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, NULL
,
2905 argv
[3], argv
[5], 0, NULL
);
2908 DEFUN (add_vnc_mac_vni_cost_life
,
2909 add_vnc_mac_vni_cost_life_cmd
,
2910 "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)",
2911 "Add registration\n"
2913 "Add/modify mac address infomation\n"
2915 "Virtual Network Identifier follows\n"
2916 "Virtual Network Identifier\n"
2917 "VN address of NVE\n"
2918 "VN IPv4 interface address\n"
2919 "VN IPv6 interface address\n"
2920 "UN address of NVE\n"
2921 "UN IPv4 interface address\n"
2922 "UN IPv6 interface address\n"
2923 "Administrative cost [default: 255]\n"
2924 "Administrative cost\n"
2925 "Registration lifetime [default: infinite]\n"
2926 "Lifetime value in seconds\n")
2928 /* pfx vn un cost life */
2929 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], argv
[13],
2931 argv
[3], argv
[5], 0, NULL
);
2935 DEFUN (add_vnc_mac_vni_cost
,
2936 add_vnc_mac_vni_cost_cmd
,
2937 "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)",
2938 "Add registration\n"
2940 "Add/modify mac address infomation\n"
2942 "Virtual Network Identifier follows\n"
2943 "Virtual Network Identifier\n"
2944 "VN address of NVE\n"
2945 "VN IPv4 interface address\n"
2946 "VN IPv6 interface address\n"
2947 "UN address of NVE\n"
2948 "UN IPv4 interface address\n"
2949 "UN IPv6 interface address\n"
2950 "Administrative cost [default: 255]\n" "Administrative cost\n")
2952 /* pfx vn un cost life */
2953 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], NULL
,
2955 argv
[3], argv
[5], 0, NULL
);
2959 DEFUN (add_vnc_mac_vni_life
,
2960 add_vnc_mac_vni_life_cmd
,
2961 "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)",
2962 "Add registration\n"
2964 "Add/modify mac address infomation\n"
2966 "Virtual Network Identifier follows\n"
2967 "Virtual Network Identifier\n"
2968 "VN address of NVE\n"
2969 "VN IPv4 interface address\n"
2970 "VN IPv6 interface address\n"
2971 "UN address of NVE\n"
2972 "UN IPv4 interface address\n"
2973 "UN IPv6 interface address\n"
2974 "Registration lifetime [default: infinite]\n"
2975 "Lifetime value in seconds\n")
2977 /* pfx vn un cost life */
2978 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, argv
[11],
2980 argv
[3], argv
[5], 0, NULL
);
2984 DEFUN (add_vnc_mac_vni
,
2985 add_vnc_mac_vni_cmd
,
2986 "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>",
2987 "Add registration\n"
2989 "Add/modify mac address infomation\n"
2991 "Virtual Network Identifier follows\n"
2992 "Virtual Network Identifier\n"
2993 "VN address of NVE\n"
2994 "VN IPv4 interface address\n"
2995 "VN IPv6 interface address\n"
2996 "UN address of NVE\n"
2997 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
2999 /* pfx vn un cost life */
3000 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, NULL
,
3002 argv
[3], argv
[5], 0, NULL
);
3005 /************************************************************************
3007 ************************************************************************/
3009 struct rfapi_local_reg_delete_arg
3014 struct rfapi_ip_addr un_address
; /* AF==0: wildcard */
3015 struct rfapi_ip_addr vn_address
; /* AF==0: wildcard */
3016 struct prefix prefix
; /* AF==0: wildcard */
3018 struct rfapi_l2address_option_match l2o
;
3026 uint32_t query_count
;
3028 uint32_t failed_pfx_count
;
3031 struct skiplist
*nves
;
3033 uint32_t remote_active_nve_count
;
3034 uint32_t remote_active_pfx_count
;
3035 uint32_t remote_holddown_nve_count
;
3036 uint32_t remote_holddown_pfx_count
;
3041 struct rfapi_ip_addr vn
;
3042 struct rfapi_ip_addr un
;
3043 struct rfapi_descriptor
*rfd
;
3044 struct rfapi_local_reg_delete_arg
*cda
;
3048 nve_addr_free (void *hap
)
3050 ((struct nve_addr
*) hap
)->cda
->nve_count
+= 1;
3051 XFREE (MTYPE_RFAPI_NVE_ADDR
, hap
);
3055 nve_addr_cmp (void *k1
, void *k2
)
3057 struct nve_addr
*a
= (struct nve_addr
*) k1
;
3058 struct nve_addr
*b
= (struct nve_addr
*) k2
;
3065 if (a
->un
.addr_family
!= b
->un
.addr_family
)
3067 return (a
->un
.addr_family
- b
->un
.addr_family
);
3069 if (a
->vn
.addr_family
!= b
->vn
.addr_family
)
3071 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
3073 if (a
->un
.addr_family
== AF_INET
)
3075 ret
= IPV4_ADDR_CMP (&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
3081 else if (a
->un
.addr_family
== AF_INET6
)
3083 ret
= IPV6_ADDR_CMP (&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
3093 if (a
->vn
.addr_family
== AF_INET
)
3095 ret
= IPV4_ADDR_CMP (&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
3099 else if (a
->vn
.addr_family
== AF_INET6
)
3101 ret
= IPV6_ADDR_CMP (&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
3115 parse_deleter_args (
3117 struct cmd_token
*carg_prefix
,
3118 struct cmd_token
*carg_vn
,
3119 struct cmd_token
*carg_un
,
3120 struct cmd_token
*carg_l2addr
,
3121 struct cmd_token
*carg_vni
,
3122 struct rfapi_local_reg_delete_arg
*rcdarg
)
3124 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
3125 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
3126 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
3127 const char *arg_l2addr
= carg_l2addr
? carg_l2addr
->arg
: NULL
;
3128 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
3129 int rc
= CMD_WARNING
;
3131 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3133 if (arg_vn
&& strcmp (arg_vn
, "*"))
3135 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3138 if (arg_un
&& strcmp (arg_un
, "*"))
3140 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3143 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3146 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3148 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
, VTY_NEWLINE
);
3157 vty_out (vty
, "Missing VNI%s", VTY_NEWLINE
);
3160 if (strcmp (arg_l2addr
, "*"))
3162 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3164 vty_out (vty
, "Malformed L2 Address \"%s\"%s",
3165 arg_l2addr
, VTY_NEWLINE
);
3168 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3170 if (strcmp (arg_vni
, "*"))
3172 VTY_GET_INTEGER ("Logical Network ID",
3173 rcdarg
->l2o
.o
.logical_net_id
, arg_vni
);
3174 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3181 record_nve_in_cda_list (
3182 struct rfapi_local_reg_delete_arg
*cda
,
3183 struct rfapi_ip_addr
*un_address
,
3184 struct rfapi_ip_addr
*vn_address
,
3185 struct rfapi_descriptor
*rfd
)
3188 struct nve_addr
*hap
;
3190 memset (&ha
, 0, sizeof (ha
));
3191 ha
.un
= *un_address
;
3192 ha
.vn
= *vn_address
;
3196 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3198 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3200 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3204 skiplist_insert (cda
->nves
, hap
, hap
);
3209 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3212 struct rfapi_descriptor
*rfd
;
3213 int query_count
= 0;
3214 struct listnode
*node
;
3215 struct bgp
*bgp_default
= bgp_get_default ();
3217 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3223 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3226 rfapiRibClear (rfd
);
3227 rfapi_query_done_all (rfd
, &query_count
);
3228 cda
->query_count
+= query_count
;
3231 * Track unique nves seen
3233 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3244 h
= bgp_default
->rfapi
;
3249 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3252 * match un, vn addresses of NVEs
3254 if (cda
->un_address
.addr_family
&&
3255 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3259 if (cda
->vn_address
.addr_family
&&
3260 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3265 rfapiRibClear (rfd
);
3267 rfapi_query_done_all (rfd
, &query_count
);
3268 cda
->query_count
+= query_count
;
3271 * Track unique nves seen
3273 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3278 * TBD need to count deleted prefixes and nves?
3280 * ENXIO BGP or VNC not configured
3283 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3285 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3286 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3287 struct prefix
*pPrefix
; /* NULL = wildcard */
3290 struct listnode
*node
;
3291 struct rfapi_descriptor
*rfd
;
3292 struct rfapi_ip_prefix rprefix
;
3293 struct bgp
*bgp_default
= bgp_get_default ();
3294 struct rfapi_next_hop_entry
*head
= NULL
;
3295 struct rfapi_next_hop_entry
*tail
= NULL
;
3296 struct rfapi_cfg
*rfapi_cfg
;
3299 vnc_zlog_debug_verbose ("%s: entry", __func__
);
3305 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3306 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3307 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3309 h
= bgp_default
->rfapi
;
3310 rfapi_cfg
= bgp_default
->rfapi_cfg
;
3312 if (!h
|| !rfapi_cfg
)
3317 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3321 vnc_zlog_debug_verbose ("%s: starting descriptor loop", __func__
);
3324 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3326 struct rfapi_adb
*adb
;
3328 int deleted_from_this_nve
;
3330 struct nve_addr
*hap
;
3333 vnc_zlog_debug_verbose ("%s: rfd=%p", __func__
, rfd
);
3337 * match un, vn addresses of NVEs
3339 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3341 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3345 vnc_zlog_debug_verbose ("%s: un, vn match", __func__
);
3352 deleted_from_this_nve
= 0;
3355 struct skiplist
*sl
;
3356 struct rfapi_ip_prefix rp
;
3358 struct list
*adb_delete_list
;
3361 * The advertisements are stored in a skiplist. Withdrawing
3362 * the registration deletes the advertisement from the
3363 * skiplist, which we can't do while iterating over that
3364 * same skiplist using the current skiplist API.
3366 * Strategy: iterate over the skiplist and build another
3367 * list containing only the matching ADBs. Then delete
3368 * _everything_ in that second list (which can be done
3369 * using either skiplists or quagga linklists).
3371 adb_delete_list
= list_new ();
3374 * Advertised IP prefixes (not 0/32 or 0/128)
3376 sl
= rfd
->advertised
.ipN_by_prefix
;
3379 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3380 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3385 if (!prefix_same (pPrefix
, &adb
->prefix_ip
))
3388 vnc_zlog_debug_verbose ("%s: adb=%p, prefix doesn't match, skipping",
3394 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3397 (cda
->l2o
.o
.macaddr
.octet
,
3398 adb
->prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3401 vnc_zlog_debug_verbose ("%s: adb=%p, macaddr doesn't match, skipping",
3408 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3410 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3413 vnc_zlog_debug_verbose ("%s: adb=%p, LNI doesn't match, skipping",
3421 vnc_zlog_debug_verbose ("%s: ipN adding adb %p to delete list", __func__
,
3425 listnode_add (adb_delete_list
, adb
);
3428 struct listnode
*node
;
3430 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3433 struct rfapi_vn_option vn1
;
3434 struct rfapi_vn_option vn2
;
3435 struct rfapi_vn_option
*pVn
;
3436 int this_advertisement_prefix_count
;
3438 this_advertisement_prefix_count
= 1;
3440 rfapiQprefix2Rprefix (&adb
->prefix_ip
, &rp
);
3442 /* if mac addr present in advert, make l2o vn option */
3443 if (adb
->prefix_eth
.family
== AF_ETHERNET
)
3446 memset (&vn1
, 0, sizeof (vn1
));
3447 memset (&vn2
, 0, sizeof (vn2
));
3449 vn1
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3450 vn1
.v
.l2addr
.macaddr
= adb
->prefix_eth
.u
.prefix_eth
;
3453 * use saved RD value instead of trying to invert
3454 * complex L2-style RD computation in rfapi_register()
3456 vn2
.type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3457 vn2
.v
.internal_rd
= adb
->prd
;
3462 ++this_advertisement_prefix_count
;
3470 vnc_zlog_debug_verbose ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3473 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, pVn
, RFAPI_REGISTER_KILL
);
3476 cda
->pfx_count
+= this_advertisement_prefix_count
;
3477 cda
->reg_count
+= 1;
3478 deleted_from_this_nve
= 1;
3480 if (h
->rfp_methods
.local_cb
)
3482 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3483 &rp
, 0, 0, NULL
, &head
, &tail
);
3486 list_delete_all_node (adb_delete_list
);
3488 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3493 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3497 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3499 sl
= rfd
->advertised
.ip0_by_ether
;
3502 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3503 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3506 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3508 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3509 adb
->prefix_eth
.u
.prefix_eth
.octet
,
3516 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3518 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3524 vnc_zlog_debug_verbose ("%s: ip0 adding adb %p to delete list",
3527 listnode_add (adb_delete_list
, adb
);
3531 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3534 struct rfapi_vn_option vn
;
3536 rfapiQprefix2Rprefix (&adb
->prefix_ip
, &rp
);
3538 memset (&vn
, 0, sizeof (vn
));
3539 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3540 vn
.v
.l2addr
= adb
->l2o
;
3543 vnc_zlog_debug_verbose ("%s: ip0 killing reg from adb %p ",
3547 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3548 RFAPI_REGISTER_KILL
);
3551 cda
->pfx_count
+= 1;
3552 cda
->reg_count
+= 1;
3553 deleted_from_this_nve
= 1;
3555 if (h
->rfp_methods
.local_cb
)
3557 struct rfapi_vn_option
*vn_opt_new
;
3559 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3560 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3561 &rfd
->vn_addr
, &rp
, 0, 0,
3562 vn_opt_new
, &head
, &tail
);
3565 list_delete_all_node (adb_delete_list
);
3567 list_delete (adb_delete_list
);
3572 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3573 h
->flags
|= RFAPI_INCALLBACK
;
3574 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3575 h
->flags
&= ~RFAPI_INCALLBACK
;
3579 if (deleted_from_this_nve
)
3582 * track unique NVEs seen
3584 memset (&ha
, 0, sizeof (ha
));
3585 ha
.un
= rfd
->un_addr
;
3586 ha
.vn
= rfd
->vn_addr
;
3589 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3590 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3592 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3596 skiplist_insert (cda
->nves
, hap
, hap
);
3607 * Deletes local and remote prefixes that match
3610 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3612 struct prefix pfx_un
;
3613 struct prefix pfx_vn
;
3615 struct prefix
*pUN
= NULL
;
3616 struct prefix
*pVN
= NULL
;
3617 struct prefix
*pPrefix
= NULL
;
3620 * Delete matching remote prefixes in holddown
3622 if (cda
->vn_address
.addr_family
)
3624 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3627 if (cda
->un_address
.addr_family
)
3629 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3632 if (cda
->prefix
.family
)
3634 pPrefix
= &cda
->prefix
;
3636 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
,
3637 0, 1, &cda
->remote_active_pfx_count
,
3638 &cda
->remote_active_nve_count
,
3639 &cda
->remote_holddown_pfx_count
,
3640 &cda
->remote_holddown_nve_count
);
3643 * Now do local prefixes
3645 rfapiDeleteLocalPrefixes (cda
);
3649 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3651 struct vty
*vty
= cda
->vty
; /* for benefit of VTY_NEWLINE */
3653 /* Our special element-deleting function counts nves */
3656 skiplist_free (cda
->nves
);
3659 if (cda
->failed_pfx_count
)
3660 vty_out (vty
, "Failed to delete %d prefixes%s",
3661 cda
->failed_pfx_count
, VTY_NEWLINE
);
3663 /* left as "prefixes" even in single case for ease of machine parsing */
3665 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs%s",
3666 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
, cda
->nve_count
,
3670 * We don't currently allow deletion of active remote prefixes from
3674 vty_out (vty
, "[Holddown] Cleared %u prefixes from %u NVEs%s",
3675 cda
->remote_holddown_pfx_count
, cda
->remote_holddown_nve_count
,
3680 * Caller has already deleted registrations and queries for this/these
3681 * NVEs. Now we just have to close their descriptors.
3684 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3686 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3687 struct nve_addr
*pKey
;
3688 struct nve_addr
*pValue
;
3689 void *cursor
= NULL
;
3695 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3697 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3702 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3703 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3704 rfapi_close (pValue
->rfd
);
3709 DEFUN (clear_vnc_nve_all
,
3710 clear_vnc_nve_all_cmd
,
3713 "VNC Information\n" "Clear per NVE information\n" "For all NVEs\n")
3716 struct rfapi_local_reg_delete_arg cda
;
3719 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3724 clear_vnc_responses (&cda
);
3725 clear_vnc_prefix (&cda
);
3726 clear_vnc_nve_closer (&cda
);
3728 print_cleared_stats (&cda
);
3733 DEFUN (clear_vnc_nve_vn_un
,
3734 clear_vnc_nve_vn_un_cmd
,
3735 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3738 "Clear prefix registration infomation\n"
3739 "VN address of NVE\n"
3740 "VN IPv4 interface address\n"
3741 "VN IPv6 interface address\n"
3742 "UN address of NVE\n"
3743 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
3745 struct rfapi_local_reg_delete_arg cda
;
3749 parse_deleter_args (vty
, NULL
, argv
[4], argv
[6], NULL
, NULL
, &cda
)))
3754 clear_vnc_responses (&cda
);
3755 clear_vnc_prefix (&cda
);
3756 clear_vnc_nve_closer (&cda
);
3758 print_cleared_stats (&cda
);
3763 DEFUN (clear_vnc_nve_un_vn
,
3764 clear_vnc_nve_un_vn_cmd
,
3765 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3768 "Clear prefix registration infomation\n"
3769 "UN address of NVE\n"
3770 "UN IPv4 interface address\n"
3771 "UN IPv6 interface address\n"
3772 "VN address of NVE\n"
3773 "VN IPv4 interface address\n" "VN IPv6 interface address\n")
3775 struct rfapi_local_reg_delete_arg cda
;
3779 parse_deleter_args (vty
, NULL
, argv
[6], argv
[4], NULL
, NULL
, &cda
)))
3784 clear_vnc_responses (&cda
);
3785 clear_vnc_prefix (&cda
);
3786 clear_vnc_nve_closer (&cda
);
3788 print_cleared_stats (&cda
);
3793 DEFUN (clear_vnc_nve_vn
,
3794 clear_vnc_nve_vn_cmd
,
3795 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3798 "Clear prefix registration infomation\n"
3799 "VN address of NVE\n"
3800 "VN IPv4 interface address\n" "VN IPv6 interface address\n")
3802 struct rfapi_local_reg_delete_arg cda
;
3805 if ((rc
= parse_deleter_args (vty
, NULL
, argv
[4], NULL
, NULL
, NULL
, &cda
)))
3810 clear_vnc_responses (&cda
);
3811 clear_vnc_prefix (&cda
);
3812 clear_vnc_nve_closer (&cda
);
3814 print_cleared_stats (&cda
);
3818 DEFUN (clear_vnc_nve_un
,
3819 clear_vnc_nve_un_cmd
,
3820 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3823 "Clear prefix registration infomation\n"
3824 "UN address of NVE\n"
3825 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
3827 struct rfapi_local_reg_delete_arg cda
;
3830 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, argv
[6], NULL
, NULL
, &cda
)))
3835 clear_vnc_responses (&cda
);
3836 clear_vnc_prefix (&cda
);
3837 clear_vnc_nve_closer (&cda
);
3839 print_cleared_stats (&cda
);
3843 /*-------------------------------------------------
3845 *-------------------------------------------------*/
3848 * This function is defined in this file (rather than in rfp_registration.c)
3849 * because here we have access to all the task handles.
3851 DEFUN (clear_vnc_prefix_vn_un
,
3852 clear_vnc_prefix_vn_un_cmd
,
3853 "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>",
3856 "Clear prefix registration infomation\n"
3860 "VN address of NVE\n"
3861 "All VN addresses\n"
3862 "VN IPv4 interface address\n"
3863 "VN IPv6 interface address\n"
3864 "UN address of NVE\n"
3865 "All UN addresses\n"
3866 "UN IPv4 interface address\n"
3867 "UN IPv6 interface address\n")
3869 struct rfapi_local_reg_delete_arg cda
;
3873 parse_deleter_args (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
, &cda
)))
3876 clear_vnc_prefix (&cda
);
3877 print_cleared_stats (&cda
);
3881 DEFUN (clear_vnc_prefix_un_vn
,
3882 clear_vnc_prefix_un_vn_cmd
,
3883 "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>",
3886 "Clear prefix registration infomation\n"
3890 "UN address of NVE\n"
3891 "All UN addresses\n"
3892 "UN IPv4 interface address\n"
3893 "UN IPv6 interface address\n"
3894 "VN address of NVE\n"
3895 "All VN addresses\n"
3896 "VN IPv4 interface address\n"
3897 "VN IPv6 interface address\n")
3899 struct rfapi_local_reg_delete_arg cda
;
3903 parse_deleter_args (vty
, argv
[3], argv
[7], argv
[5], NULL
, NULL
, &cda
)))
3906 clear_vnc_prefix (&cda
);
3907 print_cleared_stats (&cda
);
3911 DEFUN (clear_vnc_prefix_un
,
3912 clear_vnc_prefix_un_cmd
,
3913 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3916 "Clear prefix registration infomation\n"
3920 "UN address of NVE\n"
3921 "All UN addresses\n"
3922 "UN IPv4 interface address\n"
3923 "UN IPv6 interface address\n")
3925 struct rfapi_local_reg_delete_arg cda
;
3929 parse_deleter_args (vty
, argv
[3], NULL
, argv
[5], NULL
, NULL
, &cda
)))
3932 clear_vnc_prefix (&cda
);
3933 print_cleared_stats (&cda
);
3937 DEFUN (clear_vnc_prefix_vn
,
3938 clear_vnc_prefix_vn_cmd
,
3939 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
3942 "Clear prefix registration infomation\n"
3946 "UN address of NVE\n"
3947 "All VN addresses\n"
3948 "VN IPv4 interface address\n"
3949 "VN IPv6 interface address\n")
3951 struct rfapi_local_reg_delete_arg cda
;
3955 parse_deleter_args (vty
, argv
[3], argv
[5], NULL
, NULL
, NULL
, &cda
)))
3958 clear_vnc_prefix (&cda
);
3959 print_cleared_stats (&cda
);
3963 DEFUN (clear_vnc_prefix_all
,
3964 clear_vnc_prefix_all_cmd
,
3965 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
3968 "Clear prefix registration infomation\n"
3974 struct rfapi_local_reg_delete_arg cda
;
3977 if ((rc
= parse_deleter_args (vty
, argv
[3], NULL
, NULL
, NULL
, NULL
, &cda
)))
3980 clear_vnc_prefix (&cda
);
3981 print_cleared_stats (&cda
);
3985 /*-------------------------------------------------
3987 *-------------------------------------------------*/
3990 * This function is defined in this file (rather than in rfp_registration.c)
3991 * because here we have access to all the task handles.
3993 DEFUN (clear_vnc_mac_vn_un
,
3994 clear_vnc_mac_vn_un_cmd
,
3995 "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>",
3998 "Clear mac registration infomation\n"
4002 "Any virtual network identifier\n"
4003 "Virtual network identifier\n"
4004 "Virtual network identifier\n"
4005 "VN address of NVE\n"
4006 "All VN addresses\n"
4007 "VN IPv4 interface address\n"
4008 "VN IPv6 interface address\n"
4009 "UN address of NVE\n"
4010 "All UN addresses\n"
4011 "UN IPv4 interface address\n"
4012 "UN IPv6 interface address\n")
4014 struct rfapi_local_reg_delete_arg cda
;
4017 /* pfx vn un L2 VNI */
4019 parse_deleter_args (vty
, NULL
, argv
[7], argv
[9], argv
[3], argv
[5],
4023 clear_vnc_prefix (&cda
);
4024 print_cleared_stats (&cda
);
4028 DEFUN (clear_vnc_mac_un_vn
,
4029 clear_vnc_mac_un_vn_cmd
,
4030 "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>",
4033 "Clear mac registration infomation\n"
4037 "Any virtual network identifier\n"
4038 "Virtual network identifier\n"
4039 "UN address of NVE\n"
4040 "All UN addresses\n"
4041 "UN IPv4 interface address\n"
4042 "UN IPv6 interface address\n"
4043 "VN address of NVE\n"
4044 "All VN addresses\n"
4045 "VN IPv4 interface address\n"
4046 "VN IPv6 interface address\n")
4048 struct rfapi_local_reg_delete_arg cda
;
4051 /* pfx vn un L2 VNI */
4053 parse_deleter_args (vty
, NULL
, argv
[9], argv
[7], argv
[3], argv
[5],
4057 clear_vnc_prefix (&cda
);
4058 print_cleared_stats (&cda
);
4062 DEFUN (clear_vnc_mac_un
,
4063 clear_vnc_mac_un_cmd
,
4064 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4067 "Clear mac registration infomation\n"
4071 "Any virtual network identifier\n"
4072 "Virtual network identifier\n"
4073 "UN address of NVE\n"
4074 "All UN addresses\n"
4075 "UN IPv4 interface address\n"
4076 "UN IPv6 interface address\n")
4078 struct rfapi_local_reg_delete_arg cda
;
4081 /* pfx vn un L2 VNI */
4083 parse_deleter_args (vty
, NULL
, NULL
, argv
[7], argv
[3], argv
[5], &cda
)))
4086 clear_vnc_prefix (&cda
);
4087 print_cleared_stats (&cda
);
4091 DEFUN (clear_vnc_mac_vn
,
4092 clear_vnc_mac_vn_cmd
,
4093 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4096 "Clear mac registration infomation\n"
4100 "Any virtual network identifier\n"
4101 "Virtual network identifier\n"
4102 "UN address of NVE\n"
4103 "All VN addresses\n"
4104 "VN IPv4 interface address\n"
4105 "VN IPv6 interface address\n")
4107 struct rfapi_local_reg_delete_arg cda
;
4110 /* pfx vn un L2 VNI */
4112 parse_deleter_args (vty
, NULL
, argv
[7], NULL
, argv
[3], argv
[5], &cda
)))
4115 clear_vnc_prefix (&cda
);
4116 print_cleared_stats (&cda
);
4120 DEFUN (clear_vnc_mac_all
,
4121 clear_vnc_mac_all_cmd
,
4122 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4125 "Clear mac registration infomation\n"
4129 "Any virtual network identifier\n"
4130 "Virtual network identifier\n"
4133 struct rfapi_local_reg_delete_arg cda
;
4136 /* pfx vn un L2 VNI */
4138 parse_deleter_args (vty
, NULL
, NULL
, NULL
, argv
[3], argv
[5], &cda
)))
4141 clear_vnc_prefix (&cda
);
4142 print_cleared_stats (&cda
);
4146 /*-------------------------------------------------
4147 * Clear VNC MAC PREFIX
4148 *-------------------------------------------------*/
4150 DEFUN (clear_vnc_mac_vn_un_prefix
,
4151 clear_vnc_mac_vn_un_prefix_cmd
,
4152 "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>",
4155 "Clear mac registration infomation\n"
4159 "Any virtual network identifier\n"
4160 "Virtual network identifier\n"
4161 "Virtual network identifier\n"
4162 "VN address of NVE\n"
4163 "All VN addresses\n"
4164 "VN IPv4 interface address\n"
4165 "VN IPv6 interface address\n"
4166 "UN address of NVE\n"
4167 "All UN addresses\n"
4168 "UN IPv4 interface address\n"
4169 "UN IPv6 interface address\n"
4170 "Clear prefix registration infomation\n"
4175 struct rfapi_local_reg_delete_arg cda
;
4178 /* pfx vn un L2 VNI */
4180 parse_deleter_args (vty
, argv
[11], argv
[7], argv
[9], argv
[3], argv
[5],
4184 clear_vnc_prefix (&cda
);
4185 print_cleared_stats (&cda
);
4189 DEFUN (clear_vnc_mac_un_vn_prefix
,
4190 clear_vnc_mac_un_vn_prefix_cmd
,
4191 "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>",
4194 "Clear mac registration infomation\n"
4198 "Any virtual network identifier\n"
4199 "Virtual network identifier\n"
4200 "UN address of NVE\n"
4201 "All UN addresses\n"
4202 "UN IPv4 interface address\n"
4203 "UN IPv6 interface address\n"
4204 "VN address of NVE\n"
4205 "All VN addresses\n"
4206 "VN IPv4 interface address\n"
4207 "VN IPv6 interface address\n")
4209 struct rfapi_local_reg_delete_arg cda
;
4212 /* pfx vn un L2 VNI */
4214 parse_deleter_args (vty
, argv
[11], argv
[9], argv
[7], argv
[3], argv
[5],
4218 clear_vnc_prefix (&cda
);
4219 print_cleared_stats (&cda
);
4223 DEFUN (clear_vnc_mac_un_prefix
,
4224 clear_vnc_mac_un_prefix_cmd
,
4225 "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>",
4228 "Clear mac registration infomation\n"
4232 "Any virtual network identifier\n"
4233 "Virtual network identifier\n"
4234 "UN address of NVE\n"
4235 "All UN addresses\n"
4236 "UN IPv4 interface address\n"
4237 "UN IPv6 interface address\n")
4239 struct rfapi_local_reg_delete_arg cda
;
4242 /* pfx vn un L2 VNI */
4244 parse_deleter_args (vty
, argv
[9], NULL
, argv
[7], argv
[3], argv
[5],
4248 clear_vnc_prefix (&cda
);
4249 print_cleared_stats (&cda
);
4253 DEFUN (clear_vnc_mac_vn_prefix
,
4254 clear_vnc_mac_vn_prefix_cmd
,
4255 "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>",
4258 "Clear mac registration infomation\n"
4262 "Any virtual network identifier\n"
4263 "Virtual network identifier\n"
4264 "UN address of NVE\n"
4265 "All VN addresses\n"
4266 "VN IPv4 interface address\n"
4267 "VN IPv6 interface address\n")
4269 struct rfapi_local_reg_delete_arg cda
;
4272 /* pfx vn un L2 VNI */
4274 parse_deleter_args (vty
, argv
[9], argv
[7], NULL
, argv
[3], argv
[5],
4278 clear_vnc_prefix (&cda
);
4279 print_cleared_stats (&cda
);
4283 DEFUN (clear_vnc_mac_all_prefix
,
4284 clear_vnc_mac_all_prefix_cmd
,
4285 "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>",
4288 "Clear mac registration infomation\n"
4292 "Any virtual network identifier\n"
4293 "Virtual network identifier\n"
4294 "UN address of NVE\n"
4295 "All VN addresses\n"
4296 "VN IPv4 interface address\n"
4297 "VN IPv6 interface address\n")
4299 struct rfapi_local_reg_delete_arg cda
;
4302 /* pfx vn un L2 VNI */
4304 parse_deleter_args (vty
, argv
[7], NULL
, NULL
, argv
[3], argv
[5], &cda
)))
4307 clear_vnc_prefix (&cda
);
4308 print_cleared_stats (&cda
);
4312 /************************************************************************
4314 ************************************************************************/
4317 /* copied from rfp_vty.c */
4319 check_and_display_is_vnc_running (struct vty
*vty
)
4321 if (!bgp_rfapi_is_vnc_configured (NULL
))
4322 return 1; /* is running */
4327 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)%s",
4330 return 0; /* not running */
4334 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4336 struct bgp
*bgp_default
= bgp_get_default ();
4338 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4340 int active_local_routes
;
4341 int active_remote_routes
;
4342 int holddown_remote_routes
;
4343 int imported_remote_routes
;
4348 h
= bgp_default
->rfapi
;
4353 /* don't show local info if not running RFP */
4354 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4360 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4361 vty_out (vty
, "%-24s ", "NVEs:");
4362 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4363 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4364 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4367 case SHOW_NVE_SUMMARY_REGISTERED
:
4369 * NB: With the introduction of L2 route support, we no
4370 * longer have a one-to-one correspondence between
4371 * locally-originated route advertisements and routes in
4372 * the import tables that have local origin. This
4373 * discrepancy arises because a single advertisement
4374 * may contain both an IP prefix and a MAC address.
4375 * Such an advertisement results in two import table
4376 * entries: one indexed by IP prefix, the other indexed
4379 * TBD: update computation and display of registration
4380 * statistics to reflect the underlying semantics.
4384 vty_out (vty
, "%-24s ", "Registrations:");
4385 vty_out (vty
, "%-8s %-8u ", "Active:",
4386 rfapiApCountAll (bgp_default
));
4387 vty_out (vty
, "%-8s %-8u ", "Failed:",
4388 h
->stat
.count_registrations_failed
);
4389 vty_out (vty
, "%-8s %-8u", "Total:",
4390 h
->stat
.count_registrations
);
4391 vty_out (vty
, "%s", VTY_NEWLINE
);
4393 vty_out (vty
, "%-24s ", "Prefixes registered:");
4394 vty_out (vty
, "%s", VTY_NEWLINE
);
4396 rfapiCountAllItRoutes (&active_local_routes
,
4397 &active_remote_routes
,
4398 &holddown_remote_routes
,
4399 &imported_remote_routes
);
4404 vty_out (vty
, " %-20s ", "Locally:");
4405 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4406 vty_out (vty
, "%s", VTY_NEWLINE
);
4410 vty_out (vty
, " %-20s ", "Remotely:");
4411 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4412 vty_out (vty
, "%s", VTY_NEWLINE
);
4413 vty_out (vty
, " %-20s ", "In Holddown:");
4414 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4415 vty_out (vty
, "%s", VTY_NEWLINE
);
4416 vty_out (vty
, " %-20s ", "Imported:");
4417 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4420 case SHOW_NVE_SUMMARY_QUERIES
:
4421 vty_out (vty
, "%-24s ", "Queries:");
4422 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4423 vty_out (vty
, "%-8s %-8u ", "Failed:",
4424 h
->stat
.count_queries_failed
);
4425 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4428 case SHOW_NVE_SUMMARY_RESPONSES
:
4429 rfapiRibShowResponsesSummary (vty
);
4434 vty_out (vty
, "%s", VTY_NEWLINE
);
4439 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4446 struct prefix
*vn_prefix
,
4447 struct prefix
*un_prefix
)
4449 //struct hash *rfds;
4450 //struct rfp_rfapi_descriptor_param param;
4452 struct bgp
*bgp_default
= bgp_get_default ();
4454 struct listnode
*node
;
4455 struct rfapi_descriptor
*rfd
;
4464 h
= bgp_default
->rfapi
;
4469 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4473 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4476 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4479 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4488 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4489 if (!prefix_match (vn_prefix
, &pfx
))
4495 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4496 if (!prefix_match (un_prefix
, &pfx
))
4500 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4501 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4505 /* print out a header */
4507 "Active Next Hops%s", VTY_NEWLINE
);
4508 vty_out (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s%s",
4511 "Regis", "Resps", "Reach", "Remove", "Age", VTY_NEWLINE
);
4516 vty_out (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s%s",
4520 rfapi_monitor_count (rfd
),
4521 rfd
->stat_count_nh_reachable
,
4522 rfd
->stat_count_nh_removal
,
4523 rfapiFormatAge (rfd
->open_time
, age
, 10), VTY_NEWLINE
);
4526 if (printed
> 0 || vn_prefix
|| un_prefix
)
4527 vty_out (vty
, "Displayed %d out of %d active NVEs%s",
4528 printed
, total
, VTY_NEWLINE
);
4533 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4538 DEFUN (vnc_show_summary
,
4539 vnc_show_summary_cmd
,
4543 "Display VNC status summary\n")
4545 if (!check_and_display_is_vnc_running (vty
))
4547 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4548 vty_out (vty
, "%s", VTY_NEWLINE
);
4549 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4550 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4551 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4552 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4556 DEFUN (vnc_show_nves
,
4561 "List known NVEs\n")
4563 rfapi_show_nves (vty
, NULL
, NULL
);
4567 DEFUN (vnc_show_nves_ptct
,
4568 vnc_show_nves_ptct_cmd
,
4569 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4573 "VN address of NVE\n"
4574 "UN address of NVE\n"
4575 "IPv4 interface address\n"
4576 "IPv6 interface address\n")
4580 if (!check_and_display_is_vnc_running (vty
))
4583 if (!str2prefix (argv
[4]->arg
, &pfx
))
4585 vty_out (vty
, "Malformed address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4588 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4590 vty_out (vty
, "Invalid address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4594 if (argv
[3]->arg
[0] == 'u')
4596 rfapi_show_nves (vty
, NULL
, &pfx
);
4600 rfapi_show_nves (vty
, &pfx
, NULL
);
4606 /* adapted from rfp_registration_cache_log() */
4608 rfapi_show_registrations (
4610 struct prefix
*restrict_to
,
4621 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4625 /* non-expiring, local */
4626 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4630 /* non-expiring, non-local */
4631 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4635 /* expiring, including local */
4636 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4640 /* non-expiring, non-local */
4641 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4645 vty_out (vty
, "%s", VTY_NEWLINE
);
4649 DEFUN (vnc_show_registrations_pfx
,
4650 vnc_show_registrations_pfx_cmd
,
4651 "show vnc registrations [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4654 "List active prefix registrations\n"
4655 "Limit output to a particular prefix or address\n"
4656 "Limit output to a particular prefix or address\n")
4659 struct prefix
*p_addr
= NULL
;
4663 if (!str2prefix (argv
[3]->arg
, &p
))
4665 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4674 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4678 DEFUN (vnc_show_registrations_some_pfx
,
4679 vnc_show_registrations_some_pfx_cmd
,
4680 "show vnc registrations <all|holddown|imported|local|remote> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4683 "List active prefix registrations\n"
4684 "show all registrations\n"
4685 "show only registrations in holddown\n"
4686 "show only imported prefixes\n"
4687 "show only local registrations\n"
4688 "show only remote registrations\n"
4689 "Limit output to a particular prefix or address\n[A"
4690 "Limit output to a particular prefix or address\n")
4693 struct prefix
*p_addr
= NULL
;
4696 int show_remote
= 0;
4697 int show_holddown
= 0;
4698 int show_imported
= 0;
4702 if (!str2prefix (argv
[4]->arg
, &p
))
4704 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4712 switch (argv
[3]->arg
[0])
4738 rfapi_show_registrations (vty
, p_addr
,
4739 show_local
, show_remote
, show_holddown
,
4744 DEFUN (vnc_show_responses_pfx
,
4745 vnc_show_responses_pfx_cmd
,
4746 "show vnc responses [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4749 "List recent query responses\n"
4750 "Limit output to a particular prefix or address\n"
4751 "Limit output to a particular prefix or address\n")
4754 struct prefix
*p_addr
= NULL
;
4758 if (!str2prefix (argv
[3]->arg
, &p
))
4760 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4768 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4770 rfapiRibShowResponsesSummary (vty
);
4772 rfapiRibShowResponses (vty
, p_addr
, 0);
4773 rfapiRibShowResponses (vty
, p_addr
, 1);
4778 DEFUN (vnc_show_responses_some_pfx
,
4779 vnc_show_responses_some_pfx_cmd
,
4780 "show vnc responses <active|removed> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4783 "List recent query responses\n"
4784 "show only active query responses\n"
4785 "show only removed query responses\n"
4786 "Limit output to a particular prefix or address\n"
4787 "Limit output to a particular prefix or address\n")
4790 struct prefix
*p_addr
= NULL
;
4792 int show_active
= 0;
4793 int show_removed
= 0;
4795 if (!check_and_display_is_vnc_running (vty
))
4800 if (!str2prefix (argv
[4]->arg
, &p
))
4802 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4811 switch (argv
[3]->arg
[0])
4822 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4824 rfapiRibShowResponsesSummary (vty
);
4827 rfapiRibShowResponses (vty
, p_addr
, 0);
4829 rfapiRibShowResponses (vty
, p_addr
, 1);
4834 DEFUN (show_vnc_queries_pfx
,
4835 show_vnc_queries_pfx_cmd
,
4836 "show vnc queries [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4839 "List active queries\n"
4840 "Limit output to a particular IPv4 prefix or address\n"
4841 "Limit output to a particular IPv6 prefix or address\n")
4844 struct prefix
*p
= NULL
;
4848 if (!str2prefix (argv
[3]->arg
, &pfx
))
4850 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4856 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4858 return rfapiShowVncQueries (vty
, p
);
4861 DEFUN (vnc_clear_counters
,
4862 vnc_clear_counters_cmd
,
4863 "clear vnc counters",
4866 "Reset VNC counters\n")
4868 struct bgp
*bgp_default
= bgp_get_default ();
4870 struct listnode
*node
;
4871 struct rfapi_descriptor
*rfd
;
4876 h
= bgp_default
->rfapi
;
4882 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4884 rfd
->stat_count_nh_reachable
= 0;
4885 rfd
->stat_count_nh_removal
= 0;
4889 memset (&h
->stat
, 0, sizeof (h
->stat
));
4892 * 151122 per bug 103, set count_registrations = number active.
4893 * Do same for queries
4895 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4896 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4898 rfapiRibShowResponsesSummaryClear ();
4903 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4907 void rfapi_vty_init ()
4909 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
4910 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
4911 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
4912 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
4913 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
4915 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
4916 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
4917 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
4918 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
4919 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
4921 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
4922 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
4923 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
4924 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
4925 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
4926 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
4927 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
4928 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
4930 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
4931 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
4932 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
4933 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
4934 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
4936 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
4937 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
4938 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
4939 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
4940 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
4942 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
4943 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
4944 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
4945 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
4946 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
4948 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
4949 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
4950 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
4951 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
4952 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
4954 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
4956 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
4957 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
4958 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
4960 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
4961 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
4962 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
4963 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
4964 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);