/*
* firewall3 - 3rd OpenWrt UCI firewall implementation
*
- * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ * Copyright (C) 2013 Jo-Philipp Wich <jo@mein.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/file.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <netdb.h>
#include <libubox/list.h>
+#include <libubox/blob.h>
#include <uci.h>
#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;
-void warn_elem(struct uci_element *e, const char *format, ...);
-void warn(const char *format, ...);
-void error(const char *format, ...);
-void info(const char *format, ...);
+struct fw3_address;
-#define setbit(field, flag) field |= (1 << (flag))
-#define delbit(field, flag) field &= ~(1 << (flag))
-#define hasbit(field, flag) (field & (1 << (flag)))
+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 set(field, family, flag) setbit(field[family == FW3_FAMILY_V6], flag)
-#define del(field, family, flag) delbit(field[family == FW3_FAMILY_V6], flag)
-#define has(field, family, flag) hasbit(field[family == FW3_FAMILY_V6], flag)
+
+#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); \
#define fw3_command_pipe(...) __fw3_command_pipe(__VA_ARGS__, NULL)
void fw3_command_close(void);
-void fw3_pr(const char *fmt, ...);
+void fw3_pr(const char *fmt, ...)
+ __attribute__ ((format (printf, 1, 2)));
bool fw3_has_table(bool ipv6, const char *table);
bool fw3_lock(void);
void fw3_unlock(void);
+bool fw3_lock_path(int *fw3_lock_fd, const char *path);
+void fw3_unlock_path(int *fw3_lock_fd, const char *path);
void fw3_write_statefile(void *state);
bool fw3_hotplug(bool add, void *zone, void *device);
+int fw3_netmask2bitlen(int family, void *mask);
+
+bool fw3_bitlen2netmask(int family, int bits, void *mask);
+
+void fw3_flush_conntrack(void *zone);
+
+bool fw3_attr_parse_name_type(struct blob_attr *entry, const char **name, const char **type);
+
+const char * fw3_protoname(void *proto);
+
+bool fw3_check_loopback_dev(const char *name);
+
+bool fw3_check_loopback_addr(struct fw3_address *addr);
#endif