1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> 4 */ 5 #ifndef __QOS_CLASSIFY_H 6 #define __QOS_CLASSIFY_H 7 8 #include <stdbool.h> 9 #include <regex.h> 10 11 #include <bpf/bpf.h> 12 #include <bpf/libbpf.h> 13 14 #include "qosify-bpf.h" 15 16 #include <libubox/utils.h> 17 #include <libubox/avl.h> 18 #include <libubox/blobmsg.h> 19 #include <libubox/ulog.h> 20 21 #include <netinet/in.h> 22 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" 26 27 #define QOSIFY_DNS_IFNAME "ifb-dns" 28 29 #define QOSIFY_PRIO_BASE 0x110 30 31 enum qosify_map_id { 32 CL_MAP_TCP_PORTS, 33 CL_MAP_UDP_PORTS, 34 CL_MAP_IPV4_ADDR, 35 CL_MAP_IPV6_ADDR, 36 CL_MAP_CLASS, 37 CL_MAP_CONFIG, 38 CL_MAP_DNS, 39 CL_MAP_DSCP_STATS, 40 CL_MAP_PATTERN_STATS, 41 __CL_MAP_MAX, 42 }; 43 44 struct qosify_map_data { 45 enum qosify_map_id id; 46 47 bool file : 1; 48 bool user : 1; 49 50 uint8_t dscp; 51 uint8_t file_dscp; 52 uint32_t pattern_id; 53 54 union { 55 uint32_t port; 56 struct in_addr ip; 57 struct in6_addr ip6; 58 struct { 59 uint32_t seq : 30; 60 uint32_t only_cname : 1; 61 const char *pattern; 62 regex_t regex; 63 } dns; 64 } addr; 65 }; 66 67 struct qosify_map_entry { 68 struct avl_node avl; 69 70 uint32_t timeout; 71 uint64_t hits; 72 uint32_t pattern_id; 73 74 struct qosify_map_data data; 75 }; 76 77 78 extern int qosify_map_timeout; 79 extern int qosify_active_timeout; 80 extern struct qosify_config config; 81 extern struct qosify_flow_config flow_config; 82 83 int qosify_run_cmd(char *cmd, bool ignore_error); 84 85 int qosify_loader_init(void); 86 void qosify_loader_stop(void); 87 const char *qosify_get_program(uint32_t flags, int *fd); 88 89 int qosify_map_init(void); 90 int qosify_map_dscp_value(const char *val, uint8_t *dscp); 91 int qosify_map_load_file(const char *file); 92 void __qosify_map_set_entry(struct qosify_map_data *data); 93 int qosify_map_set_entry(enum qosify_map_id id, bool file, const char *str, 94 uint8_t dscp); 95 void qosify_map_reload(void); 96 void qosify_map_clear_files(void); 97 void qosify_map_gc(void); 98 void qosify_map_dump(struct blob_buf *b); 99 void qosify_map_stats(struct blob_buf *b, bool reset); 100 void qosify_map_dscp_stats(struct blob_buf *b, bool reset); 101 void qosify_map_dns_stats(struct blob_buf *b, bool reset); 102 void qosify_map_set_dscp_default(enum qosify_map_id id, uint8_t val); 103 void qosify_map_reset_config(void); 104 void qosify_map_update_config(void); 105 void qosify_map_set_classes(struct blob_attr *val); 106 int qosify_map_lookup_dns_entry(char *host, bool cname, uint8_t *dscp, uint32_t *seq, 107 uint32_t *pattern_id); 108 int qosify_map_add_dns_host(char *host, const char *addr, const char *type, int ttl); 109 int map_parse_flow_config(struct qosify_flow_config *cfg, struct blob_attr *attr, 110 bool reset); 111 int map_fill_dscp_value(uint8_t *dest, struct blob_attr *attr, bool reset); 112 113 int qosify_iface_init(void); 114 void qosify_iface_config_update(struct blob_attr *ifaces, struct blob_attr *devs); 115 void qosify_iface_check(void); 116 void qosify_iface_status(struct blob_buf *b); 117 void qosify_iface_get_devices(struct blob_buf *b); 118 void qosify_iface_stop(void); 119 120 int qosify_dns_init(void); 121 void qosify_dns_stop(void); 122 void qosify_dns_get_stats(struct blob_buf *b, bool reset); 123 124 uint32_t qosify_map_get_ebpf_entry_count(void); 125 uint32_t qosify_map_get_last_reload_time(void); 126 127 int qosify_ubus_init(void); 128 void qosify_ubus_stop(void); 129 int qosify_ubus_check_interface(const char *name, char *ifname, int ifname_len); 130 void qosify_ubus_update_bridger(bool shutdown); 131 132 #endif 133
This page was automatically generated by LXR 0.3.1. • OpenWrt