예제 #1
0
/** 
 * Move a scoreboard entry from one table to the other
 *
 * @todo This actually can probably be done faster with the rindex
 *       stuff and a SFXHASH_NODE interface.
 * 
 * @param dst where to move the address to
 * @param src where to move the address from
 * @param address the address to move
 * 
 * @return FLOW_SUCCESS on success
 */
int scoreboard_move(SCOREBOARD *dst, SCOREBOARD *src, u_int32_t *address)
{
    SCORE_ENTRY *src_entry, *dst_entry;
    
    if(!src || !dst)
    {
        return FLOW_ENULL;
    }

    if(scoreboard_find(src, address, &src_entry) != FLOW_SUCCESS)
    {
        return FLOW_NOTFOUND;
    }

    if(scoreboard_add(dst, address, &dst_entry) != FLOW_SUCCESS)
    {
        return FLOW_EINVALID;
    }

    memcpy(dst_entry,src_entry,sizeof(SCORE_ENTRY));

    dst_entry->position = dst->kind;
    
    if(scoreboard_remove(src, address) != FLOW_SUCCESS)
    {
        /* small problem here in that we have 2 versions of the same
           thing going on */           
        return FLOW_BADJUJU;
    }
    
    return FLOW_SUCCESS;
}
/** 
 * find the trackers in the table
 *
 * Currently, it first looks it up in the active table and then the
 * scanner table
 * 
 * @param trackerp tracker to search
 * @param address key to search for
 * @param sepp where to place the results
 * 
 * @return FLOW_SUCCESS on sucess and sets sepp
 */
int flowps_find_entry(PS_TRACKER *trackerp, u_int32_t *address, SCORE_ENTRY **sepp)
{
    int ret;
    
    if(!trackerp || !sepp || !address)
    {
        return FLOW_ENULL;
    }

    ret = scoreboard_find(&trackerp->table_active, address, sepp);
    
    if(ret == FLOW_NOTFOUND)
    {
        // flow_printf(stdout, "address was not found :(");
        /* the find failed -- look it up in the
         * scanner table */
        ret = scoreboard_find(&trackerp->table_scanner, address, sepp);
    }

    return ret;
}