예제 #1
0
파일: pci.c 프로젝트: msune/irati
struct pci * pci_create_from_gfp(gfp_t        flags,
                                 const void * data)
{
        struct pci * tmp;

        if (!data)
                return NULL;

        tmp = rkmalloc(sizeof(*tmp), flags);
        if (!tmp)
                return NULL;

        if (!memcpy(tmp, data, sizeof(*tmp))) {
                rkfree(tmp);
                return NULL;
        }

        if (!pci_is_ok(tmp)) {
                LOG_ERR("Cannot create PCI from bad data");
                rkfree(tmp);
                return NULL;
        }

        return tmp;
}
예제 #2
0
파일: serdes.c 프로젝트: msune/irati
int serdes_destroy(struct serdes * instance)
{
        if (!instance)
                return -1;

        if (instance->dt_cons)
                rkfree(instance->dt_cons);

        rkfree(instance);

        return 0;
}
예제 #3
0
static void
rmt_ps_default_destroy(struct ps_base * bps)
{
        struct rmt_ps *ps = container_of(bps, struct rmt_ps, base);
        struct rmt_ps_data * data = ps->priv;

        if (bps) {
                if (data) {
                        if (data->ss)    rkfree(data->ss);
                        if (data->outqs) rmt_queue_set_destroy(data->outqs);
                        rkfree(data);
                }
                rkfree(ps);
        }
}
예제 #4
0
파일: rmt-ps-cas.c 프로젝트: IRATI/stack
static struct cas_rmt_queue * cas_queue_create(port_id_t port_id)
{
        struct cas_rmt_queue * tmp;
        tmp = rkzalloc(sizeof(*tmp), GFP_ATOMIC);
        if (!tmp)
                return NULL;
        tmp->queue = rfifo_create_ni();
        if (!tmp->queue) {
                rkfree(tmp);
                return NULL;
        }

        tmp->port_id                                    = port_id;
        tmp->reg_cycles.prev_cycle.t_start.tv_sec       = 0;
        tmp->reg_cycles.prev_cycle.t_start.tv_nsec      = 0;
        tmp->reg_cycles.prev_cycle.t_last_start.tv_sec  = 0;
        tmp->reg_cycles.prev_cycle.t_last_start.tv_nsec = 0;
        tmp->reg_cycles.prev_cycle.t_end.tv_sec         = 0;
        tmp->reg_cycles.prev_cycle.t_end.tv_nsec        = 0;
        tmp->reg_cycles.prev_cycle.sum_area             = 0;
        tmp->reg_cycles.prev_cycle.avg_len              = 0;
        tmp->reg_cycles.cur_cycle                       = tmp->reg_cycles.prev_cycle;
	tmp->first_run                                  = true;

