Skip to content

Commit

Permalink
Set default kernel interface name
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Jul 12, 2021
1 parent 6d7c5b4 commit ad33552
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions pkg/networkservice/common/mechanisms/kernel/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ func NewClient(options ...Option) networkservice.NetworkServiceClient {

func (k *kernelMechanismClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) {
if !k.updateMechanismPreferences(request) {
request.MechanismPreferences = append(request.GetMechanismPreferences(), &networkservice.Mechanism{
mechanism := &networkservice.Mechanism{
Cls: cls.LOCAL,
Type: kernel.MECHANISM,
Parameters: map[string]string{
kernel.NetNSURL: (&url.URL{Scheme: "file", Path: netNSFilename}).String(),
kernel.InterfaceNameKey: k.interfaceName,
kernel.InterfaceNameKey: request.GetConnection().GetId(),
},
})
}
if k.interfaceName != "" {
mechanism.Parameters[kernel.InterfaceNameKey] = k.interfaceName
}
request.MechanismPreferences = append(request.GetMechanismPreferences(), mechanism)
}
return next.Client(ctx).Request(ctx, request, opts...)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/networkservice/common/mechanisms/kernel/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -39,6 +39,7 @@ func NewServer() networkservice.NetworkServiceServer {
func (m *kernelMechanismServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
if mechanism := kernel.ToMechanism(request.GetConnection().GetMechanism()); mechanism != nil {
mechanism.SetNetNSURL((&url.URL{Scheme: "file", Path: netNSFilename}).String())
mechanism.SetInterfaceName(request.GetConnection().GetId())
}
return next.Server(ctx).Request(ctx, request)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -38,6 +38,9 @@ import (

func kernelMechanism() *networkservice.Mechanism {
request := new(networkservice.NetworkServiceRequest)
request.Connection = &networkservice.Connection{
Id: "id",
}
_, _ = kernel.NewClient().Request(context.TODO(), request)
return request.MechanismPreferences[0]
}
Expand Down

0 comments on commit ad33552

Please sign in to comment.