Skip to content

Commit

Permalink
ppp: fix LCP packet building
Browse files Browse the repository at this point in the history
  • Loading branch information
acassen committed Feb 7, 2024
1 parent dc4b1f2 commit 9024fc0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
44 changes: 30 additions & 14 deletions src/gtp_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,32 +336,47 @@ sppp_cp_send(sppp_t *sp, uint16_t proto, uint8_t type,
{
spppoe_t *s = sp->s_pppoe;
gtp_pppoe_t *pppoe = s->pppoe;
lcp_hdr_t *lcp;
lcp_hdr_t *lh;
uint8_t *p;
pkt_t *pkt;
int plen;

/* get ethernet pkt buffer */
pkt = pppoe_eth_pkt_get(s, &s->hw_dst);
pkt = pppoe_eth_pkt_get(s, &s->hw_dst, ETH_P_PPP_SES);

/* fill in pkt*/
lcp = (lcp_hdr_t *) pkt->pbuff->data;
lcp->type = type;
lcp->ident = ident;
lcp->len = htons(LCP_HEADER_LEN + len);
/* PPPoE header*/
p = pkt->pbuff->data;
plen = sizeof(uint16_t) + sizeof(lcp_hdr_t) + len;
PPPOE_ADD_HEADER(p, PPPOE_CODE_SESSION, s->session_id, plen);
pkt_buffer_put_data(pkt->pbuff, sizeof(pppoe_hdr_t));

/* PPP LCP TAG */
p = pkt->pbuff->data;
PPPOE_ADD_16(p, PPP_LCP);
pkt_buffer_put_data(pkt->pbuff, sizeof(uint16_t));

/* LCP header */
lh = (lcp_hdr_t *) pkt->pbuff->data;
lh->type = type;
lh->ident = ident;
lh->len = htons(LCP_HEADER_LEN + len);
if (len)
bcopy(data, lcp+1, len);
bcopy(data, lh+1, len);
pkt_buffer_put_data(pkt->pbuff, sizeof(lcp_hdr_t) + len);

if (debug & 8) {
printf("%s: %s output <%s id=0x%x len=%d",
pppoe->ifname,
sppp_proto_name(proto),
sppp_cp_type_name(lcp->type), lcp->ident,
ntohs(lcp->len));
sppp_cp_type_name(lh->type), lh->ident,
ntohs(lh->len));
if (len)
sppp_print_bytes((uint8_t *) (lcp+1), len);
sppp_print_bytes((uint8_t *) (lh+1), len);
printf(">\n");
}

/* send pkt */
pkt_buffer_set_end_pointer(pkt->pbuff, pkt->pbuff->data - pkt->pbuff->head);
return pkt_send(pppoe->fd_session, &pppoe->pkt_q, pkt);
}

Expand Down Expand Up @@ -1573,7 +1588,7 @@ sppp_lcp_scr(sppp_t *sp)
if (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) {
authproto = sp->hisauth.proto;
opt[i++] = LCP_OPT_AUTH_PROTO;
opt[i++] = authproto == PPP_CHAP? 5: 4;
opt[i++] = authproto == PPP_CHAP ? 5: 4;
opt[i++] = authproto >> 8;
opt[i++] = authproto;
if (authproto == PPP_CHAP)
Expand Down Expand Up @@ -2373,7 +2388,7 @@ sppp_auth_send(const struct cp *cp, sppp_t *sp, unsigned int type, int id, ...)
va_list ap;

/* get ethernet pkt buffer */
pkt = pppoe_eth_pkt_get(s, &s->hw_dst);
pkt = pppoe_eth_pkt_get(s, &s->hw_dst, ETH_P_PPP_SES);

/* fill in pkt */
proto = (uint16_t *) pkt->pbuff->data;
Expand Down Expand Up @@ -2765,7 +2780,8 @@ sppp_up(spppoe_t *s)
sppp_lcp_up(sp);

/* Register keepalive timer */
timer_node_add(&pppoe->ppp_timer, &sp->keepalive, 10);
if (sp->pp_flags & PP_KEEPALIVE)
timer_node_add(&pppoe->ppp_timer, &sp->keepalive, 10);
return 0;
}

