a4bf05d0095ddc3b505fd450b58330b054bfbff0
[project/netifd.git] / system-dummy.c
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 #include <sys/time.h>
15 #include <stdio.h>
16 #include <string.h>
17
18 #include <arpa/inet.h>
19
20 #ifndef DEBUG
21 #define DEBUG
22 #endif
23
24 #include "netifd.h"
25 #include "device.h"
26 #include "system.h"
27
28 int system_init(void)
29 {
30 return 0;
31 }
32
33 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
34 {
35 D(SYSTEM, "brctl addbr %s vlan_filtering=%d\n",
36 bridge->ifname, cfg->vlan_filtering);
37 return 0;
38 }
39
40 int system_bridge_delbr(struct device *bridge)
41 {
42 D(SYSTEM, "brctl delbr %s\n", bridge->ifname);
43 return 0;
44 }
45
46 int system_bridge_addif(struct device *bridge, struct device *dev)
47 {
48 D(SYSTEM, "brctl addif %s %s\n", bridge->ifname, dev->ifname);
49 return 0;
50 }
51
52 int system_bridge_delif(struct device *bridge, struct device *dev)
53 {
54 D(SYSTEM, "brctl delif %s %s\n", bridge->ifname, dev->ifname);
55 return 0;
56 }
57
58 int system_link_netns_move(struct device *dev, int netns_fd, const char *target_ifname)
59 {
60 D(SYSTEM, "ip link set %s name %s netns %d\n", dev->ifname, target_ifname, netns_fd);
61 return 0;
62 }
63
64 int system_netns_open(const pid_t target_ns)
65 {
66 D(SYSTEM, "open netns of pid %d\n", target_ns);
67 return 1;
68 }
69
70 int system_netns_set(int netns_fd)
71 {
72 D(SYSTEM, "set netns %d\n", netns_fd);
73 return 0;
74 }
75
76 int system_vlan_add(struct device *dev, int id)
77 {
78 D(SYSTEM, "vconfig add %s %d\n", dev->ifname, id);
79 return 0;
80 }
81
82 int system_vlan_del(struct device *dev)
83 {
84 D(SYSTEM, "vconfig rem %s\n", dev->ifname);
85 return 0;
86 }
87
88 bool system_if_force_external(const char *ifname)
89 {
90 return false;
91 }
92
93 int system_if_up(struct device *dev)
94 {
95 D(SYSTEM, "ifconfig %s up\n", dev->ifname);
96 return 0;
97 }
98
99 int system_if_down(struct device *dev)
100 {
101 D(SYSTEM, "ifconfig %s down\n", dev->ifname);
102 return 0;
103 }
104
105 void system_if_get_settings(struct device *dev, struct device_settings *s)
106 {
107 }
108
109 void system_if_clear_state(struct device *dev)
110 {
111 device_set_ifindex(dev, system_if_resolve(dev));
112 }
113
114 int system_if_check(struct device *dev)
115 {
116 device_set_present(dev, true);
117 device_set_link(dev, true);
118
119 return 0;
120 }
121
122 int system_if_resolve(struct device *dev)
123 {
124 return 1;
125 }
126
127 struct device *
128 system_if_get_parent(struct device *dev)
129 {
130 return NULL;
131 }
132
133 int
134 system_if_dump_info(struct device *dev, struct blob_buf *b)
135 {
136 blobmsg_add_u8(b, "link", dev->present);
137 return 0;
138 }
139
140 int
141 system_if_dump_stats(struct device *dev, struct blob_buf *b)
142 {
143 return 0;
144 }
145
146 void
147 system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned int apply_mask)
148 {
149 }
150
151 static int system_address_msg(struct device *dev, struct device_addr *addr, const char *type)
152 {
153 char ipaddr[64];
154 int af = system_get_addr_family(addr->flags);
155
156 D(SYSTEM, "ifconfig %s %s %s/%u\n",
157 dev->ifname, type, inet_ntop(af, &addr->addr.in, ipaddr, sizeof(ipaddr)),
158 addr->mask);
159
160 return 0;
161 }
162
163 int system_add_address(struct device *dev, struct device_addr *addr)
164 {
165 return system_address_msg(dev, addr, "add");
166 }
167
168 int system_del_address(struct device *dev, struct device_addr *addr)
169 {
170 return system_address_msg(dev, addr, "del");
171 }
172
173 static int system_route_msg(struct device *dev, struct device_route *route, const char *type)
174 {
175 char addr[64], gw[64] = " gw ", devstr[64] = "";
176 int af = system_get_addr_family(route->flags);
177 int alen = system_get_addr_len(route->flags);
178 static uint32_t zero_addr[4];
179
180 if ((route->flags & DEVADDR_FAMILY) != DEVADDR_INET4)
181 return -1;
182
183 if (!route->mask)
184 sprintf(addr, "default");
185 else
186 inet_ntop(af, &route->addr.in, addr, sizeof(addr));
187
188 if (memcmp(&route->nexthop.in, (void *) zero_addr, alen) != 0)
189 inet_ntop(af, &route->nexthop.in, gw + 4, sizeof(gw) - 4);
190 else
191 gw[0] = 0;
192
193 if (dev)
194 sprintf(devstr, " dev %s", dev->ifname);
195
196 if (route->metric > 0)
197 sprintf(devstr, " metric %d", route->metric);
198
199 D(SYSTEM, "route %s %s%s%s\n", type, addr, gw, devstr);
200 return 0;
201 }
202
203 static int system_neighbor_msg(struct device *dev, struct device_neighbor *neighbor, const char *type)
204 {
205 char addr[64];
206 int af = system_get_addr_family(neighbor->flags);
207 inet_ntop(af, &neighbor->addr.in , addr, sizeof(addr));
208
209 D(SYSTEM, "neigh %s %s%s%s %s\n", type, addr, neighbor->proxy ? "proxy " : "",
210 (neighbor->flags & DEVNEIGH_MAC) ? format_macaddr(neighbor->macaddr) : "",
211 neighbor->router ? "router": "");
212 return 0;
213 }
214
215 int system_add_neighbor(struct device *dev, struct device_neighbor *neighbor)
216 {
217 return system_neighbor_msg(dev, neighbor, "add");
218 }
219
220 int system_del_neighbor(struct device *dev, struct device_neighbor *neighbor)
221 {
222 return system_neighbor_msg(dev, neighbor, "del");
223 }
224
225 int system_add_route(struct device *dev, struct device_route *route)
226 {
227 return system_route_msg(dev, route, "add");
228 }
229
230 int system_del_route(struct device *dev, struct device_route *route)
231 {
232 return system_route_msg(dev, route, "del");
233 }
234
235 int system_flush_routes(void)
236 {
237 return 0;
238 }
239
240 bool system_resolve_rt_type(const char *type, unsigned int *id)
241 {
242 *id = 0;
243 return true;
244 }
245
246 bool system_resolve_rt_proto(const char *type, unsigned int *id)
247 {
248 *id = 0;
249 return true;
250 }
251
252 bool system_resolve_rt_table(const char *name, unsigned int *id)
253 {
254 *id = 0;
255 return true;
256 }
257
258 bool system_is_default_rt_table(unsigned int id)
259 {
260 return true;
261 }
262
263 bool system_resolve_rpfilter(const char *filter, unsigned int *id)
264 {
265 *id = 0;
266 return true;
267 }
268
269 int system_add_iprule(struct iprule *rule)
270 {
271 return 0;
272 }
273
274 int system_del_iprule(struct iprule *rule)
275 {
276 return 0;
277 }
278
279 int system_flush_iprules(void)
280 {
281 return 0;
282 }
283
284 bool system_resolve_iprule_action(const char *action, unsigned int *id)
285 {
286 *id = 0;
287 return true;
288 }
289
290 time_t system_get_rtime(void)
291 {
292 struct timeval tv;
293
294 if (gettimeofday(&tv, NULL) == 0)
295 return tv.tv_sec;
296
297 return 0;
298 }
299
300 int system_del_ip_tunnel(const char *name, struct blob_attr *attr)
301 {
302 return 0;
303 }
304
305 int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
306 {
307 return 0;
308 }
309
310 int system_update_ipv6_mtu(struct device *dev, int mtu)
311 {
312 return 0;
313 }
314
315 int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg)
316 {
317 return 0;
318 }
319
320 int system_macvlan_del(struct device *macvlan)
321 {
322 return 0;
323 }
324
325 int system_veth_add(struct device *veth, struct veth_config *cfg)
326 {
327 return 0;
328 }
329
330 int system_veth_del(struct device *veth)
331 {
332 return 0;
333 }
334
335 int system_vlandev_add(struct device *vlandev, struct device *dev, struct vlandev_config *cfg)
336 {
337 return 0;
338 }
339
340 int system_vlandev_del(struct device *vlandev)
341 {
342 return 0;
343 }