From 39fd6b4bc20534fc8641abbea6e021bd2d2cda02 Mon Sep 17 00:00:00 2001 From: Christian Giese Date: Fri, 4 Nov 2022 16:15:01 +0000 Subject: [PATCH] add config l2tp-server->lcp-padding This config options allows to add a fixed padding to all LCP packets send from emulated LNS. --- code/bngblaster/src/bbl_config.c | 4 ++++ code/bngblaster/src/bbl_l2tp.c | 15 +++++++-------- code/bngblaster/src/bbl_l2tp.h | 1 + code/bngblaster/src/bbl_protocols.c | 5 ++++- code/bngblaster/src/bbl_protocols.h | 1 + docsrc/sources/configuration/lns.rst | 3 +++ 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/code/bngblaster/src/bbl_config.c b/code/bngblaster/src/bbl_config.c index 77e2cf45..d9fb5db9 100644 --- a/code/bngblaster/src/bbl_config.c +++ b/code/bngblaster/src/bbl_config.c @@ -2544,6 +2544,10 @@ json_parse_config(json_t *root) } else { l2tp_server->hello_interval = 30; } + value = json_object_get(sub, "lcp-padding"); + if(json_is_number(value)) { + l2tp_server->lcp_padding = json_number_value(value);; + } } } else if(json_is_object(section)) { fprintf(stderr, "JSON config error: List expected in L2TP server configuration but dictionary found\n"); diff --git a/code/bngblaster/src/bbl_l2tp.c b/code/bngblaster/src/bbl_l2tp.c index 68c90bec..0f011eef 100644 --- a/code/bngblaster/src/bbl_l2tp.c +++ b/code/bngblaster/src/bbl_l2tp.c @@ -904,21 +904,20 @@ bbl_l2tp_data_rx(bbl_network_interface_s *interface, } l2tp_session->stats.data_rx++; - switch (l2tp->protocol) { + switch(l2tp->protocol) { case PROTOCOL_LCP: lcp_rx = (bbl_lcp_s*)l2tp->next; - if(lcp_rx->code == PPP_CODE_TERM_REQUEST) { + lcp_rx->padding = l2tp_session->tunnel->server->lcp_padding; + if(lcp_rx->code == PPP_CODE_ECHO_REQUEST) { + lcp_rx->code = PPP_CODE_ECHO_REPLY; + bbl_l2tp_send_data(l2tp_session, PROTOCOL_LCP, lcp_rx); + } else if(lcp_rx->code == PPP_CODE_TERM_REQUEST) { l2tp_session->disconnect_code = 3; l2tp_session->disconnect_protocol = 0; l2tp_session->disconnect_direction = 1; bbl_l2tp_send(l2tp_session->tunnel, l2tp_session, L2TP_MESSAGE_CDN); bbl_l2tp_session_delete(l2tp_session); - return; - } - if(lcp_rx->code == PPP_CODE_ECHO_REQUEST) { - lcp_rx->code = PPP_CODE_ECHO_REPLY; - bbl_l2tp_send_data(l2tp_session, PROTOCOL_LCP, lcp_rx); - } + } break; case PROTOCOL_PAP: memset(&pap_tx, 0x0, sizeof(bbl_pap_s)); diff --git a/code/bngblaster/src/bbl_l2tp.h b/code/bngblaster/src/bbl_l2tp.h index 75565f1f..55ad9c87 100644 --- a/code/bngblaster/src/bbl_l2tp.h +++ b/code/bngblaster/src/bbl_l2tp.h @@ -67,6 +67,7 @@ typedef struct bbl_l2tp_server_ uint16_t session_limit; uint16_t receive_window; uint16_t max_retry; + uint16_t lcp_padding; bool data_control_priority; bool data_length; diff --git a/code/bngblaster/src/bbl_protocols.c b/code/bngblaster/src/bbl_protocols.c index 5906a9ab..96d961e3 100644 --- a/code/bngblaster/src/bbl_protocols.c +++ b/code/bngblaster/src/bbl_protocols.c @@ -1206,7 +1206,7 @@ encode_ppp_lcp(uint8_t *buf, uint16_t *len, lcp_len = lcp->options_len + 4; *lcp_len_field = htobe16(lcp_len); } else { - /* Constuct options ... */ + /* Options ... */ lcp_len = 4; if(lcp->mru) { *buf = PPP_LCP_OPTION_MRU; @@ -1238,6 +1238,9 @@ encode_ppp_lcp(uint8_t *buf, uint16_t *len, *lcp_len_field = htobe16(lcp_len); } } + if(lcp->padding) { + BUMP_WRITE_BUFFER(buf, len, lcp->padding); + } return PROTOCOL_SUCCESS; } diff --git a/code/bngblaster/src/bbl_protocols.h b/code/bngblaster/src/bbl_protocols.h index 485bb29e..0aaff8b2 100644 --- a/code/bngblaster/src/bbl_protocols.h +++ b/code/bngblaster/src/bbl_protocols.h @@ -634,6 +634,7 @@ typedef struct bbl_lcp_ { uint16_t vendor_value_len; uint8_t *start; uint16_t len; + uint16_t padding; uint8_t *option[PPP_MAX_OPTIONS]; bool unknown_options; } bbl_lcp_s; diff --git a/docsrc/sources/configuration/lns.rst b/docsrc/sources/configuration/lns.rst index 7599e6e4..cd1281f5 100644 --- a/docsrc/sources/configuration/lns.rst +++ b/docsrc/sources/configuration/lns.rst @@ -46,6 +46,9 @@ * - `data-control-tos` - Set the L2TP tunnel TOS priority (outer IPv4 header) for all non-IP data packets (LCP, IPCP, ...) - 0 + * - `lcp-padding` + - Add fixed padding to LCP packets send from LNS + - 0 The BNG Blaster supports different congestion modes for the reliable delivery of control messages. The ``default`` mode