-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dummy linux interface and existing IPs
Signed-off-by: Milan Lenco <[email protected]>
- Loading branch information
1 parent
58571ed
commit de9b348
Showing
16 changed files
with
880 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2020 Pantheon.tech | ||
// | ||
// 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 descriptor | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin/linuxcalls" | ||
|
||
"go.ligato.io/vpp-agent/v3/plugins/linux/ifplugin/ifaceidx" | ||
nslinuxcalls "go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin/linuxcalls" | ||
interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces" | ||
) | ||
|
||
// createDummyIf creates dummy interface. | ||
func (d *InterfaceDescriptor) createDummyIf( | ||
nsCtx nslinuxcalls.NamespaceMgmtCtx, linuxIf *interfaces.Interface, | ||
) (md *ifaceidx.LinuxIfMetadata, err error) { | ||
hostName := getHostIfName(linuxIf) | ||
agentPrefix := d.serviceLabel.GetAgentPrefix() | ||
|
||
// move to the namespace with the interface | ||
revert, err := d.nsPlugin.SwitchToNamespace(nsCtx, linuxIf.Namespace) | ||
if err != nil { | ||
d.log.Error("switch to namespace failed:", err) | ||
return nil, err | ||
} | ||
defer revert() | ||
|
||
// create a new Dummy interface | ||
err = d.ifHandler.AddDummyInterface(hostName) | ||
if err != nil { | ||
return nil, errors.WithMessagef(err, | ||
"failed to create dummy interface %s", hostName) | ||
} | ||
|
||
// add alias | ||
err = d.ifHandler.SetInterfaceAlias(hostName, agentPrefix+linuxcalls.GetDummyIfAlias(linuxIf)) | ||
if err != nil { | ||
return nil, errors.WithMessagef(err, | ||
"error setting alias for Dummy interface %s", hostName) | ||
} | ||
|
||
// build metadata | ||
link, err := d.ifHandler.GetLinkByName(hostName) | ||
if err != nil { | ||
return nil, errors.WithMessagef(err, "error getting link %s", hostName) | ||
} | ||
|
||
return &ifaceidx.LinuxIfMetadata{ | ||
Namespace: linuxIf.Namespace, | ||
LinuxIfIndex: link.Attrs().Index, | ||
HostIfName: hostName, | ||
}, nil | ||
} | ||
|
||
// deleteDummyIf removes dummy interface. | ||
func (d *InterfaceDescriptor) deleteDummyIf(linuxIf *interfaces.Interface) error { | ||
hostName := getHostIfName(linuxIf) | ||
err := d.ifHandler.DeleteInterface(hostName) | ||
if err != nil { | ||
d.log.Error(err) | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.