CMake: bump the minimum required CMake version to 3.5
[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 #include <udebug.h>
29
30 #ifdef linux
31 #include <netinet/ether.h>
32 #else
33 #include <net/ethernet.h>
34 #endif
35
36 #include "utils.h"
37
38 #ifdef DUMMY_MODE
39 #define DEFAULT_MAIN_PATH "./examples"
40 #define DEFAULT_CONFIG_PATH "./config"
41 #define DEFAULT_HOTPLUG_PATH "./examples/hotplug-cmd"
42 #define DEFAULT_RESOLV_CONF "./tmp/resolv.conf"
43 #define DEFAULT_BOARD_JSON "./config/board.json"
44 #else
45 #define DEFAULT_MAIN_PATH "/lib/netifd"
46 #define DEFAULT_CONFIG_PATH NULL /* use the default set in libuci */
47 #define DEFAULT_HOTPLUG_PATH "/sbin/hotplug-call"
48 #define DEFAULT_RESOLV_CONF "/tmp/resolv.conf.d/resolv.conf.auto"
49 #define DEFAULT_BOARD_JSON "/etc/board.json"
50 #endif
51
52 extern const char *resolv_conf;
53 extern char *hotplug_cmd_path;
54 extern unsigned int debug_mask;
55 extern struct udebug_buf udb_nl;
56
57 enum {
58 L_CRIT,
59 L_WARNING,
60 L_NOTICE,
61 L_INFO,
62 L_DEBUG
63 };
64
65 enum {
66 DEBUG_SYSTEM = 0,
67 DEBUG_DEVICE = 1,
68 DEBUG_INTERFACE = 2,
69 DEBUG_WIRELESS = 3,
70 };
71
72 #ifdef DEBUG
73 #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
74 #define D(level, format, ...) do { \
75 netifd_udebug_printf("[" #level "] %s(%d): " format, __func__, __LINE__, ## __VA_ARGS__); \
76 if (debug_mask & (1 << (DEBUG_ ## level))) { \
77 DPRINTF(format, ##__VA_ARGS__); \
78 fprintf(stderr, "\n"); \
79 } \
80 } while (0)
81 #else
82 #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
83 #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
84 #endif
85
86 #define LOG_BUF_SIZE 256
87
88 static inline void no_debug(int level, const char *fmt, ...)
89 {
90 }
91
92 struct netifd_process {
93 struct list_head list;
94 struct uloop_process uloop;
95 void (*cb)(struct netifd_process *, int ret);
96 int dir_fd;
97
98 struct ustream_fd log;
99 const char *log_prefix;
100 bool log_overflow;
101 };
102
103 void netifd_udebug_printf(const char *format, ...);
104 void netifd_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data,
105 bool enabled);
106 void netifd_log_message(int priority, const char *format, ...);
107
108 int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
109 void netifd_kill_process(struct netifd_process *proc);
110
111 struct device;
112 struct interface;
113
114 extern const char *main_path;
115 extern const char *config_path;
116 void netifd_restart(void);
117 int netifd_reload(void);
118
119 #endif