]>
git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vpn.c
1 /* VPN Related functions
2 Copyright (C) 2017 6WIND
4 This file is part of FRRouting
6 FRRouting is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 FRRouting is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with FRRouting; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "bgpd/bgpd.h"
27 #include "bgpd/bgp_route.h"
28 #include "bgpd/bgp_table.h"
29 #include "bgpd/bgp_attr.h"
30 #include "bgpd/bgp_mplsvpn.h"
31 #include "bgpd/bgp_vpn.h"
33 int show_adj_route_vpn(struct vty
*vty
, struct peer
*peer
,
34 struct prefix_rd
*prd
, afi_t afi
, safi_t safi
,
38 struct bgp_table
*table
;
45 " Network Next Hop Metric LocPrf Weight Path%s";
46 json_object
*json
= NULL
;
47 json_object
*json_scode
= NULL
;
48 json_object
*json_ocode
= NULL
;
49 json_object
*json_routes
= NULL
;
50 json_object
*json_array
= NULL
;
52 bgp
= bgp_get_default();
55 vty_out(vty
, "No BGP process is configured%s",
61 json_scode
= json_object_new_object();
62 json_ocode
= json_object_new_object();
63 json_routes
= json_object_new_object();
64 json
= json_object_new_object();
66 json_object_string_add(json_scode
, "suppressed", "s");
67 json_object_string_add(json_scode
, "damped", "d");
68 json_object_string_add(json_scode
, "history", "h");
69 json_object_string_add(json_scode
, "valid", "*");
70 json_object_string_add(json_scode
, "best", ">");
71 json_object_string_add(json_scode
, "internal", "i");
73 json_object_string_add(json_ocode
, "igp", "i");
74 json_object_string_add(json_ocode
, "egp", "e");
75 json_object_string_add(json_ocode
, "incomplete", "?");
78 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
;
79 rn
= bgp_route_next(rn
)) {
80 if (prd
&& memcmp(rn
->p
.u
.val
, prd
->val
, 8) != 0)
83 if ((table
= rn
->info
) != NULL
) {
85 json_array
= json_object_new_array();
91 for (rm
= bgp_table_top(table
); rm
;
92 rm
= bgp_route_next(rm
)) {
93 if ((attr
= rm
->info
) != NULL
) {
100 json_object_string_add(
105 json_object_object_add(
109 json_object_object_add(
115 "BGP table version is 0, local router ID is %s%s",
120 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
123 "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
126 vty_out(vty
, v4_header
,
135 struct rd_ip rd_ip
= {0};
137 struct rd_vnc_eth rd_vnc_eth
= {
144 /* Decode RD type. */
145 type
= decode_rd_type(pnt
);
146 /* Decode RD value. */
147 if (type
== RD_TYPE_AS
)
148 decode_rd_as(pnt
+ 2,
150 else if (type
== RD_TYPE_AS4
)
151 decode_rd_as4(pnt
+ 2,
153 else if (type
== RD_TYPE_IP
)
154 decode_rd_ip(pnt
+ 2,
166 if (type
== RD_TYPE_AS
167 || type
== RD_TYPE_AS4
)
179 json_object_string_add(
181 "routeDistinguisher",
185 "Route Distinguisher: ");
187 if (type
== RD_TYPE_AS
188 || type
== RD_TYPE_AS4
)
205 "%u:%02x:%02x:%02x:%02x:%02x:%02x",
233 route_vty_out_tmp(vty
, &rm
->p
, attr
,
235 use_json
, json_array
);
243 sprintf(buf_a
, "%s/%d",
244 inet_ntop(p
->family
, &p
->u
.prefix
,
247 json_object_object_add(json_routes
, buf_a
,
253 json_object_object_add(json
, "routes", json_routes
);
254 vty_out(vty
, "%s%s", json_object_to_json_string_ext(
255 json
, JSON_C_TO_STRING_PRETTY
),
257 json_object_free(json
);