3 * Copyright 2009-2016, LabN Consulting, L.L.C.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "lib/zebra.h"
25 #include "lib/prefix.h"
26 #include "lib/table.h"
28 #include "lib/memory.h"
29 #include "lib/routemap.h"
31 #include "lib/log_int.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_route.h"
39 #include "bgpd/bgp_mplsvpn.h"
41 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
42 #include "bgpd/rfapi/rfapi.h"
43 #include "bgpd/rfapi/rfapi_backend.h"
45 #include "bgpd/bgp_route.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_community.h"
48 #include "bgpd/bgp_vnc_types.h"
50 #include "bgpd/rfapi/rfapi_import.h"
51 #include "bgpd/rfapi/rfapi_private.h"
52 #include "bgpd/rfapi/rfapi_monitor.h"
53 #include "bgpd/rfapi/rfapi_rib.h"
54 #include "bgpd/rfapi/rfapi_vty.h"
55 #include "bgpd/rfapi/rfapi_ap.h"
56 #include "bgpd/rfapi/rfapi_encap_tlv.h"
57 #include "bgpd/rfapi/vnc_debug.h"
59 #define DEBUG_L2_EXTRA 0
60 #define DEBUG_SHOW_EXTRA 0
62 #define VNC_SHOW_STR "VNC information\n"
64 /* format related utilies */
67 #define FMT_MIN 60 /* seconds */
68 #define FMT_HOUR (60 * FMT_MIN)
69 #define FMT_DAY (24 * FMT_HOUR)
70 #define FMT_YEAR (365 * FMT_DAY)
73 rfapiFormatSeconds (uint32_t seconds
, char *buf
, size_t len
)
75 int year
, day
, hour
, min
;
77 if (seconds
>= FMT_YEAR
)
79 year
= seconds
/ FMT_YEAR
;
80 seconds
-= year
* FMT_YEAR
;
85 if (seconds
>= FMT_DAY
)
87 day
= seconds
/ FMT_DAY
;
88 seconds
-= day
* FMT_DAY
;
93 if (seconds
>= FMT_HOUR
)
95 hour
= seconds
/ FMT_HOUR
;
96 seconds
-= hour
* FMT_HOUR
;
101 if (seconds
>= FMT_MIN
)
103 min
= seconds
/ FMT_MIN
;
104 seconds
-= min
* FMT_MIN
;
111 snprintf (buf
, len
, "%dy%dd%dh", year
, day
, hour
);
115 snprintf (buf
, len
, "%dd%dh%dm", day
, hour
, min
);
119 snprintf (buf
, len
, "%02d:%02d:%02d", hour
, min
, seconds
);
126 rfapiFormatAge (time_t age
, char *buf
, size_t len
)
128 time_t now
, age_adjusted
;
130 now
= rfapi_time (NULL
);
131 age_adjusted
= now
- age
;
133 return rfapiFormatSeconds (age_adjusted
, buf
, len
);
138 * Reimplementation of quagga/lib/prefix.c function, but
139 * for RFAPI-style prefixes
142 rfapiRprefixApplyMask (struct rfapi_ip_prefix
*rprefix
)
148 static uint8_t maskbit
[] =
149 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
151 switch (rprefix
->prefix
.addr_family
)
154 index
= rprefix
->length
/ 8;
157 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v4
;
158 offset
= rprefix
->length
% 8;
159 pnt
[index
] &= maskbit
[offset
];
167 index
= rprefix
->length
/ 8;
170 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v6
;
171 offset
= rprefix
->length
% 8;
172 pnt
[index
] &= maskbit
[offset
];
185 * translate a quagga prefix into a rfapi IP address. The
186 * prefix is REQUIRED to be 32 bits for IPv4 and 128 bits for IPv6
194 rfapiQprefix2Raddr (struct prefix
*qprefix
, struct rfapi_ip_addr
*raddr
)
196 memset (raddr
, 0, sizeof (struct rfapi_ip_addr
));
197 raddr
->addr_family
= qprefix
->family
;
198 switch (qprefix
->family
)
201 if (qprefix
->prefixlen
!= 32)
203 raddr
->addr
.v4
= qprefix
->u
.prefix4
;
206 if (qprefix
->prefixlen
!= 128)
208 raddr
->addr
.v6
= qprefix
->u
.prefix6
;
217 * Translate Quagga prefix to RFAPI prefix
219 /* rprefix->cost set to 0 */
221 rfapiQprefix2Rprefix (struct prefix
*qprefix
, struct rfapi_ip_prefix
*rprefix
)
223 memset (rprefix
, 0, sizeof (struct rfapi_ip_prefix
));
224 rprefix
->length
= qprefix
->prefixlen
;
225 rprefix
->prefix
.addr_family
= qprefix
->family
;
226 switch (qprefix
->family
)
229 rprefix
->prefix
.addr
.v4
= qprefix
->u
.prefix4
;
232 rprefix
->prefix
.addr
.v6
= qprefix
->u
.prefix6
;
240 rfapiRprefix2Qprefix (struct rfapi_ip_prefix
*rprefix
, struct prefix
*qprefix
)
242 memset (qprefix
, 0, sizeof (struct prefix
));
243 qprefix
->prefixlen
= rprefix
->length
;
244 qprefix
->family
= rprefix
->prefix
.addr_family
;
246 switch (rprefix
->prefix
.addr_family
)
249 qprefix
->u
.prefix4
= rprefix
->prefix
.addr
.v4
;
252 qprefix
->u
.prefix6
= rprefix
->prefix
.addr
.v6
;
261 * returns 1 if prefixes have same addr family, prefix len, and address
262 * Note that host bits matter in this comparison!
264 * For paralellism with quagga/lib/prefix.c. if we need a comparison
265 * where host bits are ignored, call that function rfapiRprefixCmp.
268 rfapiRprefixSame (struct rfapi_ip_prefix
*hp1
, struct rfapi_ip_prefix
*hp2
)
270 if (hp1
->prefix
.addr_family
!= hp2
->prefix
.addr_family
)
272 if (hp1
->length
!= hp2
->length
)
274 if (hp1
->prefix
.addr_family
== AF_INET
)
275 if (IPV4_ADDR_SAME (&hp1
->prefix
.addr
.v4
, &hp2
->prefix
.addr
.v4
))
277 if (hp1
->prefix
.addr_family
== AF_INET6
)
278 if (IPV6_ADDR_SAME (&hp1
->prefix
.addr
.v6
, &hp2
->prefix
.addr
.v6
))
284 rfapiRaddr2Qprefix (struct rfapi_ip_addr
*hia
, struct prefix
*pfx
)
286 memset (pfx
, 0, sizeof (struct prefix
));
287 pfx
->family
= hia
->addr_family
;
289 switch (hia
->addr_family
)
293 pfx
->u
.prefix4
= hia
->addr
.v4
;
296 pfx
->prefixlen
= 128;
297 pfx
->u
.prefix6
= hia
->addr
.v6
;
306 rfapiL2o2Qprefix (struct rfapi_l2address_option
*l2o
, struct prefix
*pfx
)
308 memset (pfx
, 0, sizeof (struct prefix
));
309 pfx
->family
= AF_ETHERNET
;
311 pfx
->u
.prefix_eth
= l2o
->macaddr
;
315 rfapiEthAddr2Str (const struct ethaddr
*ea
, char *buf
, int bufsize
)
317 return prefix_mac2str (ea
, buf
, bufsize
);
321 rfapiStr2EthAddr (const char *str
, struct ethaddr
*ea
)
326 if (sscanf (str
, "%2x:%2x:%2x:%2x:%2x:%2x",
327 a
+ 0, a
+ 1, a
+ 2, a
+ 3, a
+ 4, a
+ 5) != 6)
333 for (i
= 0; i
< 6; ++i
)
334 ea
->octet
[i
] = a
[i
] & 0xff;
340 rfapi_ntop (int af
, const void *src
, char *buf
, socklen_t size
)
342 if (af
== AF_ETHERNET
)
344 return rfapiEthAddr2Str ((const struct ethaddr
*) src
, buf
, size
);
347 return inet_ntop (af
, src
, buf
, size
);
351 rfapiDebugPrintf (void *dummy
, const char *format
, ...)
354 va_start (args
, format
);
355 vzlog (LOG_DEBUG
, format
, args
);
361 rfapiStdioPrintf (void *stream
, const char *format
, ...)
366 va_start (args
, format
);
368 switch ((uintptr_t) stream
)
380 vfprintf (file
, format
, args
);
385 /* Fake out for debug logging */
386 static struct vty vty_dummy_zlog
;
387 static struct vty vty_dummy_stdio
;
388 #define HVTYNL ((vty == &vty_dummy_zlog)? "": VTYNL)
391 str_vty_newline (struct vty
*vty
)
393 if (vty
== &vty_dummy_zlog
)
400 void *stream
, /* input */
401 int (**fp
) (void *, const char *, ...), /* output */
402 struct vty
**vty
, /* output */
403 void **outstream
, /* output */
404 const char **vty_newline
) /* output */
409 vty_dummy_zlog
.type
= VTY_SHELL
; /* for VTYNL */
410 *vty
= &vty_dummy_zlog
;
411 *fp
= (int (*)(void *, const char *,...)) rfapiDebugPrintf
;
413 *vty_newline
= str_vty_newline (*vty
);
414 return (vzlog_test (LOG_DEBUG
));
417 if (((uintptr_t) stream
== (uintptr_t) 1) ||
418 ((uintptr_t) stream
== (uintptr_t) 2))
421 vty_dummy_stdio
.type
= VTY_SHELL
; /* for VTYNL */
422 *vty
= &vty_dummy_stdio
;
423 *fp
= (int (*)(void *, const char *,...)) rfapiStdioPrintf
;
425 *vty_newline
= str_vty_newline (*vty
);
431 *vty
= stream
; /* VTYNL requires vty to be legit */
432 *fp
= (int (*)(void *, const char *,...)) vty_out
;
434 *vty_newline
= str_vty_newline (*vty
);
441 /* called from bgpd/bgp_vty.c'route_vty_out() */
443 rfapi_vty_out_vncinfo (
453 * Print, on an indented line:
454 * UN address [if VPN route and VNC UN addr subtlv]
460 if (safi
== SAFI_MPLS_VPN
)
462 struct prefix pfx_un
;
464 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
467 vty_out (vty
, "UN=%s", inet_ntop (pfx_un
.family
,
468 pfx_un
.u
.val
, buf
, BUFSIZ
));
472 if (bi
->attr
&& bi
->attr
->ecommunity
)
474 s
= ecommunity_ecom2str (bi
->attr
->ecommunity
,
475 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
476 vty_out (vty
, " EC{%s}", s
);
477 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
480 if (bi
->extra
!= NULL
)
481 vty_out (vty
, " label=%u", decode_label (&bi
->extra
->label
));
483 if (!rfapiGetVncLifetime (bi
->attr
, &lifetime
))
485 vty_out (vty
, " life=%d", lifetime
);
488 vty_out (vty
, " type=%s, subtype=%d",
489 zebra_route_string (bi
->type
), bi
->sub_type
);
491 vty_out (vty
, "%s", HVTYNL
);
495 rfapiPrintAttrPtrs (void *stream
, struct attr
*attr
)
497 int (*fp
) (void *, const char *, ...);
500 const char *vty_newline
;
504 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
507 fp (out
, "Attr[%p]:%s", attr
, HVTYNL
);
512 inet_ntop (AF_INET
, &attr
->nexthop
, buf
, BUFSIZ
);
513 fp (out
, " nexthop=%s%s", buf
, HVTYNL
);
515 fp (out
, " aspath=%p, refcnt=%d%s", attr
->aspath
,
516 (attr
->aspath
? attr
->aspath
->refcnt
: 0), HVTYNL
);
517 fp (out
, " community=%p, refcnt=%d%s", attr
->community
,
518 (attr
->community
? attr
->community
->refcnt
: 0), HVTYNL
);
520 fp (out
, " ecommunity=%p, refcnt=%d%s", attr
->ecommunity
,
521 (attr
->ecommunity
? attr
->ecommunity
->refcnt
: 0), HVTYNL
);
522 fp (out
, " cluster=%p, refcnt=%d%s", attr
->cluster
,
523 (attr
->cluster
? attr
->cluster
->refcnt
: 0), HVTYNL
);
524 fp (out
, " transit=%p, refcnt=%d%s", attr
->transit
,
525 (attr
->transit
? attr
->transit
->refcnt
: 0), HVTYNL
);
529 * Print BI in an Import Table
532 rfapiPrintBi (void *stream
, struct bgp_info
*bi
)
537 int (*fp
) (void *, const char *, ...);
540 const char *vty_newline
;
546 struct ethaddr macaddr
;
547 struct rfapi_l2address_option l2o_buf
;
548 uint8_t l2hid
=0; /* valid if has_macaddr */
550 #define REMAIN (BUFSIZ - (p-line))
551 #define INCP {p += (r > REMAIN)? REMAIN: r;}
553 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
559 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) && bi
->extra
560 && bi
->extra
->vnc
.import
.timer
)
562 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
563 r
= snprintf (p
, REMAIN
, " [%4lu] ", thread_timer_remain_second (t
));
569 r
= snprintf (p
, REMAIN
, " ");
575 /* TBD This valid only for SAFI_MPLS_VPN, but not for encap */
576 if (decode_rd_type(bi
->extra
->vnc
.import
.rd
.val
) == RD_TYPE_VNC_ETH
)
579 memcpy (macaddr
.octet
, bi
->extra
->vnc
.import
.rd
.val
+ 2, 6);
580 l2hid
= bi
->extra
->vnc
.import
.rd
.val
[1];
589 * RFP option sizes (they are opaque values)
590 * extended communities (RTs)
595 int printed_1st_gol
= 0;
596 struct bgp_attr_encap_subtlv
*pEncap
;
597 struct prefix pfx_un
;
598 int af
= BGP_MP_NEXTHOP_FAMILY (bi
->attr
->mp_nexthop_len
);
603 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET
,
604 &bi
->attr
->mp_nexthop_global_in
,
608 else if (af
== AF_INET6
)
610 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET6
,
611 &bi
->attr
->mp_nexthop_global
,
617 r
= snprintf (p
, REMAIN
, "?");
622 * VNC tunnel subtlv, if present, contains UN address
624 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
626 r
= snprintf (p
, REMAIN
, " un=%s", inet_ntop (pfx_un
.family
,
634 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
))
636 r
= snprintf (p
, REMAIN
, " nolife");
641 if (lifetime
== 0xffffffff)
642 r
= snprintf (p
, REMAIN
, " %6s", "infini");
644 r
= snprintf (p
, REMAIN
, " %6u", lifetime
);
648 /* RFP option lengths */
649 for (pEncap
= bi
->attr
->vnc_subtlvs
; pEncap
;
650 pEncap
= pEncap
->next
)
653 if (pEncap
->type
== BGP_VNC_SUBTLV_TYPE_RFPOPTION
)
657 r
= snprintf (p
, REMAIN
, ",");
662 r
= snprintf (p
, REMAIN
, " "); /* leading space */
665 r
= snprintf (p
, REMAIN
, "%d", pEncap
->length
);
672 if (bi
->attr
->ecommunity
)
674 s
= ecommunity_ecom2str (bi
->attr
->ecommunity
,
675 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
676 r
= snprintf (p
, REMAIN
, " %s", s
);
678 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
683 r
= snprintf (p
, REMAIN
, " bi@%p", bi
);
686 r
= snprintf (p
, REMAIN
, " p@%p", bi
->peer
);
689 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
691 r
= snprintf (p
, REMAIN
, " HD=yes");
696 r
= snprintf (p
, REMAIN
, " HD=no");
703 if (bi
->attr
->weight
)
705 r
= snprintf (p
, REMAIN
, " W=%d", bi
->attr
->weight
);
709 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
711 r
= snprintf (p
, REMAIN
, " LP=%d", bi
->attr
->local_pref
);
716 r
= snprintf (p
, REMAIN
, " LP=unset");
722 snprintf (p
, REMAIN
, " %c:%u", zebra_route_char (bi
->type
), bi
->sub_type
);
725 fp (out
, "%s%s", line
, HVTYNL
);
729 fp (out
, " RD HID=%d ETH=%02x:%02x:%02x:%02x:%02x:%02x%s",
734 macaddr
.octet
[3], macaddr
.octet
[4], macaddr
.octet
[5], HVTYNL
);
737 if (!rfapiGetL2o (bi
->attr
, &l2o_buf
))
740 " L2O ETH=%02x:%02x:%02x:%02x:%02x:%02x LBL=%d LNI=%d LHI=%hhu%s",
741 l2o_buf
.macaddr
.octet
[0], l2o_buf
.macaddr
.octet
[1],
742 l2o_buf
.macaddr
.octet
[2], l2o_buf
.macaddr
.octet
[3],
743 l2o_buf
.macaddr
.octet
[4], l2o_buf
.macaddr
.octet
[5], l2o_buf
.label
,
744 l2o_buf
.logical_net_id
, l2o_buf
.local_nve_id
, HVTYNL
);
746 if (bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
751 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
752 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
757 fp (out
, " IP: %s%s", sp
, HVTYNL
);
761 struct rfapi_un_option
*uo
= rfapi_encap_tlv_to_un_option (bi
->attr
);
764 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
765 rfapi_un_options_free (uo
);
771 rfapiMonitorVpn2Str (struct rfapi_monitor_vpn
*m
, char *buf
, int size
)
773 char buf_pfx
[BUFSIZ
];
778 rfapiRfapiIpAddr2Str (&m
->rfd
->un_addr
, buf_vn
, BUFSIZ
);
779 rfapiRfapiIpAddr2Str (&m
->rfd
->vn_addr
, buf_un
, BUFSIZ
);
781 rc
= snprintf (buf
, size
,
782 "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p",
783 m
, m
->next
, m
->rfd
, buf_vn
, buf_un
,
784 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
785 m
->p
.prefixlen
, m
->node
);
793 rfapiDebugPrintMonitorVpn (void *stream
, struct rfapi_monitor_vpn
*m
)
797 int (*fp
) (void *, const char *, ...);
800 const char *vty_newline
;
802 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
805 rfapiMonitorVpn2Str (m
, buf
, BUFSIZ
);
806 fp (out
, " Mon %s%s", buf
, HVTYNL
);
810 rfapiDebugPrintMonitorEncap (void *stream
, struct rfapi_monitor_encap
*m
)
812 int (*fp
) (void *, const char *, ...);
815 const char *vty_newline
;
817 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
820 fp (out
, " Mon m=%p, next=%p, node=%p, bi=%p%s",
821 m
, m
->next
, m
->node
, m
->bi
, HVTYNL
);
825 rfapiShowItNode (void *stream
, struct route_node
*rn
)
830 int (*fp
) (void *, const char *, ...);
833 const char *vty_newline
;
835 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
838 fp (out
, "%s/%d @%p #%d%s",
839 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
840 rn
->p
.prefixlen
, rn
, rn
->lock
, HVTYNL
);
842 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
844 rfapiPrintBi (stream
, bi
);
847 /* doesn't show montors */
851 rfapiShowImportTable (
854 struct route_table
*rt
,
857 struct route_node
*rn
;
860 int (*fp
) (void *, const char *, ...);
863 const char *vty_newline
;
865 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
868 fp (out
, "Import Table [%s]%s", label
, HVTYNL
);
870 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
874 if (rn
->p
.family
== AF_ETHERNET
)
876 rfapiEthAddr2Str (&rn
->p
.u
.prefix_eth
, buf
, BUFSIZ
);
880 inet_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
);
883 fp (out
, "%s/%d @%p #%d%s", buf
, rn
->p
.prefixlen
, rn
, rn
->lock
- 1, /* account for loop iterator locking */
886 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
888 rfapiPrintBi (stream
, bi
);
893 struct rfapi_monitor_vpn
*m
;
894 for (m
= RFAPI_MONITOR_VPN (rn
); m
; m
= m
->next
)
896 rfapiDebugPrintMonitorVpn (stream
, m
);
901 struct rfapi_monitor_encap
*m
;
902 for (m
= RFAPI_MONITOR_ENCAP (rn
); m
; m
= m
->next
)
904 rfapiDebugPrintMonitorEncap (stream
, m
);
911 rfapiShowVncQueries (void *stream
, struct prefix
*pfx_match
)
915 struct listnode
*node
;
916 struct rfapi_descriptor
*rfd
;
918 int (*fp
) (void *, const char *, ...);
921 const char *vty_newline
;
923 int printedheader
= 0;
926 int nves_with_queries
= 0;
927 int nves_displayed
= 0;
929 int queries_total
= 0;
930 int queries_displayed
= 0;
932 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
935 bgp
= bgp_get_default (); /* assume 1 instance for now */
938 vty_outln (vty
, "No BGP instance");
945 vty_outln (vty
, "No RFAPI instance");
949 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
952 struct route_node
*rn
;
953 int printedquerier
= 0;
958 if (rfd
->mon
|| (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
)))
972 for (rn
= route_top (rfd
->mon
); rn
; rn
= route_next (rn
))
974 struct rfapi_monitor_vpn
*m
;
975 char buf_remain
[BUFSIZ
];
976 char buf_pfx
[BUFSIZ
];
985 if (pfx_match
&& !prefix_match (pfx_match
, &rn
->p
) &&
986 !prefix_match (&rn
->p
, pfx_match
))
994 fp (out
, "%s", VTYNL
);
995 fp (out
, "%-15s %-15s %-15s %-10s%s",
996 "VN Address", "UN Address",
997 "Target", "Remaining", VTYNL
);
1000 if (!printedquerier
)
1002 char buf_vn
[BUFSIZ
];
1003 char buf_un
[BUFSIZ
];
1005 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1006 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1008 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1014 fp (out
, "%-15s %-15s", "", "");
1018 rfapiFormatSeconds (thread_timer_remain_second (m
->timer
),
1019 buf_remain
, BUFSIZ
);
1021 fp (out
, " %-15s %-10s%s",
1022 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
1030 if (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
))
1035 struct rfapi_monitor_eth
*mon_eth
;
1039 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1042 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1046 char buf_remain
[BUFSIZ
];
1047 char buf_pfx
[BUFSIZ
];
1048 struct prefix pfx_mac
;
1052 vnc_zlog_debug_verbose ("%s: checking rfd=%p mon_eth=%p", __func__
, rfd
,
1055 memset ((void *) &pfx_mac
, 0, sizeof (struct prefix
));
1056 pfx_mac
.family
= AF_ETHERNET
;
1057 pfx_mac
.prefixlen
= 48;
1058 pfx_mac
.u
.prefix_eth
= mon_eth
->macaddr
;
1060 if (pfx_match
&& !prefix_match (pfx_match
, &pfx_mac
) &&
1061 !prefix_match (&pfx_mac
, pfx_match
))
1064 ++queries_displayed
;
1069 fp (out
, "%s", VTYNL
);
1070 fp (out
, "%-15s %-15s %-17s %10s %-10s%s",
1071 "VN Address", "UN Address",
1072 "Target", "LNI", "Remaining", VTYNL
);
1075 if (!printedquerier
)
1077 char buf_vn
[BUFSIZ
];
1078 char buf_un
[BUFSIZ
];
1080 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1081 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1083 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1089 fp (out
, "%-15s %-15s", "", "");
1093 rfapiFormatSeconds (thread_timer_remain_second
1094 (mon_eth
->timer
), buf_remain
, BUFSIZ
);
1096 fp (out
, " %-17s %10d %-10s%s",
1097 rfapi_ntop (pfx_mac
.family
, &pfx_mac
.u
.prefix
, buf_pfx
,
1098 BUFSIZ
), mon_eth
->logical_net_id
, buf_remain
,
1106 fp (out
, "%s", VTYNL
);
1107 fp (out
, "Displayed %d out of %d total queries%s",
1108 queries_displayed
, queries_total
, VTYNL
);
1114 rfapiPrintRemoteRegBi (
1117 struct route_node
*rn
,
1118 struct bgp_info
*bi
)
1120 int (*fp
) (void *, const char *, ...);
1123 const char *vty_newline
;
1124 struct prefix pfx_un
;
1125 struct prefix pfx_vn
;
1128 bgp_encap_types tun_type
;
1130 char buf_pfx
[BUFSIZ
];
1131 char buf_ntop
[BUFSIZ
];
1132 char buf_un
[BUFSIZ
];
1133 char buf_vn
[BUFSIZ
];
1134 char buf_lifetime
[BUFSIZ
];
1138 return 0; /* for debug log, print into buf & call output once */
1140 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1147 snprintf (buf_pfx
, BUFSIZ
, "%s/%d",
1148 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf_ntop
, BUFSIZ
),
1150 buf_pfx
[BUFSIZ
- 1] = 0;
1157 if (!rfapiGetUnAddrOfVpnBi (bi
, &pfx_un
))
1159 snprintf (buf_un
, BUFSIZ
, "%s",
1160 inet_ntop (pfx_un
.family
, &pfx_un
.u
.prefix
, buf_ntop
,
1164 rfapiGetTunnelType(bi
->attr
,&tun_type
);
1169 rfapiNexthop2Prefix (bi
->attr
, &pfx_vn
);
1170 if (tun_type
== BGP_ENCAP_TYPE_MPLS
)
1172 /* MPLS carries un in nrli next hop (same as vn for IP tunnels) */
1173 snprintf (buf_un
, BUFSIZ
, "%s",
1174 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1177 u_int32_t l
= decode_label (&bi
->extra
->label
);
1178 snprintf (buf_vn
, BUFSIZ
, "Label: %d", l
);
1180 else /* should never happen */
1182 snprintf (buf_vn
, BUFSIZ
, "Label: N/A");
1187 snprintf (buf_vn
, BUFSIZ
, "%s",
1188 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1190 buf_vn
[BUFSIZ
- 1] = 0;
1191 buf_un
[BUFSIZ
- 1] = 0;
1194 * Cost is encoded in local_pref as (255-cost)
1195 * See rfapi_import.c'rfapiRouteInfo2NextHopEntry() for conversion
1200 uint32_t local_pref
;
1201 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1202 local_pref
= bi
->attr
->local_pref
;
1205 cost
= (local_pref
> 255) ? 0 : 255 - local_pref
;
1212 fp (out
, "%-20s ", buf_pfx
);
1213 fp (out
, "%-15s ", buf_vn
);
1214 fp (out
, "%-15s ", buf_un
);
1215 fp (out
, "%-4d ", cost
);
1218 /* NB rfapiGetVncLifetime sets infinite value when returning !0 */
1219 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
) ||
1220 (lifetime
== RFAPI_INFINITE_LIFETIME
))
1223 fp (out
, "%-10s ", "infinite");
1227 time_t t_lifetime
= lifetime
;
1228 rfapiFormatSeconds (t_lifetime
, buf_lifetime
, BUFSIZ
);
1229 fp (out
, "%-10s ", buf_lifetime
);
1232 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) &&
1233 bi
->extra
&& bi
->extra
->vnc
.import
.timer
)
1238 char buf_age
[BUFSIZ
];
1240 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
1241 remaining
= thread_timer_remain_second (t
);
1243 #if RFAPI_REGISTRATIONS_REPORT_AGE
1245 * Calculate when the timer started. Doing so here saves
1246 * us a timestamp field in "struct bgp_info".
1248 * See rfapi_import.c'rfapiBiStartWithdrawTimer() for the
1249 * original calculation.
1251 age
= rfapiGetHolddownFromLifetime (lifetime
, factor
) - remaining
;
1252 #else /* report remaining time */
1255 rfapiFormatSeconds (age
, buf_age
, BUFSIZ
);
1257 fp (out
, "%-10s ", buf_age
);
1260 else if (RFAPI_LOCAL_BI (bi
))
1263 char buf_age
[BUFSIZ
];
1265 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.create_time
)
1267 rfapiFormatAge (bi
->extra
->vnc
.import
.create_time
, buf_age
, BUFSIZ
);
1274 fp (out
, "%-10s ", buf_age
);
1276 fp (out
, "%s", HVTYNL
);
1278 if (rn
->p
.family
== AF_ETHERNET
)
1281 * If there is a corresponding IP address && != VN address,
1282 * print that on the next line
1285 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
1289 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
1290 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
1292 buf_ntop
[BUFSIZ
- 1] = 0;
1294 if (sp
&& strcmp (buf_vn
, sp
) != 0)
1296 fp (out
, " IP: %s", sp
);
1302 if (tun_type
!= BGP_ENCAP_TYPE_MPLS
&& bi
->extra
)
1304 u_int32_t l
= decode_label (&bi
->extra
->label
);
1305 if (!MPLS_LABEL_IS_NULL (l
))
1307 fp (out
, " Label: %d", l
);
1313 fp (out
, "%s", HVTYNL
);
1319 rfapiShowRemoteRegistrationsIt (
1322 struct rfapi_import_table
*it
,
1323 struct prefix
*prefix_only
,
1324 int show_expiring
, /* either/or */
1327 int show_imported
, /* either/or */
1328 uint32_t *pLni
) /* AFI_L2VPN only */
1331 int printed_rtlist_hdr
= 0;
1333 int (*fp
) (void *, const char *, ...);
1336 const char *vty_newline
;
1340 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1343 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1346 struct route_node
*rn
;
1348 if (!it
->imported_vpn
[afi
])
1351 for (rn
= route_top (it
->imported_vpn
[afi
]); rn
; rn
= route_next (rn
))
1354 struct bgp_info
*bi
;
1357 /* allow for wider or more narrow mask from user */
1359 !prefix_match (prefix_only
, &rn
->p
) &&
1360 !prefix_match (&rn
->p
, prefix_only
))
1365 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
1368 if (!show_local
&& RFAPI_LOCAL_BI (bi
))
1371 /* local route from RFP */
1375 if (!show_remote
&& !RFAPI_LOCAL_BI (bi
))
1382 if (show_expiring
&& !CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1385 if (!show_expiring
&& CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1388 if (bi
->type
== ZEBRA_ROUTE_BGP_DIRECT
||
1389 bi
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
)
1401 if (count_only
== 1)
1403 if (!printed_rtlist_hdr
)
1405 const char *agetype
= "";
1407 const char *type
= "";
1420 if (RFAPI_LOCAL_BI (bi
))
1431 s
= ecommunity_ecom2str (it
->rt_import_list
,
1432 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1436 fp (out
, "%s[%s] L2VPN Network 0x%x (%u) RT={%s}",
1437 HVTYNL
, type
, *pLni
, (*pLni
& 0xfff), s
);
1441 fp (out
, "%s[%s] Prefix RT={%s}",
1444 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1446 if (it
->rfg
&& it
->rfg
->name
)
1448 fp (out
, " %s \"%s\"",
1449 (it
->rfg
->type
== RFAPI_GROUP_CFG_VRF
?
1450 "VRF" : "NVE group"),
1453 fp (out
, "%s", HVTYNL
);
1456 #if RFAPI_REGISTRATIONS_REPORT_AGE
1459 agetype
= "Remaining";
1462 else if (show_local
)
1467 printed_rtlist_hdr
= 1;
1469 fp (out
, "%-20s %-15s %-15s %4s %-10s %-10s%s",
1470 (pLni
? "L2 Address/IP" : "Prefix"),
1471 "VN Address", "UN Address", "Cost",
1472 "Lifetime", agetype
, HVTYNL
);
1474 printed
+= rfapiPrintRemoteRegBi (bgp
, stream
, rn
, bi
);
1482 const char *type
= "prefixes";
1486 type
= "imported prefixes";
1492 type
= "prefixes in holddown";
1496 if (show_local
&& !show_remote
)
1498 type
= "locally registered prefixes";
1500 else if (!show_local
&& show_remote
)
1502 type
= "remotely registered prefixes";
1507 fp (out
, "Displayed %d out of %d %s%s",
1508 printed
, total
, type
, HVTYNL
);
1509 #if DEBUG_SHOW_EXTRA
1510 fp(out
, "IT table above: it=%p%s", it
, HVTYNL
);
1519 * rfapiShowRemoteRegistrations
1521 * Similar to rfapiShowImportTable() above. This function
1522 * is mean to produce the "remote" portion of the output
1523 * of "show vnc registrations".
1526 rfapiShowRemoteRegistrations (
1528 struct prefix
*prefix_only
,
1536 struct rfapi_import_table
*it
;
1539 bgp
= bgp_get_default ();
1551 for (it
= h
->imports
; it
; it
= it
->next
)
1554 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1555 show_expiring
, show_local
,
1556 show_remote
, show_imported
, NULL
);
1561 void *cursor
= NULL
;
1563 uintptr_t lni_as_ptr
;
1568 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1571 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1575 if ((lni_as_ptr
& 0xffffffff) == lni_as_ptr
)
1577 lni
= (uint32_t) (lni_as_ptr
& 0xffffffff);
1582 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1583 show_expiring
, show_local
,
1584 show_remote
, show_imported
, pLni
);
1591 /*------------------------------------------
1592 * rfapiRfapiIpAddr2Str
1594 * UI helper: generate string from rfapi_ip_addr
1597 * a IP v4/v6 address
1600 * buf put string here
1601 * bufsize max space to write
1604 * NULL conversion failed
1605 * non-NULL pointer to buf
1606 --------------------------------------------*/
1608 rfapiRfapiIpAddr2Str (struct rfapi_ip_addr
*a
, char *buf
, int bufsize
)
1610 const char *rc
= NULL
;
1612 switch (a
->addr_family
)
1615 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1618 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1625 rfapiPrintRfapiIpAddr (void *stream
, struct rfapi_ip_addr
*a
)
1628 const char *rc
= NULL
;
1630 int (*fp
) (void *, const char *, ...);
1633 const char *vty_newline
;
1635 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1638 rc
= rfapiRfapiIpAddr2Str (a
, buf
, BUFSIZ
);
1641 fp (out
, "%s", buf
);
1645 rfapiRfapiIpPrefix2Str (struct rfapi_ip_prefix
*p
, char *buf
, int bufsize
)
1647 struct rfapi_ip_addr
*a
= &p
->prefix
;
1648 const char *rc
= NULL
;
1650 switch (a
->addr_family
)
1653 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1656 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1662 int alen
= strlen (buf
);
1663 int remaining
= bufsize
- alen
- 1;
1668 slen
= snprintf (buf
+ alen
, remaining
, "/%u", p
->length
);
1669 if (slen
< remaining
) /* see man page for snprintf(3) */
1678 rfapiPrintRfapiIpPrefix (void *stream
, struct rfapi_ip_prefix
*p
)
1683 int (*fp
) (void *, const char *, ...);
1686 const char *vty_newline
;
1688 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1691 rc
= rfapiRfapiIpPrefix2Str (p
, buf
, BUFSIZ
);
1694 fp (out
, "%s:%u", buf
, p
->cost
);
1700 rfapiPrintRd (struct vty
*vty
, struct prefix_rd
*prd
)
1705 prefix_rd2str (prd
, buf
, BUFSIZ
);
1706 buf
[BUFSIZ
- 1] = 0;
1707 vty_out (vty
, "%s", buf
);
1711 rfapiPrintAdvertisedInfo (
1713 struct rfapi_descriptor
*rfd
,
1717 afi_t afi
; /* of the VN address */
1718 struct bgp_node
*bn
;
1719 struct bgp_info
*bi
;
1720 uint8_t type
= ZEBRA_ROUTE_BGP
;
1723 struct prefix_rd prd0
;
1724 struct prefix_rd
*prd
;
1727 * Find the bgp_info in the RIB corresponding to this
1731 afi
= family2afi (p
->family
);
1732 assert (afi
== AFI_IP
|| afi
== AFI_IP6
);
1734 bgp
= bgp_get_default (); /* assume 1 instance for now */
1737 if (safi
== SAFI_ENCAP
)
1739 memset (&prd0
, 0, sizeof (prd0
));
1740 prd0
.family
= AF_UNSPEC
;
1741 prd0
.prefixlen
= 64;
1748 bn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
1750 vty_out (vty
, " bn=%p%s", bn
, HVTYNL
);
1752 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
1754 if (bi
->peer
== rfd
->peer
&&
1756 bi
->sub_type
== BGP_ROUTE_RFP
&&
1757 bi
->extra
&& bi
->extra
->vnc
.export
.rfapi_handle
== (void *) rfd
)
1760 rfapiPrintBi (vty
, bi
);
1767 vty_out (vty
, " --?--%s", HVTYNL
);
1774 rfapiPrintDescriptor (struct vty
*vty
, struct rfapi_descriptor
*rfd
)
1776 /* pHD un-addr vn-addr pCB cookie rd lifetime */
1777 /* RT export list */
1778 /* RT import list */
1779 /* list of advertised prefixes */
1780 /* dump import table */
1786 struct rfapi_adb
*adb
;
1789 vty_out (vty
, "%-10p ", rfd
);
1790 rfapiPrintRfapiIpAddr (vty
, &rfd
->un_addr
);
1792 rfapiPrintRfapiIpAddr (vty
, &rfd
->vn_addr
);
1793 vty_out (vty
, " %p %p ", rfd
->response_cb
, rfd
->cookie
);
1794 rfapiPrintRd (vty
, &rfd
->rd
);
1795 vty_out (vty
, " %d", rfd
->response_lifetime
);
1796 vty_out (vty
, " %s", (rfd
->rfg
? rfd
->rfg
->name
: "<orphaned>"));
1797 vty_out (vty
, "%s", HVTYNL
);
1799 vty_out (vty
, " Peer %p #%d%s", rfd
->peer
, rfd
->peer
->lock
, HVTYNL
);
1801 /* export RT list */
1802 if (rfd
->rt_export_list
)
1805 ecommunity_ecom2str (rfd
->rt_export_list
,
1806 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1807 vty_out (vty
, " Export %s%s", s
, HVTYNL
);
1808 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1812 vty_out (vty
, " Export (nil)%s", HVTYNL
);
1815 /* import RT list */
1816 if (rfd
->import_table
)
1818 s
= ecommunity_ecom2str (rfd
->import_table
->rt_import_list
,
1819 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1820 vty_out (vty
, " Import %s%s", s
, HVTYNL
);
1821 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1825 vty_out (vty
, " Import (nil)%s", HVTYNL
);
1828 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1832 family
= afi2family (afi
);
1838 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1841 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1845 /* group like family prefixes together in output */
1846 if (family
!= adb
->u
.s
.prefix_ip
.family
)
1849 prefix2str (&adb
->u
.s
.prefix_ip
, buf
, BUFSIZ
);
1850 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1852 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTYNL
);
1853 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1857 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1860 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1864 prefix2str (&adb
->u
.s
.prefix_eth
, buf
, BUFSIZ
);
1865 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1867 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTYNL
);
1869 /* TBD update the following function to print ethernet info */
1870 /* Also need to pass/use rd */
1871 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1873 vty_out (vty
, "%s", HVTYNL
);
1877 * test scripts rely on first line for each nve starting in 1st column,
1878 * leading whitespace for additional detail of that nve
1881 rfapiPrintMatchingDescriptors (struct vty
*vty
,
1882 struct prefix
*vn_prefix
,
1883 struct prefix
*un_prefix
)
1887 struct listnode
*ln
;
1888 struct rfapi_descriptor
*rfd
;
1891 bgp
= bgp_get_default (); /* assume 1 instance for now */
1898 for (ln
= listhead (&h
->descriptors
); ln
; ln
= listnextnode (ln
))
1900 rfd
= listgetdata (ln
);
1906 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
1907 if (!prefix_match (vn_prefix
, &pfx
))
1913 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
1914 if (!prefix_match (un_prefix
, &pfx
))
1920 /* print column header */
1922 "%s %s %s %s %s %s %s %s%s",
1923 "descriptor", "un-addr", "vn-addr", "callback", "cookie",
1924 "RD", "lifetime", "group", HVTYNL
);
1926 rfapiPrintDescriptor (vty
, rfd
);
1933 * Parse an address and put into a struct prefix
1936 rfapiCliGetPrefixAddr (struct vty
*vty
, const char *str
, struct prefix
*p
)
1938 if (!str2prefix (str
, p
))
1940 vty_out (vty
, "Malformed address \"%s\"%s", str
, HVTYNL
);
1946 if (p
->prefixlen
!= 32)
1948 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTYNL
);
1953 if (p
->prefixlen
!= 128)
1955 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTYNL
);
1960 vty_out (vty
, "Invalid address \"%s\"%s", str
, HVTYNL
);
1967 rfapiCliGetRfapiIpAddr (
1970 struct rfapi_ip_addr
*hai
)
1975 rc
= rfapiCliGetPrefixAddr (vty
, str
, &pfx
);
1979 hai
->addr_family
= pfx
.family
;
1980 if (pfx
.family
== AF_INET
)
1981 hai
->addr
.v4
= pfx
.u
.prefix4
;
1983 hai
->addr
.v6
= pfx
.u
.prefix6
;
1989 * Note: this function does not flush vty output, so if it is called
1990 * with a stream pointing to a vty, the user will have to type something
1991 * before the callback output shows up
1994 rfapiPrintNhl (void *stream
, struct rfapi_next_hop_entry
*next_hops
)
1996 struct rfapi_next_hop_entry
*nh
;
1999 int (*fp
) (void *, const char *, ...);
2002 const char *vty_newline
;
2004 #define REMAIN (BUFSIZ - (p-line))
2005 #define INCP {p += (r > REMAIN)? REMAIN: r;}
2008 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
2011 for (nh
= next_hops
, count
= 1; nh
; nh
= nh
->next
, ++count
)
2018 r
= snprintf (p
, REMAIN
, "%3d pfx=", count
);
2021 if (rfapiRfapiIpPrefix2Str (&nh
->prefix
, p
, REMAIN
))
2023 /* it fit, so count length */
2033 r
= snprintf (p
, REMAIN
, ", un=");
2036 if (rfapiRfapiIpAddr2Str (&nh
->un_address
, p
, REMAIN
))
2038 /* it fit, so count length */
2048 r
= snprintf (p
, REMAIN
, ", vn=");
2051 if (rfapiRfapiIpAddr2Str (&nh
->vn_address
, p
, REMAIN
))
2053 /* it fit, so count length */
2064 line
[BUFSIZ
- 1] = 0;
2065 fp (out
, "%s%s", line
, HVTYNL
);
2072 struct rfapi_vn_option
*vo
;
2073 char offset
[] = " ";
2075 for (vo
= nh
->vn_options
; vo
; vo
= vo
->next
)
2081 case RFAPI_VN_OPTION_TYPE_L2ADDR
:
2082 rfapiEthAddr2Str (&vo
->v
.l2addr
.macaddr
, pbuf
,
2084 fp (out
, "%sL2 %s LBL=0x%06x NETID=0x%06x NVEID=%d%s",
2085 offset
, pbuf
, (vo
->v
.l2addr
.label
& 0x00ffffff),
2086 (vo
->v
.l2addr
.logical_net_id
& 0x00ffffff),
2087 vo
->v
.l2addr
.local_nve_id
, HVTYNL
);
2090 case RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
:
2091 prefix2str (&vo
->v
.local_nexthop
.addr
, pbuf
, sizeof (pbuf
));
2092 fp (out
, "%sLNH %s cost=%d%s",
2093 offset
, pbuf
, vo
->v
.local_nexthop
.cost
, HVTYNL
);
2097 fp (out
, "%svn option type %d (unknown)%s",
2098 offset
, vo
->type
, HVTYNL
);
2105 struct rfapi_un_option
*uo
;
2106 char offset
[] = " ";
2108 for (uo
= nh
->un_options
; uo
; uo
= uo
->next
)
2112 case RFAPI_UN_OPTION_TYPE_TUNNELTYPE
:
2113 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
2116 fp (out
, "%sUN Option type %d%s",
2117 offset
, uo
->type
, vty_newline
);
2126 /***********************************************************************
2128 ***********************************************************************/
2131 * Add another nexthop to the NHL
2134 rfapiAddDeleteLocalRfpPrefix (
2135 struct rfapi_ip_addr
*un_addr
,
2136 struct rfapi_ip_addr
*vn_addr
,
2137 struct rfapi_ip_prefix
*rprefix
,
2139 uint32_t lifetime
, /* add only */
2140 struct rfapi_vn_option
*vn_options
,
2141 struct rfapi_next_hop_entry
**head
,
2142 struct rfapi_next_hop_entry
**tail
)
2144 struct rfapi_next_hop_entry
*new;
2150 new = XCALLOC (MTYPE_RFAPI_NEXTHOP
, sizeof (struct rfapi_next_hop_entry
));
2151 new->prefix
= *rprefix
;
2152 new->un_address
= *un_addr
;
2153 new->vn_address
= *vn_addr
;
2155 new->vn_options
= vn_options
;
2158 new->lifetime
= lifetime
;
2162 new->lifetime
= RFAPI_REMOVE_RESPONSE_LIFETIME
;
2166 (*tail
)->next
= new;
2178 struct cmd_token
*carg_prefix
,
2179 struct cmd_token
*carg_vn
,
2180 struct cmd_token
*carg_un
,
2181 struct cmd_token
*carg_cost
, /* optional */
2182 struct cmd_token
*carg_lifetime
, /* optional */
2183 struct cmd_token
*carg_macaddr
, /* optional */
2184 struct cmd_token
*carg_vni
, /* mac present=>mandatory Virtual Network ID */
2186 struct cmd_token
**argv
)
2188 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
2189 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
2190 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
2191 const char *arg_cost
= carg_cost
? carg_cost
->arg
: NULL
;
2192 const char *arg_lifetime
= carg_lifetime
? carg_lifetime
->arg
: NULL
;
2193 const char *arg_macaddr
= carg_macaddr
? carg_macaddr
->arg
: NULL
;
2194 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
2195 struct rfapi_ip_addr vn_address
;
2196 struct rfapi_ip_addr un_address
;
2198 struct rfapi_ip_prefix rpfx
;
2203 struct rfapi_vn_option optary
[10]; /* XXX must be big enough */
2204 struct rfapi_vn_option
*opt
= NULL
;
2207 int rc
= CMD_WARNING_CONFIG_FAILED
;
2211 struct rfapi_cfg
*rfapi_cfg
;
2213 const char *arg_lnh
= NULL
;
2214 const char *arg_lnh_cost
= NULL
;
2216 bgp
= bgp_get_default (); /* assume 1 instance for now */
2220 vty_outln (vty
, "BGP not configured");
2221 return CMD_WARNING_CONFIG_FAILED
;
2225 rfapi_cfg
= bgp
->rfapi_cfg
;
2226 if (!h
|| !rfapi_cfg
)
2229 vty_outln (vty
, "RFAPI not configured");
2230 return CMD_WARNING_CONFIG_FAILED
;
2233 for (; argc
; --argc
, ++argv
)
2235 if (strmatch(argv
[0]->text
, "local-next-hop"))
2239 vty_outln (vty
,"local-next-hop specified more than once");
2240 return CMD_WARNING_CONFIG_FAILED
;
2244 vty_outln (vty
,"Missing parameter for local-next-hop");
2245 return CMD_WARNING_CONFIG_FAILED
;
2248 arg_lnh
= argv
[0]->arg
;
2250 if (strmatch(argv
[0]->text
, "local-cost"))
2254 vty_outln (vty
,"local-cost specified more than once");
2255 return CMD_WARNING_CONFIG_FAILED
;
2259 vty_outln (vty
,"Missing parameter for local-cost");
2260 return CMD_WARNING_CONFIG_FAILED
;
2263 arg_lnh_cost
= argv
[0]->arg
;
2267 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &vn_address
)))
2269 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &un_address
)))
2272 /* arg_prefix is optional if mac address is given */
2273 if (arg_macaddr
&& !arg_prefix
)
2276 * fake up a 0/32 or 0/128 prefix
2278 switch (vn_address
.addr_family
)
2281 arg_prefix
= "0.0.0.0/32";
2284 arg_prefix
= "0::0/128";
2287 vty_outln (vty
,"Internal error, unknown VN address family");
2288 return CMD_WARNING_CONFIG_FAILED
;
2293 if (!str2prefix (arg_prefix
, &pfx
))
2295 vty_outln (vty
, "Malformed prefix \"%s\"",arg_prefix
);
2298 if (pfx
.family
!= AF_INET
2299 && pfx
.family
!= AF_INET6
)
2301 vty_outln (vty
, "prefix \"%s\" has invalid address family",
2307 memset (optary
, 0, sizeof (optary
));
2312 cost
= strtoul (arg_cost
, &endptr
, 10);
2313 if (*endptr
!= '\0' || cost
> 255)
2315 vty_outln (vty
, "%% Invalid %s value", "cost");
2326 if (!strcmp (arg_lifetime
, "infinite"))
2328 lifetime
= RFAPI_INFINITE_LIFETIME
;
2333 lifetime
= strtoul (arg_lifetime
, &endptr
, 10);
2334 if (*endptr
!= '\0')
2336 vty_outln (vty
, "%% Invalid %s value","lifetime");
2343 lifetime
= RFAPI_INFINITE_LIFETIME
; /* default infinite */
2351 "%% %s may only be specified with local-next-hop",
2356 lnh_cost
= strtoul (arg_lnh_cost
, &endptr
, 10);
2357 if (*endptr
!= '\0' || lnh_cost
> 255)
2359 vty_outln (vty
, "%% Invalid %s value","local-cost");
2372 vty_outln (vty
, "%% %s may only be specified with prefix",
2376 if ((rc
= rfapiCliGetPrefixAddr (vty
, arg_lnh
,
2377 &optary
[opt_next
].v
.
2378 local_nexthop
.addr
)))
2384 optary
[opt_next
].v
.local_nexthop
.cost
= lnh_cost
;
2385 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
;
2389 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2398 if (arg_vni
&& !arg_macaddr
)
2400 vty_outln (vty
, "%% %s may only be specified with mac address",
2401 "virtual-network-identifier");
2410 "Missing \"vni\" parameter (mandatory with mac)");
2411 return CMD_WARNING_CONFIG_FAILED
;
2413 optary
[opt_next
].v
.l2addr
.logical_net_id
= strtoul(arg_vni
, NULL
,
2416 if ((rc
= rfapiStr2EthAddr (arg_macaddr
,
2417 &optary
[opt_next
].v
.l2addr
.macaddr
)))
2419 vty_outln (vty
, "Invalid %s value","mac address");
2422 /* TBD label, NVE ID */
2424 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
2428 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2437 vnc_zlog_debug_verbose
2438 ("%s: vn=%s, un=%s, prefix=%s, cost=%s, lifetime=%s, lnh=%s",
2439 __func__
, arg_vn
, arg_un
, arg_prefix
,
2440 (arg_cost
? arg_cost
: "NULL"),
2441 (arg_lifetime
? arg_lifetime
: "NULL"),
2442 (arg_lnh
? arg_lnh
: "NULL"));
2444 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
2446 rpfx
.cost
= cost
& 255;
2448 /* look up rf descriptor, call open if it doesn't exist */
2450 rfapi_find_rfd (bgp
, &vn_address
, &un_address
,
2451 (struct rfapi_descriptor
**) &rfd
);
2456 struct rfapi_un_option uo
;
2459 * flag descriptor as provisionally opened for static route
2460 * registration so that we can fix up the other parameters
2461 * when the real open comes along
2463 memset (&uo
, 0, sizeof (uo
));
2464 uo
.type
= RFAPI_UN_OPTION_TYPE_PROVISIONAL
;
2466 rc
= rfapi_open (rfapi_get_rfp_start_val_by_bgp (bgp
), &vn_address
, &un_address
, &uo
, /* flags */
2467 NULL
, NULL
, /* no userdata */
2471 vty_outln (vty
, "Can't open session for this NVE: %s",
2472 rfapi_error_str(rc
));
2473 rc
= CMD_WARNING_CONFIG_FAILED
;
2479 vty_outln (vty
, "Can't find session for this NVE: %s",
2480 rfapi_error_str(rc
));
2486 rfapi_register (rfd
, &rpfx
, lifetime
, NULL
, opt
, RFAPI_REGISTER_ADD
);
2489 struct rfapi_next_hop_entry
*head
= NULL
;
2490 struct rfapi_next_hop_entry
*tail
= NULL
;
2491 struct rfapi_vn_option
*vn_opt_new
;
2493 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded, returning 0", __func__
);
2495 if (h
->rfp_methods
.local_cb
)
2497 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfd
;
2498 vn_opt_new
= rfapi_vn_options_dup (opt
);
2500 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
2501 1, lifetime
, vn_opt_new
, &head
,
2505 h
->flags
|= RFAPI_INCALLBACK
;
2506 (*h
->rfp_methods
.local_cb
) (head
, r
->cookie
);
2507 h
->flags
&= ~RFAPI_INCALLBACK
;
2514 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
2515 vty_out (vty
, VTYNL
);
2516 vty_outln (vty
, "Registration failed.");
2518 "Confirm that either the VN or UN address matches a configured NVE group.");
2519 return CMD_WARNING_CONFIG_FAILED
;
2522 vnc_zlog_debug_verbose ("%s: fail, rc=%d", __func__
, rc
);
2526 /************************************************************************
2527 * Add prefix With LNH_OPTIONS...
2528 ************************************************************************/
2529 DEFUN (add_vnc_prefix_cost_life_lnh
,
2530 add_vnc_prefix_cost_life_lnh_cmd
,
2531 "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...",
2532 "Add registration\n"
2534 "Add/modify prefix related information\n"
2537 "VN address of NVE\n"
2538 "VN IPv4 interface address\n"
2539 "VN IPv6 interface address\n"
2540 "UN address of NVE\n"
2541 "UN IPv4 interface address\n"
2542 "UN IPv6 interface address\n"
2543 "Administrative cost [default: 255]\n"
2544 "Administrative cost\n"
2545 "Registration lifetime [default: infinite]\n"
2546 "Lifetime value in seconds\n"
2547 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2549 /* pfx vn un cost life */
2550 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2552 NULL
, NULL
, argc
- 12, argv
+ 12);
2555 DEFUN (add_vnc_prefix_life_cost_lnh
,
2556 add_vnc_prefix_life_cost_lnh_cmd
,
2557 "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...",
2558 "Add registration\n"
2560 "Add/modify prefix related information\n"
2563 "VN address of NVE\n"
2564 "VN IPv4 interface address\n"
2565 "VN IPv6 interface address\n"
2566 "UN address of NVE\n"
2567 "UN IPv4 interface address\n"
2568 "UN IPv6 interface address\n"
2569 "Registration lifetime [default: infinite]\n"
2570 "Lifetime value in seconds\n"
2571 "Administrative cost [default: 255]\n"
2572 "Administrative cost\n"
2573 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2575 /* pfx vn un cost life */
2576 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2578 NULL
, NULL
, argc
- 12, argv
+ 12);
2581 DEFUN (add_vnc_prefix_cost_lnh
,
2582 add_vnc_prefix_cost_lnh_cmd
,
2583 "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...",
2584 "Add registration\n"
2586 "Add/modify prefix related information\n"
2589 "VN address of NVE\n"
2590 "VN IPv4 interface address\n"
2591 "VN IPv6 interface address\n"
2592 "UN address of NVE\n"
2593 "UN IPv4 interface address\n"
2594 "UN IPv6 interface address\n"
2595 "Administrative cost [default: 255]\n"
2596 "Administrative cost\n"
2597 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2599 /* pfx vn un cost life */
2600 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2602 NULL
, NULL
, argc
- 10, argv
+ 10);
2605 DEFUN (add_vnc_prefix_life_lnh
,
2606 add_vnc_prefix_life_lnh_cmd
,
2607 "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...",
2608 "Add registration\n"
2610 "Add/modify prefix related information\n"
2613 "VN address of NVE\n"
2614 "VN IPv4 interface address\n"
2615 "VN IPv6 interface address\n"
2616 "UN address of NVE\n"
2617 "UN IPv4 interface address\n"
2618 "UN IPv6 interface address\n"
2619 "Registration lifetime [default: infinite]\n"
2620 "Lifetime value in seconds\n"
2621 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2623 /* pfx vn un cost life */
2624 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2626 NULL
, NULL
, argc
- 10, argv
+ 10);
2629 DEFUN (add_vnc_prefix_lnh
,
2630 add_vnc_prefix_lnh_cmd
,
2631 "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...",
2632 "Add registration\n"
2634 "Add/modify prefix related information\n"
2637 "VN address of NVE\n"
2638 "VN IPv4 interface address\n"
2639 "VN IPv6 interface address\n"
2640 "UN address of NVE\n"
2641 "UN IPv4 interface address\n"
2642 "UN IPv6 interface address\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
, NULL
,
2648 NULL
, NULL
, argc
- 8, argv
+ 8);
2651 /************************************************************************
2652 * Add prefix Without LNH_OPTIONS...
2653 ************************************************************************/
2654 DEFUN (add_vnc_prefix_cost_life
,
2655 add_vnc_prefix_cost_life_cmd
,
2656 "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)",
2657 "Add registration\n"
2659 "Add/modify prefix related information\n"
2662 "VN address of NVE\n"
2663 "VN IPv4 interface address\n"
2664 "VN IPv6 interface address\n"
2665 "UN address of NVE\n"
2666 "UN IPv4 interface address\n"
2667 "UN IPv6 interface address\n"
2668 "Administrative cost [default: 255]\n"
2669 "Administrative cost\n"
2670 "Registration lifetime [default: infinite]\n"
2671 "Lifetime value in seconds\n")
2673 /* pfx vn un cost life */
2674 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2676 NULL
, NULL
, 0, NULL
);
2679 DEFUN (add_vnc_prefix_life_cost
,
2680 add_vnc_prefix_life_cost_cmd
,
2681 "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)",
2682 "Add registration\n"
2684 "Add/modify prefix related information\n"
2687 "VN address of NVE\n"
2688 "VN IPv4 interface address\n"
2689 "VN IPv6 interface address\n"
2690 "UN address of NVE\n"
2691 "UN IPv4 interface address\n"
2692 "UN IPv6 interface address\n"
2693 "Registration lifetime [default: infinite]\n"
2694 "Lifetime value in seconds\n"
2695 "Administrative cost [default: 255]\n"
2696 "Administrative cost\n")
2698 /* pfx vn un cost life */
2699 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2701 NULL
, NULL
, 0, NULL
);
2704 DEFUN (add_vnc_prefix_cost
,
2705 add_vnc_prefix_cost_cmd
,
2706 "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)",
2707 "Add registration\n"
2709 "Add/modify prefix related information\n"
2712 "VN address of NVE\n"
2713 "VN IPv4 interface address\n"
2714 "VN IPv6 interface address\n"
2715 "UN address of NVE\n"
2716 "UN IPv4 interface address\n"
2717 "UN IPv6 interface address\n"
2718 "Administrative cost [default: 255]\n"
2719 "Administrative cost\n")
2721 /* pfx vn un cost life */
2722 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2724 NULL
, NULL
, 0, NULL
);
2727 DEFUN (add_vnc_prefix_life
,
2728 add_vnc_prefix_life_cmd
,
2729 "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)",
2730 "Add registration\n"
2732 "Add/modify prefix related information\n"
2735 "VN address of NVE\n"
2736 "VN IPv4 interface address\n"
2737 "VN IPv6 interface address\n"
2738 "UN address of NVE\n"
2739 "UN IPv4 interface address\n"
2740 "UN IPv6 interface address\n"
2741 "Registration lifetime [default: infinite]\n"
2742 "Lifetime value in seconds\n")
2744 /* pfx vn un cost life */
2745 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2747 NULL
, NULL
, 0, NULL
);
2750 DEFUN (add_vnc_prefix
,
2752 "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>",
2753 "Add registration\n"
2755 "Add/modify prefix related information\n"
2758 "VN address of NVE\n"
2759 "VN IPv4 interface address\n"
2760 "VN IPv6 interface address\n"
2761 "UN address of NVE\n"
2762 "UN IPv4 interface address\n"
2763 "UN IPv6 interface address\n")
2765 /* pfx vn un cost life */
2766 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2768 NULL
, NULL
, 0, NULL
);
2771 /************************************************************************
2772 * Mac address registrations
2773 ************************************************************************/
2774 DEFUN (add_vnc_mac_vni_prefix_cost_life
,
2775 add_vnc_mac_vni_prefix_cost_life_cmd
,
2776 "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)",
2777 "Add registration\n"
2779 "Add/modify mac address information\n"
2781 "Virtual Network Identifier follows\n"
2782 "Virtual Network Identifier\n"
2783 "VN address of NVE\n"
2784 "VN IPv4 interface address\n"
2785 "VN IPv6 interface address\n"
2786 "UN address of NVE\n"
2787 "UN IPv4 interface address\n"
2788 "UN IPv6 interface address\n"
2789 "Add/modify prefix related information\n"
2792 "Administrative cost [default: 255]\n"
2793 "Administrative cost\n"
2794 "Registration lifetime [default: infinite]\n"
2795 "Lifetime value in seconds\n")
2797 /* pfx vn un cost life */
2798 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], argv
[15],
2800 argv
[3], argv
[5], 0, NULL
);
2804 DEFUN (add_vnc_mac_vni_prefix_life
,
2805 add_vnc_mac_vni_prefix_life_cmd
,
2806 "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)",
2807 "Add registration\n"
2809 "Add/modify mac address information\n"
2811 "Virtual Network Identifier follows\n"
2812 "Virtual Network Identifier\n"
2813 "VN address of NVE\n"
2814 "VN IPv4 interface address\n"
2815 "VN IPv6 interface address\n"
2816 "UN address of NVE\n"
2817 "UN IPv4 interface address\n"
2818 "UN IPv6 interface address\n"
2819 "Add/modify prefix related information\n"
2822 "Registration lifetime [default: infinite]\n"
2823 "Lifetime value in seconds\n")
2825 /* pfx vn un cost life */
2826 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, argv
[13],
2828 argv
[3], argv
[5], 0, NULL
);
2831 DEFUN (add_vnc_mac_vni_prefix_cost
,
2832 add_vnc_mac_vni_prefix_cost_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> cost (0-255)",
2834 "Add registration\n"
2836 "Add/modify mac address information\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 information\n"
2849 "Administrative cost [default: 255]\n" "Administrative cost\n")
2851 /* pfx vn un cost life */
2852 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], NULL
,
2854 argv
[3], argv
[5], 0, NULL
);
2857 DEFUN (add_vnc_mac_vni_prefix
,
2858 add_vnc_mac_vni_prefix_cmd
,
2859 "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>",
2860 "Add registration\n"
2862 "Add/modify mac address information\n"
2864 "Virtual Network Identifier follows\n"
2865 "Virtual Network Identifier\n"
2866 "VN address of NVE\n"
2867 "VN IPv4 interface address\n"
2868 "VN IPv6 interface address\n"
2869 "UN address of NVE\n"
2870 "UN IPv4 interface address\n"
2871 "UN IPv6 interface address\n"
2872 "Add/modify prefix related information\n"
2873 "IPv4 prefix\n" "IPv6 prefix\n")
2875 /* pfx vn un cost life */
2876 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, NULL
,
2878 argv
[3], argv
[5], 0, NULL
);
2881 DEFUN (add_vnc_mac_vni_cost_life
,
2882 add_vnc_mac_vni_cost_life_cmd
,
2883 "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)",
2884 "Add registration\n"
2886 "Add/modify mac address information\n"
2888 "Virtual Network Identifier follows\n"
2889 "Virtual Network Identifier\n"
2890 "VN address of NVE\n"
2891 "VN IPv4 interface address\n"
2892 "VN IPv6 interface address\n"
2893 "UN address of NVE\n"
2894 "UN IPv4 interface address\n"
2895 "UN IPv6 interface address\n"
2896 "Administrative cost [default: 255]\n"
2897 "Administrative cost\n"
2898 "Registration lifetime [default: infinite]\n"
2899 "Lifetime value in seconds\n")
2901 /* pfx vn un cost life */
2902 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], argv
[13],
2904 argv
[3], argv
[5], 0, NULL
);
2908 DEFUN (add_vnc_mac_vni_cost
,
2909 add_vnc_mac_vni_cost_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)",
2911 "Add registration\n"
2913 "Add/modify mac address information\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" "Administrative cost\n")
2925 /* pfx vn un cost life */
2926 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], NULL
,
2928 argv
[3], argv
[5], 0, NULL
);
2932 DEFUN (add_vnc_mac_vni_life
,
2933 add_vnc_mac_vni_life_cmd
,
2934 "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)",
2935 "Add registration\n"
2937 "Add/modify mac address information\n"
2939 "Virtual Network Identifier follows\n"
2940 "Virtual Network Identifier\n"
2941 "VN address of NVE\n"
2942 "VN IPv4 interface address\n"
2943 "VN IPv6 interface address\n"
2944 "UN address of NVE\n"
2945 "UN IPv4 interface address\n"
2946 "UN IPv6 interface address\n"
2947 "Registration lifetime [default: infinite]\n"
2948 "Lifetime value in seconds\n")
2950 /* pfx vn un cost life */
2951 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, argv
[11],
2953 argv
[3], argv
[5], 0, NULL
);
2957 DEFUN (add_vnc_mac_vni
,
2958 add_vnc_mac_vni_cmd
,
2959 "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>",
2960 "Add registration\n"
2962 "Add/modify mac address information\n"
2964 "Virtual Network Identifier follows\n"
2965 "Virtual Network Identifier\n"
2966 "VN address of NVE\n"
2967 "VN IPv4 interface address\n"
2968 "VN IPv6 interface address\n"
2969 "UN address of NVE\n"
2970 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
2972 /* pfx vn un cost life */
2973 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, NULL
,
2975 argv
[3], argv
[5], 0, NULL
);
2978 /************************************************************************
2980 ************************************************************************/
2982 struct rfapi_local_reg_delete_arg
2988 struct rfapi_ip_addr un_address
; /* AF==0: wildcard */
2989 struct rfapi_ip_addr vn_address
; /* AF==0: wildcard */
2990 struct prefix prefix
; /* AF==0: wildcard */
2991 struct prefix_rd rd
; /* plen!=64: wildcard */
2992 struct rfapi_nve_group_cfg
*rfg
; /* NULL: wildcard */
2994 struct rfapi_l2address_option_match l2o
;
3002 uint32_t query_count
;
3004 uint32_t failed_pfx_count
;
3007 struct skiplist
*nves
;
3009 uint32_t remote_active_nve_count
;
3010 uint32_t remote_active_pfx_count
;
3011 uint32_t remote_holddown_nve_count
;
3012 uint32_t remote_holddown_pfx_count
;
3017 struct rfapi_ip_addr vn
;
3018 struct rfapi_ip_addr un
;
3019 struct rfapi_descriptor
*rfd
;
3020 struct rfapi_local_reg_delete_arg
*cda
;
3024 nve_addr_free (void *hap
)
3026 ((struct nve_addr
*) hap
)->cda
->nve_count
+= 1;
3027 XFREE (MTYPE_RFAPI_NVE_ADDR
, hap
);
3031 nve_addr_cmp (void *k1
, void *k2
)
3033 struct nve_addr
*a
= (struct nve_addr
*) k1
;
3034 struct nve_addr
*b
= (struct nve_addr
*) k2
;
3041 if (a
->un
.addr_family
!= b
->un
.addr_family
)
3043 return (a
->un
.addr_family
- b
->un
.addr_family
);
3045 if (a
->vn
.addr_family
!= b
->vn
.addr_family
)
3047 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
3049 if (a
->un
.addr_family
== AF_INET
)
3051 ret
= IPV4_ADDR_CMP (&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
3057 else if (a
->un
.addr_family
== AF_INET6
)
3059 ret
= IPV6_ADDR_CMP (&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
3069 if (a
->vn
.addr_family
== AF_INET
)
3071 ret
= IPV4_ADDR_CMP (&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
3075 else if (a
->vn
.addr_family
== AF_INET6
)
3077 ret
= IPV6_ADDR_CMP (&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
3091 parse_deleter_args (
3094 const char *arg_prefix
,
3097 const char *arg_l2addr
,
3098 const char *arg_vni
,
3100 struct rfapi_nve_group_cfg
*arg_rfg
,
3101 struct rfapi_local_reg_delete_arg
*rcdarg
)
3103 int rc
= CMD_WARNING
;
3105 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3109 bgp
= bgp_get_default();
3111 rcdarg
->rfg
= arg_rfg
; /* may be NULL */
3113 if (arg_vn
&& strcmp (arg_vn
, "*"))
3115 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3118 if (arg_un
&& strcmp (arg_un
, "*"))
3120 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3123 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3126 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3128 vty_outln (vty
, "Malformed prefix \"%s\"", arg_prefix
);
3137 vty_outln (vty
, "Missing VNI");
3140 if (strcmp (arg_l2addr
, "*"))
3142 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3144 vty_outln (vty
, "Malformed L2 Address \"%s\"",
3148 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3150 if (strcmp (arg_vni
, "*"))
3152 rcdarg
->l2o
.o
.logical_net_id
= strtoul(arg_vni
, NULL
, 10);
3153 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3158 if (!str2prefix_rd (arg_rd
, &rcdarg
->rd
))
3160 vty_outln (vty
, "Malformed RD \"%s\"",
3170 parse_deleter_tokens (
3173 struct cmd_token
*carg_prefix
,
3174 struct cmd_token
*carg_vn
,
3175 struct cmd_token
*carg_un
,
3176 struct cmd_token
*carg_l2addr
,
3177 struct cmd_token
*carg_vni
,
3178 struct cmd_token
*carg_rd
,
3179 struct rfapi_nve_group_cfg
*arg_rfg
,
3180 struct rfapi_local_reg_delete_arg
*rcdarg
)
3182 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
3183 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
3184 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
3185 const char *arg_l2addr
= carg_l2addr
? carg_l2addr
->arg
: NULL
;
3186 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
3187 const char *arg_rd
= carg_rd
? carg_rd
->arg
: NULL
;
3188 return parse_deleter_args (vty
, bgp
,arg_prefix
, arg_vn
, arg_un
,
3189 arg_l2addr
, arg_vni
, arg_rd
,
3194 record_nve_in_cda_list (
3195 struct rfapi_local_reg_delete_arg
*cda
,
3196 struct rfapi_ip_addr
*un_address
,
3197 struct rfapi_ip_addr
*vn_address
,
3198 struct rfapi_descriptor
*rfd
)
3201 struct nve_addr
*hap
;
3203 memset (&ha
, 0, sizeof (ha
));
3204 ha
.un
= *un_address
;
3205 ha
.vn
= *vn_address
;
3209 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3211 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3213 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3217 skiplist_insert (cda
->nves
, hap
, hap
);
3222 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3225 struct rfapi_descriptor
*rfd
;
3226 int query_count
= 0;
3227 struct listnode
*node
;
3228 struct bgp
*bgp_default
= bgp_get_default ();
3230 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3236 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3239 rfapiRibClear (rfd
);
3240 rfapi_query_done_all (rfd
, &query_count
);
3241 cda
->query_count
+= query_count
;
3244 * Track unique nves seen
3246 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3257 h
= bgp_default
->rfapi
;
3262 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3265 * match un, vn addresses of NVEs
3267 if (cda
->un_address
.addr_family
&&
3268 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3272 if (cda
->vn_address
.addr_family
&&
3273 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3278 rfapiRibClear (rfd
);
3280 rfapi_query_done_all (rfd
, &query_count
);
3281 cda
->query_count
+= query_count
;
3284 * Track unique nves seen
3286 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3291 * TBD need to count deleted prefixes and nves?
3293 * ENXIO BGP or VNC not configured
3296 rfapiDeleteLocalPrefixesByRFD (struct rfapi_local_reg_delete_arg
*cda
,
3297 struct rfapi_descriptor
*rfd
)
3299 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3300 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3301 struct prefix
*pPrefix
; /* NULL = wildcard */
3302 struct prefix_rd
*pPrd
; /* NULL = wildcard */
3304 struct rfapi_ip_prefix rprefix
;
3305 struct rfapi_next_hop_entry
*head
= NULL
;
3306 struct rfapi_next_hop_entry
*tail
= NULL
;
3309 vnc_zlog_debug_verbose ("%s: entry", __func__
);
3312 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3313 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3314 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3315 pPrd
= (cda
->rd
.prefixlen
== 64 ? &cda
->rd
: NULL
);
3319 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3322 do /* to preserve old code structure */
3324 struct rfapi
*h
=cda
->bgp
->rfapi
;;
3325 struct rfapi_adb
*adb
;
3327 int deleted_from_this_nve
;
3329 struct nve_addr
*hap
;
3332 vnc_zlog_debug_verbose ("%s: rfd=%p", __func__
, rfd
);
3336 * match un, vn addresses of NVEs
3338 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3340 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3344 vnc_zlog_debug_verbose ("%s: un, vn match", __func__
);
3351 deleted_from_this_nve
= 0;
3354 struct skiplist
*sl
;
3355 struct rfapi_ip_prefix rp
;
3357 struct list
*adb_delete_list
;
3360 * The advertisements are stored in a skiplist. Withdrawing
3361 * the registration deletes the advertisement from the
3362 * skiplist, which we can't do while iterating over that
3363 * same skiplist using the current skiplist API.
3365 * Strategy: iterate over the skiplist and build another
3366 * list containing only the matching ADBs. Then delete
3367 * _everything_ in that second list (which can be done
3368 * using either skiplists or quagga linklists).
3370 adb_delete_list
= list_new ();
3373 * Advertised IP prefixes (not 0/32 or 0/128)
3375 sl
= rfd
->advertised
.ipN_by_prefix
;
3378 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3379 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3384 if (!prefix_same (pPrefix
, &adb
->u
.s
.prefix_ip
))
3387 vnc_zlog_debug_verbose ("%s: adb=%p, prefix doesn't match, skipping",
3395 if (memcmp(pPrd
->val
, adb
->u
.s
.prd
.val
, 8) != 0)
3398 vnc_zlog_debug_verbose ("%s: adb=%p, RD doesn't match, skipping",
3404 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3407 (cda
->l2o
.o
.macaddr
.octet
,
3408 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3411 vnc_zlog_debug_verbose ("%s: adb=%p, macaddr doesn't match, skipping",
3418 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3420 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3423 vnc_zlog_debug_verbose ("%s: adb=%p, LNI doesn't match, skipping",
3431 vnc_zlog_debug_verbose ("%s: ipN adding adb %p to delete list", __func__
,
3435 listnode_add (adb_delete_list
, adb
);
3438 struct listnode
*node
;
3440 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3442 int this_advertisement_prefix_count
;
3443 struct rfapi_vn_option optary
[3];
3444 struct rfapi_vn_option
*opt
= NULL
;
3447 this_advertisement_prefix_count
= 1;
3449 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3451 memset (optary
, 0, sizeof (optary
));
3453 /* if mac addr present in advert, make l2o vn option */
3454 if (adb
->u
.s
.prefix_eth
.family
== AF_ETHERNET
)
3457 opt
->next
= &optary
[cur_opt
];
3458 opt
= &optary
[cur_opt
++];
3459 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3460 opt
->v
.l2addr
.macaddr
= adb
->u
.s
.prefix_eth
.u
.prefix_eth
;
3461 ++this_advertisement_prefix_count
;
3464 * use saved RD value instead of trying to invert
3465 * complex RD computation in rfapi_register()
3468 opt
->next
= &optary
[cur_opt
];
3469 opt
= &optary
[cur_opt
++];
3470 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3471 opt
->v
.internal_rd
= adb
->u
.s
.prd
;
3474 vnc_zlog_debug_verbose ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3477 rc
= rfapi_register (rfd
, &rp
, 0, NULL
,
3478 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_KILL
);
3481 cda
->pfx_count
+= this_advertisement_prefix_count
;
3482 cda
->reg_count
+= 1;
3483 deleted_from_this_nve
= 1;
3485 if (h
->rfp_methods
.local_cb
)
3487 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3488 &rp
, 0, 0, NULL
, &head
, &tail
);
3491 list_delete_all_node (adb_delete_list
);
3493 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3498 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3502 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3504 sl
= rfd
->advertised
.ip0_by_ether
;
3507 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3508 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3511 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3513 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3514 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
,
3521 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3523 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3529 vnc_zlog_debug_verbose ("%s: ip0 adding adb %p to delete list",
3532 listnode_add (adb_delete_list
, adb
);
3536 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3539 struct rfapi_vn_option vn
;
3541 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3543 memset (&vn
, 0, sizeof (vn
));
3544 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3545 vn
.v
.l2addr
= adb
->l2o
;
3548 vnc_zlog_debug_verbose ("%s: ip0 killing reg from adb %p ",
3552 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3553 RFAPI_REGISTER_KILL
);
3556 cda
->pfx_count
+= 1;
3557 cda
->reg_count
+= 1;
3558 deleted_from_this_nve
= 1;
3560 if (h
->rfp_methods
.local_cb
)
3562 struct rfapi_vn_option
*vn_opt_new
;
3564 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3565 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3566 &rfd
->vn_addr
, &rp
, 0, 0,
3567 vn_opt_new
, &head
, &tail
);
3570 list_delete_all_node (adb_delete_list
);
3572 list_delete (adb_delete_list
);
3577 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3578 h
->flags
|= RFAPI_INCALLBACK
;
3579 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3580 h
->flags
&= ~RFAPI_INCALLBACK
;
3584 if (deleted_from_this_nve
)
3587 * track unique NVEs seen
3589 memset (&ha
, 0, sizeof (ha
));
3590 ha
.un
= rfd
->un_addr
;
3591 ha
.vn
= rfd
->vn_addr
;
3594 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3595 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3597 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3601 skiplist_insert (cda
->nves
, hap
, hap
);
3604 } while (0); /* to preserve old code structure */
3610 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3616 if (cda
->rfg
->rfd
) /* if not open, nothing to delete */
3617 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, cda
->rfg
->rfd
);
3621 struct bgp
*bgp
= cda
->bgp
;
3623 struct rfapi_cfg
*rfapi_cfg
;
3625 struct listnode
*node
;
3626 struct rfapi_descriptor
*rfd
;
3630 rfapi_cfg
= bgp
->rfapi_cfg
;
3631 if (!h
|| !rfapi_cfg
)
3633 vnc_zlog_debug_verbose ("%s: starting descriptor loop", __func__
);
3634 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3636 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, rfd
);
3645 * Deletes local and remote prefixes that match
3648 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3650 struct prefix pfx_un
;
3651 struct prefix pfx_vn
;
3653 struct prefix
*pUN
= NULL
;
3654 struct prefix
*pVN
= NULL
;
3655 struct prefix
*pPrefix
= NULL
;
3657 struct rfapi_import_table
*it
= NULL
;
3660 * Delete matching remote prefixes in holddown
3662 if (cda
->vn_address
.addr_family
)
3664 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3667 if (cda
->un_address
.addr_family
)
3669 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3672 if (cda
->prefix
.family
)
3674 pPrefix
= &cda
->prefix
;
3678 it
= cda
->rfg
->rfapi_import_table
;
3680 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
, it
,
3681 0, 1, &cda
->remote_active_pfx_count
,
3682 &cda
->remote_active_nve_count
,
3683 &cda
->remote_holddown_pfx_count
,
3684 &cda
->remote_holddown_nve_count
);
3687 * Now do local prefixes
3689 rfapiDeleteLocalPrefixes (cda
);
3693 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3695 struct vty
*vty
= cda
->vty
; /* for benefit of VTYNL */
3697 /* Our special element-deleting function counts nves */
3700 skiplist_free (cda
->nves
);
3703 if (cda
->failed_pfx_count
)
3704 vty_outln (vty
, "Failed to delete %d prefixes",
3705 cda
->failed_pfx_count
);
3707 /* left as "prefixes" even in single case for ease of machine parsing */
3709 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs",
3710 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
,cda
->nve_count
);
3713 * We don't currently allow deletion of active remote prefixes from
3717 vty_outln (vty
, "[Holddown] Cleared %u prefixes from %u NVEs",
3718 cda
->remote_holddown_pfx_count
,cda
->remote_holddown_nve_count
);
3722 * Caller has already deleted registrations and queries for this/these
3723 * NVEs. Now we just have to close their descriptors.
3726 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3728 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3729 struct nve_addr
*pKey
;
3730 struct nve_addr
*pValue
;
3731 void *cursor
= NULL
;
3737 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3739 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3744 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3745 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3746 rfapi_close (pValue
->rfd
);
3751 DEFUN (clear_vnc_nve_all
,
3752 clear_vnc_nve_all_cmd
,
3756 "Clear per NVE information\n"
3760 struct rfapi_local_reg_delete_arg cda
;
3763 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3768 clear_vnc_responses (&cda
);
3769 clear_vnc_prefix (&cda
);
3770 clear_vnc_nve_closer (&cda
);
3772 print_cleared_stats (&cda
);
3777 DEFUN (clear_vnc_nve_vn_un
,
3778 clear_vnc_nve_vn_un_cmd
,
3779 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3782 "Clear prefix registration information\n"
3783 "VN address of NVE\n"
3785 "VN IPv4 interface address\n"
3786 "VN IPv6 interface address\n"
3787 "UN address of NVE\n"
3788 "For all UN addresses\n"
3789 "UN IPv4 interface address\n"
3790 "UN IPv6 interface address\n")
3792 struct rfapi_local_reg_delete_arg cda
;
3796 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], argv
[6], NULL
, NULL
, NULL
, NULL
, &cda
)))
3801 clear_vnc_responses (&cda
);
3802 clear_vnc_prefix (&cda
);
3803 clear_vnc_nve_closer (&cda
);
3805 print_cleared_stats (&cda
);
3810 DEFUN (clear_vnc_nve_un_vn
,
3811 clear_vnc_nve_un_vn_cmd
,
3812 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3815 "Clear prefix registration information\n"
3816 "UN address of NVE\n"
3818 "UN IPv4 interface address\n"
3819 "UN IPv6 interface address\n"
3820 "VN address of NVE\n"
3822 "VN IPv4 interface address\n"
3823 "VN IPv6 interface address\n")
3825 struct rfapi_local_reg_delete_arg cda
;
3829 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[6], argv
[4], NULL
, NULL
, NULL
, NULL
, &cda
)))
3834 clear_vnc_responses (&cda
);
3835 clear_vnc_prefix (&cda
);
3836 clear_vnc_nve_closer (&cda
);
3838 print_cleared_stats (&cda
);
3843 DEFUN (clear_vnc_nve_vn
,
3844 clear_vnc_nve_vn_cmd
,
3845 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3848 "Clear prefix registration information\n"
3849 "VN address of NVE\n"
3851 "VN IPv4 interface address\n"
3852 "VN IPv6 interface address\n")
3854 struct rfapi_local_reg_delete_arg cda
;
3857 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3862 clear_vnc_responses (&cda
);
3863 clear_vnc_prefix (&cda
);
3864 clear_vnc_nve_closer (&cda
);
3866 print_cleared_stats (&cda
);
3870 DEFUN (clear_vnc_nve_un
,
3871 clear_vnc_nve_un_cmd
,
3872 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3875 "Clear prefix registration information\n"
3876 "UN address of NVE\n"
3878 "UN IPv4 interface address\n"
3879 "UN IPv6 interface address\n")
3881 struct rfapi_local_reg_delete_arg cda
;
3884 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[4], NULL
, NULL
, NULL
, NULL
, &cda
)))
3889 clear_vnc_responses (&cda
);
3890 clear_vnc_prefix (&cda
);
3891 clear_vnc_nve_closer (&cda
);
3893 print_cleared_stats (&cda
);
3897 /*-------------------------------------------------
3899 *-------------------------------------------------*/
3902 * This function is defined in this file (rather than in rfp_registration.c)
3903 * because here we have access to all the task handles.
3905 DEFUN (clear_vnc_prefix_vn_un
,
3906 clear_vnc_prefix_vn_un_cmd
,
3907 "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>",
3910 "Clear prefix registration information\n"
3914 "VN address of NVE\n"
3915 "All VN addresses\n"
3916 "VN IPv4 interface address\n"
3917 "VN IPv6 interface address\n"
3918 "UN address of NVE\n"
3919 "All UN addresses\n"
3920 "UN IPv4 interface address\n"
3921 "UN IPv6 interface address\n")
3923 struct rfapi_local_reg_delete_arg cda
;
3927 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], argv
[7], NULL
, NULL
, NULL
, NULL
, &cda
)))
3930 clear_vnc_prefix (&cda
);
3931 print_cleared_stats (&cda
);
3935 DEFUN (clear_vnc_prefix_un_vn
,
3936 clear_vnc_prefix_un_vn_cmd
,
3937 "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>",
3940 "Clear prefix registration information\n"
3944 "UN address of NVE\n"
3945 "All UN addresses\n"
3946 "UN IPv4 interface address\n"
3947 "UN IPv6 interface address\n"
3948 "VN address of NVE\n"
3949 "All VN addresses\n"
3950 "VN IPv4 interface address\n"
3951 "VN IPv6 interface address\n")
3953 struct rfapi_local_reg_delete_arg cda
;
3957 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[7], argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
3960 clear_vnc_prefix (&cda
);
3961 print_cleared_stats (&cda
);
3965 DEFUN (clear_vnc_prefix_un
,
3966 clear_vnc_prefix_un_cmd
,
3967 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3970 "Clear prefix registration information\n"
3974 "UN address of NVE\n"
3975 "All UN addresses\n"
3976 "UN IPv4 interface address\n"
3977 "UN IPv6 interface address\n")
3979 struct rfapi_local_reg_delete_arg cda
;
3983 parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
3986 clear_vnc_prefix (&cda
);
3987 print_cleared_stats (&cda
);
3991 DEFUN (clear_vnc_prefix_vn
,
3992 clear_vnc_prefix_vn_cmd
,
3993 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
3996 "Clear prefix registration information\n"
4000 "UN address of NVE\n"
4001 "All VN addresses\n"
4002 "VN IPv4 interface address\n"
4003 "VN IPv6 interface address\n")
4005 struct rfapi_local_reg_delete_arg cda
;
4009 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4012 clear_vnc_prefix (&cda
);
4013 print_cleared_stats (&cda
);
4017 DEFUN (clear_vnc_prefix_all
,
4018 clear_vnc_prefix_all_cmd
,
4019 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
4022 "Clear prefix registration information\n"
4028 struct rfapi_local_reg_delete_arg cda
;
4031 if ((rc
= parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4034 clear_vnc_prefix (&cda
);
4035 print_cleared_stats (&cda
);
4039 /*-------------------------------------------------
4041 *-------------------------------------------------*/
4044 * This function is defined in this file (rather than in rfp_registration.c)
4045 * because here we have access to all the task handles.
4047 DEFUN (clear_vnc_mac_vn_un
,
4048 clear_vnc_mac_vn_un_cmd
,
4049 "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>",
4052 "Clear mac registration information\n"
4056 "Any virtual network identifier\n"
4057 "Virtual network identifier\n"
4058 "VN address of NVE\n"
4059 "All VN addresses\n"
4060 "VN IPv4 interface address\n"
4061 "VN IPv6 interface address\n"
4062 "UN address of NVE\n"
4063 "All UN addresses\n"
4064 "UN IPv4 interface address\n"
4065 "UN IPv6 interface address\n")
4067 struct rfapi_local_reg_delete_arg cda
;
4070 /* pfx vn un L2 VNI */
4072 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], argv
[9], argv
[3], argv
[5],
4076 clear_vnc_prefix (&cda
);
4077 print_cleared_stats (&cda
);
4081 DEFUN (clear_vnc_mac_un_vn
,
4082 clear_vnc_mac_un_vn_cmd
,
4083 "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>",
4086 "Clear mac registration information\n"
4090 "Any virtual network identifier\n"
4091 "Virtual network identifier\n"
4092 "UN address of NVE\n"
4093 "All UN addresses\n"
4094 "UN IPv4 interface address\n"
4095 "UN IPv6 interface address\n"
4096 "VN address of NVE\n"
4097 "All VN addresses\n"
4098 "VN IPv4 interface address\n"
4099 "VN IPv6 interface address\n")
4101 struct rfapi_local_reg_delete_arg cda
;
4104 /* pfx vn un L2 VNI */
4106 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[9], argv
[7], argv
[3], argv
[5],
4110 clear_vnc_prefix (&cda
);
4111 print_cleared_stats (&cda
);
4115 DEFUN (clear_vnc_mac_un
,
4116 clear_vnc_mac_un_cmd
,
4117 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4120 "Clear mac registration information\n"
4124 "Any virtual network identifier\n"
4125 "Virtual network identifier\n"
4126 "UN address of NVE\n"
4127 "All UN addresses\n"
4128 "UN IPv4 interface address\n"
4129 "UN IPv6 interface address\n")
4131 struct rfapi_local_reg_delete_arg cda
;
4134 /* pfx vn un L2 VNI */
4136 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[7], argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4139 clear_vnc_prefix (&cda
);
4140 print_cleared_stats (&cda
);
4144 DEFUN (clear_vnc_mac_vn
,
4145 clear_vnc_mac_vn_cmd
,
4146 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4149 "Clear mac registration information\n"
4153 "Any virtual network identifier\n"
4154 "Virtual network identifier\n"
4155 "UN address of NVE\n"
4156 "All VN addresses\n"
4157 "VN IPv4 interface address\n"
4158 "VN IPv6 interface address\n")
4160 struct rfapi_local_reg_delete_arg cda
;
4163 /* pfx vn un L2 VNI */
4165 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4168 clear_vnc_prefix (&cda
);
4169 print_cleared_stats (&cda
);
4173 DEFUN (clear_vnc_mac_all
,
4174 clear_vnc_mac_all_cmd
,
4175 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4178 "Clear mac registration information\n"
4182 "Any virtual network identifier\n"
4183 "Virtual network identifier\n"
4186 struct rfapi_local_reg_delete_arg cda
;
4189 /* pfx vn un L2 VNI */
4191 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4194 clear_vnc_prefix (&cda
);
4195 print_cleared_stats (&cda
);
4199 /*-------------------------------------------------
4200 * Clear VNC MAC PREFIX
4201 *-------------------------------------------------*/
4203 DEFUN (clear_vnc_mac_vn_un_prefix
,
4204 clear_vnc_mac_vn_un_prefix_cmd
,
4205 "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>",
4208 "Clear mac registration information\n"
4212 "Any virtual network identifier\n"
4213 "Virtual network identifier\n"
4214 "VN address of NVE\n"
4215 "All VN addresses\n"
4216 "VN IPv4 interface address\n"
4217 "VN IPv6 interface address\n"
4218 "UN address of NVE\n"
4219 "All UN addresses\n"
4220 "UN IPv4 interface address\n"
4221 "UN IPv6 interface address\n"
4222 "Clear prefix registration information\n"
4227 struct rfapi_local_reg_delete_arg cda
;
4230 /* pfx vn un L2 VNI */
4232 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[7], argv
[9], argv
[3], argv
[5],
4236 clear_vnc_prefix (&cda
);
4237 print_cleared_stats (&cda
);
4241 DEFUN (clear_vnc_mac_un_vn_prefix
,
4242 clear_vnc_mac_un_vn_prefix_cmd
,
4243 "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>",
4246 "Clear mac registration information\n"
4250 "Any virtual network identifier\n"
4251 "Virtual network identifier\n"
4252 "UN address of NVE\n"
4253 "All UN addresses\n"
4254 "UN IPv4 interface address\n"
4255 "UN IPv6 interface address\n"
4256 "VN address of NVE\n"
4257 "All VN addresses\n"
4258 "VN IPv4 interface address\n"
4259 "VN IPv6 interface address\n"
4260 "Clear prefix registration information\n"
4264 "Clear prefix registration information\n"
4269 struct rfapi_local_reg_delete_arg cda
;
4272 /* pfx vn un L2 VNI */
4274 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[9], argv
[7], argv
[3], argv
[5],
4278 clear_vnc_prefix (&cda
);
4279 print_cleared_stats (&cda
);
4283 DEFUN (clear_vnc_mac_un_prefix
,
4284 clear_vnc_mac_un_prefix_cmd
,
4285 "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>",
4288 "Clear mac registration information\n"
4292 "Any virtual network identifier\n"
4293 "Virtual network identifier\n"
4294 "UN address of NVE\n"
4295 "All UN addresses\n"
4296 "UN IPv4 interface address\n"
4297 "UN IPv6 interface address\n"
4298 "Clear prefix registration information\n"
4303 struct rfapi_local_reg_delete_arg cda
;
4306 /* pfx vn un L2 VNI */
4308 parse_deleter_tokens (vty
, NULL
, argv
[9], NULL
, argv
[7], argv
[3], argv
[5],
4312 clear_vnc_prefix (&cda
);
4313 print_cleared_stats (&cda
);
4317 DEFUN (clear_vnc_mac_vn_prefix
,
4318 clear_vnc_mac_vn_prefix_cmd
,
4319 "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>",
4322 "Clear mac registration information\n"
4326 "Any virtual network identifier\n"
4327 "Virtual network identifier\n"
4328 "UN address of NVE\n"
4329 "All VN addresses\n"
4330 "VN IPv4 interface address\n"
4331 "VN IPv6 interface address\n"
4332 "Clear prefix registration information\n"
4337 struct rfapi_local_reg_delete_arg cda
;
4340 /* pfx vn un L2 VNI */
4342 parse_deleter_tokens (vty
, NULL
, argv
[9], argv
[7], NULL
, argv
[3], argv
[5],
4346 clear_vnc_prefix (&cda
);
4347 print_cleared_stats (&cda
);
4351 DEFUN (clear_vnc_mac_all_prefix
,
4352 clear_vnc_mac_all_prefix_cmd
,
4353 "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>",
4356 "Clear mac registration information\n"
4360 "Any virtual network identifier\n"
4361 "Virtual network identifier\n"
4362 "UN address of NVE\n"
4363 "All VN addresses\n"
4364 "VN IPv4 interface address\n"
4365 "VN IPv6 interface address\n")
4367 struct rfapi_local_reg_delete_arg cda
;
4370 /* pfx vn un L2 VNI */
4372 parse_deleter_tokens (vty
, NULL
, argv
[7], NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4375 clear_vnc_prefix (&cda
);
4376 print_cleared_stats (&cda
);
4380 /************************************************************************
4382 ************************************************************************/
4385 /* copied from rfp_vty.c */
4387 check_and_display_is_vnc_running (struct vty
*vty
)
4389 if (!bgp_rfapi_is_vnc_configured (NULL
))
4390 return 1; /* is running */
4395 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)");
4397 return 0; /* not running */
4401 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4403 struct bgp
*bgp_default
= bgp_get_default ();
4405 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4407 int active_local_routes
;
4408 int active_remote_routes
;
4409 int holddown_remote_routes
;
4410 int imported_remote_routes
;
4415 h
= bgp_default
->rfapi
;
4420 /* don't show local info if not running RFP */
4421 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4427 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4428 vty_out (vty
, "%-24s ", "NVEs:");
4429 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4430 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4431 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4434 case SHOW_NVE_SUMMARY_REGISTERED
:
4436 * NB: With the introduction of L2 route support, we no
4437 * longer have a one-to-one correspondence between
4438 * locally-originated route advertisements and routes in
4439 * the import tables that have local origin. This
4440 * discrepancy arises because a single advertisement
4441 * may contain both an IP prefix and a MAC address.
4442 * Such an advertisement results in two import table
4443 * entries: one indexed by IP prefix, the other indexed
4446 * TBD: update computation and display of registration
4447 * statistics to reflect the underlying semantics.
4451 vty_out (vty
, "%-24s ", "Registrations:");
4452 vty_out (vty
, "%-8s %-8u ", "Active:",
4453 rfapiApCountAll (bgp_default
));
4454 vty_out (vty
, "%-8s %-8u ", "Failed:",
4455 h
->stat
.count_registrations_failed
);
4456 vty_out (vty
, "%-8s %-8u", "Total:",
4457 h
->stat
.count_registrations
);
4458 vty_out (vty
, VTYNL
);
4460 vty_out (vty
, "%-24s ", "Prefixes registered:");
4461 vty_out (vty
, VTYNL
);
4463 rfapiCountAllItRoutes (&active_local_routes
,
4464 &active_remote_routes
,
4465 &holddown_remote_routes
,
4466 &imported_remote_routes
);
4471 vty_out (vty
, " %-20s ", "Locally:");
4472 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4473 vty_out (vty
, VTYNL
);
4477 vty_out (vty
, " %-20s ", "Remotely:");
4478 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4479 vty_out (vty
, VTYNL
);
4480 vty_out (vty
, " %-20s ", "In Holddown:");
4481 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4482 vty_out (vty
, VTYNL
);
4483 vty_out (vty
, " %-20s ", "Imported:");
4484 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4487 case SHOW_NVE_SUMMARY_QUERIES
:
4488 vty_out (vty
, "%-24s ", "Queries:");
4489 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4490 vty_out (vty
, "%-8s %-8u ", "Failed:",
4491 h
->stat
.count_queries_failed
);
4492 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4495 case SHOW_NVE_SUMMARY_RESPONSES
:
4496 rfapiRibShowResponsesSummary (vty
);
4501 vty_out (vty
, VTYNL
);
4506 vty_outln (vty
, "VNC is not configured.");
4513 struct prefix
*vn_prefix
,
4514 struct prefix
*un_prefix
)
4516 //struct hash *rfds;
4517 //struct rfp_rfapi_descriptor_param param;
4519 struct bgp
*bgp_default
= bgp_get_default ();
4521 struct listnode
*node
;
4522 struct rfapi_descriptor
*rfd
;
4531 h
= bgp_default
->rfapi
;
4536 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4540 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4543 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4546 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4555 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4556 if (!prefix_match (vn_prefix
, &pfx
))
4562 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4563 if (!prefix_match (un_prefix
, &pfx
))
4567 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4568 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4572 /* print out a header */
4574 " " "Active Next Hops");
4575 vty_outln (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s",
4578 "Regis", "Resps", "Reach", "Remove", "Age");
4583 vty_outln (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s",
4587 rfapi_monitor_count (rfd
),
4588 rfd
->stat_count_nh_reachable
,
4589 rfd
->stat_count_nh_removal
,
4590 rfapiFormatAge(rfd
->open_time
, age
, 10));
4593 if (printed
> 0 || vn_prefix
|| un_prefix
)
4594 vty_outln (vty
, "Displayed %d out of %d active NVEs",
4600 vty_outln (vty
, "VNC is not configured.");
4605 DEFUN (vnc_show_summary
,
4606 vnc_show_summary_cmd
,
4610 "Display VNC status summary\n")
4612 if (!check_and_display_is_vnc_running (vty
))
4614 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4615 vty_out (vty
, VTYNL
);
4616 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4617 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4618 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4619 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4623 DEFUN (vnc_show_nves
,
4628 "List known NVEs\n")
4630 rfapi_show_nves (vty
, NULL
, NULL
);
4634 DEFUN (vnc_show_nves_ptct
,
4635 vnc_show_nves_ptct_cmd
,
4636 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4640 "VN address of NVE\n"
4641 "UN address of NVE\n"
4642 "IPv4 interface address\n"
4643 "IPv6 interface address\n")
4647 if (!check_and_display_is_vnc_running (vty
))
4650 if (!str2prefix (argv
[4]->arg
, &pfx
))
4652 vty_outln (vty
, "Malformed address \"%s\"", argv
[4]->arg
);
4655 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4657 vty_outln (vty
, "Invalid address \"%s\"", argv
[4]->arg
);
4661 if (argv
[3]->arg
[0] == 'u')
4663 rfapi_show_nves (vty
, NULL
, &pfx
);
4667 rfapi_show_nves (vty
, &pfx
, NULL
);
4673 /* adapted from rfp_registration_cache_log() */
4675 rfapi_show_registrations (
4677 struct prefix
*restrict_to
,
4688 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4692 /* non-expiring, local */
4693 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4697 /* non-expiring, non-local */
4698 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4702 /* expiring, including local */
4703 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4707 /* non-expiring, non-local */
4708 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4712 vty_out (vty
, VTYNL
);
4716 DEFUN (vnc_show_registrations_pfx
,
4717 vnc_show_registrations_pfx_cmd
,
4718 "show vnc registrations [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4721 "List active prefix registrations\n"
4722 "Limit output to a particular IPv4 prefix\n"
4723 "Limit output to a particular IPv6 prefix\n"
4724 "Limit output to a particular IPv6 address\n")
4727 struct prefix
*p_addr
= NULL
;
4731 if (!str2prefix (argv
[3]->arg
, &p
))
4733 vty_outln (vty
, "Invalid prefix: %s", argv
[3]->arg
);
4742 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4746 DEFUN (vnc_show_registrations_some_pfx
,
4747 vnc_show_registrations_some_pfx_cmd
,
4748 "show vnc registrations <all|holddown|imported|local|remote> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4751 "List active prefix registrations\n"
4752 "show all registrations\n"
4753 "show only registrations in holddown\n"
4754 "show only imported prefixes\n"
4755 "show only local registrations\n"
4756 "show only remote registrations\n"
4757 "Limit output to a particular prefix or address\n"
4758 "Limit output to a particular prefix or address\n"
4759 "Limit output to a particular prefix or address\n")
4762 struct prefix
*p_addr
= NULL
;
4765 int show_remote
= 0;
4766 int show_holddown
= 0;
4767 int show_imported
= 0;
4771 if (!str2prefix (argv
[4]->arg
, &p
))
4773 vty_outln (vty
, "Invalid prefix: %s", argv
[4]->arg
);
4781 switch (argv
[3]->arg
[0])
4807 rfapi_show_registrations (vty
, p_addr
,
4808 show_local
, show_remote
, show_holddown
,
4813 DEFUN (vnc_show_responses_pfx
,
4814 vnc_show_responses_pfx_cmd
,
4815 "show vnc responses [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4818 "List recent query responses\n"
4819 "Limit output to a particular IPv4 prefix\n"
4820 "Limit output to a particular IPv6 prefix\n"
4821 "Limit output to a particular IPv6 address\n" )
4824 struct prefix
*p_addr
= NULL
;
4828 if (!str2prefix (argv
[3]->arg
, &p
))
4830 vty_outln (vty
, "Invalid prefix: %s", argv
[3]->arg
);
4838 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4840 rfapiRibShowResponsesSummary (vty
);
4842 rfapiRibShowResponses (vty
, p_addr
, 0);
4843 rfapiRibShowResponses (vty
, p_addr
, 1);
4848 DEFUN (vnc_show_responses_some_pfx
,
4849 vnc_show_responses_some_pfx_cmd
,
4850 "show vnc responses <active|removed> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4853 "List recent query responses\n"
4854 "show only active query responses\n"
4855 "show only removed query responses\n"
4856 "Limit output to a particular IPv4 prefix\n"
4857 "Limit output to a particular IPv6 prefix\n"
4858 "Limit output to a particular IPV6 address\n")
4861 struct prefix
*p_addr
= NULL
;
4863 int show_active
= 0;
4864 int show_removed
= 0;
4866 if (!check_and_display_is_vnc_running (vty
))
4871 if (!str2prefix (argv
[4]->arg
, &p
))
4873 vty_outln (vty
, "Invalid prefix: %s", argv
[4]->arg
);
4882 switch (argv
[3]->arg
[0])
4893 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4895 rfapiRibShowResponsesSummary (vty
);
4898 rfapiRibShowResponses (vty
, p_addr
, 0);
4900 rfapiRibShowResponses (vty
, p_addr
, 1);
4905 DEFUN (show_vnc_queries_pfx
,
4906 show_vnc_queries_pfx_cmd
,
4907 "show vnc queries [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4910 "List active queries\n"
4911 "Limit output to a particular IPv4 prefix or address\n"
4912 "Limit output to a particular IPv6 prefix\n"
4913 "Limit output to a particualr IPV6 address\n")
4916 struct prefix
*p
= NULL
;
4920 if (!str2prefix (argv
[3]->arg
, &pfx
))
4922 vty_outln (vty
, "Invalid prefix: %s", argv
[3]->arg
);
4928 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4930 return rfapiShowVncQueries (vty
, p
);
4933 DEFUN (vnc_clear_counters
,
4934 vnc_clear_counters_cmd
,
4935 "clear vnc counters",
4938 "Reset VNC counters\n")
4940 struct bgp
*bgp_default
= bgp_get_default ();
4942 struct listnode
*node
;
4943 struct rfapi_descriptor
*rfd
;
4948 h
= bgp_default
->rfapi
;
4954 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4956 rfd
->stat_count_nh_reachable
= 0;
4957 rfd
->stat_count_nh_removal
= 0;
4961 memset (&h
->stat
, 0, sizeof (h
->stat
));
4964 * 151122 per bug 103, set count_registrations = number active.
4965 * Do same for queries
4967 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4968 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4970 rfapiRibShowResponsesSummaryClear ();
4975 vty_outln (vty
, "VNC is not configured.");
4979 /************************************************************************
4980 * Add prefix with vrf
4982 * add [vrf <vrf-name>] prefix <prefix>
4983 * [rd <value>] [label <value>] [local-preference <0-4294967295>]
4984 ************************************************************************/
4986 vnc_add_vrf_prefix (struct vty
*vty
,
4987 const char *arg_vrf
,
4988 const char *arg_prefix
,
4989 const char *arg_rd
, /* optional */
4990 const char *arg_label
, /* optional */
4991 const char *arg_pref
) /* optional */
4994 struct rfapi_nve_group_cfg
*rfg
;
4996 struct rfapi_ip_prefix rpfx
;
4998 struct rfapi_vn_option optary
[3];
4999 struct rfapi_vn_option
*opt
= NULL
;
5002 bgp
= bgp_get_default (); /* assume main instance for now */
5005 vty_outln (vty
, "No BGP process is configured");
5006 return CMD_WARNING_CONFIG_FAILED
;
5008 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5010 vty_outln (vty
, "VRF support not configured");
5011 return CMD_WARNING_CONFIG_FAILED
;
5014 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5018 vty_outln (vty
, "VRF \"%s\" appears not to be configured.",
5020 return CMD_WARNING_CONFIG_FAILED
;
5022 if (!rfg
->rt_export_list
|| !rfg
->rfapi_import_table
)
5024 vty_outln (vty
, "VRF \"%s\" is missing RT import/export RT configuration.",
5026 return CMD_WARNING_CONFIG_FAILED
;
5028 if (!rfg
->rd
.family
&& !arg_rd
)
5030 vty_outln (vty
, "VRF \"%s\" isn't configured with an RD, so RD must be provided.",
5032 return CMD_WARNING_CONFIG_FAILED
;
5034 if (rfg
->label
> MPLS_LABEL_MAX
&& !arg_label
)
5036 vty_outln (vty
, "VRF \"%s\" isn't configured with a default labels, so a label must be provided.",
5038 return CMD_WARNING_CONFIG_FAILED
;
5040 if (!str2prefix (arg_prefix
, &pfx
))
5042 vty_outln (vty
, "Malformed prefix \"%s\"",
5044 return CMD_WARNING_CONFIG_FAILED
;
5046 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
5047 memset (optary
, 0, sizeof (optary
));
5051 opt
->next
= &optary
[cur_opt
];
5052 opt
= &optary
[cur_opt
++];
5053 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
5054 if (!str2prefix_rd (arg_rd
, &opt
->v
.internal_rd
))
5056 vty_outln (vty
, "Malformed RD \"%s\"",
5058 return CMD_WARNING_CONFIG_FAILED
;
5061 if (rfg
->label
<= MPLS_LABEL_MAX
|| arg_label
)
5063 struct rfapi_l2address_option
*l2o
;
5065 opt
->next
= &optary
[cur_opt
];
5066 opt
= &optary
[cur_opt
++];
5067 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
5068 l2o
= &opt
->v
.l2addr
;
5072 label
= strtoul(arg_label
, NULL
, 10);
5076 l2o
->label
= rfg
->label
;
5080 char *endptr
= NULL
;
5081 pref
= strtoul (arg_pref
, &endptr
, 10);
5082 if (*endptr
!= '\0')
5084 vty_outln (vty
, "%% Invalid local-preference value \"%s\"",
5086 return CMD_WARNING_CONFIG_FAILED
;
5089 rpfx
.cost
= 255 - (pref
& 255) ;
5090 if (rfg
->rfd
== NULL
) /* need new rfapi_handle */
5092 /* based on rfapi_open */
5093 struct rfapi_descriptor
*rfd
;
5094 rfd
= XCALLOC (MTYPE_RFAPI_DESC
, sizeof (struct rfapi_descriptor
));
5097 /* leave most fields empty as will get from (dynamic) config when needed */
5098 rfd
->default_tunneltype_option
.type
= BGP_ENCAP_TYPE_MPLS
;
5100 if (rfg
->vn_prefix
.family
&&
5101 !CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
))
5103 rfapiQprefix2Raddr(&rfg
->vn_prefix
, &rfd
->vn_addr
);
5107 memset(&rfd
->vn_addr
, 0, sizeof(struct rfapi_ip_addr
));
5108 rfd
->vn_addr
.addr_family
= AF_INET
;
5109 rfd
->vn_addr
.addr
.v4
= bgp
->router_id
;
5111 rfd
->un_addr
= rfd
->vn_addr
; /* sigh, need something in UN for lookups */
5112 vnc_zlog_debug_verbose ("%s: Opening RFD for VRF %s",
5113 __func__
, rfg
->name
);
5114 rfapi_init_and_open(bgp
, rfd
, rfg
);
5117 if (!rfapi_register (rfg
->rfd
, &rpfx
, RFAPI_INFINITE_LIFETIME
, NULL
,
5118 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_ADD
))
5120 struct rfapi_next_hop_entry
*head
= NULL
;
5121 struct rfapi_next_hop_entry
*tail
= NULL
;
5122 struct rfapi_vn_option
*vn_opt_new
;
5124 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded", __func__
);
5126 if (bgp
->rfapi
->rfp_methods
.local_cb
)
5128 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfg
->rfd
;
5129 vn_opt_new
= rfapi_vn_options_dup (opt
);
5131 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
5132 1, RFAPI_INFINITE_LIFETIME
,
5133 vn_opt_new
, &head
, &tail
);
5136 bgp
->rfapi
->flags
|= RFAPI_INCALLBACK
;
5137 (*bgp
->rfapi
->rfp_methods
.local_cb
) (head
, r
->cookie
);
5138 bgp
->rfapi
->flags
&= ~RFAPI_INCALLBACK
;
5142 vnc_zlog_debug_verbose ("%s completed, count=%d/%d", __func__
,
5143 rfg
->rfapi_import_table
->local_count
[AFI_IP
],
5144 rfg
->rfapi_import_table
->local_count
[AFI_IP6
]);
5148 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
5149 vty_outln (vty
, "Add failed.");
5150 return CMD_WARNING_CONFIG_FAILED
;
5153 DEFUN (add_vrf_prefix_rd_label_pref
,
5154 add_vrf_prefix_rd_label_pref_cmd
,
5155 "add vrf NAME prefix <A.B.C.D/M|X:X::X:X/M> [{rd ASN:nn_or_IP-address|label (0-1048575)|preference (0-4294967295)}]",
5159 "Add/modify prefix related information\n"
5162 "Override configured VRF Route Distinguisher\n"
5163 "<as-number>:<number> or <ip-address>:<number>\n"
5164 "Override configured VRF label\n"
5165 "Label Value <0-1048575>\n"
5166 "Set advertised local preference\n"
5167 "local preference (higher=more preferred)\n")
5169 char *arg_vrf
= argv
[2]->arg
;
5170 char *arg_prefix
= argv
[4]->arg
;
5171 char *arg_rd
= NULL
; /* optional */
5172 char *arg_label
= NULL
; /* optional */
5173 char *arg_pref
= NULL
; /* optional */
5175 argc
--; /* don't parse argument */
5176 while (pargc
< argc
)
5178 switch (argv
[pargc
++]->arg
[0])
5181 arg_rd
= argv
[pargc
]->arg
;
5184 arg_label
= argv
[pargc
]->arg
;
5187 arg_pref
= argv
[pargc
]->arg
;
5195 return vnc_add_vrf_prefix (vty
, arg_vrf
, arg_prefix
, arg_rd
, arg_label
, arg_pref
);
5198 /************************************************************************
5199 * del prefix with vrf
5201 * clear [vrf <vrf-name>] prefix <prefix> [rd <value>]
5202 ************************************************************************/
5204 rfapi_cfg_group_it_count(struct rfapi_nve_group_cfg
*rfg
)
5207 afi_t afi
= AFI_MAX
;
5210 count
+= rfg
->rfapi_import_table
->local_count
[afi
];
5216 clear_vnc_vrf_closer (struct rfapi_nve_group_cfg
*rfg
)
5218 struct rfapi_descriptor
*rfd
= rfg
->rfd
;
5223 /* check if IT is empty */
5225 afi
< AFI_MAX
&& rfg
->rfapi_import_table
->local_count
[afi
] == 0;
5230 vnc_zlog_debug_verbose ("%s: closing RFD for VRF %s",
5231 __func__
, rfg
->name
);
5237 vnc_zlog_debug_verbose ("%s: VRF %s afi=%d count=%d",
5238 __func__
, rfg
->name
, afi
,
5239 rfg
->rfapi_import_table
->local_count
[afi
]);
5244 vnc_clear_vrf (struct vty
*vty
,
5246 const char *arg_vrf
,
5247 const char *arg_prefix
, /* NULL = all */
5248 const char *arg_rd
) /* optional */
5250 struct rfapi_nve_group_cfg
*rfg
;
5251 struct rfapi_local_reg_delete_arg cda
;
5256 bgp
= bgp_get_default (); /* assume main instance for now */
5259 vty_outln (vty
, "No BGP process is configured");
5262 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5264 vty_outln (vty
, "VRF support not configured");
5267 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5271 vty_outln (vty
, "VRF \"%s\" appears not to be configured.",
5275 rc
= parse_deleter_args (vty
, bgp
, arg_prefix
, NULL
, NULL
, NULL
, NULL
,
5277 if (rc
!= CMD_SUCCESS
) /* parse error */
5280 start_count
= rfapi_cfg_group_it_count(rfg
);
5281 clear_vnc_prefix (&cda
);
5282 clear_vnc_vrf_closer (rfg
);
5283 vty_outln (vty
, "Cleared %u out of %d prefixes.",
5284 cda
.pfx_count
, start_count
);
5288 DEFUN (clear_vrf_prefix_rd
,
5289 clear_vrf_prefix_rd_cmd
,
5290 "clear vrf NAME [prefix <A.B.C.D/M|X:X::X:X/M>] [rd ASN:nn_or_IP-address]",
5291 "Clear stored data\n"
5294 "Prefix related information\n"
5297 "Specific VRF Route Distinguisher\n"
5298 "<as-number>:<number> or <ip-address>:<number>\n")
5300 char *arg_vrf
= argv
[2]->arg
;
5301 char *arg_prefix
= NULL
; /* optional */
5302 char *arg_rd
= NULL
; /* optional */
5304 argc
--; /* don't check parameter */
5305 while (pargc
< argc
)
5307 switch (argv
[pargc
++]->arg
[0])
5310 arg_rd
= argv
[pargc
]->arg
;
5313 arg_prefix
= argv
[pargc
]->arg
;
5320 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, arg_prefix
, arg_rd
);
5323 DEFUN (clear_vrf_all
,
5325 "clear vrf NAME all",
5326 "Clear stored data\n"
5331 char *arg_vrf
= argv
[2]->arg
;
5332 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, NULL
, NULL
);
5335 void rfapi_vty_init ()
5337 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
5338 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
5339 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
5340 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
5341 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
5343 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
5344 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
5345 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
5346 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
5347 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
5349 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
5350 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
5351 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
5352 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
5353 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
5354 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
5355 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
5356 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
5358 install_element (ENABLE_NODE
, &add_vrf_prefix_rd_label_pref_cmd
);
5360 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
5361 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
5362 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
5363 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
5364 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
5366 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
5367 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
5368 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
5369 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
5370 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
5372 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
5373 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
5374 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
5375 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
5376 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
5378 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
5379 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
5380 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
5381 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
5382 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
5384 install_element (ENABLE_NODE
, &clear_vrf_prefix_rd_cmd
);
5385 install_element (ENABLE_NODE
, &clear_vrf_all_cmd
);
5387 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
5389 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
5390 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
5391 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
5393 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
5394 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
5395 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
5396 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
5397 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);