Skip to content

Commit

Permalink
Merge pull request #8259 from tomastigera/tomas-bpf-internal-traffic-…
Browse files Browse the repository at this point in the history
…policy-fix

[BPF] ClusterIP should reflect InternalTrafficPolicy=Local
  • Loading branch information
tomastigera authored Nov 23, 2023
2 parents 6f713d2 + ad65c95 commit 408246a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion felix/bpf/nat/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,16 @@ func (v FrontendValue) FlagsAsString() string {
flg := uint32(1 << i)
if flgs&flg != 0 {
fstr += flgTostr[int(flg)]
fstr += ", "
}
flgs &= ^flg
if flgs == 0 {
break
}
fstr += ", "
}

if fstr != "" {
return fstr[:len(fstr)-2]
}

return fstr
Expand Down
7 changes: 6 additions & 1 deletion felix/bpf/proxy/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,12 @@ func (s *Syncer) updateService(skey svcKey, sinfo k8sp.ServicePort, id uint32, e
cnt++
}

if err := s.writeSvc(sinfo, id, cnt, local, 0); err != nil {
flags := uint32(0)
if sinfo.InternalPolicyLocal() {
flags |= nat.NATFlgInternalLocal
}

if err := s.writeSvc(sinfo, id, cnt, local, flags); err != nil {
return 0, 0, err
}

Expand Down
2 changes: 2 additions & 0 deletions felix/bpf/proxy/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ var _ = Describe("BPF Syncer", func() {
Expect(ok).To(BeTrue())
Expect(val1.Count()).To(Equal(uint32(4)))
Expect(val1.LocalCount()).To(Equal(uint32(2)))
// ClusterIP only reflects internal traffic policy, not the external one
Expect(val1.Flags()).To(Equal(uint32(nat.NATFlgInternalLocal)))

val2, ok := svcs.m[nat.NewNATKey(net.IPv4(192, 168, 0, 1), 4444, proxy.ProtoV1ToIntPanic(v1.ProtocolTCP))]
Expect(ok).To(BeTrue())
Expand Down
19 changes: 12 additions & 7 deletions felix/fv/bpf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2837,9 +2837,14 @@ func describeBPFTests(opts ...bpfTestOpt) bool {
clusterIP := testSvc.Spec.ClusterIP
port := uint16(testSvc.Spec.Ports[0].Port)

cc.ExpectSome(w[0][1], TargetIP(clusterIP), port)
cc.ExpectSome(w[1][0], TargetIP(clusterIP), port)
cc.ExpectSome(w[1][1], TargetIP(clusterIP), port)
exp := Some
if intLocal {
exp = None
}

cc.Expect(Some, w[0][1], TargetIP(clusterIP), ExpectWithPorts(port))
cc.Expect(exp, w[1][0], TargetIP(clusterIP), ExpectWithPorts(port))
cc.Expect(exp, w[1][1], TargetIP(clusterIP), ExpectWithPorts(port))
cc.CheckConnectivity()
})

Expand All @@ -2850,12 +2855,12 @@ func describeBPFTests(opts ...bpfTestOpt) bool {
node0IP := felixIP(0)
node1IP := felixIP(1)

// Should work through the nodeport where the pods is
// Should work through the nodeport from a pod on the node where the backend is
cc.ExpectSome(w[0][1], TargetIP(node0IP), npPort)
cc.ExpectSome(w[1][0], TargetIP(node0IP), npPort)
cc.ExpectSome(w[1][1], TargetIP(node0IP), npPort)

// Should not work through the nodeport where the pod isn't
// Should not work through the nodeport from a node where the backend is not.
cc.ExpectNone(w[1][0], TargetIP(node0IP), npPort)
cc.ExpectNone(w[1][1], TargetIP(node0IP), npPort)
cc.ExpectNone(w[0][1], TargetIP(node1IP), npPort)
cc.ExpectNone(w[1][0], TargetIP(node1IP), npPort)
cc.ExpectNone(w[1][1], TargetIP(node1IP), npPort)
Expand Down

0 comments on commit 408246a

Please sign in to comment.