diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-02-11 21:02:17 +0100 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2013-02-12 00:12:48 +0400 |
commit | ce807c0f2e045fb936cbf71b4d2a6d98ed12519e (patch) | |
tree | f5dafed70eb6bd3753bda6cdc80ef9f976648987 /accel-pppd/ctrl | |
parent | a8a83b316ee3b6717a6df35ca6d0f14a3963524b (diff) | |
download | accel-ppp-xebd-ce807c0f2e045fb936cbf71b4d2a6d98ed12519e.tar.gz accel-ppp-xebd-ce807c0f2e045fb936cbf71b4d2a6d98ed12519e.zip |
l2tp: Define function to compute Challenge Response
Create the l2tp_tunnel_genchallresp() function for building and
adding the Challenge Response AVP to messages that need it.
Support for this AVP is needed for sending SCCRP and SCCCN messages.
This patch replaces the previous Challenge Response computation by
calling the new function and prepares implementation of SCCCN message
sending.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/ctrl')
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index a3e829e..e20d843 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -226,6 +226,36 @@ err: return -1; } +static int l2tp_tunnel_genchallresp(uint8_t msgident, + const struct l2tp_conn_t *conn, + struct l2tp_packet_t *pack) +{ + uint8_t challresp[MD5_DIGEST_LENGTH]; + + 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"); + } + 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"); + 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) + return -1; + + return 0; +} + static int l2tp_send_StopCCN(struct l2tp_conn_t *conn, uint16_t res, uint16_t err) { @@ -1001,7 +1031,6 @@ static void l2tp_send_HELLO(struct triton_timer_t *t) static void l2tp_send_SCCRP(struct l2tp_conn_t *conn) { struct l2tp_packet_t *pack; - uint8_t chall_resp[MD5_DIGEST_LENGTH]; pack = l2tp_packet_alloc(2, Message_Type_Start_Ctrl_Conn_Reply, &conn->lac_addr); if (!pack) @@ -1017,17 +1046,10 @@ static void l2tp_send_SCCRP(struct l2tp_conn_t *conn) goto out_err; if (l2tp_packet_add_string(pack, Vendor_Name, "accel-ppp", 0)) goto out_err; - /* If challenge response available */ - if (conn->challenge_len && conn->challenge) { - if (conf_secret == NULL || strlen(conf_secret) == 0) - goto out_err; - comp_chap_md5(chall_resp, Message_Type_Start_Ctrl_Conn_Reply, - conf_secret, strlen(conf_secret), - conn->challenge, conn->challenge_len); - if (l2tp_packet_add_octets(pack, Challenge_Response, - chall_resp, MD5_DIGEST_LENGTH, 1)) - goto out_err; - } + + if (l2tp_tunnel_genchallresp(Message_Type_Start_Ctrl_Conn_Reply, + conn, pack) < 0) + goto out_err; if (l2tp_send(conn, pack, 0)) goto out; |