Minor bug fixes

This commit is contained in:
Joseph Henry 2015-10-12 21:26:32 -04:00
parent 8d1b01cb5b
commit 4e1e857949
3 changed files with 31 additions and 35 deletions

View file

@ -130,7 +130,7 @@
* MEMP_NUM_RAW_PCB: Number of raw connection PCBs * MEMP_NUM_RAW_PCB: Number of raw connection PCBs
* (requires the LWIP_RAW option) * (requires the LWIP_RAW option)
*/ */
#define MEMP_NUM_RAW_PCB 128 #define MEMP_NUM_RAW_PCB 1
/** /**
* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One

View file

@ -386,14 +386,9 @@ void NetconEthernetTap::phyOnTcpData(PhySocket *sock,void **uptr,void *data,unsi
void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr) {} void NetconEthernetTap::phyOnTcpWritable(PhySocket *sock,void **uptr) {}
/* /*
* Creates a new NetconClient for the accepted RPC connection (unix domain socket) * Add a new PhySocket for the client connection
*
* Subsequent socket connections from this client will be associated with this
* NetconClient object.
*/ */
void NetconEthernetTap::phyOnUnixAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN) void NetconEthernetTap::phyOnUnixAccept(PhySocket *sockL,PhySocket *sockN,void **uptrL,void **uptrN) {
{
//fprintf(stderr, "phyOnUnixAccept() NEW CLIENT RPC: %d\n", _phy.getDescriptor(sockN));
rpc_sockets.push_back(sockN); rpc_sockets.push_back(sockN);
} }
@ -505,7 +500,8 @@ int NetconEthernetTap::send_return_value(int fd, int retval, int _errno = 0)
[ ] EINVAL - (accept4()) invalid value in flags. [ ] EINVAL - (accept4()) invalid value in flags.
[ ] EMFILE - The per-process limit of open file descriptors has been reached. [ ] EMFILE - The per-process limit of open file descriptors has been reached.
[ ] ENFILE - The system limit on the total number of open files has been reached. [ ] ENFILE - The system limit on the total number of open files has been reached.
[ ] ENOBUFS, ENOMEM - Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory. [ ] ENOBUFS, ENOMEM - Not enough free memory. This often means that the memory allocation is
limited by the socket buffer limits, not by the system memory.
[i] ENOTSOCK - The descriptor references a file, not a socket. [i] ENOTSOCK - The descriptor references a file, not a socket.
[i] EOPNOTSUPP - The referenced socket is not of type SOCK_STREAM. [i] EOPNOTSUPP - The referenced socket is not of type SOCK_STREAM.
[ ] EPROTO - Protocol error. [ ] EPROTO - Protocol error.
@ -707,13 +703,13 @@ err_t NetconEthernetTap::nc_poll(void* arg, struct tcp_pcb *tpcb)
//fprintf(stderr, "nc_poll(): now = %u\n", now); //fprintf(stderr, "nc_poll(): now = %u\n", now);
//fprintf(stderr, "nc_poll\n"); //fprintf(stderr, "nc_poll\n");
/*
Larg *l = (Larg*)arg; Larg *l = (Larg*)arg;
TcpConnection *conn = l->conn; TcpConnection *conn = l->conn;
NetconEthernetTap *tap = l->tap; NetconEthernetTap *tap = l->tap;
if(conn && conn->idx) // if valid connection and non-zero index (indicating data present) if(conn && conn->idx) // if valid connection and non-zero index (indicating data present)
tap->handle_write(conn); tap->handle_write(conn);
*/
return ERR_OK; return ERR_OK;
} }
@ -815,6 +811,8 @@ void NetconEthernetTap::handle_bind(PhySocket *sock, void **uptr, struct bind_st
if(err == ERR_USE) if(err == ERR_USE)
send_return_value(conn, -1, EADDRINUSE); send_return_value(conn, -1, EADDRINUSE);
if(err == ERR_MEM) if(err == ERR_MEM)
send_return_value(conn, -1, ENOMEM); // FIXME: Likely won't happen
if(err == ERR_BUF)
send_return_value(conn, -1, ENOMEM); send_return_value(conn, -1, ENOMEM);
} }
else { else {

View file

@ -112,11 +112,6 @@ void load_symbols(void);
void set_up_intercept(); void set_up_intercept();
int checkpid(); int checkpid();
/* defined in unistd.h, but we don't include it because
it conflicts with our overriden symbols for read/write */
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#define BUF_SZ 1024 #define BUF_SZ 1024
#define SERVICE_CONNECT_ATTEMPTS 30 #define SERVICE_CONNECT_ATTEMPTS 30
@ -134,6 +129,9 @@ pthread_mutex_t loglock;
------------------- Intercept<--->Service Comm mechanisms----------------------- ------------------- Intercept<--->Service Comm mechanisms-----------------------
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
// TODO: Find minimum BUF_SZ for RPC
// TODO: Refactor RPC send logic
static int is_initialized = 0; static int is_initialized = 0;
static int fdret_sock; // used for fd-transfers static int fdret_sock; // used for fd-transfers
static int newfd; // used for "this_end" socket static int newfd; // used for "this_end" socket
@ -142,10 +140,8 @@ static char* af_sock_name = "/tmp/.ztnc_e5cd7a9e1c5311ab";
static int thispid; static int thispid;
/* /*
* * Check for forking
* Check for forking */
*
*/
int checkpid() { int checkpid() {
if(thispid != getpid()) { if(thispid != getpid()) {
printf("clone/fork detected. re-initializing this instance.\n"); printf("clone/fork detected. re-initializing this instance.\n");
@ -157,9 +153,20 @@ int checkpid() {
} }
/* /*
* * Sends an RPC command to the service
*/
void send_command(int rpc_fd, char *cmd)
{
int n_write = write(rpc_fd, cmd, BUF_SZ);
if(n_write < 0){
dwr("Error writing command to service (CMD = %d)\n", cmd[0]);
errno = 0;
//return -1;
}
}
/*
* Reads a return value from the service and sets errno (if applicable) * Reads a return value from the service and sets errno (if applicable)
*
*/ */
int get_retval() int get_retval()
{ {
@ -541,11 +548,7 @@ int socket(SOCKET_SIG)
cmd[0] = RPC_FD_MAP_COMPLETION; cmd[0] = RPC_FD_MAP_COMPLETION;
memcpy(&cmd[1], &newfd, sizeof(newfd)); memcpy(&cmd[1], &newfd, sizeof(newfd));
if(newfd > -1) { if(newfd > -1) {
int n_write = write(fdret_sock, cmd, BUF_SZ); send_command(fdret_sock, cmd);
if(n_write < 0) {
dwr("Error writing perceived FD to service.\n");
return get_retval();
}
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
errno = ERR_OK; // OK errno = ERR_OK; // OK
return newfd; return newfd;
@ -611,7 +614,7 @@ int connect(CONNECT_SIG)
cmd[0] = RPC_CONNECT; cmd[0] = RPC_CONNECT;
memcpy(&cmd[1], &rpc_st, sizeof(struct connect_st)); memcpy(&cmd[1], &rpc_st, sizeof(struct connect_st));
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
write(fdret_sock,cmd, BUF_SZ); send_command(fdret_sock, cmd);
if(fdret_sock >= 0) { if(fdret_sock >= 0) {
int retval; int retval;
@ -675,7 +678,6 @@ int bind(BIND_SIG)
#ifdef DUMMY #ifdef DUMMY
dwr("bind(%d)\n", sockfd); dwr("bind(%d)\n", sockfd);
return realbind(sockfd, addr, addrlen); return realbind(sockfd, addr, addrlen);
#else #else
/* make sure we don't touch any standard outputs */ /* make sure we don't touch any standard outputs */
if(sockfd == STDIN_FILENO || sockfd == STDOUT_FILENO || sockfd == STDERR_FILENO) if(sockfd == STDIN_FILENO || sockfd == STDOUT_FILENO || sockfd == STDERR_FILENO)
@ -711,7 +713,7 @@ int bind(BIND_SIG)
cmd[0]=RPC_BIND; cmd[0]=RPC_BIND;
memcpy(&cmd[1], &rpc_st, sizeof(struct bind_st)); memcpy(&cmd[1], &rpc_st, sizeof(struct bind_st));
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
write(fdret_sock, cmd, BUF_SZ); send_command(fdret_sock, cmd);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
errno = ERR_OK; errno = ERR_OK;
return get_retval(); return get_retval();
@ -730,7 +732,6 @@ int accept4(ACCEPT4_SIG)
#ifdef DUMMY #ifdef DUMMY
dwr("accept4(%d)\n", sockfd); dwr("accept4(%d)\n", sockfd);
return accept(sockfd, addr, addrlen); return accept(sockfd, addr, addrlen);
#else #else
return accept(sockfd, addr, addrlen); return accept(sockfd, addr, addrlen);
#endif #endif
@ -747,7 +748,6 @@ int accept(ACCEPT_SIG)
{ {
#ifdef DUMMY #ifdef DUMMY
return realaccept(sockfd, addr, addrlen); return realaccept(sockfd, addr, addrlen);
#else #else
/* make sure we don't touch any standard outputs */ /* make sure we don't touch any standard outputs */
if(sockfd == STDIN_FILENO || sockfd == STDOUT_FILENO || sockfd == STDERR_FILENO) if(sockfd == STDIN_FILENO || sockfd == STDOUT_FILENO || sockfd == STDERR_FILENO)
@ -820,9 +820,7 @@ int listen(LISTEN_SIG)
#ifdef DUMMY #ifdef DUMMY
dwr("listen(%d)\n", sockfd); dwr("listen(%d)\n", sockfd);
return reallisten(sockfd, backlog); return reallisten(sockfd, backlog);
#else #else
/* make sure we don't touch any standard outputs */ /* make sure we don't touch any standard outputs */
if(sockfd == STDIN_FILENO || sockfd == STDOUT_FILENO || sockfd == STDERR_FILENO) if(sockfd == STDIN_FILENO || sockfd == STDOUT_FILENO || sockfd == STDERR_FILENO)
return(reallisten(sockfd, backlog)); return(reallisten(sockfd, backlog));
@ -838,7 +836,7 @@ int listen(LISTEN_SIG)
cmd[0] = RPC_LISTEN; cmd[0] = RPC_LISTEN;
memcpy(&cmd[1], &rpc_st, sizeof(struct listen_st)); memcpy(&cmd[1], &rpc_st, sizeof(struct listen_st));
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
write(fdret_sock,cmd, BUF_SZ); send_command(fdret_sock, cmd);
pthread_mutex_unlock(&lock); pthread_mutex_unlock(&lock);
errno = ERR_OK; errno = ERR_OK;
return get_retval(); return get_retval();