]>
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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
;
44 json_object
*json
= NULL
;
45 json_object
*json_scode
= NULL
;
46 json_object
*json_ocode
= NULL
;
47 json_object
*json_routes
= NULL
;
48 json_object
*json_array
= NULL
;
50 bgp
= bgp_get_default();
53 vty_out(vty
, "No BGP process is configured\n");
58 json_scode
= json_object_new_object();
59 json_ocode
= json_object_new_object();
60 json_routes
= json_object_new_object();
61 json
= json_object_new_object();
63 json_object_string_add(json_scode
, "suppressed", "s");
64 json_object_string_add(json_scode
, "damped", "d");
65 json_object_string_add(json_scode
, "history", "h");
66 json_object_string_add(json_scode
, "valid", "*");
67 json_object_string_add(json_scode
, "best", ">");
68 json_object_string_add(json_scode
, "internal", "i");
70 json_object_string_add(json_ocode
, "igp", "i");
71 json_object_string_add(json_ocode
, "egp", "e");
72 json_object_string_add(json_ocode
, "incomplete", "?");
75 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
;
76 rn
= bgp_route_next(rn
)) {
77 if (prd
&& memcmp(rn
->p
.u
.val
, prd
->val
, 8) != 0)
80 if ((table
= rn
->info
) != NULL
) {
82 json_array
= json_object_new_array();
88 for (rm
= bgp_table_top(table
); rm
;
89 rm
= bgp_route_next(rm
)) {
90 if ((attr
= rm
->info
) != NULL
) {
97 json_object_string_add(
102 json_object_object_add(
106 json_object_object_add(
112 "BGP table version is 0, local router ID is %s\n",
116 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
118 "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n");
119 vty_out(vty
, V4_HEADER
);
127 struct rd_ip rd_ip
= {0};
129 struct rd_vnc_eth rd_vnc_eth
= {
136 /* Decode RD type. */
137 type
= decode_rd_type(pnt
);
138 /* Decode RD value. */
139 if (type
== RD_TYPE_AS
)
140 decode_rd_as(pnt
+ 2,
142 else if (type
== RD_TYPE_AS4
)
143 decode_rd_as4(pnt
+ 2,
145 else if (type
== RD_TYPE_IP
)
146 decode_rd_ip(pnt
+ 2,
158 if (type
== RD_TYPE_AS
159 || type
== RD_TYPE_AS4
)
171 json_object_string_add(
173 "routeDistinguisher",
177 "Route Distinguisher: ");
179 if (type
== RD_TYPE_AS
180 || type
== RD_TYPE_AS4
)
197 "%u:%02x:%02x:%02x:%02x:%02x:%02x",
224 route_vty_out_tmp(vty
, &rm
->p
, attr
,
226 use_json
, json_array
);
234 sprintf(buf_a
, "%s/%d",
235 inet_ntop(p
->family
, &p
->u
.prefix
,
238 json_object_object_add(json_routes
, buf_a
,
244 json_object_object_add(json
, "routes", json_routes
);
246 json_object_to_json_string_ext(
247 json
, JSON_C_TO_STRING_PRETTY
));
248 json_object_free(json
);