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
);
22 enum dev_change_type
{
29 struct list_head list
;
32 const struct config_param_list
*config_params
;
34 struct device
*(*create
)(const char *name
, struct blob_attr
*attr
);
35 void (*config_init
)(struct device
*);
36 enum dev_change_type (*reload
)(struct device
*, struct blob_attr
*);
37 void (*dump_info
)(struct device
*, struct blob_buf
*buf
);
38 void (*dump_stats
)(struct device
*, struct blob_buf
*buf
);
39 int (*check_state
)(struct device
*);
40 void (*free
)(struct device
*);
44 DEV_OPT_MTU
= (1 << 0),
45 DEV_OPT_MACADDR
= (1 << 1),
46 DEV_OPT_TXQUEUELEN
= (1 << 2)
49 /* events broadcasted to all users of a device */
64 * device dependency with callbacks
67 struct list_head list
;
73 void (*cb
)(struct device_user
*, enum device_event
);
77 * link layer device. typically represents a linux network device.
78 * can be used to support VLANs as well
81 const struct device_type
*type
;
84 struct list_head users
;
86 char ifname
[IFNAMSIZ
+ 1];
89 struct blob_attr
*config
;
98 /* set interface up or down */
99 device_state_cb set_state
;
101 const struct device_hotplug_ops
*hotplug_ops
;
103 struct device_user parent
;
109 unsigned int txqueuelen
;
113 struct device_hotplug_ops
{
114 int (*add
)(struct device
*main
, struct device
*member
);
115 int (*del
)(struct device
*main
, struct device
*member
);
118 extern const struct config_param_list device_attr_list
;
119 extern const struct device_type simple_device_type
;
120 extern const struct device_type bridge_device_type
;
122 void device_lock(void);
123 void device_unlock(void);
125 struct device
*device_create(const char *name
, const struct device_type
*type
,
126 struct blob_attr
*config
);
127 void device_init_settings(struct device
*dev
, struct blob_attr
**tb
);
128 void device_init_pending(void);
131 device_set_config(struct device
*dev
, const struct device_type
*type
,
132 struct blob_attr
*attr
);
134 void device_reset_config(void);
135 void device_reset_old(void);
137 void device_init_virtual(struct device
*dev
, const struct device_type
*type
, const char *name
);
138 int device_init(struct device
*iface
, const struct device_type
*type
, const char *ifname
);
139 void device_cleanup(struct device
*iface
);
140 struct device
*device_get(const char *name
, int create
);
141 void device_add_user(struct device_user
*dep
, struct device
*iface
);
142 void device_remove_user(struct device_user
*dep
);
144 void device_set_present(struct device
*dev
, bool state
);
145 int device_claim(struct device_user
*dep
);
146 void device_release(struct device_user
*dep
);
147 int device_check_state(struct device
*dev
);
148 void device_dump_status(struct blob_buf
*b
, struct device
*dev
);
151 device_free(struct device
*dev
)
153 dev
->type
->free(dev
);
156 void device_free_unused(struct device
*dev
);
158 struct device
*get_vlan_device_chain(const char *ifname
, bool create
);
159 void alias_notify_device(const char *name
, struct device
*dev
);