示例#1
0
// startCapturePcap starts a new capture for a specified interface on a VM,
// writing the packets to the specified filename in PCAP format.
func startCapturePcap(vm string, iface int, filename string) error {
	// get the vm
	v := vms.findVm(vm)
	if v == nil {
		return vmNotFound(vm)
	}

	if len(v.Taps) <= iface {
		return fmt.Errorf("no such interface %v", iface)
	}

	tap := v.Taps[iface]

	// attempt to start pcap on the bridge
	p, err := gopcap.NewPCAP(tap, filename)
	if err != nil {
		return err
	}

	// success! add it to the list
	ce := &capture{
		ID:        <-captureIDCount,
		Type:      "pcap",
		VM:        v.ID,
		Interface: iface,
		Path:      filename,
		pcap:      p,
	}

	captureLock.Lock()
	captureEntries[ce.ID] = ce
	captureLock.Unlock()

	return nil
}
示例#2
0
// startBridgeCapturePcap starts a new capture for all the traffic on the
// specified bridge, writing all packets to the specified filename in PCAP
// format.
func startBridgeCapturePcap(b, filename string) error {
	// create the bridge if necessary
	br, err := getBridge(b)
	if err != nil {
		return err
	}

	tap, err := br.CreateMirror()
	if err != nil {
		return err
	}

	// attempt to start pcap on the mirrored tap
	p, err := gopcap.NewPCAP(tap, filename)
	if err != nil {
		return err
	}

	// success! add it to the list
	ce := &capture{
		ID:        captureID.Next(),
		Type:      "pcap",
		Bridge:    br.Name,
		VM:        -1,
		Interface: -1,
		Path:      filename,
		pcap:      p,
		tap:       tap,
	}

	captureEntries[ce.ID] = ce

	return nil
}
示例#3
0
// startCapturePcap starts a new capture for a specified interface on a VM,
// writing the packets to the specified filename in PCAP format.
func startCapturePcap(vm string, iface int, filename string) error {
	// TODO: filter by namespace?
	// get the vm
	v := vms.FindVM(vm)
	if v == nil {
		return vmNotFound(vm)
	}

	config := getConfig(v)

	if len(config.Networks) <= iface {
		return fmt.Errorf("no such interface %v", iface)
	}

	tap := config.Networks[iface].Tap

	// attempt to start pcap on the bridge
	p, err := gopcap.NewPCAP(tap, filename)
	if err != nil {
		return err
	}

	// success! add it to the list
	ce := &capture{
		ID:        captureID.Next(),
		Type:      "pcap",
		VM:        v.GetID(),
		Interface: iface,
		Path:      filename,
		pcap:      p,
	}

	captureEntries[ce.ID] = ce

	return nil
}
示例#4
0
// startBridgeCapturePcap starts a new capture for all the traffic on the
// specified bridge, writing all packets to the specified filename in PCAP
// format.
func startBridgeCapturePcap(bridge, filename string) error {
	// create the bridge if necessary
	b, err := getBridge(bridge)
	if err != nil {
		return err
	}

	tap, err := b.CreateBridgeMirror()
	if err != nil {
		return err
	}

	// attempt to start pcap on the mirrored tap
	p, err := gopcap.NewPCAP(tap, filename)
	if err != nil {
		return err
	}

	// success! add it to the list
	ce := &capture{
		ID:        <-captureIDCount,
		Type:      "pcap",
		Bridge:    bridge,
		VM:        -1,
		Interface: -1,
		Path:      filename,
		pcap:      p,
		tap:       tap,
	}

	captureLock.Lock()
	captureEntries[ce.ID] = ce
	captureLock.Unlock()

	return nil
}