@@ -134,7 +134,7 @@ func (h *HostEndpoint) handleTunnelChange(swIfIndex uint32, isAdd bool, pending
134
134
return err
135
135
}
136
136
137
- func (h * HostEndpoint ) getHostPolicies (state * PolicyState , tiers []Tier ) (conf * types.InterfaceConfig , err error ) {
137
+ func (h * HostEndpoint ) getUserDefinedPolicies (state * PolicyState , tiers []Tier ) (conf * types.InterfaceConfig , err error ) {
138
138
conf = types .NewInterfaceConfig ()
139
139
for _ , tier := range tiers {
140
140
for _ , polName := range tier .IngressPolicies {
@@ -172,31 +172,46 @@ func (h *HostEndpoint) getHostPolicies(state *PolicyState, tiers []Tier) (conf *
172
172
}
173
173
174
174
func (h * HostEndpoint ) getTapPolicies (state * PolicyState ) (conf * types.InterfaceConfig , err error ) {
175
- conf , err = h .getHostPolicies (state , h .Tiers )
175
+ conf , err = h .getUserDefinedPolicies (state , h .Tiers )
176
176
if err != nil {
177
177
return nil , errors .Wrap (err , "cannot create host policies for TapConf" )
178
178
}
179
- if len (conf .IngressPolicyIDs ) > 0 {
180
- conf .IngressPolicyIDs = append (conf .IngressPolicyIDs , h .server .workloadsToHostPolicy .VppID )
179
+ if len (conf .IngressPolicyIDs ) == 0 && len (conf .ProfileIDs ) == 0 {
180
+ // If a host endpoint is created and network policy is not in place,
181
+ // the Calico default is to deny traffic to/from that endpoint
182
+ // (except for traffic allowed by failsafe rules).
183
+ conf .IngressPolicyIDs = []uint32 {h .server .workloadsToHostPolicy .VppID , h .server .failSafePolicy .VppID , h .server .denyAllPolicy .VppID }
184
+ } else {
185
+ if len (conf .IngressPolicyIDs ) > 0 {
186
+ conf .UserDefinedTx = 1
187
+ }
181
188
conf .IngressPolicyIDs = append ([]uint32 {h .server .failSafePolicy .VppID }, conf .IngressPolicyIDs ... )
189
+ conf .IngressPolicyIDs = append ([]uint32 {h .server .workloadsToHostPolicy .VppID }, conf .IngressPolicyIDs ... )
182
190
}
183
- if len (conf .EgressPolicyIDs ) > 0 {
184
- conf .EgressPolicyIDs = append ([]uint32 {h .server .AllowFromHostPolicy .VppID }, conf .EgressPolicyIDs ... )
191
+ if len (conf .EgressPolicyIDs ) == 0 && len (conf .ProfileIDs ) == 0 {
192
+ conf .EgressPolicyIDs = []uint32 {h .server .AllowFromHostPolicy .VppID , h .server .failSafePolicy .VppID , h .server .denyAllPolicy .VppID }
193
+ } else {
194
+ if len (conf .EgressPolicyIDs ) > 0 {
195
+ conf .UserDefinedRx = 1
196
+ }
185
197
conf .EgressPolicyIDs = append ([]uint32 {h .server .failSafePolicy .VppID }, conf .EgressPolicyIDs ... )
198
+ conf .EgressPolicyIDs = append ([]uint32 {h .server .AllowFromHostPolicy .VppID }, conf .EgressPolicyIDs ... )
186
199
}
187
200
return conf , nil
188
201
}
189
202
190
203
func (h * HostEndpoint ) getForwardPolicies (state * PolicyState ) (conf * types.InterfaceConfig , err error ) {
191
- conf , err = h .getHostPolicies (state , h .ForwardTiers )
204
+ conf , err = h .getUserDefinedPolicies (state , h .ForwardTiers )
192
205
if err != nil {
193
206
return nil , errors .Wrap (err , "cannot create host policies for forwardConf" )
194
207
}
195
208
if len (conf .EgressPolicyIDs ) > 0 {
196
209
conf .EgressPolicyIDs = append ([]uint32 {h .server .allowToHostPolicy .VppID }, conf .EgressPolicyIDs ... )
210
+ conf .UserDefinedRx = 1
197
211
}
198
212
if len (conf .IngressPolicyIDs ) > 0 {
199
213
conf .IngressPolicyIDs = append ([]uint32 {h .server .allowToHostPolicy .VppID }, conf .IngressPolicyIDs ... )
214
+ conf .UserDefinedTx = 1
200
215
}
201
216
return conf , nil
202
217
}
0 commit comments