summaryrefslogtreecommitdiff
path: root/accel-pppd/include/ipv6_dns.h
blob: b604d006c356c4690e41c8c41573eff26dda6252 (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
#ifndef __IPV6_DNS_H
#define __IPV6_DNS_H

#include <netinet/in.h>

#include "list.h"
#include "ipdb.h"
#include "ap_session.h"

/*
 * Pick the IPv6 DNS servers to advertise to a session.
 *
 * A session may have been assigned its own servers (currently by the radius
 * module, from the DNS-Server-IPv6-Address attribute of RFC 6911); those take
 * precedence. Sessions without any fall back to the globally configured ones,
 * which is what every session got before per session servers existed.
 *
 * Up to 'max' addresses are written to 'dns', the number written is returned.
 * Callers advertise nothing when that is 0.
 */
static inline int ipv6_dns_get(const struct ap_session *ses,
			       const struct in6_addr *conf_dns, int conf_dns_count,
			       struct in6_addr *dns, int max)
{
	struct ipv6db_addr_t *a;
	int count = 0;

	if (ses && ses->ipv6_dns) {
		list_for_each_entry(a, &ses->ipv6_dns->addr_list, entry) {
			if (count == max)
				break;
			dns[count++] = a->addr;
		}

		/* An empty list means "nothing assigned", not "no DNS at all" */
		if (count)
			return count;
	}

	while (count < conf_dns_count && count < max) {
		dns[count] = conf_dns[count];
		count++;
	}

	return count;
}

#endif