/* MPLS-VPN
- Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
-
-This file is part of GNU Zebra.
-
-GNU Zebra is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-GNU Zebra is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Zebra; see the file COPYING. If not, write to the Free
-Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+ * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#include <zebra.h>
#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)
{
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;
}