Re: Openssl asynchronous operation in real network

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

Adding more details to the previous mail. We have edited the OpenSSL code for implementing the polling for changed fd's as in OpenSSL speed command. Attached the code snippet of the same along with this mail.
Mentioned below some observations which found doubtful:

1) We have got prints in ASYNC_FINISH case, before getting print in ASYNC_PAUSE case. Attaching the log also, so you can understand easily. 
2) Shown below the code snippet which we have written to provide a write on fd.

if ((waitctx = ASYNC_get_wait_ctx((ASYNC_JOB *)job)) == NULL) {
        printf("In dynamic engine | waitctx == NULL : %d\n", __LINE__);
        return ret;
    }

    printf("\n----- In dynamic engine | After pausing | job is %lx |  waitctx in resume job %lx |-----\n", job, waitctx);

        if ((ret = ASYNC_WAIT_CTX_get_fd(waitctx, engine_id, &efd,
                              &custom)) > 0) {
        if (write(efd, &buf, sizeof(uint64_t)) == -1) {
            printf("\nFailed to write\n");
        }
    }

Here waitctx is getting NULL when we tried to fetch waitctx using ASYNC_get_wait_ctx(). We have printed data of sizeof(ASYNC_JOB) ie.1176 bytes contained in the job address from the engine,  we got correct data before calling ASYNC_pause() and but got half data zero data when we tried to access the same address after ASYNC_pause(). 

Attaching both job structure contents before and after calling ASYNC_pause(). Also, we got the correct data in the same address when we have printed from ssl_start_async_job() before polling starts, where we have started the async_job
The prints starting with "In dynamic engine" are prints inside the engine, rest prints are from ss/ssl_lib.c. Kindly check this and please point out if anything is wrong somewhere. Thanks in advance.


On Sun, Jan 6, 2019 at 10:30 AM Ananthu Unnikrishnan <ananthuu741@xxxxxxxxx> wrote:
Hi all,

       We have implemented a dynamic engine and tested in the async mode using OpenSSL speed command. But in a real network scenario, we have seen only starting the async_job(in file ssl/ssl_lib.c, function: ssl_start_async_job) in the OpenSSL. We haven't seen polling async_fd's for resuming the job as in apps/speed.c(in speed command case).
        So can anyone please suggest any solution for resuming the async_jobs in real network scenario? Thanks in advance.





--
With best Regards, 

         Ananthu


Attachment: ASYNC_JOB_contents_after_pause
Description: Binary data

Attachment: ASYNC_JOB_contents_before_pause
Description: Binary data

Attachment: log_async_job
Description: Binary data

static int ssl_start_async_job(SSL *s, struct ssl_async_args *args,
		int (*func) (void *))
{
	int ret;
	static int num_inprogress = 0;
	int job_op_count = 0;
	int total_op_count = 0, async_jobs, i, error;
	size_t num_job_fds = 0;
	OSSL_ASYNC_FD job_fd = 0;
	OSSL_ASYNC_FD efd;
	static ASYNC_JOB *job[3];
	static ASYNC_WAIT_CTX *waitctx[3];
	void *custom = NULL;
	uint64_t buf = 1;

	if (s->waitctx == NULL) {
		s->waitctx = ASYNC_WAIT_CTX_new();
		if (s->waitctx == NULL) {

			printf("\n----Error on s->waitctx == NULL ----\n");
			return -1;
		}
	}
	switch (ASYNC_start_job(&s->job, s->waitctx, &ret, func, args,
				sizeof(struct ssl_async_args))) {
		case ASYNC_ERR:
			s->rwstate = SSL_NOTHING;
			SSLerr(SSL_F_SSL_START_ASYNC_JOB, SSL_R_FAILED_TO_INIT_ASYNC);
			return -1;
		case ASYNC_PAUSE:
			printf("\n--------In ASYNC_PAUSE | num_inprogress is %d --------\n", num_inprogress);
			job[num_inprogress] = s->job;
			waitctx[num_inprogress] = s->waitctx;
			++num_inprogress;
			s->rwstate = SSL_ASYNC_PAUSED;
			if (num_inprogress < MAX_JOB) { /* MAX_JOB currently set as 1 */
				return -1;
			} else {
				break;
			}
		case ASYNC_NO_JOBS:
			s->rwstate = SSL_ASYNC_NO_JOBS;
			return -1;
		case ASYNC_FINISH:
			if (job_op_count == -1) {
				error = 1;
				printf("\n----Error on ASYNC_FINISH----\n");
			} else {
				total_op_count += job_op_count;
			}
			printf("\n----In ASYNC_FINISH | job : %lx | waitctx is %lx | ret: %d ----\n", s->job, s->waitctx, ret);
			s->job = NULL;
			return ret;
		default:
			s->job = NULL;
			s->rwstate = SSL_NOTHING;
			SSLerr(SSL_F_SSL_START_ASYNC_JOB, ERR_R_INTERNAL_ERROR);
			/* Shouldn't happen */
			return -1;
	}

	while (num_inprogress > 0) {
		int select_result = 0;
		OSSL_ASYNC_FD max_fd = 0;
		fd_set waitfdset;
		ASYNC_WAIT_CTX *waitctx_p;

		FD_ZERO(&waitfdset);
		async_jobs = num_inprogress;
		for (i = 0; i < async_jobs && num_inprogress > 0; i++) {
			printf("\n------ job[%d]: %lx waitctx[%d]: %lx -------\n", i, job[i], i, waitctx[i]);
			if (job[i] == NULL)
				continue;
			if (!ASYNC_WAIT_CTX_get_all_fds(waitctx[i], NULL, &num_job_fds) || num_job_fds > 1) {
				printf("\n------Too many fds in ASYNC_WAIT_CTX-----\n");
				break;
			}
			ASYNC_WAIT_CTX_get_all_fds(waitctx[i], &job_fd, &num_job_fds);
			printf("\n------- num_job_fds is %d | job_fd is %d | max_fd is %d \n", num_job_fds, job_fd, max_fd);
			FD_SET(job_fd, &waitfdset);
			if (job_fd > max_fd)
				max_fd = job_fd;
		}

		select_result = select(max_fd + 1, &waitfdset, NULL, NULL, NULL);

		if (select_result == -1 && errno == EINTR)
			continue;
		if (select_result == -1) {
			printf("\n-------Failure in the select------\n");
			break;
		}
		if (select_result == 0)
			continue;

		for (i = 0; i < async_jobs; i++) {
			if (job[i] == NULL)
				continue;

			if (!ASYNC_WAIT_CTX_get_all_fds(waitctx[i], NULL, &num_job_fds)){
				printf("\n-------Too many fds in ASYNC_WAIT_CTX-------\n");
				break;
			}
			ASYNC_WAIT_CTX_get_all_fds(waitctx[i], &job_fd, &num_job_fds);
			if (num_job_fds == 1 && !FD_ISSET(job_fd, &waitfdset))
				continue;
			ret = ASYNC_start_job(&job[i], waitctx[i], &job_op_count, func, args, sizeof(struct ssl_async_args));

			switch (ret) {
				case ASYNC_PAUSE:
					break;
				case ASYNC_FINISH:
					if (job_op_count == -1) {
						error = 1;
					} else {
						total_op_count += job_op_count;
					}
					--num_inprogress;
					s->job = NULL;
					break;
				case ASYNC_NO_JOBS:
				case ASYNC_ERR:
					--num_inprogress;
					s->job = NULL;
					printf("\n------Failure in the job------\n");
					break;
			}
		}
	}
	return error ? -1 : total_op_count;
}
-- 
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux