Skip to content

Commit

Permalink
Add constants file
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Sep 25, 2020
1 parent fb6ece2 commit e83ebf7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
26 changes: 26 additions & 0 deletions pkg/kernel/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//+build !linux

package kernel

const (
// FamilyAll is netlink.FAMILY_ALL
FamilyAll = 0x0
// NudReachable is netlink.NUD_REACHABLE
NudReachable = 0x02
)
28 changes: 28 additions & 0 deletions pkg/kernel/const_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package kernel

import (
"github.com/vishvananda/netlink"
)

const (
// FamilyAll is netlink.FAMILY_ALL
FAMILY_ALL = netlink.FAMILY_ALL
// NudReachable is netlink.NUD_REACHABLE
NUD_REACHABLE = netlink.NUD_REACHABLE
)
2 changes: 1 addition & 1 deletion pkg/kernel/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (l *link) AddAddress(ip string) error {
}

// check if address is already assigned
current, err := netlink.AddrList(l.link, 0x0) // netlink.FAMILY_ALL (linux-specific constant)
current, err := netlink.AddrList(l.link, FamilyAll)
if err != nil {
return errors.Errorf("failed to get current IP address list %q: %s", ip, err)
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/kernel/networkservice/connectioncontext/ipcontext/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import (
"os"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/pkg/errors"
"github.com/vishvananda/netlink"

"github.com/networkservicemesh/api/pkg/api/networkservice"
kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"

"github.com/networkservicemesh/sdk-kernel/pkg/kernel"
)

type ipContextServer struct{}
Expand All @@ -38,7 +41,7 @@ func NewServer() networkservice.NetworkServiceServer {
}

func (s *ipContextServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
if mech := kernel.ToMechanism(request.GetConnection().GetMechanism()); mech != nil {
if mech := kernelmech.ToMechanism(request.GetConnection().GetMechanism()); mech != nil {
ifName := mech.GetInterfaceName(request.GetConnection())
link, err := netlink.LinkByName(ifName)
if err != nil {
Expand Down Expand Up @@ -71,7 +74,7 @@ func (s *ipContextServer) Request(ctx context.Context, request *networkservice.N
}

func setIPAddr(ipAddr *netlink.Addr, link netlink.Link) error {
ipAddrs, err := netlink.AddrList(link, 0x0) // netlink.FAMILY_ALL (linux-specific constant)
ipAddrs, err := netlink.AddrList(link, kernel.FamilyAll)
if err != nil {
return errors.Wrapf(err, "failed to get the net interface IP addresses: %v", link.Attrs().Name)
}
Expand Down Expand Up @@ -117,7 +120,7 @@ func setIPNeighbors(ipNeighbours []*networkservice.IpNeighbor, link netlink.Link
}
if err := netlink.NeighAdd(&netlink.Neigh{
LinkIndex: link.Attrs().Index,
State: 0x02, // netlink.NUD_REACHABLE (linux-specific constant)
State: kernel.NudReachable,
IP: net.ParseIP(ipNeighbor.Ip),
HardwareAddr: macAddr,
}); err != nil && !os.IsExist(err) {
Expand Down

0 comments on commit e83ebf7

Please sign in to comment.