2 * netifd - network interface daemon
3 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
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
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.
14 #ifndef __INTERFACE_IP_H
15 #define __INTERFACE_IP_H
17 #include "interface.h"
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
,
25 /* externally added address */
26 DEVADDR_EXTERNAL
= (1 << 2),
28 /* route overrides the default interface metric */
29 DEVROUTE_METRIC
= (1 << 3),
31 /* route overrides the default interface mtu */
32 DEVROUTE_MTU
= (1 << 4),
34 /* route automatically added by kernel */
35 DEVADDR_KERNEL
= (1 << 5),
37 /* address is off-link (no subnet-route) */
38 DEVADDR_OFFLINK
= (1 << 6),
40 /* route resides in different table */
41 DEVROUTE_TABLE
= (1 << 7),
43 /* route resides in default source-route table */
44 DEVROUTE_SRCTABLE
= (1 << 8),
46 /* route is on-link */
47 DEVROUTE_ONLINK
= (1 << 9),
49 /* route overrides the default route type */
50 DEVROUTE_TYPE
= (1 << 10),
58 struct device_prefix_assignment
{
59 struct list_head head
;
66 struct device_prefix
{
67 struct vlist_node node
;
68 struct list_head head
;
69 struct list_head assignments
;
70 struct interface
*iface
;
72 time_t preferred_until
;
74 struct in6_addr excl_addr
;
84 struct vlist_node node
;
90 uint32_t point_to_point
;
94 time_t preferred_until
;
98 enum device_addr_flags flags
;
103 struct device_route
{
104 struct vlist_node node
;
105 struct interface
*iface
;
111 union if_addr nexthop
;
117 enum device_addr_flags flags
;
118 int metric
; // there can be multiple routes to the same target
121 unsigned int sourcemask
;
123 union if_addr source
;
126 struct device_source_table
{
127 struct list_head head
;
136 struct vlist_simple_node node
;
141 struct dns_search_domain
{
142 struct vlist_simple_node node
;
146 extern const struct uci_blob_param_list route_attr_list
;
147 extern struct list_head prefixes
;
149 void interface_ip_init(struct interface
*iface
);
150 void interface_add_dns_server(struct interface_ip_settings
*ip
, const char *str
);
151 void interface_add_dns_server_list(struct interface_ip_settings
*ip
, struct blob_attr
*list
);
152 void interface_add_dns_search_list(struct interface_ip_settings
*ip
, struct blob_attr
*list
);
153 void interface_write_resolv_conf(void);
155 void interface_ip_add_route(struct interface
*iface
, struct blob_attr
*attr
, bool v6
);
157 void interface_ip_update_start(struct interface_ip_settings
*ip
);
158 void interface_ip_update_complete(struct interface_ip_settings
*ip
);
159 void interface_ip_flush(struct interface_ip_settings
*ip
);
160 void interface_ip_set_enabled(struct interface_ip_settings
*ip
, bool enabled
);
161 void interface_ip_update_metric(struct interface_ip_settings
*ip
, int metric
);
163 struct interface
*interface_ip_add_target_route(union if_addr
*addr
, bool v6
, struct interface
*iface
);
165 struct device_prefix
* interface_ip_add_device_prefix(struct interface
*iface
,
166 struct in6_addr
*addr
, uint8_t length
, time_t valid_until
, time_t preferred_until
,
167 struct in6_addr
*excl_addr
, uint8_t excl_length
, const char *pclass
);
168 void interface_ip_set_ula_prefix(const char *prefix
);
169 void interface_refresh_assignments(bool hint
);