Ejemplo n.º 1
0
func (pb *Packetbeat) makeWorkerFactory(filter string) sniffer.WorkerFactory {
	return func(dl layers.LinkType) (sniffer.Worker, string, error) {
		var f *flows.Flows
		var err error
		config := &pb.Config

		if config.Flows.IsEnabled() {
			f, err = flows.NewFlows(pb.Pub, config.Flows)
			if err != nil {
				return nil, "", err
			}
		}

		var icmp4 icmp.ICMPv4Processor
		var icmp6 icmp.ICMPv6Processor
		if cfg := config.Protocols["icmp"]; cfg.Enabled() {
			icmp, err := icmp.New(false, pb.Pub, cfg)
			if err != nil {
				return nil, "", err
			}

			icmp4 = icmp
			icmp6 = icmp
		}

		tcp, err := tcp.NewTcp(&protos.Protos)
		if err != nil {
			return nil, "", err
		}

		udp, err := udp.NewUdp(&protos.Protos)
		if err != nil {
			return nil, "", err
		}

		worker, err := decoder.NewDecoder(f, dl, icmp4, icmp6, tcp, udp)
		if err != nil {
			return nil, "", err
		}

		if f != nil {
			pb.services = append(pb.services, f)
		}
		return worker, filter, nil
	}
}
Ejemplo n.º 2
0
func (pb *packetbeat) createWorker(dl layers.LinkType) (sniffer.Worker, error) {
	var f *flows.Flows
	var err error
	config := &pb.config

	if config.Flows.IsEnabled() {
		f, err = flows.NewFlows(pb.pub, config.Flows)
		if err != nil {
			return nil, err
		}
	}

	var icmp4 icmp.ICMPv4Processor
	var icmp6 icmp.ICMPv6Processor
	if cfg := config.Protocols["icmp"]; cfg.Enabled() {
		icmp, err := icmp.New(false, pb.pub, cfg)
		if err != nil {
			return nil, err
		}

		icmp4 = icmp
		icmp6 = icmp
	}

	tcp, err := tcp.NewTCP(&protos.Protos)
	if err != nil {
		return nil, err
	}

	udp, err := udp.NewUDP(&protos.Protos)
	if err != nil {
		return nil, err
	}

	worker, err := decoder.New(f, dl, icmp4, icmp6, tcp, udp)
	if err != nil {
		return nil, err
	}

	if f != nil {
		pb.services = append(pb.services, f)
	}
	return worker, nil
}