]>
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");
60 json_scode
= json_object_new_object();
61 json_ocode
= json_object_new_object();
62 json_routes
= json_object_new_object();
63 json
= json_object_new_object();
65 json_object_string_add(json_scode
, "suppressed", "s");
66 json_object_string_add(json_scode
, "damped", "d");
67 json_object_string_add(json_scode
, "history", "h");
68 json_object_string_add(json_scode
, "valid", "*");
69 json_object_string_add(json_scode
, "best", ">");
70 json_object_string_add(json_scode
, "internal", "i");
72 json_object_string_add(json_ocode
, "igp", "i");
73 json_object_string_add(json_ocode
, "egp", "e");
74 json_object_string_add(json_ocode
, "incomplete", "?");
77 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
;
78 rn
= bgp_route_next(rn
)) {
79 if (prd
&& memcmp(rn
->p
.u
.val
, prd
->val
, 8) != 0)
82 if ((table
= rn
->info
) != NULL
) {
84 json_array
= json_object_new_array();
90 for (rm
= bgp_table_top(table
); rm
;
91 rm
= bgp_route_next(rm
)) {
92 if ((attr
= rm
->info
) != NULL
) {
99 json_object_string_add(
104 json_object_object_add(
108 json_object_object_add(
114 "BGP table version is 0, local router ID is %s\n",
118 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
120 "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n");
121 vty_out(vty
, V4_HEADER
);
129 struct rd_ip rd_ip
= {0};
131 struct rd_vnc_eth rd_vnc_eth
= {
138 /* Decode RD type. */
139 type
= decode_rd_type(pnt
);
140 /* Decode RD value. */
141 if (type
== RD_TYPE_AS
)
142 decode_rd_as(pnt
+ 2,
144 else if (type
== RD_TYPE_AS4
)
145 decode_rd_as4(pnt
+ 2,
147 else if (type
== RD_TYPE_IP
)
148 decode_rd_ip(pnt
+ 2,
160 if (type
== RD_TYPE_AS
161 || type
== RD_TYPE_AS4
)
173 json_object_string_add(
175 "routeDistinguisher",
179 "Route Distinguisher: ");
181 if (type
== RD_TYPE_AS
182 || type
== RD_TYPE_AS4
)
199 "%u:%02x:%02x:%02x:%02x:%02x:%02x",
226 route_vty_out_tmp(vty
, &rm
->p
, attr
,
228 use_json
, json_array
);
236 sprintf(buf_a
, "%s/%d",
237 inet_ntop(p
->family
, &p
->u
.prefix
,
240 json_object_object_add(json_routes
, buf_a
,
246 json_object_object_add(json
, "routes", json_routes
);
247 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
248 json
, JSON_C_TO_STRING_PRETTY
));
249 json_object_free(json
);