Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPP memif #2005

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions analyzer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/skydive-project/skydive/topology/probes/ovn"
"github.com/skydive-project/skydive/topology/probes/ovsdb"
"github.com/skydive-project/skydive/topology/probes/runc"
"github.com/skydive-project/skydive/topology/probes/vpp"
"github.com/skydive-project/skydive/ui"
"github.com/skydive-project/skydive/websocket"
ws "github.com/skydive-project/skydive/websocket"
Expand Down Expand Up @@ -431,6 +432,7 @@ func init() {
graph.NodeMetadataDecoders["OVN"] = ovn.MetadataDecoder
graph.NodeMetadataDecoders["Neutron"] = neutron.MetadataDecoder
graph.NodeMetadataDecoders["Contrail"] = opencontrail.MetadataDecoder
graph.NodeMetadataDecoders["VPP"] = vpp.MetadataDecoder

graph.EdgeMetadataDecoders["NSM"] = nsm.MetadataDecoder
}
178 changes: 178 additions & 0 deletions common/namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// +build linux

/*
* Copyright (C) 2016 Red Hat, Inc.
*
* 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 ofthe 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 specificlanguage governing permissions and
* limitations under the License.
*
*/

package common

import (
"fmt"
"os"
"runtime"
"syscall"

"github.com/skydive-project/skydive/logging"
"github.com/vishvananda/netns"
)

// Namespace types
const (
IPCNamespace = "ipc"
MountNamespace = "mnt"
NetworkNamespace = "net"
PIDNamespace = "pid"
UserNamespace = "user"
TimeNamespace = "uts"
)

// Namespace describes a network namespace path associated with a device / inode
type Namespace struct {
netns.NsHandle
path string
dev uint64
ino uint64
}

func (ns *Namespace) String() string {
return fmt.Sprintf("%d,%d", ns.dev, ns.ino)
}

// Path returns the namespace path
func (ns *Namespace) Path() string {
return ns.path
}

// Ino returns the namespace inode number
func (ns *Namespace) Ino() uint64 {
return ns.ino
}

// Dev returns the namespace device number
func (ns *Namespace) Dev() uint64 {
return ns.dev
}

// Equal compares two Namespace objects
func (ns *Namespace) Equal(o *Namespace) bool {
return (ns.dev == o.dev && ns.ino == o.ino)
}

// GetNamespaceFromPath open a namespace fd from a path
func GetNamespaceFromPath(kind, path string) (*Namespace, error) {
ns, err := netns.GetFromPath(path)
if err != nil {
return nil, fmt.Errorf("Failed to get %s root namespace %s", kind, path)
}

var stats syscall.Stat_t
if err = syscall.Fstat(int(ns), &stats); err != nil {
return nil, fmt.Errorf("Failed to stat %s root namespace %s", kind, path)
}

return &Namespace{NsHandle: ns, path: path, dev: stats.Dev, ino: stats.Ino}, nil
}

// GetCurrentNamespace returns the current namespace of the specified kind
func GetCurrentNamespace(kind string) (*Namespace, error) {
return GetNamespaceFromPath(kind, fmt.Sprintf("/proc/%d/task/%d/ns/%s", os.Getpid(), syscall.Gettid(), kind))
}

// NamespaceContext describes a NameSpace Context switch API
type NamespaceContext struct {
nsType int
origNs netns.NsHandle
newNs netns.NsHandle
}

// Quit the NameSpace and go back to the original one
func (n *NamespaceContext) Quit() error {
if n != nil {
if err := netns.Setns(n.origNs, n.nsType); err != nil {
return err
}
n.newNs.Close()
n.origNs.Close()
}
return nil
}

// Close the NameSpace
func (n *NamespaceContext) Close() {
if n != nil && n.origNs.IsOpen() {
n.Quit()
}

runtime.UnlockOSThread()
}

func getNsType(kind string) int {
switch kind {
case NetworkNamespace:
return syscall.CLONE_NEWNET
case IPCNamespace:
return syscall.CLONE_NEWIPC
case MountNamespace:
return syscall.CLONE_NEWNS
case PIDNamespace:
return syscall.CLONE_NEWPID
case UserNamespace:
return syscall.CLONE_NEWUSER
case TimeNamespace:
return syscall.CLONE_NEWUTS
default:
return 0
}
}

// NewNamespaceContext creates a new namespace context from a path
func NewNamespaceContext(kind string, path string) (*NamespaceContext, error) {
nsType := getNsType(kind)
if nsType == 0 {
return nil, fmt.Errorf("Unsupported namespace type: %s", kind)
}

runtime.LockOSThread()

origns, err := GetCurrentNamespace(kind)
if err != nil {
return nil, fmt.Errorf("Error while getting current %s ns: %s", kind, err.Error())
}

newns, err := GetNamespaceFromPath(kind, path)
if err != nil {
origns.Close()
return nil, fmt.Errorf("Error while opening %s: %s", path, err.Error())
}

if err = netns.Setns(newns.NsHandle, nsType); err != nil {
logging.GetLogger().Errorf("Failed to set namespace %d with type %d", newns.NsHandle, nsType)
newns.Close()
origns.Close()
return nil, fmt.Errorf("Error while switching from root %s ns to %s: %s", kind, path, err.Error())
}

return &NamespaceContext{
nsType: nsType,
origNs: origns.NsHandle,
newNs: newns.NsHandle,
}, nil
}

// NewNetNsContext creates a new network namespace context from a path
func NewNetNsContext(path string) (*NamespaceContext, error) {
return NewNamespaceContext(NetworkNamespace, path)
}
81 changes: 0 additions & 81 deletions common/netns.go

