add copyright headers
[project/netifd.git] / interface.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_INTERFACE_H
15 #define __NETIFD_INTERFACE_H
16
17 #include "device.h"
18 #include "config.h"
19
20 struct interface;
21 struct interface_proto_state;
22
23 enum interface_event {
24 IFEV_DOWN,
25 IFEV_UP,
26 IFEV_FREE,
27 IFEV_RELOAD,
28 };
29
30 enum interface_state {
31 IFS_SETUP,
32 IFS_UP,
33 IFS_TEARDOWN,
34 IFS_DOWN,
35 };
36
37 enum interface_config_state {
38 IFC_NORMAL,
39 IFC_RELOAD,
40 IFC_REMOVE
41 };
42
43 struct interface_error {
44 struct list_head list;
45
46 const char *subsystem;
47 const char *code;
48 const char *data[];
49 };
50
51 struct interface_user {
52 struct list_head list;
53 struct interface *iface;
54 void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
55 };
56
57 struct interface_ip_settings {
58 struct interface *iface;
59 bool enabled;
60 bool no_defaultroute;
61
62 struct vlist_tree addr;
63 struct vlist_tree route;
64
65 struct vlist_simple_tree dns_servers;
66 struct vlist_simple_tree dns_search;
67 };
68
69 struct interface_data {
70 struct avl_node node;
71 struct blob_attr data[];
72 };
73
74 /*
75 * interface configuration
76 */
77 struct interface {
78 struct vlist_node node;
79 struct list_head hotplug_list;
80 enum interface_event hotplug_ev;
81
82 char name[IFNAMSIZ];
83 const char *ifname;
84
85 bool available;
86 bool autostart;
87 bool config_autostart;
88
89 time_t start_time;
90 enum interface_state state;
91 enum interface_config_state config_state;
92
93 struct list_head users;
94
95 /* main interface that the interface is bound to */
96 struct device_user main_dev;
97
98 /* interface that layer 3 communication will go through */
99 struct device_user l3_dev;
100
101 struct blob_attr *config;
102
103 /* primary protocol state */
104 const struct proto_handler *proto_handler;
105 struct interface_proto_state *proto;
106
107 struct interface_ip_settings proto_ip;
108 struct interface_ip_settings config_ip;
109 struct vlist_tree host_routes;
110
111 int metric;
112
113 /* errors/warnings while trying to bring up the interface */
114 struct list_head errors;
115
116 /* extra data provided by protocol handlers or modules */
117 struct avl_tree data;
118
119 struct uloop_timeout remove_timer;
120 struct ubus_object ubus;
121 };
122
123 extern struct vlist_tree interfaces;
124 extern const struct config_param_list interface_attr_list;
125
126 void interface_init(struct interface *iface, const char *name,
127 struct blob_attr *config);
128
129 void interface_add(struct interface *iface, struct blob_attr *config);
130
131 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
132
133 void interface_set_available(struct interface *iface, bool new_state);
134 int interface_set_up(struct interface *iface);
135 int interface_set_down(struct interface *iface);
136 void __interface_set_down(struct interface *iface, bool force);
137
138 void interface_set_main_dev(struct interface *iface, struct device *dev);
139 void interface_set_l3_dev(struct interface *iface, struct device *dev);
140
141 void interface_add_user(struct interface_user *dep, struct interface *iface);
142 void interface_remove_user(struct interface_user *dep);
143
144 int interface_add_link(struct interface *iface, struct device *dev);
145 int interface_remove_link(struct interface *iface, struct device *dev);
146
147 void interface_add_error(struct interface *iface, const char *subsystem,
148 const char *code, const char **data, int n_data);
149
150 int interface_add_data(struct interface *iface, const struct blob_attr *data);
151
152 void interface_update_start(struct interface *iface);
153 void interface_update_complete(struct interface *iface);
154
155 void interface_start_pending(void);
156
157 #endif