20df281af886875405c3ee335653177e32c8652e
[oweals/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 interface_addr *addr)
13 {
14         int family;
15
16         if (addr->flags & IFADDR_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, family, &addr->addr.in, addr->mask);
23 }
24
25 void interface_del_address(struct interface *iface, struct interface_addr *addr)
26 {
27         int family;
28
29         if (addr->flags & IFADDR_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, family, &addr->addr.in);
36 }
37
38 void interface_del_ctx_addr(struct interface *iface, void *ctx)
39 {
40         struct interface_addr *addr, *tmp;
41
42         list_for_each_entry_safe(addr, tmp, &iface->address, list) {
43                 if (addr->ctx != ctx)
44                         continue;
45
46                 interface_del_address(iface, addr);
47         }
48 }