        return tmp;
}
예제 #5
0
int conn_policies_destroy(struct conn_policies * cp_params)
{
        int retval = 0;

        if (!cp_params)
                return -1;

        if (cp_params->dtcp_cfg)
                if (dtcp_config_destroy(cp_params->dtcp_cfg))
                        retval = -1;

        if (cp_params->initial_sequence_number)
                if (policy_destroy(cp_params->initial_sequence_number))
                        retval = -1;

        if (cp_params->receiver_inactivity_timer)
                if (policy_destroy(cp_params->receiver_inactivity_timer))
                        retval = -1;

        if (cp_params->sender_inactivity_timer)
                if (policy_destroy(cp_params->sender_inactivity_timer))
                        retval = -1;

        rkfree(cp_params);
        return retval;
}
예제 #6
0
int connection_destroy(struct connection * conn)
{
        if (!conn)
                return -1;

        /* FIXME: The following FIXME should be now obsolete */

        /* FIXME: Here we should make sure that all the asynchronous users
         * of this connection (e.g. workqueues in the normal ipcp
         * implementation) are stopped before proceeding to destroy the
         * connection object. Setting the pointer to NULL is a workaround
         * to minimize the likelyhood of accessing dellocated memory.
         * This should be done with reference counting or locking.
         */

        if (conn->policies_params) {
                if (conn_policies_destroy(conn->policies_params))
                        return -1;
                conn->policies_params = NULL; /* FIXME: Workaround */
        }

        rkfree(conn);

        return 0;
}
예제 #7
0
파일: shm.c 프로젝트: Enextuse/RTAI
static inline void *_rt_shm_alloc(unsigned long name, int size, int suprt)
{
	void *adr;

//	suprt = USE_GFP_ATOMIC; // to force some testing
	if (!(adr = rt_get_adr_cnt(name)) && size > 0 && suprt >= 0 && RT_SHM_OP_PERM())
	{
		size = ((size - 1) & PAGE_MASK) + PAGE_SIZE;
		if ((adr = suprt ? rkmalloc(&size, SUPRT[suprt]) : rvmalloc(size)))
		{
			if (!rt_register(name, adr, suprt ? -size : size, 0))
			{
				if (suprt)
				{
					rkfree(adr, size);
				}
				else
				{
					rvfree(adr, size);
				}
				return 0;
			}
			memset(ALIGN2PAGE(adr), 0, size);
		}
	}
	return ALIGN2PAGE(adr);
}
예제 #8
0
파일: ps.c 프로젝트: javiergll/stack
static void rmt_ps_skeleton_destroy(struct ps_base * bps)
{
    struct rmt_ps *ps = container_of(bps, struct rmt_ps, base);

    if (bps) {
        rkfree(ps);
    }
}
예제 #9
0
static void dtp_ps_default_destroy(struct ps_base * bps)
{
        struct dtp_ps *ps = container_of(bps, struct dtp_ps, base);

        if (bps) {
                rkfree(ps);
        }
}
예제 #10
0
파일: pci.c 프로젝트: msune/irati
int pci_destroy(struct pci * pci)
{
        if (!pci)
                return -1;

        rkfree(pci);
        return 0;
}
예제 #11
0
파일: rbmp.c 프로젝트: IRATI/stack
int rbmp_destroy(struct rbmp * b)
{
        if (!b)
                return -1;

        rkfree(b);

        return 0;
}
예제 #12
0
static struct ps_base *
rmt_ps_default_create(struct rina_component * component)
{
        struct rmt * rmt = rmt_from_component(component);
        struct rmt_ps * ps = rkzalloc(sizeof(*ps), GFP_KERNEL);
        struct rmt_ps_data * data = rkzalloc(sizeof(*data), GFP_KERNEL);

        if (!ps || !data) {
                return NULL;
        }

        /* Allocate policy-set private data. */
        data->ss = rkzalloc(sizeof(*data->ss), GFP_KERNEL);
        if (!data->ss) {
                rkfree(ps);
                rkfree(data);
                return NULL;
        }
        data->outqs = rmt_queue_set_create();
        if (!data->outqs) {
                rkfree(data->ss);
                rkfree(ps);
                rkfree(data);
                return NULL;
        }
        ps->priv = data;

        ps->base.set_policy_set_param = rmt_ps_set_policy_set_param;
        ps->dm          = rmt;

        ps->max_q_policy_tx                  = default_max_q_policy_tx;
        ps->max_q_policy_rx                  = default_max_q_policy_rx;
        ps->rmt_q_monitor_policy_tx          = default_rmt_q_monitor_policy_tx;
        ps->rmt_q_monitor_policy_rx          = default_rmt_q_monitor_policy_rx;
        ps->rmt_next_scheduled_policy_tx     = default_rmt_next_scheduled_policy_tx;
        ps->rmt_enqueue_scheduling_policy_tx = default_rmt_enqueue_scheduling_policy_tx;
        ps->rmt_scheduling_policy_rx         = default_rmt_scheduling_policy_rx;
        ps->rmt_scheduling_create_policy_tx  = default_rmt_scheduling_create_policy_tx;
        ps->rmt_scheduling_destroy_policy_tx = default_rmt_scheduling_destroy_policy_tx;

        return &ps->base;
}
예제 #13
0
파일: rmt-ps-cas.c 프로젝트: IRATI/stack
static void rmt_ps_cas_destroy(struct ps_base * bps)
{
        struct rmt_ps *          ps = container_of(bps, struct rmt_ps, base);
        struct cas_rmt_ps_data * data;

        data = ps->priv;

        if (!ps || !data) {
                LOG_ERR("PS or PS Data to destroy");
                return;
        }

        if (bps) {

                if (data) {
                        rkfree(data);
                }
                rkfree(ps);
        }
}
예제 #14
0
struct conn_policies * conn_policies_create(void)
{
        struct conn_policies * tmp;

