Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/network/ifaceutil/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,21 @@ func MakeVethPair(name, master string, mtu int, netNs ns.NetNS) error {
}
}

peerName := fmt.Sprintf("p-%s", name)
peerPrefix := "p"
if netNs != nil {
nsName := filepath.Base(netNs.Path())

// Use last 4 characters of namespace name, or full name if less than 4
peerPrefix = nsName
if len(nsName) >= 4 {
peerPrefix = nsName[len(nsName)-4:]
}

}
peerName := fmt.Sprintf("%s-%s", peerPrefix, name)
if len(peerName) > 15 {
peerName = peerName[0:15]
}
if _, err = netlink.LinkByName(peerName); err == nil {
return fmt.Errorf("peer already exists %q", peerName)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/network/qsfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"strings"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/threefoldtech/zosbase/pkg/netbase/nft"
"github.com/threefoldtech/zosbase/pkg/network/ifaceutil"
"github.com/threefoldtech/zosbase/pkg/network/namespace"
"github.com/vishvananda/netlink"
)

var _nft = `
Expand Down Expand Up @@ -88,6 +90,12 @@ func (n networker) QSFSPrepare(id string) (string, string, error) {
return "", "", err
}

if n.mycelium != nil {
if _, err := n.attachMycelium(id, netNs); err != nil {
return "", "", errors.Wrap(err, "failed to attach mycelium to qsfs namespace")
}
}

return netNSName, ip.IP.String(), err
}

Expand All @@ -108,5 +116,14 @@ func (n networker) QSFSDestroy(id string) error {
// log and continue cleaning up
log.Error().Err(err).Msg("couldn't detach ygg interface")
}
if err := netNs.Do(func(_ ns.NetNS) error {
link, err := netlink.LinkByName(ZDBMyceliumIface)
if err != nil {
return err
}
return netlink.LinkDel(link)
}); err != nil {
log.Error().Err(err).Msg("couldn't detach mycelium interface")
}
return n.destroy(netNSName)
}
15 changes: 13 additions & 2 deletions pkg/qsfsd/qsfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err
}

env := environment.MustGet()
qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc2.flist")
qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc1.flist")
if err != nil {
err = errors.Wrap(err, "failed to construct url")
return
Expand All @@ -142,6 +142,10 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err
err = errors.Wrap(lerr, "couldn't write qsfs config")
return
}
if lerr := q.writeHosts(flistPath); lerr != nil {
err = errors.Wrap(lerr, "couldn't write /etc/hosts")
return
}
mountPath := q.mountPath(wlID)
err = q.prepareMountPath(mountPath)
if err != nil {
Expand Down Expand Up @@ -308,9 +312,16 @@ func (q *QSFS) prepareMountPath(path string) error {
return nil
}

// for some reason hosts file was corrupted in the flist, we need to rewrite it for zstor to be able to resolve localhost
func (q *QSFS) writeHosts(root string) error {
hostsPath := filepath.Join(root, "etc/hosts")
const hosts = "127.0.0.1\tlocalhost\n::1\t\tlocalhost ip6-localhost ip6-loopback\n"
return os.WriteFile(hostsPath, []byte(hosts), 0644)
}

func (q *QSFS) writeQSFSConfig(root string, cfg zstorConfig) error {
cfgPath := filepath.Join(root, "data/zstor.toml")
f, err := os.OpenFile(cfgPath, os.O_WRONLY|os.O_CREATE, 0644)
f, err := os.OpenFile(cfgPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return errors.Wrap(err, "couldn't open zstor config file")
}
Expand Down
Loading