version 1.16.8.1, 2013/08/21 22:34:18
|
version 1.16.8.6, 2013/08/22 14:01:00
|
Line 172 rpc_cli_openClient(u_char InstID, int netBuf, const ch
|
Line 172 rpc_cli_openClient(u_char InstID, int netBuf, const ch
|
else |
else |
netBuf = E_ALIGN(netBuf, 2); /* align netBuf length */ |
netBuf = E_ALIGN(netBuf, 2); /* align netBuf length */ |
|
|
#ifdef HAVE_SRANDOMDEV |
|
srandomdev(); |
|
#else |
|
time_t tim; |
|
|
|
srandom((time(&tim) ^ getpid())); |
|
#endif |
|
|
|
cli = e_malloc(sizeof(rpc_cli_t)); |
cli = e_malloc(sizeof(rpc_cli_t)); |
if (!cli) { |
if (!cli) { |
LOGERR; |
LOGERR; |
Line 330 int
|
Line 322 int
|
rpc_pkt_Receive(int sock, int type, sockaddr_t * __restrict sa, ait_val_t * __restrict pkt) |
rpc_pkt_Receive(int sock, int type, sockaddr_t * __restrict sa, ait_val_t * __restrict pkt) |
{ |
{ |
struct pollfd pfd; |
struct pollfd pfd; |
int ret, len = 0; | int ret, estlen, blen = sizeof(struct tagRPCCall), len = 0; |
u_char *buf; |
u_char *buf; |
sockaddr_t sa2; |
sockaddr_t sa2; |
socklen_t salen; |
socklen_t salen; |
|
struct tagRPCCall *rpc; |
|
|
if (!pkt) { |
if (!pkt) { |
rpc_SetErr(EINVAL, "Invalid argument(s)!"); |
rpc_SetErr(EINVAL, "Invalid argument(s)!"); |
Line 360 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
Line 353 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
return -1; |
return -1; |
} |
} |
|
|
memset(buf, 0, AIT_LEN(pkt)); | payload: |
if (type == SOCK_STREAM) | if (type == SOCK_STREAM) { |
ret = recv(sock, buf, AIT_LEN(pkt), 0); | memset(buf, 0, blen); |
else { | ret = recv(sock, buf, blen, 0); |
| /* handling case for reply without payload */ |
| if (!ret && buf != AIT_GET_BUF(pkt)) |
| return (buf - AIT_GET_BUF(pkt)); |
| } else { |
| blen = AIT_LEN(pkt); |
| memset(buf, 0, blen); |
memset(&sa2, 0, sizeof sa2); |
memset(&sa2, 0, sizeof sa2); |
salen = sa2.ss.ss_len = sizeof(sockaddr_t); |
salen = sa2.ss.ss_len = sizeof(sockaddr_t); |
ret = recvfrom(sock, buf, AIT_LEN(pkt), 0, &sa2.sa, &salen); | ret = recvfrom(sock, buf, blen, 0, &sa2.sa, &salen); |
} |
} |
if (ret < 1) { |
if (ret < 1) { |
if (ret) { |
if (ret) { |
Line 379 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
Line 378 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
} |
} |
|
|
/* check for response from known address */ |
/* check for response from known address */ |
if (type == SOCK_DGRAM) | if (type == SOCK_DGRAM) { |
if (e_addrcmp(sa, &sa2, 42)) { |
if (e_addrcmp(sa, &sa2, 42)) { |
rpc_SetErr(ERPCMISMATCH, |
rpc_SetErr(ERPCMISMATCH, |
"Received RPC response from unknown address"); |
"Received RPC response from unknown address"); |
continue; |
continue; |
} |
} |
|
} else { |
|
/* 1st read for RPC header */ |
|
if (buf == AIT_GET_BUF(pkt)) { |
|
if (ret < sizeof(struct tagRPCCall)) { |
|
rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); |
|
return -1; |
|
} |
|
|
|
/* calc estimated length */ |
|
rpc = (struct tagRPCCall*) buf; |
|
estlen = ntohl(rpc->call_len); |
|
if (estlen > AIT_LEN(pkt)) |
|
AIT_RE_BUF(pkt, estlen); |
|
buf = AIT_GET_BUF(pkt) + blen; |
|
blen = estlen - blen; |
|
goto payload; |
|
} else |
|
ret += sizeof(struct tagRPCCall); |
|
} |
} while (0); |
} while (0); |
|
|
if (ret < sizeof(struct tagRPCCall)) { |
if (ret < sizeof(struct tagRPCCall)) { |
rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); |
rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); |
return -1; |
return -1; |
Line 410 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 429 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
array_t * __restrict vars, int noreply, int nocrc) |
array_t * __restrict vars, int noreply, int nocrc) |
{ |
{ |
struct tagRPCCall *rpc; |
struct tagRPCCall *rpc; |
int ret = 0, len = sizeof(struct tagRPCCall); | int ret = 0, estlen, len = sizeof(struct tagRPCCall); |
u_char *buf; |
u_char *buf; |
|
|
if (!pkt || !sess) { |
if (!pkt || !sess) { |
rpc_SetErr(EINVAL, "Invalid argument(s)!"); |
rpc_SetErr(EINVAL, "Invalid argument(s)!"); |
return -1; |
return -1; |
} else | } |
buf = AIT_GET_BUF(pkt); | |
|
|
|
/* calc estimated length */ |
|
estlen = ait_resideVars(vars) + len; |
|
if (estlen > AIT_LEN(pkt)) |
|
AIT_RE_BUF(pkt, estlen); |
|
buf = AIT_GET_BUF(pkt); |
|
|
/* prepare RPC call */ |
/* prepare RPC call */ |
rpc = (struct tagRPCCall*) buf; |
rpc = (struct tagRPCCall*) buf; |
rpc_addPktSession(&rpc->call_session, sess); |
rpc_addPktSession(&rpc->call_session, sess); |
Line 442 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 466 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
} |
} |
|
|
/* total packet length */ |
/* total packet length */ |
rpc->call_len = htons(len); | rpc->call_len = htonl(len); |
|
|
if (!nocrc) { |
if (!nocrc) { |
/* calculate CRC */ |
/* calculate CRC */ |
Line 483 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 507 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
/* calculate CRC */ |
/* calculate CRC */ |
crc = ntohs(rpc->call_crc); |
crc = ntohs(rpc->call_crc); |
rpc->call_crc ^= rpc->call_crc; |
rpc->call_crc ^= rpc->call_crc; |
if (crc != crcFletcher16((u_short*) buf, ntohs(rpc->call_len) / 2)) { | if (crc != crcFletcher16((u_short*) buf, ntohl(rpc->call_len) / 2)) { |
rpc_SetErr(ERPCMISMATCH, "Bad CRC RPC packet"); |
rpc_SetErr(ERPCMISMATCH, "Bad CRC RPC packet"); |
return -1; |
return -1; |
} |
} |
Line 509 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 533 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ..."); |
rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ..."); |
return -1; |
return -1; |
} |
} |
if (len > ntohs(rpc->call_len) - sizeof(struct tagRPCCall)) { | if (len > ntohl(rpc->call_len) - sizeof(struct tagRPCCall)) { |
rpc_SetErr(EMSGSIZE, "Reply RPC packet is too short ..."); |
rpc_SetErr(EMSGSIZE, "Reply RPC packet is too short ..."); |
return -1; |
return -1; |
} |
} |