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_id_selection_type {
50 enum interface_update_flags {
51 IUF_ADDRESS = (1 << 0),
53 IUF_PREFIX = (1 << 2),
57 struct interface_error {
58 struct list_head list;
60 const char *subsystem;
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);
71 struct interface_ip_settings {
72 struct interface *iface;
78 struct vlist_tree addr;
79 struct vlist_tree route;
80 struct vlist_tree prefix;
82 struct vlist_simple_tree dns_servers;
83 struct vlist_simple_tree dns_search;
86 struct interface_data {
88 struct blob_attr data[];
91 struct interface_assignment_class {
92 struct list_head head;
97 * interface configuration
100 struct vlist_node node;
101 struct list_head hotplug_list;
102 enum interface_event hotplug_ev;
109 bool config_autostart;
115 bool policy_rules_set;
118 enum interface_state state;
119 enum interface_config_state config_state;
120 enum interface_update_flags updated;
122 struct list_head users;
124 /* for alias interface */
125 const char *parent_ifname;
126 struct interface_user parent_iface;
128 /* main interface that the interface is bound to */
129 struct device_user main_dev;
130 struct device_user ext_dev;
132 /* interface that layer 3 communication will go through */
133 struct device_user l3_dev;
135 struct blob_attr *config;
137 /* primary protocol state */
138 const struct proto_handler *proto_handler;
139 struct interface_proto_state *proto;
141 struct interface_ip_settings proto_ip;
142 struct interface_ip_settings config_ip;
143 struct vlist_tree host_routes;
146 unsigned int ip4table;
147 unsigned int ip6table;
149 /* IPv6 assignment parameters */
150 enum interface_id_selection_type assignment_iface_id_selection;
151 struct in6_addr assignment_fixed_iface_id;
152 uint8_t assignment_length;
153 int32_t assignment_hint;
154 struct list_head assignment_classes;
156 /* errors/warnings while trying to bring up the interface */
157 struct list_head errors;
159 /* extra data provided by protocol handlers or modules */
160 struct avl_tree data;
162 struct uloop_timeout remove_timer;
163 struct ubus_object ubus;
167 extern struct vlist_tree interfaces;
168 extern const struct uci_blob_param_list interface_attr_list;
170 struct interface *interface_alloc(const char *name, struct blob_attr *config);
172 void interface_set_dynamic(struct interface *iface);
174 void interface_add(struct interface *iface, struct blob_attr *config);
175 bool interface_add_alias(struct interface *iface, struct blob_attr *config);
177 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
179 void interface_set_available(struct interface *iface, bool new_state);
180 int interface_set_up(struct interface *iface);
181 int interface_set_down(struct interface *iface);
182 void __interface_set_down(struct interface *iface, bool force);
184 void interface_set_main_dev(struct interface *iface, struct device *dev);
185 void interface_set_l3_dev(struct interface *iface, struct device *dev);
187 void interface_add_user(struct interface_user *dep, struct interface *iface);
188 void interface_remove_user(struct interface_user *dep);
190 int interface_remove_link(struct interface *iface, struct device *dev);
191 int interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext);
193 void interface_add_error(struct interface *iface, const char *subsystem,
194 const char *code, const char **data, int n_data);
196 int interface_add_data(struct interface *iface, const struct blob_attr *data);
197 int interface_parse_data(struct interface *iface, const struct blob_attr *attr);
199 void interface_update_start(struct interface *iface);
200 void interface_update_complete(struct interface *iface);
202 void interface_start_pending(void);