contrib/fwd: renamed struct fwd_{addr,network}_list to struct fwd_{network,addr}

This commit is contained in:
Jo-Philipp Wich 2009-12-20 02:37:26 +00:00
parent ce40fff288
commit 1998087275
5 changed files with 36 additions and 46 deletions

View file

@ -25,13 +25,9 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
#include <signal.h>
#include <netinet/in.h> #include <netinet/in.h>
#if 0
#include "fwd_addr.h"
#include "fwd_rules.h"
#include "fwd_config.h"
#endif
enum fwd_policy { enum fwd_policy {
FWD_P_UNSPEC = 0, FWD_P_UNSPEC = 0,
@ -83,12 +79,12 @@ struct fwd_icmptype {
int code; int code;
}; };
struct fwd_network_list { struct fwd_network {
char *name; char *name;
char *ifname; char *ifname;
int isalias; int isalias;
struct fwd_cidr *addr; struct fwd_cidr *addr;
struct fwd_network_list *next; struct fwd_network *next;
}; };
struct fwd_defaults { struct fwd_defaults {
@ -103,7 +99,7 @@ struct fwd_defaults {
struct fwd_zone { struct fwd_zone {
char *name; char *name;
struct fwd_network_list *networks; struct fwd_network *networks;
struct fwd_data *forwardings; struct fwd_data *forwardings;
struct fwd_data *redirects; struct fwd_data *redirects;
struct fwd_data *rules; struct fwd_data *rules;
@ -168,23 +164,11 @@ struct fwd_data {
struct fwd_handle { struct fwd_handle {
int rtnl_socket; int rtnl_socket;
int unix_socket;
struct fwd_data *conf; 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, ...) /* fwd_fatal(fmt, ...)
* Prints message to stderr and termintes program. */ * Prints message to stderr and termintes program. */
#define fwd_fatal(...) do { \ #define fwd_fatal(...) do { \
@ -194,14 +178,5 @@ static void * fwd_zmalloc(size_t s)
exit(1); \ exit(1); \
} while(0) } 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 #endif

View file

@ -19,8 +19,9 @@
#include "fwd.h" #include "fwd.h"
#include "fwd_addr.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 {
struct nlmsghdr n; struct nlmsghdr n;
@ -37,7 +38,7 @@ struct fwd_addr_list * fwd_get_addrs(int fd, int family)
struct nlmsghdr *nlmp; struct nlmsghdr *nlmp;
struct ifaddrmsg *rtmp; struct ifaddrmsg *rtmp;
struct fwd_addr_list *head, *entry; struct fwd_addr *head, *entry;
/* Build request */ /* Build request */
memset(&req, 0, sizeof(req)); 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); rtmp = (struct ifaddrmsg *) NLMSG_DATA(nlmp);
rtatp = (struct rtattr *) IFA_RTA(rtmp); 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; goto error;
entry->index = rtmp->ifa_index; entry->index = rtmp->ifa_index;
@ -124,9 +125,20 @@ struct fwd_addr_list * fwd_get_addrs(int fd, int family)
return NULL; 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 ) while( entry != NULL )
{ {
@ -138,9 +150,9 @@ void fwd_free_addrs(struct fwd_addr_list *head)
head = entry = NULL; 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 ) while( entry->next != NULL )
entry = entry->next; entry = entry->next;

View file

@ -28,19 +28,21 @@
#include <arpa/inet.h> #include <arpa/inet.h>
struct fwd_addr_list { struct fwd_addr {
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
char label[IFNAMSIZ]; char label[IFNAMSIZ];
int family; int family;
int index; int index;
struct fwd_cidr ipaddr; 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 * fwd_get_addrs(int, int);
struct fwd_addr_list * fwd_append_addrs(struct fwd_addr_list *, struct fwd_addr_list *); struct fwd_addr * fwd_append_addrs(struct fwd_addr *, struct fwd_addr *);
void fwd_free_addrs(struct fwd_addr_list *); 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) #define fwd_foreach_addrs(head, entry) for(entry = head; entry; entry = entry->next)

View file

@ -19,6 +19,7 @@
#include "fwd.h" #include "fwd.h"
#include "fwd_xtables.h" #include "fwd_xtables.h"
#include "fwd_utils.h"
/* Required by certain extensions like SNAT and DNAT */ /* Required by certain extensions like SNAT and DNAT */
@ -129,7 +130,7 @@ void fwd_xt_parse_proto(
} }
void fwd_xt_parse_in( 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 ) if( n != NULL )
{ {
@ -141,7 +142,7 @@ void fwd_xt_parse_in(
} }
void fwd_xt_parse_out( 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 ) if( n != NULL )
{ {

View file

@ -50,8 +50,8 @@ void fwd_xt_init(void);
struct fwd_xt_rule * fwd_xt_init_rule(struct iptc_handle *h); 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_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_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_list *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_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_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); void fwd_xt_parse_frag(struct fwd_xt_rule *r, int frag, int inv);