        tmp = rkzalloc(sizeof(*tmp), GFP_KERNEL);
        if (!tmp)
                return NULL;

        tmp->dtcp_cfg = dtcp_config_create();
        if (!tmp->dtcp_cfg) {
                LOG_ERR("Could not create dtcp_config");
                rkfree(tmp);
                return NULL;
        }

        tmp->initial_sequence_number = policy_create();
        if (!tmp->initial_sequence_number) {
                LOG_ERR("Could not create initial_sequence_number");
                dtcp_config_destroy(tmp->dtcp_cfg);
                rkfree(tmp);
                return NULL;
        }

        tmp->receiver_inactivity_timer = policy_create();
        if (!tmp->receiver_inactivity_timer) {
                LOG_ERR("Could not create receiver_inactivity_timer policy");
                dtcp_config_destroy(tmp->dtcp_cfg);
                rkfree(tmp);
                return NULL;
        }

        tmp->sender_inactivity_timer = policy_create();
        if (!tmp->sender_inactivity_timer) {
                LOG_ERR("Could not create sender_inactivity_timer policy");
                dtcp_config_destroy(tmp->dtcp_cfg);
                rkfree(tmp);
                return NULL;
        }

        return tmp;
}
예제 #15
0
파일: pdu-ser.c 프로젝트: shinrs20/stack
int pdu_ser_destroy(struct pdu_ser * pdu)
{
    if (!pdu)
        return -1;

    if (pdu->buf)
        buffer_destroy(pdu->buf);

    rkfree(pdu);

    return 0;
}
예제 #16
0
파일: pdu.c 프로젝트: javiergll/stack
int pdu_destroy(struct pdu * p)
{
        if (!p)
                return -1;

        if (p->pci)    pci_destroy(p->pci);
        if (p->buffer) buffer_destroy(p->buffer);

        rkfree(p);

        return 0;
}
예제 #17
0
파일: rmt-ps-cas.c 프로젝트: IRATI/stack
static int cas_rmt_queue_destroy(struct cas_rmt_queue * q)
{
        if (!q) {
                LOG_ERR("No RMT Key-queue to destroy...");
                return -1;
        }

        if (q->queue) rfifo_destroy(q->queue, (void (*)(void *)) du_destroy);

        rkfree(q);

        return 0;
}
예제 #18
0
파일: pff.c 프로젝트: IRATI/stack
int pff_destroy(struct pff * instance)
{
        if (!__pff_is_ok(instance))
                return -1;

	if (instance->rset)
		rset_unregister(instance->rset);

        rina_component_fini(&instance->base);

        rkfree(instance);

        return 0;
}
예제 #19
0
static inline int _rt_shm_free(unsigned long name, int size)
{
	void *adr;

	if (size && (adr = rt_get_adr(name))) {
		if (RT_SHM_OP_PERM()) {
			if (!rt_drg_on_name_cnt(name) && name != GLOBAL_HEAP_ID) {
				if (size < 0) {
					rkfree(adr, -size);
				} else {
					rvfree(adr, size);
				}
			}
		}
		return abs(size);
	}
	return 0;
}
예제 #20
0
int ipcpf_unregister(struct ipcp_factories * factories,
                     struct ipcp_factory *   factory)
{
        struct ipcp_factory * tmp;
        const char *          name;

        if (!factories) {
                LOG_ERR("Bogus parent, cannot unregister factory");
                return -1;
        }

        if (!factory) {
                LOG_ERR("Bogus factory, cannot unregister");
                return -1;
        }

        name = kobject_name(&factory->kobj);
        ASSERT(string_is_ok(name));

        LOG_DBG("Unregistering factory '%s'", name);

        ASSERT(factories);

        tmp = ipcpf_find(factories, name);
        if (!tmp) {
                LOG_ERR("Cannot find factory '%s'", name);
                return -1;
        }

        ASSERT(tmp == factory);

        if (tmp->ops->fini(factory->data)) {
                LOG_ERR("Cannot finalize factory '%s'", name);
        }

        kobject_del(&factory->kobj);
        kobject_put(&factory->kobj);

        rkfree(factory);

        LOG_DBG("IPCP unregistered successfully");

