VCOM Linux Driver
Advantech Inc.
Loading...
Searching...
No Matches
ssl_select.c File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/socket.h>
#include <pthread.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <syslog.h>
#include <netinet/tcp.h>
#include <sys/mman.h>
#include <linux/limits.h>
#include "ssl_select.h"

Macros

#define _GNU_SOURCE
 
#define _ssl_update_wait_event(INFO, WEVENT, ERRNO)
 
#define GEN_SSL_ACTION_DIRECT(ACTION, FUNC, SUCCESS_COND, ...)
 
#define GEN_SSL_ACTION_SIMPLE_TV(ACTION, FUNC, SUCCESS_COND, ...)
 
#define GEN_SSL_ACTION_SIMPLE(ACTION, FUNC, ...)
 
#define __handle_flag(INFO, FLAG, IOTYPE, BFIELD)
 
#define INIT_WAIT_EVENT(INFO, WEVENT)
 

Functions

void init_ssl_lib (void)
 
SSL_CTX * initialize_ctx (char *rootCA, char *keyfile, char *password, ssl_pwd_data *_pwd)
 
void destroy_ctx (SSL_CTX *ctx)
 
int ssl_set_fds (ssl_info *info, int maxfd, fd_set *rfds, fd_set *wfds)
 
int __set_block (int sock)
 
int __set_nonblock (int sock)
 
int ssl_errno_str (ssl_info *info, int ssl_errno, char *buf, int buflen)
 
 GEN_SSL_ACTION_DIRECT (accept, SSL_accept(info->ssl), ret==1)
 
 GEN_SSL_ACTION_DIRECT (connect, SSL_connect(info->ssl), ret==1)
 
 GEN_SSL_ACTION_DIRECT (recv, SSL_read(info->ssl, buf, len), ret > 0, void *buf, int len)
 
 GEN_SSL_ACTION_DIRECT (send, SSL_write(info->ssl, buf, len), ret > 0, void *buf, int len)
 
 GEN_SSL_ACTION_SIMPLE_TV (accept, ssl_accept_direct(info, ssl_errno), ret==1)
 
 GEN_SSL_ACTION_SIMPLE_TV (connect, ssl_connect_direct(info, ssl_errno), ret==1)
 
 GEN_SSL_ACTION_SIMPLE_TV (recv, ssl_recv_direct(info, buf, len, ssl_errno), ret > 0, void *buf, int len)
 
 GEN_SSL_ACTION_SIMPLE_TV (send, ssl_send_direct(info, buf, len, ssl_errno), ret > 0, void *buf, int len)
 
 GEN_SSL_ACTION_SIMPLE (accept, ssl_accept_simple_tv(info, &tv, ssl_errno))
 
 GEN_SSL_ACTION_SIMPLE (connect, ssl_connect_simple_tv(info, &tv, ssl_errno))
 
 GEN_SSL_ACTION_SIMPLE (recv, ssl_recv_simple_tv(info, buf, len, &tv, ssl_errno), void *buf, int len)
 
 GEN_SSL_ACTION_SIMPLE (send, ssl_send_simple_tv(info, buf, len, &tv, ssl_errno), void *buf, int len)
 
int ssl_handle_fds (ssl_info *info, fd_set *rfds, fd_set *wfds)
 
ssl_infosslinfo_alloc (void)
 

Macro Definition Documentation

◆ __handle_flag

#define __handle_flag ( INFO,
FLAG,
IOTYPE,
BFIELD )
Value:
if((INFO)->FLAG.IOTYPE){ \
(BFIELD) |= (invoke_ssl_##FLAG);\
}

◆ _GNU_SOURCE

#define _GNU_SOURCE

◆ _ssl_update_wait_event

#define _ssl_update_wait_event ( INFO,
WEVENT,
ERRNO )
Value:
_do_ssl_update_wait_event(INFO, &(INFO->WEVENT), ERRNO, __func__)

◆ GEN_SSL_ACTION_DIRECT

#define GEN_SSL_ACTION_DIRECT ( ACTION,
FUNC,
SUCCESS_COND,
... )
Value:
int ssl_##ACTION##_direct(ssl_info * info, ##__VA_ARGS__, int * r_errno)\
{\
int ret;\
int ssl_errno;\
info->ACTION.read = 0;\
info->ACTION.write = 0;\
\
ret = (FUNC);\
\
if(SUCCESS_COND){\
/*printf("%s success\n", __func__);*/\
return ret;\
}\
ssl_errno = SSL_get_error(info->ssl, ret);\
\
if(r_errno){\
*r_errno = ssl_errno;\
}\
\
return _ssl_update_wait_event(info, ACTION, ssl_errno);\
}
#define _ssl_update_wait_event(INFO, WEVENT, ERRNO)
Definition ssl_select.c:335
Definition ssl_select.h:18

◆ GEN_SSL_ACTION_SIMPLE

#define GEN_SSL_ACTION_SIMPLE ( ACTION,
FUNC,
... )
Value:
int ssl_##ACTION##_simple(ssl_info * info, ##__VA_ARGS__, int to_ms, int *ssl_errno)\
{\
struct timeval tv;\
\
tv.tv_sec = to_ms / 1000;\
tv.tv_usec = (to_ms % 1000) * 1000;\
\
return (FUNC);\
}\

