]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* MPLS-VPN |
896014f4 DL |
2 | * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org> |
3 | * | |
8557760c | 4 | * This file is part of GxNU Zebra. |
896014f4 DL |
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 | */ | |
718e3744 | 20 | |
00d252cb | 21 | #ifndef _QUAGGA_BGP_MPLSVPN_H |
22 | #define _QUAGGA_BGP_MPLSVPN_H | |
23 | ||
4f280b15 | 24 | #include "bgpd/bgp_route.h" |
8557760c | 25 | #include "bgpd/bgp_rd.h" |
ddb5b488 | 26 | #include "bgpd/bgp_zebra.h" |
718e3744 | 27 | |
d62a17ae | 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) | |
65efcfce | 33 | |
d62a17ae | 34 | #define BGP_VPNVX_HELP_STR \ |
35 | "Address Family\n" \ | |
36 | "Address Family\n" | |
d6902373 | 37 | |
d62a17ae | 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" | |
96ade3ed | 43 | |
d62a17ae | 44 | extern void bgp_mplsvpn_init(void); |
45 | extern int bgp_nlri_parse_vpn(struct peer *, struct attr *, struct bgp_nlri *); | |
d7c0a89a | 46 | extern uint32_t decode_label(mpls_label_t *); |
9bedbb1e | 47 | extern void encode_label(mpls_label_t, mpls_label_t *); |
00d252cb | 48 | |
d62a17ae | 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, | |
d7c0a89a | 53 | int tags, uint8_t use_json); |
d6902373 | 54 | |
ddb5b488 PZ |
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); | |
e70e9f8e | 80 | extern int vpn_leak_label_callback(mpls_label_t label, void *lblid, bool alloc); |
ddb5b488 PZ |
81 | |
82 | static inline int vpn_leak_to_vpn_active(struct bgp *bgp_vrf, afi_t afi, | |
83 | const char **pmsg) | |
84 | { | |
d555f3e9 PZ |
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 | ||
ddb5b488 PZ |
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 | if (pmsg) | |
97 | *pmsg = "export not set"; | |
98 | return 0; | |
99 | } | |
100 | ||
101 | /* Is there an RT list set? */ | |
102 | if (!bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) { | |
103 | if (pmsg) | |
104 | *pmsg = "rtlist tovpn not defined"; | |
105 | return 0; | |
106 | } | |
107 | ||
108 | /* Is there an RD set? */ | |
109 | if (!CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags, | |
110 | BGP_VPN_POLICY_TOVPN_RD_SET)) { | |
111 | if (pmsg) | |
112 | *pmsg = "rd not defined"; | |
113 | return 0; | |
114 | } | |
e70e9f8e PZ |
115 | |
116 | /* Is there an "auto" export label that isn't allocated yet? */ | |
117 | if (CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags, | |
118 | BGP_VPN_POLICY_TOVPN_LABEL_AUTO) && | |
119 | (bgp_vrf->vpn_policy[afi].tovpn_label == MPLS_LABEL_NONE)) { | |
120 | ||
121 | if (pmsg) | |
122 | *pmsg = "auto label not allocated"; | |
123 | return 0; | |
124 | } | |
125 | ||
ddb5b488 PZ |
126 | return 1; |
127 | } | |
128 | ||
129 | static inline int vpn_leak_from_vpn_active(struct bgp *bgp_vrf, afi_t afi, | |
b9c7bc5a | 130 | const char **pmsg) |
ddb5b488 | 131 | { |
ddb5b488 | 132 | if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF |
d555f3e9 | 133 | && bgp_vrf->inst_type != BGP_INSTANCE_TYPE_DEFAULT) { |
ddb5b488 PZ |
134 | |
135 | if (pmsg) | |
136 | *pmsg = "destination bgp instance neither vrf nor default"; | |
137 | return 0; | |
138 | } | |
139 | ||
b9c7bc5a PZ |
140 | /* Is vrf configured to import from vpn? */ |
141 | if (!CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST], | |
142 | BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) { | |
ddb5b488 | 143 | if (pmsg) |
b9c7bc5a | 144 | *pmsg = "import not set"; |
ddb5b488 PZ |
145 | return 0; |
146 | } | |
147 | if (!bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) { | |
148 | if (pmsg) | |
149 | *pmsg = "rtlist fromvpn not defined"; | |
150 | return 0; | |
151 | } | |
152 | return 1; | |
153 | } | |
154 | ||
155 | static inline void vpn_leak_prechange(vpn_policy_direction_t direction, | |
156 | afi_t afi, struct bgp *bgp_vpn, | |
157 | struct bgp *bgp_vrf) | |
158 | { | |
d555f3e9 PZ |
159 | if ((direction == BGP_VPN_POLICY_DIR_FROMVPN) && |
160 | vpn_leak_from_vpn_active(bgp_vrf, afi, NULL)) { | |
161 | ||
ddb5b488 | 162 | vpn_leak_to_vrf_withdraw_all(bgp_vrf, afi); |
d555f3e9 PZ |
163 | } |
164 | if ((direction == BGP_VPN_POLICY_DIR_TOVPN) && | |
165 | vpn_leak_to_vpn_active(bgp_vrf, afi, NULL)) { | |
166 | ||
ddb5b488 | 167 | vpn_leak_from_vrf_withdraw_all(bgp_vpn, bgp_vrf, afi); |
d555f3e9 | 168 | } |
ddb5b488 PZ |
169 | } |
170 | ||
171 | static inline void vpn_leak_postchange(vpn_policy_direction_t direction, | |
172 | afi_t afi, struct bgp *bgp_vpn, | |
173 | struct bgp *bgp_vrf) | |
174 | { | |
175 | if (direction == BGP_VPN_POLICY_DIR_FROMVPN) | |
176 | vpn_leak_to_vrf_update_all(bgp_vrf, bgp_vpn, afi); | |
177 | if (direction == BGP_VPN_POLICY_DIR_TOVPN) { | |
178 | ||
d555f3e9 PZ |
179 | if (bgp_vrf->vpn_policy[afi].tovpn_label != |
180 | bgp_vrf->vpn_policy[afi] | |
ddb5b488 PZ |
181 | .tovpn_zebra_vrf_label_last_sent) { |
182 | vpn_leak_zebra_vrf_label_update(bgp_vrf, afi); | |
183 | } | |
184 | ||
185 | vpn_leak_from_vrf_update_all(bgp_vpn, bgp_vrf, afi); | |
186 | } | |
ddb5b488 PZ |
187 | } |
188 | ||
189 | extern void vpn_policy_routemap_event(const char *rmap_name); | |
190 | ||
301ad80a PG |
191 | extern vrf_id_t get_first_vrf_for_redirect_with_rt(struct ecommunity *eckey); |
192 | ||
00d252cb | 193 | #endif /* _QUAGGA_BGP_MPLSVPN_H */ |