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

Sources/netifd/device.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_DEVICE_H
 15 #define __NETIFD_DEVICE_H
 16 
 17 #include <libubox/avl.h>
 18 #include <libubox/safe_list.h>
 19 #include <libubox/kvlist.h>
 20 #include <netinet/in.h>
 21 
 22 struct device;
 23 struct device_type;
 24 struct device_user;
 25 struct device_hotplug_ops;
 26 struct bridge_vlan;
 27 struct interface;
 28 
 29 typedef int (*device_state_cb)(struct device *, bool up);
 30 
 31 enum {
 32         DEV_ATTR_TYPE,
 33         DEV_ATTR_MTU,
 34         DEV_ATTR_MTU6,
 35         DEV_ATTR_MACADDR,
 36         DEV_ATTR_TXQUEUELEN,
 37         DEV_ATTR_ENABLED,
 38         DEV_ATTR_IPV6,
 39         DEV_ATTR_PROMISC,
 40         DEV_ATTR_RPFILTER,
 41         DEV_ATTR_ACCEPTLOCAL,
 42         DEV_ATTR_IGMPVERSION,
 43         DEV_ATTR_MLDVERSION,
 44         DEV_ATTR_NEIGHREACHABLETIME,
 45         DEV_ATTR_DADTRANSMITS,
 46         DEV_ATTR_MULTICAST_TO_UNICAST,
 47         DEV_ATTR_MULTICAST_ROUTER,
 48         DEV_ATTR_MULTICAST_FAST_LEAVE,
 49         DEV_ATTR_MULTICAST,
 50         DEV_ATTR_LEARNING,
 51         DEV_ATTR_UNICAST_FLOOD,
 52         DEV_ATTR_NEIGHGCSTALETIME,
 53         DEV_ATTR_SENDREDIRECTS,
 54         DEV_ATTR_NEIGHLOCKTIME,
 55         DEV_ATTR_ISOLATE,
 56         DEV_ATTR_IP6SEGMENTROUTING,
 57         DEV_ATTR_DROP_V4_UNICAST_IN_L2_MULTICAST,
 58         DEV_ATTR_DROP_V6_UNICAST_IN_L2_MULTICAST,
 59         DEV_ATTR_DROP_GRATUITOUS_ARP,
 60         DEV_ATTR_DROP_UNSOLICITED_NA,
 61         DEV_ATTR_ARP_ACCEPT,
 62         DEV_ATTR_AUTH,
 63         DEV_ATTR_AUTH_VLAN,
 64         DEV_ATTR_SPEED,
 65         DEV_ATTR_DUPLEX,
 66         DEV_ATTR_VLAN,
 67         DEV_ATTR_PAUSE,
 68         DEV_ATTR_ASYM_PAUSE,
 69         DEV_ATTR_RXPAUSE,
 70         DEV_ATTR_TXPAUSE,
 71         DEV_ATTR_AUTONEG,
 72         DEV_ATTR_GRO,
 73         DEV_ATTR_MASTER,
 74         DEV_ATTR_EEE,
 75         DEV_ATTR_TAGS,
 76         DEV_ATTR_PSE,
 77         DEV_ATTR_PSE_PODL,
 78         DEV_ATTR_PSE_POWER_LIMIT,
 79         DEV_ATTR_PSE_PRIORITY,
 80         __DEV_ATTR_MAX,
 81 };
 82 
 83 enum dev_change_type {
 84         DEV_CONFIG_NO_CHANGE,
 85         DEV_CONFIG_APPLIED,
 86         DEV_CONFIG_RESTART,
 87         DEV_CONFIG_RECREATE,
 88 };
 89 
 90 struct device_type {
 91         struct list_head list;
 92         const char *name;
 93 
 94         bool bridge_capability;
 95         const char *name_prefix;
 96 
 97         const struct uci_blob_param_list *config_params;
 98 
 99         struct device *(*create)(const char *name, struct device_type *devtype,
100                 struct blob_attr *attr);
101         void (*config_init)(struct device *);
102         enum dev_change_type (*reload)(struct device *, struct blob_attr *);
103         void (*vlan_update)(struct device *);
104         void (*dump_info)(struct device *, struct blob_buf *buf);
105         void (*dump_stats)(struct device *, struct blob_buf *buf);
106         int (*check_state)(struct device *);
107         void (*stp_init)(struct device *);
108         void (*free)(struct device *);
109 };
110 
111 enum {
112         DEV_OPT_MTU                     = (1ULL << 0),
113         DEV_OPT_MACADDR                 = (1ULL << 1),
114         DEV_OPT_TXQUEUELEN              = (1ULL << 2),
115         DEV_OPT_IPV6                    = (1ULL << 3),
116         DEV_OPT_PROMISC                 = (1ULL << 4),
117         DEV_OPT_RPFILTER                = (1ULL << 5),
118         DEV_OPT_ACCEPTLOCAL             = (1ULL << 6),
119         DEV_OPT_IGMPVERSION             = (1ULL << 7),
120         DEV_OPT_MLDVERSION              = (1ULL << 8),
121         DEV_OPT_NEIGHREACHABLETIME      = (1ULL << 9),
122         DEV_OPT_DEFAULT_MACADDR         = (1ULL << 10),
123         DEV_OPT_AUTH                    = (1ULL << 11),
124         DEV_OPT_MTU6                    = (1ULL << 12),
125         DEV_OPT_DADTRANSMITS            = (1ULL << 13),
126         DEV_OPT_MULTICAST_TO_UNICAST    = (1ULL << 14),
127         DEV_OPT_MULTICAST_ROUTER        = (1ULL << 15),
128         DEV_OPT_MULTICAST               = (1ULL << 16),
129         DEV_OPT_LEARNING                = (1ULL << 17),
130         DEV_OPT_UNICAST_FLOOD           = (1ULL << 18),
131         DEV_OPT_NEIGHGCSTALETIME        = (1ULL << 19),
132         DEV_OPT_MULTICAST_FAST_LEAVE    = (1ULL << 20),
133         DEV_OPT_SENDREDIRECTS           = (1ULL << 21),
134         DEV_OPT_NEIGHLOCKTIME           = (1ULL << 22),
135         DEV_OPT_ISOLATE                 = (1ULL << 23),
136         DEV_OPT_IP6SEGMENTROUTING       = (1ULL << 24),
137         DEV_OPT_DROP_V4_UNICAST_IN_L2_MULTICAST = (1ULL << 25),
138         DEV_OPT_DROP_V6_UNICAST_IN_L2_MULTICAST = (1ULL << 26),
139         DEV_OPT_DROP_GRATUITOUS_ARP     = (1ULL << 27),
140         DEV_OPT_DROP_UNSOLICITED_NA     = (1ULL << 28),
141         DEV_OPT_ARP_ACCEPT              = (1ULL << 29),
142         DEV_OPT_SPEED                   = (1ULL << 30),
143         DEV_OPT_DUPLEX                  = (1ULL << 31),
144         DEV_OPT_PAUSE                   = (1ULL << 32),
145         DEV_OPT_ASYM_PAUSE              = (1ULL << 33),
146         DEV_OPT_RXPAUSE                 = (1ULL << 34),
147         DEV_OPT_TXPAUSE                 = (1ULL << 35),
148         DEV_OPT_AUTONEG                 = (1ULL << 36),
149         DEV_OPT_GRO                     = (1ULL << 37),
150         DEV_OPT_MASTER                  = (1ULL << 38),
151         DEV_OPT_EEE                     = (1ULL << 39),
152         DEV_OPT_PSE                     = (1ULL << 40),
153         DEV_OPT_PSE_PODL                = (1ULL << 41),
154         DEV_OPT_PSE_POWER_LIMIT         = (1ULL << 42),
155         DEV_OPT_PSE_PRIORITY            = (1ULL << 43),
156 };
157 
158 /* events broadcasted to all users of a device */
159 enum device_event {
160         DEV_EVENT_ADD,
161         DEV_EVENT_REMOVE,
162 
163         DEV_EVENT_UPDATE_IFNAME,
164         DEV_EVENT_UPDATE_IFINDEX,
165 
166         DEV_EVENT_SETUP,
167         DEV_EVENT_TEARDOWN,
168         DEV_EVENT_UP,
169         DEV_EVENT_DOWN,
170 
171         DEV_EVENT_AUTH_UP,
172         DEV_EVENT_LINK_UP,
173         DEV_EVENT_LINK_DOWN,
174 
175         /* Topology changed (i.e. bridge member added) */
176         DEV_EVENT_TOPO_CHANGE,
177 
178         __DEV_EVENT_MAX
179 };
180 
181 /*
182  * device dependency with callbacks
183  */
184 struct device_user {
185         struct safe_list list;
186 
187         bool claimed;
188         bool hotplug;
189         bool alias;
190 
191         uint8_t ev_idx[__DEV_EVENT_MAX];
192 
193         struct device *dev;
194         void (*cb)(struct device_user *, enum device_event);
195 };
196 
197 struct device_settings {
198         uint64_t flags;
199         uint64_t valid_flags;
200         unsigned int mtu;
201         unsigned int mtu6;
202         unsigned int txqueuelen;
203         uint8_t macaddr[6];
204         bool ipv6;
205         bool promisc;
206         unsigned int rpfilter;
207         bool acceptlocal;
208         unsigned int igmpversion;
209         unsigned int mldversion;
210         unsigned int neigh4reachabletime;
211         unsigned int neigh6reachabletime;
212         unsigned int neigh4gcstaletime;
213         unsigned int neigh6gcstaletime;
214         int neigh4locktime;
215         unsigned int dadtransmits;
216         bool multicast_to_unicast;
217         unsigned int multicast_router;
218         bool multicast_fast_leave;
219         bool multicast;
220         bool learning;
221         bool unicast_flood;
222         bool sendredirects;
223         bool ip6segmentrouting;
224         bool isolate;
225         bool drop_v4_unicast_in_l2_multicast;
226         bool drop_v6_unicast_in_l2_multicast;
227         bool drop_gratuitous_arp;
228         bool drop_unsolicited_na;
229         bool arp_accept;
230         bool auth;
231         unsigned int speed;
232         bool duplex;
233         bool pause;
234         bool asym_pause;
235         bool rxpause;
236         bool txpause;
237         bool autoneg;
238         bool gro;
239         int master_ifindex;
240         bool eee;
241         bool pse;
242         bool pse_podl;
243         unsigned int pse_power_limit;
244         unsigned int pse_priority;
245 };
246 
247 struct device_vlan_range {
248         uint16_t start, end;
249 };
250 
251 /*
252  * link layer device. typically represents a linux network device.
253  * can be used to support VLANs as well
254  */
255 struct device {
256         struct device_type *type;
257 
258         struct avl_node avl;
259         struct safe_list users;
260         struct safe_list aliases;
261 
262         struct vlist_tree vlans;
263         struct kvlist vlan_aliases;
264         struct blob_attr *config_auth_vlans;
265         struct blob_attr *auth_vlans;
266         struct blob_attr *tags;
267 
268         char ifname[IFNAMSIZ];
269         int ifindex;
270 
271         struct blob_attr *config;
272         bool config_pending;
273         bool sys_present;
274         /* DEV_EVENT_ADD */
275         bool present;
276         /* DEV_EVENT_UP */
277         int active;
278         /* DEV_EVENT_LINK_UP */
279         bool link_active;
280         bool auth_status;
281 
282         bool external;
283         bool disabled;
284         bool deferred;
285         bool hidden;
286 
287         bool current_config;
288         bool iface_config;
289         bool default_config;
290         bool wireless;
291         bool wireless_ap;
292         bool wireless_proxyarp;
293         bool wireless_isolate;
294         bool bpdu_filter;
295 
296         struct interface *config_iface;
297         struct device_vlan_range *extra_vlan;
298         int n_extra_vlan;
299 
300         /* set interface up or down */
301         device_state_cb set_state;
302 
303         const struct device_hotplug_ops *hotplug_ops;
304 
305         struct device_user parent;
306 
307         struct device_settings orig_settings;
308         struct device_settings settings;
309 };
310 
311 struct device_hotplug_ops {
312         int (*prepare)(struct device *dev, struct device **bridge_dev);
313         int (*add)(struct device *main, struct device *member, struct blob_attr *vlan);
314         int (*del)(struct device *main, struct device *member, struct blob_attr *vlan);
315 };
316 
317 enum bridge_vlan_flags {
318         BRVLAN_F_SELF =         (1 << 0),
319         BRVLAN_F_PVID =         (1 << 1),
320         BRVLAN_F_UNTAGGED =     (1 << 2),
321 };
322 
323 struct bridge_vlan_port {
324         const char *ifname;
325         uint16_t flags;
326         int8_t check;
327 };
328 
329 struct bridge_vlan_hotplug_port {
330         struct list_head list;
331         struct bridge_vlan_port port;
332 };
333 
334 struct bridge_vlan {
335         struct vlist_node node;
336 
337         struct bridge_vlan_port *ports;
338         int n_ports;
339 
340         struct list_head hotplug_ports;
341 
342         uint16_t vid;
343         bool local;
344         bool pending;
345 };
346 
347 extern const struct uci_blob_param_list device_attr_list;
348 extern struct device_type simple_device_type;
349 extern struct device_type tunnel_device_type;
350 
351 void device_vlan_update(bool done);
352 void device_stp_init(void);
353 
354 int device_type_add(struct device_type *devtype);
355 struct device_type *device_type_get(const char *tname);
356 struct device *device_create(const char *name, struct device_type *type,
357                              struct blob_attr *config);
358 void device_merge_settings(struct device *dev, struct device_settings *n);
359 void device_init_settings(struct device *dev, struct blob_attr **tb);
360 void device_init_pending(void);
361 
362 enum dev_change_type
363 device_apply_config(struct device *dev, struct device_type *type,
364                     struct blob_attr *config);
365 
366 void device_reset_config(void);
367 void device_reset_old(void);
368 
369 int device_init_virtual(struct device *dev, struct device_type *type, const char *name);
370 int device_init(struct device *dev, struct device_type *type, const char *ifname);
371 void device_cleanup(struct device *dev);
372 struct device *device_find(const char *name);
373 
374 struct device *__device_get(const char *name, int create, bool check_vlan);
375 static inline struct device *device_get(const char *name, int create)
376 {
377         return __device_get(name, create, true);
378 }
379 
380 void device_add_user(struct device_user *dep, struct device *dev);
381 void device_remove_user(struct device_user *dep);
382 const char *device_event_name(enum device_event ev);
383 void __device_broadcast_event(struct device *dev, enum device_event ev);
384 #define device_broadcast_event(dev, ev) do {                                    \
385         struct device *__ev_dev = (dev);                                        \
386         D(DEVICE, "%s: event (%s)",                                             \
387           (__ev_dev && __ev_dev->ifname[0] ? __ev_dev->ifname : "(none)"),      \
388           device_event_name(ev));                                               \
389         __device_broadcast_event(__ev_dev, ev);                                 \
390 } while (0)
391 
392 void _device_set_present(struct device *dev, bool state);
393 #define device_set_present(dev, state) do {                                     \
394         struct device *__ev_dev = (dev);                                        \
395         bool __ev_state = state;                                                \
396         D(DEVICE, "%s: set present=%d",                                         \
397           (__ev_dev && __ev_dev->ifname[0] ? __ev_dev->ifname : "(none)"),      \
398           __ev_state);                                                          \
399         _device_set_present(__ev_dev, __ev_state);                              \
400 } while (0)
401 
402 void device_set_link(struct device *dev, bool state);
403 void device_set_ifindex(struct device *dev, int ifindex);
404 int device_set_ifname(struct device *dev, const char *name);
405 void device_refresh_present(struct device *dev);
406 int device_claim(struct device_user *dep);
407 void device_release(struct device_user *dep);
408 int device_check_state(struct device *dev);
409 void device_dump_status(struct blob_buf *b, struct device *dev);
410 
411 void device_free_unused(void);
412 
413 struct device *get_vlan_device_chain(const char *ifname, int create);
414 void alias_notify_device(const char *name, struct device *dev);
415 struct device *device_alias_get(const char *name);
416 
417 void device_set_auth_status(struct device *dev, bool value, struct blob_attr *vlans);
418 
419 static inline void
420 device_set_deferred(struct device *dev, bool value)
421 {
422         dev->deferred = value;
423         device_refresh_present(dev);
424 }
425 
426 static inline void
427 device_set_disabled(struct device *dev, bool value)
428 {
429         dev->disabled = value;
430         device_refresh_present(dev);
431 }
432 
433 static inline bool
434 device_link_active(struct device *dev)
435 {
436         if (dev->settings.auth && !dev->auth_status)
437                 return false;
438 
439         return dev->link_active;
440 }
441 
442 bool device_check_ip6segmentrouting(void);
443 void device_hotplug_event(const char *name, bool add);
444 
445 #endif
446 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt