system-linux: parse 6rd specific settings as nested json data object
[project/netifd.git] / interface-ip.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 __INTERFACE_IP_H
15 #define __INTERFACE_IP_H
16
17 #include "interface.h"
18
19 enum device_addr_flags {
20 /* address family for routes and addresses */
21 DEVADDR_INET4 = (0 << 0),
22 DEVADDR_INET6 = (1 << 0),
23 DEVADDR_FAMILY = DEVADDR_INET4 | DEVADDR_INET6,
24
25 /* externally added address */
26 DEVADDR_EXTERNAL = (1 << 2),
27
28 /* route overrides the default interface metric */
29 DEVROUTE_METRIC = (1 << 3),
30
31 /* route overrides the default interface mtu */
32 DEVROUTE_MTU = (1 << 4),
33
34 /* route overrides the default proto type */
35 DEVROUTE_PROTO = (1 << 5),
36
37 /* address is off-link (no subnet-route) */
38 DEVADDR_OFFLINK = (1 << 6),
39
40 /* route resides in different table */
41 DEVROUTE_TABLE = (1 << 7),
42
43 /* route resides in default source-route table */
44 DEVROUTE_SRCTABLE = (1 << 8),
45
46 /* route is on-link */
47 DEVROUTE_ONLINK = (1 << 9),
48
49 /* route overrides the default route type */
50 DEVROUTE_TYPE = (1 << 10),
51 };
52
53 union if_addr {
54 struct in_addr in;
55 struct in6_addr in6;
56 };
57
58 struct device_prefix_assignment {
59 struct list_head head;
60 int32_t assigned;
61 uint8_t length;
62 int weight;
63 struct in6_addr addr;
64 bool enabled;
65 char name[];
66 };
67
68 struct device_prefix {
69 struct vlist_node node;
70 struct list_head head;
71 struct list_head assignments;
72 struct interface *iface;
73 time_t valid_until;
74 time_t preferred_until;
75
76 struct in6_addr excl_addr;
77 uint8_t excl_length;
78
79 struct in6_addr addr;
80 uint8_t length;
81
82 char pclass[];
83 };
84
85 struct device_route {
86 struct vlist_node node;
87 struct interface *iface;
88
89 bool enabled;
90 bool keep;
91 bool failed;
92
93 union if_addr nexthop;
94 int mtu;
95 unsigned int type;
96 unsigned int proto;
97 time_t valid_until;
98
99 /* must be last */
100 enum device_addr_flags flags;
101 int metric; // there can be multiple routes to the same target
102 unsigned int table;
103 unsigned int mask;
104 unsigned int sourcemask;
105 union if_addr addr;
106 union if_addr source;
107 };
108
109 struct device_addr {
110 struct vlist_node node;
111 bool enabled;
112 bool failed;
113 unsigned int policy_table;
114
115 struct device_route subnet;
116
117 /* ipv4 only */
118 uint32_t broadcast;
119 uint32_t point_to_point;
120
121 /* ipv6 only */
122 time_t valid_until;
123 time_t preferred_until;
124 char *pclass;
125
126 /* must be last */
127 enum device_addr_flags flags;
128 unsigned int mask;
129 union if_addr addr;
130 };
131
132 struct device_source_table {
133 struct list_head head;
134 uint32_t table;
135 uint16_t refcount;
136 uint8_t v6;
137 uint8_t mask;
138 union if_addr addr;
139 };
140
141 struct dns_server {
142 struct vlist_simple_node node;
143 int af;
144 union if_addr addr;
145 };
146
147 struct dns_search_domain {
148 struct vlist_simple_node node;
149 char name[];
150 };
151
152 extern const struct uci_blob_param_list route_attr_list;
153 extern struct list_head prefixes;
154
155 void interface_ip_init(struct interface *iface);
156 void interface_add_dns_server(struct interface_ip_settings *ip, const char *str);
157 void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
158 void interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list);
159 void interface_write_resolv_conf(void);
160
161 void interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6);
162
163 void interface_ip_update_start(struct interface_ip_settings *ip);
164 void interface_ip_update_complete(struct interface_ip_settings *ip);
165 void interface_ip_flush(struct interface_ip_settings *ip);
166 void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
167 void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
168
169 struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *iface);
170
171 struct device_prefix* interface_ip_add_device_prefix(struct interface *iface,
172 struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until,
173 struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass);
174 void interface_ip_set_ula_prefix(const char *prefix);
175 void interface_refresh_assignments(bool hint);
176
177 #endif