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 {
33 enum interface_state {
40 enum interface_config_state {
46 enum interface_id_selection_type {
52 enum interface_update_flags {
53 IUF_ADDRESS = (1 << 0),
55 IUF_PREFIX = (1 << 2),
59 struct interface_error {
60 struct list_head list;
62 const char *subsystem;
67 struct interface_user {
68 struct list_head list;
69 struct interface *iface;
70 void (*cb)(struct interface_user *dep, struct interface *iface, enum interface_event ev);
73 struct interface_ip_settings {
74 struct interface *iface;
80 struct vlist_tree addr;
81 struct vlist_tree route;
82 struct vlist_tree prefix;
84 struct vlist_simple_tree dns_servers;
85 struct vlist_simple_tree dns_search;
88 struct interface_data {
90 struct blob_attr data[];
93 struct interface_assignment_class {
94 struct list_head head;
99 * interface configuration
102 struct vlist_node node;
103 struct list_head hotplug_list;
104 enum interface_event hotplug_ev;
111 bool config_autostart;
117 bool policy_rules_set;
121 enum interface_state state;
122 enum interface_config_state config_state;
123 enum interface_update_flags updated;
125 struct list_head users;
127 /* for alias interface */
128 const char *parent_ifname;
129 struct interface_user parent_iface;
131 /* main interface that the interface is bound to */
132 struct device_user main_dev;
133 struct device_user ext_dev;
135 /* interface that layer 3 communication will go through */
136 struct device_user l3_dev;
138 struct blob_attr *config;
140 /* primary protocol state */
141 const struct proto_handler *proto_handler;
142 struct interface_proto_state *proto;
144 struct interface_ip_settings proto_ip;
145 struct interface_ip_settings config_ip;
146 struct vlist_tree host_routes;
150 unsigned int ip4table;
151 unsigned int ip6table;
153 /* IPv6 assignment parameters */
154 enum interface_id_selection_type assignment_iface_id_selection;
155 struct in6_addr assignment_fixed_iface_id;
156 uint8_t assignment_length;
157 int32_t assignment_hint;
158 struct list_head assignment_classes;
159 int assignment_weight;
161 /* errors/warnings while trying to bring up the interface */
162 struct list_head errors;
164 /* extra data provided by protocol handlers or modules */
165 struct avl_tree data;
167 struct uloop_timeout remove_timer;
168 struct ubus_object ubus;
172 extern struct vlist_tree interfaces;
173 extern const struct uci_blob_param_list interface_attr_list;
175 struct interface *interface_alloc(const char *name, struct blob_attr *config);
177 void interface_set_dynamic(struct interface *iface);
179 void interface_add(struct interface *iface, struct blob_attr *config);
180 bool interface_add_alias(struct interface *iface, struct blob_attr *config);
182 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
184 void interface_set_available(struct interface *iface, bool new_state);
185 int interface_set_up(struct interface *iface);
186 int interface_set_down(struct interface *iface);
187 void __interface_set_down(struct interface *iface, bool force);
188 int interface_renew(struct interface *iface);
190 void interface_set_main_dev(struct interface *iface, struct device *dev);
191 void interface_set_l3_dev(struct interface *iface, struct device *dev);
193 void interface_add_user(struct interface_user *dep, struct interface *iface);
194 void interface_remove_user(struct interface_user *dep);
196 int interface_remove_link(struct interface *iface, struct device *dev);
197 int interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext);
199 void interface_add_error(struct interface *iface, const char *subsystem,
200 const char *code, const char **data, int n_data);
202 int interface_add_data(struct interface *iface, const struct blob_attr *data);
203 int interface_parse_data(struct interface *iface, const struct blob_attr *attr);
205 void interface_update_start(struct interface *iface, const bool keep_old);
206 void interface_update_complete(struct interface *iface);
208 void interface_start_pending(void);