2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
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
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.
14 #ifndef __NETIFD_INTERFACE_H
15 #define __NETIFD_INTERFACE_H
21 struct interface_proto_state;
23 enum interface_event {
31 enum interface_state {
38 enum interface_config_state {
44 enum interface_update_flags {
45 IUF_ADDRESS = (1 << 0),
47 IUF_PREFIX = (1 << 2),
51 struct interface_error {
52 struct list_head list;
54 const char *subsystem;
59 struct interface_user {
60 struct list_head list;
61 struct interface *iface;
62 void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
65 struct interface_ip_settings {
66 struct interface *iface;
72 struct vlist_tree addr;
73 struct vlist_tree route;
74 struct vlist_tree prefix;
76 struct vlist_simple_tree dns_servers;
77 struct vlist_simple_tree dns_search;
80 struct interface_data {
82 struct blob_attr data[];
85 struct interface_assignment_class {
86 struct list_head head;
91 * interface configuration
94 struct vlist_node node;
95 struct list_head hotplug_list;
96 enum interface_event hotplug_ev;
103 bool config_autostart;
111 enum interface_state state;
112 enum interface_config_state config_state;
113 enum interface_update_flags updated;
115 struct list_head users;
117 const char *parent_ifname;
118 struct interface_user parent_iface;
120 /* main interface that the interface is bound to */
121 struct device_user main_dev;
122 struct device_user ext_dev;
124 /* interface that layer 3 communication will go through */
125 struct device_user l3_dev;
127 struct blob_attr *config;
129 /* primary protocol state */
130 const struct proto_handler *proto_handler;
131 struct interface_proto_state *proto;
133 struct interface_ip_settings proto_ip;
134 struct interface_ip_settings config_ip;
135 struct vlist_tree host_routes;
138 unsigned int ip4table;
139 unsigned int ip6table;
141 /* IPv6 assignment parameters */
142 uint8_t assignment_length;
143 int32_t assignment_hint;
144 struct list_head assignment_classes;
146 /* errors/warnings while trying to bring up the interface */
147 struct list_head errors;
149 /* extra data provided by protocol handlers or modules */
150 struct avl_tree data;
152 struct uloop_timeout remove_timer;
153 struct ubus_object ubus;
157 extern struct vlist_tree interfaces;
158 extern const struct uci_blob_param_list interface_attr_list;
160 struct interface *interface_alloc(const char *name, struct blob_attr *config);
162 void interface_set_dynamic(struct interface *iface);
164 void interface_add(struct interface *iface, struct blob_attr *config);
165 bool interface_add_alias(struct interface *iface, struct blob_attr *config);
167 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
169 void interface_set_available(struct interface *iface, bool new_state);
170 int interface_set_up(struct interface *iface);
171 int interface_set_down(struct interface *iface);
172 void __interface_set_down(struct interface *iface, bool force);
174 void interface_set_main_dev(struct interface *iface, struct device *dev);
175 void interface_set_l3_dev(struct interface *iface, struct device *dev);
177 void interface_add_user(struct interface_user *dep, struct interface *iface);
178 void interface_remove_user(struct interface_user *dep);
180 int interface_remove_link(struct interface *iface, struct device *dev);
181 int interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext);
183 void interface_add_error(struct interface *iface, const char *subsystem,
184 const char *code, const char **data, int n_data);
186 int interface_add_data(struct interface *iface, const struct blob_attr *data);
188 void interface_update_start(struct interface *iface);
189 void interface_update_complete(struct interface *iface);
191 void interface_start_pending(void);