ng_pppoe: add NGM_PPPOE_GET_SESSION_INFO for PPPoE offload

Add netgraph control message (cookie 20) that returns PPPoE session
parameters: session_id, peer MAC, state, and hook name.  Supports
both single-session query (by hook name) and list-all-sessions mode.

Used by CMM to detect active PPPoE sessions and extract the parameters
needed to program hardware flow offload (session ID for PPPoE header
insertion, peer MAC for L2 header construction).
This commit is contained in:
Tomaz Zaman 2026-03-13 11:35:49 +01:00 • committed by Maurice Walker
parent f1e91c63fa
commit 38faadb5fa
2 changed files with 136 additions and 1 deletions

View file

@ -111,6 +111,14 @@ static const struct ng_parse_type ng_pppoe_sts_state_type = {
&ng_pppoe_sts_type_fields
};
/* Parse type for struct ngpppoe_session_info */
static const struct ng_parse_struct_field ng_pppoe_session_info_type_fields[]
= NG_PPPOE_SESSION_INFO_TYPE_INFO;
static const struct ng_parse_type ng_pppoe_session_info_type = {
&ng_parse_struct_type,
&ng_pppoe_session_info_type_fields
};
/* List of commands and how to convert arguments to/from ASCII */
static const struct ng_cmdlist ng_pppoe_cmds[] = {
{
@ -204,6 +212,13 @@ static const struct ng_cmdlist ng_pppoe_cmds[] = {
&ngpppoe_init_data_state_type,
NULL
},
{
NGM_PPPOE_COOKIE,
NGM_PPPOE_GET_SESSION_INFO,
"pppoe_get_session_info",
NULL,
&ng_pppoe_session_info_type
},
{ 0 }
};
@ -1146,6 +1161,102 @@ ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
privp->max_payload.hdr.tag_len = htons(sizeof(uint16_t));
privp->max_payload.data = htons(*((uint16_t *)msg->data));
break;
case NGM_PPPOE_GET_SESSION_INFO:
{
struct ngpppoe_session_info *info;
if (msg->header.arglen >= sizeof(*ourmsg)) {
/*
* Hook name provided — return info for
* that single session.
*/
ourmsg = (struct ngpppoe_init_data *)msg->data;
ourmsg->hook[sizeof(ourmsg->hook) - 1] = '\0';
hook = ng_findhook(node, ourmsg->hook);
if (hook == NULL)
LEAVE(ENOENT);
sp = NG_HOOK_PRIVATE(hook);
if (sp == NULL)
LEAVE(EINVAL);
NG_MKRESPONSE(resp, msg, sizeof(*info),
M_NOWAIT);
if (resp == NULL)
LEAVE(ENOMEM);
info = (struct ngpppoe_session_info *)resp->data;
strlcpy(info->hook, NG_HOOK_NAME(hook),
sizeof(info->hook));
info->session_id = sp->Session_ID;
bcopy(sp->pkt_hdr.eh.ether_dhost,
info->peer_mac, ETHER_ADDR_LEN);
info->state = sp->state;
} else {
/*
* No args — return array of all connected
* sessions.
*/
struct sess_con *ssp;
int count, i, bucket;
/* Count connected sessions. */
count = 0;
for (bucket = 0; bucket < SESSHASHSIZE;
bucket++) {
mtx_lock(&privp->sesshash[bucket].mtx);
LIST_FOREACH(ssp,
&privp->sesshash[bucket].head,
sessions) {
if (ssp->state ==
PPPOE_CONNECTED ||
ssp->state ==
PPPOE_NEWCONNECTED)
count++;
}
mtx_unlock(&privp->sesshash[bucket].mtx);
}
if (count == 0)
LEAVE(ENOENT);
NG_MKRESPONSE(resp, msg,
count * sizeof(*info), M_NOWAIT);
if (resp == NULL)
LEAVE(ENOMEM);
info = (struct ngpppoe_session_info *)resp->data;
i = 0;
for (bucket = 0; bucket < SESSHASHSIZE &&
i < count; bucket++) {
mtx_lock(&privp->sesshash[bucket].mtx);
LIST_FOREACH(ssp,
&privp->sesshash[bucket].head,
sessions) {
if (i >= count)
break;
if (ssp->state !=
PPPOE_CONNECTED &&
ssp->state !=
PPPOE_NEWCONNECTED)
continue;
strlcpy(info[i].hook,
NG_HOOK_NAME(ssp->hook),
sizeof(info[i].hook));
info[i].session_id =
ssp->Session_ID;
bcopy(ssp->pkt_hdr.eh.ether_dhost,
info[i].peer_mac,
ETHER_ADDR_LEN);
info[i].state = ssp->state;
i++;
}
mtx_unlock(&privp->sesshash[bucket].mtx);
}
/* Trim response if fewer found on second pass */
resp->header.arglen = i * sizeof(*info);
}
break;
}
case NGM_PPPOE_SEND_HURL:
{
struct mbuf *m;

View file

@ -88,7 +88,8 @@ enum cmd {
NGM_PPPOE_SEND_HURL = 16, /* Send PADM HURL message */
NGM_PPPOE_HURL = 17, /* HURL for informational purposes */
NGM_PPPOE_SEND_MOTM = 18, /* Send PADM MOTM message */
NGM_PPPOE_MOTM = 19 /* MOTM for informational purposes */
NGM_PPPOE_MOTM = 19, /* MOTM for informational purposes */
NGM_PPPOE_GET_SESSION_INFO = 20 /* Query session params for offload */
};
/***********************
@ -281,4 +282,27 @@ struct maxptag {
#define TAGS_HUNIQ 3
/* for PADT */
/*
* Returned by NGM_PPPOE_GET_SESSION_INFO.
*
* If sent with a hook name (struct ngpppoe_init_data, data_len=0),
* returns info for that one session. If sent with arglen=0,
* returns an array of all connected sessions.
*/
struct ngpppoe_session_info {
char hook[NG_HOOKSIZ]; /* hook name */
uint16_t session_id; /* PPPoE session ID (host order) */
uint8_t peer_mac[ETHER_ADDR_LEN]; /* AC/peer MAC address */
uint8_t state; /* enum state value */
uint8_t _pad;
};
#define NG_PPPOE_SESSION_INFO_TYPE_INFO { \
{ "hook", &ng_parse_hookbuf_type }, \
{ "session_id", &ng_parse_uint16_type }, \
{ "peer_mac", &ng_parse_enaddr_type }, \
{ "state", &ng_parse_uint8_type }, \
{ NULL } \
}
#endif /* _NETGRAPH_NG_PPPOE_H_ */