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
|
/*
* Author: Steven Barth <steven at midlink.org>
*
* Copyright 2015 Deutsche Telekom AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef OMGPROXY_H_
#define OMGPROXY_H_
#ifdef __APPLE__
#define __APPLE_USE_RFC_3542
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
#include <sys/queue.h>
#ifdef LIST_HEAD
#undef LIST_HEAD
#endif /* LIST_HEAD */
#endif /* __APPLE__ */
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include <syslog.h>
#include <sys/types.h>
#include <libubox/utils.h>
#define STR_EXPAND(tok) #tok
#define STR(tok) STR_EXPAND(tok)
typedef int64_t omgp_time_t;
#define OMGP_TIME_MAX INT64_MAX
#define OMGP_TIME_PER_SECOND INT64_C(1000)
static inline omgp_time_t omgp_time(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ((omgp_time_t)ts.tv_sec * OMGP_TIME_PER_SECOND) +
((omgp_time_t)ts.tv_nsec / (1000000000 / OMGP_TIME_PER_SECOND));
}
// Logging macros
#ifndef L_LEVEL
#define L_LEVEL LOG_WARNING
#endif /* !L_LEVEL */
#define L_INTERNAL(level, ...) syslog(level, __VA_ARGS__);
#define L_ERR(...) L_INTERNAL(LOG_ERR, __VA_ARGS__)
#define L_WARN(...) L_INTERNAL(LOG_WARNING, __VA_ARGS__)
#define L_NOTICE(...) L_INTERNAL(LOG_NOTICE, __VA_ARGS__)
#define L_INFO(...) L_INTERNAL(LOG_INFO, __VA_ARGS__)
#define L_DEBUG(...) L_INTERNAL(LOG_DEBUG, __VA_ARGS__)
// Some C99 compatibility
#ifndef typeof
#define typeof __typeof
#endif
#ifndef container_of
#define container_of(ptr, type, member) ( \
(type *)( (char *)ptr - offsetof(type,member) ))
#endif
#ifndef __unused
#define __unused __attribute__((unused))
#endif
#endif /* PIMBD_H_ */
|