version 1.22.6.2, 2014/11/26 00:50:04
|
version 1.24.2.2, 2015/01/28 00:06:22
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004 - 2014 | Copyright 2004 - 2015 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 161 rpc_cli_openClient(u_char InstID, int netBuf, const ch
|
Line 161 rpc_cli_openClient(u_char InstID, int netBuf, const ch
|
rpc_cli_t *cli = NULL; |
rpc_cli_t *cli = NULL; |
sockaddr_t sa = E_SOCKADDR_INIT; |
sockaddr_t sa = E_SOCKADDR_INIT; |
|
|
|
if (proto < 0 || proto > SOCK_RAW) { |
|
rpc_SetErr(EINVAL, "Invalid parameters can`t open RPC client"); |
|
return NULL; |
|
} |
|
|
if (!e_gethostbyname(csHost, Port, &sa)) |
if (!e_gethostbyname(csHost, Port, &sa)) |
return NULL; |
return NULL; |
if (!Port) |
if (!Port) |
Line 195 rpc_cli_openClient(u_char InstID, int netBuf, const ch
|
Line 200 rpc_cli_openClient(u_char InstID, int netBuf, const ch
|
AIT_SET_BUFSIZ(&cli->cli_buf, 0, netBuf); |
AIT_SET_BUFSIZ(&cli->cli_buf, 0, netBuf); |
|
|
/* connect to RPC server */ |
/* connect to RPC server */ |
cli->cli_sock = socket(cli->cli_sa.sa.sa_family, cli->cli_id, 0); | cli->cli_sock = socket(cli->cli_sa.sa.sa_family, cli->cli_id, |
| cli->cli_id == SOCK_RAW ? IPPROTO_ERPC : 0); |
if (cli->cli_sock == -1) { |
if (cli->cli_sock == -1) { |
LOGERR; |
LOGERR; |
goto err; |
goto err; |
Line 350 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
Line 356 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
do { |
do { |
if (type == SOCK_STREAM) |
if (type == SOCK_STREAM) |
ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, NULL, buf, blen); |
ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, NULL, buf, blen); |
else | else if (type == SOCK_EXT) { |
| ret = rpc_Read(sock, type, 0, NULL, buf, blen); |
| if (estlen) /* hack for skip sanity checks */ |
| ret += sizeof(struct tagRPCCall); |
| } else if (type == SOCK_BPF) { |
| ret = rpc_Read(sock, type, 0, sa, AIT_GET_BUF(pkt), AIT_LEN(pkt)); |
| if (ret > 0) |
| estlen = ret; |
| } else |
ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, sa, buf, blen); |
ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, sa, buf, blen); |
if (ret < 1) |
if (ret < 1) |
return ret; |
return ret; |
|
|
|
/* 1st read for RPC header */ |
|
if (ret < sizeof(struct tagRPCCall)) { |
|
rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); |
|
return -1; |
|
} |
|
|
|
/* check for loop request */ |
|
if (!estlen && !(rpc->call_io & RPC_ACK)) |
|
continue; |
|
|
/* check for response from known address */ |
/* check for response from known address */ |
if (!estlen) { |
if (!estlen) { |
/* 1st read for RPC header */ |
|
if (ret < sizeof(struct tagRPCCall)) { |
|
rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); |
|
return -1; |
|
} |
|
|
|
/* calc estimated length */ |
/* calc estimated length */ |
estlen = ntohl(rpc->call_len); |
estlen = ntohl(rpc->call_len); |
if (estlen > AIT_LEN(pkt)) |
if (estlen > AIT_LEN(pkt)) |
AIT_RE_BUF(pkt, estlen); |
AIT_RE_BUF(pkt, estlen); |
|
blen = estlen; |
buf = AIT_GET_BUF(pkt); |
buf = AIT_GET_BUF(pkt); |
|
|
|
if (type == SOCK_EXT) { |
|
blen -= sizeof(struct tagRPCCall); |
|
buf += sizeof(struct tagRPCCall); |
|
} |
|
|
rpc = (struct tagRPCCall*) buf; |
rpc = (struct tagRPCCall*) buf; |
blen = estlen; |
|
continue; |
continue; |
} |
} |
|
|
Line 377 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
Line 401 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res
|
break; |
break; |
} while (42); |
} while (42); |
|
|
if (ret < sizeof(struct tagRPCCall) || estlen != ret) { | if (estlen != ret) { |
rpc_SetErr(ERPCMISMATCH, "RPC packet mismatch estimate %d bytes, but received %d\n", |
rpc_SetErr(ERPCMISMATCH, "RPC packet mismatch estimate %d bytes, but received %d\n", |
estlen, ret); |
estlen, ret); |
return -1; |
return -1; |
Line 423 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 447 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
if (!vars) |
if (!vars) |
rpc->call_argc = 0; |
rpc->call_argc = 0; |
else |
else |
rpc->call_argc = htons(array_Size(vars)); | rpc->call_argc = (u_char) array_Size(vars); |
|
|
/* set reply */ |
/* set reply */ |
rpc->call_req.flags = (uint64_t) htonl(noreply ? RPC_NOREPLY : RPC_REPLY); |
rpc->call_req.flags = (uint64_t) htonl(noreply ? RPC_NOREPLY : RPC_REPLY); |
Line 440 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 464 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
|
|
/* total packet length */ |
/* total packet length */ |
rpc->call_len = htonl(len); |
rpc->call_len = htonl(len); |
|
rpc->call_io = RPC_REQ; |
|
|
if (!nocrc) { |
if (!nocrc) { |
/* calculate CRC */ |
/* calculate CRC */ |
Line 455 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 480 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t
|
* |
* |
* @pkt = Packet buffer |
* @pkt = Packet buffer |
* @sess = RPC session info, if =NULL don't check session |
* @sess = RPC session info, if =NULL don't check session |
* @tag = Function tag | * @tag = Function tag, if =CALL_TAG_MAX don't check tag |
* @vars = Function argument array of values, may be NULL |
* @vars = Function argument array of values, may be NULL |
* @nocrc = Without CRC calculation |
* @nocrc = Without CRC calculation |
* return: -1 error or != -1 return value from function |
* return: -1 error or != -1 return value from function |
Line 491 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 516 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
rpc_SetErr(ERPCMISMATCH, "Get invalid RPC session"); |
rpc_SetErr(ERPCMISMATCH, "Get invalid RPC session"); |
return -1; |
return -1; |
} |
} |
if (ntohs(rpc->call_tag) != tag) { | if (tag != CALL_TAG_MAX && ntohs(rpc->call_tag) != tag) { |
rpc_SetErr(ERPCMISMATCH, "Get wrong RPC reply"); |
rpc_SetErr(ERPCMISMATCH, "Get wrong RPC reply"); |
return -1; |
return -1; |
} |
} |
Line 501 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 526 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
strerror(ntohl(rpc->call_rep.eno))); |
strerror(ntohl(rpc->call_rep.eno))); |
return -1; |
return -1; |
} |
} |
len = ntohs(rpc->call_argc) * sizeof(ait_val_t); | len = rpc->call_argc * sizeof(ait_val_t); |
if (len > AIT_LEN(pkt) - sizeof(struct tagRPCCall)) { |
if (len > AIT_LEN(pkt) - sizeof(struct tagRPCCall)) { |
rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ..."); |
rpc_SetErr(EMSGSIZE, "Reply RPC packet not enough buffer space ..."); |
return -1; |
return -1; |
Line 512 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
Line 537 rpc_pkt_Replay(ait_val_t * __restrict pkt, rpc_sess_t
|
} |
} |
|
|
/* RPC is OK! Go de-marshaling variables ... */ |
/* RPC is OK! Go de-marshaling variables ... */ |
if (vars && ntohs(rpc->call_argc)) { | if (vars && rpc->call_argc) { |
#ifdef CLI_RES_ZCOPY |
#ifdef CLI_RES_ZCOPY |
*vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len, |
*vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len, |
ntohs(rpc->call_argc), 42); | rpc->call_argc, 42); |
#else |
#else |
*vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len, |
*vars = ait_buffer2vars(buf + sizeof(struct tagRPCCall), len, |
ntohs(rpc->call_argc), 0); | rpc->call_argc, 0); |
#endif |
#endif |
if (!*vars) { |
if (!*vars) { |
rpc_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
rpc_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
Line 550 rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short
|
Line 575 rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short
|
rpc_SetErr(EINVAL, "Can`t execute call because parameter is null or invalid!"); |
rpc_SetErr(EINVAL, "Can`t execute call because parameter is null or invalid!"); |
return -1; |
return -1; |
} else { |
} else { |
if (cli->cli_id == SOCK_STREAM) | if (cli->cli_id == SOCK_STREAM || cli->cli_id == SOCK_EXT) |
type = cli->cli_id; |
type = cli->cli_id; |
buf = AIT_GET_BUF(&cli->cli_buf); |
buf = AIT_GET_BUF(&cli->cli_buf); |
} |
} |
Line 638 rpc_cli_openClient2(u_char InstID, int netBuf, const c
|
Line 663 rpc_cli_openClient2(u_char InstID, int netBuf, const c
|
register int i; |
register int i; |
struct ifreq ifr; |
struct ifreq ifr; |
int n = 1; |
int n = 1; |
|
struct bpf_insn insns[] = { |
|
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), |
|
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, RPC_DEFPORT, 0, 1), |
|
BPF_STMT(BPF_RET + BPF_K, -1), |
|
BPF_STMT(BPF_RET + BPF_K, 0), |
|
}; |
|
struct bpf_program fcode = { |
|
.bf_len = sizeof(insns) / sizeof(struct bpf_insn), |
|
.bf_insns = insns |
|
}; |
|
|
if (!csHost || !e_getlinkbyname(csHost, &sa)) |
if (!csHost || !e_getlinkbyname(csHost, &sa)) |
return NULL; |
return NULL; |
Line 646 rpc_cli_openClient2(u_char InstID, int netBuf, const c
|
Line 681 rpc_cli_openClient2(u_char InstID, int netBuf, const c
|
return NULL; |
return NULL; |
} else |
} else |
strlcpy(szIface, csIface, sizeof szIface); |
strlcpy(szIface, csIface, sizeof szIface); |
if (e_getifacebyname(szIface, &sal)) | if (!e_getifacebyname(szIface, &sal)) |
return NULL; |
return NULL; |
|
|
cli = e_malloc(sizeof(rpc_cli_t)); |
cli = e_malloc(sizeof(rpc_cli_t)); |
Line 689 rpc_cli_openClient2(u_char InstID, int netBuf, const c
|
Line 724 rpc_cli_openClient2(u_char InstID, int netBuf, const c
|
LOGERR; |
LOGERR; |
goto err; |
goto err; |
} |
} |
|
if (ioctl(cli->cli_sock, BIOCSETF, &fcode) == -1) { |
|
LOGERR; |
|
goto err; |
|
} |
n = (netBuf < RPC_MIN_BUFSIZ) ? getpagesize() : E_ALIGN(netBuf, 2); |
n = (netBuf < RPC_MIN_BUFSIZ) ? getpagesize() : E_ALIGN(netBuf, 2); |
if (ioctl(cli->cli_sock, BIOCSBLEN, &n) == -1) { |
if (ioctl(cli->cli_sock, BIOCSBLEN, &n) == -1) { |
LOGERR; |
LOGERR; |
Line 728 rpc_cli_closeClient2(rpc_cli_t ** __restrict cli)
|
Line 767 rpc_cli_closeClient2(rpc_cli_t ** __restrict cli)
|
return; |
return; |
|
|
close((*cli)->cli_sock); |
close((*cli)->cli_sock); |
|
|
|
AIT_FREE_VAL(&(*cli)->cli_buf); |
|
|
|
if ((*cli)->cli_parent) |
|
e_free((*cli)->cli_parent); |
|
|
|
e_free(*cli); |
|
*cli = NULL; |
|
} |
|
|
|
/* |
|
* rpc_cli_openClientExt() - Connect to pipe RPC Server |
|
* |
|
* @InstID = InstID for RPC session request |
|
* @netBuf = Network buffer length (min:512 bytes), if =0 == BUFSIZ (also meaning max RPC packet) |
|
* @fd = File descriptor |
|
* return: NULL == error or !=NULL connection to RPC server established |
|
*/ |
|
rpc_cli_t * |
|
rpc_cli_openClientExt(u_char InstID, int netBuf, int fd) |
|
{ |
|
rpc_cli_t *cli = NULL; |
|
int n; |
|
|
|
cli = e_malloc(sizeof(rpc_cli_t)); |
|
if (!cli) { |
|
LOGERR; |
|
return NULL; |
|
} else |
|
memset(cli, 0, sizeof(rpc_cli_t)); |
|
|
|
/* build session */ |
|
cli->cli_parent = e_malloc(sizeof(rpc_sess_t)); |
|
if (!cli->cli_parent) { |
|
LOGERR; |
|
e_free(cli); |
|
return NULL; |
|
} else { |
|
((rpc_sess_t*) cli->cli_parent)->sess_version = RPC_VERSION; |
|
((rpc_sess_t*) cli->cli_parent)->sess_instance = InstID; |
|
} |
|
|
|
cli->cli_id = SOCK_EXT; |
|
cli->cli_sock = fd; |
|
|
|
n = (netBuf < RPC_MIN_BUFSIZ) ? getpagesize() : E_ALIGN(netBuf, 2); |
|
AIT_SET_BUFSIZ(&cli->cli_buf, 0, n); |
|
|
|
fcntl(cli->cli_sock, F_SETFL, |
|
fcntl(cli->cli_sock, F_GETFL) | O_NONBLOCK); |
|
|
|
return cli; |
|
} |
|
|
|
/* |
|
* rpc_cli_closeClientExt() - Close pipe connection to RPC server and free resources |
|
* |
|
* @cli = RPC Client session |
|
* return: none |
|
*/ |
|
void |
|
rpc_cli_closeClientExt(rpc_cli_t ** __restrict cli) |
|
{ |
|
if (!cli || !*cli || (*cli)->cli_id != SOCK_EXT) |
|
return; |
|
|
AIT_FREE_VAL(&(*cli)->cli_buf); |
AIT_FREE_VAL(&(*cli)->cli_buf); |
|
|