]>
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"
32 #include "bgpd/bgp_updgrp.h"
34 int show_adj_route_vpn(struct vty
*vty
, struct peer
*peer
,
35 struct prefix_rd
*prd
, afi_t afi
, safi_t safi
,
39 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_adv
= NULL
;
48 json_object
*json_routes
= NULL
;
50 unsigned long output_count
= 0;
52 bgp
= bgp_get_default();
55 vty_out(vty
, "No BGP process is configured\n");
62 json_scode
= json_object_new_object();
63 json_ocode
= json_object_new_object();
64 json
= json_object_new_object();
65 json_adv
= json_object_new_object();
67 json_object_string_add(json_scode
, "suppressed", "s");
68 json_object_string_add(json_scode
, "damped", "d");
69 json_object_string_add(json_scode
, "history", "h");
70 json_object_string_add(json_scode
, "valid", "*");
71 json_object_string_add(json_scode
, "best", ">");
72 json_object_string_add(json_scode
, "internal", "i");
74 json_object_string_add(json_ocode
, "igp", "i");
75 json_object_string_add(json_ocode
, "egp", "e");
76 json_object_string_add(json_ocode
, "incomplete", "?");
79 for (rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rn
;
80 rn
= bgp_route_next(rn
)) {
81 const struct prefix
*rn_p
= bgp_node_get_prefix(rn
);
83 if (prd
&& memcmp(rn_p
->u
.val
, prd
->val
, 8) != 0)
86 table
= bgp_node_get_bgp_table_info(rn
);
91 * Initialize variables for each RD
92 * All prefixes under an RD is aggregated within "json_routes"
95 memset(rd_str
, 0, sizeof(rd_str
));
98 for (rm
= bgp_table_top(table
); rm
; rm
= bgp_route_next(rm
)) {
99 struct bgp_adj_out
*adj
= NULL
;
100 struct attr
*attr
= NULL
;
101 struct peer_af
*paf
= NULL
;
103 RB_FOREACH (adj
, bgp_adj_out_rb
, &rm
->adj_out
)
104 SUBGRP_FOREACH_PEER (adj
->subgroup
, paf
) {
105 if (paf
->peer
!= peer
|| !adj
->attr
)
112 if (bgp_node_get_bgp_path_info(rm
) == NULL
)
121 json
, "bgpTableVersion", 0);
122 json_object_string_add(
123 json
, "bgpLocalRouterId",
124 inet_ntoa(bgp
->router_id
));
128 bgp
->default_local_pref
);
132 json_object_object_add(json
,
135 json_object_object_add(json
,
140 "BGP table version is 0, local router ID is %s\n",
141 inet_ntoa(bgp
->router_id
));
142 vty_out(vty
, "Default local pref %u, ",
143 bgp
->default_local_pref
);
144 vty_out(vty
, "local AS %u\n", bgp
->as
);
146 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
148 "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n");
149 vty_out(vty
, V4_HEADER
);
156 struct rd_as rd_as
= {0};
157 struct rd_ip rd_ip
= {0};
158 #ifdef ENABLE_BGP_VNC
159 struct rd_vnc_eth rd_vnc_eth
= {0};
165 /* Decode RD type. */
166 type
= decode_rd_type(pnt
);
167 /* Decode RD value. */
168 if (type
== RD_TYPE_AS
)
169 decode_rd_as(pnt
+ 2, &rd_as
);
170 else if (type
== RD_TYPE_AS4
)
171 decode_rd_as4(pnt
+ 2, &rd_as
);
172 else if (type
== RD_TYPE_IP
)
173 decode_rd_ip(pnt
+ 2, &rd_ip
);
174 #ifdef ENABLE_BGP_VNC
175 else if (type
== RD_TYPE_VNC_ETH
)
176 decode_rd_vnc_eth(pnt
, &rd_vnc_eth
);
179 json_routes
= json_object_new_object();
181 if (type
== RD_TYPE_AS
182 || type
== RD_TYPE_AS4
)
183 sprintf(rd_str
, "%u:%d",
184 rd_as
.as
, rd_as
.val
);
185 else if (type
== RD_TYPE_IP
)
186 sprintf(rd_str
, "%s:%d",
189 json_object_string_add(
193 vty_out(vty
, "Route Distinguisher: ");
195 if (type
== RD_TYPE_AS
196 || type
== RD_TYPE_AS4
)
197 vty_out(vty
, "%u:%d", rd_as
.as
,
199 else if (type
== RD_TYPE_IP
)
200 vty_out(vty
, "%s:%d",
203 #ifdef ENABLE_BGP_VNC
204 else if (type
== RD_TYPE_VNC_ETH
)
206 "%u:%02x:%02x:%02x:%02x:%02x:%02x",
207 rd_vnc_eth
.local_nve_id
,
226 route_vty_out_tmp(vty
, bgp_node_get_prefix(rm
), attr
,
227 safi
, use_json
, json_routes
);
231 if (use_json
&& json_routes
)
232 json_object_object_add(json_adv
, rd_str
, json_routes
);
236 json_object_object_add(json
, "advertisedRoutes", json_adv
);
237 json_object_int_add(json
,
238 "totalPrefixCounter", output_count
);
239 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
240 json
, JSON_C_TO_STRING_PRETTY
));
241 json_object_free(json
);
243 vty_out(vty
, "\nTotal number of prefixes %ld\n", output_count
);