summaryrefslogtreecommitdiffhomepage
path: root/contrib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-12-20 02:37:26 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-12-20 02:37:26 +0000
commit19980872755027ab9fe3ca514d2053ab7b2a4c70 (patch)
tree5f8fa04af58fcb68da20d651ecf42c726bda5ed2 /contrib
parentce40fff288e28c5d758789d25cb76f1f617e105b (diff)
contrib/fwd: renamed struct fwd_{addr,network}_list to struct fwd_{network,addr}
Diffstat (limited to 'contrib')
-rw-r--r--contrib/fwd/src/fwd.h35
-rw-r--r--contrib/fwd/src/fwd_addr.c26
-rw-r--r--contrib/fwd/src/fwd_addr.h12
-rw-r--r--contrib/fwd/src/fwd_xtables.c5
-rw-r--r--contrib/fwd/src/fwd_xtables.h4
5 files changed, 36 insertions, 46 deletions
diff --git a/contrib/fwd/src/fwd.h b/contrib/fwd/src/fwd.h
index 0228daf7b6..6de8b880c9 100644
--- a/contrib/fwd/src/fwd.h
+++ b/contrib/fwd/src/fwd.h
@@ -25,13 +25,9 @@
#include <stdarg.h>
#include <stdlib.h>
#include <getopt.h>
+#include <signal.h>
#include <netinet/in.h>
-#if 0
-#include "fwd_addr.h"
-#include "fwd_rules.h"
-#include "fwd_config.h"
-#endif
enum fwd_policy {
FWD_P_UNSPEC = 0,
@@ -83,12 +79,12 @@ struct fwd_icmptype {
int code;
};
-struct fwd_network_list {
+struct fwd_network {
char *name;
char *ifname;
int isalias;
struct fwd_cidr *addr;
- struct fwd_network_list *next;
+ struct fwd_network *next;
};
struct fwd_defaults {
@@ -103,7 +99,7 @@ struct fwd_defaults {
struct fwd_zone {
char *name;
- struct fwd_network_list *networks;
+ struct fwd_network *networks;
struct fwd_data *forwardings;
struct fwd_data *redirects;
struct fwd_data *rules;
@@ -168,23 +164,11 @@ struct fwd_data {
struct fwd_handle {
int rtnl_socket;
+ int unix_socket;
struct fwd_data *conf;
- struct fwd_addr_list *addrs;
};
-/* fwd_zmalloc(size_t)
- * Allocates a zeroed buffer of the given size. */
-static void * fwd_zmalloc(size_t s)
-{
- void *b = malloc(s);
-
- if( b != NULL )
- memset(b, 0, s);
-
- return b;
-}
-
/* fwd_fatal(fmt, ...)
* Prints message to stderr and termintes program. */
#define fwd_fatal(...) do { \
@@ -194,14 +178,5 @@ static void * fwd_zmalloc(size_t s)
exit(1); \
} while(0)
-/* fwd_alloc_ptr(type)
- * Allocates a buffer with the size of the given datatype
- * and returns a pointer to it. */
-#define fwd_alloc_ptr(t) (t *) fwd_zmalloc(sizeof(t))
-
-/* fwd_free_ptr(void *)
- * Frees the given pointer and sets it to NULL.
- * Safe for NULL values. */
-#define fwd_free_ptr(x) do { if(x != NULL) free(x); x = NULL; } while(0)
#endif
diff --git a/contrib/fwd/src/fwd_addr.c b/contrib/fwd/src/fwd_addr.c
index fd277e9e0f..62e65aa62b 100644
--- a/contrib/fwd/src/fwd_addr.c
+++ b/contrib/fwd/src/fwd_addr.c
@@ -19,8 +19,9 @@
#include "fwd.h"
#include "fwd_addr.h"
+#include "fwd_utils.h"
-struct fwd_addr_list * fwd_get_addrs(int fd, int family)
+struct fwd_addr * fwd_get_addrs(int fd, int family)
{
struct {
struct nlmsghdr n;
@@ -37,7 +38,7 @@ struct fwd_addr_list * fwd_get_addrs(int fd, int family)
struct nlmsghdr *nlmp;
struct ifaddrmsg *rtmp;
- struct fwd_addr_list *head, *entry;
+ struct fwd_addr *head, *entry;
/* Build request */
memset(&req, 0, sizeof(req));
@@ -83,7 +84,7 @@ struct fwd_addr_list * fwd_get_addrs(int fd, int family)
rtmp = (struct ifaddrmsg *) NLMSG_DATA(nlmp);
rtatp = (struct rtattr *) IFA_RTA(rtmp);
- if( !(entry = fwd_alloc_ptr(struct fwd_addr_list)) )
+ if( !(entry = fwd_alloc_ptr(struct fwd_addr)) )
goto error;
entry->index = rtmp->ifa_index;
@@ -124,9 +125,20 @@ struct fwd_addr_list * fwd_get_addrs(int fd, int family)
return NULL;
}
-void fwd_free_addrs(struct fwd_addr_list *head)
+struct fwd_cidr * fwd_lookup_addr(struct fwd_addr *head, const char *ifname)
{
- struct fwd_addr_list *entry = head;
+ struct fwd_addr *entry;
+
+ for( entry = head; entry; entry = entry->next )
+ if( !strncmp(entry->ifname, ifname, IFNAMSIZ) )
+ return &entry->ipaddr;
+
+ return NULL;
+}
+
+void fwd_free_addrs(struct fwd_addr *head)
+{
+ struct fwd_addr *entry = head;
while( entry != NULL )
{
@@ -138,9 +150,9 @@ void fwd_free_addrs(struct fwd_addr_list *head)
head = entry = NULL;
}
-struct fwd_addr_list * fwd_append_addrs(struct fwd_addr_list *head, struct fwd_addr_list *add)
+struct fwd_addr * fwd_append_addrs(struct fwd_addr *head, struct fwd_addr *add)
{
- struct fwd_addr_list *entry = head;
+ struct fwd_addr *entry = head;
while( entry->next != NULL )
entry = entry->next;
diff --git a/contrib/fwd/src/fwd_addr.h b/contrib/fwd/src/fwd_addr.h
index 44465705af..3cabe09a01 100644
--- a/contrib/fwd/src/fwd_addr.h
+++ b/contrib/fwd/src/fwd_addr.h
@@ -28,19 +28,21 @@
#include <arpa/inet.h>
-struct fwd_addr_list {
+struct fwd_addr {
char ifname[IFNAMSIZ];
char label[IFNAMSIZ];
int family;
int index;
struct fwd_cidr ipaddr;
- struct fwd_addr_list *next;
+ struct fwd_addr *next;
};
-struct fwd_addr_list * fwd_get_addrs(int, int);
-struct fwd_addr_list * fwd_append_addrs(struct fwd_addr_list *, struct fwd_addr_list *);
-void fwd_free_addrs(struct fwd_addr_list *);
+struct fwd_addr * fwd_get_addrs(int, int);
+struct fwd_addr * fwd_append_addrs(struct fwd_addr *, struct fwd_addr *);
+void fwd_free_addrs(struct fwd_addr *);
+
+struct fwd_cidr * fwd_lookup_addr(struct fwd_addr *, const char *);
#define fwd_foreach_addrs(head, entry) for(entry = head; entry; entry = entry->next)
diff --git a/contrib/fwd/src/fwd_xtables.c b/contrib/fwd/src/fwd_xtables.c
index c0a3c582d8..895715d924 100644
--- a/contrib/fwd/src/fwd_xtables.c
+++ b/contrib/fwd/src/fwd_xtables.c
@@ -19,6 +19,7 @@
#include "fwd.h"
#include "fwd_xtables.h"
+#include "fwd_utils.h"
/* Required by certain extensions like SNAT and DNAT */
@@ -129,7 +130,7 @@ void fwd_xt_parse_proto(
}
void fwd_xt_parse_in(
- struct fwd_xt_rule *r, struct fwd_network_list *n, int inv
+ struct fwd_xt_rule *r, struct fwd_network *n, int inv
) {
if( n != NULL )
{
@@ -141,7 +142,7 @@ void fwd_xt_parse_in(
}
void fwd_xt_parse_out(
- struct fwd_xt_rule *r, struct fwd_network_list *n, int inv
+ struct fwd_xt_rule *r, struct fwd_network *n, int inv
) {
if( n != NULL )
{
diff --git a/contrib/fwd/src/fwd_xtables.h b/contrib/fwd/src/fwd_xtables.h
index 45b638a058..1ac57bb0e9 100644
--- a/contrib/fwd/src/fwd_xtables.h
+++ b/contrib/fwd/src/fwd_xtables.h
@@ -50,8 +50,8 @@ void fwd_xt_init(void);
struct fwd_xt_rule * fwd_xt_init_rule(struct iptc_handle *h);
void fwd_xt_parse_proto(struct fwd_xt_rule *r, struct fwd_proto *p, int inv);
-void fwd_xt_parse_in(struct fwd_xt_rule *r, struct fwd_network_list *n, int inv);
-void fwd_xt_parse_out(struct fwd_xt_rule *r, struct fwd_network_list *n, int inv);
+void fwd_xt_parse_in(struct fwd_xt_rule *r, struct fwd_network *n, int inv);
+void fwd_xt_parse_out(struct fwd_xt_rule *r, struct fwd_network *n, int inv);
void fwd_xt_parse_src(struct fwd_xt_rule *r, struct fwd_cidr *c, int inv);
void fwd_xt_parse_dest(struct fwd_xt_rule *r, struct fwd_cidr *c, int inv);
void fwd_xt_parse_frag(struct fwd_xt_rule *r, int frag, int inv);