Skip to content

Commit

Permalink
Merge pull request networkservicemesh#439 from NikitaSkrynnik/issue-438
Browse files Browse the repository at this point in the history
Fix golangci-lint job
  • Loading branch information
denis-tingaikin authored Apr 1, 2022
2 parents a7872b5 + c227cb2 commit e777a2b
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 65 deletions.
5 changes: 4 additions & 1 deletion pkg/kernel/const_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -14,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package kernel
Expand Down
7 changes: 5 additions & 2 deletions pkg/kernel/link.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2020-2021 Intel Corporation. All Rights Reserved.
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2020-2022 Intel Corporation. All Rights Reserved.
//
// Copyright (c) 2021-2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -16,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package kernel contains Link representation of network interface
Expand Down
5 changes: 3 additions & 2 deletions pkg/kernel/networkservice/connectioncontextkernel/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package connectioncontextkernel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ipaddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,49 +114,67 @@ func create(ctx context.Context, conn *networkservice.Connection, isClient bool)
}

// Remove no longer existing IPs
for _, ipNet := range toRemove {
now := time.Now()
addr := &netlink.Addr{
IPNet: ipNet,
}
if err := netlinkHandle.AddrDel(l, addr); err != nil {
return errors.Wrapf(err, "attempting to delete ip address %s to %s", addr.IPNet, l.Attrs().Name)
}
log.FromContext(ctx).
WithField("link.Name", l.Attrs().Name).
WithField("Addr", ipNet.String()).
WithField("duration", time.Since(now)).
WithField("netlink", "AddrDel").Debug("completed")

if err := removeOldIPAddrs(ctx, netlinkHandle, l, toRemove); err != nil {
return err
}

// Add new IP addresses
for _, ipNet := range toAdd {
now := time.Now()
addr := &netlink.Addr{
IPNet: ipNet,
Flags: unix.IFA_F_PERMANENT,
}
// Turns out IPv6 uses Duplicate Address Detection (DAD) which
// we don't need here and which can cause it to take more than a second
// before anything *works* (even though the interface is up). This causes
// cryptic error messages. To avoid, we use the flag to disable DAD for
// any IPv6 addresses. Further, it seems that this is only needed for veth type, not if we have a tapv2
if ipNet != nil && ipNet.IP.To4() == nil {
addr.Flags |= unix.IFA_F_NODAD
}
if err := netlinkHandle.AddrReplace(l, addr); err != nil {
return errors.Wrapf(err, "attempting to add ip address %s to %s (type: %s) with flags 0x%x", addr.IPNet, l.Attrs().Name, l.Type(), addr.Flags)
}
log.FromContext(ctx).
WithField("link.Name", l.Attrs().Name).
WithField("Addr", ipNet.String()).
WithField("duration", time.Since(now)).
WithField("netlink", "AddrAdd").Debug("completed")
if err := addNewIPAddrs(ctx, netlinkHandle, l, toAdd); err != nil {
return err
}
return waitForIPNets(ctx, ch, l, toAdd)
}
return nil
}

func removeOldIPAddrs(ctx context.Context, netlinkHandle *netlink.Handle, l netlink.Link, ipAddrs []*net.IPNet) error {
for _, ipNet := range ipAddrs {
now := time.Now()
addr := &netlink.Addr{
IPNet: ipNet,
}
if err := netlinkHandle.AddrDel(l, addr); err != nil {
return errors.Wrapf(err, "attempting to delete ip address %s to %s", addr.IPNet, l.Attrs().Name)
}
log.FromContext(ctx).
WithField("link.Name", l.Attrs().Name).
WithField("Addr", ipNet.String()).
WithField("duration", time.Since(now)).
WithField("netlink", "AddrDel").Debug("completed")
}

return nil
}

func addNewIPAddrs(ctx context.Context, netlinkHandle *netlink.Handle, l netlink.Link, ipAddrs []*net.IPNet) error {
for _, ipNet := range ipAddrs {
now := time.Now()
addr := &netlink.Addr{
IPNet: ipNet,
Flags: unix.IFA_F_PERMANENT,
}
// Turns out IPv6 uses Duplicate Address Detection (DAD) which
// we don't need here and which can cause it to take more than a second
// before anything *works* (even though the interface is up). This causes
// cryptic error messages. To avoid, we use the flag to disable DAD for
// any IPv6 addresses. Further, it seems that this is only needed for veth type, not if we have a tapv2
if ipNet != nil && ipNet.IP.To4() == nil {
addr.Flags |= unix.IFA_F_NODAD
}
if err := netlinkHandle.AddrReplace(l, addr); err != nil {
return errors.Wrapf(err, "attempting to add ip address %s to %s (type: %s) with flags 0x%x", addr.IPNet, l.Attrs().Name, l.Type(), addr.Flags)
}
log.FromContext(ctx).
WithField("link.Name", l.Attrs().Name).
WithField("Addr", ipNet.String()).
WithField("duration", time.Since(now)).
WithField("netlink", "AddrAdd").Debug("completed")
}

return nil
}

func getIPAddrDifferences(netlinkHandle *netlink.Handle, l netlink.Link, newIPs []*net.IPNet) (toAdd, toRemove []*net.IPNet, err error) {
currentIPs, err := netlinkHandle.AddrList(l, netlink.FAMILY_ALL)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ipaddress
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
Expand All @@ -16,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ipneighbors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2022 Doc.ai and/or its affiliates.
Expand All @@ -16,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ipneighbors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ipneighbors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2020 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package routes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package routes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package routes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package mtu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package mtu
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2021 Cisco and/or its affiliates.
// Copyright (c) 2021-2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package mtu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package connectioncontextkernel
Expand Down
7 changes: 5 additions & 2 deletions pkg/kernel/networkservice/ethernetcontext/vf_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Nordix Foundation.
//
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -16,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ethernetcontext
Expand Down
3 changes: 3 additions & 0 deletions pkg/kernel/networkservice/ethernetcontext/vf_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021-2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -14,6 +16,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package ethernetcontext
Expand Down
7 changes: 5 additions & 2 deletions pkg/kernel/networkservice/ethernetcontext/vf_server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2021-2022 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -16,6 +18,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

// Package ethernetcontext provides chain element for setup link ethernet properties
Expand Down
Loading

0 comments on commit e777a2b

Please sign in to comment.