        return 0;
}
예제 #21
0
int ipcpf_fini(struct ipcp_factories * factories)
{
        LOG_DBG("Finalizing layer");

        if (!factories) {
                LOG_ERR("Bogus parameter, cannot finalize");
                return -1;
        }

        /* All thetemplates have to be unregistered from now on */
        ASSERT(list_empty(&factories->set->list));

        kset_unregister(factories->set);

        rkfree(factories);

        LOG_DBG("Layer finalized successfully");

        return 0;
}
예제 #22
0
파일: pci.c 프로젝트: msune/irati
struct pci * pci_dup_gfp(gfp_t              flags,
                         const struct pci * pci)
{
        struct pci * tmp;

        if (!pci_is_ok(pci))
                return NULL;

        tmp = rkmalloc(sizeof(*tmp), flags);
        if (!tmp)
                return NULL;

        if (!memcpy(tmp, pci, sizeof(*tmp))) {
                rkfree(tmp);
                return NULL;
        }

        ASSERT(pci_is_ok(tmp));

        return tmp;
}
예제 #23
0
파일: serdes.c 프로젝트: shinrs20/stack
static struct pdu_ser * pdu_serialize_gfp(gfp_t                       flags,
                                          const const struct serdes * instance,
                                          struct pdu *                pdu,
                                          struct dup_config_entry   * dup_conf,
                                          struct crypto_blkcipher   * blkcipher)
{
        struct pdu_ser *      tmp;
        struct dt_cons *      dt_cons;
        const void *          buffer_data;
        const struct buffer * buffer;
        const struct pci *    pci;
        size_t                size;
        ssize_t               buffer_size;
        ssize_t               blk_size;
        ssize_t               encrypted_size;
        ssize_t               pci_size;
        char *                data;
        pdu_type_t            pdu_type;
        seq_num_t             seq;
        struct buffer *       buf;
        int i;

        if (!pdu_is_ok(pdu))
                return NULL;

        if (!instance)
                return NULL;

        dt_cons = instance->dt_cons;
        ASSERT(dt_cons);

        buffer = pdu_buffer_get_ro(pdu);
        if (!buffer)
                return NULL;

        buffer_data = buffer_data_ro(buffer);
        if (!buffer_data)
                return NULL;

        buffer_size = buffer_length(buffer);
        if (buffer_size <= 0)
                return NULL;

        pci = pdu_pci_get_ro(pdu);
        if (!pci)
                return NULL;

        pdu_type = pci_type(pci);
        if (!pdu_type_is_ok(pdu_type)) {
                LOG_ERR("Wrong PDU type");
                return NULL;
        }

        /* Base PCI size, fields present in all PDUs */
        pci_size = base_pci_size(dt_cons);

        /*
         * These are available in the stack at this point in time
         * Extend if necessary (e.g.) NACKs, SACKs, ...
         * Set size in first switch/case
         */
        switch (pdu_type) {
        case PDU_TYPE_MGMT:
        case PDU_TYPE_DT:
                size = pci_size + dt_cons->seq_num_length + buffer_size;

                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_FC:
                size = pci_size + CTRL_SEQ_NR + fc_pci_size(dt_cons);
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_ACK:
                size = pci_size + CTRL_SEQ_NR + dt_cons->seq_num_length;
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_ACK_AND_FC:
                size = pci_size +
                        CTRL_SEQ_NR +
                        fc_pci_size(dt_cons) +
                        dt_cons->seq_num_length;
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_CACK:
                size = pci_size +
                        2 * CTRL_SEQ_NR +
                        4 * dt_cons->seq_num_length +
                        RATE_LEN;
                if (size <= 0)
                        return NULL;

                break;
        default:
                LOG_ERR("Unknown PDU type %02X", pdu_type);
                return NULL;
        }

        data = rkmalloc(size, flags);
        if (!data)
                return NULL;

        /* Needed for all PDUs */
        if (serialize_base_pci(instance, data, pci, size)) {
                LOG_ERR("Failed to serialize base PCI");
                rkfree(data);
                return NULL;
        }

