Ejemplo n.º 1
0
func NewPatchPanel() (pp *PatchPanel, err error) {
	id := util.NewUUID4()

	pp = &PatchPanel{}
	defer func() {
		if err != nil {
			pp.Close()
			pp = nil
		}
	}()
	code := strings.Join([]string{bpf.IomoduleH, bpf.PatchC}, "\n")
	b := bpf.NewBpfModule(code, []string{"-w"})
	if b == nil {
		err = fmt.Errorf("PatchPanel: unable to load core module")
		return
	}
	pp.adapter = canvas.NewBpfAdapter(id, "patch", b)
	pp.modules = pp.adapter.Table("modules")
	if pp.modules == nil {
		err = fmt.Errorf("PatchPanel: Unable to load modules table")
		return
	}
	Debug.Printf("Patch panel modules table loaded: %v\n", pp.modules.Config())
	return
}
Ejemplo n.º 2
0
func NewAdapter(req api.ModuleBase, g Graph, id int) (adapter Adapter, err error) {
	uuid := util.NewUUID4()

	parts := strings.SplitN(req.ModuleType, "/", 2)
	switch parts[0] {
	case "bpf":
		var subtype string
		if len(parts) > 1 {
			subtype = parts[1]
		}
		a := &BpfAdapter{
			uuid:    uuid[:8],
			perm:    PermR | PermW,
			config:  make(map[string]interface{}),
			subtype: subtype,
		}
		if err = a.SetConfig(req, g, id); err != nil {
			return
		}
		adapter = a
	case "bridge":
		a := &BridgeAdapter{
			uuid:   uuid[:8],
			name:   req.DisplayName,
			tags:   req.Tags,
			perm:   PermR | PermW,
			config: make(map[string]interface{}),
		}
		if err = a.SetConfig(req, g, id); err != nil {
			return
		}
		adapter = a
	default:
		err = fmt.Errorf("unknown ModuleType %s", req.ModuleType)
		return
	}
	return
}