netifd: reconnect to ubus if the connection is lost
[project/netifd.git] / netifd.h
1 /*
2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14 #ifndef __NETIFD_H
15 #define __NETIFD_H
16
17 #include <sys/socket.h>
18 #include <net/if.h>
19
20 #include <stdbool.h>
21 #include <stdio.h>
22
23 #include <libubox/uloop.h>
24
25 #include <libubus.h>
26
27 #include "utils.h"
28
29 #ifdef DUMMY_MODE
30 #define DEFAULT_MAIN_PATH "./dummy"
31 #define DEFAULT_HOTPLUG_PATH "./scripts/hotplug-cmd"
32 #define DEFAULT_RESOLV_CONF "./tmp/resolv.conf"
33 #else
34 #define DEFAULT_MAIN_PATH "/lib/netifd"
35 #define DEFAULT_HOTPLUG_PATH "/sbin/hotplug-call"
36 #define DEFAULT_RESOLV_CONF "/tmp/resolv.conf.auto"
37 #endif
38
39 extern const char *resolv_conf;
40 extern char *hotplug_cmd_path;
41 extern unsigned int debug_mask;
42
43 enum {
44 L_CRIT,
45 L_WARNING,
46 L_NOTICE,
47 L_INFO,
48 L_DEBUG
49 };
50
51 enum {
52 DEBUG_SYSTEM = 0,
53 DEBUG_DEVICE = 1,
54 DEBUG_INTERFACE = 2,
55 };
56
57 #ifdef DEBUG
58 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
59 #define D(level, format, ...) do { \
60 if (debug_mask & (1 << (DEBUG_ ## level))) \
61 DPRINTF(format, ##__VA_ARGS__); \
62 } while (0)
63 #else
64 #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
65 #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
66 #endif
67
68 #define LOG_BUF_SIZE 256
69
70 static inline void no_debug(int level, const char *fmt, ...)
71 {
72 }
73
74 struct netifd_fd {
75 struct list_head list;
76 struct netifd_process *proc;
77 int fd;
78 };
79
80 struct netifd_process {
81 struct list_head list;
82 struct uloop_process uloop;
83 void (*cb)(struct netifd_process *, int ret);
84 int dir_fd;
85
86 struct netifd_fd log_fd;
87 struct uloop_fd log_uloop;
88 const char *log_prefix;
89 char *log_buf;
90 int log_buf_ofs;
91 bool log_overflow;
92 };
93
94 void netifd_log_message(int priority, const char *format, ...);
95
96 int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
97 void netifd_kill_process(struct netifd_process *proc);
98
99 void netifd_fd_add(struct netifd_fd *fd);
100 void netifd_fd_delete(struct netifd_fd *fd);
101
102 struct device;
103 struct interface;
104
105 extern const char *main_path;
106 void netifd_restart(void);
107 void netifd_reload(void);
108
109 #endif