Skip to content

Commit

Permalink
better naming for peers
Browse files Browse the repository at this point in the history
Signed-off-by: Ashraf Fouda <[email protected]>
  • Loading branch information
ashraffouda committed Sep 2, 2024
1 parent 0a1c03e commit c2189b5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/netlight/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ func Create(name string, master *netlink.Bridge, ndmzIP *net.IPNet, ndmzGwIP *ne
privateNetBr := fmt.Sprintf("r%s", name)
myBr := fmt.Sprintf("m%s", name)
nsName := fmt.Sprintf("n%s", name)

peerPrefix := name
if len(name) > 4 {
peerPrefix = name[0:4]
}
bridges := []string{myBr}
if privateNet != nil {
bridges = append(bridges, privateNetBr)
Expand Down Expand Up @@ -77,7 +80,7 @@ func Create(name string, master *netlink.Bridge, ndmzIP *net.IPNet, ndmzGwIP *ne
}

if !ifaceutil.Exists(infPrivate, netNS) {
privateLink, err := ifaceutil.MakeVethPair(infPrivate, privateNetBr, 1500, nsName[0:3])
privateLink, err := ifaceutil.MakeVethPair(infPrivate, privateNetBr, 1500, peerPrefix)
if err != nil {
return nil, fmt.Errorf("failed to create private link: %w", err)
}
Expand All @@ -91,7 +94,7 @@ func Create(name string, master *netlink.Bridge, ndmzIP *net.IPNet, ndmzGwIP *ne

// create public interface and attach it to ndmz bridge
if !ifaceutil.Exists(infPublic, netNS) {
pubLink, err := ifaceutil.MakeVethPair(infPublic, master.Name, 1500, nsName[0:3])
pubLink, err := ifaceutil.MakeVethPair(infPublic, master.Name, 1500, peerPrefix)
if err != nil {
return nil, fmt.Errorf("failed to create public link in namespace %s: %w", nsName, err)
}
Expand All @@ -103,7 +106,7 @@ func Create(name string, master *netlink.Bridge, ndmzIP *net.IPNet, ndmzGwIP *ne
}

if !ifaceutil.Exists(infMycelium, netNS) {
myceliumLink, err := ifaceutil.MakeVethPair(infMycelium, myBr, 1500, nsName[0:3])
myceliumLink, err := ifaceutil.MakeVethPair(infMycelium, myBr, 1500, peerPrefix)
if err != nil {
return nil, fmt.Errorf("failed to create mycelium link: %w", err)
}
Expand Down Expand Up @@ -383,9 +386,13 @@ func (r *Resource) AttachMyceliumZDB(id string, zdbNS ns.NetNS) (err error) {
deviceName := ifaceutil.DeviceNameFromInputBytes([]byte(id))
linkName := fmt.Sprintf("m-%s", deviceName)

//
peerPrefix := r.name
if len(r.name) > 4 {
peerPrefix = name[0:4]
}

if !ifaceutil.Exists(linkName, zdbNS) {
zdbLink, err := ifaceutil.MakeVethPair(linkName, "mdmz", 1500, nsName[0:3])
zdbLink, err := ifaceutil.MakeVethPair(linkName, "mdmz", 1500, peerPrefix)
if err != nil {
return fmt.Errorf("failed to create zdb link %s : %w", linkName, err)
}
Expand Down

0 comments on commit c2189b5

Please sign in to comment.