]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_mplsvpn.h
bgpd: Implement vrf - vrf route leaking cli
[mirror_frr.git] / bgpd / bgp_mplsvpn.h
1 /* MPLS-VPN
2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
3 *
4 * This file is part of GxNU Zebra.
5 *
6 * GNU Zebra 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
9 * later version.
10 *
11 * GNU Zebra 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.
15 *
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
19 */
20
21 #ifndef _QUAGGA_BGP_MPLSVPN_H
22 #define _QUAGGA_BGP_MPLSVPN_H
23
24 #include "bgpd/bgp_route.h"
25 #include "bgpd/bgp_rd.h"
26 #include "bgpd/bgp_zebra.h"
27
28 #define MPLS_LABEL_IS_SPECIAL(label) ((label) <= MPLS_LABEL_EXTENSION)
29 #define MPLS_LABEL_IS_NULL(label) \
30 ((label) == MPLS_LABEL_IPV4_EXPLICIT_NULL \
31 || (label) == MPLS_LABEL_IPV6_EXPLICIT_NULL \
32 || (label) == MPLS_LABEL_IMPLICIT_NULL)
33
34 #define BGP_VPNVX_HELP_STR \
35 "Address Family\n" \
36 "Address Family\n"
37
38 #define V4_HEADER \
39 " Network Next Hop Metric LocPrf Weight Path\n"
40 #define V4_HEADER_TAG " Network Next Hop In tag/Out tag\n"
41 #define V4_HEADER_OVERLAY \
42 " Network Next Hop EthTag Overlay Index RouterMac\n"
43
44 extern void bgp_mplsvpn_init(void);
45 extern int bgp_nlri_parse_vpn(struct peer *, struct attr *, struct bgp_nlri *);
46 extern uint32_t decode_label(mpls_label_t *);
47 extern void encode_label(mpls_label_t, mpls_label_t *);
48
49 extern int argv_find_and_parse_vpnvx(struct cmd_token **argv, int argc,
50 int *index, afi_t *afi);
51 extern int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd,
52 enum bgp_show_type type, void *output_arg,
53 int tags, uint8_t use_json);
54
55 extern void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, struct bgp *bgp_vrf,
56 struct bgp_info *info_vrf);
57
58 extern void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, struct bgp *bgp_vrf,
59 struct bgp_info *info_vrf);
60
61 extern void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn,
62 struct bgp *bgp_vrf, afi_t afi);
63
64 extern void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn,
65 struct bgp *bgp_vrf, afi_t afi);
66
67 extern void vpn_leak_to_vrf_withdraw_all(struct bgp *bgp_vrf, afi_t afi);
68
69 extern void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, struct bgp *bgp_vpn,
70 afi_t afi);
71
72 extern void vpn_leak_to_vrf_update(struct bgp *bgp_vpn,
73 struct bgp_info *info_vpn);
74
75 extern void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn,
76 struct bgp_info *info_vpn);
77
78 extern void vpn_leak_zebra_vrf_label_update(struct bgp *bgp, afi_t afi);
79 extern void vpn_leak_zebra_vrf_label_withdraw(struct bgp *bgp, afi_t afi);
80 extern int vpn_leak_label_callback(mpls_label_t label, void *lblid, bool alloc);
81
82 static inline int vpn_leak_to_vpn_active(struct bgp *bgp_vrf, afi_t afi,
83 const char **pmsg)
84 {
85 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF
86 && bgp_vrf->inst_type != BGP_INSTANCE_TYPE_DEFAULT) {
87
88 if (pmsg)
89 *pmsg = "source bgp instance neither vrf nor default";
90 return 0;
91 }
92
93 /* Is vrf configured to export to vpn? */
94 if (!CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST],
95 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
96 && !CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST],
97 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
98 if (pmsg)
99 *pmsg = "export not set";
100 return 0;
101 }
102
103 /* Is there an RT list set? */
104 if (!bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
105 if (pmsg)
106 *pmsg = "rtlist tovpn not defined";
107 return 0;
108 }
109
110 /* Is there an RD set? */
111 if (!CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags,
112 BGP_VPN_POLICY_TOVPN_RD_SET)) {
113 if (pmsg)
114 *pmsg = "rd not defined";
115 return 0;
116 }
117
118 /* Is a route-map specified, but not defined? */
119 if (bgp_vrf->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN] &&
120 !bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN]) {
121 if (pmsg)
122 *pmsg = "route-map tovpn named but not defined";
123 return 0;
124 }
125
126 /* Is there an "auto" export label that isn't allocated yet? */
127 if (CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags,
128 BGP_VPN_POLICY_TOVPN_LABEL_AUTO) &&
129 (bgp_vrf->vpn_policy[afi].tovpn_label == MPLS_LABEL_NONE)) {
130
131 if (pmsg)
132 *pmsg = "auto label not allocated";
133 return 0;
134 }
135
136 return 1;
137 }
138
139 static inline int vpn_leak_from_vpn_active(struct bgp *bgp_vrf, afi_t afi,
140 const char **pmsg)
141 {
142 if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF
143 && bgp_vrf->inst_type != BGP_INSTANCE_TYPE_DEFAULT) {
144
145 if (pmsg)
146 *pmsg = "destination bgp instance neither vrf nor default";
147 return 0;
148 }
149
150 /* Is vrf configured to import from vpn? */
151 if (!CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST],
152 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)
153 && !CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST],
154 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
155 if (pmsg)
156 *pmsg = "import not set";
157 return 0;
158 }
159
160 /* Is there an RT list set? */
161 if (!bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
162 if (pmsg)
163 *pmsg = "rtlist fromvpn not defined";
164 return 0;
165 }
166
167 /* Is a route-map specified, but not defined? */
168 if (bgp_vrf->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN] &&
169 !bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_FROMVPN]) {
170 if (pmsg)
171 *pmsg = "route-map fromvpn named but not defined";
172 return 0;
173 }
174 return 1;
175 }
176
177 static inline void vpn_leak_prechange(vpn_policy_direction_t direction,
178 afi_t afi, struct bgp *bgp_vpn,
179 struct bgp *bgp_vrf)
180 {
181 if ((direction == BGP_VPN_POLICY_DIR_FROMVPN) &&
182 vpn_leak_from_vpn_active(bgp_vrf, afi, NULL)) {
183
184 vpn_leak_to_vrf_withdraw_all(bgp_vrf, afi);
185 }
186 if ((direction == BGP_VPN_POLICY_DIR_TOVPN) &&
187 vpn_leak_to_vpn_active(bgp_vrf, afi, NULL)) {
188
189 vpn_leak_from_vrf_withdraw_all(bgp_vpn, bgp_vrf, afi);
190 }
191 }
192
193 static inline void vpn_leak_postchange(vpn_policy_direction_t direction,
194 afi_t afi, struct bgp *bgp_vpn,
195 struct bgp *bgp_vrf)
196 {
197 if (direction == BGP_VPN_POLICY_DIR_FROMVPN)
198 vpn_leak_to_vrf_update_all(bgp_vrf, bgp_vpn, afi);
199 if (direction == BGP_VPN_POLICY_DIR_TOVPN) {
200
201 if (bgp_vrf->vpn_policy[afi].tovpn_label !=
202 bgp_vrf->vpn_policy[afi]
203 .tovpn_zebra_vrf_label_last_sent) {
204 vpn_leak_zebra_vrf_label_update(bgp_vrf, afi);
205 }
206
207 vpn_leak_from_vrf_update_all(bgp_vpn, bgp_vrf, afi);
208 }
209 }
210
211 extern void vpn_policy_routemap_event(const char *rmap_name);
212
213 extern vrf_id_t get_first_vrf_for_redirect_with_rt(struct ecommunity *eckey);
214
215 #endif /* _QUAGGA_BGP_MPLSVPN_H */