        /* Do actual serializing in the second switch case */
        switch (pdu_type) {
        case PDU_TYPE_MGMT:
        case PDU_TYPE_DT:
                seq = pci_sequence_number_get(pci);
                memcpy(data + pci_size, &seq, dt_cons->seq_num_length);

                memcpy(data + pci_size + dt_cons->seq_num_length,
                       buffer_data, buffer_size);

                break;
        case PDU_TYPE_FC:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_fc_pci(instance, data, pci,
                                     pci_size + CTRL_SEQ_NR)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        case PDU_TYPE_ACK:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_ack_pci(instance, data, pci,
                                      pci_size + CTRL_SEQ_NR)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        case PDU_TYPE_ACK_AND_FC:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_ack_pci(instance, data, pci,
                                      pci_size + CTRL_SEQ_NR) ||
                    serialize_fc_pci(instance, data, pci,
                                     pci_size +
                                     CTRL_SEQ_NR +
                                     dt_cons->seq_num_length)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        case PDU_TYPE_CACK:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_cc_pci(instance, data, pci,
                                     pci_size + CTRL_SEQ_NR)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        default:
                LOG_ERR("Unknown PDU type %02X", pdu_type);
                return NULL;
        }

        buf = buffer_create_with_gfp(flags, data, size);
        if (!buf) {
                rkfree(data);
                return NULL;
        }

        tmp = pdu_ser_create_buffer_with_gfp(flags, buf);
        if (!tmp) {
                rkfree(buf);
                return NULL;
        }

        /* FIXME: this should be moved to specific policy code */
        if (dup_conf != NULL && dup_conf->ttl_policy != NULL){
            if (pdu_ser_head_grow_gfp(flags, tmp, sizeof(u8))) {
                    LOG_ERR("Failed to grow ser PDU");
                    pdu_ser_destroy(tmp);
                    return NULL;
            }

            if (!dup_ttl_set(tmp, pci_ttl(pci))) {
                    LOG_ERR("Could not set TTL");
                    pdu_ser_destroy(tmp);
                    return NULL;
            }

            if (dup_ttl_is_expired(tmp)) {
                    LOG_DBG("TTL is expired, dropping PDU");
                    pdu_ser_destroy(tmp);
                    return NULL;
            }
        }

        /* FIXME: this should be moved to specific policy code */
        if (blkcipher != NULL && dup_conf != NULL
        		&& dup_conf->enable_encryption){
                buf = pdu_ser_buffer(tmp);
                blk_size = crypto_blkcipher_blocksize(blkcipher);
                buffer_size = buffer_length(buf);
                encrypted_size = (buffer_size/blk_size + 1) * blk_size;

                if (pdu_ser_tail_grow_gfp(tmp, encrypted_size - buffer_size)){
                    LOG_ERR("Failed to grow ser PDU");
                    pdu_ser_destroy(tmp);
                    return NULL;
                }

                /* PADDING */
                data = buffer_data_rw(buf);
                for (i=encrypted_size-1; i>buffer_size; i--){
                    data[i] = encrypted_size - buffer_size;
                }

                /* Encrypt */
                if (!dup_encrypt_data(tmp, blkcipher)) {
                	LOG_ERR("Failed to encrypt PDU");
                	pdu_ser_destroy(tmp);
                	return NULL;
                }
        }

        /* FIXME: this should be moved to specific policy code */
        if (dup_conf != NULL && dup_conf->error_check_policy != NULL){
            /* Assuming CRC32 */
            if (pdu_ser_head_grow_gfp(flags, tmp, sizeof(u32))) {
                    LOG_ERR("Failed to grow ser PDU");
                    pdu_ser_destroy(tmp);
                    return NULL;
            }

            if (!dup_chksum_set(tmp)) {
                    LOG_ERR("Failed to add CRC");
                    pdu_ser_destroy(tmp);
                    return NULL;
            }

            ASSERT(dup_chksum_is_ok(tmp));
        }

