Skip to content

Commit

Permalink
L2TP fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Mar 1, 2024
1 parent ac7a321 commit 7e65668
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 54 deletions.
108 changes: 58 additions & 50 deletions code/bngblaster/src/bbl_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,62 @@ bbl_access_rx_ipv6(bbl_access_interface_s *interface,
session->stats.accounting_bytes_rx += eth->length;
}

static void
bbl_access_l2tp_stream_force_verfied(bbl_session_s *session, bbl_stream_s *stream)
{
if(stream && stream->verified == false) {
stream->verified = true;
session->session_traffic.flows_verified++;
g_ctx->stats.session_traffic_flows_verified++;
if(g_ctx->stats.session_traffic_flows_verified == g_ctx->stats.session_traffic_flows) {
LOG_NOARG(INFO, "ALL SESSION TRAFFIC FLOWS VERIFIED\n");
}
}
}

static void
bbl_access_l2tp(bbl_session_s *session, char *reply_message, uint8_t reply_message_len)
{
l2tp_key_t key = {0};
void **search = NULL;

char substring[16] = {0};
char *tok;
char *save = NULL;

if(!((reply_message_len > 23) &&
(strncmp(reply_message, L2TP_REPLY_MESSAGE, 20) == 0))) {
return;
}

session->l2tp = true;
memcpy(substring, reply_message+21, reply_message_len-21);
tok = strtok_r(substring, ":", &save);
if(tok) {
key.tunnel_id = atoi(tok);
tok = strtok_r(0, ":", &save);
if(tok) {
key.session_id = atoi(tok);
search = dict_search(g_ctx->l2tp_session_dict, &key);
if(search) {
session->l2tp_session = *search;
session->l2tp_session->pppoe_session = session;
LOG(L2TP, "L2TP (ID: %u) Tunnelled session with BNG Blaster LNS (%d:%d)\n",
session->session_id, session->l2tp_session->key.tunnel_id, session->l2tp_session->key.session_id);
/* Currently we do not support IPv6 session traffic for L2TP sessions,
* therefore if created, we mark them as verified. */
bbl_access_l2tp_stream_force_verfied(session, session->session_traffic.ipv6_up);
bbl_access_l2tp_stream_force_verfied(session, session->session_traffic.ipv6_down);
bbl_access_l2tp_stream_force_verfied(session, session->session_traffic.ipv6pd_up);
bbl_access_l2tp_stream_force_verfied(session, session->session_traffic.ipv6pd_down);
return;
}
}
}
LOG(ERROR, "L2TP (ID: %u) Failed to get BNG Blaster LNS session\n", session->session_id);
return;
}

