summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2000-10-31 02:45:24 +0000
committerbrian <brian@FreeBSD.org>2000-10-31 02:45:24 +0000
commit87f7d0a784b3001a7697f226a31288dfb982acfa (patch)
treebd7fbe4e6589c780bae7627e213885ae6359c967
parent7d8c3006374df5cf59d441ca981c999dcf83caad (diff)
downloadFreeBSD-src-87f7d0a784b3001a7697f226a31288dfb982acfa.zip
FreeBSD-src-87f7d0a784b3001a7697f226a31288dfb982acfa.tar.gz
Change the format of ngpppoe_init_data so that the provider is NUL
terminated and the data_len field is no longer necessary. Add ASCII2BINARY and BINARY2ASCII capabilities. The old format is still understood and dealt with, but can't do the ASCII2BINARY and BINARY2ASCII stuff. Approved by: archie
-rw-r--r--sys/netgraph/ng_pppoe.c147
-rw-r--r--sys/netgraph/ng_pppoe.h31
2 files changed, 148 insertions, 30 deletions
diff --git a/sys/netgraph/ng_pppoe.c b/sys/netgraph/ng_pppoe.c
index 8ae96f2..0a9fca5 100644
--- a/sys/netgraph/ng_pppoe.c
+++ b/sys/netgraph/ng_pppoe.c
@@ -57,9 +57,19 @@
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
+#include <netgraph/ng_parse.h>
#include <netgraph/ng_pppoe.h>
+#define NGM_PPPOE_OLDCOOKIE 939032003
+
+struct ngpppoe_old_init_data {
+ char hook[NG_HOOKLEN + 1]; /* hook to monitor on */
+ u_int16_t data_len; /* Length of the service name */
+ char data[0]; /* init data goes here */
+};
+
#define SIGNOFF "session closed"
+#define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
/*
* This section contains the netgraph method declarations for the
@@ -74,6 +84,70 @@ static ng_connect_t ng_pppoe_connect;
static ng_rcvdata_t ng_pppoe_rcvdata;
static ng_disconnect_t ng_pppoe_disconnect;
+/* Parse type for struct ngpppoe_init_data */
+
+static const struct ng_parse_struct_info ng_pppoe_init_data_type_info
+ = NG_PPPOE_INIT_DATA_TYPE_INFO;
+static const struct ng_parse_type ng_pppoe_init_data_state_type = {
+ &ng_parse_struct_type,
+ &ng_pppoe_init_data_type_info
+};
+
+/* Parse type for struct ngpppoe_sts */
+static const struct ng_parse_struct_info ng_pppoe_sts_type_info
+ = NG_PPPOE_STS_TYPE_INFO;
+static const struct ng_parse_type ng_pppoe_sts_state_type = {
+ &ng_parse_struct_type,
+ &ng_pppoe_sts_type_info
+};
+
+/* List of commands and how to convert arguments to/from ASCII */
+static const struct ng_cmdlist ng_pppoe_cmds[] = {
+ {
+ NGM_PPPOE_COOKIE,
+ NGM_PPPOE_CONNECT,
+ "pppoe_connect",
+ &ng_pppoe_init_data_state_type,
+ NULL
+ },
+ {
+ NGM_PPPOE_COOKIE,
+ NGM_PPPOE_LISTEN,
+ "pppoe_listen",
+ &ng_pppoe_init_data_state_type,
+ NULL
+ },
+ {
+ NGM_PPPOE_COOKIE,
+ NGM_PPPOE_OFFER,
+ "pppoe_offer",
+ &ng_pppoe_init_data_state_type,
+ NULL
+ },
+ {
+ NGM_PPPOE_COOKIE,
+ NGM_PPPOE_SUCCESS,
+ "pppoe_success",
+ &ng_pppoe_sts_state_type,
+ NULL
+ },
+ {
+ NGM_PPPOE_COOKIE,
+ NGM_PPPOE_FAIL,
+ "pppoe_fail",
+ &ng_pppoe_sts_state_type,
+ NULL
+ },
+ {
+ NGM_PPPOE_COOKIE,
+ NGM_PPPOE_CLOSE,
+ "pppoe_close",
+ &ng_pppoe_sts_state_type,
+ NULL
+ },
+ { 0 }
+};
+
/* Netgraph node type descriptor */
static struct ng_type typestruct = {
NG_VERSION,
@@ -88,7 +162,7 @@ static struct ng_type typestruct = {
ng_pppoe_rcvdata,
ng_pppoe_rcvdata,
ng_pppoe_disconnect,
- NULL
+ ng_pppoe_cmds
};
NETGRAPH_INIT(pppoe, &typestruct);
@@ -135,6 +209,7 @@ typedef struct sess_neg *negp;
* Session information that is needed after connection.
*/
struct sess_con {
+ u_int32_t typecookie; /* cookie used by sender */
hook_p hook;
u_int16_t Session_ID;
enum state state;
@@ -523,6 +598,7 @@ AAA
bzero(sp, sizeof(*sp));
hook->private = sp;
+ sp->typecookie = NGM_PPPOE_COOKIE;
sp->hook = hook;
}
return(0);
@@ -540,32 +616,54 @@ ng_pppoe_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
{
priv_p privp = node->private;
struct ngpppoe_init_data *ourmsg = NULL;
+ struct ngpppoe_old_init_data *oldmsg;
struct ng_mesg *resp = NULL;
int error = 0;
hook_p hook = NULL;
sessp sp = NULL;
negp neg = NULL;
+ uint16_t datalen = 0;
AAA
/* Deal with message according to cookie and command */
switch (msg->header.typecookie) {
+ case NGM_PPPOE_OLDCOOKIE:
case NGM_PPPOE_COOKIE:
switch (msg->header.cmd) {
case NGM_PPPOE_CONNECT:
case NGM_PPPOE_LISTEN:
case NGM_PPPOE_OFFER:
+ if (msg->header.typecookie == NGM_PPPOE_OLDCOOKIE) {
+ /* Make the old data look like new data */
+
+ oldmsg = (struct ngpppoe_old_init_data *)
+ msg->data;
+ if (sizeof(*oldmsg) + oldmsg->data_len
+ > msg->header.arglen) {
+ printf("pppoe_rcvmsg: bad arg size");
+ LEAVE(EMSGSIZE);
+ }
+ datalen = oldmsg->data_len;
+ if (datalen != 0)
+ bcopy(oldmsg->data, &oldmsg->data_len,
+ datalen);
+ ((char *)&oldmsg->data_len)[datalen] = '\0';
+ msg->header.arglen = datalen + sizeof(*ourmsg);
+ }
+
ourmsg = (struct ngpppoe_init_data *)msg->data;
- if (( sizeof(*ourmsg) > msg->header.arglen)
- || ((sizeof(*ourmsg) + ourmsg->data_len)
- > msg->header.arglen)) {
- printf("pppoe_rcvmsg: bad arg size");
+ if (msg->header.arglen - sizeof(*ourmsg) >
+ PPPOE_SERVICE_NAME_SIZE) {
+ printf("pppoe_rcvmsg: service name too big");
LEAVE(EMSGSIZE);
}
- if (ourmsg->data_len > PPPOE_SERVICE_NAME_SIZE) {
- printf("pppoe: init data too long (%d)\n",
- ourmsg->data_len);
+ if (ourmsg->data[msg->header.arglen - sizeof(*ourmsg)]
+ != '\0') {
+ printf("pppoe_rcvmsg: svc name unterminated");
LEAVE(EMSGSIZE);
}
+ datalen = strlen(ourmsg->data);
+
/* make sure strcmp will terminate safely */
ourmsg->hook[sizeof(ourmsg->hook) - 1] = '\0';
@@ -583,6 +681,7 @@ AAA
LEAVE(EINVAL);
}
sp = hook->private;
+ sp->typecookie = msg->header.typecookie;
if (sp->state |= PPPOE_SNONE) {
printf("pppoe: Session already active\n");
LEAVE(EISCONN);
@@ -650,13 +749,11 @@ AAA
* start it.
*/
neg->service.hdr.tag_type = PTT_SRV_NAME;
- neg->service.hdr.tag_len =
- htons((u_int16_t)ourmsg->data_len);
- if (ourmsg->data_len) {
- bcopy(ourmsg->data,
- neg->service.data, ourmsg->data_len);
+ neg->service.hdr.tag_len = htons(datalen);
+ if (datalen) {
+ bcopy(ourmsg->data, neg->service.data, datalen);
}
- neg->service_len = ourmsg->data_len;
+ neg->service_len = datalen;
pppoe_start(sp);
break;
case NGM_PPPOE_LISTEN:
@@ -669,14 +766,12 @@ AAA
*/
neg->service.hdr.tag_type = PTT_SRV_NAME;
- neg->service.hdr.tag_len =
- htons((u_int16_t)ourmsg->data_len);
+ neg->service.hdr.tag_len = htons(datalen);
- if (ourmsg->data_len) {
- bcopy(ourmsg->data,
- neg->service.data, ourmsg->data_len);
+ if (datalen) {
+ bcopy(ourmsg->data, neg->service.data, datalen);
}
- neg->service_len = ourmsg->data_len;
+ neg->service_len = datalen;
neg->pkt->pkt_header.ph.code = PADT_CODE;
/*
* wait for PADI packet coming from ethernet
@@ -691,13 +786,11 @@ AAA
* Store the AC-Name given and go to PRIMED.
*/
neg->ac_name.hdr.tag_type = PTT_AC_NAME;
- neg->ac_name.hdr.tag_len =
- htons((u_int16_t)ourmsg->data_len);
- if (ourmsg->data_len) {
- bcopy(ourmsg->data,
- neg->ac_name.data, ourmsg->data_len);
+ neg->ac_name.hdr.tag_len = htons(datalen);
+ if (datalen) {
+ bcopy(ourmsg->data, neg->ac_name.data, datalen);
}
- neg->ac_name_len = ourmsg->data_len;
+ neg->ac_name_len = datalen;
neg->pkt->pkt_header.ph.code = PADO_CODE;
/*
* Wait for PADI packet coming from hook
@@ -1514,7 +1607,7 @@ pppoe_send_event(sessp sp, enum cmd cmdid)
struct ngpppoe_sts *sts;
AAA
- NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
+ NG_MKMESSAGE(msg, sp->typecookie, cmdid,
sizeof(struct ngpppoe_sts), M_NOWAIT);
sts = (struct ngpppoe_sts *)msg->data;
strncpy(sts->hook, sp->hook->name, NG_HOOKLEN + 1);
diff --git a/sys/netgraph/ng_pppoe.h b/sys/netgraph/ng_pppoe.h
index fd1fbd3..c357ecd 100644
--- a/sys/netgraph/ng_pppoe.h
+++ b/sys/netgraph/ng_pppoe.h
@@ -49,7 +49,7 @@
/* Node type name. This should be unique among all netgraph node types */
#define NG_PPPOE_NODE_TYPE "pppoe"
-#define NGM_PPPOE_COOKIE 939032003
+#define NGM_PPPOE_COOKIE 939032004
/* Number of active sessions we can handle */
#define PPPOE_NUM_SESSIONS 16 /* for now */
@@ -86,6 +86,15 @@ struct ngpppoestat {
u_int packets_out; /* packets out towards ethernet */
};
+/* Keep this in sync with the above structure definition */
+#define NG_PPPOESTAT_TYPE_INFO { \
+ { \
+ { "packets_in", &ng_parse_uint_type }, \
+ { "packets_out", &ng_parse_uint_type }, \
+ { NULL } \
+ } \
+}
+
/*
* When this structure is accepted by the NGM_PPPOE_CONNECT command :
* The data field is MANDATORY.
@@ -106,10 +115,18 @@ struct ngpppoestat {
*/
struct ngpppoe_init_data {
char hook[NG_HOOKLEN + 1]; /* hook to monitor on */
- u_int16_t data_len; /* Length of the service name */
- char data[0]; /* init data goes here */
+ char data[1]; /* init data goes here */
};
+/* Keep this in sync with the above structure definition */
+#define NG_PPPOE_INIT_DATA_TYPE_INFO { \
+ { \
+ { "hook", &ng_parse_hookbuf_type }, \
+ { "data", &ng_parse_string_type }, \
+ { NULL } \
+ } \
+}
+
/*
* This structure is used by the asychronous success and failure messages.
* (to report which hook has failed or connected). The message is sent
@@ -119,6 +136,14 @@ struct ngpppoe_sts {
char hook[NG_HOOKLEN + 1]; /* hook associated with event session */
};
+/* Keep this in sync with the above structure definition */
+#define NG_PPPOE_STS_TYPE_INFO { \
+ { \
+ { "hook", &ng_parse_hookbuf_type }, \
+ { NULL } \
+ } \
+}
+
/********************************************************************
* Constants and definitions specific to pppoe
OpenPOWER on IntegriCloud