@@ -7,6 +7,15 @@ ipv6 table bgp6;
7
7
ipv4 table kernel_tun_siit4;
8
8
ipv6 table kernel_tun_siit6;
9
9
10
+ define C_SELF = 65026;
11
+ define C_CTL_PREVENT_KERNEL = 10006;
12
+ define C_CTL_ALLOW_OUTSIDE = 10011;
13
+ define C_CTL_ALLOW_INSIDE = 10012;
14
+
15
+ function filter_bgp_community() {
16
+ bgp_community.delete([(C_SELF, 10000..29999)]);
17
+ }
18
+
10
19
protocol direct {
11
20
ipv4 {
12
21
table bgp4;
@@ -57,8 +66,12 @@ protocol static {
57
66
table static4;
58
67
};
59
68
60
- route <%= node.dig(:plat, :nat64).fetch(:outer_private) %>/32 via "tun-siit";
61
- route <%= node.dig(:plat, :nat64).fetch(:outer_public) %>/32 via "tun-siit";
69
+ route <%= node.dig(:plat, :nat64).fetch(:outer_private) %>/32 via "tun-siit" {
70
+ bgp_community.add((C_SELF,C_CTL_ALLOW_OUTSIDE));
71
+ };
72
+ route <%= node.dig(:plat, :nat64).fetch(:outer_public) %>/32 via "tun-siit" {
73
+ bgp_community.add((C_SELF,C_CTL_ALLOW_OUTSIDE));
74
+ };
62
75
}
63
76
# protocol static static_bgp4 {
64
77
# ipv4 {
@@ -91,10 +104,12 @@ protocol static static_bgp6 {
91
104
igp table bgp6;
92
105
# Prevent propagation to always have blackhole route for pref64n and related prefixes in kernel tun-siit table
93
106
route 2001:df0:8500:ca6d::/64 recursive 192.0.0.0 {
94
- bgp_community.add((65026,6));
107
+ bgp_community.add((C_SELF,C_CTL_ALLOW_INSIDE));
108
+ bgp_community.add((C_SELF,C_CTL_PREVENT_KERNEL));
95
109
};
96
110
route 2001:df0:8500:ca64::/64 recursive 192.0.0.0 {
97
- bgp_community.add((65026,6));
111
+ bgp_community.add((C_SELF,C_CTL_ALLOW_INSIDE));
112
+ bgp_community.add((C_SELF,C_CTL_PREVENT_KERNEL));
98
113
};
99
114
}
100
115
# protocol pipe static2bgp6 {
@@ -106,7 +121,7 @@ protocol static static_bgp6 {
106
121
107
122
108
123
filter prevent_kernel_installation {
109
- if (defined(bgp_community)) then if ((65026,6 ) ~ bgp_community) then reject;
124
+ if (defined(bgp_community)) then if ((C_SELF,C_CTL_PREVENT_KERNEL ) ~ bgp_community) then reject;
110
125
accept;
111
126
}
112
127
@@ -143,20 +158,26 @@ protocol bgp bgp_outside {
143
158
144
159
ipv4 {
145
160
table bgp4;
146
- import all;
161
+ import filter {
162
+ filter_bgp_community();
163
+ accept;
164
+ };
147
165
export filter {
148
166
if dest = RTD_UNREACHABLE then reject; # static recursive route can be RTD_UNREACHABLE when unresolvable
167
+ if (defined(bgp_community)) then if ((C_SELF,C_CTL_ALLOW_OUTSIDE) ~ bgp_community) then accept;
149
168
if proto = "direct1" then accept;
150
- if net = <%= node.dig(:plat, :nat64).fetch(:outer_public) %>/32 then accept;
151
- if net = <%= node.dig(:plat, :nat64).fetch(:outer_private) %>/32 then accept;
152
169
reject;
153
170
};
154
171
};
155
172
ipv6 {
156
173
table bgp6;
157
- import all;
174
+ import filter {
175
+ filter_bgp_community();
176
+ accept;
177
+ };
158
178
export filter {
159
179
if dest = RTD_UNREACHABLE then reject; # static recursive route can be RTD_UNREACHABLE when unresolvable
180
+ if (defined(bgp_community)) then if ((C_SELF,C_CTL_ALLOW_OUTSIDE) ~ bgp_community) then accept;
160
181
if proto = "direct1" then accept;
161
182
reject;
162
183
};
@@ -172,30 +193,28 @@ protocol bgp bgp_inside {
172
193
ipv4 {
173
194
table bgp4;
174
195
import filter {
196
+ filter_bgp_community();
175
197
if bgp_path ~ [= * <%= inside.fetch(:peer_as) %> =] then accept; # accept only direct path
176
198
reject;
177
199
};
178
200
export filter {
179
201
if dest = RTD_UNREACHABLE then reject; # static recursive route can be RTD_UNREACHABLE when unresolvable
202
+ if (defined(bgp_community)) then if ((C_SELF,C_CTL_ALLOW_INSIDE) ~ bgp_community) then accept;
180
203
if proto = "direct1" then accept;
181
- if net !~ [10.33.0.0/16+] then reject;
182
- if proto = "static1" then accept;
183
- if proto = "static_bgp4" then accept;
184
204
reject;
185
205
};
186
206
};
187
207
ipv6 {
188
208
table bgp6;
189
209
import filter {
210
+ filter_bgp_community();
190
211
if bgp_path ~ [= * <%= inside.fetch(:peer_as) %> =] then accept; # accept only direct path
191
212
reject;
192
213
};
193
214
export filter {
194
215
if dest = RTD_UNREACHABLE then reject; # static recursive route can be RTD_UNREACHABLE when unresolvable
216
+ if (defined(bgp_community)) then if ((C_SELF,C_CTL_ALLOW_INSIDE) ~ bgp_community) then accept;
195
217
if proto = "direct1" then accept;
196
- if net !~ [2001:df0:8500:ca00::/56{56,64}] then reject;
197
- if proto = "static1" then accept;
198
- if proto = "static_bgp6" then accept;
199
218
};
200
219
};
201
220
}
0 commit comments