interface: suppress unnecessary device config overrides
[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_UPDATE,
27         IFEV_FREE,
28         IFEV_RELOAD,
29 };
30
31 enum interface_state {
32         IFS_SETUP,
33         IFS_UP,
34         IFS_TEARDOWN,
35         IFS_DOWN,
36 };
37
38 enum interface_config_state {
39         IFC_NORMAL,
40         IFC_RELOAD,
41         IFC_REMOVE
42 };
43
44 enum interface_id_selection_type {
45         IFID_FIXED,
46         IFID_RANDOM,
47         IFID_EUI64
48 };
49
50 enum interface_update_flags {
51         IUF_ADDRESS     = (1 << 0),
52         IUF_ROUTE       = (1 << 1),
53         IUF_PREFIX      = (1 << 2),
54         IUF_DATA        = (1 << 3),
55 };
56
57 struct interface_error {
58         struct list_head list;
59
60         const char *subsystem;
61         const char *code;
62         const char *data[];
63 };
64
65 struct interface_user {
66         struct list_head list;
67         struct interface *iface;
68         void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
69 };
70
71 struct interface_ip_settings {
72         struct interface *iface;
73         bool enabled;
74         bool no_defaultroute;
75         bool no_dns;
76         bool no_delegation;
77
78         struct vlist_tree addr;
79         struct vlist_tree route;
80         struct vlist_tree prefix;
81
82         struct vlist_simple_tree dns_servers;
83         struct vlist_simple_tree dns_search;
84 };
85
86 struct interface_data {
87         struct avl_node node;
88         struct blob_attr data[];
89 };
90
91 struct interface_assignment_class {
92         struct list_head head;
93         char name[];
94 };
95
96 /*
97  * interface configuration
98  */
99 struct interface {
100         struct vlist_node node;
101         struct list_head hotplug_list;
102         enum interface_event hotplug_ev;
103
104         const char *name;
105         const char *ifname;
106
107         bool available;
108         bool autostart;
109         bool config_autostart;
110         bool device_config;
111         bool enabled;
112         bool link_state;
113         bool force_link;
114         bool dynamic;
115
116         time_t start_time;
117         enum interface_state state;
118         enum interface_config_state config_state;
119         enum interface_update_flags updated;
120
121         struct list_head users;
122
123         const char *parent_ifname;
124         struct interface_user parent_iface;
125
126         /* main interface that the interface is bound to */
127         struct device_user main_dev;
128         struct device_user ext_dev;
129
130         /* interface that layer 3 communication will go through */
131         struct device_user l3_dev;
132
133         struct blob_attr *config;
134
135         /* primary protocol state */
136         const struct proto_handler *proto_handler;
137         struct interface_proto_state *proto;
138
139         struct interface_ip_settings proto_ip;
140         struct interface_ip_settings config_ip;
141         struct vlist_tree host_routes;
142
143         int metric;
144         unsigned int ip4table;
145         unsigned int ip6table;
146
147         /* IPv6 assignment parameters */
148         enum interface_id_selection_type assignment_iface_id_selection;
149         struct in6_addr assignment_fixed_iface_id;
150         uint8_t assignment_length;
151         int32_t assignment_hint;
152         struct list_head assignment_classes;
153
154         /* errors/warnings while trying to bring up the interface */
155         struct list_head errors;
156
157         /* extra data provided by protocol handlers or modules */
158         struct avl_tree data;
159
160         struct uloop_timeout remove_timer;
161         struct ubus_object ubus;
162 };
163
164
165 extern struct vlist_tree interfaces;
166 extern const struct uci_blob_param_list interface_attr_list;
167
168 struct interface *interface_alloc(const char *name, struct blob_attr *config);
169
170 void interface_set_dynamic(struct interface *iface);
171
172 void interface_add(struct interface *iface, struct blob_attr *config);
173 bool interface_add_alias(struct interface *iface, struct blob_attr *config);
174
175 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
176
177 void interface_set_available(struct interface *iface, bool new_state);
178 int interface_set_up(struct interface *iface);
179 int interface_set_down(struct interface *iface);
180 void __interface_set_down(struct interface *iface, bool force);
181
182 void interface_set_main_dev(struct interface *iface, struct device *dev);
183 void interface_set_l3_dev(struct interface *iface, struct device *dev);
184
185 void interface_add_user(struct interface_user *dep, struct interface *iface);
186 void interface_remove_user(struct interface_user *dep);
187
188 int interface_remove_link(struct interface *iface, struct device *dev);
189 int interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext);
190
191 void interface_add_error(struct interface *iface, const char *subsystem,
192                          const char *code, const char **data, int n_data);
193
194 int interface_add_data(struct interface *iface, const struct blob_attr *data);
195
196 void interface_update_start(struct interface *iface);
197 void interface_update_complete(struct interface *iface);
198
199 void interface_start_pending(void);
200
201 #endif