2 * fwd - OpenWrt firewall daemon - commmon utility functions
4 * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
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.
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.
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/.
20 #include "fwd_utils.h"
23 void fwd_log_init(void)
25 openlog("Firewall", 0, LOG_DAEMON | LOG_PERROR);
28 void __fwd_log(int prio, const char *msg, ...)
32 vsyslog(prio, msg, ap);
38 int fwd_empty_cidr(struct fwd_cidr *c)
40 if( (c == NULL) || ((c->addr.s_addr == 0) && (c->prefix == 0)) )
46 int fwd_equal_cidr(struct fwd_cidr *a, struct fwd_cidr *b)
48 if( fwd_empty_cidr(a) && fwd_empty_cidr(b) )
50 else if( (a->addr.s_addr == b->addr.s_addr) && (a->prefix == b->prefix) )
56 void fwd_update_cidr(struct fwd_cidr *a, struct fwd_cidr *b)
60 a->addr.s_addr = b ? b->addr.s_addr : 0;
61 a->prefix = b ? b->prefix : 0;
66 /* fwd_zmalloc(size_t)
67 * Allocates a zeroed buffer of the given size. */
68 void * fwd_zmalloc(size_t s)