static lagopus_result_t
s_ofp_header_create_wrap(struct channel *channel,
                         struct pbuf **pbuf,
                         struct ofp_header *xid_header) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct ofp_header header;
  struct pbuf *ret_pbuf = NULL;
  if (pbuf == NULL) {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  } else {
    ret_pbuf = pbuf_alloc(65535);
    if (ret_pbuf == NULL) {
      ret = LAGOPUS_RESULT_NO_MEMORY;
    } else {
      ret_pbuf->plen = s_plen;
      ret = ofp_header_create(channel, s_type, xid_header, &header, ret_pbuf);
      if (ret == LAGOPUS_RESULT_OK) {
        *pbuf = ret_pbuf;
      } else {
        pbuf_free(ret_pbuf);
        *pbuf = NULL;
      }
    }
  }
  return ret;
}
示例#2
0
lagopus_result_t
ofp_header_packet_set(struct channel *channel,
                      struct pbuf *pbuf) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  uint16_t cur_length;
  pbuf_info_t cur_pbuf_info;
  pbuf_info_t update_pbuf_info;
  struct ofp_header header;

  if (channel != NULL && pbuf != NULL) {
    /* Store current pbuf info. */
    pbuf_info_store(pbuf, &cur_pbuf_info);
    ret = pbuf_length_get(pbuf, &cur_length);

    if (ret == LAGOPUS_RESULT_OK) {
      /* Update pbuf info for ofp_header_decode_sneak. */
      pbuf_getp_set(&update_pbuf_info, pbuf_data_get(pbuf));
      pbuf_putp_set(&update_pbuf_info,
                    pbuf_data_get(pbuf) + sizeof(struct ofp_header));
      pbuf_plen_set(&update_pbuf_info, sizeof(struct ofp_header));
      pbuf_info_load(pbuf, &update_pbuf_info);

      ret = ofp_header_decode_sneak(pbuf, &header);
      if (ret == LAGOPUS_RESULT_OK) {
        /* Update pbuf info for ofp_header_create. */
        pbuf_reset(pbuf);
        pbuf_plen_set(pbuf, (size_t) cur_length);

        ret = ofp_header_create(channel, header.type, NULL,
                                &header, pbuf);
        if (ret == LAGOPUS_RESULT_OK) {
          /* Load pbuf info. */
          pbuf_info_load(pbuf, &cur_pbuf_info);
        } else {
          lagopus_msg_warning("FAILED (%s).\n",
                              lagopus_error_get_string(ret));
        }
      } else {
        lagopus_msg_warning("FAILED (%s).\n",
                            lagopus_error_get_string(ret));
      }
    } else {
      lagopus_msg_warning("FAILED (%s).\n",
                          lagopus_error_get_string(ret));
    }
  } else {
    return LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}