static void
bbl_access_rx_pap(bbl_access_interface_s *interface,
bbl_session_s *session,
Expand All @@ -716,13 +772,6 @@ bbl_access_rx_pap(bbl_access_interface_s *interface,
bbl_pppoe_session_s *pppoes;
bbl_pap_s *pap;

char substring[16];
char *tok;
char *save = NULL;

l2tp_key_t key = {0};
void **search = NULL;

pppoes = (bbl_pppoe_session_s*)eth->next;
pap = (bbl_pap_s*)pppoes->next;

Expand All @@ -733,24 +782,7 @@ bbl_access_rx_pap(bbl_access_interface_s *interface,
case PAP_CODE_ACK:
if(pap->reply_message_len > 23) {
if(strncmp(pap->reply_message, L2TP_REPLY_MESSAGE, 20) == 0) {
session->l2tp = true;
memset(substring, 0x0, sizeof(substring));
memcpy(substring, pap->reply_message+21, pap->reply_message_len-21);
tok = strtok_r(substring, ":", &save);
if(tok) {
key.tunnel_id = atoi(tok);
tok = strtok_r(0, ":", &save);
if(tok) {
key.session_id = atoi(tok);
search = dict_search(g_ctx->l2tp_session_dict, &key);
if(search) {
session->l2tp_session = *search;
session->l2tp_session->pppoe_session = session;
LOG(L2TP, "L2TP (ID: %u) Tunnelled session with BNG Blaster LNS (%d:%d)\n",
session->session_id, session->l2tp_session->key.tunnel_id, session->l2tp_session->key.session_id);
}
}
}
bbl_access_l2tp(session, pap->reply_message, pap->reply_message_len);
}
}
if(pap->reply_message_len) {
Expand Down Expand Up @@ -798,13 +830,6 @@ bbl_access_rx_chap(bbl_access_interface_s *interface,

MD5_CTX md5_ctx;

char substring[16];
char *tok;
char *save = NULL;

l2tp_key_t key = {0};
void **search = NULL;

UNUSED(interface);

pppoes = (bbl_pppoe_session_s*)eth->next;
Expand Down Expand Up @@ -836,24 +861,7 @@ bbl_access_rx_chap(bbl_access_interface_s *interface,
case CHAP_CODE_SUCCESS:
if(chap->reply_message_len > 23) {
if(strncmp(chap->reply_message, L2TP_REPLY_MESSAGE, 20) == 0) {
session->l2tp = true;
memset(substring, 0x0, sizeof(substring));
memcpy(substring, chap->reply_message+21, chap->reply_message_len-21);
tok = strtok_r(substring, ":", &save);
if(tok) {
key.tunnel_id = atoi(tok);
tok = strtok_r(0, ":", &save);
if(tok) {
key.session_id = atoi(tok);
search = dict_search(g_ctx->l2tp_session_dict, &key);
if(search) {
session->l2tp_session = *search;
session->l2tp_session->pppoe_session = session;
LOG(L2TP, "L2TP (ID: %u) Tunnelled session with BNG Blaster LNS (%d:%d)\n",
session->session_id, session->l2tp_session->key.tunnel_id, session->l2tp_session->key.session_id);
}
}
}
bbl_access_l2tp(session, chap->reply_message, chap->reply_message_len);
}
}
if(chap->reply_message_len) {
Expand Down
5 changes: 4 additions & 1 deletion code/bngblaster/src/bbl_l2tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ bbl_l2tp_sccrq_rx(bbl_network_interface_s *interface, bbl_ethernet_header_s *eth
CIRCLEQ_FOREACH(l2tp_tunnel2, &l2tp_server->tunnel_qhead, tunnel_qnode) {
if(l2tp_tunnel2->peer_ip == l2tp_tunnel->peer_ip &&
l2tp_tunnel2->peer_tunnel_id == l2tp_tunnel->peer_tunnel_id) {
if(l2tp_tunnel2->state == BBL_L2TP_TUNNEL_RCVD_STOPCCN) {
bbl_l2tp_tunnel_update_state(l2tp_tunnel2, BBL_L2TP_TUNNEL_TERMINATED);
}
/* Seems to be an SCCRQ retry ... */
bbl_l2tp_tunnel_delete(l2tp_tunnel);
return;
Expand Down Expand Up @@ -1222,7 +1225,7 @@ bbl_l2tp_stop_all_tunnel()
}
}

static json_t *
json_t *
l2tp_session_json(bbl_l2tp_session_s *l2tp_session)
{
char *proxy_auth_response = NULL;
Expand Down
3 changes: 3 additions & 0 deletions code/bngblaster/src/bbl_l2tp.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ bbl_l2tp_handler_rx(bbl_network_interface_s *interface, bbl_ethernet_header_s *e
void
bbl_l2tp_stop_all_tunnel();

json_t *
l2tp_session_json(bbl_l2tp_session_s *l2tp_session);

int
bbl_l2tp_ctrl_sessions(int fd, uint32_t session_id __attribute__((unused)), json_t *arguments);

Expand Down
17 changes: 14 additions & 3 deletions code/bngblaster/src/bbl_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ bbl_session_reset(bbl_session_s *session) {

/* L2TP */
session->l2tp = false;
if(session->l2tp_session &&
session->l2tp_session->pppoe_session == session) {
session->l2tp_session->pppoe_session = NULL;
}
session->l2tp_session = NULL;

/* Session traffic */
Expand Down Expand Up @@ -1129,6 +1133,7 @@ bbl_session_json(bbl_session_s *session)
json_t *root = NULL;
json_t *session_traffic = NULL;
json_t *a10nsp_session = NULL;
json_t *l2tp_session = NULL;

bbl_stream_s *stream;

Expand Down Expand Up @@ -1266,13 +1271,17 @@ bbl_session_json(bbl_session_s *session)
"tx-packets", session->a10nsp_session->stats.packets_tx,
"rx-packets", session->a10nsp_session->stats.packets_rx);
}
if(session->l2tp_session) {
l2tp_session = l2tp_session_json(session->l2tp_session);
}

if(session->access_type == ACCESS_TYPE_PPPOE) {
root = json_pack("{ss si ss ss* si ss si si ss ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* sI sI si sI sI sI sI sI sI si si si si si si si si so* so*}",
root = json_pack("{ss si ss ss* si si ss si si ss ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* sI sI si sI sI sI sI sI sI si si si si si si si si so* so* so*}",
"type", "pppoe",
"session-id", session->session_id,
"session-state", session_state_string(session->session_state),
"session-substate", bbl_session_substate_pppoe(session),
"session-version", session->version,
"flapped", session->stats.flapped,
"interface", session->access_interface->name,
"outer-vlan", session->vlan_key.outer_vlan_id,
Expand Down Expand Up @@ -1314,7 +1323,8 @@ bbl_session_json(bbl_session_s *session)
"tx-icmpv6", session->stats.icmpv6_tx,
"rx-icmpv6", session->stats.icmpv6_rx,
"session-traffic", session_traffic,
"a10nsp", a10nsp_session);
"a10nsp", a10nsp_session,
"l2tp", l2tp_session);

} else {
clock_gettime(CLOCK_MONOTONIC, &now);
Expand All @@ -1332,11 +1342,12 @@ bbl_session_json(bbl_session_s *session)
if(seconds <= session->dhcpv6_t1) dhcpv6_lease_expire_t1 = session->dhcpv6_t1 - seconds;
if(seconds <= session->dhcpv6_t2) dhcpv6_lease_expire_t2 = session->dhcpv6_t2 - seconds;

root = json_pack("{ss si ss ss* si ss si si ss ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* si si si si si si si si si si si si ss* si si si si si si si si si si si si ss* ss* sI sI si sI sI sI sI sI sI si si si si si si si si so* so*}",
root = json_pack("{ss si ss ss* si si ss si si ss ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* ss* si si si si si si si si si si si si ss* si si si si si si si si si si si si ss* ss* sI sI si sI sI sI sI sI sI si si si si si si si si so* so*}",
"type", "ipoe",
"session-id", session->session_id,
"session-state", session_state_string(session->session_state),
"session-substate", bbl_session_substate_ipoe(session),
"session-version", session->version,
"flapped", session->stats.flapped,
"interface", session->access_interface->name,
"outer-vlan", session->vlan_key.outer_vlan_id,
Expand Down
1 change: 1 addition & 0 deletions code/bngblaster/src/bbl_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,7 @@ bbl_stream_json(bbl_stream_s *stream)
}
if(stream->session) {
json_object_set(root, "session-id", json_integer(stream->session->session_id));
json_object_set(root, "session-version", json_integer(stream->session_version));
json_object_set(root, "session-traffic", json_boolean(stream->session_traffic));
}
if(stream->reverse) {
Expand Down

0 comments on commit 7e65668

Please sign in to comment.