ofl_err ofl_structs_packet_queue_unpack(struct ofp_packet_queue *src, size_t *len, struct ofl_packet_queue **dst, char *errbuf) { struct ofl_packet_queue *q; struct ofp_queue_prop_header *prop; ofl_err error; size_t i; if (*len < ntohs(src->len)) { if (errbuf != NULL) { snprintf(errbuf, OFL_ERRBUF_SIZE, "Received packet queue has invalid length (%zu).", *len); } return ofl_error(OFPET_BAD_ACTION, OFPBRC_BAD_LEN); } *len -= sizeof(struct ofp_packet_queue); q = (struct ofl_packet_queue *)malloc(sizeof(struct ofl_packet_queue)); q->queue_id = ntohl(src->queue_id); error = ofl_utils_count_ofp_queue_props((uint8_t *)src->properties, *len, &q->properties_num, errbuf); if (error) { free(q); return error; } q->properties = (struct ofl_queue_prop_header **)malloc(q->properties_num * sizeof(struct ofl_queue_prop_header *)); prop = src->properties; for (i = 0; i < q->properties_num; i++) { ofl_structs_queue_prop_unpack(prop, len, &(q->properties[i]), errbuf); //TODO error prop = (struct ofp_queue_prop_header *)((uint8_t *)prop + ntohs(prop->len)); } *dst = q; return 0; }
ofl_err ofl_structs_packet_queue_unpack(struct ofp_packet_queue *src, size_t *len, struct ofl_packet_queue **dst) { struct ofl_packet_queue *q; struct ofp_queue_prop_header *prop; ofl_err error; size_t i; if (*len < ntohs(src->len)) { OFL_LOG_WARN(LOG_MODULE, "Received packet queue has invalid length (%zu).", *len); return ofl_error(OFPET_BAD_ACTION, OFPBRC_BAD_LEN); } *len -= sizeof(struct ofp_packet_queue); q = (struct ofl_packet_queue *)malloc(sizeof(struct ofl_packet_queue)); q->queue_id = ntohl(src->queue_id); error = ofl_utils_count_ofp_queue_props((uint8_t *)src->properties, ntohs(src->len)-sizeof(struct ofp_packet_queue)/**len*/, &q->properties_num); if (error) { free(q); return error; } q->properties = (struct ofl_queue_prop_header **)malloc(q->properties_num * sizeof(struct ofl_queue_prop_header *)); prop = src->properties; for (i = 0; i < q->properties_num; i++) { ofl_structs_queue_prop_unpack(prop, len, &(q->properties[i])); prop = (struct ofp_queue_prop_header *)((uint8_t *)prop + ntohs(prop->len)); } *dst = q; return 0; }