/* * firewall3 - 3rd OpenWrt UCI firewall implementation * * Copyright (C) 2013 Jo-Philipp Wich * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __FW3_UTILS_H #define __FW3_UTILS_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FW3_STATEFILE "/var/run/fw3.state" #define FW3_LOCKFILE "/var/run/fw3.lock" #define FW3_HELPERCONF "/usr/share/fw3/helpers.conf" #define FW3_HOTPLUG "/sbin/hotplug-call" extern bool fw3_pr_debug; struct fw3_address; void warn_elem(struct uci_element *e, const char *format, ...) __attribute__ ((format (printf, 2, 3))); void warn(const char *format, ...) __attribute__ ((format (printf, 1, 2))); void error(const char *format, ...) __attribute__ ((format (printf, 1, 2))); void info(const char *format, ...) __attribute__ ((format (printf, 1, 2))); #define warn_section(t, r, e, fmt, ...) \ do { \ if (e) \ warn_elem(e, fmt, ##__VA_ARGS__); \ else \ warn("Warning: ubus " t " (%s) " fmt, \ (r && r->name) ? r->name : "?", ##__VA_ARGS__); \ } while(0) #define fw3_setbit(field, flag) field |= (1 << (flag)) #define fw3_delbit(field, flag) field &= ~(1 << (flag)) #define fw3_hasbit(field, flag) (field & (1 << (flag))) #define set(field, family, flag) fw3_setbit(field[family == FW3_FAMILY_V6], flag) #define del(field, family, flag) fw3_delbit(field[family == FW3_FAMILY_V6], flag) #define has(field, family, flag) fw3_hasbit(field[family == FW3_FAMILY_V6], flag) #define fw3_foreach(p, h) \ for (p = list_empty(h) ? NULL : list_first_entry(h, typeof(*p), list); \ list_empty(h) ? (p == NULL) : (&p->list != (h)); \ p = list_empty(h) ? list_first_entry(h, typeof(*p), list) \ : list_entry(p->list.next, typeof(*p), list)) #define fw3_is_family(p, f) \ (!p || (p)->family == FW3_FAMILY_ANY || (p)->family == f) #define fw3_no_family(flags) \ (!(flags & ((1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6)))) #define fw3_no_table(flags) \ (!(flags & ((1<