add an example script for ifup/ifdown
[project/netifd.git] / interface.h
1 #ifndef __NETIFD_INTERFACE_H
2 #define __NETIFD_INTERFACE_H
3
4 struct interface;
5 struct interface_proto;
6 struct interface_proto_state;
7
8 extern struct list_head interfaces;
9
10 enum interface_event {
11         IFEV_UP,
12         IFEV_DOWN,
13 };
14
15 struct interface_proto_state {
16         const struct interface_proto *proto;
17
18         int (*event)(struct interface *, struct interface_proto_state *, enum interface_event ev);
19         void (*free)(struct interface *, struct interface_proto_state *);
20 };
21
22 /*
23  * interface configuration
24  */
25 struct interface {
26         struct list_head list;
27
28         char name[IFNAMSIZ - 2];
29
30         /* interface is up and running */
31         bool up;
32
33         /* interface can be brought up */
34         bool active;
35
36         /* interface will be brought up when available */
37         bool autostart;
38
39         /* main interface that the interface is bound to */
40         struct device_user main_dev;
41
42         /* interface that layer 3 communication will go through */
43         struct device_user *l3_iface;
44
45         /* primary protocol state */
46         struct interface_proto_state *state;
47
48         struct ubus_object ubus;
49 };
50
51 struct interface *get_interface(const char *name);
52 struct interface *alloc_interface(const char *name);
53 void free_interface(struct interface *iface);
54
55 int set_interface_up(struct interface *iface);
56 int set_interface_down(struct interface *iface);
57
58 int interface_add_link(struct interface *iface, struct device *llif);
59 void interface_remove_link(struct interface *iface, struct device *llif);
60
61 int interface_attach_bridge(struct interface *iface, struct uci_section *s);
62
63 #endif