Skip to content

Commit

Permalink
rework ppp config request
Browse files Browse the repository at this point in the history
  • Loading branch information
w180112 committed Nov 11, 2023
1 parent 19bb3af commit 4a313ec
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 58 deletions.
7 changes: 3 additions & 4 deletions src/pppd/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/pppd/pppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; j<TOTAL_SOCK_PORT; j++) {
rte_atomic16_init(&ppp_ccb[i].addr_table[j].is_alive);
rte_atomic16_init(&ppp_ccb[i].addr_table[j].is_fill);
Expand Down
2 changes: 1 addition & 1 deletion src/pppd/pppd.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct {
U32 hsi_primary_dns;/* 1st dns addr pppoe server assign to pppoe client */
U32 hsi_second_dns; /* 2nd dns addr pppoe server assign to pppoe client */
U8 identifier; /* ppp pkt id */
U32 magic_num; /* ppp pkt magic number */
U32 magic_num; /* ppp pkt magic number, in network order */
BOOL is_pap_auth; /* pap auth boolean flag */
U16 auth_method; /* use chap or pap */
unsigned char *ppp_user_id; /* pap/chap account */
Expand Down
99 changes: 50 additions & 49 deletions unit_test/pppd/codec_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,58 +123,59 @@ void test_build_config_request() {
U8 buffer[80];
U16 mulen = 0;

PPP_INFO_t s_ppp_ccb_1 = {
.ppp_phase = {{
.timer_counter = 0,
.max_retransmit = 10,
},{
.timer_counter = 0,
.max_retransmit = 10,
},},
.user_num = 1,
.vlan = 2,
.PPP_dst_mac = (struct rte_ether_addr){
.addr_bytes = {0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31},
PPP_INFO_t s_ppp_ccb[] = {
{
.ppp_phase = {{
.timer_counter = 0,
.max_retransmit = 10,
},{
.timer_counter = 0,
.max_retransmit = 10,
},},
.user_num = 1,
.vlan = 2,
.PPP_dst_mac = (struct rte_ether_addr){
.addr_bytes = {0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31},
},
.session_id = htons(0x000a),
.cp = 0,
.magic_num = htonl(0x01020304),
.identifier = 0xfd,
.hsi_ipv4 = 0x0,
},
.session_id = htons(0x000a),
.cp = 0,
.magic_num = htonl(0x01020304),
};

char pkt_lcp[] = {0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31, 0x9c, 0x69, 0xb4, 0x61,
0x16, 0xdd, 0x81, 0x00, 0x00, 0x02, 0x88, 0x64, 0x11, 0x00, 0x00, 0x0a, 0x00,
0x10, 0xc0, 0x21, 0x01, 0x01, 0x00, 0x0e, 0x01, 0x04, 0x05, 0xd0, 0x05, 0x06,
0x01, 0x02, 0x03, 0x04};
char pkt_ipcp[] = {0x74, 0x4d, 0x28, 0x8d, 0x00, 0x31, 0x9c, 0x69, 0xb4, 0x61,
0x16, 0xdd, 0x81, 0x00, 0x00, 0x02, 0x88, 0x64, 0x11, 0x00, 0x00, 0x0a, 0x00,
0x0c, 0x80, 0x21, 0x01, 0x01, 0x00, 0x0a, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00};

/* test LCP */
build_config_request(buffer, &mulen, &s_ppp_ccb_1);
assert(mulen == sizeof(pkt_lcp));
assert(memcmp(buffer, pkt_lcp, 26/* only memcmp to lcp field */) == 0);
ppp_header_t *test_ppp_hdr = (ppp_header_t *)(buffer + 26);
assert(test_ppp_hdr->code == 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<sizeof(s_ppp_ccb)/sizeof(s_ppp_ccb[0]); i++) {
/* test LCP */
build_config_request(buffer, &mulen, &s_ppp_ccb[0]);
assert(mulen == sizeof(pkt_lcp));
assert(memcmp(buffer, pkt_lcp, sizeof(pkt_lcp)) == 0);
/* test IPCP */
s_ppp_ccb[0].cp = 1;
memset(buffer, 0, sizeof(buffer));
build_config_request(buffer, &mulen, &s_ppp_ccb[0]);
assert(mulen == sizeof(pkt_ipcp_1));
assert(memcmp(buffer, pkt_ipcp_1, sizeof(pkt_ipcp_1)) == 0);
s_ppp_ccb[0].hsi_ipv4 = htonl(0xc0a8c801);
memset(buffer, 0, sizeof(buffer));
build_config_request(buffer, &mulen, &s_ppp_ccb[0]);
assert(mulen == sizeof(pkt_ipcp_2));
assert(memcmp(buffer, pkt_ipcp_2, sizeof(pkt_ipcp_2)) == 0);
}
}

void test_build_config_ack() {
Expand Down

0 comments on commit 4a313ec

Please sign in to comment.