• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/netifd/interface.h

  1 /*
  2  * netifd - network interface daemon
  3  * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4  *
  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
  8  *
  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.
 13  */
 14 #ifndef __NETIFD_INTERFACE_H
 15 #define __NETIFD_INTERFACE_H
 16 
 17 #include "device.h"
 18 #include "config.h"
 19 
 20 struct interface;
 21 struct interface_proto_state;
 22 
 23 enum interface_event {
 24         IFEV_DOWN,
 25         IFEV_UP,
 26         IFEV_UP_FAILED,
 27         IFEV_UPDATE,
 28         IFEV_FREE,
 29         IFEV_RELOAD,
 30         IFEV_LINK_UP,
 31         /* send when a new interface created. This is before proto handlers has been attached. */
 32         IFEV_CREATE,
 33 };
 34 
 35 enum interface_state {
 36         IFS_SETUP,
 37         IFS_UP,
 38         IFS_TEARDOWN,
 39         IFS_DOWN,
 40 };
 41 
 42 enum interface_config_state {
 43         IFC_NORMAL,
 44         IFC_RELOAD,
 45         IFC_REMOVE
 46 };
 47 
 48 enum interface_id_selection_type {
 49         IFID_FIXED,
 50         IFID_RANDOM,
 51         IFID_EUI64
 52 };
 53 
 54 enum interface_update_flags {
 55         IUF_ADDRESS     = (1 << 0),
 56         IUF_ROUTE       = (1 << 1),
 57         IUF_PREFIX      = (1 << 2),
 58         IUF_DATA        = (1 << 3),
 59 };
 60 
 61 struct interface_error {
 62         struct list_head list;
 63 
 64         const char *subsystem;
 65         const char *code;
 66         const char *data[];
 67 };
 68 
 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);
 73 };
 74 
 75 struct interface_ip_settings {
 76         struct interface *iface;
 77         bool enabled;
 78         bool no_defaultroute;
 79         bool no_dns;
 80         bool no_delegation;
 81 
 82         struct vlist_tree addr;
 83         struct vlist_tree route;
 84         struct vlist_tree prefix;
 85         struct vlist_tree neighbor;
 86 
 87         struct vlist_simple_tree dns_servers;
 88         struct vlist_simple_tree dns_search;
 89 };
 90 
 91 struct interface_data {
 92         struct avl_node node;
 93         struct blob_attr data[];
 94 };
 95 
 96 struct interface_assignment_class {
 97         struct list_head head;
 98         char name[];
 99 };
100 
101 /*
102  * interface configuration
103  */
104 struct interface {
105         struct vlist_node node;
106         struct list_head hotplug_list;
107         enum interface_event hotplug_ev;
108 
109         const char *name;
110         const char *device;
111         char *zone;
112         char *jail;
113         char *jail_device;
114         char *host_device;
115         int netns_fd;
116 
117         bool available;
118         bool autostart;
119         bool config_autostart;
120         bool device_config;
121         bool enabled;
122         bool link_state;
123         bool force_link;
124         bool dynamic;
125         bool policy_rules_set;
126         bool link_up_event;
127         bool renew;
128 
129         time_t start_time;
130         enum interface_state state;
131         enum interface_config_state config_state;
132         enum interface_update_flags updated;
133 
134         struct list_head users;
135 
136         /* for alias interface */
137         const char *parent_ifname;
138         struct interface_user parent_iface;
139 
140         /* main interface that the interface is bound to */
141         struct device_user main_dev;
142         struct device_user ext_dev;
143 
144         /* interface that layer 3 communication will go through */
145         struct device_user l3_dev;
146 
147         struct blob_attr *config;
148         struct blob_attr *tags;
149 
150         /* primary protocol state */
151         const struct proto_handler *proto_handler;
152         struct interface_proto_state *proto;
153 
154         struct interface_ip_settings proto_ip;
155         struct interface_ip_settings config_ip;
156         struct vlist_tree host_routes;
157         struct vlist_tree host_neighbors;
158 
159         int metric;
160         int dns_metric;
161         unsigned int ip4table;
162         unsigned int ip6table;
163 
164         /* IPv6 assignment parameters */
165         enum interface_id_selection_type assignment_iface_id_selection;
166         struct in6_addr assignment_fixed_iface_id;
167         uint8_t assignment_length;
168         int32_t assignment_hint;
169         struct list_head assignment_classes;
170         int assignment_weight;
171 
172         /* errors/warnings while trying to bring up the interface */
173         struct list_head errors;
174 
175         /* extra data provided by protocol handlers or modules */
176         struct avl_tree data;
177 
178         struct uloop_timeout remove_timer;
179         struct ubus_object ubus;
180 };
181 
182 
183 extern struct vlist_tree interfaces;
184 extern const struct uci_blob_param_list interface_attr_list;
185 
186 struct interface *interface_alloc(const char *name, struct blob_attr *config, bool dynamic);
187 
188 bool interface_add(struct interface *iface, struct blob_attr *config);
189 bool interface_add_alias(struct interface *iface, struct blob_attr *config);
190 
191 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
192 
193 void interface_set_available(struct interface *iface, bool new_state);
194 void interface_set_up(struct interface *iface);
195 void interface_set_down(struct interface *iface);
196 int interface_renew(struct interface *iface);
197 
198 void interface_set_l3_dev(struct interface *iface, struct device *dev);
199 
200 void interface_add_user(struct interface_user *dep, struct interface *iface);
201 void interface_remove_user(struct interface_user *dep);
202 
203 int interface_handle_link(struct interface *iface, const char *name, struct blob_attr *vlan, bool add, bool link_ext);
204 
205 void interface_add_error(struct interface *iface, const char *subsystem,
206                          const char *code, const char **data, int n_data);
207 
208 int interface_add_data(struct interface *iface, const struct blob_attr *data);
209 int interface_parse_data(struct interface *iface, const struct blob_attr *attr);
210 
211 void interface_update_start(struct interface *iface, const bool keep_old);
212 void interface_update_complete(struct interface *iface);
213 
214 void interface_start_pending(void);
215 void interface_start_jail(int netns_fd, const char *jail);
216 void interface_stop_jail(int netns_fd);
217 
218 #endif
219 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt