wireless: fix parsing of the immediate flag for kill-all
[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 #include <libubox/ustream.h>
25 #include <libubox/utils.h>
26
27 #include <libubus.h>
28
29 #include "utils.h"
30
31 #ifdef DUMMY_MODE
32 #define DEFAULT_MAIN_PATH       "./examples"
33 #define DEFAULT_HOTPLUG_PATH    "./examples/hotplug-cmd"
34 #define DEFAULT_RESOLV_CONF     "./tmp/resolv.conf"
35 #else
36 #define DEFAULT_MAIN_PATH       "/lib/netifd"
37 #define DEFAULT_HOTPLUG_PATH    "/sbin/hotplug-call"
38 #define DEFAULT_RESOLV_CONF     "/tmp/resolv.conf.auto"
39 #endif
40
41 extern const char *resolv_conf;
42 extern char *hotplug_cmd_path;
43 extern unsigned int debug_mask;
44
45 enum {
46         L_CRIT,
47         L_WARNING,
48         L_NOTICE,
49         L_INFO,
50         L_DEBUG
51 };
52
53 enum {
54         DEBUG_SYSTEM    = 0,
55         DEBUG_DEVICE    = 1,
56         DEBUG_INTERFACE = 2,
57         DEBUG_WIRELESS  = 3,
58 };
59
60 #ifdef DEBUG
61 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
62 #define D(level, format, ...) do { \
63                 if (debug_mask & (1 << (DEBUG_ ## level))) \
64                                 DPRINTF(format, ##__VA_ARGS__); \
65         } while (0)
66 #else
67 #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
68 #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
69 #endif
70
71 #define LOG_BUF_SIZE    256
72
73 static inline void no_debug(int level, const char *fmt, ...)
74 {
75 }
76
77 struct netifd_process {
78         struct list_head list;
79         struct uloop_process uloop;
80         void (*cb)(struct netifd_process *, int ret);
81         int dir_fd;
82
83         struct ustream_fd log;
84         const char *log_prefix;
85         bool log_overflow;
86 };
87
88 void netifd_log_message(int priority, const char *format, ...);
89
90 int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
91 void netifd_kill_process(struct netifd_process *proc);
92
93 struct device;
94 struct interface;
95
96 extern const char *main_path;
97 void netifd_restart(void);
98 void netifd_reload(void);
99
100 #endif