From ace745214513b43a2a40b540c63b7cdbaa1ffbe0 Mon Sep 17 00:00:00 2001 From: Tassilo Schweyer Date: Tue, 22 Apr 2025 14:02:55 +0200 Subject: [PATCH] Create socket for PPPoE --- l2tpns.c | 4 ++++ pppoe.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/l2tpns.c b/l2tpns.c index febcab0..fd10322 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -1023,6 +1023,10 @@ static int create_kernel_pppox(sessionidt s) { tunnelidt t = session[s].tunnel; + if (t == TUNNEL_ID_PPPOE) { + return create_kernel_pppoe_socket(s); + } + if (tunn_local[t].l2tp_fd < 0) /* Tunnel not set up yet */ return -1; diff --git a/pppoe.c b/pppoe.c index c60f4fb..ebfc240 100644 --- a/pppoe.c +++ b/pppoe.c @@ -244,6 +244,34 @@ void init_pppoe(void) STAT(tunnel_created); } + +// setup the PPPoE session socket +int create_kernel_pppoe_socket(const sessionidt s) { + tunnelidt t = TUNNEL_ID_PPPOE; + + 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)); + return -1; + } + struct sockaddr_pppox sax; + memset(&sax, 0, sizeof(sax)); + + sax.sa_family = AF_PPPOX; + sax.sa_protocol = PX_PROTO_OE; + sax.sa_addr.pppoe.sid = 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)); + close(pppox_fd); + return -1; + } + return ret; +} + char * get_string_codepad(uint8_t codepad) { char * ptrch = NULL;