        return tmp;
}
예제 #24
0
struct ipcp_factory * ipcpf_register(struct ipcp_factories *         factories,
                                     const char *                    name,
                                     struct ipcp_factory_data *      data,
                                     const struct ipcp_factory_ops * ops)
{
        struct ipcp_factory * factory;

        LOG_DBG("Registering new factory");

        if (!string_is_ok(name)) {
                LOG_ERR("Name is bogus, cannot register factory");
                return NULL;
        }

        if (!ops_are_ok(ops)) {
                LOG_ERR("Cannot register factory '%s', ops are bogus", name);
                return NULL;
        }

        if (!factories) {
                LOG_ERR("Bogus parent, cannot register factory '%s", name);
                return NULL;
        }

        factory = ipcpf_find(factories, name);
        if (factory) {
                LOG_ERR("Factory '%s' already registered", name);
                return NULL;
        }

        LOG_DBG("Registering factory '%s'", name);

        factory = rkzalloc(sizeof(*factory), GFP_KERNEL);
        if (!factory)
                return NULL;

        factory->data      = data;
        factory->ops       = ops;
        factory->kobj.kset = factories->set;
        if (kobject_init_and_add(&factory->kobj, &ipcp_factory_ktype, NULL,
                                 "%s", name)) {
                LOG_ERR("Cannot add factory '%s' to the set", name);
                kobject_put(&factory->kobj);

                rkfree(factory);
                return NULL;
        }

        if (factory->ops->init(factory->data)) {
                LOG_ERR("Cannot initialize factory '%s'", name);
                kobject_put(&factory->kobj);
                rkfree(factory);
                return NULL;
        }

        /* Double checking for bugs */
        LOG_INFO("Factory '%s' registered successfully",
                 kobject_name(&factory->kobj));

        return factory;
}
예제 #25
0
파일: serdes.c 프로젝트: msune/irati
static struct pdu_ser * pdu_serialize_gfp(gfp_t                       flags,
                                          const const struct serdes * instance,
                                          struct pdu *                pdu)
{
        struct pdu_ser *      tmp;
        struct dt_cons *      dt_cons;
        const void *          buffer_data;
        const struct buffer * buffer;
        const struct pci *    pci;
        size_t                size;
        ssize_t               buffer_size;
        ssize_t               pci_size;
        char *                data;
        pdu_type_t            pdu_type;
        seq_num_t             seq;
        struct buffer *       buf;

        if (!pdu_is_ok(pdu))
                return NULL;

        if (!instance)
                return NULL;

        dt_cons = instance->dt_cons;
        ASSERT(dt_cons);

        buffer = pdu_buffer_get_ro(pdu);
        if (!buffer)
                return NULL;

        buffer_data = buffer_data_ro(buffer);
        if (!buffer_data)
                return NULL;

        buffer_size = buffer_length(buffer);
        if (buffer_size <= 0)
                return NULL;

        pci = pdu_pci_get_ro(pdu);
        if (!pci)
                return NULL;

        pdu_type = pci_type(pci);
        if (!pdu_type_is_ok(pdu_type)) {
                LOG_ERR("Wrong PDU type");
                return NULL;
        }

        /* Base PCI size, fields present in all PDUs */
        pci_size = base_pci_size(dt_cons);

        /*
         * These are available in the stack at this point in time
         * Extend if necessary (e.g.) NACKs, SACKs, ...
         * Set size in first switch/case
         */
        switch (pdu_type) {
        case PDU_TYPE_MGMT:
        case PDU_TYPE_DT:
                size = pci_size + dt_cons->seq_num_length + buffer_size;
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_FC:
                size = pci_size + CTRL_SEQ_NR + fc_pci_size(dt_cons);
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_ACK:
                size = pci_size + CTRL_SEQ_NR + dt_cons->seq_num_length;
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_ACK_AND_FC:
                size = pci_size +
                        CTRL_SEQ_NR +
                        fc_pci_size(dt_cons) +
                        dt_cons->seq_num_length;
                if (size <= 0)
                        return NULL;

                break;
        case PDU_TYPE_CC:
                size = pci_size +
                        2 * CTRL_SEQ_NR +
                        4 * dt_cons->seq_num_length +
                        RATE_LEN;
                if (size <= 0)
                        return NULL;

                break;
        default:
                LOG_ERR("Unknown PDU type %02X", pdu_type);
                return NULL;
        }

        data = rkmalloc(size, flags);
        if (!data)
                return NULL;

        /* Needed for all PDUs */
        if (serialize_base_pci(instance, data, pci, size)) {
                LOG_ERR("Failed to serialize base PCI");
                rkfree(data);
                return NULL;
        }

