Esempio n. 1
0
gboolean qfTraceMain(qfContext_t             *ctx)
{
    gboolean                ok = TRUE;
    qfTraceSource_t         *lts = ctx->ictx.pktsrc;
    yfPBuf_t                    *pbuf;

    libtrace_err_t          terr;
    
    int i, trv;
    
    /* process input until we're done */
    while (!yaf_quit) {
        
        i = 0;
        while (i < TRACE_PACKET_GROUP && !yaf_quit) {
            
            /* get next spot in ring buffer */
            pbuf = (yfPBuf_t *)rgaNextHead(ctx->pbufring);
            g_assert(pbuf);
            
            /* and try to parse packets into it until we get one */
            do {
                trv = trace_read_packet(lts->trace, lts->packet);
                if (trv <= 0) goto TRACE_END;
            } while (!qfTraceHandlePacket(lts, pbuf, ctx));
            i++;
        }

TRACE_END:
        /* Check for error */
        if (trace_is_err(lts->trace)) {
            terr = trace_get_err(lts->trace);
            g_warning("libtrace error: %s", terr.problem);
            ok = FALSE;
            break;
        }

        /* Check for quit or EOF */
        if (yaf_quit || trv == 0) break;

        /* Process the packet buffer */
        if (ok && !yfProcessPBufRing(ctx, &(ctx->err))) {
            ok = FALSE;
            break;
        }
        
        /* Do periodic export as necessary */
        qfTracePeriodicExport(ctx, yfFlowTabCurrentTime(ctx->flowtab));
    }

    return yfFinalFlush(ctx, ok,  &(ctx->err));
}
Esempio n. 2
0
/**
 * rgaNextHead
 *
 *
 *
 */
uint8_t *rgaNextHead(
    rgaRing_t       *ring)
{
    uint8_t         *head = NULL;

    g_mutex_lock(ring->mtx);
    while (!ring->interrupt && ((head = rgaNextHead(ring)) == NULL)) {
        g_cond_wait(ring->cnd_full, ring->mtx);
    }
    if (ring->interrupt) {
        head = NULL;
        goto end;
    }
    if (++(ring->hrsv) > ring->cap) {
        ring->hrsv = ring->cap;
    }
    g_cond_signal(ring->cnd_zero);
end:
    g_mutex_unlock(ring->mtx);
    return head;
}