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