Changeset View
Changeset View
Standalone View
Standalone View
sys/netgraph/ng_pppoe.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/ktr.h> | #include <sys/ktr.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/epoch.h> | |||||
#include <sys/errno.h> | #include <sys/errno.h> | ||||
#include <sys/syslog.h> | #include <sys/syslog.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
#include <netgraph/ng_message.h> | #include <netgraph/ng_message.h> | ||||
#include <netgraph/netgraph.h> | #include <netgraph/netgraph.h> | ||||
#include <netgraph/ng_parse.h> | #include <netgraph/ng_parse.h> | ||||
#include <netgraph/ng_pppoe.h> | #include <netgraph/ng_pppoe.h> | ||||
▲ Show 20 Lines • Show All 700 Lines • ▼ Show 20 Lines | |||||
* Get a netgraph control message. | * Get a netgraph control message. | ||||
* Check it is one we understand. If needed, send a response. | * Check it is one we understand. If needed, send a response. | ||||
* We sometimes save the address for an async action later. | * We sometimes save the address for an async action later. | ||||
* Always free the message. | * Always free the message. | ||||
*/ | */ | ||||
static int | static int | ||||
ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook) | ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook) | ||||
{ | { | ||||
struct epoch_tracker et; | |||||
priv_p privp = NG_NODE_PRIVATE(node); | priv_p privp = NG_NODE_PRIVATE(node); | ||||
struct ngpppoe_init_data *ourmsg = NULL; | struct ngpppoe_init_data *ourmsg = NULL; | ||||
struct ng_mesg *resp = NULL; | struct ng_mesg *resp = NULL; | ||||
int error = 0; | int error = 0; | ||||
hook_p hook = NULL; | hook_p hook = NULL; | ||||
sessp sp = NULL; | sessp sp = NULL; | ||||
negp neg = NULL; | negp neg = NULL; | ||||
struct ng_mesg *msg; | struct ng_mesg *msg; | ||||
NET_EPOCH_ENTER(et); | |||||
glebius: There are only three messages that initiate sending data: CONNECT, SEND_HURL and SEND_MOTM. | |||||
NGI_GET_MSG(item, msg); | NGI_GET_MSG(item, msg); | ||||
CTR5(KTR_NET, "%20s: node [%x] (%p) got message %d with cookie %d", | CTR5(KTR_NET, "%20s: node [%x] (%p) got message %d with cookie %d", | ||||
__func__, node->nd_ID, node, msg->header.cmd, | __func__, node->nd_ID, node, msg->header.cmd, | ||||
msg->header.typecookie); | msg->header.typecookie); | ||||
/* Deal with message according to cookie and command. */ | /* Deal with message according to cookie and command. */ | ||||
switch (msg->header.typecookie) { | switch (msg->header.typecookie) { | ||||
case NGM_PPPOE_COOKIE: | case NGM_PPPOE_COOKIE: | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | case NGM_PPPOE_CONNECT: | ||||
bcopy(ourmsg->data + hupos, neg->host_uniq.data, hulen); | bcopy(ourmsg->data + hupos, neg->host_uniq.data, hulen); | ||||
neg->host_uniq_len = hulen; | neg->host_uniq_len = hulen; | ||||
} | } | ||||
neg->service.hdr.tag_type = PTT_SRV_NAME; | neg->service.hdr.tag_type = PTT_SRV_NAME; | ||||
neg->service.hdr.tag_len = htons((uint16_t)srvlen); | neg->service.hdr.tag_len = htons((uint16_t)srvlen); | ||||
bcopy(ourmsg->data + srvpos, neg->service.data, srvlen); | bcopy(ourmsg->data + srvpos, neg->service.data, srvlen); | ||||
neg->service_len = srvlen; | neg->service_len = srvlen; | ||||
pppoe_start(sp); | pppoe_start(sp); | ||||
glebiusUnsubmitted Not Done Inline Actions#1 This call needs net epoch. glebius: #1 This call needs net epoch. | |||||
break; | break; | ||||
} | } | ||||
case NGM_PPPOE_LISTEN: | case NGM_PPPOE_LISTEN: | ||||
/* | /* | ||||
* Check the hook exists and is Uninitialised. | * Check the hook exists and is Uninitialised. | ||||
* Install the service matching string. | * Install the service matching string. | ||||
* Store the originator of this message so we can send | * Store the originator of this message so we can send | ||||
* a success or fail message to them later. | * a success or fail message to them later. | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | case NGM_PPPOE_SEND_HURL: | ||||
*/ | */ | ||||
tag = (void *)(&wh->ph + 1); | tag = (void *)(&wh->ph + 1); | ||||
tag->tag_type = PTT_HURL; | tag->tag_type = PTT_HURL; | ||||
tag->tag_len = htons(ourmsg->data_len); | tag->tag_len = htons(ourmsg->data_len); | ||||
strncpy((char *)(tag + 1), ourmsg->data, ourmsg->data_len); | strncpy((char *)(tag + 1), ourmsg->data, ourmsg->data_len); | ||||
m->m_pkthdr.len = m->m_len = sizeof(*wh) + sizeof(*tag) + | m->m_pkthdr.len = m->m_len = sizeof(*wh) + sizeof(*tag) + | ||||
ourmsg->data_len; | ourmsg->data_len; | ||||
wh->ph.length = htons(sizeof(*tag) + ourmsg->data_len); | wh->ph.length = htons(sizeof(*tag) + ourmsg->data_len); | ||||
NG_SEND_DATA_ONLY(error, | NG_SEND_DATA_ONLY(error, | ||||
glebiusUnsubmitted Not Done Inline Actions#2 this needs net epoch glebius: #2 this needs net epoch | |||||
privp->ethernet_hook, m); | privp->ethernet_hook, m); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
case NGM_PPPOE_SEND_MOTM: | case NGM_PPPOE_SEND_MOTM: | ||||
{ | { | ||||
struct mbuf *m; | struct mbuf *m; | ||||
Show All 26 Lines | case NGM_PPPOE_SEND_MOTM: | ||||
*/ | */ | ||||
tag = (void *)(&wh->ph + 1); | tag = (void *)(&wh->ph + 1); | ||||
tag->tag_type = PTT_MOTM; | tag->tag_type = PTT_MOTM; | ||||
tag->tag_len = htons(ourmsg->data_len); | tag->tag_len = htons(ourmsg->data_len); | ||||
strncpy((char *)(tag + 1), ourmsg->data, ourmsg->data_len); | strncpy((char *)(tag + 1), ourmsg->data, ourmsg->data_len); | ||||
m->m_pkthdr.len = m->m_len = sizeof(*wh) + sizeof(*tag) + | m->m_pkthdr.len = m->m_len = sizeof(*wh) + sizeof(*tag) + | ||||
ourmsg->data_len; | ourmsg->data_len; | ||||
wh->ph.length = htons(sizeof(*tag) + ourmsg->data_len); | wh->ph.length = htons(sizeof(*tag) + ourmsg->data_len); | ||||
NG_SEND_DATA_ONLY(error, | NG_SEND_DATA_ONLY(error, | ||||
glebiusUnsubmitted Not Done Inline Actions#3 this needs net epoch glebius: #3 this needs net epoch | |||||
privp->ethernet_hook, m); | privp->ethernet_hook, m); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
LEAVE(EINVAL); | LEAVE(EINVAL); | ||||
} | } | ||||
break; | break; | ||||
Show All 16 Lines | ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook) | ||||
} | } | ||||
/* Take care of synchronous response, if any. */ | /* Take care of synchronous response, if any. */ | ||||
quit: | quit: | ||||
CTR2(KTR_NET, "%20s: returning %d", __func__, error); | CTR2(KTR_NET, "%20s: returning %d", __func__, error); | ||||
NG_RESPOND_MSG(error, node, item, resp); | NG_RESPOND_MSG(error, node, item, resp); | ||||
/* Free the message and return. */ | /* Free the message and return. */ | ||||
NG_FREE_MSG(msg); | NG_FREE_MSG(msg); | ||||
NET_EPOCH_EXIT(et); | |||||
return(error); | return(error); | ||||
} | } | ||||
/* | /* | ||||
* Start a client into the first state. A separate function because | * Start a client into the first state. A separate function because | ||||
* it can be needed if the negotiation times out. | * it can be needed if the negotiation times out. | ||||
*/ | */ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 951 Lines • Show Last 20 Lines |
There are only three messages that initiate sending data: CONNECT, SEND_HURL and SEND_MOTM. Makes sense to reduce scope of the epoch only to those places? It is more about a self-documenting code rather than about performance. I'm not insisting on that, just suggesting. I'm marking suggested places down below.