4 #include <libubox/avl.h>
5 #include <netinet/in.h>
9 struct device_hotplug_ops;
11 typedef int (*device_state_cb)(struct device *, bool up);
23 enum dev_change_type {
31 struct list_head list;
34 const struct config_param_list *config_params;
36 struct device *(*create)(const char *name, struct blob_attr *attr);
37 void (*config_init)(struct device *);
38 enum dev_change_type (*reload)(struct device *, struct blob_attr *);
39 void (*dump_info)(struct device *, struct blob_buf *buf);
40 void (*dump_stats)(struct device *, struct blob_buf *buf);
41 int (*check_state)(struct device *);
42 void (*free)(struct device *);
46 DEV_OPT_MTU = (1 << 0),
47 DEV_OPT_MACADDR = (1 << 1),
48 DEV_OPT_TXQUEUELEN = (1 << 2)
51 /* events broadcasted to all users of a device */
66 * device dependency with callbacks
69 struct list_head list;
75 void (*cb)(struct device_user *, enum device_event);
78 struct device_settings {
81 unsigned int txqueuelen;
86 * link layer device. typically represents a linux network device.
87 * can be used to support VLANs as well
90 const struct device_type *type;
93 struct list_head users;
95 char ifname[IFNAMSIZ + 1];
98 struct blob_attr *config;
109 /* set interface up or down */
110 device_state_cb set_state;
112 const struct device_hotplug_ops *hotplug_ops;
114 struct device_user parent;
116 struct device_settings orig_settings;
117 struct device_settings settings;
120 struct device_hotplug_ops {
121 int (*prepare)(struct device *dev);
122 int (*add)(struct device *main, struct device *member);
123 int (*del)(struct device *main, struct device *member);
126 extern const struct config_param_list device_attr_list;
127 extern const struct device_type simple_device_type;
128 extern const struct device_type bridge_device_type;
129 extern const struct device_type tunnel_device_type;
131 void device_lock(void);
132 void device_unlock(void);
134 struct device *device_create(const char *name, const struct device_type *type,
135 struct blob_attr *config);
136 void device_init_settings(struct device *dev, struct blob_attr **tb);
137 void device_init_pending(void);
140 device_set_config(struct device *dev, const struct device_type *type,
141 struct blob_attr *attr);
143 void device_reset_config(void);
144 void device_reset_old(void);
146 void device_init_virtual(struct device *dev, const struct device_type *type, const char *name);
147 int device_init(struct device *iface, const struct device_type *type, const char *ifname);
148 void device_cleanup(struct device *iface);
149 struct device *device_get(const char *name, int create);
150 void device_add_user(struct device_user *dep, struct device *iface);
151 void device_remove_user(struct device_user *dep);
153 void device_set_present(struct device *dev, bool state);
154 void device_set_disabled(struct device *dev, bool value);
155 int device_claim(struct device_user *dep);
156 void device_release(struct device_user *dep);
157 int device_check_state(struct device *dev);
158 void device_dump_status(struct blob_buf *b, struct device *dev);
160 void device_free(struct device *dev);
161 void device_free_unused(struct device *dev);
163 struct device *get_vlan_device_chain(const char *ifname, bool create);
164 void alias_notify_device(const char *name, struct device *dev);