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 /* send when a new interface created. This is before proto handlers has been attached. */
35 enum interface_state
{
42 enum interface_config_state
{
48 enum interface_id_selection_type
{
54 enum interface_update_flags
{
55 IUF_ADDRESS
= (1 << 0),
57 IUF_PREFIX
= (1 << 2),
61 struct interface_error
{
62 struct list_head list
;
64 const char *subsystem
;
69 struct interface_user
{
70 struct list_head list
;
71 struct interface
*iface
;
72 void (*cb
)(struct interface_user
*dep
, struct interface
*iface
, enum interface_event ev
);
75 struct interface_ip_settings
{
76 struct interface
*iface
;
82 struct vlist_tree addr
;
83 struct vlist_tree route
;
84 struct vlist_tree prefix
;
85 struct vlist_tree neighbor
;
87 struct vlist_simple_tree dns_servers
;
88 struct vlist_simple_tree dns_search
;
91 struct interface_data
{
93 struct blob_attr data
[];
96 struct interface_assignment_class
{
97 struct list_head head
;
102 * interface configuration
105 struct vlist_node node
;
106 struct list_head hotplug_list
;
107 enum interface_event hotplug_ev
;
119 bool config_autostart
;
125 bool policy_rules_set
;
129 enum interface_state state
;
130 enum interface_config_state config_state
;
131 enum interface_update_flags updated
;
133 struct list_head users
;
135 /* for alias interface */
136 const char *parent_ifname
;
137 struct interface_user parent_iface
;
139 /* main interface that the interface is bound to */
140 struct device_user main_dev
;
141 struct device_user ext_dev
;
143 /* interface that layer 3 communication will go through */
144 struct device_user l3_dev
;
146 struct blob_attr
*config
;
148 /* primary protocol state */
149 const struct proto_handler
*proto_handler
;
150 struct interface_proto_state
*proto
;
152 struct interface_ip_settings proto_ip
;
153 struct interface_ip_settings config_ip
;
154 struct vlist_tree host_routes
;
155 struct vlist_tree host_neighbors
;
159 unsigned int ip4table
;
160 unsigned int ip6table
;
162 /* IPv6 assignment parameters */
163 enum interface_id_selection_type assignment_iface_id_selection
;
164 struct in6_addr assignment_fixed_iface_id
;
165 uint8_t assignment_length
;
166 int32_t assignment_hint
;
167 struct list_head assignment_classes
;
168 int assignment_weight
;
170 /* errors/warnings while trying to bring up the interface */
171 struct list_head errors
;
173 /* extra data provided by protocol handlers or modules */
174 struct avl_tree data
;
176 struct uloop_timeout remove_timer
;
177 struct ubus_object ubus
;
181 extern struct vlist_tree interfaces
;
182 extern const struct uci_blob_param_list interface_attr_list
;
184 struct interface
*interface_alloc(const char *name
, struct blob_attr
*config
, bool dynamic
);
186 bool interface_add(struct interface
*iface
, struct blob_attr
*config
);
187 bool interface_add_alias(struct interface
*iface
, struct blob_attr
*config
);
189 void interface_set_proto_state(struct interface
*iface
, struct interface_proto_state
*state
);
191 void interface_set_available(struct interface
*iface
, bool new_state
);
192 void interface_set_up(struct interface
*iface
);
193 void interface_set_down(struct interface
*iface
);
194 int interface_renew(struct interface
*iface
);
196 void interface_set_l3_dev(struct interface
*iface
, struct device
*dev
);
198 void interface_add_user(struct interface_user
*dep
, struct interface
*iface
);
199 void interface_remove_user(struct interface_user
*dep
);
201 int interface_handle_link(struct interface
*iface
, const char *name
, struct blob_attr
*vlan
, bool add
, bool link_ext
);
203 void interface_add_error(struct interface
*iface
, const char *subsystem
,
204 const char *code
, const char **data
, int n_data
);
206 int interface_add_data(struct interface
*iface
, const struct blob_attr
*data
);
207 int interface_parse_data(struct interface
*iface
, const struct blob_attr
*attr
);
209 void interface_update_start(struct interface
*iface
, const bool keep_old
);
210 void interface_update_complete(struct interface
*iface
);
212 void interface_start_pending(void);
213 void interface_start_jail(int netns_fd
, const char *jail
);
214 void interface_stop_jail(int netns_fd
);