+static int
+qosify_map_create_alias(struct blob_attr *attr)
+{
+ struct qosify_map_alias *alias;
+ enum {
+ MAP_ALIAS_INGRESS,
+ MAP_ALIAS_EGRESS,
+ __MAP_ALIAS_MAX
+ };
+ static const struct blobmsg_policy policy[__MAP_ALIAS_MAX] = {
+ [MAP_ALIAS_INGRESS] = { .type = BLOBMSG_TYPE_STRING },
+ [MAP_ALIAS_EGRESS] = { .type = BLOBMSG_TYPE_STRING },
+ };
+ struct blob_attr *tb[__MAP_ALIAS_MAX];
+ const char *name;
+ char *name_buf;
+
+ if (blobmsg_check_array(attr, BLOBMSG_TYPE_STRING) != 2)
+ return -1;
+
+ blobmsg_parse_array(policy, __MAP_ALIAS_MAX, tb,
+ blobmsg_data(attr), blobmsg_len(attr));
+
+ if (!tb[MAP_ALIAS_INGRESS] || !tb[MAP_ALIAS_EGRESS])
+ return -1;
+
+ name = blobmsg_name(attr);
+ alias = calloc_a(sizeof(*alias), &name_buf, strlen(name) + 1);
+ alias->avl.key = strcpy(name_buf, name);
+ if (__qosify_map_dscp_value(blobmsg_get_string(tb[MAP_ALIAS_INGRESS]),
+ &alias->value.ingress) ||
+ __qosify_map_dscp_value(blobmsg_get_string(tb[MAP_ALIAS_EGRESS]),
+ &alias->value.egress) ||
+ avl_insert(&map_aliases, &alias->avl)) {
+ free(alias);
+ return -1;
+ }
+
+ return 0;
+}
+
+void qosify_map_set_aliases(struct blob_attr *val)
+{
+ struct qosify_map_alias *alias, *tmp;
+ struct blob_attr *cur;
+ int rem;
+
+ avl_remove_all_elements(&map_aliases, alias, avl, tmp)
+ free(alias);
+
+ blobmsg_for_each_attr(cur, val, rem)
+ qosify_map_create_alias(cur);
+}
+