export carrier status in device stats
[project/netifd.git] / netifd.h
1 #ifndef __NETIFD_H
2 #define __NETIFD_H
3
4 #include <sys/socket.h>
5 #include <net/if.h>
6
7 #include <stdbool.h>
8 #include <stdio.h>
9
10 #include <libubox/uloop.h>
11
12 #include <libubus.h>
13
14 #include "utils.h"
15
16 #ifdef DUMMY_MODE
17 #define DEFAULT_MAIN_PATH       "./dummy"
18 #define DEFAULT_HOTPLUG_PATH    "./scripts/hotplug-cmd"
19 #define DEFAULT_RESOLV_CONF     "./tmp/resolv.conf"
20 #else
21 #define DEFAULT_MAIN_PATH       "/lib/netifd"
22 #define DEFAULT_HOTPLUG_PATH    "/sbin/hotplug-call"
23 #define DEFAULT_RESOLV_CONF     "/tmp/resolv.conf.auto"
24 #endif
25
26 extern const char *resolv_conf;
27 extern char *hotplug_cmd_path;
28 extern unsigned int debug_mask;
29
30 enum {
31         L_CRIT,
32         L_WARNING,
33         L_NOTICE,
34         L_INFO,
35         L_DEBUG
36 };
37
38 enum {
39         DEBUG_SYSTEM    = 0,
40         DEBUG_DEVICE    = 1,
41         DEBUG_INTERFACE = 2,
42 };
43
44 #ifdef DEBUG
45 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
46 #define D(level, format, ...) do { \
47                 if (debug_mask & (1 << (DEBUG_ ## level))) \
48                                 DPRINTF(format, ##__VA_ARGS__); \
49         } while (0)
50 #else
51 #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
52 #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
53 #endif
54
55 #define LOG_BUF_SIZE    256
56
57 static inline void no_debug(int level, const char *fmt, ...)
58 {
59 }
60
61 struct netifd_fd {
62         struct list_head list;
63         struct netifd_process *proc;
64         int fd;
65 };
66
67 struct netifd_process {
68         struct list_head list;
69         struct uloop_process uloop;
70         void (*cb)(struct netifd_process *, int ret);
71         int dir_fd;
72
73         struct netifd_fd log_fd;
74         struct uloop_fd log_uloop;
75         const char *log_prefix;
76         char *log_buf;
77         int log_buf_ofs;
78         bool log_overflow;
79 };
80
81 void netifd_log_message(int priority, const char *format, ...);
82
83 int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
84 void netifd_kill_process(struct netifd_process *proc);
85
86 void netifd_fd_add(struct netifd_fd *fd);
87 void netifd_fd_delete(struct netifd_fd *fd);
88
89 struct device;
90 struct interface;
91
92 extern const char *main_path;
93 void netifd_restart(void);
94 void netifd_reload(void);
95
96 #endif