e19d61ddbc13c57ba13f35adb280169129638ee4
[project/netifd.git] / interface.h
1 #ifndef __NETIFD_INTERFACE_H
2 #define __NETIFD_INTERFACE_H
3
4 #include <netinet/in.h>
5 #include "device.h"
6
7 struct interface;
8 struct interface_proto_state;
9
10 enum interface_event {
11         IFEV_UP,
12         IFEV_DOWN,
13 };
14
15 enum interface_state {
16         IFS_SETUP,
17         IFS_UP,
18         IFS_TEARDOWN,
19         IFS_DOWN,
20 };
21
22 struct interface_error {
23         struct list_head list;
24
25         const char *subsystem;
26         const char *code;
27         const char *data[];
28 };
29
30 enum interface_addr_flags {
31         /* address family for routes and addresses */
32         IFADDR_INET4    = (0 << 0),
33         IFADDR_INET6    = (1 << 0),
34         IFADDR_FAMILY   = IFADDR_INET4 | IFADDR_INET6,
35
36         /* device route (no gateway) */
37         IFADDR_DEVICE   = (1 << 1),
38 };
39
40 union if_addr {
41         struct in_addr in;
42         struct in6_addr in6;
43 };
44
45 struct interface_addr {
46         struct list_head list;
47         void *ctx;
48
49         enum interface_addr_flags flags;
50
51         unsigned int mask;
52         union if_addr addr;
53 };
54
55 struct interface_route {
56         struct list_head list;
57         void *ctx;
58
59         enum interface_addr_flags flags;
60
61         unsigned int mask;
62         union if_addr addr;
63         union if_addr nexthop;
64 };
65
66 /*
67  * interface configuration
68  */
69 struct interface {
70         struct list_head list;
71
72         char name[IFNAMSIZ];
73
74         bool active;
75         bool autostart;
76
77         enum interface_state state;
78
79         /* main interface that the interface is bound to */
80         struct device_user main_dev;
81
82         /* interface that layer 3 communication will go through */
83         struct device_user *l3_iface;
84
85         /* primary protocol state */
86         struct interface_proto_state *proto;
87
88         struct list_head address, routes;
89
90         /* errors/warnings while trying to bring up the interface */
91         struct list_head errors;
92
93         struct ubus_object ubus;
94 };
95
96 struct interface *get_interface(const char *name);
97 struct interface *alloc_interface(const char *name, struct uci_section *s);
98 void free_interface(struct interface *iface);
99
100 void interface_set_proto_state(struct interface *iface, struct interface_proto_state *state);
101
102 int set_interface_up(struct interface *iface);
103 int set_interface_down(struct interface *iface);
104
105 int interface_add_link(struct interface *iface, struct device *llif);
106 void interface_remove_link(struct interface *iface, struct device *llif);
107
108 void interface_add_error(struct interface *iface, const char *subsystem,
109                          const char *code, const char **data, int n_data);
110
111 int interface_attach_bridge(struct interface *iface, struct uci_section *s);
112
113 int interface_add_address(struct interface *iface, struct interface_addr *addr);
114 void interface_del_address(struct interface *iface, struct interface_addr *addr);
115 void interface_del_ctx_addr(struct interface *iface, void *ctx);
116
117 void start_pending_interfaces(void);
118
119 #endif