From 4a313ec8f931164e0151afdc540c2b2403fb30f8 Mon Sep 17 00:00:00 2001 From: the Date: Sat, 11 Nov 2023 15:31:10 +0800 Subject: [PATCH] rework ppp config request --- src/pppd/codec.c | 7 ++- src/pppd/pppd.c | 9 ++-- src/pppd/pppd.h | 2 +- unit_test/pppd/codec_test.c | 99 +++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 58 deletions(-) diff --git a/src/pppd/codec.c b/src/pppd/codec.c index bf70d5a..53ee311 100644 --- a/src/pppd/codec.c +++ b/src/pppd/codec.c @@ -685,9 +685,8 @@ void build_config_request(U8 *buffer, U16 *mulen, PPP_INFO_t *s_ppp_ccb) pppoe_header->session_id = s_ppp_ccb->session_id; ppp_hdr->code = CONFIG_REQUEST; - ppp_hdr->identifier = ((rand() % 254) + 1); - - s_ppp_ccb->identifier = ppp_hdr->identifier; + s_ppp_ccb->identifier = (s_ppp_ccb->identifier % UINT8_MAX) + 1; + ppp_hdr->identifier = s_ppp_ccb->identifier; pppoe_header->length = sizeof(ppp_header_t) + sizeof(ppp_payload->ppp_protocol); ppp_hdr->length = sizeof(ppp_header_t); @@ -739,7 +738,7 @@ void build_config_request(U8 *buffer, U16 *mulen, PPP_INFO_t *s_ppp_ccb) /* options, magic number */ cur->type = MAGIC_NUM; cur->length = 0x6; - rte_memcpy(cur->val, &(s_ppp_ccb->magic_num), sizeof(U32)); + *(U32 *)(cur->val) = s_ppp_ccb->magic_num; pppoe_header->length += 6; ppp_hdr->length += 6; } diff --git a/src/pppd/pppd.c b/src/pppd/pppd.c index 4aa0547..b14198f 100644 --- a/src/pppd/pppd.c +++ b/src/pppd/pppd.c @@ -150,14 +150,15 @@ STATUS pppdInit(void *ccb) /* vlan of each subscriptor is adding the base_vlan value in vRG_setup file to i */ ppp_ccb[i].vlan = i + vrg_ccb->base_vlan; - ppp_ccb[i].hsi_ipv4 = 0; - ppp_ccb[i].hsi_ipv4_gw = 0; - ppp_ccb[i].hsi_primary_dns = 0; - ppp_ccb[i].hsi_second_dns = 0; + ppp_ccb[i].hsi_ipv4 = 0x0; + ppp_ccb[i].hsi_ipv4_gw = 0x0; + ppp_ccb[i].hsi_primary_dns = 0x0; + ppp_ccb[i].hsi_second_dns = 0x0; ppp_ccb[i].phase = END_PHASE; ppp_ccb[i].is_pap_auth = FALSE; ppp_ccb[i].auth_method = CHAP_PROTOCOL; ppp_ccb[i].magic_num = rte_cpu_to_be_32((rand() % 0xFFFFFFFE) + 1); + ppp_ccb[i].identifier = 0x0; for(int j=0; jcode == CONFIG_REQUEST); - assert(test_ppp_hdr->length == htons(0x000e)); - ppp_options_t *test_ppp_options = (ppp_options_t *)(test_ppp_hdr + 1); - assert(test_ppp_options->type == MRU); - assert(test_ppp_options->length == 0x04); - test_ppp_options = (ppp_options_t *)((U8 *)test_ppp_options + test_ppp_options->length); - assert(test_ppp_options->type == MAGIC_NUM); - assert(test_ppp_options->length == 0x06); - - /* test IPCP */ - memset(buffer, 0, sizeof(buffer)); - s_ppp_ccb_1.cp = 1; - build_config_request(buffer, &mulen, &s_ppp_ccb_1); - assert(mulen == sizeof(pkt_ipcp)); - assert(memcmp(buffer, pkt_ipcp, 26/* only memcmp to ipcp field */) == 0); - test_ppp_hdr = (ppp_header_t *)(buffer + 26); - assert(test_ppp_hdr->code == CONFIG_REQUEST); - assert(test_ppp_hdr->length == htons(0x000a)); - test_ppp_options = (ppp_options_t *)(test_ppp_hdr + 1); - assert(test_ppp_options->type == IP_ADDRESS); - assert(test_ppp_options->length == 0x06); + U8 pkt_lcp[] = {/* mac */0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31, 0x9c, 0x69, 0xb4, + 0x61, 0x16, 0xdd, 0x81, 0x00, /* vlan */0x00, 0x02, 0x88, 0x64, /* pppoe hdr */ + 0x11, 0x00, 0x00, 0x0a, 0x00, 0x10, /* ppp protocol */0xc0, 0x21, /* ppp hdr */ + 0x01, 0xfe, 0x00, 0x0e, /* ppp option */0x01, 0x04, 0x05, 0xd0, 0x05, 0x06, 0x01, + 0x02, 0x03, 0x04}; + U8 pkt_ipcp_1[] = {/* mac */0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31, 0x9c, 0x69, 0xb4, + 0x61, 0x16, 0xdd, 0x81, 0x00, /* vlan */0x00, 0x02, 0x88, 0x64, /* pppoe hdr */ + 0x11, 0x00, 0x00, 0x0a, 0x00, 0x0c, /* ppp protocol */0x80, 0x21, /* ppp hdr */ + 0x01, 0xff, 0x00, 0x0a, /* ppp option */0x03, 0x06, 0x00, 0x00, 0x00, 0x00}; + U8 pkt_ipcp_2[] = {/* mac */0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31, 0x9c, 0x69, 0xb4, + 0x61, 0x16, 0xdd, 0x81, 0x00, /* vlan */0x00, 0x02, 0x88, 0x64, /* pppoe hdr */ + 0x11, 0x00, 0x00, 0x0a, 0x00, 0x0c, /* ppp protocol */0x80, 0x21, /* ppp hdr */ + 0x01, 0x01, 0x00, 0x0a, /* ppp option */0x03, 0x06, 0xc0, 0xa8, 0xc8, 0x01}; + + for(int i=0; i