Whitespace cleanup.

This commit is contained in:
Gleb Smirnoff 2013-12-25 01:52:55 +00:00
parent 729c09bf00
commit 22d3fb1917
2 changed files with 71 additions and 79 deletions

View File

@ -56,15 +56,15 @@ LIST_HEAD(handler_chain, proto_handler) handler_chain = LIST_HEAD_INITIALIZER(ha
#ifdef _KERNEL
struct rwlock handler_rw;
#endif
SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(dll_chain);
SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(dll_chain);
#ifdef _KERNEL
#define LIBALIAS_RWLOCK_INIT() \
rw_init(&handler_rw, "Libalias_modules_rwlock")
rw_init(&handler_rw, "Libalias_modules_rwlock")
#define LIBALIAS_RWLOCK_DESTROY() rw_destroy(&handler_rw)
#define LIBALIAS_WLOCK_ASSERT() \
rw_assert(&handler_rw, RA_WLOCKED)
rw_assert(&handler_rw, RA_WLOCKED)
static __inline void
LIBALIAS_RLOCK(void)
@ -116,7 +116,7 @@ _handler_chain_destroy(void)
#define LIBALIAS_WUNLOCK() ;
#define _handler_chain_init() ;
#define _handler_chain_destroy() ;
#endif
#endif
void
handler_chain_init(void)
@ -138,7 +138,7 @@ _attach_handler(struct proto_handler *p)
LIBALIAS_WLOCK_ASSERT();
b = NULL;
LIST_FOREACH(b, &handler_chain, entries) {
if ((b->pri == p->pri) &&
if ((b->pri == p->pri) &&
(b->dir == p->dir) &&
(b->proto == p->proto))
return (EEXIST); /* Priority conflict. */
@ -160,7 +160,7 @@ _detach_handler(struct proto_handler *p)
{
struct proto_handler *b, *b_tmp;
LIBALIAS_WLOCK_ASSERT();
LIBALIAS_WLOCK_ASSERT();
LIST_FOREACH_SAFE(b, &handler_chain, entries, b_tmp) {
if (b == p) {
LIST_REMOVE(b, entries);
@ -178,10 +178,10 @@ LibAliasAttachHandlers(struct proto_handler *_p)
LIBALIAS_WLOCK();
error = -1;
for (i = 0; 1; i++) {
if (*((int *)&_p[i]) == EOH)
if (*((int *)&_p[i]) == EOH)
break;
error = _attach_handler(&_p[i]);
if (error != 0)
if (error != 0)
break;
}
LIBALIAS_WUNLOCK();
@ -196,10 +196,10 @@ LibAliasDetachHandlers(struct proto_handler *_p)
LIBALIAS_WLOCK();
error = -1;
for (i = 0; 1; i++) {
if (*((int *)&_p[i]) == EOH)
if (*((int *)&_p[i]) == EOH)
break;
error = _detach_handler(&_p[i]);
if (error != 0)
if (error != 0)
break;
}
LIBALIAS_WUNLOCK();
@ -219,7 +219,7 @@ detach_handler(struct proto_handler *_p)
}
int
find_handler(int8_t dir, int8_t proto, struct libalias *la, __unused struct ip *pip,
find_handler(int8_t dir, int8_t proto, struct libalias *la, __unused struct ip *pip,
struct alias_data *ad)
{
struct proto_handler *p;
@ -235,14 +235,14 @@ find_handler(int8_t dir, int8_t proto, struct libalias *la, __unused struct ip *
}
}
LIBALIAS_RUNLOCK();
return (error);
return (error);
}
struct proto_handler *
first_handler(void)
{
return (LIST_FIRST(&handler_chain));
return (LIST_FIRST(&handler_chain));
}
/* Dll manipulation code - this code is not thread safe... */
@ -270,7 +270,7 @@ detach_dll(char *p)
error = NULL;
SLIST_FOREACH_SAFE(b, &dll_chain, next, b_tmp)
if (!strncmp(b->name, p, DLL_LEN)) {
SLIST_REMOVE(&dll_chain, b, dll, next);
SLIST_REMOVE(&dll_chain, b, dll, next);
error = b;
break;
}

View File

@ -45,102 +45,94 @@ MALLOC_DECLARE(M_ALIAS);
#endif
#endif
/* Protocol handlers struct & function. */
/* Packet flow direction. */
#define IN 1
#define OUT 2
#define IN 1
#define OUT 2
/* Working protocol. */
#define IP 1
#define TCP 2
#define UDP 4
#define IP 1
#define TCP 2
#define UDP 4
/*
/*
* Data passed to protocol handler module, it must be filled
* right before calling find_handler() to determine which
* module is elegible to be called.
*/
struct alias_data {
struct alias_link *lnk;
struct in_addr *oaddr; /* Original address. */
struct in_addr *aaddr; /* Alias address. */
uint16_t *aport; /* Alias port. */
uint16_t *sport, *dport; /* Source & destination port */
uint16_t maxpktsize; /* Max packet size. */
};
struct alias_data {
struct alias_link *lnk;
struct in_addr *oaddr; /* Original address. */
struct in_addr *aaddr; /* Alias address. */
uint16_t *aport; /* Alias port. */
uint16_t *sport, *dport; /* Source & destination port */
uint16_t maxpktsize; /* Max packet size. */
};
/*
/*
* This structure contains all the information necessary to make
* a protocol handler correctly work.
*/
struct proto_handler {
u_int pri; /* Handler priority. */
int16_t dir; /* Flow direction. */
uint8_t proto; /* Working protocol. */
int (*fingerprint)(struct libalias *, /* Fingerprint * function. */
struct alias_data *);
int (*protohandler)(struct libalias *, /* Aliasing * function. */
struct ip *, struct alias_data *);
u_int pri; /* Handler priority. */
int16_t dir; /* Flow direction. */
uint8_t proto; /* Working protocol. */
/* Fingerprint * function. */
int (*fingerprint)(struct libalias *, struct alias_data *);
/* Aliasing * function. */
int (*protohandler)(struct libalias *, struct ip *,
struct alias_data *);
LIST_ENTRY(proto_handler) entries;
};
/*
/*
* Used only in userland when libalias needs to keep track of all
* module loaded. In kernel land (kld mode) we don't need to care
* care about libalias modules cause it's kld to do it for us.
*/
#define DLL_LEN 32
struct dll {
char name[DLL_LEN]; /* Name of module. */
void *handle; /*
* Ptr to shared obj obtained through
* dlopen() - use this ptr to get access
* to any symbols from a loaded module
* via dlsym().
*/
SLIST_ENTRY(dll) next;
#define DLL_LEN 32
struct dll {
char name[DLL_LEN]; /* Name of module. */
void *handle; /*
* Ptr to shared obj obtained through
* dlopen() - use this ptr to get access
* to any symbols from a loaded module
* via dlsym().
*/
SLIST_ENTRY(dll) next;
};
/* Functions used with protocol handlers. */
void handler_chain_init(void);
void handler_chain_destroy(void);
int LibAliasAttachHandlers(struct proto_handler *);
int LibAliasDetachHandlers(struct proto_handler *);
int detach_handler(struct proto_handler *);
int find_handler(int8_t, int8_t, struct libalias *,
struct ip *, struct alias_data *);
void handler_chain_init(void);
void handler_chain_destroy(void);
int LibAliasAttachHandlers(struct proto_handler *);
int LibAliasDetachHandlers(struct proto_handler *);
int detach_handler(struct proto_handler *);
int find_handler(int8_t, int8_t, struct libalias *, struct ip *,
struct alias_data *);
struct proto_handler *first_handler(void);
/* Functions used with dll module. */
void dll_chain_init(void);
void dll_chain_destroy(void);
int attach_dll(struct dll *);
void *detach_dll(char *);
struct dll *walk_dll_chain(void);
void dll_chain_init(void);
void dll_chain_destroy(void);
int attach_dll(struct dll *);
void *detach_dll(char *);
struct dll *walk_dll_chain(void);
/* End of handlers. */
#define EOH -1
/*
/*
* Some defines borrowed from sys/module.h used to compile a kld
* in userland as a shared lib.
*/
#ifndef _KERNEL
typedef enum modeventtype {
MOD_LOAD,
MOD_UNLOAD,
MOD_SHUTDOWN,
MOD_QUIESCE
MOD_LOAD,
MOD_UNLOAD,
MOD_SHUTDOWN,
MOD_QUIESCE
} modeventtype_t;
typedef struct module *module_t;
typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
@ -148,10 +140,10 @@ typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *);
* Struct for registering modules statically via SYSINIT.
*/
typedef struct moduledata {
const char *name; /* module name */
modeventhand_t evhand; /* event handler */
void *priv; /* extra data */
const char *name; /* module name */
modeventhand_t evhand; /* event handler */
void *priv; /* extra data */
} moduledata_t;
#endif
#endif /* !_ALIAS_MOD_H_ */
#endif /* !_ALIAS_MOD_H_ */