]>
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
25 #include "lib/printfrr.h"
27 #include "bgpd/bgpd.h"
28 #include "bgpd/bgp_route.h"
29 #include "bgpd/bgp_table.h"
30 #include "bgpd/bgp_attr.h"
31 #include "bgpd/bgp_mplsvpn.h"
32 #include "bgpd/bgp_vpn.h"
33 #include "bgpd/bgp_updgrp.h"
35 int show_adj_route_vpn(struct vty
*vty
, struct peer
*peer
,
36 struct prefix_rd
*prd
, afi_t afi
, safi_t safi
,
40 struct bgp_table
*table
;
41 struct bgp_dest
*dest
;
45 json_object
*json
= NULL
;
46 json_object
*json_scode
= NULL
;
47 json_object
*json_ocode
= NULL
;
48 json_object
*json_adv
= NULL
;
49 json_object
*json_routes
= NULL
;
51 unsigned long output_count
= 0;
53 bgp
= bgp_get_default();
56 vty_out(vty
, "No BGP process is configured\n");
63 json_scode
= json_object_new_object();
64 json_ocode
= json_object_new_object();
65 json
= json_object_new_object();
66 json_adv
= json_object_new_object();
68 json_object_string_add(json_scode
, "suppressed", "s");
69 json_object_string_add(json_scode
, "damped", "d");
70 json_object_string_add(json_scode
, "history", "h");
71 json_object_string_add(json_scode
, "valid", "*");
72 json_object_string_add(json_scode
, "best", ">");
73 json_object_string_add(json_scode
, "internal", "i");
75 json_object_string_add(json_ocode
, "igp", "i");
76 json_object_string_add(json_ocode
, "egp", "e");
77 json_object_string_add(json_ocode
, "incomplete", "?");
80 for (dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); dest
;
81 dest
= bgp_route_next(dest
)) {
82 const struct prefix
*dest_p
= bgp_dest_get_prefix(dest
);
84 if (prd
&& memcmp(dest_p
->u
.val
, prd
->val
, 8) != 0)
87 table
= bgp_dest_get_bgp_table_info(dest
);
92 * Initialize variables for each RD
93 * All prefixes under an RD is aggregated within "json_routes"
96 memset(rd_str
, 0, sizeof(rd_str
));
99 for (rm
= bgp_table_top(table
); rm
; rm
= bgp_route_next(rm
)) {
100 struct bgp_adj_out
*adj
= NULL
;
101 struct attr
*attr
= NULL
;
102 struct peer_af
*paf
= NULL
;
104 RB_FOREACH (adj
, bgp_adj_out_rb
, &rm
->adj_out
)
105 SUBGRP_FOREACH_PEER (adj
->subgroup
, paf
) {
106 if (paf
->peer
!= peer
|| !adj
->attr
)
113 if (bgp_dest_get_bgp_path_info(rm
) == NULL
)
122 json
, "bgpTableVersion", 0);
123 json_object_string_addf(
124 json
, "bgpLocalRouterId",
125 "%pI4", &bgp
->router_id
);
129 bgp
->default_local_pref
);
133 json_object_object_add(json
,
136 json_object_object_add(json
,
141 "BGP table version is 0, local router ID is %pI4\n",
143 vty_out(vty
, "Default local pref %u, ",
144 bgp
->default_local_pref
);
145 vty_out(vty
, "local AS %u\n", bgp
->as
);
147 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
149 "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n");
150 vty_out(vty
, V4_HEADER
);
157 struct rd_as rd_as
= {0};
158 struct rd_ip rd_ip
= {0};
159 #ifdef ENABLE_BGP_VNC
160 struct rd_vnc_eth rd_vnc_eth
= {0};
166 /* Decode RD type. */
167 type
= decode_rd_type(pnt
);
168 /* Decode RD value. */
169 if (type
== RD_TYPE_AS
)
170 decode_rd_as(pnt
+ 2, &rd_as
);
171 else if (type
== RD_TYPE_AS4
)
172 decode_rd_as4(pnt
+ 2, &rd_as
);
173 else if (type
== RD_TYPE_IP
)
174 decode_rd_ip(pnt
+ 2, &rd_ip
);
175 #ifdef ENABLE_BGP_VNC
176 else if (type
== RD_TYPE_VNC_ETH
)
177 decode_rd_vnc_eth(pnt
, &rd_vnc_eth
);
180 json_routes
= json_object_new_object();
182 if (type
== RD_TYPE_AS
183 || type
== RD_TYPE_AS4
)
184 snprintf(rd_str
, sizeof(rd_str
),
187 else if (type
== RD_TYPE_IP
)
190 "%pI4:%d", &rd_ip
.ip
,
192 json_object_string_add(
196 vty_out(vty
, "Route Distinguisher: ");
198 if (type
== RD_TYPE_AS
199 || type
== RD_TYPE_AS4
)
200 vty_out(vty
, "%u:%d", rd_as
.as
,
202 else if (type
== RD_TYPE_IP
)
203 vty_out(vty
, "%pI4:%d",
204 &rd_ip
.ip
, rd_ip
.val
);
205 #ifdef ENABLE_BGP_VNC
206 else if (type
== RD_TYPE_VNC_ETH
)
208 "%u:%02x:%02x:%02x:%02x:%02x:%02x",
209 rd_vnc_eth
.local_nve_id
,
228 route_vty_out_tmp(vty
, rm
, bgp_dest_get_prefix(rm
),
229 attr
, safi
, use_json
, json_routes
,
234 if (use_json
&& json_routes
)
235 json_object_object_add(json_adv
, rd_str
, json_routes
);
239 json_object_object_add(json
, "advertisedRoutes", json_adv
);
240 json_object_int_add(json
,
241 "totalPrefixCounter", output_count
);
244 vty_out(vty
, "\nTotal number of prefixes %ld\n", output_count
);