Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sods: replace void* args with types

  • Loading branch information...
commit af696f0714d246bb667018ad76b9210e8629c734 1 parent dc12983
@msantos authored
View
55 sods/sods.h
@@ -99,12 +99,15 @@
#define MAXFWDS 32 /* Maximum number of allowed forwarders */
#define MAXDNAMELIST 256 /* Maximum number of domain names */
+struct SDS_PKT;
+struct SDS_STATE;
+
typedef struct _SDS_FWD {
u_int8_t sess; /* Unused */
struct sockaddr_in sa;
} SDS_FWD;
-typedef struct _SDS_STATE {
+typedef struct SDS_STATE {
int s;
char **dn;
int dn_max;
@@ -123,10 +126,10 @@ typedef struct _SDS_STATE {
int daemon;
int verbose;
- void (*run)(void *state);
- void (*cleanup)(void *state);
- int (*handler)(void *state, void *packet);
- int (*decapsulate)(void *state, void *packet);
+ void (*run)(struct SDS_STATE *);
+ void (*cleanup)(struct SDS_STATE *);
+ int (*handler)(struct SDS_STATE *, struct SDS_PKT *);
+ int (*decapsulate)(struct SDS_STATE *, struct SDS_PKT *);
} SDS_STATE;
struct dns_header {
@@ -161,7 +164,7 @@ typedef union _SDS_ID {
u_int32_t id;
} SDS_ID;
-typedef struct _SDS_PKT {
+typedef struct SDS_PKT {
struct {
struct dns_header hdr;
u_char query[NS_PACKETSZ - sizeof(struct dns_header)];
@@ -177,11 +180,11 @@ typedef struct _SDS_PKT {
SDS_ID sess;
size_t nread; /* amount of data to read from socket */
- int (*parse)(void *state, void *packet);
- ssize_t (*encode)(void *state, void *packet);
- int (*encapsulate)(void *state, void *packet);
- int (*chksum)(void *state, int a, int b);
- int (*forward)(void *state, void *packet);
+ int (*parse)(SDS_STATE *, struct SDS_PKT *);
+ ssize_t (*encode)(SDS_STATE *, struct SDS_PKT *);
+ int (*encapsulate)(SDS_STATE *, struct SDS_PKT *);
+ int (*chksum)(SDS_STATE *, int a, int b);
+ int (*forward)(SDS_STATE *, struct SDS_PKT *);
} SDS_PKT;
struct _SDS_CONN {
@@ -212,40 +215,40 @@ int sds_q_add(SDS_STATE *ss, SDS_CONN *sc);
int sds_q_del(u_int32_t id);
int sds_q_free(SDS_STATE *ss);
void sds_q_destroy(void);
-void sds_cleanup(void *state);
+void sds_cleanup(SDS_STATE *ss);
/* IO */
-int sds_io_write(void *state, void *packet);
-int sds_io_read(void *state, void *packet);
+int sds_io_write(SDS_STATE *ss, SDS_PKT *pkt);
+int sds_io_read(SDS_STATE *ss, SDS_PKT *pkt);
int sds_io_close(void *qe);
/* socket */
int sds_sock_init(SDS_STATE *ss);
-void sds_sock_loop(void *vp);
+void sds_sock_loop(SDS_STATE *ss);
int sds_sock_recv(SDS_STATE *ss, SDS_PKT *pkt);
int sds_sock_send(SDS_STATE *ss, SDS_PKT *pkt);
/* handler */
-int sds_handler(void *state, void *packet);
-int sds_decapsulate(void *state, void *packet);
-int sds_chk_notequal(void *state, int a, int b);
-int sds_chk_isequal(void *state, int a, int b);
+int sds_handler(SDS_STATE *ss, SDS_PKT *pkt);
+int sds_decapsulate(SDS_STATE *ss, SDS_PKT *pkt);
+int sds_chk_notequal(SDS_STATE *ss, int a, int b);
+int sds_chk_isequal(SDS_STATE *ss, int a, int b);
/* DNS */
/* query */
int sds_dns_type(SDS_PKT *pkt);
int sds_dns_getdn(SDS_STATE *ss, SDS_PKT *pkt);
-int sds_dns_query_A(void *state, void *packet);
-int sds_dns_query_TXT(void *state, void *packet);
+int sds_dns_query_A(SDS_STATE *ss, SDS_PKT *pkt);
+int sds_dns_query_TXT(SDS_STATE *ss, SDS_PKT *pkt);
int sds_dns_checkdn(SDS_STATE *ss, char *domain);
/* response */
void sds_dns_setflags(SDS_STATE *ss, SDS_PKT *pkt);
-ssize_t sds_dns_enc_A(void *state, void *packet);
-ssize_t sds_dns_enc_TXT(void *state, void *packet);
-ssize_t sds_dns_enc_CNAME(void *state, void *packet);
-ssize_t sds_dns_enc_NULL(void *state, void *packet);
-int sds_dns_response(void *state, void *packet);
+ssize_t sds_dns_enc_A(SDS_STATE *ss, SDS_PKT *pkt);
+ssize_t sds_dns_enc_TXT(SDS_STATE *ss, SDS_PKT *pkt);
+ssize_t sds_dns_enc_CNAME(SDS_STATE *ss, SDS_PKT *pkt);
+ssize_t sds_dns_enc_NULL(SDS_STATE *ss, SDS_PKT *pkt);
+int sds_dns_response(SDS_STATE *ss, SDS_PKT *pkt);
void sds_dns_packet(SDS_PKT *pkt, void *data, size_t len);
int sds_priv_init(SDS_STATE *ss);
View
33 sods/sods_dns.c
@@ -96,11 +96,8 @@ sds_dns_getdn(SDS_STATE *ss, SDS_PKT *pkt)
*
*/
int
-sds_dns_query_A(void *state, void *packet)
+sds_dns_query_A(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
char *b32 = NULL;
char *domain = NULL;
char *p = NULL;
@@ -151,11 +148,8 @@ sds_dns_query_A(void *state, void *packet)
*
*/
int
-sds_dns_query_TXT(void *state, void *packet)
+sds_dns_query_TXT(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
u_int32_t nonce = 0;
char domain[NS_MAXDNAME] = {0};
@@ -213,11 +207,8 @@ sds_dns_setflags(SDS_STATE *ss, SDS_PKT *pkt)
* A response
*/
ssize_t
-sds_dns_enc_A(void *state, void *packet)
+sds_dns_enc_A(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
(void)memcpy(&pkt->buf, &ss->ip.s_addr, NS_INADDRSZ);
pkt->buflen = NS_INADDRSZ;
ss->ip.s_addr = htonl(ntohl(ss->ip.s_addr)+1);
@@ -228,10 +219,8 @@ sds_dns_enc_A(void *state, void *packet)
* TXT response
*/
ssize_t
-sds_dns_enc_TXT(void *state, void *packet)
+sds_dns_enc_TXT(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
char b64[NS_PACKETSZ] = {0};
struct dns_txtrec txt;
ssize_t len = 0;
@@ -260,11 +249,8 @@ sds_dns_enc_TXT(void *state, void *packet)
* CNAME response
*/
ssize_t
-sds_dns_enc_CNAME(void *state, void *packet)
+sds_dns_enc_CNAME(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
char *buf = NULL;
char *p = NULL;
char *cp = NULL;
@@ -339,10 +325,8 @@ sds_dns_enc_CNAME(void *state, void *packet)
*
*/
ssize_t
-sds_dns_enc_NULL(void *state, void *packet)
+sds_dns_enc_NULL(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
char b64[NS_PACKETSZ] = {0};
size_t len = 0;
@@ -362,11 +346,8 @@ sds_dns_enc_NULL(void *state, void *packet)
* Generic DNS repsonse for READ requests
*/
int
-sds_dns_response(void *state, void *packet)
+sds_dns_response(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
struct dns_answer ans;
(void)memset(&ans, 0, sizeof(ans));
View
16 sods/sods_handler.c
@@ -33,10 +33,8 @@
*/
int
-sds_handler(void *state, void *packet)
+sds_handler(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
ssize_t n = 0;
LTZERO(ss->decapsulate(ss, pkt)); /* Parse data from application layer */
@@ -50,10 +48,8 @@ sds_handler(void *state, void *packet)
}
int
-sds_decapsulate(void *state, void *packet)
+sds_decapsulate(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
int type = 0;
/* defaults */
@@ -103,10 +99,8 @@ sds_decapsulate(void *state, void *packet)
}
int
-sds_chk_notequal(void *state, int a, int b)
+sds_chk_notequal(SDS_STATE *ss, int a, int b)
{
- SDS_STATE *ss = (SDS_STATE *)state;
-
VERBOSE(1, "sum: saved = %d, packet = %d\n", a, b);
/* New connections */
@@ -121,10 +115,8 @@ sds_chk_notequal(void *state, int a, int b)
}
int
-sds_chk_isequal(void *state, int a, int b)
+sds_chk_isequal(SDS_STATE *ss, int a, int b)
{
- SDS_STATE *ss = (SDS_STATE *)state;
-
if (a == b)
return (0);
View
10 sods/sods_io.c
@@ -23,11 +23,8 @@
SDS_FWD * sds_io_forward(SDS_STATE *ss, SDS_PKT *pkt);
int
-sds_io_write(void *state, void *packet)
+sds_io_write(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
SDS_CONN *sc = NULL;
ssize_t n = 0;
ssize_t t = 0;
@@ -63,11 +60,8 @@ sds_io_write(void *state, void *packet)
}
int
-sds_io_read(void *state, void *packet)
+sds_io_read(SDS_STATE *ss, SDS_PKT *pkt)
{
- SDS_STATE *ss = (SDS_STATE *)state;
- SDS_PKT *pkt = (SDS_PKT *)packet;
-
SDS_CONN *sc = NULL;
ssize_t n = 0;
View
3  sods/sods_q.c
@@ -120,9 +120,8 @@ sds_q_destroy(void)
}
void
-sds_cleanup (void *state)
+sds_cleanup(SDS_STATE *ss)
{
- SDS_STATE *ss = (SDS_STATE *)state;
int n = 0;
VERBOSE(3, "cleaning up connections\n");
View
3  sods/sods_sock.c
@@ -45,9 +45,8 @@ sds_sock_init(SDS_STATE *ss)
}
void
-sds_sock_loop(void *vp)
+sds_sock_loop(SDS_STATE *ss)
{
- SDS_STATE *ss = (SDS_STATE *)vp;
SDS_PKT *pkt = NULL;
IS_NULL(pkt = calloc(1, sizeof(SDS_PKT)));
Please sign in to comment.
Something went wrong with that request. Please try again.