Initial IPv6 prefix support
[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
38 union if_addr {
39 struct in_addr in;
40 struct in6_addr in6;
41 };
42
43 struct device_prefix {
44 struct vlist_node node;
45 struct list_head head;
46 struct vlist_tree *assignments;
47 struct interface *iface;
48 uint64_t avail;
49 time_t valid_until;
50 time_t preferred_until;
51
52 struct in6_addr addr;
53 uint8_t length;
54 };
55
56 struct device_prefix_assignment {
57 struct vlist_node node;
58 struct device_prefix *prefix;
59 struct in6_addr addr;
60 bool enabled;
61 uint8_t length;
62 char *name;
63 };
64
65 struct device_addr {
66 struct vlist_node node;
67 bool enabled;
68
69 /* ipv4 only */
70 uint32_t broadcast;
71 uint32_t point_to_point;
72
73 /* ipv6 only */
74 time_t valid_until;
75 time_t preferred_until;
76
77 /* must be last */
78 enum device_addr_flags flags;
79 unsigned int mask;
80 union if_addr addr;
81 };
82
83 struct device_route {
84 struct vlist_node node;
85 struct interface *iface;
86
87 bool enabled;
88 bool keep;
89
90 union if_addr nexthop;
91 int metric;
92 int mtu;
93
94 /* must be last */
95 enum device_addr_flags flags;
96 unsigned int mask;
97 union if_addr addr;
98 };
99
100 struct dns_server {
101 struct vlist_simple_node node;
102 int af;
103 union if_addr addr;
104 };
105
106 struct dns_search_domain {
107 struct vlist_simple_node node;
108 char name[];
109 };
110
111 extern const struct config_param_list route_attr_list;
112 extern struct list_head prefixes;
113
114 void interface_ip_init(struct interface *iface);
115 void interface_add_dns_server(struct interface_ip_settings *ip, const char *str);
116 void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
117 void interface_add_dns_search_list(struct interface_ip_settings *ip, struct blob_attr *list);
118 void interface_write_resolv_conf(void);
119
120 void interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6);
121
122 void interface_ip_update_start(struct interface_ip_settings *ip);
123 void interface_ip_update_complete(struct interface_ip_settings *ip);
124 void interface_ip_flush(struct interface_ip_settings *ip);
125 void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled);
126 void interface_ip_update_metric(struct interface_ip_settings *ip, int metric);
127
128 struct interface *interface_ip_add_target_route(union if_addr *addr, bool v6);
129
130 void interface_ip_set_prefix_assignment(struct device_prefix *prefix,
131 struct interface *iface, uint8_t length);
132 void interface_ip_add_device_prefix(struct interface *iface, struct in6_addr *addr,
133 uint8_t length, time_t valid_until, time_t preferred_until);
134 void interface_ip_set_ula_prefix(const char *prefix);
135
136 #endif