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/log_int.h"
33 #include "lib/linklist.h"
34 #include "lib/command.h"
36 #include "bgpd/bgpd.h"
37 #include "bgpd/bgp_ecommunity.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_route.h"
40 #include "bgpd/bgp_mplsvpn.h"
42 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
43 #include "bgpd/rfapi/rfapi.h"
44 #include "bgpd/rfapi/rfapi_backend.h"
46 #include "bgpd/bgp_route.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_community.h"
49 #include "bgpd/bgp_vnc_types.h"
51 #include "bgpd/rfapi/rfapi_import.h"
52 #include "bgpd/rfapi/rfapi_private.h"
53 #include "bgpd/rfapi/rfapi_monitor.h"
54 #include "bgpd/rfapi/rfapi_rib.h"
55 #include "bgpd/rfapi/rfapi_vty.h"
56 #include "bgpd/rfapi/rfapi_ap.h"
57 #include "bgpd/rfapi/rfapi_encap_tlv.h"
58 #include "bgpd/rfapi/vnc_debug.h"
60 #define DEBUG_L2_EXTRA 0
61 #define DEBUG_SHOW_EXTRA 0
63 #define VNC_SHOW_STR "VNC information\n"
65 /* format related utilies */
68 #define FMT_MIN 60 /* seconds */
69 #define FMT_HOUR (60 * FMT_MIN)
70 #define FMT_DAY (24 * FMT_HOUR)
71 #define FMT_YEAR (365 * FMT_DAY)
74 rfapiFormatSeconds (uint32_t seconds
, char *buf
, size_t len
)
76 int year
, day
, hour
, min
;
78 if (seconds
>= FMT_YEAR
)
80 year
= seconds
/ FMT_YEAR
;
81 seconds
-= year
* FMT_YEAR
;
86 if (seconds
>= FMT_DAY
)
88 day
= seconds
/ FMT_DAY
;
89 seconds
-= day
* FMT_DAY
;
94 if (seconds
>= FMT_HOUR
)
96 hour
= seconds
/ FMT_HOUR
;
97 seconds
-= hour
* FMT_HOUR
;
102 if (seconds
>= FMT_MIN
)
104 min
= seconds
/ FMT_MIN
;
105 seconds
-= min
* FMT_MIN
;
112 snprintf (buf
, len
, "%dy%dd%dh", year
, day
, hour
);
116 snprintf (buf
, len
, "%dd%dh%dm", day
, hour
, min
);
120 snprintf (buf
, len
, "%02d:%02d:%02d", hour
, min
, seconds
);
127 rfapiFormatAge (time_t age
, char *buf
, size_t len
)
129 time_t now
, age_adjusted
;
131 now
= rfapi_time (NULL
);
132 age_adjusted
= now
- age
;
134 return rfapiFormatSeconds (age_adjusted
, buf
, len
);
139 * Reimplementation of quagga/lib/prefix.c function, but
140 * for RFAPI-style prefixes
143 rfapiRprefixApplyMask (struct rfapi_ip_prefix
*rprefix
)
149 static uint8_t maskbit
[] =
150 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
152 switch (rprefix
->prefix
.addr_family
)
155 index
= rprefix
->length
/ 8;
158 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v4
;
159 offset
= rprefix
->length
% 8;
160 pnt
[index
] &= maskbit
[offset
];
168 index
= rprefix
->length
/ 8;
171 pnt
= (uint8_t *) & rprefix
->prefix
.addr
.v6
;
172 offset
= rprefix
->length
% 8;
173 pnt
[index
] &= maskbit
[offset
];
186 * translate a quagga prefix into a rfapi IP address. The
187 * prefix is REQUIRED to be 32 bits for IPv4 and 128 bits for IPv6
195 rfapiQprefix2Raddr (struct prefix
*qprefix
, struct rfapi_ip_addr
*raddr
)
197 memset (raddr
, 0, sizeof (struct rfapi_ip_addr
));
198 raddr
->addr_family
= qprefix
->family
;
199 switch (qprefix
->family
)
202 if (qprefix
->prefixlen
!= 32)
204 raddr
->addr
.v4
= qprefix
->u
.prefix4
;
207 if (qprefix
->prefixlen
!= 128)
209 raddr
->addr
.v6
= qprefix
->u
.prefix6
;
218 * Translate Quagga prefix to RFAPI prefix
220 /* rprefix->cost set to 0 */
222 rfapiQprefix2Rprefix (struct prefix
*qprefix
, struct rfapi_ip_prefix
*rprefix
)
224 memset (rprefix
, 0, sizeof (struct rfapi_ip_prefix
));
225 rprefix
->length
= qprefix
->prefixlen
;
226 rprefix
->prefix
.addr_family
= qprefix
->family
;
227 switch (qprefix
->family
)
230 rprefix
->prefix
.addr
.v4
= qprefix
->u
.prefix4
;
233 rprefix
->prefix
.addr
.v6
= qprefix
->u
.prefix6
;
241 rfapiRprefix2Qprefix (struct rfapi_ip_prefix
*rprefix
, struct prefix
*qprefix
)
243 memset (qprefix
, 0, sizeof (struct prefix
));
244 qprefix
->prefixlen
= rprefix
->length
;
245 qprefix
->family
= rprefix
->prefix
.addr_family
;
247 switch (rprefix
->prefix
.addr_family
)
250 qprefix
->u
.prefix4
= rprefix
->prefix
.addr
.v4
;
253 qprefix
->u
.prefix6
= rprefix
->prefix
.addr
.v6
;
262 * returns 1 if prefixes have same addr family, prefix len, and address
263 * Note that host bits matter in this comparison!
265 * For paralellism with quagga/lib/prefix.c. if we need a comparison
266 * where host bits are ignored, call that function rfapiRprefixCmp.
269 rfapiRprefixSame (struct rfapi_ip_prefix
*hp1
, struct rfapi_ip_prefix
*hp2
)
271 if (hp1
->prefix
.addr_family
!= hp2
->prefix
.addr_family
)
273 if (hp1
->length
!= hp2
->length
)
275 if (hp1
->prefix
.addr_family
== AF_INET
)
276 if (IPV4_ADDR_SAME (&hp1
->prefix
.addr
.v4
, &hp2
->prefix
.addr
.v4
))
278 if (hp1
->prefix
.addr_family
== AF_INET6
)
279 if (IPV6_ADDR_SAME (&hp1
->prefix
.addr
.v6
, &hp2
->prefix
.addr
.v6
))
285 rfapiRaddr2Qprefix (struct rfapi_ip_addr
*hia
, struct prefix
*pfx
)
287 memset (pfx
, 0, sizeof (struct prefix
));
288 pfx
->family
= hia
->addr_family
;
290 switch (hia
->addr_family
)
294 pfx
->u
.prefix4
= hia
->addr
.v4
;
297 pfx
->prefixlen
= 128;
298 pfx
->u
.prefix6
= hia
->addr
.v6
;
307 rfapiL2o2Qprefix (struct rfapi_l2address_option
*l2o
, struct prefix
*pfx
)
309 memset (pfx
, 0, sizeof (struct prefix
));
310 pfx
->family
= AF_ETHERNET
;
312 pfx
->u
.prefix_eth
= l2o
->macaddr
;
316 rfapiEthAddr2Str (const struct ethaddr
*ea
, char *buf
, int bufsize
)
318 return prefix_mac2str (ea
, buf
, bufsize
);
322 rfapiStr2EthAddr (const char *str
, struct ethaddr
*ea
)
327 if (sscanf (str
, "%2x:%2x:%2x:%2x:%2x:%2x",
328 a
+ 0, a
+ 1, a
+ 2, a
+ 3, a
+ 4, a
+ 5) != 6)
334 for (i
= 0; i
< 6; ++i
)
335 ea
->octet
[i
] = a
[i
] & 0xff;
341 rfapi_ntop (int af
, const void *src
, char *buf
, socklen_t size
)
343 if (af
== AF_ETHERNET
)
345 return rfapiEthAddr2Str ((const struct ethaddr
*) src
, buf
, size
);
348 return inet_ntop (af
, src
, buf
, size
);
352 rfapiDebugPrintf (void *dummy
, const char *format
, ...)
355 va_start (args
, format
);
356 vzlog (LOG_DEBUG
, format
, args
);
362 rfapiStdioPrintf (void *stream
, const char *format
, ...)
367 va_start (args
, format
);
369 switch ((uintptr_t) stream
)
381 vfprintf (file
, format
, args
);
386 /* Fake out for debug logging */
387 static struct vty vty_dummy_zlog
;
388 static struct vty vty_dummy_stdio
;
389 #define HVTY_NEWLINE ((vty == &vty_dummy_zlog)? "": VTY_NEWLINE)
392 str_vty_newline (struct vty
*vty
)
394 if (vty
== &vty_dummy_zlog
)
401 void *stream
, /* input */
402 int (**fp
) (void *, const char *, ...), /* output */
403 struct vty
**vty
, /* output */
404 void **outstream
, /* output */
405 const char **vty_newline
) /* output */
410 vty_dummy_zlog
.type
= VTY_SHELL
; /* for VTY_NEWLINE */
411 *vty
= &vty_dummy_zlog
;
412 *fp
= (int (*)(void *, const char *,...)) rfapiDebugPrintf
;
414 *vty_newline
= str_vty_newline (*vty
);
415 return (vzlog_test (LOG_DEBUG
));
418 if (((uintptr_t) stream
== (uintptr_t) 1) ||
419 ((uintptr_t) stream
== (uintptr_t) 2))
422 vty_dummy_stdio
.type
= VTY_SHELL
; /* for VTY_NEWLINE */
423 *vty
= &vty_dummy_stdio
;
424 *fp
= (int (*)(void *, const char *,...)) rfapiStdioPrintf
;
426 *vty_newline
= str_vty_newline (*vty
);
432 *vty
= stream
; /* VTY_NEWLINE requires vty to be legit */
433 *fp
= (int (*)(void *, const char *,...)) vty_out
;
435 *vty_newline
= str_vty_newline (*vty
);
442 /* called from bgpd/bgp_vty.c'route_vty_out() */
444 rfapi_vty_out_vncinfo (
454 * Print, on an indented line:
455 * UN address [if VPN route and VNC UN addr subtlv]
461 if (safi
== SAFI_MPLS_VPN
)
463 struct prefix pfx_un
;
465 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
468 vty_out (vty
, "UN=%s", inet_ntop (pfx_un
.family
,
469 pfx_un
.u
.val
, buf
, BUFSIZ
));
473 if (bi
->attr
&& bi
->attr
->extra
&& bi
->attr
->extra
->ecommunity
)
475 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
476 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
477 vty_out (vty
, " EC{%s}", s
);
478 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
481 if (bi
->extra
!= NULL
)
482 vty_out (vty
, " label=%u", decode_label (bi
->extra
->tag
));
484 if (!rfapiGetVncLifetime (bi
->attr
, &lifetime
))
486 vty_out (vty
, " life=%d", lifetime
);
489 vty_out (vty
, " type=%s, subtype=%d",
490 zebra_route_string (bi
->type
), bi
->sub_type
);
492 vty_out (vty
, "%s", HVTY_NEWLINE
);
496 rfapiPrintAttrPtrs (void *stream
, struct attr
*attr
)
498 int (*fp
) (void *, const char *, ...);
501 const char *vty_newline
;
503 struct attr_extra
*ae
;
506 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
509 fp (out
, "Attr[%p]:%s", attr
, HVTY_NEWLINE
);
514 inet_ntop (AF_INET
, &attr
->nexthop
, buf
, BUFSIZ
);
515 fp (out
, " nexthop=%s%s", buf
, HVTY_NEWLINE
);
517 fp (out
, " aspath=%p, refcnt=%d%s", attr
->aspath
,
518 (attr
->aspath
? attr
->aspath
->refcnt
: 0), HVTY_NEWLINE
);
519 fp (out
, " community=%p, refcnt=%d%s", attr
->community
,
520 (attr
->community
? attr
->community
->refcnt
: 0), HVTY_NEWLINE
);
522 if ((ae
= attr
->extra
))
524 fp (out
, " ecommunity=%p, refcnt=%d%s", ae
->ecommunity
,
525 (ae
->ecommunity
? ae
->ecommunity
->refcnt
: 0), HVTY_NEWLINE
);
526 fp (out
, " cluster=%p, refcnt=%d%s", ae
->cluster
,
527 (ae
->cluster
? ae
->cluster
->refcnt
: 0), HVTY_NEWLINE
);
528 fp (out
, " transit=%p, refcnt=%d%s", ae
->transit
,
529 (ae
->transit
? ae
->transit
->refcnt
: 0), HVTY_NEWLINE
);
534 * Print BI in an Import Table
537 rfapiPrintBi (void *stream
, struct bgp_info
*bi
)
542 int (*fp
) (void *, const char *, ...);
545 const char *vty_newline
;
551 struct ethaddr macaddr
;
552 struct rfapi_l2address_option l2o_buf
;
553 uint8_t l2hid
=0; /* valid if has_macaddr */
555 #define REMAIN (BUFSIZ - (p-line))
556 #define INCP {p += (r > REMAIN)? REMAIN: r;}
558 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
564 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) && bi
->extra
565 && bi
->extra
->vnc
.import
.timer
)
567 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
568 r
= snprintf (p
, REMAIN
, " [%4lu] ", thread_timer_remain_second (t
));
574 r
= snprintf (p
, REMAIN
, " ");
580 /* TBD This valid only for SAFI_MPLS_VPN, but not for encap */
581 if (decode_rd_type(bi
->extra
->vnc
.import
.rd
.val
) == RD_TYPE_VNC_ETH
)
584 memcpy (macaddr
.octet
, bi
->extra
->vnc
.import
.rd
.val
+ 2, 6);
585 l2hid
= bi
->extra
->vnc
.import
.rd
.val
[1];
594 * RFP option sizes (they are opaque values)
595 * extended communities (RTs)
597 if (bi
->attr
&& bi
->attr
->extra
)
600 int printed_1st_gol
= 0;
601 struct bgp_attr_encap_subtlv
*pEncap
;
602 struct prefix pfx_un
;
603 int af
= BGP_MP_NEXTHOP_FAMILY (bi
->attr
->extra
->mp_nexthop_len
);
608 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET
,
609 &bi
->attr
->extra
->mp_nexthop_global_in
,
613 else if (af
== AF_INET6
)
615 r
= snprintf (p
, REMAIN
, "%s", inet_ntop (AF_INET6
,
616 &bi
->attr
->extra
->mp_nexthop_global
,
622 r
= snprintf (p
, REMAIN
, "?");
627 * VNC tunnel subtlv, if present, contains UN address
629 if (!rfapiGetVncTunnelUnAddr (bi
->attr
, &pfx_un
))
631 r
= snprintf (p
, REMAIN
, " un=%s", inet_ntop (pfx_un
.family
,
639 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
))
641 r
= snprintf (p
, REMAIN
, " nolife");
646 if (lifetime
== 0xffffffff)
647 r
= snprintf (p
, REMAIN
, " %6s", "infini");
649 r
= snprintf (p
, REMAIN
, " %6u", lifetime
);
653 /* RFP option lengths */
654 for (pEncap
= bi
->attr
->extra
->vnc_subtlvs
; pEncap
;
655 pEncap
= pEncap
->next
)
658 if (pEncap
->type
== BGP_VNC_SUBTLV_TYPE_RFPOPTION
)
662 r
= snprintf (p
, REMAIN
, ",");
667 r
= snprintf (p
, REMAIN
, " "); /* leading space */
670 r
= snprintf (p
, REMAIN
, "%d", pEncap
->length
);
677 if (bi
->attr
->extra
->ecommunity
)
679 s
= ecommunity_ecom2str (bi
->attr
->extra
->ecommunity
,
680 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
681 r
= snprintf (p
, REMAIN
, " %s", s
);
683 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
688 r
= snprintf (p
, REMAIN
, " bi@%p", bi
);
691 r
= snprintf (p
, REMAIN
, " p@%p", bi
->peer
);
694 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
696 r
= snprintf (p
, REMAIN
, " HD=yes");
701 r
= snprintf (p
, REMAIN
, " HD=no");
710 r
= snprintf (p
, REMAIN
, " W=%d", bi
->attr
->extra
->weight
);
714 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
716 r
= snprintf (p
, REMAIN
, " LP=%d", bi
->attr
->local_pref
);
721 r
= snprintf (p
, REMAIN
, " LP=unset");
727 snprintf (p
, REMAIN
, " %c:%u", zebra_route_char (bi
->type
), bi
->sub_type
);
730 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
734 fp (out
, " RD HID=%d ETH=%02x:%02x:%02x:%02x:%02x:%02x%s",
739 macaddr
.octet
[3], macaddr
.octet
[4], macaddr
.octet
[5], HVTY_NEWLINE
);
742 if (!rfapiGetL2o (bi
->attr
, &l2o_buf
))
745 " L2O ETH=%02x:%02x:%02x:%02x:%02x:%02x LBL=%d LNI=%d LHI=%hhu%s",
746 l2o_buf
.macaddr
.octet
[0], l2o_buf
.macaddr
.octet
[1],
747 l2o_buf
.macaddr
.octet
[2], l2o_buf
.macaddr
.octet
[3],
748 l2o_buf
.macaddr
.octet
[4], l2o_buf
.macaddr
.octet
[5], l2o_buf
.label
,
749 l2o_buf
.logical_net_id
, l2o_buf
.local_nve_id
, HVTY_NEWLINE
);
751 if (bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
756 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
757 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
762 fp (out
, " IP: %s%s", sp
, HVTY_NEWLINE
);
766 struct rfapi_un_option
*uo
= rfapi_encap_tlv_to_un_option (bi
->attr
);
769 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
770 rfapi_un_options_free (uo
);
776 rfapiMonitorVpn2Str (struct rfapi_monitor_vpn
*m
, char *buf
, int size
)
778 char buf_pfx
[BUFSIZ
];
783 rfapiRfapiIpAddr2Str (&m
->rfd
->un_addr
, buf_vn
, BUFSIZ
);
784 rfapiRfapiIpAddr2Str (&m
->rfd
->vn_addr
, buf_un
, BUFSIZ
);
786 rc
= snprintf (buf
, size
,
787 "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p",
788 m
, m
->next
, m
->rfd
, buf_vn
, buf_un
,
789 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
790 m
->p
.prefixlen
, m
->node
);
798 rfapiDebugPrintMonitorVpn (void *stream
, struct rfapi_monitor_vpn
*m
)
802 int (*fp
) (void *, const char *, ...);
805 const char *vty_newline
;
807 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
810 rfapiMonitorVpn2Str (m
, buf
, BUFSIZ
);
811 fp (out
, " Mon %s%s", buf
, HVTY_NEWLINE
);
815 rfapiDebugPrintMonitorEncap (void *stream
, struct rfapi_monitor_encap
*m
)
817 int (*fp
) (void *, const char *, ...);
820 const char *vty_newline
;
822 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
825 fp (out
, " Mon m=%p, next=%p, node=%p, bi=%p%s",
826 m
, m
->next
, m
->node
, m
->bi
, HVTY_NEWLINE
);
830 rfapiShowItNode (void *stream
, struct route_node
*rn
)
835 int (*fp
) (void *, const char *, ...);
838 const char *vty_newline
;
840 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
843 fp (out
, "%s/%d @%p #%d%s",
844 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
845 rn
->p
.prefixlen
, rn
, rn
->lock
, HVTY_NEWLINE
);
847 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
849 rfapiPrintBi (stream
, bi
);
852 /* doesn't show montors */
856 rfapiShowImportTable (
859 struct route_table
*rt
,
862 struct route_node
*rn
;
865 int (*fp
) (void *, const char *, ...);
868 const char *vty_newline
;
870 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
873 fp (out
, "Import Table [%s]%s", label
, HVTY_NEWLINE
);
875 for (rn
= route_top (rt
); rn
; rn
= route_next (rn
))
879 if (rn
->p
.family
== AF_ETHERNET
)
881 rfapiEthAddr2Str (&rn
->p
.u
.prefix_eth
, buf
, BUFSIZ
);
885 inet_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
);
888 fp (out
, "%s/%d @%p #%d%s", buf
, rn
->p
.prefixlen
, rn
, rn
->lock
- 1, /* account for loop iterator locking */
891 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
893 rfapiPrintBi (stream
, bi
);
898 struct rfapi_monitor_vpn
*m
;
899 for (m
= RFAPI_MONITOR_VPN (rn
); m
; m
= m
->next
)
901 rfapiDebugPrintMonitorVpn (stream
, m
);
906 struct rfapi_monitor_encap
*m
;
907 for (m
= RFAPI_MONITOR_ENCAP (rn
); m
; m
= m
->next
)
909 rfapiDebugPrintMonitorEncap (stream
, m
);
916 rfapiShowVncQueries (void *stream
, struct prefix
*pfx_match
)
920 struct listnode
*node
;
921 struct rfapi_descriptor
*rfd
;
923 int (*fp
) (void *, const char *, ...);
926 const char *vty_newline
;
928 int printedheader
= 0;
931 int nves_with_queries
= 0;
932 int nves_displayed
= 0;
934 int queries_total
= 0;
935 int queries_displayed
= 0;
937 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
940 bgp
= bgp_get_default (); /* assume 1 instance for now */
943 vty_out (vty
, "No BGP instance%s", VTY_NEWLINE
);
950 vty_out (vty
, "No RFAPI instance%s", VTY_NEWLINE
);
954 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
957 struct route_node
*rn
;
958 int printedquerier
= 0;
963 if (rfd
->mon
|| (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
)))
977 for (rn
= route_top (rfd
->mon
); rn
; rn
= route_next (rn
))
979 struct rfapi_monitor_vpn
*m
;
980 char buf_remain
[BUFSIZ
];
981 char buf_pfx
[BUFSIZ
];
990 if (pfx_match
&& !prefix_match (pfx_match
, &rn
->p
) &&
991 !prefix_match (&rn
->p
, pfx_match
))
999 fp (out
, "%s", VTY_NEWLINE
);
1000 fp (out
, "%-15s %-15s %-15s %-10s%s",
1001 "VN Address", "UN Address",
1002 "Target", "Remaining", VTY_NEWLINE
);
1005 if (!printedquerier
)
1007 char buf_vn
[BUFSIZ
];
1008 char buf_un
[BUFSIZ
];
1010 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1011 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1013 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1019 fp (out
, "%-15s %-15s", "", "");
1023 rfapiFormatSeconds (thread_timer_remain_second (m
->timer
),
1024 buf_remain
, BUFSIZ
);
1026 fp (out
, " %-15s %-10s%s",
1027 inet_ntop (m
->p
.family
, &m
->p
.u
.prefix
, buf_pfx
, BUFSIZ
),
1028 buf_remain
, VTY_NEWLINE
);
1035 if (rfd
->mon_eth
&& skiplist_count (rfd
->mon_eth
))
1040 struct rfapi_monitor_eth
*mon_eth
;
1044 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1047 skiplist_next (rfd
->mon_eth
, NULL
, (void **) &mon_eth
,
1051 char buf_remain
[BUFSIZ
];
1052 char buf_pfx
[BUFSIZ
];
1053 struct prefix pfx_mac
;
1057 vnc_zlog_debug_verbose ("%s: checking rfd=%p mon_eth=%p", __func__
, rfd
,
1060 memset ((void *) &pfx_mac
, 0, sizeof (struct prefix
));
1061 pfx_mac
.family
= AF_ETHERNET
;
1062 pfx_mac
.prefixlen
= 48;
1063 pfx_mac
.u
.prefix_eth
= mon_eth
->macaddr
;
1065 if (pfx_match
&& !prefix_match (pfx_match
, &pfx_mac
) &&
1066 !prefix_match (&pfx_mac
, pfx_match
))
1069 ++queries_displayed
;
1074 fp (out
, "%s", VTY_NEWLINE
);
1075 fp (out
, "%-15s %-15s %-17s %10s %-10s%s",
1076 "VN Address", "UN Address",
1077 "Target", "LNI", "Remaining", VTY_NEWLINE
);
1080 if (!printedquerier
)
1082 char buf_vn
[BUFSIZ
];
1083 char buf_un
[BUFSIZ
];
1085 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, buf_un
, BUFSIZ
);
1086 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, buf_vn
, BUFSIZ
);
1088 fp (out
, "%-15s %-15s", buf_vn
, buf_un
);
1094 fp (out
, "%-15s %-15s", "", "");
1098 rfapiFormatSeconds (thread_timer_remain_second
1099 (mon_eth
->timer
), buf_remain
, BUFSIZ
);
1101 fp (out
, " %-17s %10d %-10s%s",
1102 rfapi_ntop (pfx_mac
.family
, &pfx_mac
.u
.prefix
, buf_pfx
,
1103 BUFSIZ
), mon_eth
->logical_net_id
, buf_remain
,
1111 fp (out
, "%s", VTY_NEWLINE
);
1112 fp (out
, "Displayed %d out of %d total queries%s",
1113 queries_displayed
, queries_total
, VTY_NEWLINE
);
1119 rfapiPrintRemoteRegBi (
1122 struct route_node
*rn
,
1123 struct bgp_info
*bi
)
1125 int (*fp
) (void *, const char *, ...);
1128 const char *vty_newline
;
1129 struct prefix pfx_un
;
1130 struct prefix pfx_vn
;
1133 bgp_encap_types tun_type
;
1135 char buf_pfx
[BUFSIZ
];
1136 char buf_ntop
[BUFSIZ
];
1137 char buf_un
[BUFSIZ
];
1138 char buf_vn
[BUFSIZ
];
1139 char buf_lifetime
[BUFSIZ
];
1143 return 0; /* for debug log, print into buf & call output once */
1145 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1152 snprintf (buf_pfx
, BUFSIZ
, "%s/%d",
1153 rfapi_ntop (rn
->p
.family
, &rn
->p
.u
.prefix
, buf_ntop
, BUFSIZ
),
1155 buf_pfx
[BUFSIZ
- 1] = 0;
1162 if (!rfapiGetUnAddrOfVpnBi (bi
, &pfx_un
))
1164 snprintf (buf_un
, BUFSIZ
, "%s",
1165 inet_ntop (pfx_un
.family
, &pfx_un
.u
.prefix
, buf_ntop
,
1169 rfapiGetTunnelType(bi
->attr
,&tun_type
);
1174 rfapiNexthop2Prefix (bi
->attr
, &pfx_vn
);
1175 if (tun_type
== BGP_ENCAP_TYPE_MPLS
)
1177 /* MPLS carries un in nrli next hop (same as vn for IP tunnels) */
1178 snprintf (buf_un
, BUFSIZ
, "%s",
1179 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1182 u_int32_t l
= decode_label (bi
->extra
->tag
);
1183 snprintf (buf_vn
, BUFSIZ
, "Label: %d", l
);
1185 else /* should never happen */
1187 snprintf (buf_vn
, BUFSIZ
, "Label: N/A");
1192 snprintf (buf_vn
, BUFSIZ
, "%s",
1193 inet_ntop (pfx_vn
.family
, &pfx_vn
.u
.prefix
, buf_ntop
, BUFSIZ
));
1195 buf_vn
[BUFSIZ
- 1] = 0;
1196 buf_un
[BUFSIZ
- 1] = 0;
1199 * Cost is encoded in local_pref as (255-cost)
1200 * See rfapi_import.c'rfapiRouteInfo2NextHopEntry() for conversion
1205 uint32_t local_pref
;
1206 if (bi
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1207 local_pref
= bi
->attr
->local_pref
;
1210 cost
= (local_pref
> 255) ? 0 : 255 - local_pref
;
1217 fp (out
, "%-20s ", buf_pfx
);
1218 fp (out
, "%-15s ", buf_vn
);
1219 fp (out
, "%-15s ", buf_un
);
1220 fp (out
, "%-4d ", cost
);
1223 /* NB rfapiGetVncLifetime sets infinite value when returning !0 */
1224 if (rfapiGetVncLifetime (bi
->attr
, &lifetime
) ||
1225 (lifetime
== RFAPI_INFINITE_LIFETIME
))
1228 fp (out
, "%-10s ", "infinite");
1232 time_t t_lifetime
= lifetime
;
1233 rfapiFormatSeconds (t_lifetime
, buf_lifetime
, BUFSIZ
);
1234 fp (out
, "%-10s ", buf_lifetime
);
1237 if (CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
) &&
1238 bi
->extra
&& bi
->extra
->vnc
.import
.timer
)
1243 char buf_age
[BUFSIZ
];
1245 struct thread
*t
= (struct thread
*) bi
->extra
->vnc
.import
.timer
;
1246 remaining
= thread_timer_remain_second (t
);
1248 #if RFAPI_REGISTRATIONS_REPORT_AGE
1250 * Calculate when the timer started. Doing so here saves
1251 * us a timestamp field in "struct bgp_info".
1253 * See rfapi_import.c'rfapiBiStartWithdrawTimer() for the
1254 * original calculation.
1256 age
= rfapiGetHolddownFromLifetime (lifetime
, factor
) - remaining
;
1257 #else /* report remaining time */
1260 rfapiFormatSeconds (age
, buf_age
, BUFSIZ
);
1262 fp (out
, "%-10s ", buf_age
);
1265 else if (RFAPI_LOCAL_BI (bi
))
1268 char buf_age
[BUFSIZ
];
1270 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.create_time
)
1272 rfapiFormatAge (bi
->extra
->vnc
.import
.create_time
, buf_age
, BUFSIZ
);
1279 fp (out
, "%-10s ", buf_age
);
1281 fp (out
, "%s", HVTY_NEWLINE
);
1283 if (rn
->p
.family
== AF_ETHERNET
)
1286 * If there is a corresponding IP address && != VN address,
1287 * print that on the next line
1290 if (bi
&& bi
->extra
&& bi
->extra
->vnc
.import
.aux_prefix
.family
)
1294 sp
= rfapi_ntop (bi
->extra
->vnc
.import
.aux_prefix
.family
,
1295 &bi
->extra
->vnc
.import
.aux_prefix
.u
.prefix
,
1297 buf_ntop
[BUFSIZ
- 1] = 0;
1299 if (sp
&& strcmp (buf_vn
, sp
) != 0)
1301 fp (out
, " IP: %s", sp
);
1307 if (tun_type
!= BGP_ENCAP_TYPE_MPLS
&& bi
->extra
)
1309 u_int32_t l
= decode_label (bi
->extra
->tag
);
1310 if (!MPLS_LABEL_IS_NULL (l
))
1312 fp (out
, " Label: %d", l
);
1318 fp (out
, "%s", HVTY_NEWLINE
);
1324 rfapiShowRemoteRegistrationsIt (
1327 struct rfapi_import_table
*it
,
1328 struct prefix
*prefix_only
,
1329 int show_expiring
, /* either/or */
1332 int show_imported
, /* either/or */
1333 uint32_t *pLni
) /* AFI_L2VPN only */
1336 int printed_rtlist_hdr
= 0;
1338 int (*fp
) (void *, const char *, ...);
1341 const char *vty_newline
;
1345 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1348 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1351 struct route_node
*rn
;
1353 if (!it
->imported_vpn
[afi
])
1356 for (rn
= route_top (it
->imported_vpn
[afi
]); rn
; rn
= route_next (rn
))
1359 struct bgp_info
*bi
;
1362 /* allow for wider or more narrow mask from user */
1364 !prefix_match (prefix_only
, &rn
->p
) &&
1365 !prefix_match (&rn
->p
, prefix_only
))
1370 for (bi
= rn
->info
; bi
; bi
= bi
->next
)
1373 if (!show_local
&& RFAPI_LOCAL_BI (bi
))
1376 /* local route from RFP */
1380 if (!show_remote
&& !RFAPI_LOCAL_BI (bi
))
1387 if (show_expiring
&& !CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1390 if (!show_expiring
&& CHECK_FLAG (bi
->flags
, BGP_INFO_REMOVED
))
1393 if (bi
->type
== ZEBRA_ROUTE_BGP_DIRECT
||
1394 bi
->type
== ZEBRA_ROUTE_BGP_DIRECT_EXT
)
1406 if (count_only
== 1)
1408 if (!printed_rtlist_hdr
)
1410 const char *agetype
= "";
1412 const char *type
= "";
1425 if (RFAPI_LOCAL_BI (bi
))
1436 s
= ecommunity_ecom2str (it
->rt_import_list
,
1437 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1441 fp (out
, "%s[%s] L2VPN Network 0x%x (%u) RT={%s}",
1442 HVTY_NEWLINE
, type
, *pLni
, (*pLni
& 0xfff), s
);
1446 fp (out
, "%s[%s] Prefix RT={%s}",
1447 HVTY_NEWLINE
, type
, s
);
1449 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1451 if (it
->rfg
&& it
->rfg
->name
)
1453 fp (out
, " %s \"%s\"",
1454 (it
->rfg
->type
== RFAPI_GROUP_CFG_VRF
?
1455 "VRF" : "NVE group"),
1458 fp (out
, "%s", HVTY_NEWLINE
);
1461 #if RFAPI_REGISTRATIONS_REPORT_AGE
1464 agetype
= "Remaining";
1467 else if (show_local
)
1472 printed_rtlist_hdr
= 1;
1474 fp (out
, "%-20s %-15s %-15s %4s %-10s %-10s%s",
1475 (pLni
? "L2 Address/IP" : "Prefix"),
1476 "VN Address", "UN Address", "Cost",
1477 "Lifetime", agetype
, HVTY_NEWLINE
);
1479 printed
+= rfapiPrintRemoteRegBi (bgp
, stream
, rn
, bi
);
1487 const char *type
= "prefixes";
1491 type
= "imported prefixes";
1497 type
= "prefixes in holddown";
1501 if (show_local
&& !show_remote
)
1503 type
= "locally registered prefixes";
1505 else if (!show_local
&& show_remote
)
1507 type
= "remotely registered prefixes";
1512 fp (out
, "Displayed %d out of %d %s%s",
1513 printed
, total
, type
, HVTY_NEWLINE
);
1514 #if DEBUG_SHOW_EXTRA
1515 fp(out
, "IT table above: it=%p%s", it
, HVTY_NEWLINE
);
1524 * rfapiShowRemoteRegistrations
1526 * Similar to rfapiShowImportTable() above. This function
1527 * is mean to produce the "remote" portion of the output
1528 * of "show vnc registrations".
1531 rfapiShowRemoteRegistrations (
1533 struct prefix
*prefix_only
,
1541 struct rfapi_import_table
*it
;
1544 bgp
= bgp_get_default ();
1556 for (it
= h
->imports
; it
; it
= it
->next
)
1559 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1560 show_expiring
, show_local
,
1561 show_remote
, show_imported
, NULL
);
1566 void *cursor
= NULL
;
1568 uintptr_t lni_as_ptr
;
1573 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1576 skiplist_next (h
->import_mac
, (void **) &lni_as_ptr
, (void **) &it
,
1580 if ((lni_as_ptr
& 0xffffffff) == lni_as_ptr
)
1582 lni
= (uint32_t) (lni_as_ptr
& 0xffffffff);
1587 rfapiShowRemoteRegistrationsIt (bgp
, stream
, it
, prefix_only
,
1588 show_expiring
, show_local
,
1589 show_remote
, show_imported
, pLni
);
1596 /*------------------------------------------
1597 * rfapiRfapiIpAddr2Str
1599 * UI helper: generate string from rfapi_ip_addr
1602 * a IP v4/v6 address
1605 * buf put string here
1606 * bufsize max space to write
1609 * NULL conversion failed
1610 * non-NULL pointer to buf
1611 --------------------------------------------*/
1613 rfapiRfapiIpAddr2Str (struct rfapi_ip_addr
*a
, char *buf
, int bufsize
)
1615 const char *rc
= NULL
;
1617 switch (a
->addr_family
)
1620 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1623 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1630 rfapiPrintRfapiIpAddr (void *stream
, struct rfapi_ip_addr
*a
)
1633 const char *rc
= NULL
;
1635 int (*fp
) (void *, const char *, ...);
1638 const char *vty_newline
;
1640 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1643 rc
= rfapiRfapiIpAddr2Str (a
, buf
, BUFSIZ
);
1646 fp (out
, "%s", buf
);
1650 rfapiRfapiIpPrefix2Str (struct rfapi_ip_prefix
*p
, char *buf
, int bufsize
)
1652 struct rfapi_ip_addr
*a
= &p
->prefix
;
1653 const char *rc
= NULL
;
1655 switch (a
->addr_family
)
1658 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v4
, buf
, bufsize
);
1661 rc
= inet_ntop (a
->addr_family
, &a
->addr
.v6
, buf
, bufsize
);
1667 int alen
= strlen (buf
);
1668 int remaining
= bufsize
- alen
- 1;
1673 slen
= snprintf (buf
+ alen
, remaining
, "/%u", p
->length
);
1674 if (slen
< remaining
) /* see man page for snprintf(3) */
1683 rfapiPrintRfapiIpPrefix (void *stream
, struct rfapi_ip_prefix
*p
)
1688 int (*fp
) (void *, const char *, ...);
1691 const char *vty_newline
;
1693 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
1696 rc
= rfapiRfapiIpPrefix2Str (p
, buf
, BUFSIZ
);
1699 fp (out
, "%s:%u", buf
, p
->cost
);
1705 rfapiPrintRd (struct vty
*vty
, struct prefix_rd
*prd
)
1710 prefix_rd2str (prd
, buf
, BUFSIZ
);
1711 buf
[BUFSIZ
- 1] = 0;
1712 vty_out (vty
, "%s", buf
);
1716 rfapiPrintAdvertisedInfo (
1718 struct rfapi_descriptor
*rfd
,
1722 afi_t afi
; /* of the VN address */
1723 struct bgp_node
*bn
;
1724 struct bgp_info
*bi
;
1725 uint8_t type
= ZEBRA_ROUTE_BGP
;
1728 struct prefix_rd prd0
;
1729 struct prefix_rd
*prd
;
1732 * Find the bgp_info in the RIB corresponding to this
1736 afi
= family2afi (p
->family
);
1737 assert (afi
== AFI_IP
|| afi
== AFI_IP6
);
1739 bgp
= bgp_get_default (); /* assume 1 instance for now */
1742 if (safi
== SAFI_ENCAP
)
1744 memset (&prd0
, 0, sizeof (prd0
));
1745 prd0
.family
= AF_UNSPEC
;
1746 prd0
.prefixlen
= 64;
1753 bn
= bgp_afi_node_get (bgp
->rib
[afi
][safi
], afi
, safi
, p
, prd
);
1755 vty_out (vty
, " bn=%p%s", bn
, HVTY_NEWLINE
);
1757 for (bi
= bn
->info
; bi
; bi
= bi
->next
)
1759 if (bi
->peer
== rfd
->peer
&&
1761 bi
->sub_type
== BGP_ROUTE_RFP
&&
1762 bi
->extra
&& bi
->extra
->vnc
.export
.rfapi_handle
== (void *) rfd
)
1765 rfapiPrintBi (vty
, bi
);
1772 vty_out (vty
, " --?--%s", HVTY_NEWLINE
);
1779 rfapiPrintDescriptor (struct vty
*vty
, struct rfapi_descriptor
*rfd
)
1781 /* pHD un-addr vn-addr pCB cookie rd lifetime */
1782 /* RT export list */
1783 /* RT import list */
1784 /* list of advertised prefixes */
1785 /* dump import table */
1791 struct rfapi_adb
*adb
;
1794 vty_out (vty
, "%-10p ", rfd
);
1795 rfapiPrintRfapiIpAddr (vty
, &rfd
->un_addr
);
1797 rfapiPrintRfapiIpAddr (vty
, &rfd
->vn_addr
);
1798 vty_out (vty
, " %p %p ", rfd
->response_cb
, rfd
->cookie
);
1799 rfapiPrintRd (vty
, &rfd
->rd
);
1800 vty_out (vty
, " %d", rfd
->response_lifetime
);
1801 vty_out (vty
, " %s", (rfd
->rfg
? rfd
->rfg
->name
: "<orphaned>"));
1802 vty_out (vty
, "%s", HVTY_NEWLINE
);
1804 vty_out (vty
, " Peer %p #%d%s", rfd
->peer
, rfd
->peer
->lock
, HVTY_NEWLINE
);
1806 /* export RT list */
1807 if (rfd
->rt_export_list
)
1810 ecommunity_ecom2str (rfd
->rt_export_list
,
1811 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1812 vty_out (vty
, " Export %s%s", s
, HVTY_NEWLINE
);
1813 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1817 vty_out (vty
, " Export (nil)%s", HVTY_NEWLINE
);
1820 /* import RT list */
1821 if (rfd
->import_table
)
1823 s
= ecommunity_ecom2str (rfd
->import_table
->rt_import_list
,
1824 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
1825 vty_out (vty
, " Import %s%s", s
, HVTY_NEWLINE
);
1826 XFREE (MTYPE_ECOMMUNITY_STR
, s
);
1830 vty_out (vty
, " Import (nil)%s", HVTY_NEWLINE
);
1833 for (afi
= AFI_IP
; afi
< AFI_MAX
; ++afi
)
1837 family
= afi2family (afi
);
1843 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1846 skiplist_next (rfd
->advertised
.ipN_by_prefix
, NULL
, (void **) &adb
,
1850 /* group like family prefixes together in output */
1851 if (family
!= adb
->u
.s
.prefix_ip
.family
)
1854 prefix2str (&adb
->u
.s
.prefix_ip
, buf
, BUFSIZ
);
1855 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1857 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1858 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1862 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1865 skiplist_next (rfd
->advertised
.ip0_by_ether
, NULL
, (void **) &adb
,
1869 prefix2str (&adb
->u
.s
.prefix_eth
, buf
, BUFSIZ
);
1870 buf
[BUFSIZ
- 1] = 0; /* guarantee NUL-terminated */
1872 vty_out (vty
, " Adv Pfx: %s%s", buf
, HVTY_NEWLINE
);
1874 /* TBD update the following function to print ethernet info */
1875 /* Also need to pass/use rd */
1876 rfapiPrintAdvertisedInfo (vty
, rfd
, SAFI_MPLS_VPN
, &adb
->u
.s
.prefix_ip
);
1878 vty_out (vty
, "%s", HVTY_NEWLINE
);
1882 * test scripts rely on first line for each nve starting in 1st column,
1883 * leading whitespace for additional detail of that nve
1886 rfapiPrintMatchingDescriptors (struct vty
*vty
,
1887 struct prefix
*vn_prefix
,
1888 struct prefix
*un_prefix
)
1892 struct listnode
*ln
;
1893 struct rfapi_descriptor
*rfd
;
1896 bgp
= bgp_get_default (); /* assume 1 instance for now */
1903 for (ln
= listhead (&h
->descriptors
); ln
; ln
= listnextnode (ln
))
1905 rfd
= listgetdata (ln
);
1911 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
1912 if (!prefix_match (vn_prefix
, &pfx
))
1918 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
1919 if (!prefix_match (un_prefix
, &pfx
))
1925 /* print column header */
1927 "%s %s %s %s %s %s %s %s%s",
1928 "descriptor", "un-addr", "vn-addr", "callback", "cookie",
1929 "RD", "lifetime", "group", HVTY_NEWLINE
);
1931 rfapiPrintDescriptor (vty
, rfd
);
1938 * Parse an address and put into a struct prefix
1941 rfapiCliGetPrefixAddr (struct vty
*vty
, const char *str
, struct prefix
*p
)
1943 if (!str2prefix (str
, p
))
1945 vty_out (vty
, "Malformed address \"%s\"%s", str
, HVTY_NEWLINE
);
1951 if (p
->prefixlen
!= 32)
1953 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1958 if (p
->prefixlen
!= 128)
1960 vty_out (vty
, "Not a host address: \"%s\"%s", str
, HVTY_NEWLINE
);
1965 vty_out (vty
, "Invalid address \"%s\"%s", str
, HVTY_NEWLINE
);
1972 rfapiCliGetRfapiIpAddr (
1975 struct rfapi_ip_addr
*hai
)
1980 rc
= rfapiCliGetPrefixAddr (vty
, str
, &pfx
);
1984 hai
->addr_family
= pfx
.family
;
1985 if (pfx
.family
== AF_INET
)
1986 hai
->addr
.v4
= pfx
.u
.prefix4
;
1988 hai
->addr
.v6
= pfx
.u
.prefix6
;
1994 * Note: this function does not flush vty output, so if it is called
1995 * with a stream pointing to a vty, the user will have to type something
1996 * before the callback output shows up
1999 rfapiPrintNhl (void *stream
, struct rfapi_next_hop_entry
*next_hops
)
2001 struct rfapi_next_hop_entry
*nh
;
2004 int (*fp
) (void *, const char *, ...);
2007 const char *vty_newline
;
2009 #define REMAIN (BUFSIZ - (p-line))
2010 #define INCP {p += (r > REMAIN)? REMAIN: r;}
2013 if (rfapiStream2Vty (stream
, &fp
, &vty
, &out
, &vty_newline
) == 0)
2016 for (nh
= next_hops
, count
= 1; nh
; nh
= nh
->next
, ++count
)
2023 r
= snprintf (p
, REMAIN
, "%3d pfx=", count
);
2026 if (rfapiRfapiIpPrefix2Str (&nh
->prefix
, p
, REMAIN
))
2028 /* it fit, so count length */
2038 r
= snprintf (p
, REMAIN
, ", un=");
2041 if (rfapiRfapiIpAddr2Str (&nh
->un_address
, p
, REMAIN
))
2043 /* it fit, so count length */
2053 r
= snprintf (p
, REMAIN
, ", vn=");
2056 if (rfapiRfapiIpAddr2Str (&nh
->vn_address
, p
, REMAIN
))
2058 /* it fit, so count length */
2069 line
[BUFSIZ
- 1] = 0;
2070 fp (out
, "%s%s", line
, HVTY_NEWLINE
);
2077 struct rfapi_vn_option
*vo
;
2078 char offset
[] = " ";
2080 for (vo
= nh
->vn_options
; vo
; vo
= vo
->next
)
2086 case RFAPI_VN_OPTION_TYPE_L2ADDR
:
2087 rfapiEthAddr2Str (&vo
->v
.l2addr
.macaddr
, pbuf
,
2089 fp (out
, "%sL2 %s LBL=0x%06x NETID=0x%06x NVEID=%d%s",
2090 offset
, pbuf
, (vo
->v
.l2addr
.label
& 0x00ffffff),
2091 (vo
->v
.l2addr
.logical_net_id
& 0x00ffffff),
2092 vo
->v
.l2addr
.local_nve_id
, HVTY_NEWLINE
);
2095 case RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
:
2096 prefix2str (&vo
->v
.local_nexthop
.addr
, pbuf
, sizeof (pbuf
));
2097 fp (out
, "%sLNH %s cost=%d%s",
2098 offset
, pbuf
, vo
->v
.local_nexthop
.cost
, HVTY_NEWLINE
);
2102 fp (out
, "%svn option type %d (unknown)%s",
2103 offset
, vo
->type
, HVTY_NEWLINE
);
2110 struct rfapi_un_option
*uo
;
2111 char offset
[] = " ";
2113 for (uo
= nh
->un_options
; uo
; uo
= uo
->next
)
2117 case RFAPI_UN_OPTION_TYPE_TUNNELTYPE
:
2118 rfapi_print_tunneltype_option (stream
, 8, &uo
->v
.tunnel
);
2121 fp (out
, "%sUN Option type %d%s",
2122 offset
, uo
->type
, vty_newline
);
2131 /***********************************************************************
2133 ***********************************************************************/
2136 * Add another nexthop to the NHL
2139 rfapiAddDeleteLocalRfpPrefix (
2140 struct rfapi_ip_addr
*un_addr
,
2141 struct rfapi_ip_addr
*vn_addr
,
2142 struct rfapi_ip_prefix
*rprefix
,
2144 uint32_t lifetime
, /* add only */
2145 struct rfapi_vn_option
*vn_options
,
2146 struct rfapi_next_hop_entry
**head
,
2147 struct rfapi_next_hop_entry
**tail
)
2149 struct rfapi_next_hop_entry
*new;
2155 new = XCALLOC (MTYPE_RFAPI_NEXTHOP
, sizeof (struct rfapi_next_hop_entry
));
2156 new->prefix
= *rprefix
;
2157 new->un_address
= *un_addr
;
2158 new->vn_address
= *vn_addr
;
2160 new->vn_options
= vn_options
;
2163 new->lifetime
= lifetime
;
2167 new->lifetime
= RFAPI_REMOVE_RESPONSE_LIFETIME
;
2171 (*tail
)->next
= new;
2183 struct cmd_token
*carg_prefix
,
2184 struct cmd_token
*carg_vn
,
2185 struct cmd_token
*carg_un
,
2186 struct cmd_token
*carg_cost
, /* optional */
2187 struct cmd_token
*carg_lifetime
, /* optional */
2188 struct cmd_token
*carg_macaddr
, /* optional */
2189 struct cmd_token
*carg_vni
, /* mac present=>mandatory Virtual Network ID */
2191 struct cmd_token
**argv
)
2193 const char *arg_prefix
= carg_prefix
->arg
;
2194 const char *arg_vn
= carg_vn
->arg
;
2195 const char *arg_un
= carg_un
->arg
;
2196 const char *arg_cost
= carg_cost
? carg_cost
->arg
: NULL
;
2197 const char *arg_lifetime
= carg_lifetime
? carg_lifetime
->arg
: NULL
;
2198 const char *arg_macaddr
= carg_macaddr
? carg_macaddr
->arg
: NULL
;
2199 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
2200 struct rfapi_ip_addr vn_address
;
2201 struct rfapi_ip_addr un_address
;
2203 struct rfapi_ip_prefix rpfx
;
2208 struct rfapi_vn_option optary
[10]; /* XXX must be big enough */
2209 struct rfapi_vn_option
*opt
= NULL
;
2212 int rc
= CMD_WARNING
;
2216 struct rfapi_cfg
*rfapi_cfg
;
2218 const char *arg_lnh
= NULL
;
2219 const char *arg_lnh_cost
= NULL
;
2221 bgp
= bgp_get_default (); /* assume 1 instance for now */
2225 vty_out (vty
, "BGP not configured%s", VTY_NEWLINE
);
2230 rfapi_cfg
= bgp
->rfapi_cfg
;
2231 if (!h
|| !rfapi_cfg
)
2234 vty_out (vty
, "RFAPI not configured%s", VTY_NEWLINE
);
2238 for (; argc
; --argc
, ++argv
)
2240 if (!strcmp (argv
[0]->arg
, "local-next-hop"))
2244 vty_out (vty
, "local-next-hop specified more than once%s",
2250 vty_out (vty
, "Missing parameter for local-next-hop%s",
2255 arg_lnh
= argv
[0]->arg
;
2257 if (!strcmp (argv
[0]->arg
, "local-cost"))
2261 vty_out (vty
, "local-cost specified more than once%s",
2267 vty_out (vty
, "Missing parameter for local-cost%s",
2272 arg_lnh_cost
= argv
[0]->arg
;
2276 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &vn_address
)))
2278 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &un_address
)))
2281 /* arg_prefix is optional if mac address is given */
2282 if (arg_macaddr
&& !arg_prefix
)
2285 * fake up a 0/32 or 0/128 prefix
2287 switch (vn_address
.addr_family
)
2290 arg_prefix
= "0.0.0.0/32";
2293 arg_prefix
= "0::0/128";
2296 vty_out (vty
, "Internal error, unknown VN address family%s",
2303 if (!str2prefix (arg_prefix
, &pfx
))
2305 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
,
2309 if (pfx
.family
!= AF_INET
2310 && pfx
.family
!= AF_INET6
)
2312 vty_out (vty
, "prefix \"%s\" has invalid address family%s",
2313 arg_prefix
, VTY_NEWLINE
);
2318 memset (optary
, 0, sizeof (optary
));
2323 cost
= strtoul (arg_cost
, &endptr
, 10);
2324 if (*endptr
!= '\0' || cost
> 255)
2326 vty_out (vty
, "%% Invalid %s value%s", "cost", VTY_NEWLINE
);
2337 if (!strcmp (arg_lifetime
, "infinite"))
2339 lifetime
= RFAPI_INFINITE_LIFETIME
;
2344 lifetime
= strtoul (arg_lifetime
, &endptr
, 10);
2345 if (*endptr
!= '\0')
2347 vty_out (vty
, "%% Invalid %s value%s", "lifetime",
2355 lifetime
= RFAPI_INFINITE_LIFETIME
; /* default infinite */
2363 "%% %s may only be specified with local-next-hop%s",
2364 "local-cost", VTY_NEWLINE
);
2368 lnh_cost
= strtoul (arg_lnh_cost
, &endptr
, 10);
2369 if (*endptr
!= '\0' || lnh_cost
> 255)
2371 vty_out (vty
, "%% Invalid %s value%s", "local-cost",
2385 vty_out (vty
, "%% %s may only be specified with prefix%s",
2386 "local-next-hop", VTY_NEWLINE
);
2389 if ((rc
= rfapiCliGetPrefixAddr (vty
, arg_lnh
,
2390 &optary
[opt_next
].v
.
2391 local_nexthop
.addr
)))
2397 optary
[opt_next
].v
.local_nexthop
.cost
= lnh_cost
;
2398 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP
;
2402 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2411 if (arg_vni
&& !arg_macaddr
)
2413 vty_out (vty
, "%% %s may only be specified with mac address%s",
2414 "virtual-network-identifier", VTY_NEWLINE
);
2423 "Missing \"vni\" parameter (mandatory with mac)%s",
2427 VTY_GET_INTEGER ("Logical Network ID",
2428 optary
[opt_next
].v
.l2addr
.logical_net_id
,
2431 if ((rc
= rfapiStr2EthAddr (arg_macaddr
,
2432 &optary
[opt_next
].v
.l2addr
.macaddr
)))
2434 vty_out (vty
, "Invalid %s value%s", "mac address",
2438 /* TBD label, NVE ID */
2440 optary
[opt_next
].type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
2444 optary
[opt_next
- 1].next
= optary
+ opt_next
;
2453 vnc_zlog_debug_verbose
2454 ("%s: vn=%s, un=%s, prefix=%s, cost=%s, lifetime=%s, lnh=%s",
2455 __func__
, arg_vn
, arg_un
, arg_prefix
,
2456 (arg_cost
? arg_cost
: "NULL"),
2457 (arg_lifetime
? arg_lifetime
: "NULL"),
2458 (arg_lnh
? arg_lnh
: "NULL"));
2460 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
2462 rpfx
.cost
= cost
& 255;
2464 /* look up rf descriptor, call open if it doesn't exist */
2466 rfapi_find_rfd (bgp
, &vn_address
, &un_address
,
2467 (struct rfapi_descriptor
**) &rfd
);
2472 struct rfapi_un_option uo
;
2475 * flag descriptor as provisionally opened for static route
2476 * registration so that we can fix up the other parameters
2477 * when the real open comes along
2479 memset (&uo
, 0, sizeof (uo
));
2480 uo
.type
= RFAPI_UN_OPTION_TYPE_PROVISIONAL
;
2482 rc
= rfapi_open (rfapi_get_rfp_start_val_by_bgp (bgp
), &vn_address
, &un_address
, &uo
, /* flags */
2483 NULL
, NULL
, /* no userdata */
2487 vty_out (vty
, "Can't open session for this NVE: %s%s",
2488 rfapi_error_str (rc
), VTY_NEWLINE
);
2495 vty_out (vty
, "Can't find session for this NVE: %s%s",
2496 rfapi_error_str (rc
), VTY_NEWLINE
);
2502 rfapi_register (rfd
, &rpfx
, lifetime
, NULL
, opt
, RFAPI_REGISTER_ADD
);
2505 struct rfapi_next_hop_entry
*head
= NULL
;
2506 struct rfapi_next_hop_entry
*tail
= NULL
;
2507 struct rfapi_vn_option
*vn_opt_new
;
2509 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded, returning 0", __func__
);
2511 if (h
->rfp_methods
.local_cb
)
2513 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfd
;
2514 vn_opt_new
= rfapi_vn_options_dup (opt
);
2516 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
2517 1, lifetime
, vn_opt_new
, &head
,
2521 h
->flags
|= RFAPI_INCALLBACK
;
2522 (*h
->rfp_methods
.local_cb
) (head
, r
->cookie
);
2523 h
->flags
&= ~RFAPI_INCALLBACK
;
2530 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
2531 vty_out (vty
, "%s", VTY_NEWLINE
);
2532 vty_out (vty
, "Registration failed.%s", VTY_NEWLINE
);
2534 "Confirm that either the VN or UN address matches a configured NVE group.%s",
2539 vnc_zlog_debug_verbose ("%s: fail, rc=%d", __func__
, rc
);
2543 /************************************************************************
2544 * Add prefix With LNH_OPTIONS...
2545 ************************************************************************/
2546 DEFUN (add_vnc_prefix_cost_life_lnh
,
2547 add_vnc_prefix_cost_life_lnh_cmd
,
2548 "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...",
2549 "Add registration\n"
2551 "Add/modify prefix related information\n"
2554 "VN address of NVE\n"
2555 "VN IPv4 interface address\n"
2556 "VN IPv6 interface address\n"
2557 "UN address of NVE\n"
2558 "UN IPv4 interface address\n"
2559 "UN IPv6 interface address\n"
2560 "Administrative cost [default: 255]\n"
2561 "Administrative cost\n"
2562 "Registration lifetime [default: infinite]\n"
2563 "Lifetime value in seconds\n"
2564 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2566 /* pfx vn un cost life */
2567 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2569 NULL
, NULL
, argc
- 12, argv
+ 12);
2572 DEFUN (add_vnc_prefix_life_cost_lnh
,
2573 add_vnc_prefix_life_cost_lnh_cmd
,
2574 "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...",
2575 "Add registration\n"
2577 "Add/modify prefix related information\n"
2580 "VN address of NVE\n"
2581 "VN IPv4 interface address\n"
2582 "VN IPv6 interface address\n"
2583 "UN address of NVE\n"
2584 "UN IPv4 interface address\n"
2585 "UN IPv6 interface address\n"
2586 "Registration lifetime [default: infinite]\n"
2587 "Lifetime value in seconds\n"
2588 "Administrative cost [default: 255]\n"
2589 "Administrative cost\n"
2590 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2592 /* pfx vn un cost life */
2593 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2595 NULL
, NULL
, argc
- 12, argv
+ 12);
2598 DEFUN (add_vnc_prefix_cost_lnh
,
2599 add_vnc_prefix_cost_lnh_cmd
,
2600 "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...",
2601 "Add registration\n"
2603 "Add/modify prefix related information\n"
2606 "VN address of NVE\n"
2607 "VN IPv4 interface address\n"
2608 "VN IPv6 interface address\n"
2609 "UN address of NVE\n"
2610 "UN IPv4 interface address\n"
2611 "UN IPv6 interface address\n"
2612 "Administrative cost [default: 255]\n"
2613 "Administrative cost\n"
2614 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2616 /* pfx vn un cost life */
2617 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2619 NULL
, NULL
, argc
- 10, argv
+ 10);
2622 DEFUN (add_vnc_prefix_life_lnh
,
2623 add_vnc_prefix_life_lnh_cmd
,
2624 "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...",
2625 "Add registration\n"
2627 "Add/modify prefix related information\n"
2630 "VN address of NVE\n"
2631 "VN IPv4 interface address\n"
2632 "VN IPv6 interface address\n"
2633 "UN address of NVE\n"
2634 "UN IPv4 interface address\n"
2635 "UN IPv6 interface address\n"
2636 "Registration lifetime [default: infinite]\n"
2637 "Lifetime value in seconds\n"
2638 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2640 /* pfx vn un cost life */
2641 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2643 NULL
, NULL
, argc
- 10, argv
+ 10);
2646 DEFUN (add_vnc_prefix_lnh
,
2647 add_vnc_prefix_lnh_cmd
,
2648 "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...",
2649 "Add registration\n"
2651 "Add/modify prefix related information\n"
2654 "VN address of NVE\n"
2655 "VN IPv4 interface address\n"
2656 "VN IPv6 interface address\n"
2657 "UN address of NVE\n"
2658 "UN IPv4 interface address\n"
2659 "UN IPv6 interface address\n"
2660 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2662 /* pfx vn un cost life */
2663 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2665 NULL
, NULL
, argc
- 8, argv
+ 8);
2668 /************************************************************************
2669 * Add prefix Without LNH_OPTIONS...
2670 ************************************************************************/
2671 DEFUN (add_vnc_prefix_cost_life
,
2672 add_vnc_prefix_cost_life_cmd
,
2673 "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)",
2674 "Add registration\n"
2676 "Add/modify prefix related information\n"
2679 "VN address of NVE\n"
2680 "VN IPv4 interface address\n"
2681 "VN IPv6 interface address\n"
2682 "UN address of NVE\n"
2683 "UN IPv4 interface address\n"
2684 "UN IPv6 interface address\n"
2685 "Administrative cost [default: 255]\n"
2686 "Administrative cost\n"
2687 "Registration lifetime [default: infinite]\n"
2688 "Lifetime value in seconds\n"
2689 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2691 /* pfx vn un cost life */
2692 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], argv
[11],
2694 NULL
, NULL
, 0, NULL
);
2697 DEFUN (add_vnc_prefix_life_cost
,
2698 add_vnc_prefix_life_cost_cmd
,
2699 "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)",
2700 "Add registration\n"
2702 "Add/modify prefix related information\n"
2705 "VN address of NVE\n"
2706 "VN IPv4 interface address\n"
2707 "VN IPv6 interface address\n"
2708 "UN address of NVE\n"
2709 "UN IPv4 interface address\n"
2710 "UN IPv6 interface address\n"
2711 "Registration lifetime [default: infinite]\n"
2712 "Lifetime value in seconds\n"
2713 "Administrative cost [default: 255]\n"
2714 "Administrative cost\n"
2715 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2717 /* pfx vn un cost life */
2718 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[11], argv
[9],
2720 NULL
, NULL
, 0, NULL
);
2723 DEFUN (add_vnc_prefix_cost
,
2724 add_vnc_prefix_cost_cmd
,
2725 "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)",
2726 "Add registration\n"
2728 "Add/modify prefix related information\n"
2731 "VN address of NVE\n"
2732 "VN IPv4 interface address\n"
2733 "VN IPv6 interface address\n"
2734 "UN address of NVE\n"
2735 "UN IPv4 interface address\n"
2736 "UN IPv6 interface address\n"
2737 "Administrative cost [default: 255]\n"
2738 "Administrative cost\n"
2739 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2741 /* pfx vn un cost life */
2742 return register_add (vty
, argv
[3], argv
[5], argv
[7], argv
[9], NULL
,
2744 NULL
, NULL
, 0, NULL
);
2747 DEFUN (add_vnc_prefix_life
,
2748 add_vnc_prefix_life_cmd
,
2749 "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)",
2750 "Add registration\n"
2752 "Add/modify prefix related information\n"
2755 "VN address of NVE\n"
2756 "VN IPv4 interface address\n"
2757 "VN IPv6 interface address\n"
2758 "UN address of NVE\n"
2759 "UN IPv4 interface address\n"
2760 "UN IPv6 interface address\n"
2761 "Registration lifetime [default: infinite]\n"
2762 "Lifetime value in seconds\n"
2763 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2765 /* pfx vn un cost life */
2766 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, argv
[9],
2768 NULL
, NULL
, 0, NULL
);
2771 DEFUN (add_vnc_prefix
,
2773 "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>",
2774 "Add registration\n"
2776 "Add/modify prefix related information\n"
2779 "VN address of NVE\n"
2780 "VN IPv4 interface address\n"
2781 "VN IPv6 interface address\n"
2782 "UN address of NVE\n"
2783 "UN IPv4 interface address\n"
2784 "UN IPv6 interface address\n"
2785 "[local-next-hop (A.B.C.D|X:X::X:X)] [local-cost <0-255>]\n")
2787 /* pfx vn un cost life */
2788 return register_add (vty
, argv
[3], argv
[5], argv
[7], NULL
, NULL
,
2790 NULL
, NULL
, 0, NULL
);
2793 /************************************************************************
2794 * Mac address registrations
2795 ************************************************************************/
2796 DEFUN (add_vnc_mac_vni_prefix_cost_life
,
2797 add_vnc_mac_vni_prefix_cost_life_cmd
,
2798 "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)",
2799 "Add registration\n"
2801 "Add/modify mac address information\n"
2803 "Virtual Network Identifier follows\n"
2804 "Virtual Network Identifier\n"
2805 "VN address of NVE\n"
2806 "VN IPv4 interface address\n"
2807 "VN IPv6 interface address\n"
2808 "UN address of NVE\n"
2809 "UN IPv4 interface address\n"
2810 "UN IPv6 interface address\n"
2811 "Add/modify prefix related information\n"
2814 "Administrative cost [default: 255]\n"
2815 "Administrative cost\n"
2816 "Registration lifetime [default: infinite]\n"
2817 "Lifetime value in seconds\n")
2819 /* pfx vn un cost life */
2820 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], argv
[15],
2822 argv
[3], argv
[5], 0, NULL
);
2826 DEFUN (add_vnc_mac_vni_prefix_life
,
2827 add_vnc_mac_vni_prefix_life_cmd
,
2828 "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)",
2829 "Add registration\n"
2831 "Add/modify mac address information\n"
2833 "Virtual Network Identifier follows\n"
2834 "Virtual Network Identifier\n"
2835 "VN address of NVE\n"
2836 "VN IPv4 interface address\n"
2837 "VN IPv6 interface address\n"
2838 "UN address of NVE\n"
2839 "UN IPv4 interface address\n"
2840 "UN IPv6 interface address\n"
2841 "Add/modify prefix related information\n"
2844 "Registration lifetime [default: infinite]\n"
2845 "Lifetime value in seconds\n")
2847 /* pfx vn un cost life */
2848 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, argv
[13],
2850 argv
[3], argv
[5], 0, NULL
);
2853 DEFUN (add_vnc_mac_vni_prefix_cost
,
2854 add_vnc_mac_vni_prefix_cost_cmd
,
2855 "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)",
2856 "Add registration\n"
2858 "Add/modify mac address information\n"
2860 "Virtual Network Identifier follows\n"
2861 "Virtual Network Identifier\n"
2862 "VN address of NVE\n"
2863 "VN IPv4 interface address\n"
2864 "VN IPv6 interface address\n"
2865 "UN address of NVE\n"
2866 "UN IPv4 interface address\n"
2867 "UN IPv6 interface address\n"
2868 "Add/modify prefix related information\n"
2871 "Administrative cost [default: 255]\n" "Administrative cost\n")
2873 /* pfx vn un cost life */
2874 return register_add (vty
, argv
[11], argv
[7], argv
[9], argv
[13], NULL
,
2876 argv
[3], argv
[5], 0, NULL
);
2879 DEFUN (add_vnc_mac_vni_prefix
,
2880 add_vnc_mac_vni_prefix_cmd
,
2881 "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>",
2882 "Add registration\n"
2884 "Add/modify mac address information\n"
2886 "Virtual Network Identifier follows\n"
2887 "Virtual Network Identifier\n"
2888 "VN address of NVE\n"
2889 "VN IPv4 interface address\n"
2890 "VN IPv6 interface address\n"
2891 "UN address of NVE\n"
2892 "UN IPv4 interface address\n"
2893 "UN IPv6 interface address\n"
2894 "Add/modify prefix related information\n"
2895 "IPv4 prefix\n" "IPv6 prefix\n")
2897 /* pfx vn un cost life */
2898 return register_add (vty
, argv
[11], argv
[7], argv
[9], NULL
, NULL
,
2900 argv
[3], argv
[5], 0, NULL
);
2903 DEFUN (add_vnc_mac_vni_cost_life
,
2904 add_vnc_mac_vni_cost_life_cmd
,
2905 "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)",
2906 "Add registration\n"
2908 "Add/modify mac address information\n"
2910 "Virtual Network Identifier follows\n"
2911 "Virtual Network Identifier\n"
2912 "VN address of NVE\n"
2913 "VN IPv4 interface address\n"
2914 "VN IPv6 interface address\n"
2915 "UN address of NVE\n"
2916 "UN IPv4 interface address\n"
2917 "UN IPv6 interface address\n"
2918 "Administrative cost [default: 255]\n"
2919 "Administrative cost\n"
2920 "Registration lifetime [default: infinite]\n"
2921 "Lifetime value in seconds\n")
2923 /* pfx vn un cost life */
2924 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], argv
[13],
2926 argv
[3], argv
[5], 0, NULL
);
2930 DEFUN (add_vnc_mac_vni_cost
,
2931 add_vnc_mac_vni_cost_cmd
,
2932 "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)",
2933 "Add registration\n"
2935 "Add/modify mac address information\n"
2937 "Virtual Network Identifier follows\n"
2938 "Virtual Network Identifier\n"
2939 "VN address of NVE\n"
2940 "VN IPv4 interface address\n"
2941 "VN IPv6 interface address\n"
2942 "UN address of NVE\n"
2943 "UN IPv4 interface address\n"
2944 "UN IPv6 interface address\n"
2945 "Administrative cost [default: 255]\n" "Administrative cost\n")
2947 /* pfx vn un cost life */
2948 return register_add (vty
, NULL
, argv
[7], argv
[9], argv
[11], NULL
,
2950 argv
[3], argv
[5], 0, NULL
);
2954 DEFUN (add_vnc_mac_vni_life
,
2955 add_vnc_mac_vni_life_cmd
,
2956 "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)",
2957 "Add registration\n"
2959 "Add/modify mac address information\n"
2961 "Virtual Network Identifier follows\n"
2962 "Virtual Network Identifier\n"
2963 "VN address of NVE\n"
2964 "VN IPv4 interface address\n"
2965 "VN IPv6 interface address\n"
2966 "UN address of NVE\n"
2967 "UN IPv4 interface address\n"
2968 "UN IPv6 interface address\n"
2969 "Registration lifetime [default: infinite]\n"
2970 "Lifetime value in seconds\n")
2972 /* pfx vn un cost life */
2973 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, argv
[11],
2975 argv
[3], argv
[5], 0, NULL
);
2979 DEFUN (add_vnc_mac_vni
,
2980 add_vnc_mac_vni_cmd
,
2981 "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>",
2982 "Add registration\n"
2984 "Add/modify mac address information\n"
2986 "Virtual Network Identifier follows\n"
2987 "Virtual Network Identifier\n"
2988 "VN address of NVE\n"
2989 "VN IPv4 interface address\n"
2990 "VN IPv6 interface address\n"
2991 "UN address of NVE\n"
2992 "UN IPv4 interface address\n" "UN IPv6 interface address\n")
2994 /* pfx vn un cost life */
2995 return register_add (vty
, NULL
, argv
[7], argv
[9], NULL
, NULL
,
2997 argv
[3], argv
[5], 0, NULL
);
3000 /************************************************************************
3002 ************************************************************************/
3004 struct rfapi_local_reg_delete_arg
3010 struct rfapi_ip_addr un_address
; /* AF==0: wildcard */
3011 struct rfapi_ip_addr vn_address
; /* AF==0: wildcard */
3012 struct prefix prefix
; /* AF==0: wildcard */
3013 struct prefix_rd rd
; /* plen!=64: wildcard */
3014 struct rfapi_nve_group_cfg
*rfg
; /* NULL: wildcard */
3016 struct rfapi_l2address_option_match l2o
;
3024 uint32_t query_count
;
3026 uint32_t failed_pfx_count
;
3029 struct skiplist
*nves
;
3031 uint32_t remote_active_nve_count
;
3032 uint32_t remote_active_pfx_count
;
3033 uint32_t remote_holddown_nve_count
;
3034 uint32_t remote_holddown_pfx_count
;
3039 struct rfapi_ip_addr vn
;
3040 struct rfapi_ip_addr un
;
3041 struct rfapi_descriptor
*rfd
;
3042 struct rfapi_local_reg_delete_arg
*cda
;
3046 nve_addr_free (void *hap
)
3048 ((struct nve_addr
*) hap
)->cda
->nve_count
+= 1;
3049 XFREE (MTYPE_RFAPI_NVE_ADDR
, hap
);
3053 nve_addr_cmp (void *k1
, void *k2
)
3055 struct nve_addr
*a
= (struct nve_addr
*) k1
;
3056 struct nve_addr
*b
= (struct nve_addr
*) k2
;
3063 if (a
->un
.addr_family
!= b
->un
.addr_family
)
3065 return (a
->un
.addr_family
- b
->un
.addr_family
);
3067 if (a
->vn
.addr_family
!= b
->vn
.addr_family
)
3069 return (a
->vn
.addr_family
- b
->vn
.addr_family
);
3071 if (a
->un
.addr_family
== AF_INET
)
3073 ret
= IPV4_ADDR_CMP (&a
->un
.addr
.v4
, &b
->un
.addr
.v4
);
3079 else if (a
->un
.addr_family
== AF_INET6
)
3081 ret
= IPV6_ADDR_CMP (&a
->un
.addr
.v6
, &b
->un
.addr
.v6
);
3091 if (a
->vn
.addr_family
== AF_INET
)
3093 ret
= IPV4_ADDR_CMP (&a
->vn
.addr
.v4
, &b
->vn
.addr
.v4
);
3097 else if (a
->vn
.addr_family
== AF_INET6
)
3099 ret
= IPV6_ADDR_CMP (&a
->vn
.addr
.v6
, &b
->vn
.addr
.v6
);
3113 parse_deleter_args (
3116 const char *arg_prefix
,
3119 const char *arg_l2addr
,
3120 const char *arg_vni
,
3122 struct rfapi_nve_group_cfg
*arg_rfg
,
3123 struct rfapi_local_reg_delete_arg
*rcdarg
)
3125 int rc
= CMD_WARNING
;
3127 memset (rcdarg
, 0, sizeof (struct rfapi_local_reg_delete_arg
));
3131 bgp
= bgp_get_default();
3133 rcdarg
->rfg
= arg_rfg
; /* may be NULL */
3135 if (arg_vn
&& strcmp (arg_vn
, "*"))
3137 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_vn
, &rcdarg
->vn_address
)))
3140 if (arg_un
&& strcmp (arg_un
, "*"))
3142 if ((rc
= rfapiCliGetRfapiIpAddr (vty
, arg_un
, &rcdarg
->un_address
)))
3145 if (arg_prefix
&& strcmp (arg_prefix
, "*"))
3148 if (!str2prefix (arg_prefix
, &rcdarg
->prefix
))
3150 vty_out (vty
, "Malformed prefix \"%s\"%s", arg_prefix
, VTY_NEWLINE
);
3159 vty_out (vty
, "Missing VNI%s", VTY_NEWLINE
);
3162 if (strcmp (arg_l2addr
, "*"))
3164 if ((rc
= rfapiStr2EthAddr (arg_l2addr
, &rcdarg
->l2o
.o
.macaddr
)))
3166 vty_out (vty
, "Malformed L2 Address \"%s\"%s",
3167 arg_l2addr
, VTY_NEWLINE
);
3170 rcdarg
->l2o
.flags
|= RFAPI_L2O_MACADDR
;
3172 if (strcmp (arg_vni
, "*"))
3174 VTY_GET_INTEGER ("Logical Network ID",
3175 rcdarg
->l2o
.o
.logical_net_id
, arg_vni
);
3176 rcdarg
->l2o
.flags
|= RFAPI_L2O_LNI
;
3181 if (!str2prefix_rd (arg_rd
, &rcdarg
->rd
))
3183 vty_out (vty
, "Malformed RD \"%s\"%s",
3184 arg_rd
, VTY_NEWLINE
);
3193 parse_deleter_tokens (
3196 struct cmd_token
*carg_prefix
,
3197 struct cmd_token
*carg_vn
,
3198 struct cmd_token
*carg_un
,
3199 struct cmd_token
*carg_l2addr
,
3200 struct cmd_token
*carg_vni
,
3201 struct cmd_token
*carg_rd
,
3202 struct rfapi_nve_group_cfg
*arg_rfg
,
3203 struct rfapi_local_reg_delete_arg
*rcdarg
)
3205 const char *arg_prefix
= carg_prefix
? carg_prefix
->arg
: NULL
;
3206 const char *arg_vn
= carg_vn
? carg_vn
->arg
: NULL
;
3207 const char *arg_un
= carg_un
? carg_un
->arg
: NULL
;
3208 const char *arg_l2addr
= carg_l2addr
? carg_l2addr
->arg
: NULL
;
3209 const char *arg_vni
= carg_vni
? carg_vni
->arg
: NULL
;
3210 const char *arg_rd
= carg_rd
? carg_rd
->arg
: NULL
;
3211 return parse_deleter_args (vty
, bgp
,arg_prefix
, arg_vn
, arg_un
,
3212 arg_l2addr
, arg_vni
, arg_rd
,
3217 record_nve_in_cda_list (
3218 struct rfapi_local_reg_delete_arg
*cda
,
3219 struct rfapi_ip_addr
*un_address
,
3220 struct rfapi_ip_addr
*vn_address
,
3221 struct rfapi_descriptor
*rfd
)
3224 struct nve_addr
*hap
;
3226 memset (&ha
, 0, sizeof (ha
));
3227 ha
.un
= *un_address
;
3228 ha
.vn
= *vn_address
;
3232 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3234 if (skiplist_search (cda
->nves
, &ha
, (void *) &hap
))
3236 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3240 skiplist_insert (cda
->nves
, hap
, hap
);
3245 clear_vnc_responses (struct rfapi_local_reg_delete_arg
*cda
)
3248 struct rfapi_descriptor
*rfd
;
3249 int query_count
= 0;
3250 struct listnode
*node
;
3251 struct bgp
*bgp_default
= bgp_get_default ();
3253 if (cda
->vn_address
.addr_family
&& cda
->un_address
.addr_family
)
3259 (bgp_default
, &cda
->vn_address
, &cda
->un_address
, &rfd
))
3262 rfapiRibClear (rfd
);
3263 rfapi_query_done_all (rfd
, &query_count
);
3264 cda
->query_count
+= query_count
;
3267 * Track unique nves seen
3269 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3280 h
= bgp_default
->rfapi
;
3285 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3288 * match un, vn addresses of NVEs
3290 if (cda
->un_address
.addr_family
&&
3291 rfapi_ip_addr_cmp (&cda
->un_address
, &rfd
->un_addr
))
3295 if (cda
->vn_address
.addr_family
&&
3296 rfapi_ip_addr_cmp (&cda
->vn_address
, &rfd
->vn_addr
))
3301 rfapiRibClear (rfd
);
3303 rfapi_query_done_all (rfd
, &query_count
);
3304 cda
->query_count
+= query_count
;
3307 * Track unique nves seen
3309 record_nve_in_cda_list (cda
, &rfd
->un_addr
, &rfd
->vn_addr
, rfd
);
3314 * TBD need to count deleted prefixes and nves?
3316 * ENXIO BGP or VNC not configured
3319 rfapiDeleteLocalPrefixesByRFD (struct rfapi_local_reg_delete_arg
*cda
,
3320 struct rfapi_descriptor
*rfd
)
3322 struct rfapi_ip_addr
*pUn
; /* NULL = wildcard */
3323 struct rfapi_ip_addr
*pVn
; /* NULL = wildcard */
3324 struct prefix
*pPrefix
; /* NULL = wildcard */
3325 struct prefix_rd
*pPrd
; /* NULL = wildcard */
3327 struct rfapi_ip_prefix rprefix
;
3328 struct rfapi_next_hop_entry
*head
= NULL
;
3329 struct rfapi_next_hop_entry
*tail
= NULL
;
3332 vnc_zlog_debug_verbose ("%s: entry", __func__
);
3335 pUn
= (cda
->un_address
.addr_family
? &cda
->un_address
: NULL
);
3336 pVn
= (cda
->vn_address
.addr_family
? &cda
->vn_address
: NULL
);
3337 pPrefix
= (cda
->prefix
.family
? &cda
->prefix
: NULL
);
3338 pPrd
= (cda
->rd
.prefixlen
== 64 ? &cda
->rd
: NULL
);
3342 rfapiQprefix2Rprefix (pPrefix
, &rprefix
);
3345 do /* to preserve old code structure */
3347 struct rfapi
*h
=cda
->bgp
->rfapi
;;
3348 struct rfapi_adb
*adb
;
3350 int deleted_from_this_nve
;
3352 struct nve_addr
*hap
;
3355 vnc_zlog_debug_verbose ("%s: rfd=%p", __func__
, rfd
);
3359 * match un, vn addresses of NVEs
3361 if (pUn
&& (rfapi_ip_addr_cmp (pUn
, &rfd
->un_addr
)))
3363 if (pVn
&& (rfapi_ip_addr_cmp (pVn
, &rfd
->vn_addr
)))
3367 vnc_zlog_debug_verbose ("%s: un, vn match", __func__
);
3374 deleted_from_this_nve
= 0;
3377 struct skiplist
*sl
;
3378 struct rfapi_ip_prefix rp
;
3380 struct list
*adb_delete_list
;
3383 * The advertisements are stored in a skiplist. Withdrawing
3384 * the registration deletes the advertisement from the
3385 * skiplist, which we can't do while iterating over that
3386 * same skiplist using the current skiplist API.
3388 * Strategy: iterate over the skiplist and build another
3389 * list containing only the matching ADBs. Then delete
3390 * _everything_ in that second list (which can be done
3391 * using either skiplists or quagga linklists).
3393 adb_delete_list
= list_new ();
3396 * Advertised IP prefixes (not 0/32 or 0/128)
3398 sl
= rfd
->advertised
.ipN_by_prefix
;
3401 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3402 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3407 if (!prefix_same (pPrefix
, &adb
->u
.s
.prefix_ip
))
3410 vnc_zlog_debug_verbose ("%s: adb=%p, prefix doesn't match, skipping",
3418 if (memcmp(pPrd
->val
, adb
->u
.s
.prd
.val
, 8) != 0)
3421 vnc_zlog_debug_verbose ("%s: adb=%p, RD doesn't match, skipping",
3427 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3430 (cda
->l2o
.o
.macaddr
.octet
,
3431 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
, ETHER_ADDR_LEN
))
3434 vnc_zlog_debug_verbose ("%s: adb=%p, macaddr doesn't match, skipping",
3441 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3443 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3446 vnc_zlog_debug_verbose ("%s: adb=%p, LNI doesn't match, skipping",
3454 vnc_zlog_debug_verbose ("%s: ipN adding adb %p to delete list", __func__
,
3458 listnode_add (adb_delete_list
, adb
);
3461 struct listnode
*node
;
3463 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3465 int this_advertisement_prefix_count
;
3466 struct rfapi_vn_option optary
[3];
3467 struct rfapi_vn_option
*opt
= NULL
;
3470 this_advertisement_prefix_count
= 1;
3472 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3474 memset (optary
, 0, sizeof (optary
));
3476 /* if mac addr present in advert, make l2o vn option */
3477 if (adb
->u
.s
.prefix_eth
.family
== AF_ETHERNET
)
3480 opt
->next
= &optary
[cur_opt
];
3481 opt
= &optary
[cur_opt
++];
3482 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3483 opt
->v
.l2addr
.macaddr
= adb
->u
.s
.prefix_eth
.u
.prefix_eth
;
3484 ++this_advertisement_prefix_count
;
3487 * use saved RD value instead of trying to invert
3488 * complex RD computation in rfapi_register()
3491 opt
->next
= &optary
[cur_opt
];
3492 opt
= &optary
[cur_opt
++];
3493 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
3494 opt
->v
.internal_rd
= adb
->u
.s
.prd
;
3497 vnc_zlog_debug_verbose ("%s: ipN killing reg from adb %p ", __func__
, adb
);
3500 rc
= rfapi_register (rfd
, &rp
, 0, NULL
,
3501 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_KILL
);
3504 cda
->pfx_count
+= this_advertisement_prefix_count
;
3505 cda
->reg_count
+= 1;
3506 deleted_from_this_nve
= 1;
3508 if (h
->rfp_methods
.local_cb
)
3510 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
, &rfd
->vn_addr
,
3511 &rp
, 0, 0, NULL
, &head
, &tail
);
3514 list_delete_all_node (adb_delete_list
);
3516 if (!(pPrefix
&& !RFAPI_0_PREFIX (pPrefix
)))
3521 * Caller didn't specify a prefix, or specified (0/32 or 0/128)
3525 * Advertised 0/32 and 0/128 (indexed by ethernet address)
3527 sl
= rfd
->advertised
.ip0_by_ether
;
3530 rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
);
3531 !rc
; rc
= skiplist_next (sl
, NULL
, (void **) &adb
, &cursor
))
3534 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_MACADDR
))
3536 if (memcmp (cda
->l2o
.o
.macaddr
.octet
,
3537 adb
->u
.s
.prefix_eth
.u
.prefix_eth
.octet
,
3544 if (CHECK_FLAG (cda
->l2o
.flags
, RFAPI_L2O_LNI
))
3546 if (cda
->l2o
.o
.logical_net_id
!= adb
->l2o
.logical_net_id
)
3552 vnc_zlog_debug_verbose ("%s: ip0 adding adb %p to delete list",
3555 listnode_add (adb_delete_list
, adb
);
3559 for (ALL_LIST_ELEMENTS_RO (adb_delete_list
, node
, adb
))
3562 struct rfapi_vn_option vn
;
3564 rfapiQprefix2Rprefix (&adb
->u
.s
.prefix_ip
, &rp
);
3566 memset (&vn
, 0, sizeof (vn
));
3567 vn
.type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
3568 vn
.v
.l2addr
= adb
->l2o
;
3571 vnc_zlog_debug_verbose ("%s: ip0 killing reg from adb %p ",
3575 rc
= rfapi_register (rfd
, &rp
, 0, NULL
, &vn
,
3576 RFAPI_REGISTER_KILL
);
3579 cda
->pfx_count
+= 1;
3580 cda
->reg_count
+= 1;
3581 deleted_from_this_nve
= 1;
3583 if (h
->rfp_methods
.local_cb
)
3585 struct rfapi_vn_option
*vn_opt_new
;
3587 vn_opt_new
= rfapi_vn_options_dup (&vn
);
3588 rfapiAddDeleteLocalRfpPrefix (&rfd
->un_addr
,
3589 &rfd
->vn_addr
, &rp
, 0, 0,
3590 vn_opt_new
, &head
, &tail
);
3593 list_delete_all_node (adb_delete_list
);
3595 list_delete (adb_delete_list
);
3600 { /* should not be set if (NULL == rfapi_cfg->local_cb) */
3601 h
->flags
|= RFAPI_INCALLBACK
;
3602 (*h
->rfp_methods
.local_cb
) (head
, rfd
->cookie
);
3603 h
->flags
&= ~RFAPI_INCALLBACK
;
3607 if (deleted_from_this_nve
)
3610 * track unique NVEs seen
3612 memset (&ha
, 0, sizeof (ha
));
3613 ha
.un
= rfd
->un_addr
;
3614 ha
.vn
= rfd
->vn_addr
;
3617 cda
->nves
= skiplist_new (0, nve_addr_cmp
, nve_addr_free
);
3618 if (skiplist_search (cda
->nves
, &ha
, (void **) &hap
))
3620 hap
= XCALLOC (MTYPE_RFAPI_NVE_ADDR
, sizeof (struct nve_addr
));
3624 skiplist_insert (cda
->nves
, hap
, hap
);
3627 } while (0); /* to preserve old code structure */
3633 rfapiDeleteLocalPrefixes (struct rfapi_local_reg_delete_arg
*cda
)
3639 if (cda
->rfg
->rfd
) /* if not open, nothing to delete */
3640 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, cda
->rfg
->rfd
);
3644 struct bgp
*bgp
= cda
->bgp
;
3646 struct rfapi_cfg
*rfapi_cfg
;
3648 struct listnode
*node
;
3649 struct rfapi_descriptor
*rfd
;
3653 rfapi_cfg
= bgp
->rfapi_cfg
;
3654 if (!h
|| !rfapi_cfg
)
3656 vnc_zlog_debug_verbose ("%s: starting descriptor loop", __func__
);
3657 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
3659 rc
= rfapiDeleteLocalPrefixesByRFD (cda
, rfd
);
3668 * Deletes local and remote prefixes that match
3671 clear_vnc_prefix (struct rfapi_local_reg_delete_arg
*cda
)
3673 struct prefix pfx_un
;
3674 struct prefix pfx_vn
;
3676 struct prefix
*pUN
= NULL
;
3677 struct prefix
*pVN
= NULL
;
3678 struct prefix
*pPrefix
= NULL
;
3680 struct rfapi_import_table
*it
= NULL
;
3683 * Delete matching remote prefixes in holddown
3685 if (cda
->vn_address
.addr_family
)
3687 if (!rfapiRaddr2Qprefix (&cda
->vn_address
, &pfx_vn
))
3690 if (cda
->un_address
.addr_family
)
3692 if (!rfapiRaddr2Qprefix (&cda
->un_address
, &pfx_un
))
3695 if (cda
->prefix
.family
)
3697 pPrefix
= &cda
->prefix
;
3701 it
= cda
->rfg
->rfapi_import_table
;
3703 rfapiDeleteRemotePrefixes (pUN
, pVN
, pPrefix
, it
,
3704 0, 1, &cda
->remote_active_pfx_count
,
3705 &cda
->remote_active_nve_count
,
3706 &cda
->remote_holddown_pfx_count
,
3707 &cda
->remote_holddown_nve_count
);
3710 * Now do local prefixes
3712 rfapiDeleteLocalPrefixes (cda
);
3716 print_cleared_stats (struct rfapi_local_reg_delete_arg
*cda
)
3718 struct vty
*vty
= cda
->vty
; /* for benefit of VTY_NEWLINE */
3720 /* Our special element-deleting function counts nves */
3723 skiplist_free (cda
->nves
);
3726 if (cda
->failed_pfx_count
)
3727 vty_out (vty
, "Failed to delete %d prefixes%s",
3728 cda
->failed_pfx_count
, VTY_NEWLINE
);
3730 /* left as "prefixes" even in single case for ease of machine parsing */
3732 "[Local] Cleared %u registrations, %u prefixes, %u responses from %d NVEs%s",
3733 cda
->reg_count
, cda
->pfx_count
, cda
->query_count
, cda
->nve_count
,
3737 * We don't currently allow deletion of active remote prefixes from
3741 vty_out (vty
, "[Holddown] Cleared %u prefixes from %u NVEs%s",
3742 cda
->remote_holddown_pfx_count
, cda
->remote_holddown_nve_count
,
3747 * Caller has already deleted registrations and queries for this/these
3748 * NVEs. Now we just have to close their descriptors.
3751 clear_vnc_nve_closer (struct rfapi_local_reg_delete_arg
*cda
)
3753 struct skiplist
*sl
= cda
->nves
; /* contains affected NVEs */
3754 struct nve_addr
*pKey
;
3755 struct nve_addr
*pValue
;
3756 void *cursor
= NULL
;
3762 for (rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
);
3764 rc
= skiplist_next (sl
, (void **) &pKey
, (void **) &pValue
, &cursor
))
3769 ((struct rfapi_descriptor
*) pValue
->rfd
)->flags
|=
3770 RFAPI_HD_FLAG_CLOSING_ADMINISTRATIVELY
;
3771 rfapi_close (pValue
->rfd
);
3776 DEFUN (clear_vnc_nve_all
,
3777 clear_vnc_nve_all_cmd
,
3781 "Clear per NVE information\n"
3785 struct rfapi_local_reg_delete_arg cda
;
3788 if ((rc
= parse_deleter_args (vty
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3793 clear_vnc_responses (&cda
);
3794 clear_vnc_prefix (&cda
);
3795 clear_vnc_nve_closer (&cda
);
3797 print_cleared_stats (&cda
);
3802 DEFUN (clear_vnc_nve_vn_un
,
3803 clear_vnc_nve_vn_un_cmd
,
3804 "clear vnc nve vn <*|A.B.C.D|X:X::X:X> un <*|A.B.C.D|X:X::X:X>",
3807 "Clear prefix registration information\n"
3808 "VN address of NVE\n"
3810 "VN IPv4 interface address\n"
3811 "VN IPv6 interface address\n"
3812 "UN address of NVE\n"
3813 "For all UN addresses\n"
3814 "UN IPv4 interface address\n"
3815 "UN IPv6 interface address\n")
3817 struct rfapi_local_reg_delete_arg cda
;
3821 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], argv
[6], NULL
, NULL
, NULL
, NULL
, &cda
)))
3826 clear_vnc_responses (&cda
);
3827 clear_vnc_prefix (&cda
);
3828 clear_vnc_nve_closer (&cda
);
3830 print_cleared_stats (&cda
);
3835 DEFUN (clear_vnc_nve_un_vn
,
3836 clear_vnc_nve_un_vn_cmd
,
3837 "clear vnc nve un <*|A.B.C.D|X:X::X:X> vn <*|A.B.C.D|X:X::X:X>",
3840 "Clear prefix registration information\n"
3841 "UN address of NVE\n"
3843 "UN IPv4 interface address\n"
3844 "UN IPv6 interface address\n"
3845 "VN address of NVE\n"
3847 "VN IPv4 interface address\n"
3848 "VN IPv6 interface address\n")
3850 struct rfapi_local_reg_delete_arg cda
;
3854 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[6], argv
[4], NULL
, NULL
, NULL
, NULL
, &cda
)))
3859 clear_vnc_responses (&cda
);
3860 clear_vnc_prefix (&cda
);
3861 clear_vnc_nve_closer (&cda
);
3863 print_cleared_stats (&cda
);
3868 DEFUN (clear_vnc_nve_vn
,
3869 clear_vnc_nve_vn_cmd
,
3870 "clear vnc nve vn <*|A.B.C.D|X:X::X:X>",
3873 "Clear prefix registration information\n"
3874 "VN address of NVE\n"
3876 "VN IPv4 interface address\n"
3877 "VN IPv6 interface address\n")
3879 struct rfapi_local_reg_delete_arg cda
;
3882 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, argv
[4], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
3887 clear_vnc_responses (&cda
);
3888 clear_vnc_prefix (&cda
);
3889 clear_vnc_nve_closer (&cda
);
3891 print_cleared_stats (&cda
);
3895 DEFUN (clear_vnc_nve_un
,
3896 clear_vnc_nve_un_cmd
,
3897 "clear vnc nve un <*|A.B.C.D|X:X::X:X>",
3900 "Clear prefix registration information\n"
3901 "UN address of NVE\n"
3903 "UN IPv4 interface address\n"
3904 "UN IPv6 interface address\n")
3906 struct rfapi_local_reg_delete_arg cda
;
3909 if ((rc
= parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[6], NULL
, NULL
, NULL
, NULL
, &cda
)))
3914 clear_vnc_responses (&cda
);
3915 clear_vnc_prefix (&cda
);
3916 clear_vnc_nve_closer (&cda
);
3918 print_cleared_stats (&cda
);
3922 /*-------------------------------------------------
3924 *-------------------------------------------------*/
3927 * This function is defined in this file (rather than in rfp_registration.c)
3928 * because here we have access to all the task handles.
3930 DEFUN (clear_vnc_prefix_vn_un
,
3931 clear_vnc_prefix_vn_un_cmd
,
3932 "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>",
3935 "Clear prefix registration information\n"
3939 "VN address of NVE\n"
3940 "All VN addresses\n"
3941 "VN IPv4 interface address\n"
3942 "VN IPv6 interface address\n"
3943 "UN address of NVE\n"
3944 "All UN addresses\n"
3945 "UN IPv4 interface address\n"
3946 "UN IPv6 interface address\n")
3948 struct rfapi_local_reg_delete_arg cda
;
3952 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], argv
[7], NULL
, NULL
, NULL
, NULL
, &cda
)))
3955 clear_vnc_prefix (&cda
);
3956 print_cleared_stats (&cda
);
3960 DEFUN (clear_vnc_prefix_un_vn
,
3961 clear_vnc_prefix_un_vn_cmd
,
3962 "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>",
3965 "Clear prefix registration information\n"
3969 "UN address of NVE\n"
3970 "All UN addresses\n"
3971 "UN IPv4 interface address\n"
3972 "UN IPv6 interface address\n"
3973 "VN address of NVE\n"
3974 "All VN addresses\n"
3975 "VN IPv4 interface address\n"
3976 "VN IPv6 interface address\n")
3978 struct rfapi_local_reg_delete_arg cda
;
3982 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[7], argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
3985 clear_vnc_prefix (&cda
);
3986 print_cleared_stats (&cda
);
3990 DEFUN (clear_vnc_prefix_un
,
3991 clear_vnc_prefix_un_cmd
,
3992 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> un <*|A.B.C.D|X:X::X:X>",
3995 "Clear prefix registration information\n"
3999 "UN address of NVE\n"
4000 "All UN addresses\n"
4001 "UN IPv4 interface address\n"
4002 "UN IPv6 interface address\n")
4004 struct rfapi_local_reg_delete_arg cda
;
4008 parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, argv
[5], NULL
, NULL
, NULL
, NULL
, &cda
)))
4011 clear_vnc_prefix (&cda
);
4012 print_cleared_stats (&cda
);
4016 DEFUN (clear_vnc_prefix_vn
,
4017 clear_vnc_prefix_vn_cmd
,
4018 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> vn <*|A.B.C.D|X:X::X:X>",
4021 "Clear prefix registration information\n"
4025 "UN address of NVE\n"
4026 "All VN addresses\n"
4027 "VN IPv4 interface address\n"
4028 "VN IPv6 interface address\n")
4030 struct rfapi_local_reg_delete_arg cda
;
4034 parse_deleter_tokens (vty
, NULL
, argv
[3], argv
[5], NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4037 clear_vnc_prefix (&cda
);
4038 print_cleared_stats (&cda
);
4042 DEFUN (clear_vnc_prefix_all
,
4043 clear_vnc_prefix_all_cmd
,
4044 "clear vnc prefix <*|A.B.C.D/M|X:X::X:X/M> *",
4047 "Clear prefix registration information\n"
4053 struct rfapi_local_reg_delete_arg cda
;
4056 if ((rc
= parse_deleter_tokens (vty
, NULL
, argv
[3], NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &cda
)))
4059 clear_vnc_prefix (&cda
);
4060 print_cleared_stats (&cda
);
4064 /*-------------------------------------------------
4066 *-------------------------------------------------*/
4069 * This function is defined in this file (rather than in rfp_registration.c)
4070 * because here we have access to all the task handles.
4072 DEFUN (clear_vnc_mac_vn_un
,
4073 clear_vnc_mac_vn_un_cmd
,
4074 "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>",
4077 "Clear mac registration information\n"
4081 "Any virtual network identifier\n"
4082 "Virtual network identifier\n"
4083 "Virtual network identifier\n"
4084 "VN address of NVE\n"
4085 "All VN addresses\n"
4086 "VN IPv4 interface address\n"
4087 "VN IPv6 interface address\n"
4088 "UN address of NVE\n"
4089 "All UN addresses\n"
4090 "UN IPv4 interface address\n"
4091 "UN IPv6 interface address\n")
4093 struct rfapi_local_reg_delete_arg cda
;
4096 /* pfx vn un L2 VNI */
4098 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], argv
[9], argv
[3], argv
[5],
4102 clear_vnc_prefix (&cda
);
4103 print_cleared_stats (&cda
);
4107 DEFUN (clear_vnc_mac_un_vn
,
4108 clear_vnc_mac_un_vn_cmd
,
4109 "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>",
4112 "Clear mac registration information\n"
4116 "Any virtual network identifier\n"
4117 "Virtual network identifier\n"
4118 "UN address of NVE\n"
4119 "All UN addresses\n"
4120 "UN IPv4 interface address\n"
4121 "UN IPv6 interface address\n"
4122 "VN address of NVE\n"
4123 "All VN addresses\n"
4124 "VN IPv4 interface address\n"
4125 "VN IPv6 interface address\n")
4127 struct rfapi_local_reg_delete_arg cda
;
4130 /* pfx vn un L2 VNI */
4132 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[9], argv
[7], argv
[3], argv
[5],
4136 clear_vnc_prefix (&cda
);
4137 print_cleared_stats (&cda
);
4141 DEFUN (clear_vnc_mac_un
,
4142 clear_vnc_mac_un_cmd
,
4143 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> un <*|A.B.C.D|X:X::X:X>",
4146 "Clear mac registration information\n"
4150 "Any virtual network identifier\n"
4151 "Virtual network identifier\n"
4152 "UN address of NVE\n"
4153 "All UN addresses\n"
4154 "UN IPv4 interface address\n"
4155 "UN IPv6 interface address\n")
4157 struct rfapi_local_reg_delete_arg cda
;
4160 /* pfx vn un L2 VNI */
4162 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, argv
[7], argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4165 clear_vnc_prefix (&cda
);
4166 print_cleared_stats (&cda
);
4170 DEFUN (clear_vnc_mac_vn
,
4171 clear_vnc_mac_vn_cmd
,
4172 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> vn <*|A.B.C.D|X:X::X:X>",
4175 "Clear mac registration information\n"
4179 "Any virtual network identifier\n"
4180 "Virtual network identifier\n"
4181 "UN address of NVE\n"
4182 "All VN addresses\n"
4183 "VN IPv4 interface address\n"
4184 "VN IPv6 interface address\n")
4186 struct rfapi_local_reg_delete_arg cda
;
4189 /* pfx vn un L2 VNI */
4191 parse_deleter_tokens (vty
, NULL
, NULL
, argv
[7], NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4194 clear_vnc_prefix (&cda
);
4195 print_cleared_stats (&cda
);
4199 DEFUN (clear_vnc_mac_all
,
4200 clear_vnc_mac_all_cmd
,
4201 "clear vnc mac <*|YY:YY:YY:YY:YY:YY> virtual-network-identifier <*|(1-4294967295)> *",
4204 "Clear mac registration information\n"
4208 "Any virtual network identifier\n"
4209 "Virtual network identifier\n"
4212 struct rfapi_local_reg_delete_arg cda
;
4215 /* pfx vn un L2 VNI */
4217 parse_deleter_tokens (vty
, NULL
, NULL
, NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4220 clear_vnc_prefix (&cda
);
4221 print_cleared_stats (&cda
);
4225 /*-------------------------------------------------
4226 * Clear VNC MAC PREFIX
4227 *-------------------------------------------------*/
4229 DEFUN (clear_vnc_mac_vn_un_prefix
,
4230 clear_vnc_mac_vn_un_prefix_cmd
,
4231 "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>",
4234 "Clear mac registration information\n"
4238 "Any virtual network identifier\n"
4239 "Virtual network identifier\n"
4240 "VN address of NVE\n"
4241 "All VN addresses\n"
4242 "VN IPv4 interface address\n"
4243 "VN IPv6 interface address\n"
4244 "UN address of NVE\n"
4245 "All UN addresses\n"
4246 "UN IPv4 interface address\n"
4247 "UN IPv6 interface address\n"
4248 "Clear prefix registration information\n"
4253 struct rfapi_local_reg_delete_arg cda
;
4256 /* pfx vn un L2 VNI */
4258 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[7], argv
[9], argv
[3], argv
[5],
4262 clear_vnc_prefix (&cda
);
4263 print_cleared_stats (&cda
);
4267 DEFUN (clear_vnc_mac_un_vn_prefix
,
4268 clear_vnc_mac_un_vn_prefix_cmd
,
4269 "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>",
4272 "Clear mac registration information\n"
4276 "Any virtual network identifier\n"
4277 "Virtual network identifier\n"
4278 "UN address of NVE\n"
4279 "All UN addresses\n"
4280 "UN IPv4 interface address\n"
4281 "UN IPv6 interface address\n"
4282 "VN address of NVE\n"
4283 "All VN addresses\n"
4284 "VN IPv4 interface address\n"
4285 "VN IPv6 interface address\n"
4286 "Clear prefix registration information\n"
4290 "Clear prefix registration information\n"
4295 struct rfapi_local_reg_delete_arg cda
;
4298 /* pfx vn un L2 VNI */
4300 parse_deleter_tokens (vty
, NULL
, argv
[11], argv
[9], argv
[7], argv
[3], argv
[5],
4304 clear_vnc_prefix (&cda
);
4305 print_cleared_stats (&cda
);
4309 DEFUN (clear_vnc_mac_un_prefix
,
4310 clear_vnc_mac_un_prefix_cmd
,
4311 "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>",
4314 "Clear mac registration information\n"
4318 "Any virtual network identifier\n"
4319 "Virtual network identifier\n"
4320 "UN address of NVE\n"
4321 "All UN addresses\n"
4322 "UN IPv4 interface address\n"
4323 "UN IPv6 interface address\n"
4324 "Clear prefix registration information\n"
4329 struct rfapi_local_reg_delete_arg cda
;
4332 /* pfx vn un L2 VNI */
4334 parse_deleter_tokens (vty
, NULL
, argv
[9], NULL
, argv
[7], argv
[3], argv
[5],
4338 clear_vnc_prefix (&cda
);
4339 print_cleared_stats (&cda
);
4343 DEFUN (clear_vnc_mac_vn_prefix
,
4344 clear_vnc_mac_vn_prefix_cmd
,
4345 "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>",
4348 "Clear mac registration information\n"
4352 "Any virtual network identifier\n"
4353 "Virtual network identifier\n"
4354 "UN address of NVE\n"
4355 "All VN addresses\n"
4356 "VN IPv4 interface address\n"
4357 "VN IPv6 interface address\n"
4358 "Clear prefix registration information\n"
4363 struct rfapi_local_reg_delete_arg cda
;
4366 /* pfx vn un L2 VNI */
4368 parse_deleter_tokens (vty
, NULL
, argv
[9], argv
[7], NULL
, argv
[3], argv
[5],
4372 clear_vnc_prefix (&cda
);
4373 print_cleared_stats (&cda
);
4377 DEFUN (clear_vnc_mac_all_prefix
,
4378 clear_vnc_mac_all_prefix_cmd
,
4379 "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>",
4382 "Clear mac registration information\n"
4386 "Any virtual network identifier\n"
4387 "Virtual network identifier\n"
4388 "UN address of NVE\n"
4389 "All VN addresses\n"
4390 "VN IPv4 interface address\n"
4391 "VN IPv6 interface address\n")
4393 struct rfapi_local_reg_delete_arg cda
;
4396 /* pfx vn un L2 VNI */
4398 parse_deleter_tokens (vty
, NULL
, argv
[7], NULL
, NULL
, argv
[3], argv
[5], NULL
, NULL
, &cda
)))
4401 clear_vnc_prefix (&cda
);
4402 print_cleared_stats (&cda
);
4406 /************************************************************************
4408 ************************************************************************/
4411 /* copied from rfp_vty.c */
4413 check_and_display_is_vnc_running (struct vty
*vty
)
4415 if (!bgp_rfapi_is_vnc_configured (NULL
))
4416 return 1; /* is running */
4421 "VNC is not configured. (There are no configured BGP VPN SAFI peers.)%s",
4424 return 0; /* not running */
4428 rfapi_vty_show_nve_summary (struct vty
*vty
, show_nve_summary_t show_type
)
4430 struct bgp
*bgp_default
= bgp_get_default ();
4432 int is_vnc_running
= !bgp_rfapi_is_vnc_configured (bgp_default
);
4434 int active_local_routes
;
4435 int active_remote_routes
;
4436 int holddown_remote_routes
;
4437 int imported_remote_routes
;
4442 h
= bgp_default
->rfapi
;
4447 /* don't show local info if not running RFP */
4448 if (is_vnc_running
|| show_type
== SHOW_NVE_SUMMARY_REGISTERED
)
4454 case SHOW_NVE_SUMMARY_ACTIVE_NVES
:
4455 vty_out (vty
, "%-24s ", "NVEs:");
4456 vty_out (vty
, "%-8s %-8u ", "Active:", h
->descriptors
.count
);
4457 vty_out (vty
, "%-8s %-8u ", "Maximum:", h
->stat
.max_descriptors
);
4458 vty_out (vty
, "%-8s %-8u", "Unknown:", h
->stat
.count_unknown_nves
);
4461 case SHOW_NVE_SUMMARY_REGISTERED
:
4463 * NB: With the introduction of L2 route support, we no
4464 * longer have a one-to-one correspondence between
4465 * locally-originated route advertisements and routes in
4466 * the import tables that have local origin. This
4467 * discrepancy arises because a single advertisement
4468 * may contain both an IP prefix and a MAC address.
4469 * Such an advertisement results in two import table
4470 * entries: one indexed by IP prefix, the other indexed
4473 * TBD: update computation and display of registration
4474 * statistics to reflect the underlying semantics.
4478 vty_out (vty
, "%-24s ", "Registrations:");
4479 vty_out (vty
, "%-8s %-8u ", "Active:",
4480 rfapiApCountAll (bgp_default
));
4481 vty_out (vty
, "%-8s %-8u ", "Failed:",
4482 h
->stat
.count_registrations_failed
);
4483 vty_out (vty
, "%-8s %-8u", "Total:",
4484 h
->stat
.count_registrations
);
4485 vty_out (vty
, "%s", VTY_NEWLINE
);
4487 vty_out (vty
, "%-24s ", "Prefixes registered:");
4488 vty_out (vty
, "%s", VTY_NEWLINE
);
4490 rfapiCountAllItRoutes (&active_local_routes
,
4491 &active_remote_routes
,
4492 &holddown_remote_routes
,
4493 &imported_remote_routes
);
4498 vty_out (vty
, " %-20s ", "Locally:");
4499 vty_out (vty
, "%-8s %-8u ", "Active:", active_local_routes
);
4500 vty_out (vty
, "%s", VTY_NEWLINE
);
4504 vty_out (vty
, " %-20s ", "Remotely:");
4505 vty_out (vty
, "%-8s %-8u", "Active:", active_remote_routes
);
4506 vty_out (vty
, "%s", VTY_NEWLINE
);
4507 vty_out (vty
, " %-20s ", "In Holddown:");
4508 vty_out (vty
, "%-8s %-8u", "Active:", holddown_remote_routes
);
4509 vty_out (vty
, "%s", VTY_NEWLINE
);
4510 vty_out (vty
, " %-20s ", "Imported:");
4511 vty_out (vty
, "%-8s %-8u", "Active:", imported_remote_routes
);
4514 case SHOW_NVE_SUMMARY_QUERIES
:
4515 vty_out (vty
, "%-24s ", "Queries:");
4516 vty_out (vty
, "%-8s %-8u ", "Active:", rfapi_monitor_count (NULL
));
4517 vty_out (vty
, "%-8s %-8u ", "Failed:",
4518 h
->stat
.count_queries_failed
);
4519 vty_out (vty
, "%-8s %-8u", "Total:", h
->stat
.count_queries
);
4522 case SHOW_NVE_SUMMARY_RESPONSES
:
4523 rfapiRibShowResponsesSummary (vty
);
4528 vty_out (vty
, "%s", VTY_NEWLINE
);
4533 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4540 struct prefix
*vn_prefix
,
4541 struct prefix
*un_prefix
)
4543 //struct hash *rfds;
4544 //struct rfp_rfapi_descriptor_param param;
4546 struct bgp
*bgp_default
= bgp_get_default ();
4548 struct listnode
*node
;
4549 struct rfapi_descriptor
*rfd
;
4558 h
= bgp_default
->rfapi
;
4563 rc
= rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4567 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4570 char vn_addr_buf
[INET6_ADDRSTRLEN
] =
4573 char un_addr_buf
[INET6_ADDRSTRLEN
] =
4582 assert (!rfapiRaddr2Qprefix (&rfd
->vn_addr
, &pfx
));
4583 if (!prefix_match (vn_prefix
, &pfx
))
4589 assert (!rfapiRaddr2Qprefix (&rfd
->un_addr
, &pfx
));
4590 if (!prefix_match (un_prefix
, &pfx
))
4594 rfapiRfapiIpAddr2Str (&rfd
->vn_addr
, vn_addr_buf
, INET6_ADDRSTRLEN
);
4595 rfapiRfapiIpAddr2Str (&rfd
->un_addr
, un_addr_buf
, INET6_ADDRSTRLEN
);
4599 /* print out a header */
4601 "Active Next Hops%s", VTY_NEWLINE
);
4602 vty_out (vty
, "%-15s %-15s %-5s %-5s %-6s %-6s %s%s",
4605 "Regis", "Resps", "Reach", "Remove", "Age", VTY_NEWLINE
);
4610 vty_out (vty
, "%-15s %-15s %-5u %-5u %-6u %-6u %s%s",
4614 rfapi_monitor_count (rfd
),
4615 rfd
->stat_count_nh_reachable
,
4616 rfd
->stat_count_nh_removal
,
4617 rfapiFormatAge (rfd
->open_time
, age
, 10), VTY_NEWLINE
);
4620 if (printed
> 0 || vn_prefix
|| un_prefix
)
4621 vty_out (vty
, "Displayed %d out of %d active NVEs%s",
4622 printed
, total
, VTY_NEWLINE
);
4627 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
4632 DEFUN (vnc_show_summary
,
4633 vnc_show_summary_cmd
,
4637 "Display VNC status summary\n")
4639 if (!check_and_display_is_vnc_running (vty
))
4641 bgp_rfapi_show_summary (bgp_get_default (), vty
);
4642 vty_out (vty
, "%s", VTY_NEWLINE
);
4643 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_ACTIVE_NVES
);
4644 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4645 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_RESPONSES
);
4646 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4650 DEFUN (vnc_show_nves
,
4655 "List known NVEs\n")
4657 rfapi_show_nves (vty
, NULL
, NULL
);
4661 DEFUN (vnc_show_nves_ptct
,
4662 vnc_show_nves_ptct_cmd
,
4663 "show vnc nves <vn|un> <A.B.C.D|X:X::X:X>",
4667 "VN address of NVE\n"
4668 "UN address of NVE\n"
4669 "IPv4 interface address\n"
4670 "IPv6 interface address\n")
4674 if (!check_and_display_is_vnc_running (vty
))
4677 if (!str2prefix (argv
[4]->arg
, &pfx
))
4679 vty_out (vty
, "Malformed address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4682 if (pfx
.family
!= AF_INET
&& pfx
.family
!= AF_INET6
)
4684 vty_out (vty
, "Invalid address \"%s\"%s", argv
[4]->arg
, VTY_NEWLINE
);
4688 if (argv
[3]->arg
[0] == 'u')
4690 rfapi_show_nves (vty
, NULL
, &pfx
);
4694 rfapi_show_nves (vty
, &pfx
, NULL
);
4700 /* adapted from rfp_registration_cache_log() */
4702 rfapi_show_registrations (
4704 struct prefix
*restrict_to
,
4715 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_REGISTERED
);
4719 /* non-expiring, local */
4720 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 1, 0, 0);
4724 /* non-expiring, non-local */
4725 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 0);
4729 /* expiring, including local */
4730 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 1, 1, 1, 0);
4734 /* non-expiring, non-local */
4735 printed
+= rfapiShowRemoteRegistrations (vty
, restrict_to
, 0, 0, 1, 1);
4739 vty_out (vty
, "%s", VTY_NEWLINE
);
4743 DEFUN (vnc_show_registrations_pfx
,
4744 vnc_show_registrations_pfx_cmd
,
4745 "show vnc registrations [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4748 "List active prefix registrations\n"
4749 "Limit output to a particular IPv4 prefix\n"
4750 "Limit output to a particular IPv6 prefix\n"
4751 "Limit output to a particular IPv6 address\n")
4754 struct prefix
*p_addr
= NULL
;
4758 if (!str2prefix (argv
[3]->arg
, &p
))
4760 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4769 rfapi_show_registrations (vty
, p_addr
, 1, 1, 1, 1);
4773 DEFUN (vnc_show_registrations_some_pfx
,
4774 vnc_show_registrations_some_pfx_cmd
,
4775 "show vnc registrations <all|holddown|imported|local|remote> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4778 "List active prefix registrations\n"
4779 "show all registrations\n"
4780 "show only registrations in holddown\n"
4781 "show only imported prefixes\n"
4782 "show only local registrations\n"
4783 "show only remote registrations\n"
4784 "Limit output to a particular prefix or address\n"
4785 "Limit output to a particular prefix or address\n"
4786 "Limit output to a particular prefix or address\n")
4789 struct prefix
*p_addr
= NULL
;
4792 int show_remote
= 0;
4793 int show_holddown
= 0;
4794 int show_imported
= 0;
4798 if (!str2prefix (argv
[4]->arg
, &p
))
4800 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4808 switch (argv
[3]->arg
[0])
4834 rfapi_show_registrations (vty
, p_addr
,
4835 show_local
, show_remote
, show_holddown
,
4840 DEFUN (vnc_show_responses_pfx
,
4841 vnc_show_responses_pfx_cmd
,
4842 "show vnc responses [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4845 "List recent query responses\n"
4846 "Limit output to a particular IPv4 prefix\n"
4847 "Limit output to a particular IPv6 prefix\n"
4848 "Limit output to a particular IPv6 address\n" )
4851 struct prefix
*p_addr
= NULL
;
4855 if (!str2prefix (argv
[3]->arg
, &p
))
4857 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4865 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4867 rfapiRibShowResponsesSummary (vty
);
4869 rfapiRibShowResponses (vty
, p_addr
, 0);
4870 rfapiRibShowResponses (vty
, p_addr
, 1);
4875 DEFUN (vnc_show_responses_some_pfx
,
4876 vnc_show_responses_some_pfx_cmd
,
4877 "show vnc responses <active|removed> [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4880 "List recent query responses\n"
4881 "show only active query responses\n"
4882 "show only removed query responses\n"
4883 "Limit output to a particular IPv4 prefix\n"
4884 "Limit output to a particular IPv6 prefix\n"
4885 "Limit output to a particular IPV6 address\n")
4888 struct prefix
*p_addr
= NULL
;
4890 int show_active
= 0;
4891 int show_removed
= 0;
4893 if (!check_and_display_is_vnc_running (vty
))
4898 if (!str2prefix (argv
[4]->arg
, &p
))
4900 vty_out (vty
, "Invalid prefix: %s%s", argv
[4]->arg
, VTY_NEWLINE
);
4909 switch (argv
[3]->arg
[0])
4920 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4922 rfapiRibShowResponsesSummary (vty
);
4925 rfapiRibShowResponses (vty
, p_addr
, 0);
4927 rfapiRibShowResponses (vty
, p_addr
, 1);
4932 DEFUN (show_vnc_queries_pfx
,
4933 show_vnc_queries_pfx_cmd
,
4934 "show vnc queries [<A.B.C.D/M|X:X::X:X/M|YY:YY:YY:YY:YY:YY>]",
4937 "List active queries\n"
4938 "Limit output to a particular IPv4 prefix or address\n"
4939 "Limit output to a particular IPv6 prefix\n"
4940 "Limit output to a particualr IPV6 address\n")
4943 struct prefix
*p
= NULL
;
4947 if (!str2prefix (argv
[3]->arg
, &pfx
))
4949 vty_out (vty
, "Invalid prefix: %s%s", argv
[3]->arg
, VTY_NEWLINE
);
4955 rfapi_vty_show_nve_summary (vty
, SHOW_NVE_SUMMARY_QUERIES
);
4957 return rfapiShowVncQueries (vty
, p
);
4960 DEFUN (vnc_clear_counters
,
4961 vnc_clear_counters_cmd
,
4962 "clear vnc counters",
4965 "Reset VNC counters\n")
4967 struct bgp
*bgp_default
= bgp_get_default ();
4969 struct listnode
*node
;
4970 struct rfapi_descriptor
*rfd
;
4975 h
= bgp_default
->rfapi
;
4981 for (ALL_LIST_ELEMENTS_RO (&h
->descriptors
, node
, rfd
))
4983 rfd
->stat_count_nh_reachable
= 0;
4984 rfd
->stat_count_nh_removal
= 0;
4988 memset (&h
->stat
, 0, sizeof (h
->stat
));
4991 * 151122 per bug 103, set count_registrations = number active.
4992 * Do same for queries
4994 h
->stat
.count_registrations
= rfapiApCountAll (bgp_default
);
4995 h
->stat
.count_queries
= rfapi_monitor_count (NULL
);
4997 rfapiRibShowResponsesSummaryClear ();
5002 vty_out (vty
, "VNC is not configured.%s", VTY_NEWLINE
);
5006 /************************************************************************
5007 * Add prefix with vrf
5009 * add [vrf <vrf-name>] prefix <prefix>
5010 * [rd <value>] [label <value>] [local-preference <0-4294967295>]
5011 ************************************************************************/
5013 vnc_add_vrf_prefix (struct vty
*vty
,
5014 const char *arg_vrf
,
5015 const char *arg_prefix
,
5016 const char *arg_rd
, /* optional */
5017 const char *arg_label
, /* optional */
5018 const char *arg_pref
) /* optional */
5021 struct rfapi_nve_group_cfg
*rfg
;
5023 struct rfapi_ip_prefix rpfx
;
5025 struct rfapi_vn_option optary
[3];
5026 struct rfapi_vn_option
*opt
= NULL
;
5029 bgp
= bgp_get_default (); /* assume main instance for now */
5032 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
5035 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5037 vty_out (vty
, "VRF support not configured%s", VTY_NEWLINE
);
5041 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5045 vty_out (vty
, "VRF \"%s\" appears not to be configured.%s",
5046 arg_vrf
, VTY_NEWLINE
);
5049 if (!rfg
->rt_export_list
|| !rfg
->rfapi_import_table
)
5051 vty_out (vty
, "VRF \"%s\" is missing RT import/export RT configuration.%s",
5052 arg_vrf
, VTY_NEWLINE
);
5055 if (!rfg
->rd
.family
&& !arg_rd
)
5057 vty_out (vty
, "VRF \"%s\" isn't configured with an RD, so RD must be provided.%s",
5058 arg_vrf
, VTY_NEWLINE
);
5061 if (rfg
->label
> MPLS_LABEL_MAX
&& !arg_label
)
5063 vty_out (vty
, "VRF \"%s\" isn't configured with a default labels, so a label must be provided.%s",
5064 arg_vrf
, VTY_NEWLINE
);
5067 if (!str2prefix (arg_prefix
, &pfx
))
5069 vty_out (vty
, "Malformed prefix \"%s\"%s",
5070 arg_prefix
, VTY_NEWLINE
);
5073 rfapiQprefix2Rprefix (&pfx
, &rpfx
);
5074 memset (optary
, 0, sizeof (optary
));
5078 opt
->next
= &optary
[cur_opt
];
5079 opt
= &optary
[cur_opt
++];
5080 opt
->type
= RFAPI_VN_OPTION_TYPE_INTERNAL_RD
;
5081 if (!str2prefix_rd (arg_rd
, &opt
->v
.internal_rd
))
5083 vty_out (vty
, "Malformed RD \"%s\"%s",
5084 arg_rd
, VTY_NEWLINE
);
5088 if (rfg
->label
<= MPLS_LABEL_MAX
|| arg_label
)
5090 struct rfapi_l2address_option
*l2o
;
5092 opt
->next
= &optary
[cur_opt
];
5093 opt
= &optary
[cur_opt
++];
5094 opt
->type
= RFAPI_VN_OPTION_TYPE_L2ADDR
;
5095 l2o
= &opt
->v
.l2addr
;
5099 VTY_GET_INTEGER_RANGE ("Label value", label
, arg_label
, 0, MPLS_LABEL_MAX
);
5103 l2o
->label
= rfg
->label
;
5107 char *endptr
= NULL
;
5108 pref
= strtoul (arg_pref
, &endptr
, 10);
5109 if (*endptr
!= '\0')
5111 vty_out (vty
, "%% Invalid local-preference value \"%s\"%s", arg_pref
, VTY_NEWLINE
);
5115 rpfx
.cost
= 255 - (pref
& 255) ;
5116 if (rfg
->rfd
== NULL
) /* need new rfapi_handle */
5118 /* based on rfapi_open */
5119 struct rfapi_descriptor
*rfd
;
5120 rfd
= XCALLOC (MTYPE_RFAPI_DESC
, sizeof (struct rfapi_descriptor
));
5123 /* leave most fields empty as will get from (dynamic) config when needed */
5124 rfd
->default_tunneltype_option
.type
= BGP_ENCAP_TYPE_MPLS
;
5126 if (rfg
->vn_prefix
.family
&&
5127 !CHECK_FLAG(rfg
->flags
, RFAPI_RFG_VPN_NH_SELF
))
5129 rfapiQprefix2Raddr(&rfg
->vn_prefix
, &rfd
->vn_addr
);
5133 memset(&rfd
->vn_addr
, 0, sizeof(struct rfapi_ip_addr
));
5134 rfd
->vn_addr
.addr_family
= AF_INET
;
5135 rfd
->vn_addr
.addr
.v4
= bgp
->router_id
;
5137 rfd
->un_addr
= rfd
->vn_addr
; /* sigh, need something in UN for lookups */
5138 vnc_zlog_debug_verbose ("%s: Opening RFD for VRF %s",
5139 __func__
, rfg
->name
);
5140 rfapi_init_and_open(bgp
, rfd
, rfg
);
5143 if (!rfapi_register (rfg
->rfd
, &rpfx
, RFAPI_INFINITE_LIFETIME
, NULL
,
5144 (cur_opt
? optary
: NULL
), RFAPI_REGISTER_ADD
))
5146 struct rfapi_next_hop_entry
*head
= NULL
;
5147 struct rfapi_next_hop_entry
*tail
= NULL
;
5148 struct rfapi_vn_option
*vn_opt_new
;
5150 vnc_zlog_debug_verbose ("%s: rfapi_register succeeded", __func__
);
5152 if (bgp
->rfapi
->rfp_methods
.local_cb
)
5154 struct rfapi_descriptor
*r
= (struct rfapi_descriptor
*) rfg
->rfd
;
5155 vn_opt_new
= rfapi_vn_options_dup (opt
);
5157 rfapiAddDeleteLocalRfpPrefix (&r
->un_addr
, &r
->vn_addr
, &rpfx
,
5158 1, RFAPI_INFINITE_LIFETIME
,
5159 vn_opt_new
, &head
, &tail
);
5162 bgp
->rfapi
->flags
|= RFAPI_INCALLBACK
;
5163 (*bgp
->rfapi
->rfp_methods
.local_cb
) (head
, r
->cookie
);
5164 bgp
->rfapi
->flags
&= ~RFAPI_INCALLBACK
;
5168 vnc_zlog_debug_verbose ("%s completed, count=%d/%d", __func__
,
5169 rfg
->rfapi_import_table
->local_count
[AFI_IP
],
5170 rfg
->rfapi_import_table
->local_count
[AFI_IP6
]);
5174 vnc_zlog_debug_verbose ("%s: rfapi_register failed", __func__
);
5175 vty_out (vty
, "Add failed.%s", VTY_NEWLINE
);
5179 DEFUN (add_vrf_prefix_rd_label_pref
,
5180 add_vrf_prefix_rd_label_pref_cmd
,
5181 "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)}]",
5185 "Add/modify prefix related information\n"
5188 "Override configured VRF Route Distinguisher\n"
5189 "<as-number>:<number> or <ip-address>:<number>\n"
5190 "Override configured VRF label\n"
5191 "Label Value <0-1048575>\n"
5192 "Set advertised local preference\n"
5193 "local preference (higher=more preferred)\n")
5195 char *arg_vrf
= argv
[2]->arg
;
5196 char *arg_prefix
= argv
[4]->arg
;
5197 char *arg_rd
= NULL
; /* optional */
5198 char *arg_label
= NULL
; /* optional */
5199 char *arg_pref
= NULL
; /* optional */
5201 argc
--; /* don't parse argument */
5202 while (pargc
< argc
)
5204 switch (argv
[pargc
++]->arg
[0])
5207 arg_rd
= argv
[pargc
]->arg
;
5210 arg_label
= argv
[pargc
]->arg
;
5213 arg_pref
= argv
[pargc
]->arg
;
5221 return vnc_add_vrf_prefix (vty
, arg_vrf
, arg_prefix
, arg_rd
, arg_label
, arg_pref
);
5224 /************************************************************************
5225 * del prefix with vrf
5227 * clear [vrf <vrf-name>] prefix <prefix> [rd <value>]
5228 ************************************************************************/
5230 rfapi_cfg_group_it_count(struct rfapi_nve_group_cfg
*rfg
)
5233 afi_t afi
= AFI_MAX
;
5236 count
+= rfg
->rfapi_import_table
->local_count
[afi
];
5242 clear_vnc_vrf_closer (struct rfapi_nve_group_cfg
*rfg
)
5244 struct rfapi_descriptor
*rfd
= rfg
->rfd
;
5249 /* check if IT is empty */
5251 afi
< AFI_MAX
&& rfg
->rfapi_import_table
->local_count
[afi
] == 0;
5256 vnc_zlog_debug_verbose ("%s: closing RFD for VRF %s",
5257 __func__
, rfg
->name
);
5263 vnc_zlog_debug_verbose ("%s: VRF %s afi=%d count=%d",
5264 __func__
, rfg
->name
, afi
,
5265 rfg
->rfapi_import_table
->local_count
[afi
]);
5270 vnc_clear_vrf (struct vty
*vty
,
5272 const char *arg_vrf
,
5273 const char *arg_prefix
, /* NULL = all */
5274 const char *arg_rd
) /* optional */
5276 struct rfapi_nve_group_cfg
*rfg
;
5277 struct rfapi_local_reg_delete_arg cda
;
5282 bgp
= bgp_get_default (); /* assume main instance for now */
5285 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
5288 if (!bgp
->rfapi
|| !bgp
->rfapi_cfg
)
5290 vty_out (vty
, "VRF support not configured%s", VTY_NEWLINE
);
5293 rfg
= bgp_rfapi_cfg_match_byname (bgp
, arg_vrf
, RFAPI_GROUP_CFG_VRF
);
5297 vty_out (vty
, "VRF \"%s\" appears not to be configured.%s",
5298 arg_vrf
, VTY_NEWLINE
);
5301 rc
= parse_deleter_args (vty
, bgp
, arg_prefix
, NULL
, NULL
, NULL
, NULL
,
5303 if (rc
!= CMD_SUCCESS
) /* parse error */
5306 start_count
= rfapi_cfg_group_it_count(rfg
);
5307 clear_vnc_prefix (&cda
);
5308 clear_vnc_vrf_closer (rfg
);
5309 vty_out (vty
, "Cleared %u out of %d prefixes.%s",
5310 cda
.pfx_count
, start_count
, VTY_NEWLINE
);
5314 DEFUN (clear_vrf_prefix_rd
,
5315 clear_vrf_prefix_rd_cmd
,
5316 "clear vrf NAME [prefix <A.B.C.D/M|X:X::X:X/M>] [rd ASN:nn_or_IP-address]",
5317 "Clear stored data\n"
5320 "Prefix related information\n"
5323 "Specific VRF Route Distinguisher\n"
5324 "<as-number>:<number> or <ip-address>:<number>\n")
5326 char *arg_vrf
= argv
[2]->arg
;
5327 char *arg_prefix
= NULL
; /* optional */
5328 char *arg_rd
= NULL
; /* optional */
5330 argc
--; /* don't check parameter */
5331 while (pargc
< argc
)
5333 switch (argv
[pargc
++]->arg
[0])
5336 arg_rd
= argv
[pargc
]->arg
;
5339 arg_prefix
= argv
[pargc
]->arg
;
5346 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, arg_prefix
, arg_rd
);
5349 DEFUN (clear_vrf_all
,
5351 "clear vrf NAME all",
5352 "Clear stored data\n"
5357 char *arg_vrf
= argv
[2]->arg
;
5358 return vnc_clear_vrf (vty
, NULL
, arg_vrf
, NULL
, NULL
);
5361 void rfapi_vty_init ()
5363 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_lnh_cmd
);
5364 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_lnh_cmd
);
5365 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_lnh_cmd
);
5366 install_element (ENABLE_NODE
, &add_vnc_prefix_life_lnh_cmd
);
5367 install_element (ENABLE_NODE
, &add_vnc_prefix_lnh_cmd
);
5369 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_life_cmd
);
5370 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cost_cmd
);
5371 install_element (ENABLE_NODE
, &add_vnc_prefix_cost_cmd
);
5372 install_element (ENABLE_NODE
, &add_vnc_prefix_life_cmd
);
5373 install_element (ENABLE_NODE
, &add_vnc_prefix_cmd
);
5375 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_life_cmd
);
5376 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_life_cmd
);
5377 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cost_cmd
);
5378 install_element (ENABLE_NODE
, &add_vnc_mac_vni_prefix_cmd
);
5379 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_life_cmd
);
5380 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cost_cmd
);
5381 install_element (ENABLE_NODE
, &add_vnc_mac_vni_life_cmd
);
5382 install_element (ENABLE_NODE
, &add_vnc_mac_vni_cmd
);
5384 install_element (ENABLE_NODE
, &add_vrf_prefix_rd_label_pref_cmd
);
5386 install_element (ENABLE_NODE
, &clear_vnc_nve_all_cmd
);
5387 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_un_cmd
);
5388 install_element (ENABLE_NODE
, &clear_vnc_nve_un_vn_cmd
);
5389 install_element (ENABLE_NODE
, &clear_vnc_nve_vn_cmd
);
5390 install_element (ENABLE_NODE
, &clear_vnc_nve_un_cmd
);
5392 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_un_cmd
);
5393 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_vn_cmd
);
5394 install_element (ENABLE_NODE
, &clear_vnc_prefix_un_cmd
);
5395 install_element (ENABLE_NODE
, &clear_vnc_prefix_vn_cmd
);
5396 install_element (ENABLE_NODE
, &clear_vnc_prefix_all_cmd
);
5398 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_cmd
);
5399 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_cmd
);
5400 install_element (ENABLE_NODE
, &clear_vnc_mac_un_cmd
);
5401 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_cmd
);
5402 install_element (ENABLE_NODE
, &clear_vnc_mac_all_cmd
);
5404 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_un_prefix_cmd
);
5405 install_element (ENABLE_NODE
, &clear_vnc_mac_un_vn_prefix_cmd
);
5406 install_element (ENABLE_NODE
, &clear_vnc_mac_un_prefix_cmd
);
5407 install_element (ENABLE_NODE
, &clear_vnc_mac_vn_prefix_cmd
);
5408 install_element (ENABLE_NODE
, &clear_vnc_mac_all_prefix_cmd
);
5410 install_element (ENABLE_NODE
, &clear_vrf_prefix_rd_cmd
);
5411 install_element (ENABLE_NODE
, &clear_vrf_all_cmd
);
5413 install_element (ENABLE_NODE
, &vnc_clear_counters_cmd
);
5415 install_element (VIEW_NODE
, &vnc_show_summary_cmd
);
5416 install_element (VIEW_NODE
, &vnc_show_nves_cmd
);
5417 install_element (VIEW_NODE
, &vnc_show_nves_ptct_cmd
);
5419 install_element (VIEW_NODE
, &vnc_show_registrations_pfx_cmd
);
5420 install_element (VIEW_NODE
, &vnc_show_registrations_some_pfx_cmd
);
5421 install_element (VIEW_NODE
, &vnc_show_responses_pfx_cmd
);
5422 install_element (VIEW_NODE
, &vnc_show_responses_some_pfx_cmd
);
5423 install_element (VIEW_NODE
, &show_vnc_queries_pfx_cmd
);