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
{
30 enum interface_state
{
37 enum interface_config_state
{
43 struct interface_error
{
44 struct list_head list
;
46 const char *subsystem
;
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
);
57 struct interface_ip_settings
{
58 struct interface
*iface
;
62 uint8_t assignment_length
;
64 struct vlist_tree addr
;
65 struct vlist_tree route
;
66 struct vlist_tree prefix
;
68 struct vlist_simple_tree dns_servers
;
69 struct vlist_simple_tree dns_search
;
72 struct interface_data
{
74 struct blob_attr data
[];
78 * interface configuration
81 struct vlist_node node
;
82 struct list_head hotplug_list
;
83 enum interface_event hotplug_ev
;
90 bool config_autostart
;
94 enum interface_state state
;
95 enum interface_config_state config_state
;
97 struct list_head users
;
99 const char *parent_ifname
;
100 struct interface_user parent_iface
;
102 /* main interface that the interface is bound to */
103 struct device_user main_dev
;
105 /* interface that layer 3 communication will go through */
106 struct device_user l3_dev
;
108 struct blob_attr
*config
;
110 /* primary protocol state */
111 const struct proto_handler
*proto_handler
;
112 struct interface_proto_state
*proto
;
114 struct interface_ip_settings proto_ip
;
115 struct interface_ip_settings config_ip
;
116 struct vlist_tree host_routes
;
120 /* errors/warnings while trying to bring up the interface */
121 struct list_head errors
;
123 /* extra data provided by protocol handlers or modules */
124 struct avl_tree data
;
126 struct uloop_timeout remove_timer
;
127 struct ubus_object ubus
;
131 extern struct vlist_tree interfaces
;
132 extern const struct config_param_list interface_attr_list
;
134 void interface_init(struct interface
*iface
, const char *name
,
135 struct blob_attr
*config
);
137 void interface_add(struct interface
*iface
, struct blob_attr
*config
);
138 bool interface_add_alias(struct interface
*iface
, struct blob_attr
*config
);
140 void interface_set_proto_state(struct interface
*iface
, struct interface_proto_state
*state
);
142 void interface_set_available(struct interface
*iface
, bool new_state
);
143 int interface_set_up(struct interface
*iface
);
144 int interface_set_down(struct interface
*iface
);
145 void __interface_set_down(struct interface
*iface
, bool force
);
147 void interface_set_main_dev(struct interface
*iface
, struct device
*dev
);
148 void interface_set_l3_dev(struct interface
*iface
, struct device
*dev
);
150 void interface_add_user(struct interface_user
*dep
, struct interface
*iface
);
151 void interface_remove_user(struct interface_user
*dep
);
153 int interface_add_link(struct interface
*iface
, struct device
*dev
);
154 int interface_remove_link(struct interface
*iface
, struct device
*dev
);
156 void interface_add_error(struct interface
*iface
, const char *subsystem
,
157 const char *code
, const char **data
, int n_data
);
159 int interface_add_data(struct interface
*iface
, const struct blob_attr
*data
);
161 void interface_update_start(struct interface
*iface
);
162 void interface_update_complete(struct interface
*iface
);
164 void interface_start_pending(void);