Skip to content

Commit f33df6b

Browse files
committed
fix: fix reverse routing for KubeSpan
This allows it to not come down when rp_filter is enabled. Fixes #9814 Signed-off-by: Dmitry Sharshakov <[email protected]>
1 parent 650eb3a commit f33df6b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

internal/app/machined/pkg/controllers/kubespan/manager.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
378378
},
379379
Verdict: pointer.To(nethelpers.VerdictAccept),
380380
},
381+
// Mark packets to be sent over the KubeSpan link.
381382
{
382383
MatchDestinationAddress: &network.NfTablesAddressMatch{
383384
IncludeSubnets: allowedIPsSet.Prefixes(),
@@ -388,6 +389,18 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
388389
},
389390
Verdict: pointer.To(nethelpers.VerdictAccept),
390391
},
392+
// Mark incoming packets from the KubeSpan link for rp_filter to find the correct routing table.
393+
{
394+
MatchIIfName: &network.NfTablesIfNameMatch{
395+
InterfaceNames: []string{constants.KubeSpanLinkName},
396+
Operator: nethelpers.OperatorEqual,
397+
},
398+
SetMark: &network.NfTablesMark{
399+
Mask: ^uint32(constants.KubeSpanDefaultFirewallMask),
400+
Xor: constants.KubeSpanDefaultForceFirewallMark,
401+
},
402+
Verdict: pointer.To(nethelpers.VerdictAccept),
403+
},
391404
}
392405

393406
return nil

internal/app/machined/pkg/controllers/kubespan/manager_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ func (suite *ManagerSuite) TestReconcile() {
244244
asrt.Equal(nethelpers.ChainPriorityFilter, spec.Priority)
245245
asrt.Equal(nethelpers.VerdictAccept, spec.Policy)
246246

247-
asrt.Len(spec.Rules, 2)
247+
asrt.Len(spec.Rules, 3)
248248

249-
if len(spec.Rules) != 2 {
249+
if len(spec.Rules) != 3 {
250250
return
251251
}
252252

@@ -277,6 +277,21 @@ func (suite *ManagerSuite) TestReconcile() {
277277
},
278278
spec.Rules[1],
279279
)
280+
281+
asrt.Equal(
282+
network.NfTablesRule{
283+
MatchIIfName: &network.NfTablesIfNameMatch{
284+
InterfaceNames: []string{constants.KubeSpanLinkName},
285+
Operator: nethelpers.OperatorEqual,
286+
},
287+
SetMark: &network.NfTablesMark{
288+
Mask: ^uint32(constants.KubeSpanDefaultFirewallMask),
289+
Xor: constants.KubeSpanDefaultForceFirewallMark,
290+
},
291+
Verdict: pointer.To(nethelpers.VerdictAccept),
292+
},
293+
spec.Rules[2],
294+
)
280295
},
281296
)
282297

internal/app/machined/pkg/controllers/runtime/kernel_param_defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func (ctrl *KernelParamDefaultsController) getKernelParams() []*kernel.Param {
120120
Key: "proc.sys.net.ipv4.tcp_keepalive_intvl",
121121
Value: "60",
122122
},
123+
// Consider fwmark for rp_filter routing table lookup.
124+
{
125+
Key: "proc.sys.net.ipv4.conf.kubespan.src_valid_mark",
126+
Value: "1",
127+
},
123128
{
124129
Key: "proc.sys.kernel.panic",
125130
Value: "10",

0 commit comments

Comments
 (0)