Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.10 backports 2021-06-22 #16614

Merged
merged 14 commits into from Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/check-crd-compat-table.sh
Expand Up @@ -15,7 +15,7 @@ export LC_ALL=C

get_schema_of_tag(){
tag="${1}"
git grep -o 'CustomResourceDefinitionSchemaVersion =.*' ${tag} -- pkg/k8s | sed 's/.*=\ "//;s/"//'
git grep -o 'CustomResourceDefinitionSchemaVersion =.*' ${tag} -- pkg/k8s | head -n1 | sed 's/.*=\ "//;s/"//'
}

get_line_of_schema_version(){
Expand Down
2 changes: 1 addition & 1 deletion Documentation/gettingstarted/bgp.rst
Expand Up @@ -95,7 +95,7 @@ backends:
apiVersion: apps/v1
kind: Deployment
metadata:
app: nginx
name: nginx
spec:
selector:
matchLabels:
Expand Down
10 changes: 6 additions & 4 deletions bpf/lib/nat.h
Expand Up @@ -324,9 +324,9 @@ static __always_inline int snat_v4_rewrite_egress(struct __ctx_buff *ctx,
struct ipv4_nat_entry *state,
__u32 off, bool has_l4_header)
{
int ret, flags = BPF_F_PSEUDO_HDR;
struct csum_offset csum = {};
__be32 sum_l4 = 0, sum;
int ret;

if (state->to_saddr == tuple->saddr &&
state->to_sport == tuple->sport)
Expand Down Expand Up @@ -356,6 +356,7 @@ static __always_inline int snat_v4_rewrite_egress(struct __ctx_buff *ctx,
return DROP_WRITE_ERROR;
from = tuple->sport;
to = state->to_sport;
flags = 0; /* ICMPv4 has no pseudo-header */
sum_l4 = csum_diff(&from, 4, &to, 4, 0);
csum.offset = offsetof(struct icmphdr, checksum);
break;
Expand All @@ -371,7 +372,7 @@ static __always_inline int snat_v4_rewrite_egress(struct __ctx_buff *ctx,
if (tuple->nexthdr == IPPROTO_ICMP)
sum = sum_l4;
if (csum.offset &&
csum_l4_replace(ctx, off, &csum, 0, sum, BPF_F_PSEUDO_HDR) < 0)
csum_l4_replace(ctx, off, &csum, 0, sum, flags) < 0)
return DROP_CSUM_L4;
return 0;
}
Expand All @@ -381,9 +382,9 @@ static __always_inline int snat_v4_rewrite_ingress(struct __ctx_buff *ctx,
struct ipv4_nat_entry *state,
__u32 off)
{
int ret, flags = BPF_F_PSEUDO_HDR;
struct csum_offset csum = {};
__be32 sum_l4 = 0, sum;
int ret;

if (state->to_daddr == tuple->daddr &&
state->to_dport == tuple->dport)
Expand Down Expand Up @@ -411,6 +412,7 @@ static __always_inline int snat_v4_rewrite_ingress(struct __ctx_buff *ctx,
return DROP_WRITE_ERROR;
from = tuple->dport;
to = state->to_dport;
flags = 0; /* ICMPv4 has no pseudo-header */
sum_l4 = csum_diff(&from, 4, &to, 4, 0);
csum.offset = offsetof(struct icmphdr, checksum);
break;
Expand All @@ -425,7 +427,7 @@ static __always_inline int snat_v4_rewrite_ingress(struct __ctx_buff *ctx,
if (tuple->nexthdr == IPPROTO_ICMP)
sum = sum_l4;
if (csum.offset &&
csum_l4_replace(ctx, off, &csum, 0, sum, BPF_F_PSEUDO_HDR) < 0)
csum_l4_replace(ctx, off, &csum, 0, sum, flags) < 0)
return DROP_CSUM_L4;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -114,7 +114,7 @@ replace (
github.com/miekg/dns => github.com/cilium/dns v1.1.4-0.20190417235132-8e25ec9a0ff3
github.com/optiopay/kafka => github.com/cilium/kafka v0.0.0-20180809090225-01ce283b732b

go.universe.tf/metallb => github.com/cilium/metallb v0.1.1-0.20210520171949-40d425d20241
go.universe.tf/metallb => github.com/cilium/metallb v0.1.1-0.20210607221240-b4c60b959dd7

// Using private fork of controller-tools. See commit msg for more context
// as to why we are using a private fork.
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -37,4 +37,5 @@ rules:
- hubble-ca-secret
verbs:
- get
- update
{{- end }}
9 changes: 6 additions & 3 deletions pkg/datapath/linux/ipsec/ipsec_linux.go
Expand Up @@ -486,9 +486,7 @@ func LoadIPSecKeysFile(path string) (int, uint8, error) {
func loadIPSecKeys(r io.Reader) (int, uint8, error) {
var spi uint8
var keyLen int
scopedLog := log.WithFields(logrus.Fields{
"spi": spi,
})
scopedLog := log

if err := encrypt.MapCreate(); err != nil {
return 0, 0, fmt.Errorf("Encrypt map create failed: %v", err)
Expand Down Expand Up @@ -581,6 +579,11 @@ func loadIPSecKeys(r io.Reader) (int, uint8, error) {
ipSecKeysGlobal[""] = ipSecKey
}

scopedLog := log.WithFields(logrus.Fields{
"oldSPI": oldSpi,
"SPI": spi,
})

// Detect a version change and call cleanup routine to remove old
// keys after a timeout period. We also want to ensure on restart
// we remove any stale keys for example when a restart changes keys.
Expand Down
2 changes: 1 addition & 1 deletion pkg/datapath/linux/node.go
Expand Up @@ -788,7 +788,7 @@ func (n *linuxNodeHandler) insertNeighbor(ctx context.Context, newNode *nodeType
// issued arping after us, as it might have a more recent hwAddr value.
return
}
n.neighLastPingByNextHop[nextHopStr] = time.Now()
n.neighLastPingByNextHop[nextHopStr] = now
if prevHwAddr, found := n.neighByNextHop[nextHopStr]; found && prevHwAddr.String() == hwAddr.String() {
// Nothing to update, return early to avoid calling to netlink. This
// is based on the assumption that n.neighByNextHop gets populated
Expand Down
31 changes: 18 additions & 13 deletions pkg/datapath/linux/node_linux_test.go
Expand Up @@ -1188,23 +1188,28 @@ func (s *linuxPrivilegedIPv4OnlyTestSuite) TestArpPingHandling(c *check.C) {
c.Assert(err, check.IsNil)
return nil
})

// Check that MAC has been changed in the neigh table
time.Sleep(500 * time.Millisecond)
neighs, err = netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4)
c.Assert(err, check.IsNil)
found = false
for _, n := range neighs {
if n.IP.Equal(ip1) && n.State == netlink.NUD_PERMANENT {
c.Assert(n.HardwareAddr.String(), check.Equals, mac.String())
c.Assert(neighHwAddr(ip1.String()), check.Equals, mac.String())
c.Assert(neighRefCount(ip1.String()), check.Equals, 1)
found = true
break
var found bool
err := testutils.WaitUntilWithSleep(func() bool {
neighs, err = netlink.NeighList(veth0.Attrs().Index, netlink.FAMILY_V4)
c.Assert(err, check.IsNil)
found = false
for _, n := range neighs {
if n.IP.Equal(ip1) && n.State == netlink.NUD_PERMANENT &&
n.HardwareAddr.String() == mac.String() &&
neighHwAddr(ip1.String()) == mac.String() &&
neighRefCount(ip1.String()) == 1 {
found = true
return true
}
}
}
return false
}, 5*time.Second, 200*time.Millisecond)
c.Assert(err, check.IsNil)
c.Assert(found, check.Equals, true)

}

// Cleanup
close(done)
wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/watchers/pod.go
Expand Up @@ -209,7 +209,7 @@ func (k *K8sWatcher) addK8sPodV1(pod *slim_corev1.Pod) error {
logfields.K8sNamespace: pod.ObjectMeta.Namespace,
"podIP": pod.Status.PodIP,
"podIPs": pod.Status.PodIPs,
"hostIP": pod.Status.PodIP,
"hostIP": pod.Status.HostIP,
})

// In Kubernetes Jobs, Pods can be left in Kubernetes until the Job
Expand Down
2 changes: 1 addition & 1 deletion pkg/option/config.go
Expand Up @@ -2002,7 +2002,7 @@ var (
AutoCreateCiliumNodeResource: defaults.AutoCreateCiliumNodeResource,
IdentityAllocationMode: IdentityAllocationModeKVstore,
AllowICMPFragNeeded: defaults.AllowICMPFragNeeded,
EnableWellKnownIdentities: defaults.EnableEndpointRoutes,
EnableWellKnownIdentities: defaults.EnableWellKnownIdentities,
K8sEnableK8sEndpointSlice: defaults.K8sEnableEndpointSlice,
k8sEnableAPIDiscovery: defaults.K8sEnableAPIDiscovery,
AllocatorListTimeout: defaults.AllocatorListTimeout,
Expand Down
6 changes: 3 additions & 3 deletions pkg/policy/l4.go
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/cilium/cilium/pkg/policy/api"
"github.com/cilium/cilium/pkg/policy/trafficdirection"
"github.com/cilium/cilium/pkg/u8proto"
"github.com/cilium/proxy/go/cilium/api"
cilium "github.com/cilium/proxy/go/cilium/api"

"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -426,8 +426,8 @@ func (l4Filter *L4Filter) ToMapState(policyOwner PolicyOwner, direction trafficd
}

// IdentitySelectionUpdated implements CachedSelectionUser interface
// This call is made while holding name manager and selector cache
// locks, must beware of deadlocking!
// This call is made from a single goroutine in FIFO order to keep add
// and delete events ordered properly. No locks are held.
//
// The caller is responsible for making sure the same identity is not
// present in both 'added' and 'deleted'.
Expand Down
5 changes: 5 additions & 0 deletions pkg/policy/resolve_deny_test.go
Expand Up @@ -17,6 +17,8 @@
package policy

import (
"time"

"github.com/cilium/cilium/pkg/checker"
"github.com/cilium/cilium/pkg/identity"
"github.com/cilium/cilium/pkg/identity/cache"
Expand Down Expand Up @@ -356,6 +358,7 @@ func (ds *PolicyTestSuite) TestMapStateWithIngressDenyWildcard(c *C) {
identity.NumericIdentity(192): labels.ParseSelectLabelArray("id=resolve_test_1"),
}
testSelectorCache.UpdateIdentities(added1, nil)
time.Sleep(100 * time.Millisecond)
c.Assert(policy.policyMapChanges.changes, HasLen, 0)

// Have to remove circular reference before testing to avoid an infinite loop
Expand Down Expand Up @@ -433,12 +436,14 @@ func (ds *PolicyTestSuite) TestMapStateWithIngressDeny(c *C) {
testSelectorCache.UpdateIdentities(added1, nil)
// Cleanup the identities from the testSelectorCache
defer testSelectorCache.UpdateIdentities(nil, added1)
time.Sleep(100 * time.Millisecond)
c.Assert(policy.policyMapChanges.changes, HasLen, 3)

deleted1 := cache.IdentityCache{
identity.NumericIdentity(193): labels.ParseSelectLabelArray("id=resolve_test_1", "num=2"),
}
testSelectorCache.UpdateIdentities(nil, deleted1)
time.Sleep(100 * time.Millisecond)
c.Assert(policy.policyMapChanges.changes, HasLen, 4)

cachedSelectorWorld := testSelectorCache.FindCachedIdentitySelector(api.ReservedEndpointSelectors[labels.IDNameWorld])
Expand Down
4 changes: 4 additions & 0 deletions pkg/policy/resolve_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"sync"
"testing"
"time"

"github.com/cilium/cilium/pkg/checker"
"github.com/cilium/cilium/pkg/identity"
Expand Down Expand Up @@ -519,6 +520,7 @@ func (ds *PolicyTestSuite) TestMapStateWithIngressWildcard(c *C) {
identity.NumericIdentity(192): labels.ParseSelectLabelArray("id=resolve_test_1"),
}
testSelectorCache.UpdateIdentities(added1, nil)
time.Sleep(100 * time.Millisecond)
c.Assert(policy.policyMapChanges.changes, HasLen, 0)

// Have to remove circular reference before testing to avoid an infinite loop
Expand Down Expand Up @@ -598,12 +600,14 @@ func (ds *PolicyTestSuite) TestMapStateWithIngress(c *C) {
testSelectorCache.UpdateIdentities(added1, nil)
// Cleanup the identities from the testSelectorCache
defer testSelectorCache.UpdateIdentities(nil, added1)
time.Sleep(100 * time.Millisecond)
c.Assert(policy.policyMapChanges.changes, HasLen, 3)

deleted1 := cache.IdentityCache{
identity.NumericIdentity(193): labels.ParseSelectLabelArray("id=resolve_test_1", "num=2"),
}
testSelectorCache.UpdateIdentities(nil, deleted1)
time.Sleep(100 * time.Millisecond)
c.Assert(policy.policyMapChanges.changes, HasLen, 4)

cachedSelectorWorld := testSelectorCache.FindCachedIdentitySelector(api.ReservedEndpointSelectors[labels.IDNameWorld])
Expand Down