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