Exemple #1
0
static inline lagopus_result_t
policer_attr_create(policer_attr_t **attr) {
  lagopus_result_t rc;

  if (attr == NULL) {
    return LAGOPUS_RESULT_INVALID_ARGS;
  }

  if (*attr != NULL) {
    policer_attr_destroy(*attr);
    *attr = NULL;
  }

  if ((*attr = (policer_attr_t *) malloc(sizeof(policer_attr_t)))
      == NULL) {
    return LAGOPUS_RESULT_NO_MEMORY;
  }

  (*attr)->bandwidth_limit = DEFAULT_BANDWIDTH_LIMIT;
  (*attr)->burst_size_limit = DEFAULT_BURST_SIZE_LIMIT;
  (*attr)->bandwidth_percent = DEFAULT_BANDWIDTH_PERCENT;
  (*attr)->action_names = NULL;
  rc = datastore_names_create(&((*attr)->action_names));
  if (rc != LAGOPUS_RESULT_OK) {
    goto error;
  }

  return LAGOPUS_RESULT_OK;

error:
  datastore_names_destroy((*attr)->action_names);
  free((void *) *attr);
  *attr = NULL;
  return rc;
}
Exemple #2
0
static inline void
policer_attr_destroy(policer_attr_t *attr) {
  if (attr != NULL) {
    datastore_names_destroy(attr->action_names);
    free((void *) attr);
  }
}
Exemple #3
0
lagopus_result_t
datastore_names_create(datastore_name_info_t **names) {
  if (names == NULL) {
    return LAGOPUS_RESULT_INVALID_ARGS;
  }

  if (*names != NULL) {
    datastore_names_destroy(*names);
    *names = NULL;
  }

  if ((*names = (datastore_name_info_t *) malloc(sizeof(datastore_name_info_t)))
      == NULL) {
    return LAGOPUS_RESULT_NO_MEMORY;
  }
  (*names)->size = 0;
  TAILQ_INIT(&((*names)->head));

  return LAGOPUS_RESULT_OK;
}