bpf: refactor code to support explicit opt-in for bulk+prio detection
[project/qosify.git] / main.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2021 Felix Fietkau <nbd@nbd.name>
4 */
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <stdint.h>
8
9 #include <libubox/uloop.h>
10
11 #include "qosify.h"
12
13 static int usage(const char *progname)
14 {
15 fprintf(stderr, "Usage: %s [options]\n"
16 "Options:\n"
17 " -l <file> Load defaults from <file>\n"
18 " -o only load program/maps without running as daemon\n"
19 "\n", progname);
20
21 return 1;
22 }
23
24 int main(int argc, char **argv)
25 {
26 const char *load_file = NULL;
27 bool oneshot = false;
28 int ch;
29
30 while ((ch = getopt(argc, argv, "fl:o")) != -1) {
31 switch (ch) {
32 case 'f':
33 break;
34 case 'l':
35 load_file = optarg;
36 break;
37 case 'o':
38 oneshot = true;
39 break;
40 default:
41 return usage(argv[0]);
42 }
43 }
44
45 if (qosify_loader_init())
46 return 2;
47
48 if (qosify_map_init())
49 return 2;
50
51 if (qosify_map_load_file(load_file))
52 return 2;
53
54 if (oneshot)
55 return 0;
56
57 ulog_open(ULOG_SYSLOG, LOG_DAEMON, "qosify");
58 uloop_init();
59
60 if (qosify_ubus_init() ||
61 qosify_iface_init())
62 return 2;
63
64 uloop_run();
65
66 qosify_ubus_stop();
67 qosify_iface_stop();
68
69 uloop_done();
70
71 return 0;
72 }