6 * Copyright (c) 1996-1999 Whistle Communications, Inc.
9 * Subject to the following obligations and disclaimer of warranty, use and
10 * redistribution of this software, in source or object code forms, with or
11 * without modifications are expressly permitted by Whistle Communications;
12 * provided, however, that:
13 * 1. Any and all reproductions of the source or object code must include the
14 * copyright notice above and the following disclaimer of warranties; and
15 * 2. No rights are granted, in any manner or form, to use Whistle
16 * Communications, Inc. trademarks, including the mark "WHISTLE
17 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
18 * such appears in the above copyright notice or in the software.
20 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
21 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
22 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
23 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
25 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
26 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
27 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
28 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
29 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
30 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
31 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
38 * Author: Julian Elischer <julian@freebsd.org>
41 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
44 #define DBG do { printf("ng_device: %s\n", __func__ ); } while (0)
46 #define DBG do {} while (0)
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
53 #include <sys/malloc.h>
54 #include <sys/errno.h>
55 #include <sys/syslog.h>
56 #include <net/ethernet.h>
58 #include <netgraph/ng_message.h>
59 #include <netgraph/netgraph.h>
60 #include <netgraph/ng_parse.h>
61 #include <netgraph/ng_pppoe.h>
63 #ifdef NG_SEPARATE_MALLOC
64 MALLOC_DEFINE(M_NETGRAPH_PPPOE, "netgraph_pppoe", "netgraph pppoe node");
66 #define M_NETGRAPH_PPPOE M_NETGRAPH
69 #define SIGNOFF "session closed"
70 #define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
73 * This section contains the netgraph method declarations for the
74 * pppoe node. These methods define the netgraph pppoe 'type'.
77 static ng_constructor_t ng_pppoe_constructor;
78 static ng_rcvmsg_t ng_pppoe_rcvmsg;
79 static ng_shutdown_t ng_pppoe_shutdown;
80 static ng_newhook_t ng_pppoe_newhook;
81 static ng_rcvdata_t ng_pppoe_rcvdata;
82 static ng_disconnect_t ng_pppoe_disconnect;
84 /* Parse type for struct ngpppoe_init_data */
85 static const struct ng_parse_struct_field ngpppoe_init_data_type_fields[]
86 = NG_PPPOE_INIT_DATA_TYPE_INFO;
87 static const struct ng_parse_type ngpppoe_init_data_state_type = {
88 &ng_parse_struct_type,
89 &ngpppoe_init_data_type_fields
92 /* Parse type for struct ngpppoe_sts */
93 static const struct ng_parse_struct_field ng_pppoe_sts_type_fields[]
94 = NG_PPPOE_STS_TYPE_INFO;
95 static const struct ng_parse_type ng_pppoe_sts_state_type = {
96 &ng_parse_struct_type,
97 &ng_pppoe_sts_type_fields
100 /* List of commands and how to convert arguments to/from ASCII */
101 static const struct ng_cmdlist ng_pppoe_cmds[] = {
106 &ngpppoe_init_data_state_type,
113 &ngpppoe_init_data_state_type,
120 &ngpppoe_init_data_state_type,
127 &ngpppoe_init_data_state_type,
134 &ng_pppoe_sts_state_type,
141 &ng_pppoe_sts_state_type,
148 &ng_pppoe_sts_state_type,
155 &ng_parse_string_type,
163 &ng_parse_string_type
168 /* Netgraph node type descriptor */
169 static struct ng_type typestruct = {
170 .version = NG_ABI_VERSION,
171 .name = NG_PPPOE_NODE_TYPE,
172 .constructor = ng_pppoe_constructor,
173 .rcvmsg = ng_pppoe_rcvmsg,
174 .shutdown = ng_pppoe_shutdown,
175 .newhook = ng_pppoe_newhook,
176 .rcvdata = ng_pppoe_rcvdata,
177 .disconnect = ng_pppoe_disconnect,
178 .cmdlist = ng_pppoe_cmds,
180 NETGRAPH_INIT(pppoe, &typestruct);
183 * States for the session state machine.
184 * These have no meaning if there is no hook attached yet.
187 PPPOE_SNONE=0, /* [both] Initial state */
188 PPPOE_LISTENING, /* [Daemon] Listening for discover initiation pkt */
189 PPPOE_SINIT, /* [Client] Sent discovery initiation */
190 PPPOE_PRIMED, /* [Server] Awaiting PADI from daemon */
191 PPPOE_SOFFER, /* [Server] Sent offer message (got PADI)*/
192 PPPOE_SREQ, /* [Client] Sent a Request */
193 PPPOE_NEWCONNECTED, /* [Server] Connection established, No data received */
194 PPPOE_CONNECTED, /* [Both] Connection established, Data received */
195 PPPOE_DEAD /* [Both] */
198 #define NUMTAGS 20 /* number of tags we are set up to work with */
201 * Information we store for each hook on each node for negotiating the
202 * session. The mbuf and cluster are freed once negotiation has completed.
203 * The whole negotiation block is then discarded.
207 struct mbuf *m; /* holds cluster with last sent packet */
208 union packet *pkt; /* points within the above cluster */
209 struct callout handle; /* see timeout(9) */
210 u_int timeout; /* 0,1,2,4,8,16 etc. seconds */
212 const struct pppoe_tag *tags[NUMTAGS];
216 struct datatag service;
217 struct datatag ac_name;
219 typedef struct sess_neg *negp;
222 * Session information that is needed after connection.
226 u_int16_t Session_ID;
228 ng_ID_t creator; /* who to notify */
229 struct pppoe_full_hdr pkt_hdr; /* used when connected */
230 negp neg; /* used when negotiating */
231 /*struct sess_con *hash_next;*/ /* not yet used */
233 typedef struct sess_con *sessp;
235 #define NG_PPPOE_SESSION_NODE(sp) NG_HOOK_NODE(sp->hook)
238 PPPOE_STANDARD = 1, /* standard RFC2516 mode */
239 PPPOE_NONSTANDARD, /* 3Com proprietary mode */
242 struct ng_pppoe_mode_t {
244 const struct ether_header *eh_prototype;
248 static const struct ether_header eh_standard =
249 {{0xff,0xff,0xff,0xff,0xff,0xff},
250 {0x00,0x00,0x00,0x00,0x00,0x00},
251 ETHERTYPE_PPPOE_DISC};
253 static const struct ether_header eh_3Com =
254 {{0xff,0xff,0xff,0xff,0xff,0xff},
255 {0x00,0x00,0x00,0x00,0x00,0x00},
256 ETHERTYPE_PPPOE_STUPID_DISC};
258 static const struct ng_pppoe_mode_t ng_pppoe_modes[] = {
259 { PPPOE_STANDARD, &eh_standard, NG_PPPOE_STANDARD },
260 { PPPOE_NONSTANDARD, &eh_3Com, NG_PPPOE_NONSTANDARD },
265 * Information we store for each node
268 node_p node; /* back pointer to node */
269 hook_p ethernet_hook;
271 u_int packets_in; /* packets in from ethernet */
272 u_int packets_out; /* packets out towards ethernet */
274 const struct ng_pppoe_mode_t *mode; /* standard PPPoE or 3Com? */
275 /*struct sess_con *buckets[HASH_SIZE];*/ /* not yet used */
277 typedef struct PPPOE *priv_p;
280 char bytes[sizeof(void *)];
284 #define LEAVE(x) do { error = x; goto quit; } while(0)
285 static void pppoe_start(sessp sp);
286 static void sendpacket(sessp sp);
287 static void pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2);
288 static const struct pppoe_tag *scan_tags(sessp sp,
289 const struct pppoe_hdr* ph);
290 static int pppoe_send_event(sessp sp, enum cmd cmdid);
292 /*************************************************************************
293 * Some basic utilities from the Linux version with author's permission.*
294 * Author: Michal Ostrowski <mostrows@styx.uwaterloo.ca> *
295 ************************************************************************/
298 * Generate a new session id
299 * XXX find out the FreeBSD locking scheme.
302 get_new_sid(node_p node)
304 static int pppoe_sid = 10;
308 priv_p privp = NG_NODE_PRIVATE(node);
314 * Spec says 0xFFFF is reserved.
315 * Also don't use 0x0000
322 /* Check it isn't already in use */
323 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
324 /* don't check special hooks */
325 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
326 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
328 sp = NG_HOOK_PRIVATE(hook);
329 if (sp->Session_ID == val)
338 * Return the location where the next tag can be put
340 static __inline const struct pppoe_tag*
341 next_tag(const struct pppoe_hdr* ph)
343 return (const struct pppoe_tag*)(((const char*)&ph->tag[0])
344 + ntohs(ph->length));
348 * Look for a tag of a specific type
349 * Don't trust any length the other end says.
350 * but assume we already sanity checked ph->length.
352 static const struct pppoe_tag*
353 get_tag(const struct pppoe_hdr* ph, u_int16_t idx)
355 const char *const end = (const char *)next_tag(ph);
357 const struct pppoe_tag *pt = &ph->tag[0];
359 * Keep processing tags while a tag header will still fit.
362 while((const char*)(pt + 1) <= end) {
364 * If the tag data would go past the end of the packet, abort.
366 ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
370 if(pt->tag_type == idx)
373 pt = (const struct pppoe_tag*)ptn;
378 /**************************************************************************
379 * inlines to initialise or add tags to a session's tag list,
380 **************************************************************************/
382 * Initialise the session's tag list
388 if(sp->neg == NULL) {
389 printf("pppoe: asked to init NULL neg pointer\n");
392 sp->neg->numtags = 0;
396 insert_tag(sessp sp, const struct pppoe_tag *tp)
402 if((neg = sp->neg) == NULL) {
403 printf("pppoe: asked to use NULL neg pointer\n");
406 if ((i = neg->numtags++) < NUMTAGS) {
409 printf("pppoe: asked to add too many tags to packet\n");
415 * Make up a packet, using the tags filled out for the session.
417 * Assume that the actual pppoe header and ethernet header
418 * are filled out externally to this routine.
419 * Also assume that neg->wh points to the correct
420 * location at the front of the buffer space.
423 make_packet(sessp sp) {
424 struct pppoe_full_hdr *wh = &sp->neg->pkt->pkt_header;
425 const struct pppoe_tag **tag;
429 u_int16_t length = 0;
432 if ((sp->neg == NULL) || (sp->neg->m == NULL)) {
433 printf("pppoe: make_packet called from wrong state\n");
435 dp = (char *)wh->ph.tag;
436 for (count = 0, tag = sp->neg->tags;
437 ((count < sp->neg->numtags) && (count < NUMTAGS));
439 tlen = ntohs((*tag)->tag_len) + sizeof(**tag);
440 if ((length + tlen) > (ETHER_MAX_LEN - 4 - sizeof(*wh))) {
441 printf("pppoe: tags too long\n");
442 sp->neg->numtags = count;
443 break; /* XXX chop off what's too long */
445 bcopy(*tag, (char *)dp, tlen);
449 wh->ph.length = htons(length);
450 sp->neg->m->m_len = length + sizeof(*wh);
451 sp->neg->m->m_pkthdr.len = length + sizeof(*wh);
454 /**************************************************************************
455 * Routine to match a service offered *
456 **************************************************************************/
458 * Find a hook that has a service string that matches that
459 * we are seeking. for now use a simple string.
460 * In the future we may need something like regexp().
461 * for testing allow a null string to match 1st found and a null service
462 * to match all requests. Also make '*' do the same.
465 #define NG_MATCH_EXACT 1
466 #define NG_MATCH_ANY 2
469 pppoe_match_svc(node_p node, const char *svc_name, int svc_len, int match)
473 priv_p privp = NG_NODE_PRIVATE(node);
474 hook_p allhook = NULL;
478 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
480 /* skip any hook that is debug or ethernet */
481 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
482 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
484 sp = NG_HOOK_PRIVATE(hook);
486 /* Skip any sessions which are not in LISTEN mode. */
487 if ( sp->state != PPPOE_LISTENING)
492 /* Special case for a blank or "*" service name (wildcard) */
493 if (match == NG_MATCH_ANY && neg->service_len == 1 &&
494 neg->service.data[0] == '*') {
499 /* If the lengths don't match, that aint it. */
500 if (neg->service_len != svc_len)
503 /* An exact match? */
507 if (strncmp(svc_name, neg->service.data, svc_len) == 0)
510 return (hook ? hook : allhook);
512 /**************************************************************************
513 * Routine to find a particular session that matches an incoming packet *
514 **************************************************************************/
516 pppoe_findsession(node_p node, const struct pppoe_full_hdr *wh)
520 priv_p privp = NG_NODE_PRIVATE(node);
521 u_int16_t session = ntohs(wh->ph.sid);
524 * find matching peer/session combination.
527 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
528 /* don't check special hooks */
529 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
530 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) {
533 sp = NG_HOOK_PRIVATE(hook);
534 if ( ( (sp->state == PPPOE_CONNECTED)
535 || (sp->state == PPPOE_NEWCONNECTED) )
536 && (sp->Session_ID == session)
537 && (bcmp(sp->pkt_hdr.eh.ether_dhost,
539 ETHER_ADDR_LEN)) == 0) {
547 pppoe_finduniq(node_p node, const struct pppoe_tag *tag)
550 priv_p privp = NG_NODE_PRIVATE(node);
554 bcopy(tag->tag_data, uniq.bytes, sizeof(void *));
555 /* cycle through all known hooks */
556 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
557 /* don't check special hooks */
558 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
559 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
561 if (uniq.pointer == NG_HOOK_PRIVATE(hook))
567 /**************************************************************************
568 * start of Netgraph entrypoints *
569 **************************************************************************/
572 * Allocate the private data structure and the generic node
573 * and link them together.
575 * ng_make_node_common() returns with a generic node struct
576 * with a single reference for us.. we transfer it to the
577 * private structure.. when we free the private struct we must
578 * unref the node so it gets freed too.
581 ng_pppoe_constructor(node_p node)
586 /* Initialize private descriptor */
587 MALLOC(privdata, priv_p, sizeof(*privdata), M_NETGRAPH_PPPOE,
589 if (privdata == NULL)
592 /* Link structs together; this counts as our one reference to *nodep */
593 NG_NODE_SET_PRIVATE(node, privdata);
594 privdata->node = node;
596 /* Initialize to standard mode (the first one in ng_pppoe_modes[]). */
597 privdata->mode = &ng_pppoe_modes[0];
603 * Give our ok for a hook to be added...
604 * point the hook's private info to the hook structure.
606 * The following hook names are special:
607 * Ethernet: the hook that should be connected to a NIC.
608 * debug: copies of data sent out here (when I write the code).
609 * All other hook names need only be unique. (the framework checks this).
612 ng_pppoe_newhook(node_p node, hook_p hook, const char *name)
614 const priv_p privp = NG_NODE_PRIVATE(node);
618 if (strcmp(name, NG_PPPOE_HOOK_ETHERNET) == 0) {
619 privp->ethernet_hook = hook;
620 NG_HOOK_SET_PRIVATE(hook, &privp->ethernet_hook);
621 } else if (strcmp(name, NG_PPPOE_HOOK_DEBUG) == 0) {
622 privp->debug_hook = hook;
623 NG_HOOK_SET_PRIVATE(hook, &privp->debug_hook);
626 * Any other unique name is OK.
627 * The infrastructure has already checked that it's unique,
628 * so just allocate it and hook it in.
630 MALLOC(sp, sessp, sizeof(*sp), M_NETGRAPH_PPPOE, M_NOWAIT | M_ZERO);
635 NG_HOOK_SET_PRIVATE(hook, sp);
642 * Get a netgraph control message.
643 * Check it is one we understand. If needed, send a response.
644 * We sometimes save the address for an async action later.
645 * Always free the message.
648 ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
650 priv_p privp = NG_NODE_PRIVATE(node);
651 struct ngpppoe_init_data *ourmsg = NULL;
652 struct ng_mesg *resp = NULL;
660 NGI_GET_MSG(item, msg);
661 /* Deal with message according to cookie and command */
662 switch (msg->header.typecookie) {
663 case NGM_PPPOE_COOKIE:
664 switch (msg->header.cmd) {
665 case NGM_PPPOE_CONNECT:
666 case NGM_PPPOE_LISTEN:
667 case NGM_PPPOE_OFFER:
668 case NGM_PPPOE_SERVICE:
669 ourmsg = (struct ngpppoe_init_data *)msg->data;
670 if (msg->header.arglen < sizeof(*ourmsg)) {
671 printf("pppoe: init data too small\n");
674 if (msg->header.arglen - sizeof(*ourmsg) >
675 PPPOE_SERVICE_NAME_SIZE) {
676 printf("pppoe_rcvmsg: service name too big");
679 if (msg->header.arglen - sizeof(*ourmsg) <
681 printf("pppoe: init data has bad length,"
682 " %d should be %zd\n", ourmsg->data_len,
683 msg->header.arglen - sizeof (*ourmsg));
687 /* make sure strcmp will terminate safely */
688 ourmsg->hook[sizeof(ourmsg->hook) - 1] = '\0';
690 /* cycle through all known hooks */
691 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
692 if (NG_HOOK_NAME(hook)
693 && strcmp(NG_HOOK_NAME(hook), ourmsg->hook) == 0)
699 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
700 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) {
703 sp = NG_HOOK_PRIVATE(hook);
705 if (msg->header.cmd == NGM_PPPOE_LISTEN) {
707 * Ensure we aren't already listening for this
710 if (pppoe_match_svc(node, ourmsg->data,
711 ourmsg->data_len, NG_MATCH_EXACT) != NULL) {
717 * PPPOE_SERVICE advertisments are set up
718 * on sessions that are in PRIMED state.
720 if (msg->header.cmd == NGM_PPPOE_SERVICE) {
723 if (sp->state != PPPOE_SNONE) {
724 printf("pppoe: Session already active\n");
729 * set up prototype header
731 MALLOC(neg, negp, sizeof(*neg), M_NETGRAPH_PPPOE,
735 printf("pppoe: Session out of memory\n");
738 MGETHDR(neg->m, M_DONTWAIT, MT_DATA);
740 printf("pppoe: Session out of mbufs\n");
741 FREE(neg, M_NETGRAPH_PPPOE);
744 neg->m->m_pkthdr.rcvif = NULL;
745 MCLGET(neg->m, M_DONTWAIT);
746 if ((neg->m->m_flags & M_EXT) == 0) {
747 printf("pppoe: Session out of mcls\n");
749 FREE(neg, M_NETGRAPH_PPPOE);
753 ng_callout_init(&neg->handle);
754 neg->m->m_len = sizeof(struct pppoe_full_hdr);
755 neg->pkt = mtod(neg->m, union packet*);
756 memcpy((void *)&neg->pkt->pkt_header.eh,
757 (const void *)privp->mode->eh_prototype,
758 sizeof(struct ether_header));
759 neg->pkt->pkt_header.ph.ver = 0x1;
760 neg->pkt->pkt_header.ph.type = 0x1;
761 neg->pkt->pkt_header.ph.sid = 0x0000;
764 sp->creator = NGI_RETADDR(item);
766 switch (msg->header.cmd) {
767 case NGM_PPPOE_GET_STATUS:
769 struct ngpppoestat *stats;
771 NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
775 stats = (struct ngpppoestat *) resp->data;
776 stats->packets_in = privp->packets_in;
777 stats->packets_out = privp->packets_out;
780 case NGM_PPPOE_CONNECT:
782 * Check the hook exists and is Uninitialised.
783 * Send a PADI request, and start the timeout logic.
784 * Store the originator of this message so we can send
785 * a success of fail message to them later.
786 * Move the session to SINIT
787 * Set up the session to the correct state and
790 neg->service.hdr.tag_type = PTT_SRV_NAME;
791 neg->service.hdr.tag_len =
792 htons((u_int16_t)ourmsg->data_len);
793 if (ourmsg->data_len)
794 bcopy(ourmsg->data, neg->service.data,
796 neg->service_len = ourmsg->data_len;
799 case NGM_PPPOE_LISTEN:
801 * Check the hook exists and is Uninitialised.
802 * Install the service matching string.
803 * Store the originator of this message so we can send
804 * a success of fail message to them later.
805 * Move the hook to 'LISTENING'
807 neg->service.hdr.tag_type = PTT_SRV_NAME;
808 neg->service.hdr.tag_len =
809 htons((u_int16_t)ourmsg->data_len);
811 if (ourmsg->data_len)
812 bcopy(ourmsg->data, neg->service.data,
814 neg->service_len = ourmsg->data_len;
815 neg->pkt->pkt_header.ph.code = PADT_CODE;
817 * wait for PADI packet coming from ethernet
819 sp->state = PPPOE_LISTENING;
821 case NGM_PPPOE_OFFER:
823 * Check the hook exists and is Uninitialised.
824 * Store the originator of this message so we can send
825 * a success of fail message to them later.
826 * Store the AC-Name given and go to PRIMED.
828 neg->ac_name.hdr.tag_type = PTT_AC_NAME;
829 neg->ac_name.hdr.tag_len =
830 htons((u_int16_t)ourmsg->data_len);
831 if (ourmsg->data_len)
832 bcopy(ourmsg->data, neg->ac_name.data,
834 neg->ac_name_len = ourmsg->data_len;
835 neg->pkt->pkt_header.ph.code = PADO_CODE;
837 * Wait for PADI packet coming from hook
839 sp->state = PPPOE_PRIMED;
841 case NGM_PPPOE_SERVICE:
843 * Check the session is primed.
844 * for now just allow ONE service to be advertised.
845 * If you do it twice you just overwrite.
847 if (sp->state != PPPOE_PRIMED) {
848 printf("pppoe: Session not primed\n");
852 neg->service.hdr.tag_type = PTT_SRV_NAME;
853 neg->service.hdr.tag_len =
854 htons((u_int16_t)ourmsg->data_len);
856 if (ourmsg->data_len)
857 bcopy(ourmsg->data, neg->service.data,
859 neg->service_len = ourmsg->data_len;
861 case NGM_PPPOE_SETMODE:
863 const struct ng_pppoe_mode_t *mode;
867 if (msg->header.arglen == 0)
870 s = (char *)msg->data;
871 len = msg->header.arglen - 1;
873 /* Search for matching mode string */
874 for (mode = ng_pppoe_modes; mode->id != 0; mode++ )
875 if ((strlen(mode->name) == len) &&
876 !strncmp(mode->name, s, len))
885 case NGM_PPPOE_GETMODE:
886 NG_MKRESPONSE(resp, msg, strlen(privp->mode->name) + 1,
890 strlcpy((char *)resp->data, privp->mode->name,
891 strlen(privp->mode->name) + 1);
901 /* Take care of synchronous response, if any */
903 NG_RESPOND_MSG(error, node, item, resp);
904 /* Free the message and return */
910 * Start a client into the first state. A separate function because
911 * it can be needed if the negotiation times out.
914 pppoe_start(sessp sp)
916 priv_p privp = NG_NODE_PRIVATE(NG_PPPOE_SESSION_NODE(sp));
918 struct pppoe_tag hdr;
923 * kick the state machine into starting up
926 sp->state = PPPOE_SINIT;
927 /* Reset the packet header to broadcast. Since we are in a client
928 * mode use configured ethertype. */
929 memcpy((void *)&sp->neg->pkt->pkt_header.eh,
930 (const void *)privp->mode->eh_prototype,
931 sizeof(struct ether_header));
932 sp->neg->pkt->pkt_header.ph.code = PADI_CODE;
933 uniqtag.hdr.tag_type = PTT_HOST_UNIQ;
934 uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(uniqtag.data));
935 uniqtag.data.pointer = sp;
937 insert_tag(sp, &uniqtag.hdr);
938 insert_tag(sp, &sp->neg->service.hdr);
944 send_acname(sessp sp, const struct pppoe_tag *tag)
948 struct ngpppoe_sts *sts;
950 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, NGM_PPPOE_ACNAME,
951 sizeof(struct ngpppoe_sts), M_NOWAIT);
955 sts = (struct ngpppoe_sts *)msg->data;
956 tlen = min(NG_HOOKSIZ - 1, ntohs(tag->tag_len));
957 strncpy(sts->hook, tag->tag_data, tlen);
958 sts->hook[tlen] = '\0';
959 NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
965 send_sessionid(sessp sp)
970 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, NGM_PPPOE_SESSIONID,
971 sizeof(u_int16_t), M_NOWAIT);
975 *(u_int16_t *)msg->data = sp->Session_ID;
976 NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
982 * Receive data, and do something with it.
983 * The caller will never free m, so if we use up this data
984 * or abort we must free it.
987 ng_pppoe_rcvdata(hook_p hook, item_p item)
989 node_p node = NG_HOOK_NODE(hook);
990 const priv_p privp = NG_NODE_PRIVATE(node);
991 sessp sp = NG_HOOK_PRIVATE(hook);
992 const struct pppoe_full_hdr *wh;
993 const struct pppoe_hdr *ph;
998 const struct pppoe_tag *utag = NULL, *tag = NULL;
1001 struct pppoe_tag hdr;
1009 if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) {
1011 * Data from the debug hook gets sent without modification
1012 * straight to the ethernet.
1014 NG_FWD_ITEM_HOOK( error, item, privp->ethernet_hook);
1015 privp->packets_out++;
1016 } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) {
1019 * Dig out various fields from the packet.
1020 * use them to decide where to send it.
1023 privp->packets_in++;
1024 if( m->m_len < sizeof(*wh)) {
1025 m = m_pullup(m, sizeof(*wh)); /* Checks length */
1027 printf("couldn't m_pullup\n");
1031 wh = mtod(m, struct pppoe_full_hdr *);
1032 length = ntohs(wh->ph.length);
1033 switch(wh->eh.ether_type) {
1034 case ETHERTYPE_PPPOE_STUPID_DISC: /* fall through */
1035 case ETHERTYPE_PPPOE_DISC:
1037 * We need to try to make sure that the tag area
1038 * is contiguous, or we could wander off the end
1039 * of a buffer and make a mess.
1040 * (Linux wouldn't have this problem).
1042 if (m->m_pkthdr.len <= MHLEN) {
1043 if( m->m_len < m->m_pkthdr.len) {
1044 m = m_pullup(m, m->m_pkthdr.len);
1046 printf("couldn't m_pullup\n");
1051 if (m->m_len != m->m_pkthdr.len) {
1053 * It's not all in one piece.
1054 * We need to do extra work.
1055 * Put it into a cluster.
1058 n = m_dup(m, M_DONTWAIT);
1062 /* just check we got a cluster */
1063 if (m->m_len != m->m_pkthdr.len) {
1069 printf("packet fragmented\n");
1073 wh = mtod(m, struct pppoe_full_hdr *);
1074 length = ntohs(wh->ph.length);
1076 session = ntohs(wh->ph.sid);
1083 * Look for a hook with the required service
1084 * and send the ENTIRE packet up there.
1085 * It should come back to a new hook in
1086 * PRIMED state. Look there for further
1089 tag = get_tag(ph, PTT_SRV_NAME);
1091 printf("no service tag\n");
1094 sendhook = pppoe_match_svc(NG_HOOK_NODE(hook),
1095 tag->tag_data, ntohs(tag->tag_len),
1098 NG_FWD_NEW_DATA(error, item,
1107 * Use the host_uniq tag to find the
1108 * hook this is in response to.
1109 * Received #2, now send #3
1110 * For now simply accept the first we receive.
1112 utag = get_tag(ph, PTT_HOST_UNIQ);
1114 || (ntohs(utag->tag_len) != sizeof(sp))) {
1115 printf("no host unique field\n");
1119 sendhook = pppoe_finduniq(node, utag);
1120 if (sendhook == NULL) {
1121 printf("no matching session\n");
1126 * Check the session is in the right state.
1127 * It needs to be in PPPOE_SINIT.
1129 sp = NG_HOOK_PRIVATE(sendhook);
1130 if (sp->state != PPPOE_SINIT) {
1131 printf("session in wrong state\n");
1135 ng_uncallout(&neg->handle, node);
1138 * This is the first time we hear
1139 * from the server, so note it's
1140 * unicast address, replacing the
1141 * broadcast address .
1143 bcopy(wh->eh.ether_shost,
1144 neg->pkt->pkt_header.eh.ether_dhost,
1147 neg->pkt->pkt_header.ph.code = PADR_CODE;
1149 insert_tag(sp, utag); /* Host Unique */
1150 if ((tag = get_tag(ph, PTT_AC_COOKIE)))
1151 insert_tag(sp, tag); /* return cookie */
1152 if ((tag = get_tag(ph, PTT_AC_NAME))) {
1153 insert_tag(sp, tag); /* return it */
1154 send_acname(sp, tag);
1156 insert_tag(sp, &neg->service.hdr); /* Service */
1159 sp->state = PPPOE_SREQ;
1166 * Use the ac_cookie tag to find the
1167 * hook this is in response to.
1169 utag = get_tag(ph, PTT_AC_COOKIE);
1171 || (ntohs(utag->tag_len) != sizeof(sp))) {
1175 sendhook = pppoe_finduniq(node, utag);
1176 if (sendhook == NULL) {
1181 * Check the session is in the right state.
1182 * It needs to be in PPPOE_SOFFER
1183 * or PPPOE_NEWCONNECTED. If the latter,
1184 * then this is a retry by the client.
1185 * so be nice, and resend.
1187 sp = NG_HOOK_PRIVATE(sendhook);
1188 if (sp->state == PPPOE_NEWCONNECTED) {
1190 * Whoa! drop back to resend that
1192 * We should still have a copy of it.
1194 sp->state = PPPOE_SOFFER;
1196 if (sp->state != PPPOE_SOFFER) {
1197 LEAVE (ENETUNREACH);
1201 ng_uncallout(&neg->handle, node);
1202 neg->pkt->pkt_header.ph.code = PADS_CODE;
1203 if (sp->Session_ID == 0)
1204 neg->pkt->pkt_header.ph.sid =
1205 htons(sp->Session_ID
1206 = get_new_sid(node));
1210 * start working out the tags to respond with.
1213 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
1214 if ((tag = get_tag(ph, PTT_SRV_NAME)))
1215 insert_tag(sp, tag);/* return service */
1216 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1217 insert_tag(sp, tag); /* return it */
1218 insert_tag(sp, utag); /* ac_cookie */
1221 sp->state = PPPOE_NEWCONNECTED;
1224 * Having sent the last Negotiation header,
1225 * Set up the stored packet header to
1226 * be correct for the actual session.
1227 * But keep the negotialtion stuff
1228 * around in case we need to resend this last
1229 * packet. We'll discard it when we move
1230 * from NEWCONNECTED to CONNECTED
1232 sp->pkt_hdr = neg->pkt->pkt_header;
1233 /* Configure ethertype depending on what
1234 * ethertype was used at discovery phase */
1235 if (sp->pkt_hdr.eh.ether_type ==
1236 ETHERTYPE_PPPOE_STUPID_DISC)
1237 sp->pkt_hdr.eh.ether_type
1238 = ETHERTYPE_PPPOE_STUPID_SESS;
1240 sp->pkt_hdr.eh.ether_type
1241 = ETHERTYPE_PPPOE_SESS;
1242 sp->pkt_hdr.ph.code = 0;
1243 pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
1248 * Use the host_uniq tag to find the
1249 * hook this is in response to.
1250 * take the session ID and store it away.
1251 * Also make sure the pre-made header is
1252 * correct and set us into Session mode.
1254 utag = get_tag(ph, PTT_HOST_UNIQ);
1256 || (ntohs(utag->tag_len) != sizeof(sp))) {
1257 LEAVE (ENETUNREACH);
1260 sendhook = pppoe_finduniq(node, utag);
1261 if (sendhook == NULL) {
1266 * Check the session is in the right state.
1267 * It needs to be in PPPOE_SREQ.
1269 sp = NG_HOOK_PRIVATE(sendhook);
1270 if (sp->state != PPPOE_SREQ) {
1274 ng_uncallout(&neg->handle, node);
1275 neg->pkt->pkt_header.ph.sid = wh->ph.sid;
1276 sp->Session_ID = ntohs(wh->ph.sid);
1279 sp->state = PPPOE_CONNECTED;
1281 * Now we have gone to Connected mode,
1282 * Free all resources needed for
1284 * Keep a copy of the header we will be using.
1286 sp->pkt_hdr = neg->pkt->pkt_header;
1287 if (privp->mode->id == PPPOE_NONSTANDARD)
1288 sp->pkt_hdr.eh.ether_type
1289 = ETHERTYPE_PPPOE_STUPID_SESS;
1291 sp->pkt_hdr.eh.ether_type
1292 = ETHERTYPE_PPPOE_SESS;
1293 sp->pkt_hdr.ph.code = 0;
1295 FREE(sp->neg, M_NETGRAPH_PPPOE);
1297 pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
1301 * Send a 'close' message to the controlling
1302 * process (the one that set us up);
1303 * And then tear everything down.
1305 * Find matching peer/session combination.
1307 sendhook = pppoe_findsession(node, wh);
1308 if (sendhook == NULL) {
1311 /* send message to creator */
1314 ng_rmhook_self(sendhook);
1318 LEAVE(EPFNOSUPPORT);
1321 case ETHERTYPE_PPPOE_STUPID_SESS:
1322 case ETHERTYPE_PPPOE_SESS:
1324 * find matching peer/session combination.
1326 sendhook = pppoe_findsession(node, wh);
1327 if (sendhook == NULL) {
1328 LEAVE (ENETUNREACH);
1331 sp = NG_HOOK_PRIVATE(sendhook);
1332 m_adj(m, sizeof(*wh));
1333 if (m->m_pkthdr.len < length) {
1334 /* Packet too short, dump it */
1338 /* Also need to trim excess at the end */
1339 if (m->m_pkthdr.len > length) {
1340 m_adj(m, -((int)(m->m_pkthdr.len - length)));
1342 if ( sp->state != PPPOE_CONNECTED) {
1343 if (sp->state == PPPOE_NEWCONNECTED) {
1344 sp->state = PPPOE_CONNECTED;
1346 * Now we have gone to Connected mode,
1347 * Free all resources needed for
1348 * negotiation. Be paranoid about
1349 * whether there may be a timeout.
1351 m_freem(sp->neg->m);
1352 ng_uncallout(&sp->neg->handle, node);
1353 FREE(sp->neg, M_NETGRAPH_PPPOE);
1356 LEAVE (ENETUNREACH);
1360 NG_FWD_NEW_DATA( error, item, sendhook, m);
1363 LEAVE(EPFNOSUPPORT);
1367 * Not ethernet or debug hook..
1369 * The packet has come in on a normal hook.
1370 * We need to find out what kind of hook,
1371 * So we can decide how to handle it.
1372 * Check the hook's state.
1374 sp = NG_HOOK_PRIVATE(hook);
1375 switch (sp->state) {
1376 case PPPOE_NEWCONNECTED:
1377 case PPPOE_CONNECTED: {
1378 static const u_char addrctrl[] = { 0xff, 0x03 };
1379 struct pppoe_full_hdr *wh;
1382 * Remove PPP address and control fields, if any.
1383 * For example, ng_ppp(4) always sends LCP packets
1384 * with address and control fields as required by
1385 * generic PPP. PPPoE is an exception to the rule.
1387 if (m->m_pkthdr.len >= 2) {
1388 if (m->m_len < 2 && !(m = m_pullup(m, 2)))
1390 if (bcmp(mtod(m, u_char *), addrctrl, 2) == 0)
1394 * Bang in a pre-made header, and set the length up
1395 * to be correct. Then send it to the ethernet driver.
1396 * But first correct the length.
1398 sp->pkt_hdr.ph.length = htons((short)(m->m_pkthdr.len));
1399 M_PREPEND(m, sizeof(*wh), M_DONTWAIT);
1403 wh = mtod(m, struct pppoe_full_hdr *);
1404 bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
1405 NG_FWD_NEW_DATA( error, item, privp->ethernet_hook, m);
1406 privp->packets_out++;
1411 * A PADI packet is being returned by the application
1412 * that has set up this hook. This indicates that it
1413 * wants us to offer service.
1416 if (m->m_len < sizeof(*wh)) {
1417 m = m_pullup(m, sizeof(*wh));
1422 wh = mtod(m, struct pppoe_full_hdr *);
1424 session = ntohs(wh->ph.sid);
1425 length = ntohs(wh->ph.length);
1427 /* Use peers mode in session */
1428 neg->pkt->pkt_header.eh.ether_type = wh->eh.ether_type;
1429 if ( code != PADI_CODE) {
1432 ng_uncallout(&neg->handle, node);
1435 * This is the first time we hear
1436 * from the client, so note it's
1437 * unicast address, replacing the
1438 * broadcast address.
1440 bcopy(wh->eh.ether_shost,
1441 neg->pkt->pkt_header.eh.ether_dhost,
1443 sp->state = PPPOE_SOFFER;
1445 neg->pkt->pkt_header.ph.code = PADO_CODE;
1448 * start working out the tags to respond with.
1450 uniqtag.hdr.tag_type = PTT_AC_COOKIE;
1451 uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(sp));
1452 uniqtag.data.pointer = sp;
1454 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
1455 if ((tag = get_tag(ph, PTT_SRV_NAME)))
1456 insert_tag(sp, tag); /* return service */
1458 * If we have a NULL service request
1459 * and have an extra service defined in this hook,
1460 * then also add a tag for the extra service.
1461 * XXX this is a hack. eventually we should be able
1462 * to support advertising many services, not just one
1464 if (((tag == NULL) || (tag->tag_len == 0))
1465 && (neg->service.hdr.tag_len != 0)) {
1466 insert_tag(sp, &neg->service.hdr); /* SERVICE */
1468 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1469 insert_tag(sp, tag); /* returned hostunique */
1470 insert_tag(sp, &uniqtag.hdr);
1477 * Packets coming from the hook make no sense
1478 * to sessions in these states. Throw them away.
1484 case PPPOE_LISTENING:
1498 * Do local shutdown processing..
1499 * If we are a persistant device, we might refuse to go away, and
1500 * we'd only remove our links and reset ourself.
1503 ng_pppoe_shutdown(node_p node)
1505 const priv_p privdata = NG_NODE_PRIVATE(node);
1508 NG_NODE_SET_PRIVATE(node, NULL);
1509 NG_NODE_UNREF(privdata->node);
1510 FREE(privdata, M_NETGRAPH_PPPOE);
1515 * Hook disconnection
1517 * Clean up all dangling links and information about the session/hook.
1518 * For this type, removal of the last link destroys the node
1521 ng_pppoe_disconnect(hook_p hook)
1523 node_p node = NG_HOOK_NODE(hook);
1524 priv_p privp = NG_NODE_PRIVATE(node);
1529 hooks = NG_NODE_NUMHOOKS(node); /* this one already not counted */
1530 if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) {
1531 privp->debug_hook = NULL;
1532 } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) {
1533 privp->ethernet_hook = NULL;
1534 if (NG_NODE_IS_VALID(node))
1535 ng_rmnode_self(node);
1537 sp = NG_HOOK_PRIVATE(hook);
1538 if (sp->state != PPPOE_SNONE ) {
1539 pppoe_send_event(sp, NGM_PPPOE_CLOSE);
1542 * According to the spec, if we are connected,
1543 * we should send a DISC packet if we are shutting down
1546 if ((privp->ethernet_hook)
1547 && ((sp->state == PPPOE_CONNECTED)
1548 || (sp->state == PPPOE_NEWCONNECTED))) {
1550 struct pppoe_full_hdr *wh;
1551 struct pppoe_tag *tag;
1552 int msglen = strlen(SIGNOFF);
1555 /* revert the stored header to DISC/PADT mode */
1557 wh->ph.code = PADT_CODE;
1558 /* Configure ethertype depending on what was used during
1559 * sessions stage. */
1560 if (sp->pkt_hdr.eh.ether_type ==
1561 ETHERTYPE_PPPOE_STUPID_SESS)
1562 wh->eh.ether_type = ETHERTYPE_PPPOE_STUPID_DISC;
1564 wh->eh.ether_type = ETHERTYPE_PPPOE_DISC;
1566 /* generate a packet of that type */
1567 MGETHDR(m, M_DONTWAIT, MT_DATA);
1569 printf("pppoe: Session out of mbufs\n");
1571 m->m_pkthdr.rcvif = NULL;
1572 m->m_pkthdr.len = m->m_len = sizeof(*wh);
1573 bcopy((caddr_t)wh, mtod(m, caddr_t),
1576 * Add a General error message and adjust
1579 wh = mtod(m, struct pppoe_full_hdr *);
1581 tag->tag_type = PTT_GEN_ERR;
1582 tag->tag_len = htons((u_int16_t)msglen);
1583 strncpy(tag->tag_data, SIGNOFF, msglen);
1584 m->m_pkthdr.len = (m->m_len += sizeof(*tag) +
1586 wh->ph.length = htons(sizeof(*tag) + msglen);
1587 NG_SEND_DATA_ONLY(error,
1588 privp->ethernet_hook, m);
1592 * As long as we have somewhere to store the timeout handle,
1593 * we may have a timeout pending.. get rid of it.
1596 ng_uncallout(&sp->neg->handle, node);
1598 m_freem(sp->neg->m);
1599 FREE(sp->neg, M_NETGRAPH_PPPOE);
1601 FREE(sp, M_NETGRAPH_PPPOE);
1602 NG_HOOK_SET_PRIVATE(hook, NULL);
1603 /* work out how many session hooks there are */
1604 /* Node goes away on last session hook removal */
1605 if (privp->ethernet_hook) hooks -= 1;
1606 if (privp->debug_hook) hooks -= 1;
1608 if ((NG_NODE_NUMHOOKS(node) == 0)
1609 && (NG_NODE_IS_VALID(node)))
1610 ng_rmnode_self(node);
1615 * timeouts come here.
1618 pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2)
1620 sessp sp = NG_HOOK_PRIVATE(hook);
1623 struct mbuf *m0 = NULL;
1624 priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
1629 * resend the last packet, using an exponential backoff.
1630 * After a period of time, stop growing the backoff,
1631 * and either leave it, or revert to the start.
1635 /* timeouts on these produce resends */
1636 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1637 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1638 ng_callout(&neg->handle, node, hook, neg->timeout * hz,
1639 pppoe_ticker, NULL, 0);
1640 if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
1641 if (sp->state == PPPOE_SREQ) {
1642 /* revert to SINIT mode */
1645 neg->timeout = PPPOE_TIMEOUT_LIMIT;
1651 /* a timeout on these says "give up" */
1652 ng_rmhook_self(hook);
1655 /* timeouts have no meaning in other states */
1656 printf("pppoe: unexpected timeout\n");
1662 sendpacket(sessp sp)
1664 struct mbuf *m0 = NULL;
1665 hook_p hook = sp->hook;
1666 node_p node = NG_HOOK_NODE(hook);
1667 priv_p privp = NG_NODE_PRIVATE(node);
1673 case PPPOE_LISTENING:
1676 case PPPOE_CONNECTED:
1677 printf("pppoe: sendpacket: unexpected state\n");
1680 case PPPOE_NEWCONNECTED:
1681 /* send the PADS without a timeout - we're now connected */
1682 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1683 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1687 /* No packet to send, but set up the timeout */
1688 ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
1689 pppoe_ticker, NULL, 0);
1694 * send the offer but if they don't respond
1695 * in PPPOE_OFFER_TIMEOUT seconds, forget about it.
1697 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1698 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1699 ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
1700 pppoe_ticker, NULL, 0);
1705 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1706 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1707 ng_callout(&neg->handle, node, hook, PPPOE_INITIAL_TIMEOUT * hz,
1708 pppoe_ticker, NULL, 0);
1709 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1714 printf("pppoe: timeout: bad state\n");
1716 /* return (error); */
1720 * Parse an incoming packet to see if any tags should be copied to the
1721 * output packet. Don't do any tags that have been handled in the main
1724 static const struct pppoe_tag*
1725 scan_tags(sessp sp, const struct pppoe_hdr* ph)
1727 const char *const end = (const char *)next_tag(ph);
1729 const struct pppoe_tag *pt = &ph->tag[0];
1731 * Keep processing tags while a tag header will still fit.
1734 while((const char*)(pt + 1) <= end) {
1736 * If the tag data would go past the end of the packet, abort.
1738 ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
1742 switch (pt->tag_type) {
1758 pt = (const struct pppoe_tag*)ptn;
1764 pppoe_send_event(sessp sp, enum cmd cmdid)
1767 struct ng_mesg *msg;
1768 struct ngpppoe_sts *sts;
1771 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
1772 sizeof(struct ngpppoe_sts), M_NOWAIT);
1775 sts = (struct ngpppoe_sts *)msg->data;
1776 strncpy(sts->hook, NG_HOOK_NAME(sp->hook), NG_HOOKSIZ);
1777 NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);