]>
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 char v4_header
[] = " Network Next Hop Metric LocPrf Weight Path%s";
45 json_object
*json
= NULL
;
46 json_object
*json_scode
= NULL
;
47 json_object
*json_ocode
= NULL
;
48 json_object
*json_routes
= NULL
;
49 json_object
*json_array
= NULL
;
51 bgp
= bgp_get_default ();
55 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
61 json_scode
= json_object_new_object();
62 json_ocode
= json_object_new_object();
63 json_routes
= json_object_new_object();
64 json
= json_object_new_object();
66 json_object_string_add(json_scode
, "suppressed", "s");
67 json_object_string_add(json_scode
, "damped", "d");
68 json_object_string_add(json_scode
, "history", "h");
69 json_object_string_add(json_scode
, "valid", "*");
70 json_object_string_add(json_scode
, "best", ">");
71 json_object_string_add(json_scode
, "internal", "i");
73 json_object_string_add(json_ocode
, "igp", "i");
74 json_object_string_add(json_ocode
, "egp", "e");
75 json_object_string_add(json_ocode
, "incomplete", "?");
78 for (rn
= bgp_table_top (bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
;
79 rn
= bgp_route_next (rn
))
81 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
84 if ((table
= rn
->info
) != NULL
)
87 json_array
= json_object_new_array();
93 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
95 if ((attr
= rm
->info
) != NULL
)
101 json_object_int_add(json
, "bgpTableVersion", 0);
102 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
103 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
104 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
108 vty_out (vty
, "BGP table version is 0, local router ID is %s%s",
109 inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
110 vty_out (vty
, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
112 vty_out (vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
113 VTY_NEWLINE
, VTY_NEWLINE
);
114 vty_out (vty
, v4_header
, VTY_NEWLINE
);
123 struct rd_ip rd_ip
= {0};
125 struct rd_vnc_eth rd_vnc_eth
= {0};
131 /* Decode RD type. */
132 type
= decode_rd_type (pnt
);
133 /* Decode RD value. */
134 if (type
== RD_TYPE_AS
)
135 decode_rd_as (pnt
+ 2, &rd_as
);
136 else if (type
== RD_TYPE_AS4
)
137 decode_rd_as4 (pnt
+ 2, &rd_as
);
138 else if (type
== RD_TYPE_IP
)
139 decode_rd_ip (pnt
+ 2, &rd_ip
);
141 else if (type
== RD_TYPE_VNC_ETH
)
142 decode_rd_vnc_eth (pnt
, &rd_vnc_eth
);
148 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
149 sprintf (buffer
, "%u:%d", rd_as
.as
, rd_as
.val
);
150 else if (type
== RD_TYPE_IP
)
151 sprintf (buffer
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
152 json_object_string_add(json_routes
, "routeDistinguisher", buffer
);
156 vty_out (vty
, "Route Distinguisher: ");
158 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
159 vty_out (vty
, "%u:%d", rd_as
.as
, rd_as
.val
);
160 else if (type
== RD_TYPE_IP
)
161 vty_out (vty
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
163 else if (type
== RD_TYPE_VNC_ETH
)
164 vty_out (vty
, "%u:%02x:%02x:%02x:%02x:%02x:%02x",
165 rd_vnc_eth
.local_nve_id
,
166 rd_vnc_eth
.macaddr
.octet
[0],
167 rd_vnc_eth
.macaddr
.octet
[1],
168 rd_vnc_eth
.macaddr
.octet
[2],
169 rd_vnc_eth
.macaddr
.octet
[3],
170 rd_vnc_eth
.macaddr
.octet
[4],
171 rd_vnc_eth
.macaddr
.octet
[5]);
174 vty_out (vty
, "%s", VTY_NEWLINE
);
178 route_vty_out_tmp (vty
, &rm
->p
, attr
, SAFI_MPLS_VPN
, use_json
, json_array
);
187 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
188 json_object_object_add(json_routes
, buf_a
, json_array
);
194 json_object_object_add(json
, "routes", json_routes
);
195 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
196 json_object_free(json
);