]>
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"
34 show_adj_route_vpn (struct vty
*vty
, struct peer
*peer
, struct prefix_rd
*prd
,
35 afi_t afi
, safi_t safi
, u_char use_json
)
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 ();
54 vty_outln (vty
, "No BGP process is configured");
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
))
80 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
83 if ((table
= rn
->info
) != NULL
)
86 json_array
= json_object_new_array();
92 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
94 if ((attr
= rm
->info
) != NULL
)
100 json_object_int_add(json
, "bgpTableVersion", 0);
101 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
102 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
103 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
107 vty_outln (vty
, "BGP table version is 0, local router ID is %s",
108 inet_ntoa(bgp
->router_id
));
110 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal");
111 vty_outln (vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete%s",
113 vty_outln (vty
, V4_HEADER
);
122 struct rd_ip rd_ip
= {0};
124 struct rd_vnc_eth rd_vnc_eth
= {0};
130 /* Decode RD type. */
131 type
= decode_rd_type (pnt
);
132 /* Decode RD value. */
133 if (type
== RD_TYPE_AS
)
134 decode_rd_as (pnt
+ 2, &rd_as
);
135 else if (type
== RD_TYPE_AS4
)
136 decode_rd_as4 (pnt
+ 2, &rd_as
);
137 else if (type
== RD_TYPE_IP
)
138 decode_rd_ip (pnt
+ 2, &rd_ip
);
140 else if (type
== RD_TYPE_VNC_ETH
)
141 decode_rd_vnc_eth (pnt
, &rd_vnc_eth
);
147 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
148 sprintf (buffer
, "%u:%d", rd_as
.as
, rd_as
.val
);
149 else if (type
== RD_TYPE_IP
)
150 sprintf (buffer
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
151 json_object_string_add(json_routes
, "routeDistinguisher", buffer
);
155 vty_out (vty
, "Route Distinguisher: ");
157 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
158 vty_out (vty
, "%u:%d", rd_as
.as
, rd_as
.val
);
159 else if (type
== RD_TYPE_IP
)
160 vty_out (vty
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
162 else if (type
== RD_TYPE_VNC_ETH
)
163 vty_out (vty
, "%u:%02x:%02x:%02x:%02x:%02x:%02x",
164 rd_vnc_eth
.local_nve_id
,
165 rd_vnc_eth
.macaddr
.octet
[0],
166 rd_vnc_eth
.macaddr
.octet
[1],
167 rd_vnc_eth
.macaddr
.octet
[2],
168 rd_vnc_eth
.macaddr
.octet
[3],
169 rd_vnc_eth
.macaddr
.octet
[4],
170 rd_vnc_eth
.macaddr
.octet
[5]);
173 vty_out (vty
, VTYNL
);
177 route_vty_out_tmp (vty
, &rm
->p
, attr
, SAFI_MPLS_VPN
, use_json
, json_array
);
186 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
187 json_object_object_add(json_routes
, buf_a
, json_array
);
193 json_object_object_add(json
, "routes", json_routes
);
194 vty_outln (vty
, "%s",
195 json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
));
196 json_object_free(json
);