◆ GEN_SSL_ACTION_SIMPLE_TV

#define GEN_SSL_ACTION_SIMPLE_TV ( ACTION,
FUNC,
SUCCESS_COND,
... )
Value:
int ssl_##ACTION##_simple_tv(ssl_info * info, ##__VA_ARGS__, struct timeval * tv, int *ssl_errno)\
{\
int ret, sel;\
fd_set rfds, wfds;\
\
do{\
ret = (FUNC);\
\
if(SUCCESS_COND){\
return ret;\
}else if(ret == SSL_OPS_FAIL){\
break;\
}\
\
FD_ZERO(&rfds);\
FD_ZERO(&wfds);\
\
ssl_set_fds(info, 0, &rfds, &wfds);\
sel = select( info->sk + 1, &rfds, &wfds, 0, tv);\
\
}while(sel > 0);\
\
return ret;\
}
@ SSL_OPS_FAIL
Definition ssl_select.h:7

◆ INIT_WAIT_EVENT

#define INIT_WAIT_EVENT ( INFO,
WEVENT )
Value:
{(INFO)->WEVENT.read = (INFO)->WEVENT.write = 0;}

Function Documentation

◆ __set_block()

int __set_block ( int sock)

◆ __set_nonblock()

int __set_nonblock ( int sock)

◆ destroy_ctx()

void destroy_ctx ( SSL_CTX * ctx)

◆ GEN_SSL_ACTION_DIRECT() [1/4]

GEN_SSL_ACTION_DIRECT ( accept ,
SSL_accept(info->ssl) ,
ret = =1 )

◆ GEN_SSL_ACTION_DIRECT() [2/4]

GEN_SSL_ACTION_DIRECT ( connect ,
SSL_connect(info->ssl) ,
ret = =1 )

◆ GEN_SSL_ACTION_DIRECT() [3/4]

GEN_SSL_ACTION_DIRECT ( recv ,
SSL_read(info->ssl, buf, len) ,
ret ,
0 ,
void * buf,
int len )

◆ GEN_SSL_ACTION_DIRECT() [4/4]

GEN_SSL_ACTION_DIRECT ( send ,
SSL_write(info->ssl, buf, len) ,
ret ,
0 ,
void * buf,
int len )

◆ GEN_SSL_ACTION_SIMPLE() [1/4]

GEN_SSL_ACTION_SIMPLE ( accept ,
ssl_accept_simple_tv(info, &tv, ssl_errno)  )

◆ GEN_SSL_ACTION_SIMPLE() [2/4]

GEN_SSL_ACTION_SIMPLE ( connect ,
ssl_connect_simple_tv(info, &tv, ssl_errno)  )

◆ GEN_SSL_ACTION_SIMPLE() [3/4]

GEN_SSL_ACTION_SIMPLE ( recv ,
ssl_recv_simple_tv(info, buf, len, &tv, ssl_errno) ,
void * buf,
int len )

◆ GEN_SSL_ACTION_SIMPLE() [4/4]

GEN_SSL_ACTION_SIMPLE ( send ,
ssl_send_simple_tv(info, buf, len, &tv, ssl_errno) ,
void * buf,
int len )

◆ GEN_SSL_ACTION_SIMPLE_TV() [1/4]

GEN_SSL_ACTION_SIMPLE_TV ( accept ,
ssl_accept_direct(info, ssl_errno) ,
ret = =1 )

◆ GEN_SSL_ACTION_SIMPLE_TV() [2/4]

GEN_SSL_ACTION_SIMPLE_TV ( connect ,
ssl_connect_direct(info, ssl_errno) ,
ret = =1 )

◆ GEN_SSL_ACTION_SIMPLE_TV() [3/4]

GEN_SSL_ACTION_SIMPLE_TV ( recv ,
ssl_recv_direct(info, buf, len, ssl_errno) ,
ret ,
0 ,
void * buf,
int len )

◆ GEN_SSL_ACTION_SIMPLE_TV() [4/4]

GEN_SSL_ACTION_SIMPLE_TV ( send ,
ssl_send_direct(info, buf, len, ssl_errno) ,
ret ,
0 ,
void * buf,
int len )

◆ init_ssl_lib()

void init_ssl_lib ( void )

◆ initialize_ctx()

SSL_CTX * initialize_ctx ( char * rootCA,
char * keyfile,
char * password,
ssl_pwd_data * _pwd )

◆ ssl_errno_str()

int ssl_errno_str ( ssl_info * info,
int ssl_errno,
char * buf,
int buflen )

◆ ssl_handle_fds()

int ssl_handle_fds ( ssl_info * info,
fd_set * rfds,
fd_set * wfds )

◆ ssl_set_fds()

int ssl_set_fds ( ssl_info * info,
int maxfd,
fd_set * rfds,
fd_set * wfds )

◆ sslinfo_alloc()

ssl_info * sslinfo_alloc ( void )