6decaea7b16861c0adc00cf4316f8f70f8242881
[project/netifd.git] / interface-ip.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "netifd.h"
6 #include "device.h"
7 #include "interface.h"
8 #include "interface-ip.h"
9 #include "proto.h"
10 #include "ubus.h"
11 #include "system.h"
12
13 int interface_add_address(struct interface *iface, struct device_addr *addr)
14 {
15 int family;
16
17 if (addr->flags & DEVADDR_INET6)
18 family = AF_INET6;
19 else
20 family = AF_INET;
21
22 list_add_tail(&addr->list, &iface->address);
23 return system_add_address(iface->l3_iface->dev, addr);
24 }
25
26 void interface_del_address(struct interface *iface, struct device_addr *addr)
27 {
28 int family;
29
30 if (addr->flags & DEVADDR_INET6)
31 family = AF_INET6;
32 else
33 family = AF_INET;
34
35 list_del(&addr->list);
36 system_del_address(iface->l3_iface->dev, addr);
37 }
38
39 void interface_del_ctx_addr(struct interface *iface, void *ctx)
40 {
41 struct device_addr *addr, *tmp;
42
43 list_for_each_entry_safe(addr, tmp, &iface->address, list) {
44 if (ctx && addr->ctx != ctx)
45 continue;
46
47 interface_del_address(iface, addr);
48 }
49 }
50
51 int interface_add_route(struct interface *iface, struct device_route *route)
52 {
53 list_add_tail(&route->list, &iface->routes);
54 return system_add_route(iface->l3_iface->dev, route);
55 }
56
57 void interface_del_route(struct interface *iface, struct device_route *route)
58 {
59 list_del(&route->list);
60 system_del_route(iface->l3_iface->dev, route);
61 }
62
63 void interface_del_all_routes(struct interface *iface)
64 {
65 struct device_route *route, *tmp;
66
67 list_for_each_entry_safe(route, tmp, &iface->routes, list)
68 interface_del_route(iface, route);
69 }