618a53784dfbb5a3bb58f59ca0ab467916b9d871
[project/luci.git] / contrib / fwd / src / fwd_utils.h
1 /*
2  * fwd - OpenWrt firewall daemon - commmon utility header
3  *
4  *   Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
5  *
6  * The fwd program is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version 2
8  * as published by the Free Software Foundation.
9  *
10  * The fwd program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with the fwd program. If not, see http://www.gnu.org/licenses/.
17  */
18
19 #ifndef __FWD_UTILS_H__
20 #define __FWD_UTILS_H__
21
22 #include <syslog.h>
23
24 #include "fwd.h"
25
26 void fwd_log_init(void);
27 void __fwd_log(int, const char *, ...);
28 #define fwd_log_info(...) __fwd_log(LOG_INFO, __VA_ARGS__)
29 #define fwd_log_err(...) __fwd_log(LOG_ERR, __VA_ARGS__)
30
31 int fwd_empty_cidr(struct fwd_cidr *);
32 int fwd_equal_cidr(struct fwd_cidr *, struct fwd_cidr *);
33 void fwd_update_cidr(struct fwd_cidr *, struct fwd_cidr *);
34
35 /* fwd_zmalloc(size_t)
36  * Allocates a zeroed buffer of the given size. */
37 void * fwd_zmalloc(size_t);
38
39 /* fwd_alloc_ptr(type)
40  * Allocates a buffer with the size of the given datatype
41  * and returns a pointer to it. */
42 #define fwd_alloc_ptr(t) (t *) fwd_zmalloc(sizeof(t))
43
44 /* fwd_free_ptr(void *)
45  * Frees the given pointer and sets it to NULL.
46  * Safe for NULL values. */
47 #define fwd_free_ptr(x) do { if(x != NULL) free(x); x = NULL; } while(0)
48
49 #endif
50