proto-shell: move script handler config parse code to handler.c
[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 struct interface_error {
45         struct list_head list;
46
47         const char *subsystem;
48         const char *code;
49         const char *data[];
50 };
51
52 struct interface_user {
53         struct list_head list;
54         struct interface *iface;
55         void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
56 };
57
58 struct interface_ip_settings {
59         struct interface *iface;
60         bool enabled;
61         bool no_defaultroute;
62         bool no_dns;
63         bool no_delegation;
64
65         struct vlist_tree addr;
66         struct vlist_tree route;
67         struct vlist_tree prefix;
68
69         struct vlist_simple_tree dns_servers;
70         struct vlist_simple_tree dns_search;
71 };
72
73 struct interface_data {
74         struct avl_node node;
75         struct blob_attr data[];
76 };
77
78 struct interface_assignment_class {
79         struct list_head head;
80         char name[];
81 };
82
83 /*
84  * interface configuration
85  */
86 struct interface {
87         struct vlist_node node;
88         struct list_head hotplug_list;
89         enum interface_event hotplug_ev;
90
91         const char *name;
92         const char *ifname;
93
94         bool available;
95         bool autostart;
96         bool config_autostart;
97         bool device_config;
98         bool dynamic;
99
100         time_t start_time;
101         enum interface_state state;
102         enum interface_config_state config_state;
103
104         struct list_head users;
105
106         const char *parent_ifname;
107         struct interface_user parent_iface;
108
109         /* main interface that the interface is bound to */
110         struct device_user main_dev;
111
112         /* interface that layer 3 communication will go through */
113         struct device_user l3_dev;
114
115         struct blob_attr *config;
116
117         /* primary protocol state */
118         const struct proto_handler *proto_handler;
119         struct interface_proto_state *proto;
120
121         struct interface_ip_settings proto_ip;
122         struct interface_ip_settings config_ip;
123         struct vlist_tree host_routes;
124
125         int metric;
126         unsigned int ip4table;
127         unsigned int ip6table;
128
129         /* IPv6 assignment parameters */
130         uint8_t assignment_length;
131         int32_t assignment_hint;
132         struct list_head assignment_classes;
133
134         /* errors/warnings while trying to bring up the interface */
135         struct list_head errors;
136
137         /* extra data provided by protocol handlers or modules */
138         struct avl_tree data;
139
140         struct uloop_timeout remove_timer;
141         struct ubus_object ubus;
142 };
143
144
145 extern struct vlist_tree interfaces;
146 extern const struct uci_blob_param_list interface_attr_list;
147
148 struct interface *interface_alloc(const char *name, struct blob_attr *config);
149
150 void interface_set_dynamic(struct interface *iface);
151
152 void interface_add(struct interface *iface, struct blob_attr *config);
153 bool interface_add_alias(struct interface *iface, struct blob_attr *config);
154
155 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
156
157 void interface_set_available(struct interface *iface, bool new_state);
158 int interface_set_up(struct interface *iface);
159 int interface_set_down(struct interface *iface);
160 void __interface_set_down(struct interface *iface, bool force);
161
162 void interface_set_main_dev(struct interface *iface, struct device *dev);
163 void interface_set_l3_dev(struct interface *iface, struct device *dev);
164
165 void interface_add_user(struct interface_user *dep, struct interface *iface);
166 void interface_remove_user(struct interface_user *dep);
167
168 int interface_add_link(struct interface *iface, struct device *dev);
169 int interface_remove_link(struct interface *iface, struct device *dev);
170
171 void interface_add_error(struct interface *iface, const char *subsystem,
172                          const char *code, const char **data, int n_data);
173
174 int interface_add_data(struct interface *iface, const struct blob_attr *data);
175
176 void interface_update_start(struct interface *iface);
177 void interface_update_complete(struct interface *iface);
178
179 void interface_start_pending(void);
180
181 #endif