int prev_timemout = qosify_map_timeout;
struct blob_attr *tb[__CL_ADD_MAX];
struct blob_attr *cur;
- int dscp = -1;
+ uint8_t dscp = 0xff;
int ret;
blobmsg_parse(qosify_add_policy, __CL_ADD_MAX, tb,
blobmsg_data(msg), blobmsg_len(msg));
if (!strcmp(method, "add")) {
- if ((cur = tb[CL_ADD_DSCP]) != NULL)
- dscp = qosify_map_dscp_value(blobmsg_get_string(cur));
- else
- return UBUS_STATUS_INVALID_ARGUMENT;
- if (dscp < 0)
+ if ((cur = tb[CL_ADD_DSCP]) == NULL ||
+ qosify_map_dscp_value(blobmsg_get_string(cur), &dscp))
return UBUS_STATUS_INVALID_ARGUMENT;
if ((cur = tb[CL_ADD_TIMEOUT]) != NULL)
qosify_map_timeout = blobmsg_get_u32(cur);
- } else {
- dscp = 0xff;
}
if ((cur = tb[CL_ADD_IPV4]) != NULL &&
CL_CONFIG_TIMEOUT,
CL_CONFIG_DSCP_UDP,
CL_CONFIG_DSCP_TCP,
- CL_CONFIG_DSCP_PRIO,
- CL_CONFIG_DSCP_BULK,
CL_CONFIG_DSCP_ICMP,
- CL_CONFIG_BULK_TIMEOUT,
- CL_CONFIG_BULK_PPS,
- CL_CONFIG_PRIO_PKT_LEN,
CL_CONFIG_INTERFACES,
CL_CONFIG_DEVICES,
+ CL_CONFIG_CLASSES,
__CL_CONFIG_MAX
};
[CL_CONFIG_TIMEOUT] = { "timeout", BLOBMSG_TYPE_INT32 },
[CL_CONFIG_DSCP_UDP] = { "dscp_default_udp", BLOBMSG_TYPE_STRING },
[CL_CONFIG_DSCP_TCP] = { "dscp_default_tcp", BLOBMSG_TYPE_STRING },
- [CL_CONFIG_DSCP_PRIO] = { "dscp_prio", BLOBMSG_TYPE_STRING },
- [CL_CONFIG_DSCP_BULK] = { "dscp_bulk", BLOBMSG_TYPE_STRING },
[CL_CONFIG_DSCP_ICMP] = { "dscp_icmp", BLOBMSG_TYPE_STRING },
- [CL_CONFIG_BULK_TIMEOUT] = { "bulk_trigger_timeout", BLOBMSG_TYPE_INT32 },
- [CL_CONFIG_BULK_PPS] = { "bulk_trigger_pps", BLOBMSG_TYPE_INT32 },
- [CL_CONFIG_PRIO_PKT_LEN] = { "prio_max_avg_pkt_len", BLOBMSG_TYPE_INT32 },
[CL_CONFIG_INTERFACES] = { "interfaces", BLOBMSG_TYPE_TABLE },
[CL_CONFIG_DEVICES] = { "devices", BLOBMSG_TYPE_TABLE },
+ [CL_CONFIG_CLASSES] = { "classes", BLOBMSG_TYPE_TABLE },
};
-static int __set_dscp(uint8_t *dest, struct blob_attr *attr, bool reset)
-{
- int dscp;
-
- if (reset)
- *dest = 0xff;
-
- if (!attr)
- return 0;
-
- dscp = qosify_map_dscp_value(blobmsg_get_string(attr));
- if (dscp < 0)
- return -1;
-
- *dest = dscp;
-
- return 0;
-}
-
static int
qosify_ubus_config(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
if (reset)
qosify_map_reset_config();
+ if ((cur = tb[CL_CONFIG_CLASSES]) != NULL || reset)
+ qosify_map_set_classes(cur);
+
if ((cur = tb[CL_CONFIG_TIMEOUT]) != NULL)
qosify_map_timeout = blobmsg_get_u32(cur);
(ret = qosify_ubus_set_files(cur) != 0))
return ret;
- __set_dscp(&dscp, tb[CL_CONFIG_DSCP_UDP], true);
+ if (map_parse_flow_config(&flow_config, msg, reset) ||
+ map_fill_dscp_value(&config.dscp_icmp, tb[CL_CONFIG_DSCP_ICMP], reset))
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ map_fill_dscp_value(&dscp, tb[CL_CONFIG_DSCP_UDP], true);
if (dscp != 0xff)
qosify_map_set_dscp_default(CL_MAP_UDP_PORTS, dscp);
- __set_dscp(&dscp, tb[CL_CONFIG_DSCP_TCP], true);
+ map_fill_dscp_value(&dscp, tb[CL_CONFIG_DSCP_TCP], true);
if (dscp != 0xff)
qosify_map_set_dscp_default(CL_MAP_TCP_PORTS, dscp);
- __set_dscp(&config.dscp_prio, tb[CL_CONFIG_DSCP_PRIO], reset);
- __set_dscp(&config.dscp_bulk, tb[CL_CONFIG_DSCP_BULK], reset);
- __set_dscp(&config.dscp_icmp, tb[CL_CONFIG_DSCP_ICMP], reset);
-
- if ((cur = tb[CL_CONFIG_BULK_TIMEOUT]) != NULL)
- config.bulk_trigger_timeout = blobmsg_get_u32(cur);
-
- if ((cur = tb[CL_CONFIG_BULK_PPS]) != NULL)
- config.bulk_trigger_pps = blobmsg_get_u32(cur);
-
- if ((cur = tb[CL_CONFIG_PRIO_PKT_LEN]) != NULL)
- config.prio_max_avg_pkt_len = blobmsg_get_u32(cur);
-
qosify_map_update_config();
qosify_iface_config_update(tb[CL_CONFIG_INTERFACES], tb[CL_CONFIG_DEVICES]);
};
static int
-qosify_ubus_add_dns_host(struct ubus_context *ctx, struct ubus_object *obj,
- struct ubus_request_data *req, const char *method,
- struct blob_attr *msg)
+__qosify_ubus_add_dns_host(struct blob_attr *msg)
{
struct blob_attr *tb[__CL_DNS_HOST_MAX];
struct blob_attr *cur;
return 0;
}
+static int
+qosify_ubus_add_dns_host(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ return __qosify_ubus_add_dns_host(msg);
+}
+
static const struct ubus_method qosify_methods[] = {
UBUS_METHOD_NOARG("reload", qosify_ubus_reload),
UBUS_METHOD("add", qosify_ubus_add, qosify_add_policy),
.n_methods = ARRAY_SIZE(qosify_methods),
};
+static void
+qosify_subscribe_dnsmasq(struct ubus_context *ctx)
+{
+ static struct ubus_subscriber sub = {
+ .cb = qosify_ubus_add_dns_host,
+ };
+ uint32_t id;
+
+ if (!sub.obj.id &&
+ ubus_register_subscriber(ctx, &sub))
+ return;
+
+ if (ubus_lookup_id(ctx, "dnsmasq.dns", &id))
+ return;
+
+ ubus_subscribe(ctx, &sub, id);
+}
+
+static void
+qosify_ubus_event_cb(struct ubus_context *ctx, struct ubus_event_handler *ev,
+ const char *type, struct blob_attr *msg)
+{
+ static const struct blobmsg_policy policy =
+ { "path", BLOBMSG_TYPE_STRING };
+ struct blob_attr *attr;
+ const char *path;
+
+ blobmsg_parse(&policy, 1, &attr, blobmsg_data(msg), blobmsg_len(msg));
+
+ if (!attr)
+ return;
+
+ path = blobmsg_get_string(attr);
+ if (!strcmp(path, "dnsmasq.dns"))
+ qosify_subscribe_dnsmasq(ctx);
+}
+
+
static void
ubus_connect_handler(struct ubus_context *ctx)
{
+ static struct ubus_event_handler ev = {
+ .cb = qosify_ubus_event_cb
+ };
+
ubus_add_object(ctx, &qosify_object);
+ ubus_register_event_handler(ctx, &ev, "ubus.object.add");
+ qosify_subscribe_dnsmasq(ctx);
}
static struct ubus_auto_conn conn;
if (ubus_lookup_id(&conn.ctx, obj_name, &id))
return -1;
+ blob_buf_init(&b, 0);
ubus_invoke(&conn.ctx, id, "status", b.head, netifd_if_cb, &req, 1000);
if (!ifname[0])