Expand Down
10 changes: 5 additions & 5 deletions src/gtp_pppoe_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static const struct ether_addr hw_brd = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};


pkt_t *
pppoe_eth_pkt_get(spppoe_t *s, const struct ether_addr *hw_dst)
pppoe_eth_pkt_get(spppoe_t *s, const struct ether_addr *hw_dst, const uint16_t proto)
{
gtp_pppoe_t *pppoe = s->pppoe;
struct ether_header *eh;
Expand All @@ -57,7 +57,7 @@ pppoe_eth_pkt_get(spppoe_t *s, const struct ether_addr *hw_dst)
eh = (struct ether_header *) pkt->pbuff->head;
memcpy(eh->ether_dhost, hw_dst, ETH_ALEN);
memcpy(eh->ether_shost, &s->hw_src, ETH_ALEN);
eh->ether_type = htons(ETH_P_PPP_DISC);
eh->ether_type = htons(proto);
pkt_buffer_put_data(pkt->pbuff, sizeof(struct ether_header));

return pkt;
Expand Down Expand Up @@ -85,7 +85,7 @@ pppoe_send_padi(spppoe_t *s)
}

/* get ethernet pkt buffer */
pkt = pppoe_eth_pkt_get(s, &hw_brd);
pkt = pppoe_eth_pkt_get(s, &hw_brd, ETH_P_PPP_DISC);

/* fill in pkt */
p = pkt->pbuff->data;
Expand Down Expand Up @@ -139,7 +139,7 @@ pppoe_send_padr(spppoe_t *s)
len += sizeof(pppoe_tag_t) + s->relay_sid_len; /* Relay SID */

/* get ethernet pkt buffer */
pkt = pppoe_eth_pkt_get(s, &s->hw_dst);
pkt = pppoe_eth_pkt_get(s, &s->hw_dst, ETH_P_PPP_DISC);

/* fill in pkt */
p = pkt->pbuff->data;
Expand Down Expand Up @@ -185,7 +185,7 @@ pppoe_send_padt(spppoe_t *s)
uint8_t *p;

/* get ethernet pkt buffer */
pkt = pppoe_eth_pkt_get(s, &s->hw_dst);
pkt = pppoe_eth_pkt_get(s, &s->hw_dst, ETH_P_PPP_DISC);

/* fill in pkt */
p = pkt->pbuff->data;
Expand Down
1 change: 1 addition & 0 deletions src/gtp_pppoe_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ spppoe_destroy(spppoe_t *s)

spppoe_unique_unhash(&s->pppoe->unique_tab, s);
spppoe_session_unhash(&s->pppoe->session_tab, s);
sppp_destroy(s->s_ppp);
FREE(s);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/include/gtp_pppoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */
#define PPPOE_TAG_GENERIC_ERR 0x0203 /* generic error */

#define PPPOE_CODE_SESSION 0x00 /* Session */
#define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
#define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
#define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
Expand Down
2 changes: 1 addition & 1 deletion src/include/gtp_pppoe_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
} while(0)

/* Prototypes */
extern pkt_t *pppoe_eth_pkt_get(spppoe_t *, const struct ether_addr *);
extern pkt_t *pppoe_eth_pkt_get(spppoe_t *, const struct ether_addr *, const uint16_t);
extern void pppoe_dispatch_disc_pkt(gtp_pppoe_t *, pkt_t *);
extern void pppoe_dispatch_session_pkt(gtp_pppoe_t *, pkt_t *);
extern int pppoe_timeout(void *);
Expand Down

0 comments on commit 9024fc0

Please sign in to comment.