summaryrefslogtreecommitdiffhomepage
path: root/interface-ip.c
blob: b86acb5856033d240724a80e022f83b1d8e132c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "netifd.h"
#include "device.h"
#include "interface.h"
#include "interface-ip.h"
#include "proto.h"
#include "ubus.h"
#include "system.h"

int interface_add_address(struct interface *iface, struct device_addr *addr)
{
	int family;

	if (addr->flags & DEVADDR_INET6)
		family = AF_INET6;
	else
		family = AF_INET;

	list_add_tail(&addr->list, &iface->address);
	return system_add_address(iface->l3_iface->dev, addr);
}

void interface_del_address(struct interface *iface, struct device_addr *addr)
{
	int family;

	if (addr->flags & DEVADDR_INET6)
		family = AF_INET6;
	else
		family = AF_INET;

	list_del(&addr->list);
	system_del_address(iface->l3_iface->dev, addr);
	free(addr);
}

void interface_del_ctx_addr(struct interface *iface, void *ctx)
{
	struct device_addr *addr, *tmp;

	list_for_each_entry_safe(addr, tmp, &iface->address, list) {
		if (ctx && addr->ctx != ctx)
			continue;

		interface_del_address(iface, addr);
	}
}

int interface_add_route(struct interface *iface, struct device_route *route)
{
	list_add_tail(&route->list, &iface->routes);
	return system_add_route(iface->l3_iface->dev, route);
}

void interface_del_route(struct interface *iface, struct device_route *route)
{
	list_del(&route->list);
	system_del_route(iface->l3_iface->dev, route);
	if (!route->keep)
		free(route);
}

void interface_del_all_routes(struct interface *iface)
{
	struct device_route *route, *tmp;

	list_for_each_entry_safe(route, tmp, &iface->routes, list)
		interface_del_route(iface, route);
}