Пример #1
0
static void
add_request(ipmi_packet_data_t * data, const ipmi_header_t * hdr)
{
	/* get current frame */
	ipmi_frame_data_t * rq_frame = data->curr_frame;

	/* get current command data */
	ipmi_cmd_data_t * rq_data = rq_frame->cmd_data[data->curr_level];

	/* check if parse response for the first time */
	if (!rq_data) {
		ipmi_request_t * rq;

		/* allocate command data */
		rq_data = wmem_new0(wmem_file_scope(), ipmi_cmd_data_t);

		/* set command data pointer */
		rq_frame->cmd_data[data->curr_level] = rq_data;

		/* allocate request data */
		rq = wmem_new0(wmem_file_scope(), ipmi_request_t);

		/* copy request header */
		memcpy(&rq->hdr, hdr, sizeof(rq->hdr));

		/* override context, channel and direction */
		rq->hdr.context = 0;
		rq->hdr.channel = data->curr_channel;
		rq->hdr.dir = data->curr_dir;

		/* set request frame number */
		rq->frame_num = data->curr_frame_num;

		/* set command nest level */
		rq->nest_level = data->curr_level;

		/* append request to list */
		wmem_list_append(data->request_list, rq);

#ifdef DEBUG
	fprintf(stderr, "%d, %d: hdr : {\n"
			"\tchannel=%d\n"
			"\tdir=%d\n"
			"\trs_sa=%x\n"
			"\trs_lun=%d\n"
			"\tnetfn=%x\n"
			"\trq_sa=%x\n"
			"\trq_lun=%d\n"
			"\trq_seq=%x\n"
			"\tcmd=%x\n}\n",
			data->curr_frame_num, data->curr_level,
			rq->hdr.channel, rq->hdr.dir, rq->hdr.rs_sa, rq->hdr.rs_lun,
			rq->hdr.netfn, rq->hdr.rq_sa, rq->hdr.rq_lun, rq->hdr.rq_seq,
			rq->hdr.cmd);
#endif
	}
}
Пример #2
0
static lbttcp_client_transport_t * lbttcp_client_transport_add(lbttcp_transport_t * transport, const address * receiver_address, guint16 receiver_port, guint32 frame)
{
    lbttcp_client_transport_t * entry;
    conversation_t * client_conv = NULL;
    wmem_tree_t * session_tree = NULL;

    if (transport == NULL)
    {
        return (NULL);
    }
    entry = lbttcp_client_transport_find(transport, receiver_address, receiver_port, frame);
    if (entry != NULL)
    {
        return (entry);
    }
    entry = wmem_new(wmem_file_scope(), lbttcp_client_transport_t);
    copy_address_wmem(wmem_file_scope(), &(entry->receiver_address), receiver_address);
    entry->receiver_port = receiver_port;
    entry->id = transport->next_client_id++;

    /* See if a conversation for this address/port pair exists. */
    client_conv = find_conversation(frame, &(transport->source_address), receiver_address, PT_TCP, transport->source_port, receiver_port, 0);
    if (client_conv == NULL)
    {
        client_conv = conversation_new(frame, &(transport->source_address), receiver_address, PT_TCP, transport->source_port, receiver_port, 0);
        session_tree = wmem_tree_new(wmem_file_scope());
        conversation_add_proto_data(client_conv, proto_lbttcp, (void *) session_tree);
    }
    session_tree = (wmem_tree_t *) conversation_get_proto_data(client_conv, proto_lbttcp);
    if (session_tree == NULL)
    {
        session_tree = wmem_tree_new(wmem_file_scope());
        conversation_add_proto_data(client_conv, proto_lbttcp, (void *) session_tree);
    }
    wmem_tree_insert32(session_tree, transport->session_id, (void *) entry);

    /* Add this client to the transport. */
    wmem_list_append(transport->client_list, (void *) entry);
    return (entry);
}
Пример #3
0
static void
wmem_test_list(void)
{
    wmem_allocator_t  *allocator;
    wmem_list_t       *list;
    wmem_list_frame_t *frame;
    unsigned int       i;

    allocator = wmem_allocator_new(WMEM_ALLOCATOR_STRICT);

    list = wmem_list_new(allocator);
    g_assert(list);
    g_assert(wmem_list_count(list) == 0);

    frame = wmem_list_head(list);
    g_assert(frame == NULL);

    for (i=0; i<CONTAINER_ITERS; i++) {
        wmem_list_prepend(list, GINT_TO_POINTER(i));
        g_assert(wmem_list_count(list) == i+1);

        frame = wmem_list_head(list);
        g_assert(frame);
        g_assert(wmem_list_frame_data(frame) == GINT_TO_POINTER(i));
    }
    wmem_strict_check_canaries(allocator);

    i = CONTAINER_ITERS - 1;
    frame = wmem_list_head(list);
    while (frame) {
        g_assert(wmem_list_frame_data(frame) == GINT_TO_POINTER(i));
        i--;
        frame = wmem_list_frame_next(frame);
    }

    i = 0;
    frame = wmem_list_tail(list);
    while (frame) {
        g_assert(wmem_list_frame_data(frame) == GINT_TO_POINTER(i));
        i++;
        frame = wmem_list_frame_prev(frame);
    }

    i = CONTAINER_ITERS - 2;
    while (wmem_list_count(list) > 1) {
        wmem_list_remove(list, GINT_TO_POINTER(i));
        i--;
    }
    wmem_list_remove(list, GINT_TO_POINTER(CONTAINER_ITERS - 1));
    g_assert(wmem_list_count(list) == 0);
    g_assert(wmem_list_head(list) == NULL);
    g_assert(wmem_list_tail(list) == NULL);

    for (i=0; i<CONTAINER_ITERS; i++) {
        wmem_list_append(list, GINT_TO_POINTER(i));
        g_assert(wmem_list_count(list) == i+1);

        frame = wmem_list_head(list);
        g_assert(frame);
    }
    wmem_strict_check_canaries(allocator);

    i = 0;
    frame = wmem_list_head(list);
    while (frame) {
        g_assert(wmem_list_frame_data(frame) == GINT_TO_POINTER(i));
        i++;
        frame = wmem_list_frame_next(frame);
    }

    i = CONTAINER_ITERS - 1;
    frame = wmem_list_tail(list);
    while (frame) {
        g_assert(wmem_list_frame_data(frame) == GINT_TO_POINTER(i));
        i--;
        frame = wmem_list_frame_prev(frame);
    }

    wmem_destroy_allocator(allocator);

    list = wmem_list_new(NULL);
    for (i=0; i<CONTAINER_ITERS; i++) {
        wmem_list_prepend(list, GINT_TO_POINTER(i));
    }
    g_assert(wmem_list_count(list) == CONTAINER_ITERS);
    wmem_destroy_list(list);
}