Exemple #1
0
static int pfring_zc_daq_acquire_best_effort(void *handle, int cnt, DAQ_Analysis_Func_t callback,
#if (DAQ_API_VERSION >= 0x00010002)
        DAQ_Meta_Func_t metaback,
#endif
        void *user) {
    Pfring_Context_t *context = (Pfring_Context_t *) handle;
    int ret = 0, c = 0;
    u_int32_t rx_ring_idx = context->num_devices - 1, rx_ring_idx_clone;
    u_int32_t mask = 0;
    u_char *pkt_buffer;

    context->analysis_func = callback;
    context->breakloop = 0;

    while (!context->breakloop && (cnt <= 0 || c < cnt)) {

#ifdef SIG_RELOAD
        if (pfring_zc_daq_reload_requested)
            pfring_zc_daq_reload(context);
#endif

        while (pfring_zc_daq_in_packets(context, &rx_ring_idx) && !context->breakloop) {

            pfring_zc_recv_pkt(context->rx_queues[rx_ring_idx], &context->buffer, 0);

            context->buffer->hash = context->ifindexes[rx_ring_idx];

            pkt_buffer = pfring_zc_pkt_buff_data(context->buffer, context->rx_queues[rx_ring_idx]);

#ifdef ENABLE_BPF
            if (!context->bpf_filter || bpf_filter(context->filter.bf_insns, pkt_buffer, context->buffer->len /* caplen */, context->buffer->len) != 0) { /* accept */
#endif
                /* enqueueing pkt (and don't care of no room available) */
                mask = 1 << (context->num_devices);
#ifdef ENABLE_BPF
            } else {
                context->stats.packets_received++;
                context->stats.verdicts[DAQ_VERDICT_PASS]++;
            }
#endif
            mask |= 1 << (rx_ring_idx ^ 0x1);
            pfring_zc_send_pkt_multi(context->mq, &context->buffer, mask, 0);
        }

        rx_ring_idx_clone = rx_ring_idx;
        while (!(ret = pfring_zc_daq_in_packets(context, &rx_ring_idx_clone)) && !pfring_zc_queue_is_empty(context->q) && !context->breakloop) {
            ret = pfring_zc_recv_pkt(context->q, &context->buffer, 0);
            pfring_zc_daq_process(context, context->buffer, user);
            c++;
        }

        if (!ret) {
            if (usleep(1) == -1)
                if (errno == EINTR)
                    break;
        }
    }

    return 0;
}
Exemple #2
0
void *packet_consumer_thread(void *_id) {
  struct volatile_globals *g = globals;
  pfring_zc_queue *_inzq = inzq;
  pfring_zc_queue **_outzq = outzq;
  pfring_zc_multi_queue *_mq = mq;
  pfring_zc_pkt_buff **_ph = ph;
  u_int32_t _num_slaves = num_slaves;
  int i, ns, flush_tx = 0, toprocess = 0;
#ifdef USE_RECV_BURST
  int nr;
#endif

  bind2core(bind_core);

  while(!g->do_shutdown) {

#ifdef USE_RECV_BURST
    if ((nr = pfring_zc_recv_pkt_burst(_inzq, _ph, SWAP_BUFFERS, 0 /* g->wait_for_packet */)) > 0)
#else
    if (pfring_zc_recv_pkt(_inzq, _ph, 0 /* g->wait_for_packet */) > 0)
#endif
    {

#ifdef USE_RECV_BURST
      toprocess = 0;
      while (toprocess < nr) {
#endif
        pfring_zc_pkt_buff **buff_p = &_ph[toprocess];
        pfring_zc_pkt_buff *buff = *buff_p;

        if (g->time_pulse) {
          u_int64_t pulse_timestamp_ns = *g->pulse_timestamp_ns;
          buff->ts.tv_sec = pulse_timestamp_ns >> 32;
          buff->ts.tv_nsec = pulse_timestamp_ns & 0xffffffff;
        }

        g->numPkts++;
        g->numBytes += buff->len + 24; /* 8 Preamble + 4 CRC + 12 IFG */

        ns = pfring_zc_send_pkt_multi(_mq, buff_p, 0xffffffff, 0);

	//drop += _num_slaves - ns;
        g->sentPkts += ns;

#ifdef USE_RECV_BURST
        toprocess++;
      }
#endif
      flush_tx = 1;

    } else {