        /* Do actual serializing in the second switch case */
        switch (pdu_type) {
        case PDU_TYPE_MGMT:
        case PDU_TYPE_DT:
                seq = pci_sequence_number_get(pci);
                memcpy(data + pci_size, &seq, dt_cons->seq_num_length);

                memcpy(data + pci_size + dt_cons->seq_num_length,
                       buffer_data, buffer_size);

                break;
        case PDU_TYPE_FC:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_fc_pci(instance, data, pci,
                                     pci_size + CTRL_SEQ_NR)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        case PDU_TYPE_ACK:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_ack_pci(instance, data, pci,
                                      pci_size + CTRL_SEQ_NR)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        case PDU_TYPE_ACK_AND_FC:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_ack_pci(instance, data, pci,
                                      pci_size + CTRL_SEQ_NR) ||
                    serialize_fc_pci(instance, data, pci,
                                     pci_size +
                                     CTRL_SEQ_NR +
                                     dt_cons->seq_num_length)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        case PDU_TYPE_CC:
                if (serialize_ctrl_seq(instance, data, pci, pci_size) ||
                    serialize_cc_pci(instance, data, pci,
                                     pci_size + CTRL_SEQ_NR)) {
                        rkfree(data);
                        return NULL;
                }

                break;
        default:
                LOG_ERR("Unknown PDU type %02X", pdu_type);
                return NULL;
        }

        buf = buffer_create_with_gfp(flags, data, size);
        if (!buf) {
                rkfree(data);
                return NULL;
        }

        tmp = pdu_ser_create_buffer_with_gfp(flags, buf);
        if (!tmp) {
                rkfree(buf);
                return NULL;
        }

        pdu_destroy(pdu);

        return tmp;
}
예제 #26
0
파일: ps.c 프로젝트: gaixas1/testRINA
/*
 * DESTROY
 */
static void rmt_ps_deltaq_destroy(
		struct ps_base * bps) {

	struct rmt_ps * _ps =
			container_of(bps, struct rmt_ps, base);
	rmtdata_p ps =
			container_of(_ps, struct int_rmt_data, base);

	/*Release buffers*/
	while (ps->bufferST_begin != NULL) {
		t_sizetime_n t = ps->bufferST_begin;
		ps->bufferST_begin = t->next;
		kfree(t);
	}

	while (ps->bufferT_begin != NULL) {
		t_time_n t = ps->bufferT_begin;
		ps->bufferT_begin = t->next;
		kfree(t);
	}

	while (ps->bufferPDU_begin != NULL) {
		t_pdu_n t = ps->bufferPDU_begin;
		ps->bufferPDU_begin = t->next;
		kfree(t);
	}

	/*Release ports data*/
	while (ps->portvals_begin != NULL) {
		t_portvals_n t_port = ps->portvals_begin;

		/*Release Port Qos values*/
		while (t_port->qosvals_begin != NULL) {
			t_qosvals_n t_qos = t_port->qosvals_begin;

			/*Release remaining PDUs. !!should be empty on destroy*/
			while (t_qos->queue_begin != NULL) {
				t_pdu_n t_node = t_qos->queue_begin;
				t_qos->queue_begin = t_node->next;
				kfree(t_node->p);/* Release also pdu data? ask*/
				kfree(t_node);
			}

			/*Release remaining PDUs in time. !!should be empty on destroy*/
			while (t_qos->wtime_begin != NULL) {
				t_time_n t_node = t_qos->wtime_begin;
				t_qos->wtime_begin = t_node->next;
				kfree(t_node);
			}

			/*Release received size/time log for inputLimit*/

			/* Not used, in-drop at EFCP
			/*
			while (t_qos->recivedST_begin != NULL) {
				t_sizetime_n t_node =
						t_qos->recivedST_begin;
				t_qos->recivedST_begin = t_node->next;
				kfree(t_node);
			}
			*/

			/*Release send size/time log for outputLimit*/
			while (t_qos->sendST_begin != NULL) {
				t_sizetime_n t_node = t_qos->sendST_begin;
				t_qos->sendST_begin = t_node->next;
				kfree(t_node);
			}

			t_port->qosvals_begin = t_qos->next;
			kfree(t_qos);
		}

		ps->portvals_begin = t_port->next;
		kfree(t_port);
	}

	if (bps) {
		rkfree(ps);
	}
}