#include "stream.h"
#include "queue.h"
#include "filter.h"
-
#include "lib/json.h"
+
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h"
+#include "bgpd/bgp_label.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_vty.h"
}
u_int32_t
-decode_label (u_char *pnt)
+decode_label (mpls_label_t *label_pnt)
{
u_int32_t l;
+ u_char *pnt = (u_char *) label_pnt;
l = ((u_int32_t) *pnt++ << 12);
l |= (u_int32_t) *pnt++ << 4;
}
void
-encode_label(u_int32_t label,
- u_char *pnt)
+encode_label(mpls_label_t label,
+ mpls_label_t *label_pnt)
{
+ u_char *pnt = (u_char *) label_pnt;
if (pnt == NULL)
return;
*pnt++ = (label>>12) & 0xff;
struct rd_as rd_as;
struct rd_ip rd_ip;
struct prefix_rd prd;
- u_char *tagpnt;
+ mpls_label_t label;
afi_t afi;
safi_t safi;
int addpath_encoded;
return -1;
}
- /* Copyr label to prefix. */
- tagpnt = pnt;
+ /* Copy label to prefix. */
+ memcpy(&label, pnt, BGP_LABEL_BYTES);
+ bgp_set_valid_label(&label);
/* Copy routing distinguisher to rd. */
- memcpy (&prd.val, pnt + 3, 8);
+ memcpy (&prd.val, pnt + BGP_LABEL_BYTES, 8);
/* Decode RD type. */
- type = decode_rd_type (pnt + 3);
+ type = decode_rd_type (pnt + BGP_LABEL_BYTES);
switch (type)
{
if (attr)
{
bgp_update (peer, &p, addpath_id, attr, packet->afi, SAFI_MPLS_VPN,
- ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0, NULL);
+ ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, &label, 0, NULL);
}
else
{
bgp_withdraw (peer, &p, addpath_id, attr, packet->afi, SAFI_MPLS_VPN,
- ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, NULL);
+ ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, &label, NULL);
}
}
/* Packet length consistency check. */
return lret;
}
-int
-str2tag (const char *str, u_char *tag)
-{
- unsigned long l;
- char *endptr;
- u_int32_t t;
-
- if (*str == '-')
- return 0;
-
- errno = 0;
- l = strtoul (str, &endptr, 10);
-
- if (*endptr != '\0' || errno || l > UINT32_MAX)
- return 0;
-
- t = (u_int32_t) l;
-
- tag[0] = (u_char)(t >> 12);
- tag[1] = (u_char)(t >> 4);
- tag[2] = (u_char)(t << 4);
-
- return 1;
-}
-
char *
prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
{
/* For testing purpose, static route of MPLS-VPN. */
DEFUN (vpnv4_network,
vpnv4_network_cmd,
- "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
+ "network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
"Specify a network to announce via BGP\n"
"IPv4 prefix\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
- "BGP tag\n"
- "tag value\n")
+ "VPN NLRI label (tag)\n"
+ "VPN NLRI label (tag)\n"
+ "Label value\n")
{
int idx_ipv4_prefixlen = 1;
int idx_ext_community = 3;
- int idx_word = 5;
- return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, argv[idx_ext_community]->arg,
- argv[idx_word]->arg, NULL, 0, NULL, NULL, NULL, NULL);
+ int idx_label = 5;
+ return bgp_static_set_safi (AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, argv[idx_ext_community]->arg,
+ argv[idx_label]->arg, NULL, 0, NULL, NULL, NULL, NULL);
}
DEFUN (vpnv4_network_route_map,
vpnv4_network_route_map_cmd,
- "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD",
+ "network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575) route-map WORD",
"Specify a network to announce via BGP\n"
"IPv4 prefix\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
- "BGP tag\n"
- "tag value\n"
+ "VPN NLRI label (tag)\n"
+ "VPN NLRI label (tag)\n"
+ "Label value\n"
"route map\n"
"route map name\n")
{
int idx_ipv4_prefixlen = 1;
int idx_ext_community = 3;
- int idx_word = 5;
+ int idx_label = 5;
int idx_word_2 = 7;
- return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg,
+ return bgp_static_set_safi (AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, argv[idx_ext_community]->arg, argv[idx_label]->arg,
argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL);
}
/* For testing purpose, static route of MPLS-VPN. */
DEFUN (no_vpnv4_network,
no_vpnv4_network_cmd,
- "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
+ "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
NO_STR
"Specify a network to announce via BGP\n"
"IPv4 prefix\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
- "BGP tag\n"
- "tag value\n")
+ "VPN NLRI label (tag)\n"
+ "VPN NLRI label (tag)\n"
+ "Label value\n")
{
int idx_ipv4_prefixlen = 2;
int idx_ext_community = 4;
- int idx_word = 6;
- return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg,
- argv[idx_ext_community]->arg, argv[idx_word]->arg,
+ int idx_label = 6;
+ return bgp_static_unset_safi (AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg,
+ argv[idx_ext_community]->arg, argv[idx_label]->arg,
0, NULL, NULL, NULL);
}
DEFUN (vpnv6_network,
vpnv6_network_cmd,
- "network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD [route-map WORD]",
+ "network X:X::X:X/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575) [route-map WORD]",
"Specify a network to announce via BGP\n"
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
- "BGP tag\n"
- "tag value\n"
+ "VPN NLRI label (tag)\n"
+ "VPN NLRI label (tag)\n"
+ "Label value\n"
"route map\n"
"route map name\n")
{
int idx_ipv6_prefix = 1;
int idx_ext_community = 3;
- int idx_word = 5;
+ int idx_label = 5;
int idx_word_2 = 7;
if (argc == 8)
- return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg, argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL);
+ return bgp_static_set_safi (AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_label]->arg, argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL);
else
- return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg, NULL, 0, NULL, NULL, NULL, NULL);
+ return bgp_static_set_safi (AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_label]->arg, NULL, 0, NULL, NULL, NULL, NULL);
}
/* For testing purpose, static route of MPLS-VPN. */
DEFUN (no_vpnv6_network,
no_vpnv6_network_cmd,
- "no network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD",
+ "no network X:X::X:X/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
NO_STR
"Specify a network to announce via BGP\n"
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
- "BGP tag\n"
- "tag value\n")
+ "VPN NLRI label (tag)\n"
+ "VPN NLRI label (tag)\n"
+ "Label value\n")
{
int idx_ipv6_prefix = 2;
int idx_ext_community = 4;
- int idx_word = 6;
- return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg, 0, NULL, NULL, NULL);
+ int idx_label = 6;
+ return bgp_static_unset_safi (AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_label]->arg, 0, NULL, NULL, NULL);
}
int
struct bgp_info *ri;
int rd_header;
int header = 1;
- char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
- char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
unsigned long output_count = 0;
unsigned long total_count = 0;
json_object *json = NULL;
if (bgp == NULL)
{
if (!use_json)
- vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
+ vty_out (vty, "No BGP process is configured\n");
return CMD_WARNING;
}
if ((afi != AFI_IP) && (afi != AFI_IP6))
{
- vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE);
+ vty_out (vty, "Afi %d not supported\n", afi);
return CMD_WARNING;
}
else
{
if (tags)
- vty_out (vty, v4_header_tag, VTY_NEWLINE);
+ vty_outln (vty, V4_HEADER_TAG);
else
{
- vty_out (vty, "BGP table version is 0, local router ID is %s%s",
- inet_ntoa (bgp->router_id), VTY_NEWLINE);
- vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
- VTY_NEWLINE);
- vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
- VTY_NEWLINE, VTY_NEWLINE);
- vty_out (vty, v4_header, VTY_NEWLINE);
+ vty_out (vty, "BGP table version is 0, local router ID is %s\n",
+ inet_ntoa(bgp->router_id));
+ vty_out (vty,
+ "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
+ vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s\n",
+ VTYNL);
+ vty_outln (vty, V4_HEADER);
}
}
header = 0;
rd_vnc_eth.macaddr.octet[4],
rd_vnc_eth.macaddr.octet[5]);
#endif
- vty_out (vty, "%s", VTY_NEWLINE);
+ vty_out (vty, VTYNL);
}
rd_header = 0;
}
if (use_json)
{
json_object_object_add(json, "routes", json_nroute);
- vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
+ vty_out (vty, "%s\n",
+ json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
else
{
if (output_count == 0)
- vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
+ vty_out (vty, "No prefixes displayed, %ld exist\n", total_count);
else
- vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
- VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
+ vty_out (vty, "%sDisplayed %ld routes and %ld total paths\n",
+ VTYNL, output_count, total_count);
}
return CMD_SUCCESS;
ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
if (! ret)
{
- vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
+ vty_out (vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, afi, &prd, bgp_show_type_normal, NULL, 0, use_json (argc, argv));
ret = str2prefix_rd (argv[idx_ext_community]->arg, &prd);
if (! ret)
{
- vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
+ vty_out (vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, afi, &prd, bgp_show_type_normal, NULL, 0, 0);
ret = str2prefix_rd (argv[idx_ext_community]->arg, &prd);
if (! ret)
{
- vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
+ vty_out (vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, afi, &prd, bgp_show_type_normal, NULL, 1, 0);
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "Malformed address: %s%s", argv[idx_ipv4]->arg, VTY_NEWLINE);
+ vty_out (vty, "Malformed address: %s\n", argv[idx_ipv4]->arg);
return CMD_WARNING;
}
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
+ vty_out (vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed Route Distinguisher");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
+ vty_out (vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "Malformed address: %s%s", argv[idx_ext_community]->arg, VTY_NEWLINE);
+ vty_out (vty, "Malformed address: %s\n",
+ argv[idx_ext_community]->arg);
return CMD_WARNING;
}
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
+ vty_out (vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "Malformed address: %s%s", argv[idx_ipv4]->arg, VTY_NEWLINE);
+ vty_out (vty, "Malformed address: %s\n", argv[idx_ipv4]->arg);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
+ vty_out (vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, NULL, AFI_IP, SAFI_MPLS_VPN, uj);
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "Malformed address: %s%s", argv[idx_ext_community]->arg, VTY_NEWLINE);
+ vty_out (vty, "Malformed address: %s\n",
+ argv[idx_ext_community]->arg);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
+ vty_out (vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed Route Distinguisher");
- vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
+ vty_out (vty, "%s\n", json_object_to_json_string(json_no));
json_object_free(json_no);
}
else
- vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
+ vty_out (vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}