summaryrefslogtreecommitdiff
path: root/libndp/ndp_private.h
blob: a75587f51a1af4cf1d436fd80fa1d816eeedb7b8 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *   ndp_private.h - Neighbour discovery library private header
 *   Copyright (C) 2013-2015 Jiri Pirko <jiri@resnulli.us>
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2.1 of the License, or (at your option) any later version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _NDP_PRIVATE_H_
#define _NDP_PRIVATE_H_

#include <stdarg.h>
#include <syslog.h>
#include <ndp.h>

#include "list.h"

#define NDP_EXPORT __attribute__ ((visibility("default")))
#define NDP_THREAD __thread

/**
 * SECTION: ndp
 * @short_description: libndp context
 */

struct ndp {
	int sock;
	void (*log_fn)(struct ndp *ndp, int priority,
		       const char *file, int line, const char *fn,
		       const char *format, va_list args);
	int log_priority;
	struct list_item msgrcv_handler_list;
};

/**
 * SECTION: logging
 * @short_description: libndp logging facility
 */

void ndp_log(struct ndp *ndp, int priority,
	     const char *file, int line, const char *fn,
	     const char *format, ...);

static inline void __attribute__((always_inline, format(printf, 2, 3)))
ndp_log_null(struct ndp *ndp, const char *format, ...) {}

#define ndp_log_cond(ndp, prio, arg...)					\
	do {								\
		if (ndp_get_log_priority(ndp) >= prio)			\
			ndp_log(ndp, prio, __FILE__, __LINE__,		\
				__FUNCTION__, ## arg);			\
	} while (0)

#ifdef ENABLE_LOGGING
#  ifdef ENABLE_DEBUG
#    define dbg(ndp, arg...) ndp_log_cond(ndp, LOG_DEBUG, ## arg)
#  else
#    define dbg(ndp, arg...) ndp_log_null(ndp, ## arg)
#  endif
#  define info(ndp, arg...) ndp_log_cond(ndp, LOG_INFO, ## arg)
#  define warn(ndp, arg...) ndp_log_cond(ndp, LOG_WARNING, ## arg)
#  define err(ndp, arg...) ndp_log_cond(ndp, LOG_ERR, ## arg)
#else
#  define dbg(ndp, arg...) ndp_log_null(ndp, ## arg)
#  define info(ndp, arg...) ndp_log_null(ndp, ## arg)
#  define warn(ndp, arg...) ndp_log_null(ndp, ## arg)
#  define err(ndp, arg...) ndp_log_null(ndp, ## arg)
#endif

/**
 * SECTION: netinet/icmp6.h addendum
 * @short_description: defines and structs missing from netinet/icmp6.h
 */

#define __ND_OPT_ROUTE_INFO 24 /* rfc4191 */
#define __ND_OPT_RDNSS 25 /* rfc6106 */
#define __ND_OPT_DNSSL 31 /* rfc6106 */

struct __nd_opt_route_info { /* route information */
	uint8_t		nd_opt_ri_type;
	uint8_t		nd_opt_ri_len;
	uint8_t		nd_opt_ri_prefix_len;
	uint8_t		nd_opt_ri_prf_reserved;
	uint32_t	nd_opt_ri_lifetime;
	char		nd_opt_ri_prefix[0];
};

struct __nd_opt_rdnss { /* Recursive DNS Server */
	uint8_t		nd_opt_rdnss_type;
	uint8_t		nd_opt_rdnss_len;
	uint16_t	nd_opt_rdnss_reserved;
	uint32_t	nd_opt_rdnss_lifetime;
	char		nd_opt_rdnss_addresses[0];
};

struct __nd_opt_dnssl { /* DNS Search List */
	uint8_t		nd_opt_dnssl_type;
	uint8_t		nd_opt_dnssl_len;
	uint16_t	nd_opt_dnssl_reserved;
	uint32_t	nd_opt_dnssl_lifetime;
	char		nd_opt_dnssl_domains[0];
};


#endif /* _NDP_PRIVATE_H_ */