PPPoE termination offload: session detection, flow offload, soft parser fix
CMM: detect PPPoE sessions via netgraph (NGM_PPPOE_GET_SESSION_INFO), register with CDX (FPP_CMD_PPPOE_ENTRY), resolve point-to-point neighbor MAC from session info instead of ARP. Prevent duplicate CMM instances via pidfile(3) locking. CDX: fix egress PPPoE flags in dpa_get_tx_info_by_itf() — set add_pppoe_hdr/ac_mac_addr instead of pppoe_present. Add pppoe_stats_offset for IPsec path. Remove CDX_TODO_PPPOE ifdefs in control_pppoe.c (timer always marks active, PF handles timeouts). Soft parser (cdx_sp.xml): PPPoE data frames now return to HXS instead of short-circuiting to relay CC table. HXS chains PPPoE→IPv4→TCP/UDP naturally, enabling PCD KeyGen to build 5-tuple hash keys for IPv4 CC table matching. LCP control packets still go directly to host. Verified: 1.6 Gbps through PPPoE with hardware offload (all cores idle, zero FMan drops). Bottleneck is test infrastructure PPPoE server, not GDK.
This commit is contained in:
parent
c08fcc125b
commit
162890791d
14 changed files with 586 additions and 107 deletions
|
|
@ -1,57 +0,0 @@
|
|||
# WiFi Offload Audit — CDX devman gaps vs Linux vendor code
|
||||
|
||||
## Context
|
||||
|
||||
The FreeBSD `cdx_devman_freebsd.c` was written from scratch for Ethernet
|
||||
offload. WiFi (`IF_TYPE_WLAN`) support is being added incrementally as
|
||||
errors surface. The Linux vendor code (`vendor/cdx/dpa_wifi.c`, ~3000 lines)
|
||||
has a complete WiFi TX/RX path. We need to audit all devman functions that
|
||||
walk interface hierarchies or resolve interface properties, and ensure they
|
||||
handle `IF_TYPE_WLAN` correctly.
|
||||
|
||||
## What was already fixed
|
||||
|
||||
1. **`dpa_get_fm_port_index()`** — added `IF_TYPE_WLAN` check to return
|
||||
`wlan_info.fman_idx/port_idx/portid` instead of walking to eth parent.
|
||||
|
||||
2. **`dpa_get_tx_info_by_itf()`** — added `IF_TYPE_WLAN` case in the
|
||||
interface hierarchy walk to get TX FQID from OH port and MAC from
|
||||
`wlan_info.mac_addr`.
|
||||
|
||||
3. **`cdx_ioc_set_dpa_params()`** — added OH port registration loop
|
||||
(step 7d) that was present in Linux `dpa_cfg.c` but missing from
|
||||
the FreeBSD port.
|
||||
|
||||
## Prompt for Claude
|
||||
|
||||
Audit ALL functions in `cdx_devman_freebsd.c` that use `devman_find_eth_parent()`,
|
||||
`IF_TYPE_ETHERNET`, or walk interface hierarchies (VLAN→PPPoE→Ethernet chains).
|
||||
For each one, determine if it needs `IF_TYPE_WLAN` handling.
|
||||
|
||||
Cross-reference with the Linux vendor code:
|
||||
- `vendor/cdx/dpa_wifi.c` — full WiFi TX/RX/VAP management
|
||||
- `vendor/cdx/dpa_wifi.h` — WiFi data structures and FD helpers
|
||||
- `vendor/cdx/devman.c` — Linux devman (compare interface walking)
|
||||
- `vendor/cdx/devoh.c` — Linux OH port management
|
||||
|
||||
Specifically check these functions in `cdx_devman_freebsd.c`:
|
||||
- `dpa_get_tx_l2info_by_itf()` — uses `devman_find_eth_parent()` for L2 bridge flows
|
||||
- `add_incoming_iface_info()` — resolves ingress interface info for hash insertion
|
||||
- `dpa_get_phys_iface()` — returns physical parent interface
|
||||
- Any function that reads `eth_info.*` fields
|
||||
|
||||
Also check `cdx_ehash.c` for WiFi-specific paths:
|
||||
- `fill_actions()` — builds opcode chain for header modification
|
||||
- `insert_entry_in_classif_table()` — already fixed fmindex, but check
|
||||
other assumptions (e.g., L2 header construction, ethertype handling)
|
||||
- `fill_sobject()` / `fill_dobject()` — source/dest object fill
|
||||
|
||||
And check `cdx_devoh_freebsd.c`:
|
||||
- `cdxdrv_create_of_fqs()` — creates QMan FQs for OH ports
|
||||
- Does it create distribution FQs that WiFi needs?
|
||||
|
||||
The goal is to find ALL remaining `IF_TYPE_WLAN` gaps before they surface
|
||||
as runtime errors, rather than fixing them one-by-one.
|
||||
|
||||
Do NOT write code — just research and report findings. List each function,
|
||||
whether it needs a fix, and what the fix would be.
|
||||
|
|
@ -3,24 +3,15 @@
|
|||
<execute-code>
|
||||
<before>
|
||||
<if expr="($FW[48:16]) == 0xc021">
|
||||
<if-false>
|
||||
<!-- PPPoE session packet, police the packet first -->
|
||||
<assign-variable name="$nia" value="0x4C0000"/>
|
||||
<!--NOTE: this ccbase +0x30 is corresponding pppoe relay table -->
|
||||
<!-- this pppoe relay table is allocated dynamically by FMC while pushing tables from cdx_pcd.xml -->
|
||||
<!-- If any new table gets added ccbase value of ppoe relay table should be checked and updated accordingly -->
|
||||
<assign-variable name="$ccbase" value="$ccbase + 0x30"/>
|
||||
<!--indicate we came into cc from pppoe schema-->
|
||||
<assign-variable name="$shimr" value="0x40"/>
|
||||
<action type="exit" confirm="yes" nextproto="end_parse"/>
|
||||
</if-false>
|
||||
<if-true>
|
||||
<!-- PPPoE control packet, enqueue directly -->
|
||||
<!-- PPPoE control packet (LCP), enqueue directly -->
|
||||
<assign-variable name="$hpnia" value="0x500002"/>
|
||||
<action type="exit" confirm="yes" nextproto="end_parse"/>
|
||||
</if-true>
|
||||
</if>
|
||||
</before>
|
||||
<!-- Data: return to HXS with no modifications, let PPPoE->IPv4->TCP chain naturally -->
|
||||
<action type="exit" confirm="no" nextproto="return"/>
|
||||
</before>
|
||||
</execute-code>
|
||||
</protocol>
|
||||
<protocol name="ethernetschema" longname="offline port Ethernet correction" prevproto="ethernet">
|
||||
|
|
|
|||
|
|
@ -762,8 +762,13 @@ dpa_get_tx_info_by_itf(PRouteEntry rt_entry,
|
|||
} else if (cur->if_flags & IF_TYPE_LAGG) {
|
||||
cur = cur->lagg_info.parent;
|
||||
} else if (cur->if_flags & IF_TYPE_PPPOE) {
|
||||
l2_info->pppoe_present = 1;
|
||||
l2_info->add_pppoe_hdr = 1;
|
||||
l2_info->pppoe_sess_id = cur->pppoe_info.session_id;
|
||||
memcpy(l2_info->ac_mac_addr,
|
||||
cur->pppoe_info.mac_addr, ETH_ALEN);
|
||||
#ifdef INCLUDE_PPPoE_IFSTATS
|
||||
l2_info->pppoe_stats_offset = cur->txstats_index;
|
||||
#endif
|
||||
cur = cur->pppoe_info.parent;
|
||||
} else if (cur->if_flags & IF_TYPE_WLAN) {
|
||||
/* WiFi VAP — TX goes to per-VAP FQ or OH default */
|
||||
|
|
@ -1974,6 +1979,10 @@ dpa_get_l2l3_info_by_itf_id(uint32_t itf_id,
|
|||
iface_info->pppoe_info.session_id;
|
||||
memcpy(l2_info->ac_mac_addr,
|
||||
iface_info->pppoe_info.mac_addr, ETH_ALEN);
|
||||
#ifdef INCLUDE_PPPoE_IFSTATS
|
||||
l2_info->pppoe_stats_offset =
|
||||
iface_info->txstats_index;
|
||||
#endif
|
||||
iface_info = iface_info->pppoe_info.parent;
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ SRCS= cmm.c \
|
|||
cmm_ipsec.c \
|
||||
cmm_tunnel.c \
|
||||
cmm_ctrl.c \
|
||||
cmm_wifi.c
|
||||
cmm_wifi.c \
|
||||
cmm_pppoe.c
|
||||
|
||||
CFLAGS+= -I${.CURDIR}/../fci_lib
|
||||
CFLAGS+= -I${.CURDIR}/../fci
|
||||
|
|
@ -38,7 +39,7 @@ CFLAGS+= -DLS1043
|
|||
CFLAGS+= -DWIFI_ENABLE
|
||||
CFLAGS+= -Wall -Wextra -Wno-unused-parameter
|
||||
|
||||
# libfci
|
||||
LDADD+= -L${.CURDIR}/../fci_lib -lfci
|
||||
# libfci + libnetgraph (for PPPoE session detection)
|
||||
LDADD+= -L${.CURDIR}/../fci_lib -lfci -lnetgraph
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ CMM_SRCS= cmm.c cmm_conn.c cmm_route.c cmm_neigh.c \
|
|||
cmm_itf.c cmm_rtsock.c cmm_fe.c cmm_offload.c \
|
||||
cmm_lagg.c cmm_vlan.c cmm_ipsec.c cmm_tunnel.c cmm_deny.c \
|
||||
cmm_socket.c cmm_bridge.c cmm_ctrl.c cmm_l2tp.c \
|
||||
cmm_wifi.c
|
||||
cmm_wifi.c cmm_pppoe.c
|
||||
CMM_OBJS= ${CMM_SRCS:.c=.o}
|
||||
|
||||
PROG= cmm
|
||||
|
|
@ -36,7 +36,7 @@ CFLAGS+= -DLS1043
|
|||
CFLAGS+= -DWIFI_ENABLE
|
||||
|
||||
LDFLAGS= ${TARGET} --sysroot=${SYSROOT}
|
||||
LIBS=
|
||||
LIBS= -lnetgraph -lutil
|
||||
|
||||
all: ${PROG}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ ported:
|
|||
| 7 | CLI daemon | `client_daemon.c` | 1,644 | (dispatcher) | Runtime CLI command interface | [x] |
|
||||
| 8 | Socket accel | `module_socket.c` | 1,886 | `FPP_CMD_IPV4/6_SOCK_*` | TCP socket-level acceleration | [x] |
|
||||
| 9 | RTP/voice | `module_rtp.c`, `voicebuf.c` | 1,810 | `FPP_CMD_RTP_*`, `_VOICE_BUFFER_*` | RTP/RTCP flow monitoring, voice buffers | |
|
||||
| 10 | PPPoE | `pppoe.c`, `module_relay.c` | 960 | `FPP_CMD_PPPOE_ENTRY`, `_RELAY_ENTRY` | PPPoE session management and relay | |
|
||||
| 10 | PPPoE | `pppoe.c`, `module_relay.c` | 960 | `FPP_CMD_PPPOE_ENTRY`, `_RELAY_ENTRY` | PPPoE session management and relay | [x] |
|
||||
| 11 | ICC | `module_icc.c` | 554 | `FPP_CMD_ICC_*` | Ingress congestion control | [x] |
|
||||
| 12 | Profiling | `module_prf.c` | 608 | `FPP_CMD_TRC_*` | FPP debug tracing and CPU profiling | [x] |
|
||||
| 13 | WiFi | `module_wifi.c` | 476 | `FPP_CMD_WIFI_VAP_*` | WiFi VAP management | |
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include <net/pfvar.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <libutil.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -39,6 +40,7 @@
|
|||
#include "cmm_socket.h"
|
||||
#include "cmm_bridge.h"
|
||||
#include "cmm_wifi.h"
|
||||
#include "cmm_pppoe.h"
|
||||
#include "cmm_ctrl.h"
|
||||
#include "pf_notify.h"
|
||||
#include "libfci.h"
|
||||
|
|
@ -72,18 +74,6 @@ sigterm_handler(int sig __unused)
|
|||
cmm_g.running = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
write_pidfile(void)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
f = fopen(CMM_PID_FILE, "w");
|
||||
if (f != NULL) {
|
||||
fprintf(f, "%d\n", getpid());
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
|
@ -101,6 +91,7 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
struct cmm_global *g = &cmm_g;
|
||||
struct pidfh *pfh;
|
||||
struct kevent kev[16];
|
||||
const char *deny_conf = NULL;
|
||||
int ch, nev;
|
||||
|
|
@ -147,14 +138,33 @@ main(int argc, char *argv[])
|
|||
cmm_print(CMM_LOG_INFO, "CMM starting (debug=%d poll=%dms)",
|
||||
g->debug_level, g->poll_ms);
|
||||
|
||||
/* Acquire PID file lock — prevents duplicate instances */
|
||||
{
|
||||
pid_t otherpid;
|
||||
|
||||
pfh = pidfile_open(CMM_PID_FILE, 0600, &otherpid);
|
||||
if (pfh == NULL) {
|
||||
if (errno == EEXIST) {
|
||||
cmm_print(CMM_LOG_ERR,
|
||||
"already running (pid %jd)",
|
||||
(intmax_t)otherpid);
|
||||
exit(1);
|
||||
}
|
||||
cmm_print(CMM_LOG_ERR, "pidfile_open: %s",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Daemonize unless -f */
|
||||
if (!g->foreground) {
|
||||
if (daemon(0, 1) < 0) {
|
||||
cmm_print(CMM_LOG_ERR, "daemon: %s", strerror(errno));
|
||||
pidfile_remove(pfh);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
write_pidfile();
|
||||
pidfile_write(pfh);
|
||||
|
||||
/* Install signal handlers */
|
||||
{
|
||||
|
|
@ -262,6 +272,7 @@ main(int argc, char *argv[])
|
|||
cmm_socket_init();
|
||||
cmm_bridge_init(g);
|
||||
cmm_wifi_init(g);
|
||||
cmm_pppoe_init(g);
|
||||
|
||||
if (cmm_ipsec_init() < 0)
|
||||
goto out;
|
||||
|
|
@ -470,7 +481,7 @@ out:
|
|||
if (g->fci_handle != NULL)
|
||||
fci_close(g->fci_handle);
|
||||
|
||||
unlink(CMM_PID_FILE);
|
||||
pidfile_remove(pfh);
|
||||
cmm_print(CMM_LOG_INFO, "exited");
|
||||
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -113,6 +113,9 @@ static const uint16_t ctrl_whitelist[] = {
|
|||
/* MACVLAN (virtual MAC interfaces) */
|
||||
FPP_CMD_MACVLAN_ENTRY,
|
||||
FPP_CMD_MACVLAN_RESET,
|
||||
/* PPPoE */
|
||||
FPP_CMD_PPPOE_ENTRY,
|
||||
FPP_CMD_PPPOE_GET_IDLE,
|
||||
/* L2TP */
|
||||
FPP_CMD_L2TP_ITF_ADD,
|
||||
FPP_CMD_L2TP_ITF_DEL,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include "cmm_tunnel.h"
|
||||
#include "cmm_bridge.h"
|
||||
#include "cmm_wifi.h"
|
||||
#include "cmm_pppoe.h"
|
||||
#include "cmm_lagg.h"
|
||||
|
||||
static struct list_head itf_hash[ITF_HASH_SIZE];
|
||||
|
|
@ -345,6 +346,7 @@ cmm_itf_init(void)
|
|||
close(sd);
|
||||
}
|
||||
itf_detect_wifi(itf);
|
||||
itf_detect_pppoe(itf);
|
||||
}
|
||||
|
||||
cmm_print(CMM_LOG_INFO,
|
||||
|
|
@ -486,6 +488,7 @@ cmm_itf_handle_ifinfo(struct cmm_global *g, void *msg, int msglen)
|
|||
close(sd);
|
||||
}
|
||||
itf_detect_wifi(itf);
|
||||
itf_detect_pppoe(itf);
|
||||
}
|
||||
|
||||
cmm_print(CMM_LOG_INFO,
|
||||
|
|
@ -537,11 +540,12 @@ cmm_itf_handle_ifinfo(struct cmm_global *g, void *msg, int msglen)
|
|||
itf->mtu = ifm->ifm_data.ifi_mtu;
|
||||
}
|
||||
|
||||
/* Notify LAGG, VLAN, tunnel, WiFi, and bridge modules of flag changes */
|
||||
/* Notify LAGG, VLAN, tunnel, WiFi, PPPoE, and bridge modules of flag changes */
|
||||
cmm_lagg_notify(g, itf);
|
||||
cmm_vlan_notify(g, itf);
|
||||
cmm_tunnel_notify(g, itf);
|
||||
cmm_wifi_notify(g, itf);
|
||||
cmm_pppoe_notify(g, itf);
|
||||
|
||||
/* If this is a bridge or a potential bridge member, rescan */
|
||||
if ((itf->itf_flags & ITF_F_BRIDGE) ||
|
||||
|
|
@ -783,3 +787,21 @@ cmm_itf_foreach_wifi(struct cmm_global *g, cmm_itf_wifi_fn fn)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cmm_itf_foreach_pppoe(struct cmm_global *g, cmm_itf_pppoe_fn fn)
|
||||
{
|
||||
struct list_head *bucket, *pos;
|
||||
struct cmm_interface *itf;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ITF_HASH_SIZE; i++) {
|
||||
bucket = &itf_hash[i];
|
||||
for (pos = list_first(bucket); pos != bucket;
|
||||
pos = list_next(pos)) {
|
||||
itf = container_of(pos, struct cmm_interface, entry);
|
||||
if (itf->itf_flags & ITF_F_PPPOE)
|
||||
fn(g, itf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ struct cmm_ifaddr {
|
|||
#define ITF_F_FPP_WIFI (1 << 8) /* WiFi VAP registered in CDX */
|
||||
#define ITF_F_LAGG (1 << 9) /* LAGG (link aggregation) */
|
||||
#define ITF_F_FPP_LAGG (1 << 10) /* LAGG registered in CDX */
|
||||
#define ITF_F_PPPOE (1 << 11) /* PPPoE session interface */
|
||||
#define ITF_F_FPP_PPPOE (1 << 12) /* PPPoE registered in CDX */
|
||||
|
||||
struct cmm_route;
|
||||
|
||||
|
|
@ -66,6 +68,10 @@ struct cmm_interface {
|
|||
char lagg_active_port[IFNAMSIZ];
|
||||
char lagg_members[8][IFNAMSIZ];
|
||||
int lagg_num_members;
|
||||
/* PPPoE state (valid when ITF_F_PPPOE set) */
|
||||
uint16_t pppoe_session_id;
|
||||
uint8_t pppoe_peer_mac[ETHER_ADDR_LEN];
|
||||
int pppoe_parent_ifindex;
|
||||
};
|
||||
|
||||
/* Initialize interface table from getifaddrs */
|
||||
|
|
@ -106,7 +112,14 @@ void cmm_itf_foreach_wifi(struct cmm_global *g, cmm_itf_wifi_fn fn);
|
|||
typedef int (*cmm_itf_lagg_fn)(struct cmm_global *, struct cmm_interface *);
|
||||
void cmm_itf_foreach_lagg(struct cmm_global *g, cmm_itf_lagg_fn fn);
|
||||
|
||||
/* Iterate all PPPoE interfaces, calling fn for each with ITF_F_PPPOE set */
|
||||
typedef int (*cmm_itf_pppoe_fn)(struct cmm_global *, struct cmm_interface *);
|
||||
void cmm_itf_foreach_pppoe(struct cmm_global *g, cmm_itf_pppoe_fn fn);
|
||||
|
||||
/* Probe interface for tunnel endpoints (gif/gre) */
|
||||
void itf_detect_tunnel(struct cmm_interface *itf, int sd);
|
||||
|
||||
/* Probe interface for PPPoE session (via netgraph) */
|
||||
void itf_detect_pppoe(struct cmm_interface *itf);
|
||||
|
||||
#endif /* CMM_ITF_H */
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "cmm.h"
|
||||
#include "cmm_neigh.h"
|
||||
#include "cmm_itf.h"
|
||||
#include "cmm_rtsock.h"
|
||||
|
||||
static struct list_head neigh_hash[NEIGH_HASH_SIZE];
|
||||
|
|
@ -77,6 +78,22 @@ neigh_resolve(struct cmm_global *g __unused, struct cmm_neigh *neigh)
|
|||
struct rt_msghdr *rtm;
|
||||
struct cmm_rtsock_addrs addrs;
|
||||
|
||||
/*
|
||||
* PPPoE is point-to-point — no ARP. The peer MAC is known
|
||||
* from PPPoE session negotiation, stored in the interface.
|
||||
*/
|
||||
{
|
||||
struct cmm_interface *itf;
|
||||
|
||||
itf = cmm_itf_find_by_index(neigh->ifindex);
|
||||
if (itf != NULL && (itf->itf_flags & ITF_F_PPPOE)) {
|
||||
memcpy(neigh->macaddr, itf->pppoe_peer_mac,
|
||||
ETHER_ADDR_LEN);
|
||||
neigh->state = NEIGH_RESOLVED;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_ROUTE;
|
||||
mib[2] = 0;
|
||||
|
|
|
|||
455
fastpath/cmm/cmm_pppoe.c
Normal file
455
fastpath/cmm/cmm_pppoe.c
Normal file
|
|
@ -0,0 +1,455 @@
|
|||
/*
|
||||
* cmm_pppoe.c — PPPoE session offload
|
||||
*
|
||||
* Detects PPPoE sessions via netgraph and registers them with CDX
|
||||
* so the hardware can strip/insert PPPoE headers in the fast path.
|
||||
*
|
||||
* Copyright 2026 Mono Technologies Inc.
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <net/if.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/ng_pppoe.h>
|
||||
#include <netgraph.h>
|
||||
|
||||
#include "cmm.h"
|
||||
#include "cmm_pppoe.h"
|
||||
#include "cmm_itf.h"
|
||||
|
||||
/*
|
||||
* Query the ng_pppoe node associated with a pppN interface to get
|
||||
* the PPPoE session parameters and the underlying physical interface.
|
||||
*
|
||||
* Netgraph topology for a PPPoE client session:
|
||||
* ppp0: (ng_ppp) --[pppoe]--> ng_pppoe --[ethernet]--> ng_ether (dtsec3:)
|
||||
*
|
||||
* We walk: pppN: → list hooks → find the "pppoe" peer → that's the ng_pppoe
|
||||
* node → send NGM_PPPOE_GET_SESSION_INFO → then list ng_pppoe's hooks to
|
||||
* find "ethernet" peer → that's the ng_ether node → its name is the
|
||||
* physical interface.
|
||||
*/
|
||||
/*
|
||||
* Helper: list hooks on a netgraph node and find a peer of the given type.
|
||||
* Returns the peer's node ID in *peer_id and the peer's hook name in
|
||||
* peer_hook (caller provides NG_HOOKSIZ buffer). Returns 0 on success.
|
||||
*/
|
||||
static int
|
||||
ng_find_peer_by_type(int csock, const char *node_path, const char *type,
|
||||
uint32_t *peer_id, char *peer_hook)
|
||||
{
|
||||
struct ng_mesg *resp = NULL;
|
||||
struct hooklist *hl;
|
||||
int i;
|
||||
|
||||
if (NgSendMsg(csock, node_path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
|
||||
NULL, 0) < 0)
|
||||
return (-1);
|
||||
|
||||
if (NgAllocRecvMsg(csock, &resp, NULL) < 0 || resp == NULL)
|
||||
return (-1);
|
||||
|
||||
hl = (struct hooklist *)resp->data;
|
||||
for (i = 0; i < (int)hl->nodeinfo.hooks; i++) {
|
||||
struct linkinfo *li = &hl->link[i];
|
||||
|
||||
if (strcmp(li->nodeinfo.type, type) == 0) {
|
||||
*peer_id = li->nodeinfo.id;
|
||||
if (peer_hook != NULL)
|
||||
strlcpy(peer_hook, li->peerhook,
|
||||
NG_HOOKSIZ);
|
||||
free(resp);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
free(resp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static int
|
||||
pppoe_query_netgraph(struct cmm_interface *itf)
|
||||
{
|
||||
int csock, dsock;
|
||||
char path[128];
|
||||
char pppoe_path[128];
|
||||
char session_hook[NG_HOOKSIZ];
|
||||
uint32_t ppp_id, pppoe_id;
|
||||
int rc = -1;
|
||||
|
||||
if (NgMkSockNode(NULL, &csock, &dsock) < 0) {
|
||||
cmm_print(CMM_LOG_WARN,
|
||||
"pppoe: NgMkSockNode failed: %s", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mpd5/OPNsense netgraph topology:
|
||||
* pppoe0 (ng_iface) → ng_ppp → ng_pppoe → ng_ether (dtsec3)
|
||||
*
|
||||
* Walk from the interface node through ng_ppp to ng_pppoe.
|
||||
*/
|
||||
snprintf(path, sizeof(path), "%s:", itf->ifname);
|
||||
|
||||
/*
|
||||
* Step 1: List hooks on the node to determine topology.
|
||||
*
|
||||
* OPNsense/mpd5 names the ng_pppoe node after the interface
|
||||
* (e.g. "pppoe0"), so addressing "pppoe0:" in netgraph
|
||||
* reaches the ng_pppoe node directly. The LISTHOOKS response
|
||||
* tells us the node's own type via nodeinfo.
|
||||
*/
|
||||
if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
|
||||
NULL, 0) < 0) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: NGM_LISTHOOKS %s failed: %s",
|
||||
path, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
{
|
||||
struct ng_mesg *lresp = NULL;
|
||||
struct hooklist *hl;
|
||||
int i;
|
||||
int found_session = 0;
|
||||
|
||||
if (NgAllocRecvMsg(csock, &lresp, NULL) < 0 ||
|
||||
lresp == NULL)
|
||||
goto out;
|
||||
|
||||
hl = (struct hooklist *)lresp->data;
|
||||
|
||||
if (strcmp(hl->nodeinfo.type, "pppoe") == 0) {
|
||||
/*
|
||||
* We're directly on the ng_pppoe node.
|
||||
* Find the session hook (any hook that isn't
|
||||
* "ethernet") and the physical interface.
|
||||
*/
|
||||
snprintf(pppoe_path, sizeof(pppoe_path),
|
||||
"[%x]:", hl->nodeinfo.id);
|
||||
|
||||
for (i = 0; i < (int)hl->nodeinfo.hooks; i++) {
|
||||
struct linkinfo *li = &hl->link[i];
|
||||
|
||||
if (strcmp(li->ourhook, "ethernet") == 0) {
|
||||
itf->pppoe_parent_ifindex =
|
||||
if_nametoindex(
|
||||
li->nodeinfo.name);
|
||||
} else if (!found_session) {
|
||||
strlcpy(session_hook, li->ourhook,
|
||||
sizeof(session_hook));
|
||||
found_session = 1;
|
||||
}
|
||||
}
|
||||
free(lresp);
|
||||
} else {
|
||||
/*
|
||||
* Not an ng_pppoe node — walk through peers.
|
||||
* Try: iface → pppoe (direct), or
|
||||
* iface → ppp → pppoe (mpd5 with ng_ppp).
|
||||
*/
|
||||
int found = 0;
|
||||
|
||||
for (i = 0; i < (int)hl->nodeinfo.hooks; i++) {
|
||||
struct linkinfo *li = &hl->link[i];
|
||||
|
||||
if (strcmp(li->nodeinfo.type, "pppoe") == 0) {
|
||||
pppoe_id = li->nodeinfo.id;
|
||||
strlcpy(session_hook, li->peerhook,
|
||||
sizeof(session_hook));
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
if (strcmp(li->nodeinfo.type, "ppp") == 0)
|
||||
ppp_id = li->nodeinfo.id;
|
||||
}
|
||||
free(lresp);
|
||||
|
||||
if (!found && ppp_id != 0) {
|
||||
char ppp_path[128];
|
||||
|
||||
snprintf(ppp_path, sizeof(ppp_path),
|
||||
"[%x]:", ppp_id);
|
||||
if (ng_find_peer_by_type(csock, ppp_path,
|
||||
"pppoe", &pppoe_id, session_hook) < 0) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: %s no ng_pppoe found",
|
||||
itf->ifname);
|
||||
goto out;
|
||||
}
|
||||
found = 1;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: %s no ng_pppoe in graph",
|
||||
itf->ifname);
|
||||
goto out;
|
||||
}
|
||||
|
||||
snprintf(pppoe_path, sizeof(pppoe_path),
|
||||
"[%x]:", pppoe_id);
|
||||
|
||||
/* Find physical interface from ng_pppoe hooks */
|
||||
{
|
||||
struct ng_mesg *hresp = NULL;
|
||||
struct hooklist *phl;
|
||||
int j;
|
||||
|
||||
if (NgSendMsg(csock, pppoe_path,
|
||||
NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
|
||||
NULL, 0) < 0)
|
||||
goto out;
|
||||
if (NgAllocRecvMsg(csock, &hresp, NULL) < 0 ||
|
||||
hresp == NULL)
|
||||
goto out;
|
||||
|
||||
phl = (struct hooklist *)hresp->data;
|
||||
for (j = 0; j < (int)phl->nodeinfo.hooks;
|
||||
j++) {
|
||||
struct linkinfo *pli = &phl->link[j];
|
||||
|
||||
if (strcmp(pli->ourhook,
|
||||
"ethernet") == 0) {
|
||||
itf->pppoe_parent_ifindex =
|
||||
if_nametoindex(
|
||||
pli->nodeinfo.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(hresp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_session &&
|
||||
strcmp(hl->nodeinfo.type, "pppoe") == 0) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: %s no session hook found",
|
||||
itf->ifname);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 2: Query session info from ng_pppoe */
|
||||
{
|
||||
struct ngpppoe_init_data qmsg;
|
||||
struct ng_mesg *sresp;
|
||||
struct ngpppoe_session_info *si;
|
||||
|
||||
memset(&qmsg, 0, sizeof(qmsg));
|
||||
strlcpy(qmsg.hook, session_hook, sizeof(qmsg.hook));
|
||||
qmsg.data_len = 0;
|
||||
|
||||
if (NgSendMsg(csock, pppoe_path, NGM_PPPOE_COOKIE,
|
||||
NGM_PPPOE_GET_SESSION_INFO, &qmsg, sizeof(qmsg)) < 0) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: GET_SESSION_INFO for %s failed: %s",
|
||||
itf->ifname, strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
sresp = NULL;
|
||||
if (NgAllocRecvMsg(csock, &sresp, NULL) < 0 ||
|
||||
sresp == NULL) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: recv SESSION_INFO failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
si = (struct ngpppoe_session_info *)sresp->data;
|
||||
itf->pppoe_session_id = si->session_id;
|
||||
memcpy(itf->pppoe_peer_mac, si->peer_mac, ETHER_ADDR_LEN);
|
||||
|
||||
/* State 7 = PPPOE_CONNECTED, State 6 = PPPOE_NEWCONNECTED */
|
||||
if (si->state < 6) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: %s session not connected (state=%u)",
|
||||
itf->ifname, si->state);
|
||||
free(sresp);
|
||||
goto out;
|
||||
}
|
||||
free(sresp);
|
||||
}
|
||||
|
||||
if (itf->pppoe_parent_ifindex != 0)
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
close(csock);
|
||||
close(dsock);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
void
|
||||
itf_detect_pppoe(struct cmm_interface *itf)
|
||||
{
|
||||
/* PPP interfaces are named pppN or pppoeN (OPNsense/mpd5) */
|
||||
if (strncmp(itf->ifname, "ppp", 3) != 0)
|
||||
return;
|
||||
|
||||
if (pppoe_query_netgraph(itf) == 0) {
|
||||
itf->itf_flags |= ITF_F_PPPOE;
|
||||
cmm_print(CMM_LOG_INFO,
|
||||
"pppoe: %s detected — session_id=%u "
|
||||
"peer=%02x:%02x:%02x:%02x:%02x:%02x parent_idx=%d",
|
||||
itf->ifname,
|
||||
itf->pppoe_session_id,
|
||||
itf->pppoe_peer_mac[0], itf->pppoe_peer_mac[1],
|
||||
itf->pppoe_peer_mac[2], itf->pppoe_peer_mac[3],
|
||||
itf->pppoe_peer_mac[4], itf->pppoe_peer_mac[5],
|
||||
itf->pppoe_parent_ifindex);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
cmm_pppoe_register(struct cmm_global *g, struct cmm_interface *itf)
|
||||
{
|
||||
fpp_pppoe_cmd_t cmd;
|
||||
struct cmm_interface *parent;
|
||||
int rc;
|
||||
|
||||
if (!(itf->itf_flags & ITF_F_PPPOE))
|
||||
return (0);
|
||||
if (itf->itf_flags & ITF_F_FPP_PPPOE)
|
||||
return (0);
|
||||
if (itf->pppoe_session_id == 0)
|
||||
return (0);
|
||||
|
||||
parent = cmm_itf_find_by_index(itf->pppoe_parent_ifindex);
|
||||
if (parent == NULL) {
|
||||
cmm_print(CMM_LOG_WARN,
|
||||
"pppoe: %s parent idx=%d not found",
|
||||
itf->ifname, itf->pppoe_parent_ifindex);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
cmd.action = FPP_ACTION_REGISTER;
|
||||
cmd.sessionid = htons(itf->pppoe_session_id);
|
||||
memcpy(cmd.macaddr, itf->pppoe_peer_mac, ETHER_ADDR_LEN);
|
||||
strlcpy(cmd.phy_intf, parent->ifname, sizeof(cmd.phy_intf));
|
||||
strlcpy(cmd.log_intf, itf->ifname, sizeof(cmd.log_intf));
|
||||
|
||||
rc = fci_write(g->fci_handle, FPP_CMD_PPPOE_ENTRY,
|
||||
sizeof(cmd), (unsigned short *)&cmd);
|
||||
if (rc == FPP_ERR_PPPOE_ENTRY_ALREADY_REGISTERED) {
|
||||
cmm_print(CMM_LOG_DEBUG,
|
||||
"pppoe: %s already in CDX, reusing", itf->ifname);
|
||||
} else if (rc != 0) {
|
||||
cmm_print(CMM_LOG_WARN,
|
||||
"pppoe: register %s failed: %d", itf->ifname, rc);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
itf->itf_flags |= ITF_F_FPP_PPPOE;
|
||||
cmm_print(CMM_LOG_INFO,
|
||||
"pppoe: registered %s (session=%u parent=%s)",
|
||||
itf->ifname, itf->pppoe_session_id, parent->ifname);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
cmm_pppoe_deregister(struct cmm_global *g, struct cmm_interface *itf)
|
||||
{
|
||||
fpp_pppoe_cmd_t cmd;
|
||||
struct cmm_interface *parent;
|
||||
int rc;
|
||||
|
||||
if (!(itf->itf_flags & ITF_F_FPP_PPPOE))
|
||||
return (0);
|
||||
|
||||
parent = cmm_itf_find_by_index(itf->pppoe_parent_ifindex);
|
||||
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
cmd.action = FPP_ACTION_DEREGISTER;
|
||||
cmd.sessionid = htons(itf->pppoe_session_id);
|
||||
memcpy(cmd.macaddr, itf->pppoe_peer_mac, ETHER_ADDR_LEN);
|
||||
strlcpy(cmd.log_intf, itf->ifname, sizeof(cmd.log_intf));
|
||||
if (parent != NULL)
|
||||
strlcpy(cmd.phy_intf, parent->ifname, sizeof(cmd.phy_intf));
|
||||
|
||||
rc = fci_write(g->fci_handle, FPP_CMD_PPPOE_ENTRY,
|
||||
sizeof(cmd), (unsigned short *)&cmd);
|
||||
if (rc != 0 && rc != FPP_ERR_PPPOE_ENTRY_NOT_FOUND)
|
||||
cmm_print(CMM_LOG_WARN,
|
||||
"pppoe: deregister %s failed: %d", itf->ifname, rc);
|
||||
|
||||
itf->itf_flags &= ~ITF_F_FPP_PPPOE;
|
||||
cmm_print(CMM_LOG_INFO,
|
||||
"pppoe: deregistered %s (session=%u)",
|
||||
itf->ifname, itf->pppoe_session_id);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
cmm_pppoe_init(struct cmm_global *g)
|
||||
{
|
||||
cmm_itf_foreach_pppoe(g, cmm_pppoe_register);
|
||||
cmm_print(CMM_LOG_INFO, "pppoe: initialized");
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
cmm_pppoe_fini(struct cmm_global *g)
|
||||
{
|
||||
cmm_itf_foreach_pppoe(g, cmm_pppoe_deregister);
|
||||
}
|
||||
|
||||
void
|
||||
cmm_pppoe_notify(struct cmm_global *g, struct cmm_interface *itf)
|
||||
{
|
||||
/*
|
||||
* PPPoE sessions can come and go. If the interface is up and we
|
||||
* haven't detected a PPPoE session yet, try now (the session may
|
||||
* have just connected).
|
||||
*/
|
||||
if ((itf->flags & IFF_UP) && !(itf->itf_flags & ITF_F_PPPOE)) {
|
||||
itf_detect_pppoe(itf);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the session was detected, check if the session parameters
|
||||
* changed (reconnect with new session_id).
|
||||
*/
|
||||
if ((itf->flags & IFF_UP) && (itf->itf_flags & ITF_F_PPPOE)) {
|
||||
uint16_t old_sid = itf->pppoe_session_id;
|
||||
|
||||
/* Re-query to detect session changes */
|
||||
if (pppoe_query_netgraph(itf) == 0 &&
|
||||
itf->pppoe_session_id != old_sid &&
|
||||
(itf->itf_flags & ITF_F_FPP_PPPOE)) {
|
||||
/* Session changed — deregister old, register new */
|
||||
cmm_print(CMM_LOG_INFO,
|
||||
"pppoe: %s session changed %u -> %u",
|
||||
itf->ifname, old_sid,
|
||||
itf->pppoe_session_id);
|
||||
itf->pppoe_session_id = old_sid; /* restore for dereg */
|
||||
cmm_pppoe_deregister(g, itf);
|
||||
pppoe_query_netgraph(itf); /* re-read new params */
|
||||
}
|
||||
|
||||
if (!(itf->itf_flags & ITF_F_FPP_PPPOE))
|
||||
cmm_pppoe_register(g, itf);
|
||||
}
|
||||
|
||||
/* Interface went down — deregister */
|
||||
if (!(itf->flags & IFF_UP) && (itf->itf_flags & ITF_F_FPP_PPPOE))
|
||||
cmm_pppoe_deregister(g, itf);
|
||||
|
||||
/* Clear PPPoE detection if interface went down */
|
||||
if (!(itf->flags & IFF_UP) && (itf->itf_flags & ITF_F_PPPOE)) {
|
||||
itf->itf_flags &= ~ITF_F_PPPOE;
|
||||
itf->pppoe_session_id = 0;
|
||||
memset(itf->pppoe_peer_mac, 0, ETHER_ADDR_LEN);
|
||||
itf->pppoe_parent_ifindex = 0;
|
||||
}
|
||||
}
|
||||
24
fastpath/cmm/cmm_pppoe.h
Normal file
24
fastpath/cmm/cmm_pppoe.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* cmm_pppoe.h — PPPoE session offload
|
||||
*
|
||||
* Copyright 2026 Mono Technologies Inc.
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef CMM_PPPOE_H
|
||||
#define CMM_PPPOE_H
|
||||
|
||||
#include "cmm.h"
|
||||
|
||||
struct cmm_interface;
|
||||
|
||||
/* Register all existing UP PPPoE sessions with CDX */
|
||||
int cmm_pppoe_init(struct cmm_global *g);
|
||||
|
||||
/* Deregister all PPPoE sessions from CDX */
|
||||
void cmm_pppoe_fini(struct cmm_global *g);
|
||||
|
||||
/* Called when interface flags change — register/deregister as needed */
|
||||
void cmm_pppoe_notify(struct cmm_global *g, struct cmm_interface *itf);
|
||||
|
||||
#endif /* CMM_PPPOE_H */
|
||||
20
fastpath/vendor/cdx/control_pppoe.c
vendored
20
fastpath/vendor/cdx/control_pppoe.c
vendored
|
|
@ -40,9 +40,6 @@ static void __pppoe_add(pPPPoE_Info pEntry, U16 hash_key)
|
|||
/* Add to our local hash */
|
||||
slist_add(&pppoe_cache[hash_key], &pEntry->list);
|
||||
|
||||
#ifdef CDX_TODO_PPPOE
|
||||
/* Construct the hardware entry, converting virtual addresses and endianess where needed */
|
||||
#endif
|
||||
cdx_timer_init(&pEntry->timer, M_pppoe_timer);
|
||||
cdx_timer_add(&pEntry->timer, PPPOE_TIMER_PERIOD);
|
||||
}
|
||||
|
|
@ -66,10 +63,6 @@ static void __pppoe_remove(pPPPoE_Info pEntry, U16 hash_key)
|
|||
|
||||
prev = slist_prev(&pppoe_cache[hash_key], &pEntry->list);
|
||||
|
||||
#ifdef CDX_TODO_PPPOE
|
||||
/* remove the hardware entry */
|
||||
#endif
|
||||
|
||||
/* Remove from our local hash */
|
||||
slist_remove_after(prev);
|
||||
|
||||
|
|
@ -91,14 +84,11 @@ static void pppoe_remove_relay(pPPPoE_Info pEntry, U16 hash_key, pPPPoE_Info pRe
|
|||
static int M_pppoe_timer(TIMER_ENTRY *timer)
|
||||
{
|
||||
pPPPoE_Info pEntry = container_of(timer, PPPoE_Info, timer);
|
||||
#ifdef CDX_TODO_PPPOE
|
||||
if (hw_get_active_pppoe_rcv(zzz)) // TODO: implement check
|
||||
#endif
|
||||
pEntry->last_pkt_rcvd = JIFFIES32;
|
||||
#ifdef CDX_TODO_PPPOE
|
||||
if (hw_get_active_pppoe_xmt(zzz)) // TODO: implement check
|
||||
#endif
|
||||
pEntry->last_pkt_xmit = JIFFIES32;
|
||||
|
||||
/* Always mark as active — PF handles session timeouts for
|
||||
* termination mode. HW stats polling can be added later. */
|
||||
pEntry->last_pkt_rcvd = JIFFIES32;
|
||||
pEntry->last_pkt_xmit = JIFFIES32;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue