summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl/l2tp
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2013-03-13 18:43:11 +0100
committerKozlov Dmitry <xeb@mail.ru>2013-03-15 23:59:31 +0400
commit7004505febb3560fa2188bb852a6366fa8180bad (patch)
tree4107d967190199223c50d10ea0ee4a1fb59ca90f /accel-pppd/ctrl/l2tp
parent819d634942cd3fb5bb83f906393b687b4a3d9de8 (diff)
downloadaccel-ppp-7004505febb3560fa2188bb852a6366fa8180bad.tar.gz
accel-ppp-7004505febb3560fa2188bb852a6366fa8180bad.zip
l2tp: Use tunnel/session logging functions
Define macros for logging tunnel or session messages with automatic context information display. Use these macros to replace most existing error messages + add missing ones. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/ctrl/l2tp')
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c1059
1 files changed, 752 insertions, 307 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index 69e5d14..1b32f26 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -129,6 +129,24 @@ static int l2tp_conn_read(struct triton_md_handler_t *);
static void l2tp_tunnel_session_freed(void *data);
+#define log_tunnel(log_func, conn, fmt, ...) \
+ do { \
+ char addr[17]; \
+ u_inet_ntoa(conn->peer_addr.sin_addr.s_addr, addr); \
+ log_func("l2tp tunnel %hu-%hu (%s:%hu): " fmt, \
+ conn->tid, conn->peer_tid, addr, \
+ ntohs(conn->peer_addr.sin_port), \
+ ##__VA_ARGS__); \
+ } while (0)
+
+#define log_session(log_func, sess, fmt, ...) \
+ do { \
+ log_func("l2tp session %hu-%hu, %hu-%hu: " \
+ fmt, sess->paren_conn->tid, \
+ sess->paren_conn->peer_tid, sess->sid, \
+ sess->peer_sid, ##__VA_ARGS__); \
+ } while (0)
+
static inline void comp_chap_md5(uint8_t *md5, uint8_t ident,
const void *secret, size_t secret_len,
const void *chall, size_t chall_len)
@@ -228,9 +246,9 @@ static int l2tp_tunnel_genchall(uint16_t chall_len,
if (conn->challenge_len != chall_len) {
ptr = _realloc(conn->challenge, chall_len);
if (ptr == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Challenge generation failure:"
- " Memory allocation failed\n");
+ log_tunnel(log_error, conn,
+ "impossible to generate Challenge:"
+ " memory allocation failed\n");
goto err;
}
conn->challenge = ptr;
@@ -244,23 +262,28 @@ static int l2tp_tunnel_genchall(uint16_t chall_len,
if (errno == EINTR)
rdlen = 0;
else {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Challenge generation failure:"
- " Reading from urandom failed: %s\n",
- strerror(errno));
+ log_tunnel(log_error, conn,
+ "impossible to generate Challenge:"
+ " reading from urandom failed: %s\n",
+ strerror(errno));
goto err;
}
} else if (rdlen == 0) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Challenge generation failure:"
- " EOF reached while reading from urandom\n");
+ log_tunnel(log_error, conn,
+ "impossible to generate Challenge:"
+ " end of file reached while reading"
+ " from urandom\n");
goto err;
}
}
if (l2tp_packet_add_octets(pack, Challenge, conn->challenge,
- conn->challenge_len, 1) < 0)
+ conn->challenge_len, 1) < 0) {
+ log_tunnel(log_error, conn,
+ "impossible to generate Challenge:"
+ " adding data to packet failed\n");
goto err;
+ }
return 0;
@@ -288,18 +311,17 @@ static int l2tp_tunnel_storechall(struct l2tp_conn_t *conn,
}
if (conf_secret == NULL || strlen(conf_secret) == 0) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Authentication required by peer,"
- " but no secret has been set for this tunnel\n");
+ log_tunnel(log_error, conn, "authentication required by peer,"
+ " but no secret has been set for this tunnel\n");
goto err;
}
if (conn->challenge_len != chall->length) {
ptr = realloc(conn->challenge, chall->length);
if (ptr == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Impossible to store received"
- " challenge: Memory allocation failed\n");
+ log_tunnel(log_error, conn,
+ "impossible to store received"
+ " Challenge: memory allocation failed\n");
goto err;
}
conn->challenge = ptr;
@@ -327,24 +349,28 @@ static int l2tp_tunnel_genchallresp(uint8_t msgident,
if (conn->challenge == NULL) {
if (conf_secret && strlen(conf_secret) > 0) {
- l2tp_conn_log(log_warn, conn);
- log_warn("l2tp: No Challenge sent by peer\n");
+ log_tunnel(log_warn, conn,
+ "no Challenge sent by peer\n");
}
return 0;
}
if (conf_secret == NULL || strlen(conf_secret) == 0) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Challenge Response generation failure:"
- " No secret set for this tunnel\n");
+ log_tunnel(log_error, conn,
+ "impossible to generate Challenge Response:"
+ " no secret set for this tunnel\n");
return -1;
}
comp_chap_md5(challresp, msgident, conf_secret, strlen(conf_secret),
conn->challenge, conn->challenge_len);
if (l2tp_packet_add_octets(pack, Challenge_Response, challresp,
- MD5_DIGEST_LENGTH, 1) < 0)
+ MD5_DIGEST_LENGTH, 1) < 0) {
+ log_tunnel(log_error, conn,
+ "impossible to generate Challenge Response:"
+ " adding data to packet failed\n");
return -1;
+ }
return 0;
}
@@ -357,35 +383,37 @@ static int l2tp_tunnel_checkchallresp(uint8_t msgident,
if (conf_secret == NULL || strlen(conf_secret) == 0) {
if (challresp) {
- l2tp_conn_log(log_warn, conn);
- log_warn("l2tp: Unexpected Challenge Response sent"
- " by peer\n");
+ log_tunnel(log_warn, conn,
+ "discarding unexpected Challenge Response"
+ " sent by peer\n");
}
return 0;
}
if (conn->challenge == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Challenge missing\n");
+ log_tunnel(log_error, conn, "impossible to authenticate peer:"
+ " Challenge is unavailable\n");
return -1;
}
if (challresp == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: No Challenge Response sent by peer\n");
+ log_tunnel(log_error, conn, "impossible to authenticate peer:"
+ " no Challenge Response sent by peer\n");
return -1;
} else if (challresp->length != MD5_DIGEST_LENGTH) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Inconsistent Challenge Response sent by"
- " peer (invalid length %i)\n", challresp->length);
+ log_tunnel(log_error, conn, "impossible to authenticate peer:"
+ " invalid Challenge Response sent by peer"
+ " (inconsistent length: %i bytes)\n",
+ challresp->length);
return -1;
}
comp_chap_md5(challref, msgident, conf_secret, strlen(conf_secret),
conn->challenge, conn->challenge_len);
if (memcmp(challref, challresp->val.octets, MD5_DIGEST_LENGTH) != 0) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Invalid Challenge Response sent by peer\n");
+ log_tunnel(log_error, conn, "impossible to authenticate peer:"
+ " invalid Challenge Response sent by peer"
+ " (wrong secret)\n");
return -1;
}
@@ -400,15 +428,31 @@ static int l2tp_send_StopCCN(struct l2tp_conn_t *conn,
pack = l2tp_packet_alloc(2, Message_Type_Stop_Ctrl_Conn_Notify,
&conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_tunnel(log_error, conn, "impossible to send StopCCN:"
+ " packet allocation failed\n");
goto out_err;
- if (l2tp_packet_add_int16(pack, Assigned_Tunnel_ID, conn->tid, 1) < 0)
+ }
+ if (l2tp_packet_add_int16(pack, Assigned_Tunnel_ID,
+ conn->tid, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send StopCCN:"
+ " adding data to packet failed\n");
goto out_err;
+ }
if (l2tp_packet_add_octets(pack, Result_Code, (uint8_t *)&rc,
- sizeof(rc), 1) < 0)
+ sizeof(rc), 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send StopCCN:"
+ " adding data to packet failed\n");
goto out_err;
+ }
+
+ if (l2tp_send(conn, pack, 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send StopCCN:"
+ " sending packet failed\n");
+ return -1;
+ }
- return l2tp_send(conn, pack, 0);
+ return 0;
out_err:
if (pack)
@@ -423,14 +467,23 @@ static int l2tp_send_CDN(struct l2tp_sess_t *sess, uint16_t res, uint16_t err)
pack = l2tp_packet_alloc(2, Message_Type_Call_Disconnect_Notify,
&sess->paren_conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_session(log_error, sess, "impossible to send CDN:"
+ " packet allocation failed\n");
goto out_err;
+ }
if (l2tp_packet_add_int16(pack, Assigned_Session_ID,
- sess->sid, 1) < 0)
+ sess->sid, 1) < 0) {
+ log_session(log_error, sess, "impossible to send CDN:"
+ " adding data to packet failed\n");
goto out_err;
+ }
if (l2tp_packet_add_octets(pack, Result_Code, (uint8_t *)&rc,
- sizeof(rc), 1) < 0)
+ sizeof(rc), 1) < 0) {
+ log_session(log_error, sess, "impossible to send CDN:"
+ " adding data to packet failed\n");
goto out_err;
+ }
pack->hdr.sid = htons(sess->peer_sid);
@@ -448,8 +501,12 @@ static int l2tp_tunnel_disconnect(struct l2tp_conn_t *conn, int res, int err)
{
log_ppp_debug("l2tp: terminate (%i, %i)\n", res, err);
- if (l2tp_send_StopCCN(conn, res, err) < 0)
+ if (l2tp_send_StopCCN(conn, res, err) < 0) {
+ log_tunnel(log_error, conn,
+ "impossible to notify peer of tunnel disconnection,"
+ " disconnecting anyway\n");
return -1;
+ }
conn->state = STATE_FIN;
@@ -501,8 +558,11 @@ static void __l2tp_session_free(void *data)
if (sess->ctrl.called_station_id)
_free(sess->ctrl.called_station_id);
- triton_context_call(&sess->paren_conn->ctx,
- l2tp_tunnel_session_freed, NULL);
+ if (triton_context_call(&sess->paren_conn->ctx,
+ l2tp_tunnel_session_freed, NULL) < 0)
+ log_session(log_error, sess,
+ "impossible to notify parent tunnel that"
+ " session has been freed\n");
mempool_free(sess);
}
@@ -511,7 +571,11 @@ static void __l2tp_tunnel_free_session(void *data)
{
struct l2tp_sess_t *sess = data;
- triton_context_call(&sess->sctx, __l2tp_session_free, sess);
+ if (triton_context_call(&sess->sctx, __l2tp_session_free, sess) < 0)
+ log_tunnel(log_error, l2tp_tunnel_self(),
+ "impossible to free session %hu/%hu:"
+ " call to child session failed\n",
+ sess->sid, sess->peer_sid);
}
static void l2tp_tunnel_free_session(void *sess)
@@ -537,8 +601,11 @@ static void l2tp_session_free(struct l2tp_sess_t *sess)
{
intptr_t sid = sess->sid;
- triton_context_call(&sess->paren_conn->ctx,
- l2tp_tunnel_free_sessionid, (void *)sid);
+ if (triton_context_call(&sess->paren_conn->ctx,
+ l2tp_tunnel_free_sessionid, (void *)sid) < 0) {
+ log_session(log_error, sess, "impossible to free session:"
+ " call to parent tunnel failed\n");
+ }
}
static void l2tp_tunnel_free(struct l2tp_conn_t *conn)
@@ -620,18 +687,25 @@ static void l2tp_tunnel_session_freed(void *data)
{
struct l2tp_conn_t *conn = l2tp_tunnel_self();
- if (--conn->sess_count == 0) {
- if (conn->state != STATE_CLOSE)
- l2tp_send_StopCCN(conn, 1, 0);
- l2tp_tunnel_free(conn);
- }
+ if (--conn->sess_count != 0)
+ return;
+
+ if (conn->state != STATE_CLOSE)
+ if (l2tp_send_StopCCN(conn, 1, 0) < 0)
+ log_tunnel(log_error, conn,
+ "impossible to notify peer of tunnel"
+ " disconnection, disconnecting anyway\n");
+ l2tp_tunnel_free(conn);
}
static int l2tp_session_disconnect(struct l2tp_sess_t *sess,
uint16_t res, uint16_t err)
{
if (l2tp_send_CDN(sess, res, err) < 0)
- return -1;
+ log_session(log_error, sess,
+ "impossible to notify peer of session"
+ " disconnection, disconnecting anyway\n");
+
l2tp_session_free(sess);
return 0;
@@ -645,7 +719,10 @@ static void l2tp_ppp_finished(struct ap_session *ses)
__sync_sub_and_fetch(&stat_active, 1);
if (sess->state1 != STATE_CLOSE) {
sess->state1 = STATE_CLOSE;
- l2tp_send_CDN(sess, 2, 0);
+ if (l2tp_send_CDN(sess, 2, 0) < 0)
+ log_session(log_error, sess,
+ "impossible to notify peer of session"
+ " disconnection, disconnecting anyway\n");
l2tp_session_free(sess);
} else {
/* Called by __l2tp_session_free() via ap_session_terminate().
@@ -676,32 +753,33 @@ static struct l2tp_sess_t *l2tp_tunnel_new_session(struct l2tp_conn_t *conn)
sess = mempool_alloc(l2tp_sess_pool);
if (sess == NULL) {
- log_warn("l2tp: Impossible to allocate new session for"
- " tunnel %hu: memory allocation error\n", conn->tid);
+ log_tunnel(log_error, conn,
+ "impossible to allocate new session:"
+ " memory allocation failed\n");
goto out_err;
}
memset(sess, 0, sizeof(*sess));
rdlen = read(urandom_fd, &sess->sid, sizeof(sess->sid));
if (rdlen != sizeof(sess->sid)) {
- log_warn("l2tp: Impossible to allocate new session for"
- " tunnel %hu: could not get random number (%s)\n",
- conn->tid,
- (rdlen < 0) ? strerror(errno) : "short read");
+ log_tunnel(log_error, conn,
+ "impossible to allocate new session:"
+ " reading from urandom failed: %s\n",
+ (rdlen < 0) ? strerror(errno) : "short read");
goto out_err;
}
if (sess->sid == 0) {
- log_warn("l2tp: Impossible to allocate new session for"
- " tunnel %hu: could not get a valid session ID\n",
- conn->tid);
+ log_tunnel(log_error, conn,
+ "impossible to allocate new session:"
+ " session ID generation failed\n");
goto out_err;
}
sess_search = tsearch(sess, &conn->sessions, sess_cmp);
if (*sess_search != sess) {
- log_warn("l2tp: Impossible to allocate new session for"
- " tunnel %hu: could not find any unused session ID\n",
- conn->tid);
+ log_tunnel(log_error, conn,
+ "impossible to allocate new session:"
+ " could not find any unused session ID\n");
goto out_err;
}
@@ -717,7 +795,8 @@ static void l2tp_sess_close(struct triton_context_t *ctx)
{
struct l2tp_sess_t *sess = container_of(ctx, typeof(*sess), sctx);
- l2tp_session_disconnect(sess, 3, 0);
+ if (l2tp_session_disconnect(sess, 3, 0) < 0)
+ log_session(log_error, sess, "session disconnection failed\n");
}
static struct l2tp_sess_t *l2tp_tunnel_alloc_session(struct l2tp_conn_t *conn)
@@ -765,8 +844,11 @@ static int l2tp_tunnel_confirm_session(struct l2tp_sess_t *sess)
{
struct l2tp_conn_t *conn = l2tp_tunnel_self();
- if (triton_context_register(&sess->sctx, &sess->ppp.ses) < 0)
+ if (triton_context_register(&sess->sctx, &sess->ppp.ses) < 0) {
+ log_tunnel(log_error, conn, "impossible to start new session:"
+ " context registration failed\n");
return -1;
+ }
triton_context_wakeup(&sess->sctx);
__sync_add_and_fetch(&stat_starting, 1);
++conn->sess_count;
@@ -798,14 +880,23 @@ static int l2tp_tunnel_start(struct l2tp_conn_t *conn,
triton_event_func start_func,
void *start_param)
{
- if (triton_context_register(&conn->ctx, NULL) < 0)
+ if (triton_context_register(&conn->ctx, NULL) < 0) {
+ log_error("l2tp: impossible to start new tunnel:"
+ " context registration failed\n");
return -1;
+ }
triton_md_register_handler(&conn->ctx, &conn->hnd);
- if (triton_md_enable_handler(&conn->hnd, MD_MODE_READ) < 0)
+ if (triton_md_enable_handler(&conn->hnd, MD_MODE_READ) < 0) {
+ log_error("l2tp: impossible to start new tunnel:"
+ " enabling handler failed\n");
goto out_err;
+ }
triton_context_wakeup(&conn->ctx);
- if (triton_context_call(&conn->ctx, start_func, start_param) < 0)
+ if (triton_context_call(&conn->ctx, start_func, start_param) < 0) {
+ log_error("l2tp: impossible to start new tunnel:"
+ " call to tunnel context failed\n");
goto out_err;
+ }
return 0;
@@ -828,7 +919,8 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(const struct sockaddr_in *peer,
conn = mempool_alloc(l2tp_conn_pool);
if (!conn) {
- log_emerg("l2tp: out of memory\n");
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " memory allocation failed\n");
return NULL;
}
@@ -837,49 +929,56 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(const struct sockaddr_in *peer,
conn->hnd.fd = socket(PF_INET, SOCK_DGRAM, 0);
if (conn->hnd.fd < 0) {
- log_error("l2tp: socket: %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " socket(PF_INET) failed: %s\n", strerror(errno));
mempool_free(conn);
return NULL;
}
flag = fcntl(conn->hnd.fd, F_GETFD);
if (flag < 0) {
- log_error("l2tp: fcntl(F_GETFD): %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " fcntl(F_GETFD) failed: %s\n", strerror(errno));
goto out_err;
}
flag = fcntl(conn->hnd.fd, F_SETFD, flag | FD_CLOEXEC);
if (flag < 0) {
- log_error("l2tp: failed to set close-on-exec flag:"
- " fcntl(F_SETFD): %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " fcntl(F_SETFD) failed: %s\n",
+ strerror(errno));
goto out_err;
}
flag = 1;
if (setsockopt(conn->hnd.fd, SOL_SOCKET, SO_REUSEADDR,
&flag, sizeof(flag)) < 0) {
- log_error("l2tp: setsockopt(SO_REUSEADDR): %s\n",
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " setsockopt(SO_REUSEADDR) failed: %s\n",
strerror(errno));
goto out_err;
}
if (bind(conn->hnd.fd, host, sizeof(*host))) {
- log_error("l2tp: bind: %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " bind() failed: %s\n", strerror(errno));
goto out_err;
}
if (connect(conn->hnd.fd, (struct sockaddr *)peer, sizeof(*peer))) {
- log_error("l2tp: connect: %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " connect() failed: %s\n", strerror(errno));
goto out_err;
}
flag = fcntl(conn->hnd.fd, F_GETFL);
if (flag < 0) {
- log_error("l2tp: fcntl(F_GETFL): %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " fcntl(F_GETFL) failed: %s\n", strerror(errno));
goto out_err;
}
flag = fcntl(conn->hnd.fd, F_SETFL, flag | O_NONBLOCK);
if (flag < 0) {
- log_error("l2tp: failed to set nonblocking mode:"
- " fcntl(F_SETFL): %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " fcntl(F_SETFL) failed: %s\n", strerror(errno));
goto out_err;
}
@@ -896,18 +995,21 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(const struct sockaddr_in *peer,
pthread_mutex_unlock(&l2tp_lock);
if (!conn->tid) {
- if (conf_verbose)
- log_warn("l2tp: no free tid available\n");
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " no more tunnel available\n");
goto out_err;
}
if (getsockname(conn->hnd.fd, &conn->host_addr, &hostaddrlen) < 0) {
- log_error("l2tp: getsockname: %s\n", strerror(errno));
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " getsockname() failed: %s\n", strerror(errno));
goto out_err;
}
if (hostaddrlen != sizeof(conn->host_addr)) {
- log_error("l2tp: getsockname: invalid address length: %i\n",
- hostaddrlen);
+ log_error("l2tp: impossible to allocate new tunnel:"
+ " inconsistent address length returned by"
+ " getsockname(): %i bytes instead of %zu\n",
+ hostaddrlen, sizeof(conn->host_addr));
goto out_err;
}
@@ -947,10 +1049,10 @@ static inline int l2tp_tunnel_update_peerport(struct l2tp_conn_t *conn,
conn->peer_addr.sin_port = port_nbo;
res = connect(conn->hnd.fd, &conn->peer_addr, sizeof(conn->peer_addr));
if (res < 0) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: Impossible to update peer port from"
- " %hu to %hu: connect() failed: %s\n",
- ntohs(old_port), ntohs(port_nbo), strerror(errno));
+ log_tunnel(log_error, conn,
+ "impossible to update peer port from %hu to %hu:"
+ " connect() failed: %s\n",
+ ntohs(old_port), ntohs(port_nbo), strerror(errno));
conn->peer_addr.sin_port = old_port;
}
@@ -968,18 +1070,21 @@ static int l2tp_session_connect(struct l2tp_sess_t *sess)
sess->ppp.fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
if (sess->ppp.fd < 0) {
- log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno));
+ log_session(log_error, sess, "impossible to connect session:"
+ " socket(AF_PPPOX) failed: %s\n", strerror(errno));
goto out_err;
}
flg = fcntl(sess->ppp.fd, F_GETFD);
if (flg < 0) {
- log_ppp_error("l2tp: fcntl(F_GETFD): %s\n", strerror(errno));
+ log_session(log_error, sess, "impossible to connect session:"
+ " fcntl(F_GETFD) failed: %s\n", strerror(errno));
goto out_err;
}
flg = fcntl(sess->ppp.fd, F_SETFD, flg | FD_CLOEXEC);
if (flg < 0) {
- log_ppp_error("l2tp: fcntl(F_SETFD): %s\n", strerror(errno));
+ log_session(log_error, sess, "impossible to connect session:"
+ " fcntl(F_SETFD) failed: %s\n", strerror(errno));
goto out_err;
}
@@ -994,14 +1099,18 @@ static int l2tp_session_connect(struct l2tp_sess_t *sess)
pppox_addr.pppol2tp.s_session = sess->sid;
pppox_addr.pppol2tp.d_session = sess->peer_sid;
- if (connect(sess->ppp.fd, (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) {
- log_ppp_error("l2tp: connect(session): %s\n", strerror(errno));
+ if (connect(sess->ppp.fd,
+ (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) {
+ log_session(log_error, sess, "impossible to connect session:"
+ " connect() failed: %s\n", strerror(errno));
goto out_err;
}
if (setsockopt(sess->ppp.fd, SOL_PPPOL2TP, PPPOL2TP_SO_LNSMODE,
&lns_mode, sizeof(lns_mode))) {
- log_ppp_error("l2tp: setsockopt: %s\n", strerror(errno));
+ log_session(log_error, sess, "impossible to connect session:"
+ " setsockopt(PPPOL2TP_SO_LNSMODE) failed: %s\n",
+ strerror(errno));
goto out_err;
}
@@ -1012,8 +1121,11 @@ static int l2tp_session_connect(struct l2tp_sess_t *sess)
triton_event_fire(EV_CTRL_STARTED, &sess->ppp.ses);
- if (establish_ppp(&sess->ppp))
+ if (establish_ppp(&sess->ppp)) {
+ log_session(log_error, sess, "impossible to connect session:"
+ "PPP establishment failed\n");
goto out_err;
+ }
__sync_sub_and_fetch(&stat_starting, 1);
__sync_add_and_fetch(&stat_active, 1);
@@ -1046,28 +1158,37 @@ static int l2tp_tunnel_connect(struct l2tp_conn_t *conn)
conn->tunnel_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
if (conn->tunnel_fd < 0) {
- log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno));
+ log_tunnel(log_error, conn, "impossible to connect tunnel:"
+ " socket(AF_PPPOX) failed: %s\n", strerror(errno));
goto out_err;
}
flg = fcntl(conn->tunnel_fd, F_GETFD);
if (flg < 0) {
- log_ppp_error("l2tp: fcntl(F_GETFD): %s\n", strerror(errno));
+ log_tunnel(log_error, conn, "impossible to connect tunnel:"
+ " fcntl(F_GETFD) failed: %s\n", strerror(errno));
goto out_err;
}
flg = fcntl(conn->tunnel_fd, F_SETFD, flg | FD_CLOEXEC);
if (flg < 0) {
- log_ppp_error("l2tp: fcntl(F_SETFD): %s\n", strerror(errno));
+ log_tunnel(log_error, conn, "impossible to connect tunnel:"
+ " fcntl(F_SETFD) failed: %s\n", strerror(errno));
goto out_err;
}
- if (connect(conn->tunnel_fd, (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) {
- log_ppp_error("l2tp: connect(tunnel): %s\n", strerror(errno));
+ if (connect(conn->tunnel_fd,
+ (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) {
+ log_tunnel(log_error, conn, "impossible to connect tunnel:"
+ " connect() failed: %s\n", strerror(errno));
goto out_err;
}
if (conf_hello_interval)
- triton_timer_add(&conn->ctx, &conn->hello_timer, 0);
+ if (triton_timer_add(&conn->ctx, &conn->hello_timer, 0) < 0) {
+ log_tunnel(log_error, conn,
+ "impossible to connect tunnel:"
+ " setting HELLO timer failed\n");
+ }
return 0;
@@ -1090,7 +1211,10 @@ static void l2tp_retransmit(struct l2tp_conn_t *conn)
log_debug("send ");
l2tp_packet_print(pack, log_debug);
}
- l2tp_packet_send(conn->hnd.fd, pack);
+ if (l2tp_packet_send(conn->hnd.fd, pack) < 0) {
+ log_tunnel(log_error, conn,
+ "packet retransmission failure\n");
+ }
}
static void l2tp_rtimeout(struct triton_timer_t *t)
@@ -1107,8 +1231,9 @@ static void l2tp_rtimeout(struct triton_timer_t *t)
log_ppp_debug("send ");
l2tp_packet_print(pack, log_ppp_debug);
}
- if (l2tp_packet_send(conn->hnd.fd, pack) == 0)
- return;
+ if (l2tp_packet_send(conn->hnd.fd, pack) < 0)
+ log_tunnel(log_error, conn,
+ "packet retransmission failure\n");
} else
l2tp_tunnel_free(conn);
}
@@ -1145,16 +1270,23 @@ static int l2tp_send(struct l2tp_conn_t *conn, struct l2tp_packet_t *pack, int d
}
}
- if (l2tp_packet_send(conn->hnd.fd, pack))
+ if (l2tp_packet_send(conn->hnd.fd, pack)) {
+ log_tunnel(log_error, conn, "packet transmission failure\n");
goto out_err;
+ }
if (!list_empty(&pack->attrs)) {
list_add_tail(&pack->entry, &conn->send_queue);
if (!conn->rtimeout_timer.tpd)
- triton_timer_add(&conn->ctx, &conn->rtimeout_timer, 0);
+ if (triton_timer_add(&conn->ctx,
+ &conn->rtimeout_timer, 0) < 0)
+ log_tunnel(log_warn, conn,
+ "setting retransmission timer for"
+ " packet %hu failed\n",
+ conn->Ns - 1);
} else
l2tp_packet_free(pack);
-
+
return 0;
out_err:
@@ -1175,11 +1307,17 @@ static int l2tp_send_ZLB(struct l2tp_conn_t *conn)
struct l2tp_packet_t *pack;
pack = l2tp_packet_alloc(2, 0, &conn->peer_addr);
- if (!pack)
+ if (!pack) {
+ log_tunnel(log_error, conn, "impossible to send ZLB:"
+ " packet allocation failed\n");
return -1;
+ }
- if (l2tp_send(conn, pack, 1))
+ if (l2tp_send(conn, pack, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send ZLB:"
+ " sending packet failed\n");
return -1;
+ }
return 0;
}
@@ -1191,6 +1329,8 @@ static void l2tp_send_HELLO(struct triton_timer_t *t)
pack = l2tp_packet_alloc(2, Message_Type_Hello, &conn->peer_addr);
if (!pack) {
+ log_tunnel(log_error, conn, "impossible to send HELLO:"
+ " packet allocation failed\n");
l2tp_tunnel_free(conn);
return;
}
@@ -1206,36 +1346,69 @@ static void l2tp_send_SCCRQ(void *peer_addr)
pack = l2tp_packet_alloc(2, Message_Type_Start_Ctrl_Conn_Request,
&conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " packet allocation failed\n");
goto err;
+ }
if (l2tp_packet_add_int16(pack, Protocol_Version,
- L2TP_V2_PROTOCOL_VERSION, 1) < 0)
+ L2TP_V2_PROTOCOL_VERSION, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " adding data to packet failed\n");
goto pack_err;
- if (l2tp_packet_add_string(pack, Host_Name, conf_host_name, 1) < 0)
+ }
+ if (l2tp_packet_add_string(pack, Host_Name, conf_host_name, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " adding data to packet failed\n");
goto pack_err;
+ }
if (l2tp_packet_add_int32(pack, Framing_Capabilities,
- conn->framing_cap, 1) < 0)
+ conn->framing_cap, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " adding data to packet failed\n");
goto pack_err;
- if (l2tp_packet_add_int16(pack, Assigned_Tunnel_ID, conn->tid, 1) < 0)
+ }
+ if (l2tp_packet_add_int16(pack, Assigned_Tunnel_ID,
+ conn->tid, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " adding data to packet failed\n");
goto pack_err;
- if (l2tp_packet_add_string(pack, Vendor_Name, "accel-ppp", 0) < 0)
+ }
+ if (l2tp_packet_add_string(pack, Vendor_Name, "accel-ppp", 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " adding data to packet failed\n");
goto pack_err;
+ }
- if (l2tp_tunnel_genchall(MD5_DIGEST_LENGTH, conn, pack) < 0)
+ if (l2tp_tunnel_genchall(MD5_DIGEST_LENGTH, conn, pack) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " Challenge generation failed\n");
goto pack_err;
+ }
/* Peer may reply with arbitrary source port */
- if (l2tp_tunnel_update_peerport(conn, 0) < 0)
+ if (l2tp_tunnel_update_peerport(conn, 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " resetting peer port failed\n");
goto err;
+ }
- if (l2tp_send(conn, pack, 0) < 0)
+ if (l2tp_send(conn, pack, 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRQ:"
+ " sending packet failed\n");
goto err;
+ }
- if (!conn->timeout_timer.tpd)
- triton_timer_add(&conn->ctx, &conn->timeout_timer, 0);
- else
- triton_timer_mod(&conn->timeout_timer, 0);
+ if (!conn->timeout_timer.tpd) {
+ if (triton_timer_add(&conn->ctx, &conn->timeout_timer, 0) < 0)
+ log_tunnel(log_warn, conn, "SCCRQ: setting tunnel"
+ " establishment timer failed\n");
+ } else {
+ if (triton_timer_mod(&conn->timeout_timer, 0) < 0)
+ log_tunnel(log_warn, conn, "SCCRQ: resetting tunnel"
+ " establishment timer failed\n");
+ }
conn->state = STATE_WAIT_SCCRP;
@@ -1253,33 +1426,68 @@ static void l2tp_send_SCCRP(struct l2tp_conn_t *conn)
pack = l2tp_packet_alloc(2, Message_Type_Start_Ctrl_Conn_Reply,
&conn->peer_addr);
- if (!pack)
+ if (!pack) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " packet allocation failed\n");
goto out;
-
- if (l2tp_packet_add_int16(pack, Protocol_Version, L2TP_V2_PROTOCOL_VERSION, 1))
+ }
+
+ if (l2tp_packet_add_int16(pack, Protocol_Version,
+ L2TP_V2_PROTOCOL_VERSION, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_string(pack, Host_Name, conf_host_name, 1))
+ }
+ if (l2tp_packet_add_string(pack, Host_Name, conf_host_name, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Framing_Capabilities, conn->framing_cap, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Framing_Capabilities,
+ conn->framing_cap, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int16(pack, Assigned_Tunnel_ID, conn->tid, 1))
+ }
+ if (l2tp_packet_add_int16(pack,
+ Assigned_Tunnel_ID, conn->tid, 1) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_string(pack, Vendor_Name, "accel-ppp", 0))
+ }
+ if (l2tp_packet_add_string(pack, Vendor_Name, "accel-ppp", 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " adding data to packet failed\n");
goto out_err;
+ }
if (l2tp_tunnel_genchallresp(Message_Type_Start_Ctrl_Conn_Reply,
- conn, pack) < 0)
+ conn, pack) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " Challenge Response generation failed\n");
goto out_err;
- if (l2tp_tunnel_genchall(MD5_DIGEST_LENGTH, conn, pack) < 0)
+ }
+ if (l2tp_tunnel_genchall(MD5_DIGEST_LENGTH, conn, pack) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " Challenge generation failed\n");
goto out_err;
+ }
- if (l2tp_send(conn, pack, 0))
+ if (l2tp_send(conn, pack, 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCRP:"
+ " sending packet failed\n");
goto out;
+ }
- if (!conn->timeout_timer.tpd)
- triton_timer_add(&conn->ctx, &conn->timeout_timer, 0);
- else
- triton_timer_mod(&conn->timeout_timer, 0);
+ if (!conn->timeout_timer.tpd) {
+ if (triton_timer_add(&conn->ctx, &conn->timeout_timer, 0) < 0)
+ log_tunnel(log_warn, conn, "SCCRP: setting tunnel"
+ " establishment timer failed\n");
+ } else {
+ if (triton_timer_mod(&conn->timeout_timer, 0) < 0)
+ log_tunnel(log_warn, conn, "SCCRP: resetting tunnel"
+ " establishment timer failed\n");
+ }
conn->state = STATE_WAIT_SCCCN;
@@ -1297,16 +1505,25 @@ static int l2tp_send_SCCCN(struct l2tp_conn_t *conn)
pack = l2tp_packet_alloc(2, Message_Type_Start_Ctrl_Conn_Connected,
&conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_tunnel(log_error, conn, "impossible to send SCCCN:"
+ " packet allocation failed\n");
goto err;
+ }
if (l2tp_tunnel_genchallresp(Message_Type_Start_Ctrl_Conn_Connected,
- conn, pack) < 0)
+ conn, pack) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCCN:"
+ " Challenge Response generation failed\n");
goto pack_err;
+ }
l2tp_tunnel_storechall(conn, NULL);
- if (l2tp_send(conn, pack, 0) < 0)
+ if (l2tp_send(conn, pack, 0) < 0) {
+ log_tunnel(log_error, conn, "impossible to send SCCCN:"
+ " sending packet failed\n");
goto err;
+ }
return 0;
@@ -1322,21 +1539,39 @@ static int l2tp_send_ICRQ(struct l2tp_sess_t *sess)
pack = l2tp_packet_alloc(2, Message_Type_Incoming_Call_Request,
&sess->paren_conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_session(log_error, sess, "impossible to send ICRQ:"
+ " packet allocation failed\n");
return -1;
+ }
- if (l2tp_packet_add_int16(pack, Assigned_Session_ID, sess->sid, 1))
+ if (l2tp_packet_add_int16(pack, Assigned_Session_ID,
+ sess->sid, 1) < 0) {
+ log_session(log_error, sess, "impossible to send ICRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Call_Serial_Number, 0, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Call_Serial_Number, 0, 1) < 0) {
+ log_session(log_error, sess, "impossible to send ICRQ:"
+ " adding data to packet failed\n");
goto out_err;
+ }
- if (l2tp_send(sess->paren_conn, pack, 0))
+ if (l2tp_send(sess->paren_conn, pack, 0) < 0) {
+ log_session(log_error, sess, "impossible to send ICRQ:"
+ " sending packet failed\n");
return -1;
+ }
- if (!sess->timeout_timer.tpd)
- triton_timer_add(&sess->sctx, &sess->timeout_timer, 0);
- else
- triton_timer_mod(&sess->timeout_timer, 0);
+ if (!sess->timeout_timer.tpd) {
+ if (triton_timer_add(&sess->sctx, &sess->timeout_timer, 0) < 0)
+ log_session(log_warn, sess, "ICRQ: setting session"
+ " establishment timer failed\n");
+ } else {
+ if (triton_timer_mod(&sess->timeout_timer, 0) < 0)
+ log_session(log_warn, sess, "ICRQ: resetting session"
+ " establishment timer failed\n");
+ }
return 0;
@@ -1351,15 +1586,25 @@ static int l2tp_send_ICRP(struct l2tp_sess_t *sess)
pack = l2tp_packet_alloc(2, Message_Type_Incoming_Call_Reply,
&sess->paren_conn->peer_addr);
- if (!pack)
+ if (!pack) {
+ log_session(log_error, sess, "impossible to send ICRP:"
+ " packet allocation failed\n");
return -1;
+ }
pack->hdr.sid = htons(sess->peer_sid);
- if (l2tp_packet_add_int16(pack, Assigned_Session_ID, sess->sid, 1))
+ if (l2tp_packet_add_int16(pack, Assigned_Session_ID,
+ sess->sid, 1) < 0) {
+ log_session(log_error, sess, "impossible to send ICRP:"
+ " adding data to packet failed\n");
goto out_err;
+ }
- l2tp_send(sess->paren_conn, pack, 0);
+ if (l2tp_send(sess->paren_conn, pack, 0) < 0) {
+ log_session(log_error, sess, "impossible to send ICRP:"
+ " sending packet failed\n");
+ }
if (!sess->timeout_timer.tpd)
triton_timer_add(&sess->sctx, &sess->timeout_timer, 0);
@@ -1381,20 +1626,36 @@ static int l2tp_send_ICCN(struct l2tp_sess_t *sess)
pack = l2tp_packet_alloc(2, Message_Type_Incoming_Call_Connected,
&sess->paren_conn->peer_addr);
- if (pack == 0)
+ if (pack == 0) {
+ log_session(log_error, sess, "impossible to send ICCN:"
+ " packet allocation failed\n");
return -1;
+ }
pack->hdr.sid = htons(sess->peer_sid);
- if (l2tp_packet_add_int16(pack, Assigned_Session_ID, sess->sid, 1) < 0)
+ if (l2tp_packet_add_int16(pack, Assigned_Session_ID,
+ sess->sid, 1) < 0) {
+ log_session(log_error, sess, "impossible to send ICCN:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, TX_Speed, 1000, 1) < 0)
+ }
+ if (l2tp_packet_add_int32(pack, TX_Speed, 1000, 1) < 0) {
+ log_session(log_error, sess, "impossible to send ICCN:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Framing_Type, 3, 1) < 0)
+ }
+ if (l2tp_packet_add_int32(pack, Framing_Type, 3, 1) < 0) {
+ log_session(log_error, sess, "impossible to send ICCN:"
+ " adding data to packet failed\n");
goto out_err;
+ }
- if (l2tp_send(sess->paren_conn, pack, 0) < 0)
+ if (l2tp_send(sess->paren_conn, pack, 0) < 0) {
+ log_session(log_error, sess, "impossible to send ICCN:"
+ " sending packet failed\n");
return -1;
+ }
return 0;
@@ -1409,31 +1670,64 @@ static int l2tp_send_OCRQ(struct l2tp_sess_t *sess)
pack = l2tp_packet_alloc(2, Message_Type_Outgoing_Call_Request,
&sess->paren_conn->peer_addr);
- if (!pack)
+ if (!pack) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " packet allocation failed\n");
return -1;
+ }
- if (l2tp_packet_add_int16(pack, Assigned_Session_ID, sess->sid, 1))
+ if (l2tp_packet_add_int16(pack, Assigned_Session_ID,
+ sess->sid, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Call_Serial_Number, 0, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Call_Serial_Number, 0, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Minimum_BPS, 100, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Minimum_BPS, 100, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Maximum_BPS, 100000, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Maximum_BPS, 100000, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Bearer_Type, 3, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Bearer_Type, 3, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Framing_Type, 3, 1))
+ }
+ if (l2tp_packet_add_int32(pack, Framing_Type, 3, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_string(pack, Called_Number, "", 1))
+ }
+ if (l2tp_packet_add_string(pack, Called_Number, "", 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " adding data to packet failed\n");
goto out_err;
+ }
- if (l2tp_send(sess->paren_conn, pack, 0))
+ if (l2tp_send(sess->paren_conn, pack, 0) < 0) {
+ log_session(log_error, sess, "impossible to send OCRQ:"
+ " sending packet failed\n");
return -1;
+ }
- if (!sess->timeout_timer.tpd)
- triton_timer_add(&sess->sctx, &sess->timeout_timer, 0);
- else
- triton_timer_mod(&sess->timeout_timer, 0);
+ if (!sess->timeout_timer.tpd) {
+ if (triton_timer_add(&sess->sctx, &sess->timeout_timer, 0) < 0)
+ log_session(log_warn, sess, "OCRQ: setting session"
+ " establishment timer failed\n");
+ } else {
+ if (triton_timer_mod(&sess->timeout_timer, 0) < 0)
+ log_session(log_warn, sess, "OCRQ: resetting session"
+ " establishment timer failed\n");
+ }
return 0;
@@ -1448,16 +1742,26 @@ static int l2tp_send_OCRP(struct l2tp_sess_t *sess)
pack = l2tp_packet_alloc(2, Message_Type_Outgoing_Call_Reply,
&sess->paren_conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_session(log_error, sess, "impossible to send OCRP:"
+ " packet allocation failed\n");
return -1;
+ }
pack->hdr.sid = htons(sess->peer_sid);
- if (l2tp_packet_add_int16(pack, Assigned_Session_ID, sess->sid, 1) < 0)
+ if (l2tp_packet_add_int16(pack, Assigned_Session_ID,
+ sess->sid, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCRP:"
+ " adding data to packet failed\n");
goto out_err;
+ }
- if (l2tp_send(sess->paren_conn, pack, 0) < 0)
+ if (l2tp_send(sess->paren_conn, pack, 0) < 0) {
+ log_session(log_error, sess, "impossible to send OCRP:"
+ " sending packet failed\n");
return -1;
+ }
return 0;
@@ -1472,18 +1776,30 @@ static int l2tp_send_OCCN(struct l2tp_sess_t *sess)
pack = l2tp_packet_alloc(2, Message_Type_Outgoing_Call_Connected,
&sess->paren_conn->peer_addr);
- if (pack == NULL)
+ if (pack == NULL) {
+ log_session(log_error, sess, "impossible to send OCCN:"
+ " packet allocation failed\n");
return -1;
+ }
pack->hdr.sid = htons(sess->peer_sid);
- if (l2tp_packet_add_int32(pack, TX_Speed, 1000, 1) < 0)
+ if (l2tp_packet_add_int32(pack, TX_Speed, 1000, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCCN:"
+ " adding data to packet failed\n");
goto out_err;
- if (l2tp_packet_add_int32(pack, Framing_Type, 3, 1) < 0)
+ }
+ if (l2tp_packet_add_int32(pack, Framing_Type, 3, 1) < 0) {
+ log_session(log_error, sess, "impossible to send OCCN:"
+ " adding data to packet failed\n");
goto out_err;
+ }
- if (l2tp_send(sess->paren_conn, pack, 0) < 0)
+ if (l2tp_send(sess->paren_conn, pack, 0) < 0) {
+ log_session(log_error, sess, "impossible to send OCCN:"
+ " sending packet failed\n");
return -1;
+ }
return 0;
@@ -1505,6 +1821,9 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
const struct l2tp_attr_t *challenge = NULL;
struct l2tp_conn_t *conn = NULL;
struct sockaddr_in host_addr = { 0 };
+ char src_addr[17];
+
+ u_inet_ntoa(pack->addr.sin_addr.s_addr, src_addr);
if (ap_shutdown)
return 0;
@@ -1533,26 +1852,31 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
router_id = attr;
break;
case Message_Digest:
- if (conf_verbose)
- log_warn("l2tp: Message-Digest is not supported\n");
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " Message Digest is not supported\n",
+ src_addr);
return -1;
}
}
if (assigned_tid) {
if (!protocol_version) {
- if (conf_verbose)
- log_warn("l2tp: SCCRQ: no Protocol-Version present in message\n");
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " no Protocol Version present in message\n",
+ src_addr);
return -1;
}
if (protocol_version->val.uint16 != L2TP_V2_PROTOCOL_VERSION) {
- if (conf_verbose)
- log_warn("l2tp: protocol version %02x is not supported\n", protocol_version->val.uint16);
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " unknown Protocol Version %hhu.%hhu\n",
+ src_addr, protocol_version->val.uint16 >> 8,
+ protocol_version->val.uint16 & 0x00FF);
return -1;
}
if (!framing_cap) {
- if (conf_verbose)
- log_warn("l2tp: SCCRQ: no Framing-Capabilities present in message\n");
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " no Framing Capabilities present in message\n",
+ src_addr);
return -1;
}
@@ -1562,8 +1886,11 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
conn = l2tp_tunnel_alloc(&pack->addr, &host_addr,
framing_cap->val.uint32, 1);
- if (conn == NULL)
+ if (conn == NULL) {
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " tunnel allocation failed\n", src_addr);
return -1;
+ }
if (conf_verbose) {
log_switch(&conn->ctx, NULL);
@@ -1572,6 +1899,8 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
}
if (l2tp_tunnel_storechall(conn, challenge) < 0) {
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " storing challenge failed\n", src_addr);
l2tp_tunnel_free(conn);
return -1;
}
@@ -1580,6 +1909,8 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
conn->Nr = 1;
if (l2tp_tunnel_start(conn, (triton_event_func)l2tp_send_SCCRP, conn) < 0) {
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " starting tunnel failed\n", src_addr);
l2tp_tunnel_free(conn);
return -1;
}
@@ -1588,8 +1919,9 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
// not yet implemented
return 0;
} else {
- if (conf_verbose)
- log_warn("l2tp: SCCRQ: no Assigned-Tunnel-ID or Assigned-Connection-ID present in message\n");
+ log_error("l2tp: impossible to handle SCCRQ from %s:"
+ " no Assigned-Tunnel-ID or Assigned-Connection-ID present in message\n",
+ src_addr);
return -1;
}
@@ -1647,20 +1979,18 @@ static int l2tp_recv_SCCRP(struct l2tp_conn_t *conn,
default:
if (attr->M)
unknown_attr = attr;
- else {
- l2tp_conn_log(log_warn, conn);
- log_warn("l2tp: SCCRP:"
- " unknown attribute %i\n",
- attr->attr->id);
- }
+ else
+ log_tunnel(log_warn, conn,
+ "discarding unknown attribute type"
+ " %i in SCCRP\n", attr->attr->id);
break;
}
}
if (assigned_tid == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: SCCRP: missing mandatory AVP:"
- " Assigned Tunnel ID\n");
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " no Assigned Tunnel ID present in message,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
@@ -1670,50 +2000,64 @@ static int l2tp_recv_SCCRP(struct l2tp_conn_t *conn,
conn->peer_tid = assigned_tid->val.uint16;
if (unknown_attr) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: SCCRP: unknown mandatory attribute %i\n",
- unknown_attr->attr->id);
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " unknown mandatory attribute type %i,"
+ " disconnecting tunnel\n",
+ unknown_attr->attr->id);
l2tp_tunnel_disconnect(conn, 2, 8);
return -1;
}
if (framing_cap == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: SCCRP: missing mandatory AVP:"
- " Framing Capabilities\n");
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " no Framing Capabilities present in message,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
if (protocol_version == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: SCCRP: missing mandatory AVP:"
- " Protocol Version\n");
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " no Protocol Version present in message,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
if (protocol_version->val.uint16 != L2TP_V2_PROTOCOL_VERSION) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: SCCRP: unknown protocol version %hhu.%hhu\n",
- protocol_version->val.uint16 >> 8,
- protocol_version->val.uint16 & 0x00FF);
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " unknown Protocol Version %hhu.%hhu,"
+ " disconnecting tunnel\n",
+ protocol_version->val.uint16 >> 8,
+ protocol_version->val.uint16 & 0x00FF);
l2tp_tunnel_disconnect(conn, 5, 0);
return -1;
}
if (l2tp_tunnel_checkchallresp(Message_Type_Start_Ctrl_Conn_Reply,
conn, challenge_resp) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " checking Challenge Response failed,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 4, 0);
return -1;
}
if (l2tp_tunnel_storechall(conn, challenge) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " storing Challenge failed,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 4);
return -1;
}
if (l2tp_tunnel_connect(conn) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " connecting tunnel failed,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
if (l2tp_send_SCCCN(conn) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle SCCRP:"
+ " sending SCCCN failed,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
@@ -1745,10 +2089,11 @@ static int l2tp_recv_SCCCN(struct l2tp_conn_t *conn,
break;
default:
if (attr->M) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: SCCCN:"
- " unknown attribute %i\n",
- attr->attr->id);
+ log_tunnel(log_error, conn,
+ "impossible to handle SCCCN:"
+ " unknown mandatory attribute type %i,"
+ " disconnecting tunnel\n",
+ attr->attr->id);
l2tp_tunnel_disconnect(conn, 2, 8);
return -1;
}
@@ -1757,12 +2102,18 @@ static int l2tp_recv_SCCCN(struct l2tp_conn_t *conn,
if (l2tp_tunnel_checkchallresp(Message_Type_Start_Ctrl_Conn_Connected,
conn, challenge_resp) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle SCCCN:"
+ " checking Challenge Response failed,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 4, 0);
return -1;
}
l2tp_tunnel_storechall(conn, NULL);
if (l2tp_tunnel_connect(conn) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle SCCCN:"
+ " connecting tunnel failed,"
+ " disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
@@ -1825,9 +2176,9 @@ static int l2tp_recv_StopCCN(struct l2tp_conn_t *conn,
break;
default:
if (attr->M) {
- l2tp_conn_log(log_error, conn);
- log_error("StopCCN: unknown attribute %i\n",
- attr->attr->id);
+ log_tunnel(log_warn, conn,
+ "discarding unknown attribute type"
+ " %i in StopCCN\n", attr->attr->id);
}
break;
}
@@ -1837,27 +2188,23 @@ static int l2tp_recv_StopCCN(struct l2tp_conn_t *conn,
if (conn->peer_tid == 0)
conn->peer_tid = assigned_tid->val.uint16;
else if (conn->peer_tid != assigned_tid->val.uint16) {
- l2tp_conn_log(log_error, conn);
- log_error("StopCCN: invalid Assigned Tunnel ID %hu"
- " (tid: %hu, peer tid: %hu)\n",
- assigned_tid->val.uint16,
- conn->tid, conn->peer_tid);
+ log_tunnel(log_warn, conn,
+ "discarding invalid Assigned Tunnel ID %hu"
+ " in StopCCN\n", assigned_tid->val.uint16);
}
} else {
- l2tp_conn_log(log_error, conn);
- log_error("StopCCN: missing mandatory AVP:"
- " Assigned Tunnel ID\n");
+ log_tunnel(log_warn, conn,
+ "no Assigned Tunnel ID present in StopCCN\n");
}
if (result_code) {
if (rescode_get_data(result_code, &res, &err, &err_msg) < 0) {
- l2tp_conn_log(log_error, conn);
- log_error("StopCCN: invalid Result Code\n");
+ log_tunnel(log_warn, conn,
+ "invalid Result Code in StopCCN\n");
}
} else {
- l2tp_conn_log(log_error, conn);
- log_error("StopCCN: missing mandatory AVP:"
- " Result Code\n");
+ log_tunnel(log_warn, conn,
+ "no Result Code present in StopCCN\n");
}
l2tp_conn_log(log_info2, conn);
@@ -1871,7 +2218,8 @@ static int l2tp_recv_StopCCN(struct l2tp_conn_t *conn,
if (err_msg)
_free(err_msg);
- l2tp_send_ZLB(conn);
+ if (l2tp_send_ZLB(conn) < 0)
+ log_tunnel(log_warn, conn, "acknowledging StopCCN failed\n");
return -1;
}
@@ -1879,9 +2227,11 @@ static int l2tp_recv_StopCCN(struct l2tp_conn_t *conn,
static int l2tp_recv_HELLO(struct l2tp_conn_t *conn,
const struct l2tp_packet_t *pack)
{
- if (l2tp_send_ZLB(conn))
+ if (l2tp_send_ZLB(conn) < 0) {
+ log_tunnel(log_error, conn, "acknowledging HELLO failed\n");
return -1;
-
+ }
+
return 0;
}
@@ -1931,8 +2281,9 @@ static int l2tp_recv_ICRQ(struct l2tp_conn_t *conn,
}
if (!assigned_sid) {
- if (conf_verbose)
- log_ppp_warn("l2tp: ICRQ: no Assigned-Session-ID attribute present in message\n");
+ log_tunnel(log_error, conn, "impossible to handle ICRQ:"
+ " no Assigned Session ID present in message,"
+ " disconnecting session\n");
res = 2;
err = 6;
goto out_reject;
@@ -1944,6 +2295,9 @@ static int l2tp_recv_ICRQ(struct l2tp_conn_t *conn,
goto out_reject;
if (l2tp_tunnel_confirm_session(sess) < 0) {
+ log_tunnel(log_error, conn, "impossible to handle ICRQ:"
+ " starting session failed,"
+ " disconnecting session\n");
res = 2;
err = 4;
goto out_reject;
@@ -1984,17 +2338,20 @@ static int l2tp_recv_ICRP(struct l2tp_sess_t *sess,
if (attr->M)
unknown_attr = attr;
else
- log_ppp_warn("l2tp: ICRP:"
- " unknown attribute %i\n",
- attr->attr->id);
+ log_session(log_warn, sess,
+ "discarding unknown attribute type"
+ " %i in ICRP\n", attr->attr->id);
break;
}
}
if (assigned_sid == NULL) {
- log_ppp_error("l2tp: ICRP: missing mandatory AVP:"
- " Assigned Session ID\n");
- l2tp_session_disconnect(sess, 2, 6);
+ log_session(log_error, sess, "impossible to handle ICRP:"
+ " no Assigned Session ID present in message,"
+ " disconnecting session\n");
+ if (l2tp_session_disconnect(sess, 2, 6) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
@@ -2003,23 +2360,35 @@ static int l2tp_recv_ICRP(struct l2tp_sess_t *sess,
sess->peer_sid = assigned_sid->val.uint16;
if (unknown_attr) {
- log_ppp_error("l2tp: ICRP: unknown mandatory attribute %i\n",
- unknown_attr->attr->id);
- l2tp_session_disconnect(sess, 2, 8);
+ log_session(log_error, sess, "impossible to handle ICRP:"
+ " unknown mandatory attribute type %i,"
+ " disconnecting session\n",
+ unknown_attr->attr->id);
+ if (l2tp_session_disconnect(sess, 2, 8) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
if (l2tp_send_ICCN(sess) < 0) {
- log_ppp_error("l2tp: ICRP: Error while sending ICCN\n");
- l2tp_session_disconnect(sess, 2, 6);
+ log_session(log_error, sess, "impossible to handle ICRP:"
+ " sending ICCN failed,"
+ " disconnecting session\n");
+ if (l2tp_session_disconnect(sess, 2, 6) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
sess->state1 = STATE_ESTB;
if (l2tp_session_connect(sess) < 0) {
- log_ppp_error("l2tp: ICRP: Error while connection session\n");
- l2tp_session_disconnect(sess, 2, 6);
+ log_session(log_error, sess, "impossible to handle ICRP:"
+ " connecting session failed,"
+ " disconnecting session\n");
+ if (l2tp_session_disconnect(sess, 2, 6) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
@@ -2037,13 +2406,22 @@ static int l2tp_recv_ICCN(struct l2tp_sess_t *sess,
sess->state1 = STATE_ESTB;
if (l2tp_session_connect(sess)) {
- if (l2tp_session_disconnect(sess, 2, 4) < 0)
+ log_session(log_error, sess, "impossible to handle ICCN:"
+ " connecting session failed,"
+ " disconnecting session\n");
+ if (l2tp_session_disconnect(sess, 2, 4) < 0) {
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
+ }
return 0;
}
- if (l2tp_send_ZLB(sess->paren_conn))
+ if (l2tp_send_ZLB(sess->paren_conn) < 0) {
+ log_session(log_error, sess, "impossible to handle ICCN:"
+ " sending ZLB failed\n");
return -1;
+ }
triton_timer_del(&sess->timeout_timer);
@@ -2055,21 +2433,25 @@ static void l2tp_session_outcall_reply(void *data)
struct l2tp_sess_t *sess = data;
if (l2tp_send_OCRP(sess) < 0) {
- log_ppp_error("l2tp: impossible to handle outgoing call:"
- " error while sending OCRP\n");
+ log_session(log_error, sess,
+ "impossible to reply to outgoing call:"
+ " sending OCRP failed, disconnecting session\n");
goto out_err;
}
if (l2tp_send_OCCN(sess) < 0) {
- log_ppp_error("l2tp: impossible to handle outgoing call:"
- " error while sending OCCN\n");
+ log_session(log_error, sess,
+ "impossible to reply to outgoing call:"
+ " sending OCCN failed, disconnecting session\n");
goto out_err;
}
sess->state1 = STATE_ESTB;
if (l2tp_session_connect(sess) < 0) {
- log_ppp_error("l2tp: impossible to handle outgoing call:"
- " error while connecting session\n");
+ log_session(log_error, sess,
+ "impossible to reply to outgoing call:"
+ " connecting session failed,"
+ " disconnecting session\n");
goto out_err;
}
@@ -2121,18 +2503,18 @@ static int l2tp_recv_OCRQ(struct l2tp_conn_t *conn,
if (attr->M)
unknown_attr = attr;
else {
- l2tp_conn_log(log_warn, conn);
- log_warn("l2tp: OCRQ: unknown attribute %i\n",
- attr->attr->id);
+ log_tunnel(log_warn, conn,
+ "discarding unknown attribute type"
+ " %i in OCRQ\n", attr->attr->id);
}
break;
}
}
if (assigned_sid == NULL) {
- l2tp_conn_log(log_error, conn);
- log_error("l2tp: OCRQ: missing mandatory AVP:"
- " Assigned Session ID\n");
+ log_tunnel(log_error, conn, "impossible to handle OCRQ:"
+ " no Assigned Session ID present in message,"
+ " disconnecting session\n");
res = 2;
err = 6;
goto out_cancel;
@@ -2171,7 +2553,10 @@ static int l2tp_recv_OCRQ(struct l2tp_conn_t *conn,
return 0;
out_cancel:
- l2tp_send_CDN(sess, res, err);
+ if (l2tp_send_CDN(sess, res, err) < 0)
+ log_tunnel(log_warn, conn,
+ "impossible to reject OCRQ:"
+ " sending CDN failed\n");
l2tp_tunnel_cancel_session(sess);
return -1;
}
@@ -2199,17 +2584,20 @@ static int l2tp_recv_OCRP(struct l2tp_sess_t *sess,
if (attr->M)
unknown_attr = attr;
else
- log_ppp_warn("l2tp: OCRP:"
- " unknown attribute %i\n",
- attr->attr->id);
+ log_session(log_warn, sess,
+ "discarding unknown attribute type"
+ " %i in OCRP\n", attr->attr->id);
break;
}
}
if (assigned_sid == NULL) {
- log_ppp_error("l2tp: OCRP: missing mandatory AVP:"
- " Assigned Session ID\n");
- l2tp_session_disconnect(sess, 2, 6);
+ log_session(log_error, sess, "impossible to handle OCRP:"
+ " no Assigned Session ID present in message,"
+ " disconnecting session\n");
+ if (l2tp_session_disconnect(sess, 2, 6) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
@@ -2218,9 +2606,13 @@ static int l2tp_recv_OCRP(struct l2tp_sess_t *sess,
sess->peer_sid = assigned_sid->val.uint16;
if (unknown_attr) {
- log_ppp_error("l2tp: OCRP: unknown mandatory attribute %i\n",
- unknown_attr->attr->id);
- l2tp_session_disconnect(sess, 2, 8);
+ log_session(log_error, sess, "impossible to handle OCRP:"
+ " unknown mandatory attribute type %i,"
+ " disconnecting session\n",
+ unknown_attr->attr->id);
+ if (l2tp_session_disconnect(sess, 2, 8) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
@@ -2252,29 +2644,41 @@ static int l2tp_recv_OCCN(struct l2tp_sess_t *sess,
if (attr->M)
unknown_attr = attr;
else
- log_ppp_warn("l2tp: OCCN:"
- " unknown attribute %i\n",
- attr->attr->id);
+ log_session(log_warn, sess,
+ "discarding unknown attribute type"
+ " %i in OCCN\n", attr->attr->id);
break;
}
}
if (unknown_attr) {
- log_ppp_error("l2tp: OCCN: unknown mandatory attribute %i\n",
- unknown_attr->attr->id);
- l2tp_session_disconnect(sess, 2, 8);
+ log_session(log_error, sess, "impossible to handle OCCN:"
+ " unknown mandatory attribute type %i,"
+ " disconnecting session\n",
+ unknown_attr->attr->id);
+ if (l2tp_session_disconnect(sess, 2, 8) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
sess->state1 = STATE_ESTB;
if (l2tp_session_connect(sess) < 0) {
- l2tp_session_disconnect(sess, 2, 4);
+ log_session(log_error, sess, "impossible to handle OCCN:"
+ " connecting session failed,"
+ " disconnecting session\n");
+ if (l2tp_session_disconnect(sess, 2, 4) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
return -1;
}
- if (l2tp_send_ZLB(sess->paren_conn) < 0)
+ if (l2tp_send_ZLB(sess->paren_conn) < 0) {
+ log_session(log_error, sess, "impossible to handle OCCN:"
+ " sending ZLB failed\n");
return -1;
+ }
return 0;
}
@@ -2302,7 +2706,8 @@ static int l2tp_recv_SLI(struct l2tp_conn_t *conn,
log_warn("l2tp: unexpected SLI\n");
}
- l2tp_send_ZLB(conn);
+ if (l2tp_send_ZLB(conn) < 0)
+ log_tunnel(log_error, conn, "acknowledging SLI failed\n");
return 0;
}
@@ -2337,20 +2742,20 @@ static void l2tp_tunnel_create_session(void *data)
struct l2tp_sess_t *sess = NULL;
if (conn->state != STATE_ESTB) {
- log_ppp_error("l2tp: impossible to place call:"
- " tunnel is not connected\n");
+ log_tunnel(log_error, conn, "impossible to create session:"
+ " tunnel is not connected\n");
return;
}
sess = l2tp_tunnel_alloc_session(conn);
if (sess == NULL) {
- log_ppp_error("l2tp: impossible to place call:"
- " no more session available\n");
+ log_tunnel(log_error, conn, "impossible to create session:"
+ " session allocation failed");
return;
}
if (l2tp_tunnel_confirm_session(sess) < 0) {
- log_ppp_error("l2tp: impossible to place call:"
- " session initialisation failed\n");
+ log_tunnel(log_error, conn, "impossible to create session:"
+ " starting session failed\n");
l2tp_tunnel_cancel_session(sess);
return;
}
@@ -2391,8 +2796,17 @@ static void l2tp_session_recv(void *data)
msg_type->val.uint16);
}
if (msg_type->M) {
- l2tp_session_disconnect(sess, 2, 8);
- }
+ log_session(log_error, sess,
+ "impossible to handle unknown message type"
+ " %i, disconnecting session\n",
+ msg_type->val.uint16);
+ if (l2tp_session_disconnect(sess, 2, 8) < 0)
+ log_session(log_error, sess,
+ "session disconnection failed\n");
+ } else
+ log_session(log_warn, sess,
+ "discarding unknown message type %i\n",
+ msg_type->val.uint16);
break;
}
@@ -2424,15 +2838,18 @@ static int l2tp_conn_read(struct triton_md_handler_t *h)
destination port for further outgoing messages */
res = l2tp_tunnel_update_peerport(conn,
pack->addr.sin_port);
- if (res < 0)
+ if (res < 0) {
+ log_tunnel(log_error, conn,
+ "peer port update failed,"
+ " closing tunnel\n");
goto drop;
+ }
}
if (ntohs(pack->hdr.tid) != conn->tid && (pack->hdr.tid || !conf_dir300_quirk)) {
- if (conf_verbose) {
- l2tp_conn_log(log_warn, conn);
- log_warn("incorrect tid %i in tunnel %i\n", ntohs(pack->hdr.tid), conn->tid);
- }
+ log_tunnel(log_warn, conn,
+ "discarding message with invalid tid %hu\n",
+ ntohs(pack->hdr.tid));
l2tp_packet_free(pack);
continue;
}
@@ -2545,7 +2962,12 @@ static int l2tp_conn_read(struct triton_md_handler_t *h)
sess = l2tp_tunnel_get_session(conn, ntohs(pack->hdr.sid));
if (sess == NULL)
goto drop;
- triton_context_call(&sess->sctx, l2tp_session_recv, pack);
+ if (triton_context_call(&sess->sctx, l2tp_session_recv, pack) < 0) {
+ log_tunnel(log_warn, conn,
+ "impossible to handle message for session %hu:"
+ " call to child session failed\n",
+ sess->sid);
+ }
continue;
case Message_Type_Set_Link_Info:
if (l2tp_recv_SLI(conn, pack))
@@ -2580,6 +3002,7 @@ static int l2tp_udp_read(struct triton_md_handler_t *h)
struct l2tp_packet_t *pack;
const struct l2tp_attr_t *msg_type;
struct in_pktinfo pkt_info;
+ char src_addr[17];
while (1) {
if (l2tp_recv(h->fd, &pack, &pkt_info))
@@ -2588,24 +3011,33 @@ static int l2tp_udp_read(struct triton_md_handler_t *h)
if (!pack)
continue;
+ u_inet_ntoa(pack->addr.sin_addr.s_addr, src_addr);
+
if (iprange_client_check(pack->addr.sin_addr.s_addr)) {
- log_warn("l2tp: IP is out of client-ip-range, droping connection...\n");
+ log_warn("l2tp: discarding unexpected message from %s:"
+ " IP address is out of client-ip-range\n",
+ src_addr);
goto skip;
}
- if (pack->hdr.tid)
+ if (pack->hdr.tid) {
+ log_warn("l2tp: discarding unexpected message from %s:"
+ " invalid tid %hu\n",
+ src_addr, ntohs(pack->hdr.tid));
goto skip;
+ }
if (list_empty(&pack->attrs)) {
- if (conf_verbose)
- log_warn("l2tp: to Message-Type attribute present\n");
+ log_warn("l2tp: discarding unexpected message from %s:"
+ " message is empty\n", src_addr);
goto skip;
}
msg_type = list_entry(pack->attrs.next, typeof(*msg_type), entry);
if (msg_type->attr->id != Message_Type) {
- if (conf_verbose)
- log_warn("l2tp: first attribute is not Message-Type\n");
+ log_warn("l2tp: discarding unexpected message from %s:"
+ " invalid first attribute type %i\n",
+ src_addr, msg_type->attr->id);
goto skip;
}
@@ -2616,6 +3048,9 @@ static int l2tp_udp_read(struct triton_md_handler_t *h)
log_warn("recv (unexpected) ");
l2tp_packet_print(pack, log_ppp_warn);
}
+ log_warn("l2tp: discarding unexpected message from %s:"
+ " invalid Message Type %i\n",
+ src_addr, msg_type->val.uint16);
}
skip:
l2tp_packet_free(pack);
@@ -2653,7 +3088,8 @@ static void start_udp_server(void)
udp_serv.hnd.fd = socket(PF_INET, SOCK_DGRAM, 0);
if (udp_serv.hnd.fd < 0) {
- log_emerg("l2tp: socket: %s\n", strerror(errno));
+ log_error("l2tp: impossible to start L2TP server:"
+ " socket(PF_INET) failed: %s\n", strerror(errno));
return;
}
@@ -2692,9 +3128,15 @@ static void start_udp_server(void)
memcpy(&udp_serv.addr, &addr, sizeof(addr));
- triton_context_register(&udp_serv.ctx, NULL);
+ if (triton_context_register(&udp_serv.ctx, NULL) < 0) {
+ log_error("l2tp: impossible to start L2TP server:"
+ " context registration failed\n");
+ }
triton_md_register_handler(&udp_serv.ctx, &udp_serv.hnd);
- triton_md_enable_handler(&udp_serv.hnd, MD_MODE_READ);
+ if (triton_md_enable_handler(&udp_serv.hnd, MD_MODE_READ) < 0) {
+ log_error("l2tp: impossible to start L2TP server:"
+ " enabling handler failed\n");
+ }
triton_context_wakeup(&udp_serv.ctx);
}
@@ -2907,7 +3349,10 @@ static void l2tp_init(void)
l2tp_create_session_help, 3,
"l2tp", "create", "session");
- triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
+ if (triton_event_register_handler(EV_CONFIG_RELOAD,
+ (triton_event_func)load_config) < 0)
+ log_warn("l2tp: registration of CONFIG_RELOAD event failed,"
+ " configuration reloading deactivated\n");
}
DEFINE_INIT(22, l2tp_init);