Improve veth name construction; use a constant instead of "ethwe"
This commit is contained in:
1 parent
8717fd15ed
commit
2702b85ee5
5 files changed
+14
-8
No files matched your search
+9
-3
@@ -100,6 +100,11 @@ func contains(addrs []netlink.Addr, addr *net.IPNet) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
VethName = "ethwe" // name inside container namespace
|
||||
vethPrefix = "v" + VethName // starts with "veth" to suppress UI notifications
|
||||
)
|
||||
|
||||
func interfaceExistsInNamespace(ns netns.NsHandle, ifName string) bool {
|
||||
err := WithNetNS(ns, func() error {
|
||||
_, err := netlink.LinkByName(ifName)
|
||||
@@ -110,10 +115,11 @@ func interfaceExistsInNamespace(ns netns.NsHandle, ifName string) bool {
|
||||
|
||||
func AttachContainer(ns netns.NsHandle, id, ifName, bridgeName string, mtu int, withMulticastRoute bool, cidrs []*net.IPNet) error {
|
||||
if !interfaceExistsInNamespace(ns, ifName) {
|
||||
if len(id) > 5 {
|
||||
id = id[:5]
|
||||
maxIDLen := IFNAMSIZ - 1 - len(vethPrefix+"pl")
|
||||
if len(id) > maxIDLen {
|
||||
id = id[:maxIDLen] // trim passed ID if too long
|
||||
}
|
||||
name, peerName := "vethwepl"+id, "vethwg"+id
|
||||
name, peerName := vethPrefix+"pl"+id, vethPrefix+"pg"+id
|
||||
_, err := CreateAndAttachVeth(name, peerName, bridgeName, mtu, func(veth netlink.Link) error {
|
||||
EthtoolTXOff(peerName) // TODO: do we want to do this under fastdp?
|
||||
if err := netlink.LinkSetNsFd(veth, int(ns)); err != nil {
|
||||
|
||||
@@ -108,7 +108,7 @@ func (driver *driver) JoinEndpoint(j *api.JoinRequest) (*api.JoinResponse, error
|
||||
response := &api.JoinResponse{
|
||||
InterfaceName: &api.InterfaceName{
|
||||
SrcName: peerName,
|
||||
DstPrefix: "ethwe",
|
||||
DstPrefix: weavenet.VethName,
|
||||
},
|
||||
}
|
||||
if !driver.noMulticastRoute {
|
||||
|
||||
@@ -40,7 +40,7 @@ func attach(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = weavenet.AttachContainer(nsContainer, fmt.Sprint(pid), "ethwe", args[1], mtu, withMulticastRoute, cidrs)
|
||||
err = weavenet.AttachContainer(nsContainer, fmt.Sprint(pid), weavenet.VethName, args[1], mtu, withMulticastRoute, cidrs)
|
||||
// If we detected an error but the container has died, tell the user that instead.
|
||||
if err != nil && !processExists(pid) {
|
||||
err = fmt.Errorf("Container %s died", args[0])
|
||||
@@ -97,5 +97,5 @@ func detach(args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return weavenet.DetachContainer(ns, args[0], "ethwe", cidrs)
|
||||
return weavenet.DetachContainer(ns, args[0], weavenet.VethName, cidrs)
|
||||
}
|
||||
@@ -7,6 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func checkNetwork() error {
|
||||
_, err := weavenet.EnsureInterface("ethwe")
|
||||
_, err := weavenet.EnsureInterface(weavenet.VethName)
|
||||
return err
|
||||
}
|
||||
@@ -7,6 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func checkNetwork() error {
|
||||
_, err := weavenet.EnsureInterfaceAndMcastRoute("ethwe")
|
||||
_, err := weavenet.EnsureInterfaceAndMcastRoute(weavenet.VethName)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user