IPv6: Remove local ULA if there is an external one
[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 automatically added by kernel */
35 DEVADDR_KERNEL = (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
44 union if_addr {
45 struct in_addr in;
46 struct in6_addr in6;
47 };
48
49 struct device_prefix_assignment {
50 struct list_head head;
51 int32_t assigned;
52 uint8_t length;
53 bool enabled;
54 char name[];
55 };
56
57 struct device_prefix {
58 struct vlist_node node;
59 struct list_head head;
60 struct list_head assignments;
61 struct interface *iface;
62 time_t valid_until;
63 time_t preferred_until;
64
65 struct in6_addr addr;
66 struct in6_addr excl_addr;
67
68 uint8_t length;
69 uint8_t excl_length;
70 };
71
72 struct device_addr {
73 struct vlist_node node;
74 bool enabled;
75
76 /* ipv4 only */
77 uint32_t broadcast;
78 uint32_t point_to_point;
79
80 /* ipv6 only */
81 time_t valid_until;
82 time_t preferred_until;
83
84 /* must be last */
85 enum device_addr_flags flags;
86 unsigned int mask;
87 union if_addr addr;
88 };
89
90 struct device_route {
91 struct vlist_node node;
92 struct interface *iface;
93
94 bool enabled;
95 bool keep;
96
97 union if_addr nexthop;
98 int mtu;
99 time_t valid_until;
100
101 /* must be last */
102 enum device_addr_flags flags;
103 int metric; // there can be multiple routes to the same target
104 unsigned int table;
105 unsigned int mask;
106 union if_addr addr;
107 };
108
109 struct dns_server {
110 struct vlist_simple_node node;
111 int af;
112 union if_addr addr;
113 };
114
115 struct dns_search_domain {
116 struct vlist_simple_node node;
117 char name[];
118 };
119
120 extern const struct config_param_list route_attr_list;
121 extern struct list_head prefixes;
122
123 void interface_ip_init(struct interface *iface);
124 void interface_add_dns_server(struct interface_ip_settings *ip, const char *str);
125 void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
126 void interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list);
127 void interface_write_resolv_conf(void);
128
129 void interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6);
130
131 void interface_ip_update_start(struct interface_ip_settings *ip);
132 void interface_ip_update_complete(struct interface_ip_settings *ip);
133 void interface_ip_flush(struct interface_ip_settings *ip);
134 void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
135 void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
136
137 struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6);
138
139 struct device_prefix* interface_ip_add_device_prefix(struct interface *iface,
140 struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until,
141 struct in6_addr *excl_addr, uint8_t excl_length);
142 void interface_ip_set_ula_prefix(const char *prefix);
143 void interface_refresh_assignments(bool hint);
144
145 #endif