Attempt to hack in acceleration for PPPoE

This commit is contained in:
Tassilo Schweyer 2025-04-29 00:43:40 +02:00
parent 0c9338b03a
commit 57004c5744
4 changed files with 40 additions and 9 deletions

22
pppoe.c
View file

@ -225,6 +225,7 @@ static void init_pppoe_sess(void)
LOG(0, 0, 0, "Error pppoe: failed to set nonblocking mode: %s\n", strerror(errno));
exit(1);
}
//pppoesessfd = 0;
}
// set up pppoe discovery/session socket
@ -248,10 +249,13 @@ void init_pppoe(void)
// setup the PPPoE session socket
int create_kernel_pppoe_socket(const sessionidt s) {
tunnelidt t = TUNNEL_ID_PPPOE;
LOG(3, s, t, "Creating kernel-accelerated pppoe socket on %s\n", config->pppoe_if_to_bind);
LOG_HEX(3, "Mac: ", session[s].src_hwaddr, ETH_ALEN);
int pppox_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OE);
if (pppox_fd < 0) {
LOG(2, s, t, "Can't create PPPoE socket: %s\n", strerror(errno));
LOG(3, s, t, "Can't create PPPoE socket: %s\n", strerror(errno));
return -1;
}
struct sockaddr_pppox sax;
@ -259,17 +263,18 @@ int create_kernel_pppoe_socket(const sessionidt s) {
sax.sa_family = AF_PPPOX;
sax.sa_protocol = PX_PROTO_OE;
sax.sa_addr.pppoe.sid = s;
sax.sa_addr.pppoe.sid = htons(s);
memcpy(sax.sa_addr.pppoe.dev, config->pppoe_if_to_bind, IFNAMSIZ);
memcpy(sax.sa_addr.pppoe.remote, session[s].src_hwaddr, ETH_ALEN);
int ret = connect(pppox_fd, (struct sockaddr *)&sax, sizeof(sax));
if (ret < 0) {
LOG(2, s, t, "Can't connect PPPoE: %s\n", strerror(errno));
LOG(3, s, t, "Can't connect PPPoE: %s\n", strerror(errno));
close(pppox_fd);
return -1;
}
return ret;
return pppox_fd;
}
char * get_string_codepad(uint8_t codepad)
@ -579,6 +584,7 @@ static void pppoe_recv_PADI(uint8_t *pack, int size)
pppoe_send_PADO(ethhdr->h_source, host_uniq_tag, relay_sid_tag, service_name_tag);
}
static void pppoe_recv_PADR(uint8_t *pack, int size)
{
struct ethhdr *ethhdr = (struct ethhdr *)pack;
@ -696,6 +702,7 @@ static void pppoe_recv_PADR(uint8_t *pack, int size)
sess_local[sid].mp_epdis = 0;
memcpy(session[sid].src_hwaddr, ethhdr->h_source, ETH_ALEN);
//set_kernel_accel(sid, 1, 1);
pppoe_send_PADS(sid, ethhdr->h_source, host_uniq_tag, relay_sid_tag, service_name_tag);
sendlcp(sid, session[sid].tunnel);
@ -947,9 +954,9 @@ static void pppoe_forwardto_session_rmlns(uint8_t *pack, int size, sessionidt se
{
struct pppoe_hdr *hdr = (struct pppoe_hdr *)(pack + ETH_HLEN);
uint16_t lppp = ntohs(hdr->length);
uint16_t ll2tp = lppp + 6;
uint16_t ll2tp = lppp + 8;
uint8_t *pppdata = (uint8_t *) hdr->tag;
uint8_t *pl2tp = pppdata - 6;
uint8_t *pl2tp = pppdata - 8;
uint8_t *p = pl2tp;
uint16_t t = 0, s = 0;
@ -980,6 +987,9 @@ static void pppoe_forwardto_session_rmlns(uint8_t *pack, int size, sessionidt se
p += 2;
*(uint16_t *) p = htons(session[s].far); // session
p += 2;
*(uint16_t *) p = htons(0xFF03); // HDLC header
p += 2;
if ((proto == PPPIP) || (proto == PPPMP) ||(proto == PPPIPV6 && config->ipv6_prefix.s6_addr[0]))
{