3 * Copyright 2009-2016, LabN Consulting, L.L.C.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "lib/zebra.h"
26 #include "lib/prefix.h"
27 #include "lib/table.h"
29 #include "lib/memory.h"
30 #include "lib/routemap.h"
32 #include "lib/linklist.h"
33 #include "lib/command.h"
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_ecommunity.h"
37 #include "bgpd/bgp_attr.h"
38 #include "bgpd/bgp_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 (NULL
, 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 HVTY_NEWLINE ((vty == &vty_dummy_zlog)? "": VTY_NEWLINE)
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 VTY_NEWLINE */
410 *vty
= &vty_dummy_zlog
;
411 *fp
= (int (*)(void *, const char *,...)) rfapiDebugPrintf
;
413 *vty_newline
= str_vty_newline (*vty
);
414 return (vzlog_test (NULL
, 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 VTY_NEWLINE */
422 *vty
= &vty_dummy_stdio
;
423 *fp
= (int (*)(void *, const char *,...)) rfapiStdioPrintf
;
425 *vty_newline
= str_vty_newline (*vty
);
431 *vty
= stream
; /* VTY_NEWLINE 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
->extra
&& bi
->attr
->extra
->ecommunity
)
474 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
475 ECOMMUNITY_FORMAT_ROUTE_MAP
);
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
->tag
));
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", HVTY_NEWLINE
);
495 rfapiPrintAttrPtrs (void *stream
, struct attr
*attr
)
497 int (*fp
) (void *, const char *, ...);
500 const char *vty_newline
;
502 struct attr_extra
*ae
;
505 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
508 fp (out
, "Attr[%p]:%s", attr
, HVTY_NEWLINE
);
513 inet_ntop (AF_INET
, &attr
->nexthop
, buf
, BUFSIZ
);
514 fp (out
, " nexthop=%s%s", buf
, HVTY_NEWLINE
);
516 fp (out
, " aspath=%p, refcnt=%d%s", attr
->aspath
,
517 (attr
->aspath
? attr
->aspath
->refcnt
: 0), HVTY_NEWLINE
);
518 fp (out
, " community=%p, refcnt=%d%s", attr
->community
,
519 (attr
->community
? attr
->community
->refcnt
: 0), HVTY_NEWLINE
);
521 if ((ae
= attr
->extra
))
523 fp (out
, " ecommunity=%p, refcnt=%d%s", ae
->ecommunity
,
524 (ae
->ecommunity
? ae
->ecommunity
->refcnt
: 0), HVTY_NEWLINE
);
525 fp (out
, " cluster=%p, refcnt=%d%s", ae
->cluster
,
526 (ae
->cluster
? ae
->cluster
->refcnt
: 0), HVTY_NEWLINE
);
527 fp (out
, " transit=%p, refcnt=%d%s", ae
->transit
,
528 (ae
->transit
? ae
->transit
->refcnt
: 0), HVTY_NEWLINE
);
533 * Print BI in an Import Table
536 rfapiPrintBi (void *stream
, struct bgp_info
*bi
)
541 int (*fp
) (void *, const char *, ...);
544 const char *vty_newline
;
550 struct ethaddr macaddr
;
551 struct rfapi_l2address_option l2o_buf
;
552 uint8_t l2hid
=0; /* valid if has_macaddr */
554 #define REMAIN (BUFSIZ - (p-line))
555 #define INCP {p += (r > REMAIN)? REMAIN: r;}
557 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
563 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) && bi
->extra
564 && bi
->extra
->vnc
.import
.timer
)
566 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
567 r
= snprintf (p
, REMAIN
, " [%4lu] ", thread_timer_remain_second (t
));
573 r
= snprintf (p
, REMAIN
, " ");
579 /* TBD This valid only for SAFI_MPLS_VPN, but not for encap */
580 if (decode_rd_type(bi
->extra
->vnc
.import
.rd
.val
) == RD_TYPE_VNC_ETH
)
583 memcpy (macaddr
.octet
, bi
->extra
->vnc
.import
.rd
.val
+ 2, 6);
584 l2hid
= bi
->extra
->vnc
.import
.rd
.val
[1];
593 * RFP option sizes (they are opaque values)
594 * extended communities (RTs)
596 if (bi
->attr
&& bi
->attr
->extra
)
599 int printed_1st_gol
= 0;
600 struct bgp_attr_encap_subtlv
*pEncap
;
601 struct prefix pfx_un
;
602 int af
= BGP_MP_NEXTHOP_FAMILY (bi
->attr
->extra
->mp_nexthop_len
);
607 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET
,
608 &bi
->attr
->extra
->mp_nexthop_global_in
,
612 else if (af
== AF_INET6
)
614 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET6
,
615 &bi
->attr
->extra
->mp_nexthop_global
,
621 r
= snprintf (p
, REMAIN
, "?");
626 * VNC tunnel subtlv, if present, contains UN address
628 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
630 r
= snprintf (p
, REMAIN
, " un=%s", inet_ntop (pfx_un
.family
,
638 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
))
640 r
= snprintf (p
, REMAIN
, " nolife");
645 if (lifetime
== 0xffffffff)
646 r
= snprintf (p
, REMAIN
, " %6s", "infini");
648 r
= snprintf (p
, REMAIN
, " %6u", lifetime
);
652 /* RFP option lengths */
653 for (pEncap
= bi
->attr
->extra
->vnc_subtlvs
; pEncap
;
654 pEncap
= pEncap
->next
)
657 if (pEncap
->type
== BGP_VNC_SUBTLV_TYPE_RFPOPTION
)
661 r
= snprintf (p
, REMAIN
, ",");
666 r
= snprintf (p
, REMAIN
, " "); /* leading space */
669 r
= snprintf (p
, REMAIN
, "%d", pEncap
->length
);
676 if (bi
->attr
->extra
->ecommunity
)
678 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
679 ECOMMUNITY_FORMAT_ROUTE_MAP
);
680 r
= snprintf (p
, REMAIN
, " %s", s
);
682 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
687 r
= snprintf (p
, REMAIN
, " bi@%p", bi
);
690 r
= snprintf (p
, REMAIN
, " p@%p", bi
->peer
);
693 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
695 r
= snprintf (p
, REMAIN
, " HD=yes");
700 r
= snprintf (p
, REMAIN
, " HD=no");
709 r
= snprintf (p
, REMAIN
, " W=%d", bi
->attr
->extra
->weight
);
713 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
715 r
= snprintf (p
, REMAIN
, " LP=%d", bi
->attr
->local_pref
);
720 r
= snprintf (p
, REMAIN
, " LP=unset");
726 snprintf (p
, REMAIN
, " %c:%u", zebra_route_char (bi
->type
), bi
->sub_type
);
729 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
733 fp (out
, " RD HID=%d ETH=%02x:%02x:%02x:%02x:%02x:%02x%s",
738 macaddr
.octet
[3], macaddr
.octet
[4], macaddr
.octet
[5], HVTY_NEWLINE
);
741 if (!rfapiGetL2o (bi
->attr
, &l2o_buf
))
744 " L2O ETH=%02x:%02x:%02x:%02x:%02x:%02x LBL=%d LNI=%d LHI=%hhu%s",
745 l2o_buf
.macaddr
.octet
[0], l2o_buf
.macaddr
.octet
[1],
746 l2o_buf
.macaddr
.octet
[2], l2o_buf
.macaddr
.octet
[3],
747 l2o_buf
.macaddr
.octet
[4], l2o_buf
.macaddr
.octet
[5], l2o_buf
.label
,
748 l2o_buf
.logical_net_id
, l2o_buf
.local_nve_id
, HVTY_NEWLINE
);
750 if (bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
755 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
756 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
761 fp (out
, " IP: %s%s", sp
, HVTY_NEWLINE
);
765 struct rfapi_un_option
*uo
= rfapi_encap_tlv_to_un_option (bi
->attr
);
768 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
769 rfapi_un_options_free (uo
);
775 rfapiMonitorVpn2Str (struct rfapi_monitor_vpn
*m
, char *buf
, int size
)
777 char buf_pfx
[BUFSIZ
];
782 rfapiRfapiIpAddr2Str (&m
->rfd
->un_addr
, buf_vn
, BUFSIZ
);
783 rfapiRfapiIpAddr2Str (&m
->rfd
->vn_addr
, buf_un
, BUFSIZ
);
785 rc
= snprintf (buf
, size
,
786 "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p",
787 m
, m
->next
, m
->rfd
, buf_vn
, buf_un
,
788 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
789 m
->p
.prefixlen
, m
->node
);
797 rfapiDebugPrintMonitorVpn (void *stream
, struct rfapi_monitor_vpn
*m
)
801 int (*fp
) (void *, const char *, ...);
804 const char *vty_newline
;
806 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
809 rfapiMonitorVpn2Str (m
, buf
, BUFSIZ
);
810 fp (out
, " Mon %s%s", buf
, HVTY_NEWLINE
);
814 rfapiDebugPrintMonitorEncap (void *stream
, struct rfapi_monitor_encap
*m
)
816 int (*fp
) (void *, const char *, ...);
819 const char *vty_newline
;
821 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
824 fp (out
, " Mon m=%p, next=%p, node=%p, bi=%p%s",
825 m
, m
->next
, m
->node
, m
->bi
, HVTY_NEWLINE
);
829 rfapiShowItNode (void *stream
, struct route_node
*rn
)
834 int (*fp
) (void *, const char *, ...);
837 const char *vty_newline
;
839 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
842 fp (out
, "%s/%d @%p #%d%s",
843 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
844 rn
->p
.prefixlen
, rn
, rn
->lock
, HVTY_NEWLINE
);
846 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
848 rfapiPrintBi (stream
, bi
);
851 /* doesn't show montors */
855 rfapiShowImportTable (
858 struct route_table
*rt
,
861 struct route_node
*rn
;
864 int (*fp
) (void *, const char *, ...);
867 const char *vty_newline
;
869 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
872 fp (out
, "Import Table [%s]%s", label
, HVTY_NEWLINE
);
874 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
878 if (rn
->p
.family
== AF_ETHERNET
)
880 rfapiEthAddr2Str (&rn
->p
.u
.prefix_eth
, buf
, BUFSIZ
);
884 inet_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
);
887 fp (out
, "%s/%d @%p #%d%s", buf
, rn
->p
.prefixlen
, rn
, rn
->lock
- 1, /* account for loop iterator locking */
890 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
892 rfapiPrintBi (stream
, bi
);
897 struct rfapi_monitor_vpn
*m
;
898 for (m
= RFAPI_MONITOR_VPN (rn
); m
; m
= m
->next
)
900 rfapiDebugPrintMonitorVpn (stream
, m
);
905 struct rfapi_monitor_encap
*m
;
906 for (m
= RFAPI_MONITOR_ENCAP (rn
); m
; m
= m
->next
)
908 rfapiDebugPrintMonitorEncap (stream
, m
);
915 rfapiShowVncQueries (void *stream
, struct prefix
*pfx_match
)
919 struct listnode
*node
;
920 struct rfapi_descriptor
*rfd
;
922 int (*fp
) (void *, const char *, ...);
925 const char *vty_newline
;
927 int printedheader
= 0;
930 int nves_with_queries
= 0;
931 int nves_displayed
= 0;
933 int queries_total
= 0;
934 int queries_displayed
= 0;
936 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
939 bgp
= bgp_get_default (); /* assume 1 instance for now */
942 vty_out (vty
, "No BGP instance%s", VTY_NEWLINE
);
949 vty_out (vty
, "No RFAPI instance%s", VTY_NEWLINE
);
953 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
956 struct route_node
*rn
;
957 int printedquerier
= 0;
962 if (rfd
->mon
|| (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
)))
976 for (rn
= route_top (rfd
->mon
); rn
; rn
= route_next (rn
))
978 struct rfapi_monitor_vpn
*m
;
979 char buf_remain
[BUFSIZ
];
980 char buf_pfx
[BUFSIZ
];
989 if (pfx_match
&& !prefix_match (pfx_match
, &rn
->p
) &&
990 !prefix_match (&rn
->p
, pfx_match
))
998 fp (out
, "%s", VTY_NEWLINE
);
999 fp (out
, "%-15s %-15s %-15s %-10s%s",
1000 "VN Address", "UN Address",
1001 "Target", "Remaining", VTY_NEWLINE
);
1004 if (!printedquerier
)
1006 char buf_vn
[BUFSIZ
];
1007 char buf_un
[BUFSIZ
];
1009 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1010 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1012 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1018 fp (out
, "%-15s %-15s", "", "");
1022 rfapiFormatSeconds (thread_timer_remain_second (m
->timer
),
1023 buf_remain
, BUFSIZ
);
1025 fp (out
, " %-15s %-10s%s",
1026 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
1027 buf_remain
, VTY_NEWLINE
);
1034 if (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
))
1039 struct rfapi_monitor_eth
*mon_eth
;
1043 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1046 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1050 char buf_remain
[BUFSIZ
];
1051 char buf_pfx
[BUFSIZ
];
1052 struct prefix pfx_mac
;
1056 vnc_zlog_debug_verbose ("%s: checking rfd=%p mon_eth=%p", __func__
, rfd
,
1059 memset ((void *) &pfx_mac
, 0, sizeof (struct prefix
));
1060 pfx_mac
.family
= AF_ETHERNET
;
1061 pfx_mac
.prefixlen
= 48;
1062 pfx_mac
.u
.prefix_eth
= mon_eth
->macaddr
;
1064 if (pfx_match
&& !prefix_match (pfx_match
, &pfx_mac
) &&
1065 !prefix_match (&pfx_mac
, pfx_match
))
1068 ++queries_displayed
;
1073 fp (out
, "%s", VTY_NEWLINE
);
1074 fp (out
, "%-15s %-15s %-17s %10s %-10s%s",
1075 "VN Address", "UN Address",
1076 "Target", "LNI", "Remaining", VTY_NEWLINE
);
1079 if (!printedquerier
)
1081 char buf_vn
[BUFSIZ
];
1082 char buf_un
[BUFSIZ
];
1084 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1085 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1087 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1093 fp (out
, "%-15s %-15s", "", "");
1097 rfapiFormatSeconds (thread_timer_remain_second
1098 (mon_eth
->timer
), buf_remain
, BUFSIZ
);
1100 fp (out
, " %-17s %10d %-10s%s",
1101 rfapi_ntop (pfx_mac
.family
, &pfx_mac
.u
.prefix
, buf_pfx
,
1102 BUFSIZ
), mon_eth
->logical_net_id
, buf_remain
,
1110 fp (out
, "%s", VTY_NEWLINE
);
1111 fp (out
, "Displayed %d out of %d total queries%s",
1112 queries_displayed
, queries_total
, VTY_NEWLINE
);
1118 rfapiPrintRemoteRegBi (
1121 struct route_node
*rn
,
1122 struct bgp_info
*bi
)
1124 int (*fp
) (void *, const char *, ...);
1127 const char *vty_newline
;
1128 struct prefix pfx_un
;
1129 struct prefix pfx_vn
;
1132 bgp_encap_types tun_type
;
1134 char buf_pfx
[BUFSIZ
];
1135 char buf_ntop
[BUFSIZ
];
1136 char buf_un
[BUFSIZ
];
1137 char buf_vn
[BUFSIZ
];
1138 char buf_lifetime
[BUFSIZ
];
1142 return 0; /* for debug log, print into buf & call output once */
1144 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1151 snprintf (buf_pfx
, BUFSIZ
, "%s/%d",
1152 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf_ntop
, BUFSIZ
),
1154 buf_pfx
[BUFSIZ
- 1] = 0;
1161 if (!rfapiGetUnAddrOfVpnBi (bi
, &pfx_un
))
1163 snprintf (buf_un
, BUFSIZ
, "%s",
1164 inet_ntop (pfx_un
.family
, &pfx_un
.u
.prefix
, buf_ntop
,
1168 rfapiGetTunnelType(bi
->attr
,&tun_type
);
1173 rfapiNexthop2Prefix (bi
->attr
, &pfx_vn
);
1174 if (tun_type
== BGP_ENCAP_TYPE_MPLS
)
1176 /* MPLS carries un in nrli next hop (same as vn for IP tunnels) */
1177 snprintf (buf_un
, BUFSIZ
, "%s",
1178 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1181 u_int32_t l
= decode_label (bi
->extra
->tag
);
1182 snprintf (buf_vn
, BUFSIZ
, "Label: %d", l
);
1184 else /* should never happen */
1186 snprintf (buf_vn
, BUFSIZ
, "Label: N/A");
1191 snprintf (buf_vn
, BUFSIZ
, "%s",
1192 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1194 buf_vn
[BUFSIZ
- 1] = 0;
1195 buf_un
[BUFSIZ
- 1] = 0;
1198 * Cost is encoded in local_pref as (255-cost)
1199 * See rfapi_import.c'rfapiRouteInfo2NextHopEntry() for conversion
1204 uint32_t local_pref
;
1205 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1206 local_pref
= bi
->attr
->local_pref
;
1209 cost
= (local_pref
> 255) ? 0 : 255 - local_pref
;
1216 fp (out
, "%-20s ", buf_pfx
);
1217 fp (out
, "%-15s ", buf_vn
);
1218 fp (out
, "%-15s ", buf_un
);
1219 fp (out
, "%-4d ", cost
);
1222 /* NB rfapiGetVncLifetime sets infinite value when returning !0 */
1223 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
) ||
1224 (lifetime
== RFAPI_INFINITE_LIFETIME
))
1227 fp (out
, "%-10s ", "infinite");
1231 time_t t_lifetime
= lifetime
;
1232 rfapiFormatSeconds (t_lifetime
, buf_lifetime
, BUFSIZ
);
1233 fp (out
, "%-10s ", buf_lifetime
);
1236 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) &&
1237 bi
->extra
&& bi
->extra
->vnc
.import
.timer
)
1242 char buf_age
[BUFSIZ
];
1244 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
1245 remaining
= thread_timer_remain_second (t
);
1247 #if RFAPI_REGISTRATIONS_REPORT_AGE
1249 * Calculate when the timer started. Doing so here saves
1250 * us a timestamp field in "struct bgp_info".
1252 * See rfapi_import.c'rfapiBiStartWithdrawTimer() for the
1253 * original calculation.
1255 age
= rfapiGetHolddownFromLifetime (lifetime
, factor
) - remaining
;
1256 #else /* report remaining time */
1259 rfapiFormatSeconds (age
, buf_age
, BUFSIZ
);
1261 fp (out
, "%-10s ", buf_age
);
1264 else if (RFAPI_LOCAL_BI (bi
))
1267 char buf_age
[BUFSIZ
];
1269 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.create_time
)
1271 rfapiFormatAge (bi
->extra
->vnc
.import
.create_time
, buf_age
, BUFSIZ
);
1278 fp (out
, "%-10s ", buf_age
);
1280 fp (out
, "%s", HVTY_NEWLINE
);
1282 if (rn
->p
.family
== AF_ETHERNET
)
1285 * If there is a corresponding IP address && != VN address,
1286 * print that on the next line
1289 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
1293 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
1294 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
1296 buf_ntop
[BUFSIZ
- 1] = 0;
1298 if (sp
&& strcmp (buf_vn
, sp
) != 0)
1300 fp (out
, " IP: %s", sp
);
1306 if (tun_type
!= BGP_ENCAP_TYPE_MPLS
&& bi
->extra
)
1308 u_int32_t l
= decode_label (bi
->extra
->tag
);
1309 if (!MPLS_LABEL_IS_NULL (l
))
1311 fp (out
, " Label: %d", l
);
1317 fp (out
, "%s", HVTY_NEWLINE
);
1323 rfapiShowRemoteRegistrationsIt (
1326 struct rfapi_import_table
*it
,
1327 struct prefix
*prefix_only
,
1328 int show_expiring
, /* either/or */
1331 int show_imported
, /* either/or */
1332 uint32_t *pLni
) /* AFI_ETHER only */
1335 int printed_rtlist_hdr
= 0;
1337 int (*fp
) (void *, const char *, ...);
1340 const char *vty_newline
;
1344 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1347 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1350 struct route_node
*rn
;
1352 if (!it
->imported_vpn
[afi
])
1355 for (rn
= route_top (it
->imported_vpn
[afi
]); rn
; rn
= route_next (rn
))
1358 struct bgp_info
*bi
;
1361 /* allow for wider or more narrow mask from user */
1363 !prefix_match (prefix_only
, &rn
->p
) &&
1364 !prefix_match (&rn
->p
, prefix_only
))
1369 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
1372 if (!show_local
&& RFAPI_LOCAL_BI (bi
))
1375 /* local route from RFP */
1379 if (!show_remote
&& !RFAPI_LOCAL_BI (bi
))
1386 if (show_expiring
&& !CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1389 if (!show_expiring
&& CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1392 if (bi
->type
== ZEBRA_ROUTE_BGP_DIRECT
||
1393 bi
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
)
1405 if (count_only
== 1)
1407 if (!printed_rtlist_hdr
)
1409 const char *agetype
= "";
1411 const char *type
= "";
1424 if (RFAPI_LOCAL_BI (bi
))
1435 s
= ecommunity_ecom2str (it
->rt_import_list
,
1436 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1440 fp (out
, "%s[%s] L2VPN Network 0x%x (%u) RT={%s}",
1441 HVTY_NEWLINE
, type
, *pLni
, (*pLni
& 0xfff), s
);
1445 fp (out
, "%s[%s] Prefix RT={%s}",
1446 HVTY_NEWLINE
, type
, s
);
1448 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1450 if (it
->rfg
&& it
->rfg
->name
)
1452 fp (out
, " %s \"%s\"",
1453 (it
->rfg
->type
== RFAPI_GROUP_CFG_VRF
?
1454 "VRF" : "NVE group"),
1457 fp (out
, "%s", HVTY_NEWLINE
);
1460 #if RFAPI_REGISTRATIONS_REPORT_AGE
1463 agetype
= "Remaining";
1466 else if (show_local
)
1471 printed_rtlist_hdr
= 1;
1473 fp (out
, "%-20s %-15s %-15s %4s %-10s %-10s%s",
1474 (pLni
? "L2 Address/IP" : "Prefix"),
1475 "VN Address", "UN Address", "Cost",
1476 "Lifetime", agetype
, HVTY_NEWLINE
);
1478 printed
+= rfapiPrintRemoteRegBi (bgp
, stream
, rn
, bi
);
1486 const char *type
= "prefixes";
1490 type
= "imported prefixes";
1496 type
= "prefixes in holddown";
1500 if (show_local
&& !show_remote
)
1502 type
= "locally registered prefixes";
1504 else if (!show_local
&& show_remote
)
1506 type
= "remotely registered prefixes";
1511 fp (out
, "Displayed %d out of %d %s%s",
1512 printed
, total
, type
, HVTY_NEWLINE
);
1513 #if DEBUG_SHOW_EXTRA
1514 fp(out
, "IT table above: it=%p%s", it
, HVTY_NEWLINE
);
1523 * rfapiShowRemoteRegistrations
1525 * Similar to rfapiShowImportTable() above. This function
1526 * is mean to produce the "remote" portion of the output
1527 * of "show vnc registrations".
1530 rfapiShowRemoteRegistrations (
1532 struct prefix
*prefix_only
,
1540 struct rfapi_import_table
*it
;
1543 bgp
= bgp_get_default ();
1555 for (it
= h
->imports
; it
; it
= it
->next
)
1558 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1559 show_expiring
, show_local
,
1560 show_remote
, show_imported
, NULL
);
1565 void *cursor
= NULL
;
1567 uintptr_t lni_as_ptr
;
1572 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1575 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1579 if ((lni_as_ptr
& 0xffffffff) == lni_as_ptr
)
1581 lni
= (uint32_t) (lni_as_ptr
& 0xffffffff);
1586 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1587 show_expiring
, show_local
,
1588 show_remote
, show_imported
, pLni
);
1595 /*------------------------------------------
1596 * rfapiRfapiIpAddr2Str
1598 * UI helper: generate string from rfapi_ip_addr
1601 * a IP v4/v6 address
1604 * buf put string here
1605 * bufsize max space to write
1608 * NULL conversion failed
1609 * non-NULL pointer to buf
1610 --------------------------------------------*/
1612 rfapiRfapiIpAddr2Str (struct rfapi_ip_addr
*a
, char *buf
, int bufsize
)
1614 const char *rc
= NULL
;
1616 switch (a
->addr_family
)
1619 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1622 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1629 rfapiPrintRfapiIpAddr (void *stream
, struct rfapi_ip_addr
*a
)
1632 const char *rc
= NULL
;
1634 int (*fp
) (void *, const char *, ...);
1637 const char *vty_newline
;
1639 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1642 rc
= rfapiRfapiIpAddr2Str (a
, buf
, BUFSIZ
);
1645 fp (out
, "%s", buf
);
1649 rfapiRfapiIpPrefix2Str (struct rfapi_ip_prefix
*p
, char *buf
, int bufsize
)
1651 struct rfapi_ip_addr
*a
= &p
->prefix
;
1652 const char *rc
= NULL
;
1654 switch (a
->addr_family
)
1657 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1660 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1666 int alen
= strlen (buf
);
1667 int remaining
= bufsize
- alen
- 1;
1672 slen
= snprintf (buf
+ alen
, remaining
, "/%u", p
->length
);
1673 if (slen
< remaining
) /* see man page for snprintf(3) */
1682 rfapiPrintRfapiIpPrefix (void *stream
, struct rfapi_ip_prefix
*p
)
1687 int (*fp
) (void *, const char *, ...);
1690 const char *vty_newline
;
1692 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1695 rc
= rfapiRfapiIpPrefix2Str (p
, buf
, BUFSIZ
);
1698 fp (out
, "%s:%u", buf
, p
->cost
);
1704 rfapiPrintRd (struct vty
*vty
, struct prefix_rd
*prd
)
1709 prefix_rd2str (prd
, buf
, BUFSIZ
);
1710 buf
[BUFSIZ
- 1] = 0;
1711 vty_out (vty
, "%s", buf
);
1715 rfapiPrintAdvertisedInfo (
1717 struct rfapi_descriptor
*rfd
,
1721 afi_t afi
; /* of the VN address */
1722 struct bgp_node
*bn
;
1723 struct bgp_info
*bi
;
1724 uint8_t type
= ZEBRA_ROUTE_BGP
;
1727 struct prefix_rd prd0
;
1728 struct prefix_rd
*prd
;
1731 * Find the bgp_info in the RIB corresponding to this
1735 afi
= family2afi (p
->family
);
1736 assert (afi
== AFI_IP
|| afi
== AFI_IP6
);
1738 bgp
= bgp_get_default (); /* assume 1 instance for now */
1741 if (safi
== SAFI_ENCAP
)
1743 memset (&prd0
, 0, sizeof (prd0
));
1744 prd0
.family
= AF_UNSPEC
;
1745 prd0
.prefixlen
= 64;
1752 bn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
1754 vty_out (vty
, " bn=%p%s", bn
, HVTY_NEWLINE
);
1756 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
1758 if (bi
->peer
== rfd
->peer
&&
1760 bi
->sub_type
== BGP_ROUTE_RFP
&&
1761 bi
->extra
&& bi
->extra
->vnc
.export
.rfapi_handle
== (void *) rfd
)
1764 rfapiPrintBi (vty
, bi
);
1771 vty_out (vty
, " --?--%s", HVTY_NEWLINE
);
1778 rfapiPrintDescriptor (struct vty
*vty
, struct rfapi_descriptor
*rfd
)
1780 /* pHD un-addr vn-addr pCB cookie rd lifetime */
1781 /* RT export list */
1782 /* RT import list */
1783 /* list of advertised prefixes */
1784 /* dump import table */
1790 struct rfapi_adb
*adb
;
1793 vty_out (vty
, "%-10p ", rfd
);
1794 rfapiPrintRfapiIpAddr (vty
, &rfd
->un_addr
);
1796 rfapiPrintRfapiIpAddr (vty
, &rfd
->vn_addr
);
1797 vty_out (vty
, " %p %p ", rfd
->response_cb
, rfd
->cookie
);
1798 rfapiPrintRd (vty
, &rfd
->rd
);
1799 vty_out (vty
, " %d", rfd
->response_lifetime
);
1800 vty_out (vty
, " %s", (rfd
->rfg
? rfd
->rfg
->name
: "<orphaned>"));
1801 vty_out (vty
, "%s", HVTY_NEWLINE
);
1803 vty_out (vty
, " Peer %p #%d%s", rfd
->peer
, rfd
->peer
->lock
, HVTY_NEWLINE
);
1805 /* export RT list */
1806 if (rfd
->rt_export_list
)
1809 ecommunity_ecom2str (rfd
->rt_export_list
,
1810 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1811 vty_out (vty
, " Export %s%s", s
, HVTY_NEWLINE
);
1812 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1816 vty_out (vty
, " Export (nil)%s", HVTY_NEWLINE
);
1819 /* import RT list */
1820 if (rfd
->import_table
)
1822 s
= ecommunity_ecom2str (rfd
->import_table
->rt_import_list
,
1823 ECOMMUNITY_FORMAT_ROUTE_MAP
);
1824 vty_out (vty
, " Import %s%s", s
, HVTY_NEWLINE
);
1825 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1829 vty_out (vty
, " Import (nil)%s", HVTY_NEWLINE
);
1832 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1836 family
= afi2family (afi
);
1842 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1845 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1849 /* group like family prefixes together in output */
1850 if (family
!= adb
->u
.s
.prefix_ip
.family
)
1853 prefix2str (&adb
->u
.s
.prefix_ip
, buf
, BUFSIZ
);
1854 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1856 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1857 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1861 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1864 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1868 prefix2str (&adb
->u
.s
.prefix_eth
, buf
, BUFSIZ
);
1869 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1871 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1873 /* TBD update the following function to print ethernet info */
1874 /* Also need to pass/use rd */
1875 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1877 vty_out (vty
, "%s", HVTY_NEWLINE
);
1881 * test scripts rely on first line for each nve starting in 1st column,
1882 * leading whitespace for additional detail of that nve
1885 rfapiPrintMatchingDescriptors (struct vty
*vty
,
1886 struct prefix
*vn_prefix
,
1887 struct prefix
*un_prefix
)
1891 struct listnode
*ln
;
1892 struct rfapi_descriptor
*rfd
;
1895 bgp
= bgp_get_default (); /* assume 1 instance for now */
1902 for (ln
= listhead (&h
->descriptors
); ln
; ln
= listnextnode (ln
))
1904 rfd
= listgetdata (ln
);
1910 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
1911 if (!prefix_match (vn_prefix
, &pfx
))
1917 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
1918 if (!prefix_match (un_prefix
, &pfx
))
1924 /* print column header */
1926 "%s %s %s %s %s %s %s %s%s",
1927 "descriptor", "un-addr", "vn-addr", "callback", "cookie",
1928 "RD", "lifetime", "group", HVTY_NEWLINE
);
1930 rfapiPrintDescriptor (vty
, rfd
);
1937 * Parse an address and put into a struct prefix
1940 rfapiCliGetPrefixAddr (struct vty
*vty
, const char *str
, struct prefix
*p
)
1942 if (!str2prefix (str
, p
))
1944 vty_out (vty
, "Malformed address \"%s\"%s", str
, HVTY_NEWLINE
);
1950 if (p
->prefixlen
!= 32)
1952 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1957 if (p
->prefixlen
!= 128)
1959 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1964 vty_out (vty
, "Invalid address \"%s\"%s", str
, HVTY_NEWLINE
);
1971 rfapiCliGetRfapiIpAddr (
1974 struct rfapi_ip_addr
*hai
)
1979 rc
= rfapiCliGetPrefixAddr (vty
, str
, &pfx
);
1983 hai
->addr_family
= pfx
.family
;
1984 if (pfx
.family
== AF_INET
)
1985 hai
->addr
.v4
= pfx
.u
.prefix4
;
1987 hai
->addr
.v6
= pfx
.u
.prefix6
;
1993 * Note: this function does not flush vty output, so if it is called
1994 * with a stream pointing to a vty, the user will have to type something
1995 * before the callback output shows up
1998 rfapiPrintNhl (void *stream
, struct rfapi_next_hop_entry
*next_hops
)
2000 struct rfapi_next_hop_entry
*nh
;
2003 int (*fp
) (void *, const char *, ...);
2006 const char *vty_newline
;
2008 #define REMAIN (BUFSIZ - (p-line))
2009 #define INCP {p += (r > REMAIN)? REMAIN: r;}
2012 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
2015 for (nh
= next_hops
, count
= 1; nh
; nh
= nh
->next
, ++count
)
2022 r
= snprintf (p
, REMAIN
, "%3d pfx=", count
);
2025 if (rfapiRfapiIpPrefix2Str (&nh
->prefix
, p
, REMAIN
))
2027 /* it fit, so count length */
2037 r
= snprintf (p
, REMAIN
, ", un=");
2040 if (rfapiRfapiIpAddr2Str (&nh
->un_address
, p
, REMAIN
))
2042 /* it fit, so count length */
2052 r
= snprintf (p
, REMAIN
, ", vn=");
2055 if (rfapiRfapiIpAddr2Str (&nh
->vn_address
, p
, REMAIN
))
2057 /* it fit, so count length */
2068 line
[BUFSIZ
- 1] = 0;
2069 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
2076 struct rfapi_vn_option
*vo
;
2077 char offset
[] = " ";
2079 for (vo
= nh
->vn_options
; vo
; vo
= vo
->next
)
2085 case RFAPI_VN_OPTION_TYPE_L2ADDR
:
2086 rfapiEthAddr2Str (&vo
->v
.l2addr
.macaddr
, pbuf
,
2088 fp (out
, "%sL2 %s LBL=0x%06x NETID=0x%06x NVEID=%d%s",
2089 offset
, pbuf
, (vo
->v
.l2addr
.label
& 0x00ffffff),
2090 (vo
->v
.l2addr
.logical_net_id
& 0x00ffffff),
2091 vo
->v
.l2addr
.local_nve_id
, HVTY_NEWLINE
);
2094 case RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
:
2095 prefix2str (&vo
->v
.local_nexthop
.addr
, pbuf
, sizeof (pbuf
));
2096 fp (out
, "%sLNH %s cost=%d%s",
2097 offset
, pbuf
, vo
->v
.local_nexthop
.cost
, HVTY_NEWLINE
);
2101 fp (out
, "%svn option type %d (unknown)%s",
2102 offset
, vo
->type
, HVTY_NEWLINE
);
2109 struct rfapi_un_option
*uo
;
2110 char offset
[] = " ";
2112 for (uo
= nh
->un_options
; uo
; uo
= uo
->next
)
2116 case RFAPI_UN_OPTION_TYPE_TUNNELTYPE
:
2117 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
2120 fp (out
, "%sUN Option type %d%s",
2121 offset
, uo
->type
, vty_newline
);
2130 /***********************************************************************
2132 ***********************************************************************/
2135 * Add another nexthop to the NHL
2138 rfapiAddDeleteLocalRfpPrefix (
2139 struct rfapi_ip_addr
*un_addr
,
2140 struct rfapi_ip_addr
*vn_addr
,
2141 struct rfapi_ip_prefix
*rprefix
,
2143 uint32_t lifetime
, /* add only */
2144 struct rfapi_vn_option
*vn_options
,
2145 struct rfapi_next_hop_entry
**head
,
2146 struct rfapi_next_hop_entry
**tail
)
2148 struct rfapi_next_hop_entry
*new;
2154 new = XCALLOC (MTYPE_RFAPI_NEXTHOP
, sizeof (struct rfapi_next_hop_entry
));
2155 new->prefix
= *rprefix
;
2156 new->un_address
= *un_addr
;
2157 new->vn_address
= *vn_addr
;
2159 new->vn_options
= vn_options
;
2162 new->lifetime
= lifetime
;
2166 new->lifetime
= RFAPI_REMOVE_RESPONSE_LIFETIME
;
2170 (*tail
)->next
= new;
2182 struct cmd_token
*carg_prefix
,
2183 struct cmd_token
*carg_vn
,
2184 struct cmd_token
*carg_un
,
2185 struct cmd_token
*carg_cost
, /* optional */
2186 struct cmd_token
*carg_lifetime
, /* optional */
2187 struct cmd_token
*carg_macaddr
, /* optional */
2188 struct cmd_token
*carg_vni
, /* mac present=>mandatory Virtual Network ID */
2190 struct cmd_token
**argv
)
2192 const char *arg_prefix
= carg_prefix
->arg
;
2193 const char *arg_vn
= carg_vn
->arg
;
2194 const char *arg_un
= carg_un
->arg
;
2195 const char *arg_cost
= carg_cost
? carg_cost
->arg
: NULL
;
2196 const char *arg_lifetime
= carg_lifetime
? carg_lifetime
->arg
: NULL
;
2197 const char *arg_macaddr
= carg_macaddr
? carg_macaddr
->arg
: NULL
;
2198 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
2199 struct rfapi_ip_addr vn_address
;
2200 struct rfapi_ip_addr un_address
;
2202 struct rfapi_ip_prefix rpfx
;
2207 struct rfapi_vn_option optary
[10]; /* XXX must be big enough */
2208 struct rfapi_vn_option
*opt
= NULL
;
2211 int rc
= CMD_WARNING
;
2215 struct rfapi_cfg
*rfapi_cfg
;
2217 const char *arg_lnh
= NULL
;
2218 const char *arg_lnh_cost
= NULL
;
2220 bgp
= bgp_get_default (); /* assume 1 instance for now */
2224 vty_out (vty
, "BGP not configured%s", VTY_NEWLINE
);
2229 rfapi_cfg
= bgp
->rfapi_cfg
;
2230 if (!h
|| !rfapi_cfg
)
2233 vty_out (vty
, "RFAPI not configured%s", VTY_NEWLINE
);
2237 for (; argc
; --argc
, ++argv
)
2239 if (!strcmp (argv
[0]->arg
, "local-next-hop"))
2243 vty_out (vty
, "local-next-hop specified more than once%s",
2249 vty_out (vty
, "Missing parameter for local-next-hop%s",
2254 arg_lnh
= argv
[0]->arg
;
2256 if (!strcmp (argv
[0]->arg
, "local-cost"))
2260 vty_out (vty
, "local-cost specified more than once%s",
2266 vty_out (vty
, "Missing parameter for local-cost%s",
2271 arg_lnh_cost
= argv
[0]->arg
;
2275 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &vn_address
)))
2277 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &un_address
)))
2280 /* arg_prefix is optional if mac address is given */
2281 if (arg_macaddr
&& !arg_prefix
)
2284 * fake up a 0/32 or 0/128 prefix
2286 switch (vn_address
.addr_family
)
2289 arg_prefix
= "0.0.0.0/32";
2292 arg_prefix
= "0::0/128";
2295 vty_out (vty
, "Internal error, unknown VN address family%s",
2302 if (!str2prefix (arg_prefix
, &pfx
))
2304 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
,
2308 if (pfx
.family
!= AF_INET
2309 && pfx
.family
!= AF_INET6
)
2311 vty_out (vty
, "prefix \"%s\" has invalid address family%s",
2312 arg_prefix
, VTY_NEWLINE
);
2317 memset (optary
, 0, sizeof (optary
));
2322 cost
= strtoul (arg_cost
, &endptr
, 10);
2323 if (*endptr
!= '\0' || cost
> 255)
2325 vty_out (vty
, "%% Invalid %s value%s", "cost", VTY_NEWLINE
);
2336 if (!strcmp (arg_lifetime
, "infinite"))
2338 lifetime
= RFAPI_INFINITE_LIFETIME
;
2343 lifetime
= strtoul (arg_lifetime
, &endptr
, 10);
2344 if (*endptr
!= '\0')
2346 vty_out (vty
, "%% Invalid %s value%s", "lifetime",
2354 lifetime
= RFAPI_INFINITE_LIFETIME
; /* default infinite */
2362 "%% %s may only be specified with local-next-hop%s",
2363 "local-cost", VTY_NEWLINE
);
2367 lnh_cost
= strtoul (arg_lnh_cost
, &endptr
, 10);
2368 if (*endptr
!= '\0' || lnh_cost
> 255)
2370 vty_out (vty
, "%% Invalid %s value%s", "local-cost",
2384 vty_out (vty
, "%% %s may only be specified with prefix%s",
2385 "local-next-hop", VTY_NEWLINE
);
2388 if ((rc
= rfapiCliGetPrefixAddr (vty
, arg_lnh
,
2389 &optary
[opt_next
].v
.
2390 local_nexthop
.addr
)))
2396 optary
[opt_next
].v
.local_nexthop
.cost
= lnh_cost
;
2397 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
;
2401 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2410 if (arg_vni
&& !arg_macaddr
)
2412 vty_out (vty
, "%% %s may only be specified with mac address%s",
2413 "virtual-network-identifier", VTY_NEWLINE
);
2422 "Missing \"vni\" parameter (mandatory with mac)%s",
2426 VTY_GET_INTEGER ("Logical Network ID",
2427 optary
[opt_next
].v
.l2addr
.logical_net_id
,
2430 if ((rc
= rfapiStr2EthAddr (arg_macaddr
,
2431 &optary
[opt_next
].v
.l2addr
.macaddr
)))
2433 vty_out (vty
, "Invalid %s value%s", "mac address",
2437 /* TBD label, NVE ID */
2439 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
2443 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2452 vnc_zlog_debug_verbose
2453 ("%s: vn=%s, un=%s, prefix=%s, cost=%s, lifetime=%s, lnh=%s",
2454 __func__
, arg_vn
, arg_un
, arg_prefix
,
2455 (arg_cost
? arg_cost
: "NULL"),
2456 (arg_lifetime
? arg_lifetime
: "NULL"),
2457 (arg_lnh
? arg_lnh
: "NULL"));
2459 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
2461 rpfx
.cost
= cost
& 255;
2463 /* look up rf descriptor, call open if it doesn't exist */
2465 rfapi_find_rfd (bgp
, &vn_address
, &un_address
,
2466 (struct rfapi_descriptor
**) &rfd
);
2471 struct rfapi_un_option uo
;
2474 * flag descriptor as provisionally opened for static route
2475 * registration so that we can fix up the other parameters
2476 * when the real open comes along
2478 memset (&uo
, 0, sizeof (uo
));
2479 uo
.type
= RFAPI_UN_OPTION_TYPE_PROVISIONAL
;
2481 rc
= rfapi_open (rfapi_get_rfp_start_val_by_bgp (bgp
), &vn_address
, &un_address
, &uo
, /* flags */
2482 NULL
, NULL
, /* no userdata */
2486 vty_out (vty
, "Can't open session for this NVE: %s%s",
2487 rfapi_error_str (rc
), VTY_NEWLINE
);
2494 vty_out (vty
, "Can't find session for this NVE: %s%s",
2495 rfapi_error_str (rc
), VTY_NEWLINE
);
2501 rfapi_register (rfd
, &rpfx
, lifetime
, NULL
, opt
, RFAPI_REGISTER_ADD
);
2504 struct rfapi_next_hop_entry
*head
= NULL
;
2505 struct rfapi_next_hop_entry
*tail
= NULL
;
2506 struct rfapi_vn_option
*vn_opt_new
;
2508 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded, returning 0", __func__
);
2510 if (h
->rfp_methods
.local_cb
)
2512 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfd
;
2513 vn_opt_new
= rfapi_vn_options_dup (opt
);
2515 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
2516 1, lifetime
, vn_opt_new
, &head
,
2520 h
->flags
|= RFAPI_INCALLBACK
;
2521 (*h
->rfp_methods
.local_cb
) (head
, r
->cookie
);
2522 h
->flags
&= ~RFAPI_INCALLBACK
;
2529 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
2530 vty_out (vty
, "%s", VTY_NEWLINE
);
2531 vty_out (vty
, "Registration failed.%s", VTY_NEWLINE
);
2533 "Confirm that either the VN or UN address matches a configured NVE group.%s",
2538 vnc_zlog_debug_verbose ("%s: fail, rc=%d", __func__
, rc
);
2542 /************************************************************************
2543 * Add prefix With LNH_OPTIONS...
2544 ************************************************************************/
2545 DEFUN (add_vnc_prefix_cost_life_lnh
,
2546 add_vnc_prefix_cost_life_lnh_cmd
,
2547 "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...",
2548 "Add registration\n"
2550 "Add/modify prefix related information\n"
2553 "VN address of NVE\n"
2554 "VN IPv4 interface address\n"
2555 "VN IPv6 interface address\n"
2556 "UN address of NVE\n"
2557 "UN IPv4 interface address\n"
2558 "UN IPv6 interface address\n"
2559 "Administrative cost [default: 255]\n"
2560 "Administrative cost\n"
2561 "Registration lifetime [default: infinite]\n"
2562 "Lifetime value in seconds\n"
2563 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2565 /* pfx vn un cost life */
2566 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2568 NULL
, NULL
, argc
- 12, argv
+ 12);
2571 DEFUN (add_vnc_prefix_life_cost_lnh
,
2572 add_vnc_prefix_life_cost_lnh_cmd
,
2573 "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...",
2574 "Add registration\n"
2576 "Add/modify prefix related information\n"
2579 "VN address of NVE\n"
2580 "VN IPv4 interface address\n"
2581 "VN IPv6 interface address\n"
2582 "UN address of NVE\n"
2583 "UN IPv4 interface address\n"
2584 "UN IPv6 interface address\n"
2585 "Registration lifetime [default: infinite]\n"
2586 "Lifetime value in seconds\n"
2587 "Administrative cost [default: 255]\n"
2588 "Administrative cost\n"
2589 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2591 /* pfx vn un cost life */
2592 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2594 NULL
, NULL
, argc
- 12, argv
+ 12);
2597 DEFUN (add_vnc_prefix_cost_lnh
,
2598 add_vnc_prefix_cost_lnh_cmd
,
2599 "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...",
2600 "Add registration\n"
2602 "Add/modify prefix related information\n"
2605 "VN address of NVE\n"
2606 "VN IPv4 interface address\n"
2607 "VN IPv6 interface address\n"
2608 "UN address of NVE\n"
2609 "UN IPv4 interface address\n"
2610 "UN IPv6 interface address\n"
2611 "Administrative cost [default: 255]\n"
2612 "Administrative cost\n"
2613 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2615 /* pfx vn un cost life */
2616 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2618 NULL
, NULL
, argc
- 10, argv
+ 10);
2621 DEFUN (add_vnc_prefix_life_lnh
,
2622 add_vnc_prefix_life_lnh_cmd
,
2623 "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...",
2624 "Add registration\n"
2626 "Add/modify prefix related information\n"
2629 "VN address of NVE\n"
2630 "VN IPv4 interface address\n"
2631 "VN IPv6 interface address\n"
2632 "UN address of NVE\n"
2633 "UN IPv4 interface address\n"
2634 "UN IPv6 interface address\n"
2635 "Registration lifetime [default: infinite]\n"
2636 "Lifetime value in seconds\n"
2637 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2639 /* pfx vn un cost life */
2640 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2642 NULL
, NULL
, argc
- 10, argv
+ 10);
2645 DEFUN (add_vnc_prefix_lnh
,
2646 add_vnc_prefix_lnh_cmd
,
2647 "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...",
2648 "Add registration\n"
2650 "Add/modify prefix related information\n"
2653 "VN address of NVE\n"
2654 "VN IPv4 interface address\n"
2655 "VN IPv6 interface address\n"
2656 "UN address of NVE\n"
2657 "UN IPv4 interface address\n"
2658 "UN IPv6 interface address\n"
2659 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2661 /* pfx vn un cost life */
2662 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2664 NULL
, NULL
, argc
- 8, argv
+ 8);
2667 /************************************************************************
2668 * Add prefix Without LNH_OPTIONS...
2669 ************************************************************************/
2670 DEFUN (add_vnc_prefix_cost_life
,
2671 add_vnc_prefix_cost_life_cmd
,
2672 "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)",
2673 "Add registration\n"
2675 "Add/modify prefix related information\n"
2678 "VN address of NVE\n"
2679 "VN IPv4 interface address\n"
2680 "VN IPv6 interface address\n"
2681 "UN address of NVE\n"
2682 "UN IPv4 interface address\n"
2683 "UN IPv6 interface address\n"
2684 "Administrative cost [default: 255]\n"
2685 "Administrative cost\n"
2686 "Registration lifetime [default: infinite]\n"
2687 "Lifetime value in seconds\n"
2688 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2690 /* pfx vn un cost life */
2691 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2693 NULL
, NULL
, 0, NULL
);
2696 DEFUN (add_vnc_prefix_life_cost
,
2697 add_vnc_prefix_life_cost_cmd
,
2698 "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)",
2699 "Add registration\n"
2701 "Add/modify prefix related information\n"
2704 "VN address of NVE\n"
2705 "VN IPv4 interface address\n"
2706 "VN IPv6 interface address\n"
2707 "UN address of NVE\n"
2708 "UN IPv4 interface address\n"
2709 "UN IPv6 interface address\n"
2710 "Registration lifetime [default: infinite]\n"
2711 "Lifetime value in seconds\n"
2712 "Administrative cost [default: 255]\n"
2713 "Administrative cost\n"
2714 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2716 /* pfx vn un cost life */
2717 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2719 NULL
, NULL
, 0, NULL
);
2722 DEFUN (add_vnc_prefix_cost
,
2723 add_vnc_prefix_cost_cmd
,
2724 "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)",
2725 "Add registration\n"
2727 "Add/modify prefix related information\n"
2730 "VN address of NVE\n"
2731 "VN IPv4 interface address\n"
2732 "VN IPv6 interface address\n"
2733 "UN address of NVE\n"
2734 "UN IPv4 interface address\n"
2735 "UN IPv6 interface address\n"
2736 "Administrative cost [default: 255]\n"
2737 "Administrative cost\n"
2738 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2740 /* pfx vn un cost life */
2741 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2743 NULL
, NULL
, 0, NULL
);
2746 DEFUN (add_vnc_prefix_life
,
2747 add_vnc_prefix_life_cmd
,
2748 "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)",
2749 "Add registration\n"
2751 "Add/modify prefix related information\n"
2754 "VN address of NVE\n"
2755 "VN IPv4 interface address\n"
2756 "VN IPv6 interface address\n"
2757 "UN address of NVE\n"
2758 "UN IPv4 interface address\n"
2759 "UN IPv6 interface address\n"
2760 "Registration lifetime [default: infinite]\n"
2761 "Lifetime value in seconds\n"
2762 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2764 /* pfx vn un cost life */
2765 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2767 NULL
, NULL
, 0, NULL
);
2770 DEFUN (add_vnc_prefix
,
2772 "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>",
2773 "Add registration\n"
2775 "Add/modify prefix related information\n"
2778 "VN address of NVE\n"
2779 "VN IPv4 interface address\n"
2780 "VN IPv6 interface address\n"
2781 "UN address of NVE\n"
2782 "UN IPv4 interface address\n"
2783 "UN IPv6 interface address\n"
2784 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2786 /* pfx vn un cost life */
2787 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2789 NULL
, NULL
, 0, NULL
);
2792 /************************************************************************
2793 * Mac address registrations
2794 ************************************************************************/
2795 DEFUN (add_vnc_mac_vni_prefix_cost_life
,
2796 add_vnc_mac_vni_prefix_cost_life_cmd
,
2797 "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)",
2798 "Add registration\n"
2800 "Add/modify mac address information\n"
2802 "Virtual Network Identifier follows\n"
2803 "Virtual Network Identifier\n"
2804 "VN address of NVE\n"
2805 "VN IPv4 interface address\n"
2806 "VN IPv6 interface address\n"
2807 "UN address of NVE\n"
2808 "UN IPv4 interface address\n"
2809 "UN IPv6 interface address\n"
2810 "Add/modify prefix related information\n"
2813 "Administrative cost [default: 255]\n"
2814 "Administrative cost\n"
2815 "Registration lifetime [default: infinite]\n"
2816 "Lifetime value in seconds\n")
2818 /* pfx vn un cost life */
2819 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], argv
[15],
2821 argv
[3], argv
[5], 0, NULL
);
2825 DEFUN (add_vnc_mac_vni_prefix_life
,
2826 add_vnc_mac_vni_prefix_life_cmd
,
2827 "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)",
2828 "Add registration\n"
2830 "Add/modify mac address information\n"
2832 "Virtual Network Identifier follows\n"
2833 "Virtual Network Identifier\n"
2834 "VN address of NVE\n"
2835 "VN IPv4 interface address\n"
2836 "VN IPv6 interface address\n"
2837 "UN address of NVE\n"
2838 "UN IPv4 interface address\n"
2839 "UN IPv6 interface address\n"
2840 "Add/modify prefix related information\n"
2843 "Registration lifetime [default: infinite]\n"
2844 "Lifetime value in seconds\n")
2846 /* pfx vn un cost life */
2847 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, argv
[13],
2849 argv
[3], argv
[5], 0, NULL
);
2852 DEFUN (add_vnc_mac_vni_prefix_cost
,
2853 add_vnc_mac_vni_prefix_cost_cmd
,
2854 "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)",
2855 "Add registration\n"
2857 "Add/modify mac address information\n"
2859 "Virtual Network Identifier follows\n"
2860 "Virtual Network Identifier\n"
2861 "VN address of NVE\n"
2862 "VN IPv4 interface address\n"
2863 "VN IPv6 interface address\n"
2864 "UN address of NVE\n"
2865 "UN IPv4 interface address\n"
2866 "UN IPv6 interface address\n"
2867 "Add/modify prefix related information\n"
2870 "Administrative cost [default: 255]\n" "Administrative cost\n")
2872 /* pfx vn un cost life */
2873 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], NULL
,
2875 argv
[3], argv
[5], 0, NULL
);
2878 DEFUN (add_vnc_mac_vni_prefix
,
2879 add_vnc_mac_vni_prefix_cmd
,
2880 "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>",
2881 "Add registration\n"
2883 "Add/modify mac address information\n"
2885 "Virtual Network Identifier follows\n"
2886 "Virtual Network Identifier\n"
2887 "VN address of NVE\n"
2888 "VN IPv4 interface address\n"
2889 "VN IPv6 interface address\n"
2890 "UN address of NVE\n"
2891 "UN IPv4 interface address\n"
2892 "UN IPv6 interface address\n"
2893 "Add/modify prefix related information\n"
2894 "IPv4 prefix\n" "IPv6 prefix\n")
2896 /* pfx vn un cost life */
2897 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, NULL
,
2899 argv
[3], argv
[5], 0, NULL
);
2902 DEFUN (add_vnc_mac_vni_cost_life
,
2903 add_vnc_mac_vni_cost_life_cmd
,
2904 "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)",
2905 "Add registration\n"
2907 "Add/modify mac address information\n"
2909 "Virtual Network Identifier follows\n"
2910 "Virtual Network Identifier\n"
2911 "VN address of NVE\n"
2912 "VN IPv4 interface address\n"
2913 "VN IPv6 interface address\n"
2914 "UN address of NVE\n"
2915 "UN IPv4 interface address\n"
2916 "UN IPv6 interface address\n"
2917 "Administrative cost [default: 255]\n"
2918 "Administrative cost\n"
2919 "Registration lifetime [default: infinite]\n"
2920 "Lifetime value in seconds\n")
2922 /* pfx vn un cost life */
2923 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], argv
[13],
2925 argv
[3], argv
[5], 0, NULL
);
2929 DEFUN (add_vnc_mac_vni_cost
,
2930 add_vnc_mac_vni_cost_cmd
,
2931 "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)",
2932 "Add registration\n"
2934 "Add/modify mac address information\n"
2936 "Virtual Network Identifier follows\n"
2937 "Virtual Network Identifier\n"
2938 "VN address of NVE\n"
2939 "VN IPv4 interface address\n"
2940 "VN IPv6 interface address\n"
2941 "UN address of NVE\n"
2942 "UN IPv4 interface address\n"
2943 "UN IPv6 interface address\n"
2944 "Administrative cost [default: 255]\n" "Administrative cost\n")
2946 /* pfx vn un cost life */
2947 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], NULL
,
2949 argv
[3], argv
[5], 0, NULL
);
2953 DEFUN (add_vnc_mac_vni_life
,
2954 add_vnc_mac_vni_life_cmd
,
2955 "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)",
2956 "Add registration\n"
2958 "Add/modify mac address information\n"
2960 "Virtual Network Identifier follows\n"
2961 "Virtual Network Identifier\n"
2962 "VN address of NVE\n"
2963 "VN IPv4 interface address\n"
2964 "VN IPv6 interface address\n"
2965 "UN address of NVE\n"
2966 "UN IPv4 interface address\n"
2967 "UN IPv6 interface address\n"
2968 "Registration lifetime [default: infinite]\n"
2969 "Lifetime value in seconds\n")
2971 /* pfx vn un cost life */
2972 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, argv
[11],
2974 argv
[3], argv
[5], 0, NULL
);
2978 DEFUN (add_vnc_mac_vni
,
2979 add_vnc_mac_vni_cmd
,
2980 "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>",
2981 "Add registration\n"
2983 "Add/modify mac address information\n"
2985 "Virtual Network Identifier follows\n"
2986 "Virtual Network Identifier\n"
2987 "VN address of NVE\n"
2988 "VN IPv4 interface address\n"
2989 "VN IPv6 interface address\n"
2990 "UN address of NVE\n"
2991 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
2993 /* pfx vn un cost life */
2994 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, NULL
,
2996 argv
[3], argv
[5], 0, NULL
);
2999 /************************************************************************
3001 ************************************************************************/
3003 struct rfapi_local_reg_delete_arg
3009 struct rfapi_ip_addr un_address
; /* AF==0: wildcard */
3010 struct rfapi_ip_addr vn_address
; /* AF==0: wildcard */
3011 struct prefix prefix
; /* AF==0: wildcard */
3012 struct prefix_rd rd
; /* plen!=64: wildcard */
3013 struct rfapi_nve_group_cfg
*rfg
; /* NULL: wildcard */
3015 struct rfapi_l2address_option_match l2o
;
3023 uint32_t query_count
;
3025 uint32_t failed_pfx_count
;
3028 struct skiplist
*nves
;
3030 uint32_t remote_active_nve_count
;
3031 uint32_t remote_active_pfx_count
;
3032 uint32_t remote_holddown_nve_count
;
3033 uint32_t remote_holddown_pfx_count
;
3038 struct rfapi_ip_addr vn
;
3039 struct rfapi_ip_addr un
;
3040 struct rfapi_descriptor
*rfd
;
3041 struct rfapi_local_reg_delete_arg
*cda
;
3045 nve_addr_free (void *hap
)
3047 ((struct nve_addr
*) hap
)->cda
->nve_count
+= 1;
3048 XFREE (MTYPE_RFAPI_NVE_ADDR
, hap
);
3052 nve_addr_cmp (void *k1
, void *k2
)
3054 struct nve_addr
*a
= (struct nve_addr
*) k1
;
3055 struct nve_addr
*b
= (struct nve_addr
*) k2
;
3062 if (a
->un
.addr_family
!= b
->un
.addr_family
)
3064 return (a
->un
.addr_family
- b
->un
.addr_family
);
3066 if (a
->vn
.addr_family
!= b
->vn
.addr_family
)
3068 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
3070 if (a
->un
.addr_family
== AF_INET
)
3072 ret
= IPV4_ADDR_CMP (&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
3078 else if (a
->un
.addr_family
== AF_INET6
)
3080 ret
= IPV6_ADDR_CMP (&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
3090 if (a
->vn
.addr_family
== AF_INET
)
3092 ret
= IPV4_ADDR_CMP (&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
3096 else if (a
->vn
.addr_family
== AF_INET6
)
3098 ret
= IPV6_ADDR_CMP (&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
3112 parse_deleter_args (
3115 const char *arg_prefix
,
3118 const char *arg_l2addr
,
3119 const char *arg_vni
,
3121 struct rfapi_nve_group_cfg
*arg_rfg
,
3122 struct rfapi_local_reg_delete_arg
*rcdarg
)
3124 int rc
= CMD_WARNING
;
3126 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3130 bgp
= bgp_get_default();
3132 rcdarg
->rfg
= arg_rfg
; /* may be NULL */
3134 if (arg_vn
&& strcmp (arg_vn
, "*"))
3136 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3139 if (arg_un
&& strcmp (arg_un
, "*"))
3141 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3144 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3147 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3149 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
, VTY_NEWLINE
);
3158 vty_out (vty
, "Missing VNI%s", VTY_NEWLINE
);
3161 if (strcmp (arg_l2addr
, "*"))
3163 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3165 vty_out (vty
, "Malformed L2 Address \"%s\"%s",
3166 arg_l2addr
, VTY_NEWLINE
);
3169 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3171 if (strcmp (arg_vni
, "*"))
3173 VTY_GET_INTEGER ("Logical Network ID",
3174 rcdarg
->l2o
.o
.logical_net_id
, arg_vni
);
3175 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3180 if (!str2prefix_rd (arg_rd
, &rcdarg
->rd
))
3182 vty_out (vty
, "Malformed RD \"%s\"%s",
3183 arg_rd
, VTY_NEWLINE
);
3192 parse_deleter_tokens (
3195 struct cmd_token
*carg_prefix
,
3196 struct cmd_token
*carg_vn
,
3197 struct cmd_token
*carg_un
,
3198 struct cmd_token
*carg_l2addr
,
3199 struct cmd_token
*carg_vni
,
3200 struct cmd_token
*carg_rd
,
3201 struct rfapi_nve_group_cfg
*arg_rfg
,
3202 struct rfapi_local_reg_delete_arg
*rcdarg
)
3204 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
3205 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
3206 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
3207 const char *arg_l2addr
= carg_l2addr
? carg_l2addr
->arg
: NULL
;
3208 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
3209 const char *arg_rd
= carg_rd
? carg_rd
->arg
: NULL
;
3210 return parse_deleter_args (vty
, bgp
,arg_prefix
, arg_vn
, arg_un
,
3211 arg_l2addr
, arg_vni
, arg_rd
,
3216 record_nve_in_cda_list (
3217 struct rfapi_local_reg_delete_arg
*cda
,
3218 struct rfapi_ip_addr
*un_address
,
3219 struct rfapi_ip_addr
*vn_address
,
3220 struct rfapi_descriptor
*rfd
)
3223 struct nve_addr
*hap
;
3225 memset (&ha
, 0, sizeof (ha
));
3226 ha
.un
= *un_address
;
3227 ha
.vn
= *vn_address
;
3231 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3233 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3235 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3239 skiplist_insert (cda
->nves
, hap
, hap
);
3244 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3247 struct rfapi_descriptor
*rfd
;
3248 int query_count
= 0;
3249 struct listnode
*node
;
3250 struct bgp
*bgp_default
= bgp_get_default ();
3252 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3258 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3261 rfapiRibClear (rfd
);
3262 rfapi_query_done_all (rfd
, &query_count
);
3263 cda
->query_count
+= query_count
;
3266 * Track unique nves seen
3268 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3279 h
= bgp_default
->rfapi
;
3284 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3287 * match un, vn addresses of NVEs
3289 if (cda
->un_address
.addr_family
&&
3290 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3294 if (cda
->vn_address
.addr_family
&&
3295 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3300 rfapiRibClear (rfd
);
3302 rfapi_query_done_all (rfd
, &query_count
);
3303 cda
->query_count
+= query_count
;
3306 * Track unique nves seen
3308 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3313 * TBD need to count deleted prefixes and nves?
3315 * ENXIO BGP or VNC not configured
3318 rfapiDeleteLocalPrefixesByRFD (struct rfapi_local_reg_delete_arg
*cda
,
3319 struct rfapi_descriptor
*rfd
)
3321 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3322 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3323 struct prefix
*pPrefix
; /* NULL = wildcard */
3324 struct prefix_rd
*pPrd
; /* NULL = wildcard */
3326 struct rfapi_ip_prefix rprefix
;
3327 struct rfapi_next_hop_entry
*head
= NULL
;
3328 struct rfapi_next_hop_entry
*tail
= NULL
;
3331 vnc_zlog_debug_verbose ("%s: entry", __func__
);
3334 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3335 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3336 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3337 pPrd
= (cda
->rd
.prefixlen
== 64 ? &cda
->rd
: NULL
);
3341 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3344 do /* to preserve old code structure */
3346 struct rfapi
*h
=cda
->bgp
->rfapi
;;
3347 struct rfapi_adb
*adb
;
3349 int deleted_from_this_nve
;
3351 struct nve_addr
*hap
;
3354 vnc_zlog_debug_verbose ("%s: rfd=%p", __func__
, rfd
);
3358 * match un, vn addresses of NVEs
3360 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3362 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3366 vnc_zlog_debug_verbose ("%s: un, vn match", __func__
);
3373 deleted_from_this_nve
= 0;
3376 struct skiplist
*sl
;
3377 struct rfapi_ip_prefix rp
;
3379 struct list
*adb_delete_list
;
3382 * The advertisements are stored in a skiplist. Withdrawing
3383 * the registration deletes the advertisement from the
3384 * skiplist, which we can't do while iterating over that
3385 * same skiplist using the current skiplist API.
3387 * Strategy: iterate over the skiplist and build another
3388 * list containing only the matching ADBs. Then delete
3389 * _everything_ in that second list (which can be done
3390 * using either skiplists or quagga linklists).
3392 adb_delete_list
= list_new ();
3395 * Advertised IP prefixes (not 0/32 or 0/128)
3397 sl
= rfd
->advertised
.ipN_by_prefix
;
3400 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3401 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3406 if (!prefix_same (pPrefix
, &adb
->u
.s
.prefix_ip
))
3409 vnc_zlog_debug_verbose ("%s: adb=%p, prefix doesn't match, skipping",
3417 if (memcmp(pPrd
->val
, adb
->u
.s
.prd
.val
, 8) != 0)
3420 vnc_zlog_debug_verbose ("%s: adb=%p, RD doesn't match, skipping",
3426 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3429 (cda
->l2o
.o
.macaddr
.octet
,
3430 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3433 vnc_zlog_debug_verbose ("%s: adb=%p, macaddr doesn't match, skipping",
3440 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3442 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3445 vnc_zlog_debug_verbose ("%s: adb=%p, LNI doesn't match, skipping",
3453 vnc_zlog_debug_verbose ("%s: ipN adding adb %p to delete list", __func__
,
3457 listnode_add (adb_delete_list
, adb
);
3460 struct listnode
*node
;
3462 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3464 int this_advertisement_prefix_count
;
3465 struct rfapi_vn_option optary
[3];
3466 struct rfapi_vn_option
*opt
= NULL
;
3469 this_advertisement_prefix_count
= 1;
3471 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3473 memset (optary
, 0, sizeof (optary
));
3475 /* if mac addr present in advert, make l2o vn option */
3476 if (adb
->u
.s
.prefix_eth
.family
== AF_ETHERNET
)
3479 opt
->next
= &optary
[cur_opt
];
3480 opt
= &optary
[cur_opt
++];
3481 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3482 opt
->v
.l2addr
.macaddr
= adb
->u
.s
.prefix_eth
.u
.prefix_eth
;
3483 ++this_advertisement_prefix_count
;
3486 * use saved RD value instead of trying to invert
3487 * complex RD computation in rfapi_register()
3490 opt
->next
= &optary
[cur_opt
];
3491 opt
= &optary
[cur_opt
++];
3492 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3493 opt
->v
.internal_rd
= adb
->u
.s
.prd
;
3496 vnc_zlog_debug_verbose ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3499 rc
= rfapi_register (rfd
, &rp
, 0, NULL
,
3500 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_KILL
);
3503 cda
->pfx_count
+= this_advertisement_prefix_count
;
3504 cda
->reg_count
+= 1;
3505 deleted_from_this_nve
= 1;
3507 if (h
->rfp_methods
.local_cb
)
3509 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3510 &rp
, 0, 0, NULL
, &head
, &tail
);
3513 list_delete_all_node (adb_delete_list
);
3515 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3520 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3524 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3526 sl
= rfd
->advertised
.ip0_by_ether
;
3529 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3530 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3533 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3535 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3536 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
,
3543 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3545 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3551 vnc_zlog_debug_verbose ("%s: ip0 adding adb %p to delete list",
3554 listnode_add (adb_delete_list
, adb
);
3558 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3561 struct rfapi_vn_option vn
;
3563 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3565 memset (&vn
, 0, sizeof (vn
));
3566 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3567 vn
.v
.l2addr
= adb
->l2o
;
3570 vnc_zlog_debug_verbose ("%s: ip0 killing reg from adb %p ",
3574 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3575 RFAPI_REGISTER_KILL
);
3578 cda
->pfx_count
+= 1;
3579 cda
->reg_count
+= 1;
3580 deleted_from_this_nve
= 1;
3582 if (h
->rfp_methods
.local_cb
)
3584 struct rfapi_vn_option
*vn_opt_new
;
3586 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3587 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3588 &rfd
->vn_addr
, &rp
, 0, 0,
3589 vn_opt_new
, &head
, &tail
);
3592 list_delete_all_node (adb_delete_list
);
3594 list_delete (adb_delete_list
);
3599 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3600 h
->flags
|= RFAPI_INCALLBACK
;
3601 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3602 h
->flags
&= ~RFAPI_INCALLBACK
;
3606 if (deleted_from_this_nve
)
3609 * track unique NVEs seen
3611 memset (&ha
, 0, sizeof (ha
));
3612 ha
.un
= rfd
->un_addr
;
3613 ha
.vn
= rfd
->vn_addr
;
3616 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3617 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3619 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3623 skiplist_insert (cda
->nves
, hap
, hap
);
3626 } while (0); /* to preserve old code structure */
3632 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3638 if (cda
->rfg
->rfd
) /* if not open, nothing to delete */
3639 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, cda
->rfg
->rfd
);
3643 struct bgp
*bgp
= cda
->bgp
;
3645 struct rfapi_cfg
*rfapi_cfg
;
3647 struct listnode
*node
;
3648 struct rfapi_descriptor
*rfd
;
3652 rfapi_cfg
= bgp
->rfapi_cfg
;
3653 if (!h
|| !rfapi_cfg
)
3655 vnc_zlog_debug_verbose ("%s: starting descriptor loop", __func__
);
3656 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3658 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, rfd
);
3667 * Deletes local and remote prefixes that match
3670 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3672 struct prefix pfx_un
;
3673 struct prefix pfx_vn
;
3675 struct prefix
*pUN
= NULL
;
3676 struct prefix
*pVN
= NULL
;
3677 struct prefix
*pPrefix
= NULL
;
3679 struct rfapi_import_table
*it
= NULL
;
3682 * Delete matching remote prefixes in holddown
3684 if (cda
->vn_address
.addr_family
)
3686 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3689 if (cda
->un_address
.addr_family
)
3691 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3694 if (cda
->prefix
.family
)
3696 pPrefix
= &cda
->prefix
;
3700 it
= cda
->rfg
->rfapi_import_table
;
3702 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
, it
,
3703 0, 1, &cda
->remote_active_pfx_count
,
3704 &cda
->remote_active_nve_count
,
3705 &cda
->remote_holddown_pfx_count
,
3706 &cda
->remote_holddown_nve_count
);
3709 * Now do local prefixes
3711 rfapiDeleteLocalPrefixes (cda
);
3715 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3717 struct vty
*vty
= cda
->vty
; /* for benefit of VTY_NEWLINE */
3719 /* Our special element-deleting function counts nves */
3722 skiplist_free (cda
->nves
);
3725 if (cda
->failed_pfx_count
)
3726 vty_out (vty
, "Failed to delete %d prefixes%s",
3727 cda
->failed_pfx_count
, VTY_NEWLINE
);
3729 /* left as "prefixes" even in single case for ease of machine parsing */
3731 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs%s",
3732 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
, cda
->nve_count
,
3736 * We don't currently allow deletion of active remote prefixes from
3740 vty_out (vty
, "[Holddown] Cleared %u prefixes from %u NVEs%s",
3741 cda
->remote_holddown_pfx_count
, cda
->remote_holddown_nve_count
,
3746 * Caller has already deleted registrations and queries for this/these
3747 * NVEs. Now we just have to close their descriptors.
3750 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3752 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3753 struct nve_addr
*pKey
;
3754 struct nve_addr
*pValue
;
3755 void *cursor
= NULL
;
3761 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3763 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3768 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3769 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3770 rfapi_close (pValue
->rfd
);
3775 DEFUN (clear_vnc_nve_all
,
3776 clear_vnc_nve_all_cmd
,
3780 "Clear per NVE information\n"
3784 struct rfapi_local_reg_delete_arg cda
;
3787 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3792 clear_vnc_responses (&cda
);
3793 clear_vnc_prefix (&cda
);
3794 clear_vnc_nve_closer (&cda
);
3796 print_cleared_stats (&cda
);
3801 DEFUN (clear_vnc_nve_vn_un
,
3802 clear_vnc_nve_vn_un_cmd
,
3803 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3806 "Clear prefix registration information\n"
3807 "VN address of NVE\n"
3809 "VN IPv4 interface address\n"
3810 "VN IPv6 interface address\n"
3811 "UN address of NVE\n"
3812 "For all UN addresses\n"
3813 "UN IPv4 interface address\n"
3814 "UN IPv6 interface address\n")
3816 struct rfapi_local_reg_delete_arg cda
;
3820 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], argv
[6], NULL
, NULL
, NULL
, NULL
, &cda
)))
3825 clear_vnc_responses (&cda
);
3826 clear_vnc_prefix (&cda
);
3827 clear_vnc_nve_closer (&cda
);
3829 print_cleared_stats (&cda
);
3834 DEFUN (clear_vnc_nve_un_vn
,
3835 clear_vnc_nve_un_vn_cmd
,
3836 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3839 "Clear prefix registration information\n"
3840 "UN address of NVE\n"
3842 "UN IPv4 interface address\n"
3843 "UN IPv6 interface address\n"
3844 "VN address of NVE\n"
3846 "VN IPv4 interface address\n"
3847 "VN IPv6 interface address\n")
3849 struct rfapi_local_reg_delete_arg cda
;
3853 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[6], argv
[4], NULL
, NULL
, NULL
, NULL
, &cda
)))
3858 clear_vnc_responses (&cda
);
3859 clear_vnc_prefix (&cda
);
3860 clear_vnc_nve_closer (&cda
);
3862 print_cleared_stats (&cda
);
3867 DEFUN (clear_vnc_nve_vn
,
3868 clear_vnc_nve_vn_cmd
,
3869 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3872 "Clear prefix registration information\n"
3873 "VN address of NVE\n"
3875 "VN IPv4 interface address\n"
3876 "VN IPv6 interface address\n")
3878 struct rfapi_local_reg_delete_arg cda
;
3881 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3886 clear_vnc_responses (&cda
);
3887 clear_vnc_prefix (&cda
);
3888 clear_vnc_nve_closer (&cda
);
3890 print_cleared_stats (&cda
);
3894 DEFUN (clear_vnc_nve_un
,
3895 clear_vnc_nve_un_cmd
,
3896 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3899 "Clear prefix registration information\n"
3900 "UN address of NVE\n"
3902 "UN IPv4 interface address\n"
3903 "UN IPv6 interface address\n")
3905 struct rfapi_local_reg_delete_arg cda
;
3908 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[6], NULL
, NULL
, NULL
, NULL
, &cda
)))
3913 clear_vnc_responses (&cda
);
3914 clear_vnc_prefix (&cda
);
3915 clear_vnc_nve_closer (&cda
);
3917 print_cleared_stats (&cda
);
3921 /*-------------------------------------------------
3923 *-------------------------------------------------*/
3926 * This function is defined in this file (rather than in rfp_registration.c)
3927 * because here we have access to all the task handles.
3929 DEFUN (clear_vnc_prefix_vn_un
,
3930 clear_vnc_prefix_vn_un_cmd
,
3931 "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>",
3934 "Clear prefix registration information\n"
3938 "VN address of NVE\n"
3939 "All VN addresses\n"
3940 "VN IPv4 interface address\n"
3941 "VN IPv6 interface address\n"
3942 "UN address of NVE\n"
3943 "All UN addresses\n"
3944 "UN IPv4 interface address\n"
3945 "UN IPv6 interface address\n")
3947 struct rfapi_local_reg_delete_arg cda
;
3951 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], argv
[7], NULL
, NULL
, NULL
, NULL
, &cda
)))
3954 clear_vnc_prefix (&cda
);
3955 print_cleared_stats (&cda
);
3959 DEFUN (clear_vnc_prefix_un_vn
,
3960 clear_vnc_prefix_un_vn_cmd
,
3961 "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>",
3964 "Clear prefix registration information\n"
3968 "UN address of NVE\n"
3969 "All UN addresses\n"
3970 "UN IPv4 interface address\n"
3971 "UN IPv6 interface address\n"
3972 "VN address of NVE\n"
3973 "All VN addresses\n"
3974 "VN IPv4 interface address\n"
3975 "VN IPv6 interface address\n")
3977 struct rfapi_local_reg_delete_arg cda
;
3981 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[7], argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
3984 clear_vnc_prefix (&cda
);
3985 print_cleared_stats (&cda
);
3989 DEFUN (clear_vnc_prefix_un
,
3990 clear_vnc_prefix_un_cmd
,
3991 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3994 "Clear prefix registration information\n"
3998 "UN address of NVE\n"
3999 "All UN addresses\n"
4000 "UN IPv4 interface address\n"
4001 "UN IPv6 interface address\n")
4003 struct rfapi_local_reg_delete_arg cda
;
4007 parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
4010 clear_vnc_prefix (&cda
);
4011 print_cleared_stats (&cda
);
4015 DEFUN (clear_vnc_prefix_vn
,
4016 clear_vnc_prefix_vn_cmd
,
4017 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
4020 "Clear prefix registration information\n"
4024 "UN address of NVE\n"
4025 "All VN addresses\n"
4026 "VN IPv4 interface address\n"
4027 "VN IPv6 interface address\n")
4029 struct rfapi_local_reg_delete_arg cda
;
4033 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4036 clear_vnc_prefix (&cda
);
4037 print_cleared_stats (&cda
);
4041 DEFUN (clear_vnc_prefix_all
,
4042 clear_vnc_prefix_all_cmd
,
4043 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
4046 "Clear prefix registration information\n"
4052 struct rfapi_local_reg_delete_arg cda
;
4055 if ((rc
= parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4058 clear_vnc_prefix (&cda
);
4059 print_cleared_stats (&cda
);
4063 /*-------------------------------------------------
4065 *-------------------------------------------------*/
4068 * This function is defined in this file (rather than in rfp_registration.c)
4069 * because here we have access to all the task handles.
4071 DEFUN (clear_vnc_mac_vn_un
,
4072 clear_vnc_mac_vn_un_cmd
,
4073 "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>",
4076 "Clear mac registration information\n"
4080 "Any virtual network identifier\n"
4081 "Virtual network identifier\n"
4082 "Virtual network identifier\n"
4083 "VN address of NVE\n"
4084 "All VN addresses\n"
4085 "VN IPv4 interface address\n"
4086 "VN IPv6 interface address\n"
4087 "UN address of NVE\n"
4088 "All UN addresses\n"
4089 "UN IPv4 interface address\n"
4090 "UN IPv6 interface address\n")
4092 struct rfapi_local_reg_delete_arg cda
;
4095 /* pfx vn un L2 VNI */
4097 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], argv
[9], argv
[3], argv
[5],
4101 clear_vnc_prefix (&cda
);
4102 print_cleared_stats (&cda
);
4106 DEFUN (clear_vnc_mac_un_vn
,
4107 clear_vnc_mac_un_vn_cmd
,
4108 "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>",
4111 "Clear mac registration information\n"
4115 "Any virtual network identifier\n"
4116 "Virtual network identifier\n"
4117 "UN address of NVE\n"
4118 "All UN addresses\n"
4119 "UN IPv4 interface address\n"
4120 "UN IPv6 interface address\n"
4121 "VN address of NVE\n"
4122 "All VN addresses\n"
4123 "VN IPv4 interface address\n"
4124 "VN IPv6 interface address\n")
4126 struct rfapi_local_reg_delete_arg cda
;
4129 /* pfx vn un L2 VNI */
4131 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[9], argv
[7], argv
[3], argv
[5],
4135 clear_vnc_prefix (&cda
);
4136 print_cleared_stats (&cda
);
4140 DEFUN (clear_vnc_mac_un
,
4141 clear_vnc_mac_un_cmd
,
4142 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4145 "Clear mac registration information\n"
4149 "Any virtual network identifier\n"
4150 "Virtual network identifier\n"
4151 "UN address of NVE\n"
4152 "All UN addresses\n"
4153 "UN IPv4 interface address\n"
4154 "UN IPv6 interface address\n")
4156 struct rfapi_local_reg_delete_arg cda
;
4159 /* pfx vn un L2 VNI */
4161 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[7], argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4164 clear_vnc_prefix (&cda
);
4165 print_cleared_stats (&cda
);
4169 DEFUN (clear_vnc_mac_vn
,
4170 clear_vnc_mac_vn_cmd
,
4171 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4174 "Clear mac registration information\n"
4178 "Any virtual network identifier\n"
4179 "Virtual network identifier\n"
4180 "UN address of NVE\n"
4181 "All VN addresses\n"
4182 "VN IPv4 interface address\n"
4183 "VN IPv6 interface address\n")
4185 struct rfapi_local_reg_delete_arg cda
;
4188 /* pfx vn un L2 VNI */
4190 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4193 clear_vnc_prefix (&cda
);
4194 print_cleared_stats (&cda
);
4198 DEFUN (clear_vnc_mac_all
,
4199 clear_vnc_mac_all_cmd
,
4200 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4203 "Clear mac registration information\n"
4207 "Any virtual network identifier\n"
4208 "Virtual network identifier\n"
4211 struct rfapi_local_reg_delete_arg cda
;
4214 /* pfx vn un L2 VNI */
4216 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4219 clear_vnc_prefix (&cda
);
4220 print_cleared_stats (&cda
);
4224 /*-------------------------------------------------
4225 * Clear VNC MAC PREFIX
4226 *-------------------------------------------------*/
4228 DEFUN (clear_vnc_mac_vn_un_prefix
,
4229 clear_vnc_mac_vn_un_prefix_cmd
,
4230 "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>",
4233 "Clear mac registration information\n"
4237 "Any virtual network identifier\n"
4238 "Virtual network identifier\n"
4239 "VN address of NVE\n"
4240 "All VN addresses\n"
4241 "VN IPv4 interface address\n"
4242 "VN IPv6 interface address\n"
4243 "UN address of NVE\n"
4244 "All UN addresses\n"
4245 "UN IPv4 interface address\n"
4246 "UN IPv6 interface address\n"
4247 "Clear prefix registration information\n"
4252 struct rfapi_local_reg_delete_arg cda
;
4255 /* pfx vn un L2 VNI */
4257 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[7], argv
[9], argv
[3], argv
[5],
4261 clear_vnc_prefix (&cda
);
4262 print_cleared_stats (&cda
);
4266 DEFUN (clear_vnc_mac_un_vn_prefix
,
4267 clear_vnc_mac_un_vn_prefix_cmd
,
4268 "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>",
4271 "Clear mac registration information\n"
4275 "Any virtual network identifier\n"
4276 "Virtual network identifier\n"
4277 "UN address of NVE\n"
4278 "All UN addresses\n"
4279 "UN IPv4 interface address\n"
4280 "UN IPv6 interface address\n"
4281 "VN address of NVE\n"
4282 "All VN addresses\n"
4283 "VN IPv4 interface address\n"
4284 "VN IPv6 interface address\n"
4285 "Clear prefix registration information\n"
4289 "Clear prefix registration information\n"
4294 struct rfapi_local_reg_delete_arg cda
;
4297 /* pfx vn un L2 VNI */
4299 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[9], argv
[7], argv
[3], argv
[5],
4303 clear_vnc_prefix (&cda
);
4304 print_cleared_stats (&cda
);
4308 DEFUN (clear_vnc_mac_un_prefix
,
4309 clear_vnc_mac_un_prefix_cmd
,
4310 "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>",
4313 "Clear mac registration information\n"
4317 "Any virtual network identifier\n"
4318 "Virtual network identifier\n"
4319 "UN address of NVE\n"
4320 "All UN addresses\n"
4321 "UN IPv4 interface address\n"
4322 "UN IPv6 interface address\n"
4323 "Clear prefix registration information\n"
4328 struct rfapi_local_reg_delete_arg cda
;
4331 /* pfx vn un L2 VNI */
4333 parse_deleter_tokens (vty
, NULL
, argv
[9], NULL
, argv
[7], argv
[3], argv
[5],
4337 clear_vnc_prefix (&cda
);
4338 print_cleared_stats (&cda
);
4342 DEFUN (clear_vnc_mac_vn_prefix
,
4343 clear_vnc_mac_vn_prefix_cmd
,
4344 "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>",
4347 "Clear mac registration information\n"
4351 "Any virtual network identifier\n"
4352 "Virtual network identifier\n"
4353 "UN address of NVE\n"
4354 "All VN addresses\n"
4355 "VN IPv4 interface address\n"
4356 "VN IPv6 interface address\n"
4357 "Clear prefix registration information\n"
4362 struct rfapi_local_reg_delete_arg cda
;
4365 /* pfx vn un L2 VNI */
4367 parse_deleter_tokens (vty
, NULL
, argv
[9], argv
[7], NULL
, argv
[3], argv
[5],
4371 clear_vnc_prefix (&cda
);
4372 print_cleared_stats (&cda
);
4376 DEFUN (clear_vnc_mac_all_prefix
,
4377 clear_vnc_mac_all_prefix_cmd
,
4378 "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>",
4381 "Clear mac registration information\n"
4385 "Any virtual network identifier\n"
4386 "Virtual network identifier\n"
4387 "UN address of NVE\n"
4388 "All VN addresses\n"
4389 "VN IPv4 interface address\n"
4390 "VN IPv6 interface address\n")
4392 struct rfapi_local_reg_delete_arg cda
;
4395 /* pfx vn un L2 VNI */
4397 parse_deleter_tokens (vty
, NULL
, argv
[7], NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4400 clear_vnc_prefix (&cda
);
4401 print_cleared_stats (&cda
);
4405 /************************************************************************
4407 ************************************************************************/
4410 /* copied from rfp_vty.c */
4412 check_and_display_is_vnc_running (struct vty
*vty
)
4414 if (!bgp_rfapi_is_vnc_configured (NULL
))
4415 return 1; /* is running */
4420 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)%s",
4423 return 0; /* not running */
4427 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4429 struct bgp
*bgp_default
= bgp_get_default ();
4431 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4433 int active_local_routes
;
4434 int active_remote_routes
;
4435 int holddown_remote_routes
;
4436 int imported_remote_routes
;
4441 h
= bgp_default
->rfapi
;
4446 /* don't show local info if not running RFP */
4447 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4453 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4454 vty_out (vty
, "%-24s ", "NVEs:");
4455 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4456 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4457 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4460 case SHOW_NVE_SUMMARY_REGISTERED
:
4462 * NB: With the introduction of L2 route support, we no
4463 * longer have a one-to-one correspondence between
4464 * locally-originated route advertisements and routes in
4465 * the import tables that have local origin. This
4466 * discrepancy arises because a single advertisement
4467 * may contain both an IP prefix and a MAC address.
4468 * Such an advertisement results in two import table
4469 * entries: one indexed by IP prefix, the other indexed
4472 * TBD: update computation and display of registration
4473 * statistics to reflect the underlying semantics.
4477 vty_out (vty
, "%-24s ", "Registrations:");
4478 vty_out (vty
, "%-8s %-8u ", "Active:",
4479 rfapiApCountAll (bgp_default
));
4480 vty_out (vty
, "%-8s %-8u ", "Failed:",
4481 h
->stat
.count_registrations_failed
);
4482 vty_out (vty
, "%-8s %-8u", "Total:",
4483 h
->stat
.count_registrations
);
4484 vty_out (vty
, "%s", VTY_NEWLINE
);
4486 vty_out (vty
, "%-24s ", "Prefixes registered:");
4487 vty_out (vty
, "%s", VTY_NEWLINE
);
4489 rfapiCountAllItRoutes (&active_local_routes
,
4490 &active_remote_routes
,
4491 &holddown_remote_routes
,
4492 &imported_remote_routes
);
4497 vty_out (vty
, " %-20s ", "Locally:");
4498 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4499 vty_out (vty
, "%s", VTY_NEWLINE
);
4503 vty_out (vty
, " %-20s ", "Remotely:");
4504 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4505 vty_out (vty
, "%s", VTY_NEWLINE
);
4506 vty_out (vty
, " %-20s ", "In Holddown:");
4507 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4508 vty_out (vty
, "%s", VTY_NEWLINE
);
4509 vty_out (vty
, " %-20s ", "Imported:");
4510 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4513 case SHOW_NVE_SUMMARY_QUERIES
:
4514 vty_out (vty
, "%-24s ", "Queries:");
4515 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4516 vty_out (vty
, "%-8s %-8u ", "Failed:",
4517 h
->stat
.count_queries_failed
);
4518 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4521 case SHOW_NVE_SUMMARY_RESPONSES
:
4522 rfapiRibShowResponsesSummary (vty
);
4527 vty_out (vty
, "%s", VTY_NEWLINE
);
4532 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4539 struct prefix
*vn_prefix
,
4540 struct prefix
*un_prefix
)
4542 //struct hash *rfds;
4543 //struct rfp_rfapi_descriptor_param param;
4545 struct bgp
*bgp_default
= bgp_get_default ();
4547 struct listnode
*node
;
4548 struct rfapi_descriptor
*rfd
;
4557 h
= bgp_default
->rfapi
;
4562 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4566 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4569 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4572 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4581 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4582 if (!prefix_match (vn_prefix
, &pfx
))
4588 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4589 if (!prefix_match (un_prefix
, &pfx
))
4593 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4594 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4598 /* print out a header */
4600 "Active Next Hops%s", VTY_NEWLINE
);
4601 vty_out (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s%s",
4604 "Regis", "Resps", "Reach", "Remove", "Age", VTY_NEWLINE
);
4609 vty_out (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s%s",
4613 rfapi_monitor_count (rfd
),
4614 rfd
->stat_count_nh_reachable
,
4615 rfd
->stat_count_nh_removal
,
4616 rfapiFormatAge (rfd
->open_time
, age
, 10), VTY_NEWLINE
);
4619 if (printed
> 0 || vn_prefix
|| un_prefix
)
4620 vty_out (vty
, "Displayed %d out of %d active NVEs%s",
4621 printed
, total
, VTY_NEWLINE
);
4626 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4631 DEFUN (vnc_show_summary
,
4632 vnc_show_summary_cmd
,
4636 "Display VNC status summary\n")
4638 if (!check_and_display_is_vnc_running (vty
))
4640 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4641 vty_out (vty
, "%s", VTY_NEWLINE
);
4642 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4643 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4644 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4645 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4649 DEFUN (vnc_show_nves
,
4654 "List known NVEs\n")
4656 rfapi_show_nves (vty
, NULL
, NULL
);
4660 DEFUN (vnc_show_nves_ptct
,
4661 vnc_show_nves_ptct_cmd
,
4662 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4666 "VN address of NVE\n"
4667 "UN address of NVE\n"
4668 "IPv4 interface address\n"
4669 "IPv6 interface address\n")
4673 if (!check_and_display_is_vnc_running (vty
))
4676 if (!str2prefix (argv
[4]->arg
, &pfx
))
4678 vty_out (vty
, "Malformed address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4681 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4683 vty_out (vty
, "Invalid address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4687 if (argv
[3]->arg
[0] == 'u')
4689 rfapi_show_nves (vty
, NULL
, &pfx
);
4693 rfapi_show_nves (vty
, &pfx
, NULL
);
4699 /* adapted from rfp_registration_cache_log() */
4701 rfapi_show_registrations (
4703 struct prefix
*restrict_to
,
4714 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4718 /* non-expiring, local */
4719 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4723 /* non-expiring, non-local */
4724 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4728 /* expiring, including local */
4729 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4733 /* non-expiring, non-local */
4734 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4738 vty_out (vty
, "%s", VTY_NEWLINE
);
4742 DEFUN (vnc_show_registrations_pfx
,
4743 vnc_show_registrations_pfx_cmd
,
4744 "show vnc registrations [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4747 "List active prefix registrations\n"
4748 "Limit output to a particular IPv4 prefix\n"
4749 "Limit output to a particular IPv6 prefix\n"
4750 "Limit output to a particular IPv6 address\n")
4753 struct prefix
*p_addr
= NULL
;
4757 if (!str2prefix (argv
[3]->arg
, &p
))
4759 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4768 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4772 DEFUN (vnc_show_registrations_some_pfx
,
4773 vnc_show_registrations_some_pfx_cmd
,
4774 "show vnc registrations <all|holddown|imported|local|remote> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4777 "List active prefix registrations\n"
4778 "show all registrations\n"
4779 "show only registrations in holddown\n"
4780 "show only imported prefixes\n"
4781 "show only local registrations\n"
4782 "show only remote registrations\n"
4783 "Limit output to a particular prefix or address\n"
4784 "Limit output to a particular prefix or address\n"
4785 "Limit output to a particular prefix or address\n")
4788 struct prefix
*p_addr
= NULL
;
4791 int show_remote
= 0;
4792 int show_holddown
= 0;
4793 int show_imported
= 0;
4797 if (!str2prefix (argv
[4]->arg
, &p
))
4799 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4807 switch (argv
[3]->arg
[0])
4833 rfapi_show_registrations (vty
, p_addr
,
4834 show_local
, show_remote
, show_holddown
,
4839 DEFUN (vnc_show_responses_pfx
,
4840 vnc_show_responses_pfx_cmd
,
4841 "show vnc responses [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4844 "List recent query responses\n"
4845 "Limit output to a particular IPv4 prefix\n"
4846 "Limit output to a particular IPv6 prefix\n"
4847 "Limit output to a particular IPv6 address\n" )
4850 struct prefix
*p_addr
= NULL
;
4854 if (!str2prefix (argv
[3]->arg
, &p
))
4856 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4864 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4866 rfapiRibShowResponsesSummary (vty
);
4868 rfapiRibShowResponses (vty
, p_addr
, 0);
4869 rfapiRibShowResponses (vty
, p_addr
, 1);
4874 DEFUN (vnc_show_responses_some_pfx
,
4875 vnc_show_responses_some_pfx_cmd
,
4876 "show vnc responses <active|removed> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4879 "List recent query responses\n"
4880 "show only active query responses\n"
4881 "show only removed query responses\n"
4882 "Limit output to a particular IPv4 prefix\n"
4883 "Limit output to a particular IPv6 prefix\n"
4884 "Limit output to a particular IPV6 address\n")
4887 struct prefix
*p_addr
= NULL
;
4889 int show_active
= 0;
4890 int show_removed
= 0;
4892 if (!check_and_display_is_vnc_running (vty
))
4897 if (!str2prefix (argv
[4]->arg
, &p
))
4899 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4908 switch (argv
[3]->arg
[0])
4919 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4921 rfapiRibShowResponsesSummary (vty
);
4924 rfapiRibShowResponses (vty
, p_addr
, 0);
4926 rfapiRibShowResponses (vty
, p_addr
, 1);
4931 DEFUN (show_vnc_queries_pfx
,
4932 show_vnc_queries_pfx_cmd
,
4933 "show vnc queries [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4936 "List active queries\n"
4937 "Limit output to a particular IPv4 prefix or address\n"
4938 "Limit output to a particular IPv6 prefix\n"
4939 "Limit output to a particualr IPV6 address\n")
4942 struct prefix
*p
= NULL
;
4946 if (!str2prefix (argv
[3]->arg
, &pfx
))
4948 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4954 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4956 return rfapiShowVncQueries (vty
, p
);
4959 DEFUN (vnc_clear_counters
,
4960 vnc_clear_counters_cmd
,
4961 "clear vnc counters",
4964 "Reset VNC counters\n")
4966 struct bgp
*bgp_default
= bgp_get_default ();
4968 struct listnode
*node
;
4969 struct rfapi_descriptor
*rfd
;
4974 h
= bgp_default
->rfapi
;
4980 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4982 rfd
->stat_count_nh_reachable
= 0;
4983 rfd
->stat_count_nh_removal
= 0;
4987 memset (&h
->stat
, 0, sizeof (h
->stat
));
4990 * 151122 per bug 103, set count_registrations = number active.
4991 * Do same for queries
4993 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4994 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4996 rfapiRibShowResponsesSummaryClear ();
5001 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
5005 /************************************************************************
5006 * Add prefix with vrf
5008 * add [vrf <vrf-name>] prefix <prefix>
5009 * [rd <value>] [label <value>] [local-preference <0-4294967295>]
5010 ************************************************************************/
5012 vnc_add_vrf_prefix (struct vty
*vty
,
5013 const char *arg_vrf
,
5014 const char *arg_prefix
,
5015 const char *arg_rd
, /* optional */
5016 const char *arg_label
, /* optional */
5017 const char *arg_pref
) /* optional */
5020 struct rfapi_nve_group_cfg
*rfg
;
5022 struct rfapi_ip_prefix rpfx
;
5024 struct rfapi_vn_option optary
[3];
5025 struct rfapi_vn_option
*opt
= NULL
;
5028 bgp
= bgp_get_default (); /* assume main instance for now */
5031 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
5034 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5036 vty_out (vty
, "VRF support not configured%s", VTY_NEWLINE
);
5040 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5044 vty_out (vty
, "VRF \"%s\" appears not to be configured.%s",
5045 arg_vrf
, VTY_NEWLINE
);
5048 if (!rfg
->rt_export_list
|| !rfg
->rfapi_import_table
)
5050 vty_out (vty
, "VRF \"%s\" is missing RT import/export RT configuration.%s",
5051 arg_vrf
, VTY_NEWLINE
);
5054 if (!rfg
->rd
.family
&& !arg_rd
)
5056 vty_out (vty
, "VRF \"%s\" isn't configured with an RD, so RD must be provided.%s",
5057 arg_vrf
, VTY_NEWLINE
);
5060 if (rfg
->label
> MPLS_LABEL_MAX
&& !arg_label
)
5062 vty_out (vty
, "VRF \"%s\" isn't configured with a default labels, so a label must be provided.%s",
5063 arg_vrf
, VTY_NEWLINE
);
5066 if (!str2prefix (arg_prefix
, &pfx
))
5068 vty_out (vty
, "Malformed prefix \"%s\"%s",
5069 arg_prefix
, VTY_NEWLINE
);
5072 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
5073 memset (optary
, 0, sizeof (optary
));
5077 opt
->next
= &optary
[cur_opt
];
5078 opt
= &optary
[cur_opt
++];
5079 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
5080 if (!str2prefix_rd (arg_rd
, &opt
->v
.internal_rd
))
5082 vty_out (vty
, "Malformed RD \"%s\"%s",
5083 arg_rd
, VTY_NEWLINE
);
5087 if (rfg
->label
<= MPLS_LABEL_MAX
|| arg_label
)
5089 struct rfapi_l2address_option
*l2o
;
5091 opt
->next
= &optary
[cur_opt
];
5092 opt
= &optary
[cur_opt
++];
5093 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
5094 l2o
= &opt
->v
.l2addr
;
5098 VTY_GET_INTEGER_RANGE ("Label value", label
, arg_label
, 0, MPLS_LABEL_MAX
);
5102 l2o
->label
= rfg
->label
;
5106 char *endptr
= NULL
;
5107 pref
= strtoul (arg_pref
, &endptr
, 10);
5108 if (*endptr
!= '\0')
5110 vty_out (vty
, "%% Invalid local-preference value \"%s\"%s", arg_pref
, VTY_NEWLINE
);
5114 rpfx
.cost
= 255 - (pref
& 255) ;
5115 if (rfg
->rfd
== NULL
) /* need new rfapi_handle */
5117 /* based on rfapi_open */
5118 struct rfapi_descriptor
*rfd
;
5119 rfd
= XCALLOC (MTYPE_RFAPI_DESC
, sizeof (struct rfapi_descriptor
));
5122 /* leave most fields empty as will get from (dynamic) config when needed */
5123 rfd
->default_tunneltype_option
.type
= BGP_ENCAP_TYPE_MPLS
;
5125 if (rfg
->vn_prefix
.family
&&
5126 !CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
))
5128 rfapiQprefix2Raddr(&rfg
->vn_prefix
, &rfd
->vn_addr
);
5132 memset(&rfd
->vn_addr
, 0, sizeof(struct rfapi_ip_addr
));
5133 rfd
->vn_addr
.addr_family
= AF_INET
;
5134 rfd
->vn_addr
.addr
.v4
= bgp
->router_id
;
5136 rfd
->un_addr
= rfd
->vn_addr
; /* sigh, need something in UN for lookups */
5137 vnc_zlog_debug_verbose ("%s: Opening RFD for VRF %s",
5138 __func__
, rfg
->name
);
5139 rfapi_init_and_open(bgp
, rfd
, rfg
);
5142 if (!rfapi_register (rfg
->rfd
, &rpfx
, RFAPI_INFINITE_LIFETIME
, NULL
,
5143 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_ADD
))
5145 struct rfapi_next_hop_entry
*head
= NULL
;
5146 struct rfapi_next_hop_entry
*tail
= NULL
;
5147 struct rfapi_vn_option
*vn_opt_new
;
5149 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded", __func__
);
5151 if (bgp
->rfapi
->rfp_methods
.local_cb
)
5153 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfg
->rfd
;
5154 vn_opt_new
= rfapi_vn_options_dup (opt
);
5156 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
5157 1, RFAPI_INFINITE_LIFETIME
,
5158 vn_opt_new
, &head
, &tail
);
5161 bgp
->rfapi
->flags
|= RFAPI_INCALLBACK
;
5162 (*bgp
->rfapi
->rfp_methods
.local_cb
) (head
, r
->cookie
);
5163 bgp
->rfapi
->flags
&= ~RFAPI_INCALLBACK
;
5167 vnc_zlog_debug_verbose ("%s completed, count=%d/%d", __func__
,
5168 rfg
->rfapi_import_table
->local_count
[AFI_IP
],
5169 rfg
->rfapi_import_table
->local_count
[AFI_IP6
]);
5173 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
5174 vty_out (vty
, "Add failed.%s", VTY_NEWLINE
);
5178 DEFUN (add_vrf_prefix_rd_label_pref
,
5179 add_vrf_prefix_rd_label_pref_cmd
,
5180 "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)}]",
5184 "Add/modify prefix related information\n"
5187 "Override configured VRF Route Distinguisher\n"
5188 "<as-number>:<number> or <ip-address>:<number>\n"
5189 "Override configured VRF label\n"
5190 "Label Value <0-1048575>\n"
5191 "Set advertised local preference\n"
5192 "local preference (higher=more preferred)\n")
5194 char *arg_vrf
= argv
[2]->arg
;
5195 char *arg_prefix
= argv
[4]->arg
;
5196 char *arg_rd
= NULL
; /* optional */
5197 char *arg_label
= NULL
; /* optional */
5198 char *arg_pref
= NULL
; /* optional */
5200 argc
--; /* don't parse argument */
5201 while (pargc
< argc
)
5203 switch (argv
[pargc
++]->arg
[0])
5206 arg_rd
= argv
[pargc
]->arg
;
5209 arg_label
= argv
[pargc
]->arg
;
5212 arg_pref
= argv
[pargc
]->arg
;
5220 return vnc_add_vrf_prefix (vty
, arg_vrf
, arg_prefix
, arg_rd
, arg_label
, arg_pref
);
5223 /************************************************************************
5224 * del prefix with vrf
5226 * clear [vrf <vrf-name>] prefix <prefix> [rd <value>]
5227 ************************************************************************/
5229 rfapi_cfg_group_it_count(struct rfapi_nve_group_cfg
*rfg
)
5232 afi_t afi
= AFI_MAX
;
5235 count
+= rfg
->rfapi_import_table
->local_count
[afi
];
5241 clear_vnc_vrf_closer (struct rfapi_nve_group_cfg
*rfg
)
5243 struct rfapi_descriptor
*rfd
= rfg
->rfd
;
5248 /* check if IT is empty */
5250 afi
< AFI_MAX
&& rfg
->rfapi_import_table
->local_count
[afi
] == 0;
5255 vnc_zlog_debug_verbose ("%s: closing RFD for VRF %s",
5256 __func__
, rfg
->name
);
5262 vnc_zlog_debug_verbose ("%s: VRF %s afi=%d count=%d",
5263 __func__
, rfg
->name
, afi
,
5264 rfg
->rfapi_import_table
->local_count
[afi
]);
5269 vnc_clear_vrf (struct vty
*vty
,
5271 const char *arg_vrf
,
5272 const char *arg_prefix
, /* NULL = all */
5273 const char *arg_rd
) /* optional */
5275 struct rfapi_nve_group_cfg
*rfg
;
5276 struct rfapi_local_reg_delete_arg cda
;
5281 bgp
= bgp_get_default (); /* assume main instance for now */
5284 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
5287 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5289 vty_out (vty
, "VRF support not configured%s", VTY_NEWLINE
);
5292 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5296 vty_out (vty
, "VRF \"%s\" appears not to be configured.%s",
5297 arg_vrf
, VTY_NEWLINE
);
5300 rc
= parse_deleter_args (vty
, bgp
, arg_prefix
, NULL
, NULL
, NULL
, NULL
,
5302 if (rc
!= CMD_SUCCESS
) /* parse error */
5305 start_count
= rfapi_cfg_group_it_count(rfg
);
5306 clear_vnc_prefix (&cda
);
5307 clear_vnc_vrf_closer (rfg
);
5308 vty_out (vty
, "Cleared %u out of %d prefixes.%s",
5309 cda
.pfx_count
, start_count
, VTY_NEWLINE
);
5313 DEFUN (clear_vrf_prefix_rd
,
5314 clear_vrf_prefix_rd_cmd
,
5315 "clear vrf NAME [prefix <A.B.C.D/M|X:X::X:X/M>] [rd ASN:nn_or_IP-address]",
5316 "Clear stored data\n"
5319 "Prefix related information\n"
5322 "Specific VRF Route Distinguisher\n"
5323 "<as-number>:<number> or <ip-address>:<number>\n")
5325 char *arg_vrf
= argv
[2]->arg
;
5326 char *arg_prefix
= NULL
; /* optional */
5327 char *arg_rd
= NULL
; /* optional */
5329 argc
--; /* don't check parameter */
5330 while (pargc
< argc
)
5332 switch (argv
[pargc
++]->arg
[0])
5335 arg_rd
= argv
[pargc
]->arg
;
5338 arg_prefix
= argv
[pargc
]->arg
;
5345 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, arg_prefix
, arg_rd
);
5348 DEFUN (clear_vrf_all
,
5350 "clear vrf NAME all",
5351 "Clear stored data\n"
5356 char *arg_vrf
= argv
[2]->arg
;
5357 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, NULL
, NULL
);
5360 void rfapi_vty_init ()
5362 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
5363 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
5364 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
5365 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
5366 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
5368 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
5369 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
5370 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
5371 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
5372 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
5374 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
5375 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
5376 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
5377 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
5378 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
5379 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
5380 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
5381 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
5383 install_element (ENABLE_NODE
, &add_vrf_prefix_rd_label_pref_cmd
);
5385 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
5386 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
5387 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
5388 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
5389 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
5391 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
5392 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
5393 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
5394 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
5395 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
5397 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
5398 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
5399 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
5400 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
5401 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
5403 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
5404 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
5405 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
5406 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
5407 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
5409 install_element (ENABLE_NODE
, &clear_vrf_prefix_rd_cmd
);
5410 install_element (ENABLE_NODE
, &clear_vrf_all_cmd
);
5412 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
5414 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
5415 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
5416 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
5418 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
5419 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
5420 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
5421 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
5422 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);