From b2841e642d10ca80a8f3ec2b3aca9dd0ec1cf064 Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Wed, 13 Mar 2013 18:43:33 +0100 Subject: l2tp: Display error message when session creation fails (CLI) Print details about errors that can occur when using the "l2tp create session" command line. Signed-off-by: Guillaume Nault --- accel-pppd/ctrl/l2tp/l2tp.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'accel-pppd/ctrl/l2tp') diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 43c985a..2f6a1fc 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -3283,25 +3283,39 @@ static int l2tp_create_session_exec(const char *cmd, char * const *fields, long int tid; int res; - if (fields_cnt != 5) + if (fields_cnt != 5) { + cli_send(client, "invalid number of arguments\r\n"); return CLI_CMD_SYNTAX; + } - if (strcmp("tid", fields[3]) != 0) + if (strcmp("tid", fields[3]) != 0) { + cli_sendv(client, "invalid option: \"%s\"\r\n", fields[3]); return CLI_CMD_SYNTAX; + } - if (u_readlong(&tid, fields[4], 1, L2TP_MAX_TID - 1) < 0) + if (u_readlong(&tid, fields[4], 1, L2TP_MAX_TID - 1) < 0) { + cli_sendv(client, "invalid Tunnel ID: \"%s\"\r\n", fields[4]); return CLI_CMD_INVAL; + } pthread_mutex_lock(&l2tp_lock); conn = l2tp_conn[tid]; if (conn) { - triton_context_call(&conn->ctx, - l2tp_tunnel_create_session, conn); - res = CLI_CMD_OK; - } else + if (triton_context_call(&conn->ctx, l2tp_tunnel_create_session, + conn) < 0) + res = CLI_CMD_FAILED; + else + res = CLI_CMD_OK; + } else { res = CLI_CMD_INVAL; + } pthread_mutex_unlock(&l2tp_lock); + if (res == CLI_CMD_FAILED) + cli_send(client, "session creation failed\r\n"); + else if (res == CLI_CMD_INVAL) + cli_sendv(client, "tunnel %li not found\r\n", tid); + return res; } -- cgit v1.2.3