1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2021 Felix Fietkau <nbd@nbd.name>
5 #ifndef __QOS_CLASSIFY_H
6 #define __QOS_CLASSIFY_H
12 #include <bpf/libbpf.h>
14 #include "qosify-bpf.h"
16 #include <libubox/utils.h>
17 #include <libubox/avl.h>
18 #include <libubox/blobmsg.h>
19 #include <libubox/ulog.h>
21 #include <netinet/in.h>
23 #define CLASSIFY_PROG_PATH "/lib/bpf/qosify-bpf.o"
24 #define CLASSIFY_PIN_PATH "/sys/fs/bpf/qosify"
25 #define CLASSIFY_DATA_PATH "/sys/fs/bpf/qosify_data"
27 #define QOSIFY_DNS_IFNAME "ifb-dns"
29 #define QOSIFY_PRIO_BASE 0x110
42 struct qosify_map_data
{
43 enum qosify_map_id id
;
57 uint32_t only_cname
: 1;
64 struct qosify_map_entry
{
69 struct qosify_map_data data
;
73 extern int qosify_map_timeout
;
74 extern int qosify_active_timeout
;
75 extern struct qosify_config config
;
76 extern struct qosify_flow_config flow_config
;
78 int qosify_run_cmd(char *cmd
, bool ignore_error
);
80 int qosify_loader_init(void);
82 int qosify_map_init(void);
83 int qosify_map_dscp_value(const char *val
, uint8_t *dscp
);
84 int qosify_map_load_file(const char *file
);
85 void __qosify_map_set_entry(struct qosify_map_data
*data
);
86 int qosify_map_set_entry(enum qosify_map_id id
, bool file
, const char *str
,
88 void qosify_map_reload(void);
89 void qosify_map_clear_files(void);
90 void qosify_map_gc(void);
91 void qosify_map_dump(struct blob_buf
*b
);
92 void qosify_map_set_dscp_default(enum qosify_map_id id
, uint8_t val
);
93 void qosify_map_reset_config(void);
94 void qosify_map_update_config(void);
95 void qosify_map_set_classes(struct blob_attr
*val
);
96 int qosify_map_lookup_dns_entry(char *host
, bool cname
, uint8_t *dscp
, uint32_t *seq
);
97 int qosify_map_add_dns_host(char *host
, const char *addr
, const char *type
, int ttl
);
98 int map_parse_flow_config(struct qosify_flow_config
*cfg
, struct blob_attr
*attr
,
100 int map_fill_dscp_value(uint8_t *dest
, struct blob_attr
*attr
, bool reset
);
102 int qosify_iface_init(void);
103 void qosify_iface_config_update(struct blob_attr
*ifaces
, struct blob_attr
*devs
);
104 void qosify_iface_check(void);
105 void qosify_iface_status(struct blob_buf
*b
);
106 void qosify_iface_stop(void);
108 int qosify_dns_init(void);
109 void qosify_dns_stop(void);
111 int qosify_ubus_init(void);
112 void qosify_ubus_stop(void);
113 int qosify_ubus_check_interface(const char *name
, char *ifname
, int ifname_len
);