This file was deleted.

18 changes: 9 additions & 9 deletions common/no_netns.go → common/no_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@

package common

// NetNSContext describes a NameSpace Context switch API
type NetNSContext struct {
// NamespaceContext describes a namespace context switch API
type NamespaceContext struct {
}

// Quit the NameSpace and go back to the original one
func (n *NetNSContext) Quit() error {
// Quit the namespace and go back to the original one
func (n *NamespaceContext) Quit() error {
return nil
}

// Close the NameSpace
func (n *NetNSContext) Close() {
// Close the namespace
func (n *NamespaceContext) Close() {
}

// NewNetNsContext creates a new NameSpace context base on path
func NewNetNsContext(path string) (*NetNSContext, error) {
// NewNetNsContext creates a new namespace context base on path
func NewNetNsContext(path string) (*NamespaceContext, error) {
if path != "" {
return nil, ErrNotImplemented
}

return &NetNSContext{}, nil
return &NamespaceContext{}, nil
}
2 changes: 1 addition & 1 deletion flow/probes/gopacket/gopacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (p *Probe) listen(packetCallback func(gopacket.Packet)) error {
func (p *Probe) Run(packetCallback func(gopacket.Packet), e probes.ProbeEventHandler) error {
p.state.Store(common.RunningState)

var nsContext *common.NetNSContext
var nsContext *common.NamespaceContext
var err error
if p.nsPath != "" {
p.Ctx.Logger.Debugf("Switching to namespace (path: %s)", p.nsPath)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/skydive-project/skydive

require (
git.fd.io/govpp.git v0.0.0-20190321220742-345201eedce4
git.fd.io/govpp.git v0.1.0
github.com/GehirnInc/crypt v0.0.0-20170404120257-5a3fafaa7c86
github.com/IBM/ibm-cos-sdk-go v0.0.0-20190328184230-08c1143e8d36
github.com/Knetic/govaluate v0.0.0-20171022003610-9aa49832a739 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSR
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
git.fd.io/govpp.git v0.0.0-20190321220742-345201eedce4 h1:RgD/hziNkW6p1RJSU1wH9vtj27KBlPDYlApd/SWwyM0=
git.fd.io/govpp.git v0.0.0-20190321220742-345201eedce4/go.mod h1:+vyimAjILe5SYKjw4/WJ/8qPl9U5Qd9IT2v6b9VB83o=
git.fd.io/govpp.git v0.1.0 h1:fV5H9ghURFfmNAjk7Scb/aG3OGwevLayHfSdS8GsYjE=
git.fd.io/govpp.git v0.1.0/go.mod h1:+vyimAjILe5SYKjw4/WJ/8qPl9U5Qd9IT2v6b9VB83o=
github.com/Azure/go-autorest v11.1.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest v11.1.2+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -394,9 +395,12 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kshvakov/clickhouse v1.3.5/go.mod h1:DMzX7FxRymoNkVgizH0DWAL8Cur7wHLgx3MUnGwJqpE=
github.com/lebauce/go-libvirt v0.0.0-20190717144624-7799d804f7e4 h1:x5KFqNwY2VCNzeb/e3uDMXFGTsJIkshXR196AICUFlA=
github.com/lebauce/go-libvirt v0.0.0-20190717144624-7799d804f7e4/go.mod h1:0vvEvX3eAM/+BVh8JR6ujCJR5kiHdNz6EmbN+UXekPY=
github.com/lebauce/gobpf v0.0.0-20190909090614-f9e9df81702a/go.mod h1:JhYasZSlL+g2F1yLuDe6xblKOyBqS74nxpnrmkjvyIE=
github.com/lebauce/netlink v0.0.0-20190122103356-fa328be7c8d2 h1:BJ76NzXWxDpXfIllk9aqIUAkfE9ii5vckEVzbnu8Xuo=
github.com/lebauce/netlink v0.0.0-20190122103356-fa328be7c8d2/go.mod h1:BM4By6mUPPgCziwQuGvUvszl5C2leD3bQWoot0sEgxA=
github.com/lebauce/viper v0.0.0-20190903114911-3b7a98e30843 h1:ECfqMmqlbfCw03LG3vqLw59qHkftBcmhWpupIgc20r0=
github.com/lebauce/viper v0.0.0-20190903114911-3b7a98e30843/go.mod h1:jUyf+v/KTOnRyUy2/AsjF537WfJWVv3AnlcKSNd+AIg=
github.com/libvirt/libvirt-go v0.0.0-20181005092746-9c5bdce3c18f h1:MR3DdYRibNNyUFwDOmuMynXQMTrlktmPK20JlTyW8qo=
github.com/libvirt/libvirt-go v0.0.0-20181005092746-9c5bdce3c18f/go.mod h1:34zsnB4iGeOv7Byj6qotuW8Ya4v4Tr43ttjz/F0wjLE=
Expand Down
4 changes: 3 additions & 1 deletion graffiti/common/subscriber_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ func (t *SubscriberEndpoint) OnConnected(c ws.Speaker) {
if gremlinFilter != "" {
host := c.GetRemoteHost()

subscriber, err := t.newSubscriber(host, gremlinFilter, false)
subscriber, err := t.newSubscriber(host, gremlinFilter, true)
if err != nil {
logging.GetLogger().Error(err)
return
}

logging.GetLogger().Infof("Client %s subscribed with filter %s during the connection", host, gremlinFilter)
t.Lock()
t.subscribers[c] = subscriber
t.Unlock()
}
}

Expand Down
Loading