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 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/errno.h>
51 #include <net/ethernet.h>
53 #include <netgraph/ng_message.h>
54 #include <netgraph/netgraph.h>
55 #include <netgraph/ng_parse.h>
56 #include <netgraph/ng_pppoe.h>
58 #ifdef NG_SEPARATE_MALLOC
59 MALLOC_DEFINE(M_NETGRAPH_PPPOE, "netgraph_pppoe", "netgraph pppoe node");
61 #define M_NETGRAPH_PPPOE M_NETGRAPH
64 #define SIGNOFF "session closed"
65 #define OFFSETOF(s, e) ((char *)&((s *)0)->e - (char *)((s *)0))
68 * This section contains the netgraph method declarations for the
69 * pppoe node. These methods define the netgraph pppoe 'type'.
72 static ng_constructor_t ng_pppoe_constructor;
73 static ng_rcvmsg_t ng_pppoe_rcvmsg;
74 static ng_shutdown_t ng_pppoe_shutdown;
75 static ng_newhook_t ng_pppoe_newhook;
76 static ng_rcvdata_t ng_pppoe_rcvdata;
77 static ng_disconnect_t ng_pppoe_disconnect;
79 /* Parse type for struct ngpppoe_init_data */
80 static const struct ng_parse_struct_field ngpppoe_init_data_type_fields[]
81 = NG_PPPOE_INIT_DATA_TYPE_INFO;
82 static const struct ng_parse_type ngpppoe_init_data_state_type = {
83 &ng_parse_struct_type,
84 &ngpppoe_init_data_type_fields
87 /* Parse type for struct ngpppoe_sts */
88 static const struct ng_parse_struct_field ng_pppoe_sts_type_fields[]
89 = NG_PPPOE_STS_TYPE_INFO;
90 static const struct ng_parse_type ng_pppoe_sts_state_type = {
91 &ng_parse_struct_type,
92 &ng_pppoe_sts_type_fields
95 /* List of commands and how to convert arguments to/from ASCII */
96 static const struct ng_cmdlist ng_pppoe_cmds[] = {
101 &ngpppoe_init_data_state_type,
108 &ngpppoe_init_data_state_type,
115 &ngpppoe_init_data_state_type,
122 &ngpppoe_init_data_state_type,
129 &ng_pppoe_sts_state_type,
136 &ng_pppoe_sts_state_type,
143 &ng_pppoe_sts_state_type,
150 &ng_parse_string_type,
158 &ng_parse_string_type
163 /* Netgraph node type descriptor */
164 static struct ng_type typestruct = {
165 .version = NG_ABI_VERSION,
166 .name = NG_PPPOE_NODE_TYPE,
167 .constructor = ng_pppoe_constructor,
168 .rcvmsg = ng_pppoe_rcvmsg,
169 .shutdown = ng_pppoe_shutdown,
170 .newhook = ng_pppoe_newhook,
171 .rcvdata = ng_pppoe_rcvdata,
172 .disconnect = ng_pppoe_disconnect,
173 .cmdlist = ng_pppoe_cmds,
175 NETGRAPH_INIT(pppoe, &typestruct);
178 * States for the session state machine.
179 * These have no meaning if there is no hook attached yet.
182 PPPOE_SNONE=0, /* [both] Initial state */
183 PPPOE_LISTENING, /* [Daemon] Listening for discover initiation pkt */
184 PPPOE_SINIT, /* [Client] Sent discovery initiation */
185 PPPOE_PRIMED, /* [Server] Awaiting PADI from daemon */
186 PPPOE_SOFFER, /* [Server] Sent offer message (got PADI)*/
187 PPPOE_SREQ, /* [Client] Sent a Request */
188 PPPOE_NEWCONNECTED, /* [Server] Connection established, No data received */
189 PPPOE_CONNECTED, /* [Both] Connection established, Data received */
190 PPPOE_DEAD /* [Both] */
193 #define NUMTAGS 20 /* number of tags we are set up to work with */
196 * Information we store for each hook on each node for negotiating the
197 * session. The mbuf and cluster are freed once negotiation has completed.
198 * The whole negotiation block is then discarded.
202 struct mbuf *m; /* holds cluster with last sent packet */
203 union packet *pkt; /* points within the above cluster */
204 struct callout handle; /* see timeout(9) */
205 u_int timeout; /* 0,1,2,4,8,16 etc. seconds */
207 const struct pppoe_tag *tags[NUMTAGS];
211 struct datatag service;
212 struct datatag ac_name;
214 typedef struct sess_neg *negp;
217 * Session information that is needed after connection.
223 ng_ID_t creator; /* who to notify */
224 struct pppoe_full_hdr pkt_hdr; /* used when connected */
225 negp neg; /* used when negotiating */
227 typedef struct sess_con *sessp;
229 #define NG_PPPOE_SESSION_NODE(sp) NG_HOOK_NODE(sp->hook)
232 PPPOE_STANDARD = 1, /* standard RFC2516 mode */
233 PPPOE_NONSTANDARD, /* 3Com proprietary mode */
236 struct ng_pppoe_mode_t {
238 const struct ether_header *eh_prototype;
242 static const struct ether_header eh_standard =
243 {{0xff,0xff,0xff,0xff,0xff,0xff},
244 {0x00,0x00,0x00,0x00,0x00,0x00},
245 ETHERTYPE_PPPOE_DISC};
247 static const struct ether_header eh_3Com =
248 {{0xff,0xff,0xff,0xff,0xff,0xff},
249 {0x00,0x00,0x00,0x00,0x00,0x00},
250 ETHERTYPE_PPPOE_STUPID_DISC};
252 static const struct ng_pppoe_mode_t ng_pppoe_modes[] = {
253 { PPPOE_STANDARD, &eh_standard, NG_PPPOE_STANDARD },
254 { PPPOE_NONSTANDARD, &eh_3Com, NG_PPPOE_NONSTANDARD },
259 * Information we store for each node
262 node_p node; /* back pointer to node */
263 hook_p ethernet_hook;
265 u_int packets_in; /* packets in from ethernet */
266 u_int packets_out; /* packets out towards ethernet */
268 const struct ng_pppoe_mode_t *mode; /* standard PPPoE or 3Com? */
270 typedef struct PPPoE *priv_p;
273 char bytes[sizeof(void *)];
277 #define LEAVE(x) do { error = x; goto quit; } while(0)
278 static void pppoe_start(sessp sp);
279 static void sendpacket(sessp sp);
280 static void pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2);
281 static const struct pppoe_tag *scan_tags(sessp sp,
282 const struct pppoe_hdr* ph);
283 static int pppoe_send_event(sessp sp, enum cmd cmdid);
285 /*************************************************************************
286 * Some basic utilities from the Linux version with author's permission.*
287 * Author: Michal Ostrowski <mostrows@styx.uwaterloo.ca> *
288 ************************************************************************/
291 * Generate a new session id
292 * XXX find out the FreeBSD locking scheme.
295 get_new_sid(node_p node)
297 priv_p privp = NG_NODE_PRIVATE(node);
298 static int pppoe_sid = 10;
306 * Spec says 0xFFFF is reserved.
307 * Also don't use 0x0000
314 /* Check it isn't already in use. */
315 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
316 /* Don't check special hooks. */
317 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
318 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
320 sp = NG_HOOK_PRIVATE(hook);
321 if (sp->Session_ID == val)
325 CTR2(KTR_NET, "%20s: new sid %d", __func__, val);
332 * Return the location where the next tag can be put
334 static __inline const struct pppoe_tag*
335 next_tag(const struct pppoe_hdr* ph)
337 return (const struct pppoe_tag*)(((const char*)&ph->tag[0])
338 + ntohs(ph->length));
342 * Look for a tag of a specific type.
343 * Don't trust any length the other end says,
344 * but assume we already sanity checked ph->length.
346 static const struct pppoe_tag*
347 get_tag(const struct pppoe_hdr* ph, uint16_t idx)
349 const char *const end = (const char *)next_tag(ph);
350 const struct pppoe_tag *pt = &ph->tag[0];
354 * Keep processing tags while a tag header will still fit.
356 while((const char*)(pt + 1) <= end) {
358 * If the tag data would go past the end of the packet, abort.
360 ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
362 CTR2(KTR_NET, "%20s: invalid length for tag %d",
366 if (pt->tag_type == idx) {
367 CTR2(KTR_NET, "%20s: found tag %d", __func__, idx);
371 pt = (const struct pppoe_tag*)ptn;
374 CTR2(KTR_NET, "%20s: not found tag %d", __func__, idx);
378 /**************************************************************************
379 * Inlines to initialise or add tags to a session's tag list.
380 **************************************************************************/
382 * Initialise the session's tag list.
387 KASSERT(sp->neg != NULL, ("%s: no neg", __func__));
388 sp->neg->numtags = 0;
392 insert_tag(sessp sp, const struct pppoe_tag *tp)
397 KASSERT(neg != NULL, ("%s: no neg", __func__));
398 if ((i = neg->numtags++) < NUMTAGS) {
401 printf("pppoe: asked to add too many tags to packet\n");
407 * Make up a packet, using the tags filled out for the session.
409 * Assume that the actual pppoe header and ethernet header
410 * are filled out externally to this routine.
411 * Also assume that neg->wh points to the correct
412 * location at the front of the buffer space.
415 make_packet(sessp sp) {
416 struct pppoe_full_hdr *wh = &sp->neg->pkt->pkt_header;
417 const struct pppoe_tag **tag;
423 KASSERT((sp->neg != NULL) && (sp->neg->m != NULL),
424 ("%s: make_packet called from wrong state", __func__));
425 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
427 dp = (char *)wh->ph.tag;
428 for (count = 0, tag = sp->neg->tags;
429 ((count < sp->neg->numtags) && (count < NUMTAGS));
431 tlen = ntohs((*tag)->tag_len) + sizeof(**tag);
432 if ((length + tlen) > (ETHER_MAX_LEN - 4 - sizeof(*wh))) {
433 printf("pppoe: tags too long\n");
434 sp->neg->numtags = count;
435 break; /* XXX chop off what's too long */
437 bcopy(*tag, (char *)dp, tlen);
441 wh->ph.length = htons(length);
442 sp->neg->m->m_len = length + sizeof(*wh);
443 sp->neg->m->m_pkthdr.len = length + sizeof(*wh);
446 /**************************************************************************
447 * Routine to match a service offered *
448 **************************************************************************/
450 * Find a hook that has a service string that matches that
451 * we are seeking. for now use a simple string.
452 * In the future we may need something like regexp().
453 * for testing allow a null string to match 1st found and a null service
454 * to match all requests. Also make '*' do the same.
457 #define NG_MATCH_EXACT 1
458 #define NG_MATCH_ANY 2
461 pppoe_match_svc(node_p node, const char *svc_name, int svc_len, int match)
465 priv_p privp = NG_NODE_PRIVATE(node);
466 hook_p allhook = NULL;
469 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
471 /* skip any hook that is debug or ethernet */
472 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
473 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
475 sp = NG_HOOK_PRIVATE(hook);
477 /* Skip any sessions which are not in LISTEN mode. */
478 if ( sp->state != PPPOE_LISTENING)
483 /* Special case for a blank or "*" service name (wildcard) */
484 if (match == NG_MATCH_ANY && neg->service_len == 1 &&
485 neg->service.data[0] == '*') {
490 /* If the lengths don't match, that aint it. */
491 if (neg->service_len != svc_len)
494 /* An exact match? */
498 if (strncmp(svc_name, neg->service.data, svc_len) == 0)
501 CTR3(KTR_NET, "%20s: matched %p for %s", __func__, hook, svc_name);
503 return (hook ? hook : allhook);
506 /**************************************************************************
507 * Routine to find a particular session that matches an incoming packet. *
508 **************************************************************************/
510 pppoe_findsession(node_p node, const struct pppoe_full_hdr *wh)
512 priv_p privp = NG_NODE_PRIVATE(node);
515 uint16_t session = ntohs(wh->ph.sid);
518 * Find matching peer/session combination.
520 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
521 /* don't check special hooks */
522 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
523 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook)) {
526 sp = NG_HOOK_PRIVATE(hook);
527 if ( ( (sp->state == PPPOE_CONNECTED)
528 || (sp->state == PPPOE_NEWCONNECTED) )
529 && (sp->Session_ID == session)
530 && (bcmp(sp->pkt_hdr.eh.ether_dhost,
532 ETHER_ADDR_LEN)) == 0) {
536 CTR3(KTR_NET, "%20s: matched %p for %d", __func__, hook, session);
542 pppoe_finduniq(node_p node, const struct pppoe_tag *tag)
544 priv_p privp = NG_NODE_PRIVATE(node);
548 bcopy(tag->tag_data, uniq.bytes, sizeof(void *));
549 /* Cycle through all known hooks. */
550 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
551 /* Don't check special hooks. */
552 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook)
553 || (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
555 if (uniq.pointer == NG_HOOK_PRIVATE(hook))
558 CTR3(KTR_NET, "%20s: matched %p for %p", __func__, hook, uniq.pointer);
563 /**************************************************************************
564 * Start of Netgraph entrypoints. *
565 **************************************************************************/
568 * Allocate the private data structure and link it with node.
571 ng_pppoe_constructor(node_p node)
575 /* Initialize private descriptor. */
576 privp = malloc(sizeof(*privp), M_NETGRAPH_PPPOE, M_NOWAIT | M_ZERO);
580 /* Link structs together; this counts as our one reference to *node. */
581 NG_NODE_SET_PRIVATE(node, privp);
584 /* Initialize to standard mode (the first one in ng_pppoe_modes[]). */
585 privp->mode = &ng_pppoe_modes[0];
587 CTR3(KTR_NET, "%20s: created node [%x] (%p)",
588 __func__, node->nd_ID, node);
594 * Give our ok for a hook to be added...
595 * point the hook's private info to the hook structure.
597 * The following hook names are special:
598 * "ethernet": the hook that should be connected to a NIC.
599 * "debug": copies of data sent out here (when I write the code).
600 * All other hook names need only be unique. (the framework checks this).
603 ng_pppoe_newhook(node_p node, hook_p hook, const char *name)
605 const priv_p privp = NG_NODE_PRIVATE(node);
608 if (strcmp(name, NG_PPPOE_HOOK_ETHERNET) == 0) {
609 privp->ethernet_hook = hook;
610 NG_HOOK_SET_PRIVATE(hook, &privp->ethernet_hook);
611 } else if (strcmp(name, NG_PPPOE_HOOK_DEBUG) == 0) {
612 privp->debug_hook = hook;
613 NG_HOOK_SET_PRIVATE(hook, &privp->debug_hook);
616 * Any other unique name is OK.
617 * The infrastructure has already checked that it's unique,
618 * so just allocate it and hook it in.
620 sp = malloc(sizeof(*sp), M_NETGRAPH_PPPOE, M_NOWAIT | M_ZERO);
624 NG_HOOK_SET_PRIVATE(hook, sp);
627 CTR5(KTR_NET, "%20s: node [%x] (%p) connected hook %s (%p)",
628 __func__, node->nd_ID, node, name, hook);
634 * Get a netgraph control message.
635 * Check it is one we understand. If needed, send a response.
636 * We sometimes save the address for an async action later.
637 * Always free the message.
640 ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
642 priv_p privp = NG_NODE_PRIVATE(node);
643 struct ngpppoe_init_data *ourmsg = NULL;
644 struct ng_mesg *resp = NULL;
651 NGI_GET_MSG(item, msg);
652 CTR5(KTR_NET, "%20s: node [%x] (%p) got message %d with cookie %d",
653 __func__, node->nd_ID, node, msg->header.cmd,
654 msg->header.typecookie);
656 /* Deal with message according to cookie and command. */
657 switch (msg->header.typecookie) {
658 case NGM_PPPOE_COOKIE:
659 switch (msg->header.cmd) {
660 case NGM_PPPOE_CONNECT:
661 case NGM_PPPOE_LISTEN:
662 case NGM_PPPOE_OFFER:
663 case NGM_PPPOE_SERVICE:
664 ourmsg = (struct ngpppoe_init_data *)msg->data;
665 if (msg->header.arglen < sizeof(*ourmsg)) {
666 printf("pppoe: init data too small\n");
669 if (msg->header.arglen - sizeof(*ourmsg) >
670 PPPOE_SERVICE_NAME_SIZE) {
671 printf("pppoe_rcvmsg: service name too big");
674 if (msg->header.arglen - sizeof(*ourmsg) <
676 printf("pppoe: init data has bad length,"
677 " %d should be %zd\n", ourmsg->data_len,
678 msg->header.arglen - sizeof (*ourmsg));
682 /* Make sure strcmp will terminate safely. */
683 ourmsg->hook[sizeof(ourmsg->hook) - 1] = '\0';
685 /* Cycle through all known hooks. */
686 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
687 if (NG_HOOK_NAME(hook) &&
688 strcmp(NG_HOOK_NAME(hook), ourmsg->hook) ==
695 if ((NG_HOOK_PRIVATE(hook) == &privp->debug_hook) ||
696 (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook))
699 sp = NG_HOOK_PRIVATE(hook);
701 if (msg->header.cmd == NGM_PPPOE_LISTEN) {
703 * Ensure we aren't already listening for this
706 if (pppoe_match_svc(node, ourmsg->data,
707 ourmsg->data_len, NG_MATCH_EXACT) != NULL)
712 * PPPOE_SERVICE advertisments are set up
713 * on sessions that are in PRIMED state.
715 if (msg->header.cmd == NGM_PPPOE_SERVICE)
718 if (sp->state != PPPOE_SNONE) {
719 printf("pppoe: Session already active\n");
724 * Set up prototype header.
726 neg = malloc(sizeof(*neg), M_NETGRAPH_PPPOE,
732 neg->m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
733 if (neg->m == NULL) {
734 free(neg, M_NETGRAPH_PPPOE);
737 neg->m->m_pkthdr.rcvif = NULL;
739 ng_callout_init(&neg->handle);
740 neg->m->m_len = sizeof(struct pppoe_full_hdr);
741 neg->pkt = mtod(neg->m, union packet*);
742 memcpy((void *)&neg->pkt->pkt_header.eh,
743 (const void *)privp->mode->eh_prototype,
744 sizeof(struct ether_header));
745 neg->pkt->pkt_header.ph.ver = 0x1;
746 neg->pkt->pkt_header.ph.type = 0x1;
747 neg->pkt->pkt_header.ph.sid = 0x0000;
750 sp->creator = NGI_RETADDR(item);
752 switch (msg->header.cmd) {
753 case NGM_PPPOE_GET_STATUS:
755 struct ngpppoestat *stats;
757 NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
761 stats = (struct ngpppoestat *) resp->data;
762 stats->packets_in = privp->packets_in;
763 stats->packets_out = privp->packets_out;
766 case NGM_PPPOE_CONNECT:
768 * Check the hook exists and is Uninitialised.
769 * Send a PADI request, and start the timeout logic.
770 * Store the originator of this message so we can send
771 * a success of fail message to them later.
772 * Move the session to SINIT.
773 * Set up the session to the correct state and
776 neg->service.hdr.tag_type = PTT_SRV_NAME;
777 neg->service.hdr.tag_len =
778 htons((uint16_t)ourmsg->data_len);
779 if (ourmsg->data_len)
780 bcopy(ourmsg->data, neg->service.data,
782 neg->service_len = ourmsg->data_len;
785 case NGM_PPPOE_LISTEN:
787 * Check the hook exists and is Uninitialised.
788 * Install the service matching string.
789 * Store the originator of this message so we can send
790 * a success of fail message to them later.
791 * Move the hook to 'LISTENING'
793 neg->service.hdr.tag_type = PTT_SRV_NAME;
794 neg->service.hdr.tag_len =
795 htons((uint16_t)ourmsg->data_len);
797 if (ourmsg->data_len)
798 bcopy(ourmsg->data, neg->service.data,
800 neg->service_len = ourmsg->data_len;
801 neg->pkt->pkt_header.ph.code = PADT_CODE;
803 * Wait for PADI packet coming from Ethernet.
805 sp->state = PPPOE_LISTENING;
807 case NGM_PPPOE_OFFER:
809 * Check the hook exists and is Uninitialised.
810 * Store the originator of this message so we can send
811 * a success of fail message to them later.
812 * Store the AC-Name given and go to PRIMED.
814 neg->ac_name.hdr.tag_type = PTT_AC_NAME;
815 neg->ac_name.hdr.tag_len =
816 htons((uint16_t)ourmsg->data_len);
817 if (ourmsg->data_len)
818 bcopy(ourmsg->data, neg->ac_name.data,
820 neg->ac_name_len = ourmsg->data_len;
821 neg->pkt->pkt_header.ph.code = PADO_CODE;
823 * Wait for PADI packet coming from hook.
825 sp->state = PPPOE_PRIMED;
827 case NGM_PPPOE_SERVICE:
829 * Check the session is primed.
830 * for now just allow ONE service to be advertised.
831 * If you do it twice you just overwrite.
833 if (sp->state != PPPOE_PRIMED) {
834 printf("pppoe: Session not primed\n");
838 neg->service.hdr.tag_type = PTT_SRV_NAME;
839 neg->service.hdr.tag_len =
840 htons((uint16_t)ourmsg->data_len);
842 if (ourmsg->data_len)
843 bcopy(ourmsg->data, neg->service.data,
845 neg->service_len = ourmsg->data_len;
847 case NGM_PPPOE_SETMODE:
849 const struct ng_pppoe_mode_t *mode;
853 if (msg->header.arglen == 0)
856 s = (char *)msg->data;
857 len = msg->header.arglen - 1;
859 /* Search for matching mode string. */
860 for (mode = ng_pppoe_modes; mode->id != 0; mode++ )
861 if ((strlen(mode->name) == len) &&
862 !strncmp(mode->name, s, len))
871 case NGM_PPPOE_GETMODE:
872 NG_MKRESPONSE(resp, msg, strlen(privp->mode->name) + 1,
876 strlcpy((char *)resp->data, privp->mode->name,
877 strlen(privp->mode->name) + 1);
887 CTR2(KTR_NET, "%20s: returning %d", __func__, error);
889 /* Take care of synchronous response, if any. */
891 NG_RESPOND_MSG(error, node, item, resp);
892 /* Free the message and return. */
898 * Start a client into the first state. A separate function because
899 * it can be needed if the negotiation times out.
902 pppoe_start(sessp sp)
904 priv_p privp = NG_NODE_PRIVATE(NG_PPPOE_SESSION_NODE(sp));
906 struct pppoe_tag hdr;
911 * Kick the state machine into starting up.
913 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
914 sp->state = PPPOE_SINIT;
916 * Reset the packet header to broadcast. Since we are
918 * mode use configured ethertype.
920 memcpy((void *)&sp->neg->pkt->pkt_header.eh,
921 (const void *)privp->mode->eh_prototype,
922 sizeof(struct ether_header));
923 sp->neg->pkt->pkt_header.ph.code = PADI_CODE;
924 uniqtag.hdr.tag_type = PTT_HOST_UNIQ;
925 uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(uniqtag.data));
926 uniqtag.data.pointer = sp;
928 insert_tag(sp, &uniqtag.hdr);
929 insert_tag(sp, &sp->neg->service.hdr);
935 send_acname(sessp sp, const struct pppoe_tag *tag)
939 struct ngpppoe_sts *sts;
941 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
943 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, NGM_PPPOE_ACNAME,
944 sizeof(struct ngpppoe_sts), M_NOWAIT);
948 sts = (struct ngpppoe_sts *)msg->data;
949 tlen = min(NG_HOOKSIZ - 1, ntohs(tag->tag_len));
950 strncpy(sts->hook, tag->tag_data, tlen);
951 sts->hook[tlen] = '\0';
952 NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
958 send_sessionid(sessp sp)
963 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
965 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, NGM_PPPOE_SESSIONID,
966 sizeof(uint16_t), M_NOWAIT);
970 *(uint16_t *)msg->data = sp->Session_ID;
971 NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
977 * Receive data, and do something with it.
978 * The caller will never free m, so if we use up this data
979 * or abort we must free it.
982 ng_pppoe_rcvdata(hook_p hook, item_p item)
984 node_p node = NG_HOOK_NODE(hook);
985 const priv_p privp = NG_NODE_PRIVATE(node);
986 sessp sp = NG_HOOK_PRIVATE(hook);
987 const struct pppoe_tag *utag = NULL, *tag = NULL;
988 const struct pppoe_full_hdr *wh;
989 const struct pppoe_hdr *ph;
998 struct pppoe_tag hdr;
1002 CTR6(KTR_NET, "%20s: node [%x] (%p) received %p on \"%s\" (%p)",
1003 __func__, node->nd_ID, node, item, hook->hk_name, hook);
1006 if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) {
1008 * Data from the debug hook gets sent without modification
1009 * straight to the ethernet.
1011 NG_FWD_ITEM_HOOK( error, item, privp->ethernet_hook);
1012 privp->packets_out++;
1013 } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) {
1016 * Dig out various fields from the packet.
1017 * Use them to decide where to send it.
1020 privp->packets_in++;
1021 if( m->m_len < sizeof(*wh)) {
1022 m = m_pullup(m, sizeof(*wh)); /* Checks length */
1024 printf("couldn't m_pullup\n");
1028 wh = mtod(m, struct pppoe_full_hdr *);
1029 length = ntohs(wh->ph.length);
1030 switch(wh->eh.ether_type) {
1031 case ETHERTYPE_PPPOE_STUPID_DISC: /* fall through */
1032 case ETHERTYPE_PPPOE_DISC:
1034 * We need to try to make sure that the tag area
1035 * is contiguous, or we could wander off the end
1036 * of a buffer and make a mess.
1037 * (Linux wouldn't have this problem).
1039 if (m->m_pkthdr.len <= MHLEN) {
1040 if( m->m_len < m->m_pkthdr.len) {
1041 m = m_pullup(m, m->m_pkthdr.len);
1043 printf("couldn't m_pullup\n");
1048 if (m->m_len != m->m_pkthdr.len) {
1050 * It's not all in one piece.
1051 * We need to do extra work.
1052 * Put it into a cluster.
1055 n = m_dup(m, M_DONTWAIT);
1059 /* just check we got a cluster */
1060 if (m->m_len != m->m_pkthdr.len) {
1066 printf("packet fragmented\n");
1070 wh = mtod(m, struct pppoe_full_hdr *);
1071 length = ntohs(wh->ph.length);
1073 session = ntohs(wh->ph.sid);
1080 * Look for a hook with the required service
1081 * and send the ENTIRE packet up there.
1082 * It should come back to a new hook in
1083 * PRIMED state. Look there for further
1086 tag = get_tag(ph, PTT_SRV_NAME);
1088 printf("no service tag\n");
1091 sendhook = pppoe_match_svc(NG_HOOK_NODE(hook),
1092 tag->tag_data, ntohs(tag->tag_len),
1095 NG_FWD_NEW_DATA(error, item,
1104 * Use the host_uniq tag to find the
1105 * hook this is in response to.
1106 * Received #2, now send #3
1107 * For now simply accept the first we receive.
1109 utag = get_tag(ph, PTT_HOST_UNIQ);
1111 || (ntohs(utag->tag_len) != sizeof(sp))) {
1112 printf("no host unique field\n");
1116 sendhook = pppoe_finduniq(node, utag);
1117 if (sendhook == NULL) {
1118 printf("no matching session\n");
1123 * Check the session is in the right state.
1124 * It needs to be in PPPOE_SINIT.
1126 sp = NG_HOOK_PRIVATE(sendhook);
1127 if (sp->state != PPPOE_SINIT) {
1128 printf("session in wrong state\n");
1132 ng_uncallout(&neg->handle, node);
1135 * This is the first time we hear
1136 * from the server, so note it's
1137 * unicast address, replacing the
1138 * broadcast address .
1140 bcopy(wh->eh.ether_shost,
1141 neg->pkt->pkt_header.eh.ether_dhost,
1144 neg->pkt->pkt_header.ph.code = PADR_CODE;
1146 insert_tag(sp, utag); /* Host Unique */
1147 if ((tag = get_tag(ph, PTT_AC_COOKIE)))
1148 insert_tag(sp, tag); /* return cookie */
1149 if ((tag = get_tag(ph, PTT_AC_NAME))) {
1150 insert_tag(sp, tag); /* return it */
1151 send_acname(sp, tag);
1153 insert_tag(sp, &neg->service.hdr); /* Service */
1156 sp->state = PPPOE_SREQ;
1163 * Use the ac_cookie tag to find the
1164 * hook this is in response to.
1166 utag = get_tag(ph, PTT_AC_COOKIE);
1168 || (ntohs(utag->tag_len) != sizeof(sp))) {
1172 sendhook = pppoe_finduniq(node, utag);
1173 if (sendhook == NULL) {
1178 * Check the session is in the right state.
1179 * It needs to be in PPPOE_SOFFER
1180 * or PPPOE_NEWCONNECTED. If the latter,
1181 * then this is a retry by the client.
1182 * so be nice, and resend.
1184 sp = NG_HOOK_PRIVATE(sendhook);
1185 if (sp->state == PPPOE_NEWCONNECTED) {
1187 * Whoa! drop back to resend that
1189 * We should still have a copy of it.
1191 sp->state = PPPOE_SOFFER;
1193 if (sp->state != PPPOE_SOFFER) {
1194 LEAVE (ENETUNREACH);
1198 ng_uncallout(&neg->handle, node);
1199 neg->pkt->pkt_header.ph.code = PADS_CODE;
1200 if (sp->Session_ID == 0)
1201 neg->pkt->pkt_header.ph.sid =
1202 htons(sp->Session_ID
1203 = get_new_sid(node));
1207 * start working out the tags to respond with.
1210 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
1211 if ((tag = get_tag(ph, PTT_SRV_NAME)))
1212 insert_tag(sp, tag);/* return service */
1213 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1214 insert_tag(sp, tag); /* return it */
1215 insert_tag(sp, utag); /* ac_cookie */
1218 sp->state = PPPOE_NEWCONNECTED;
1221 * Having sent the last Negotiation header,
1222 * Set up the stored packet header to
1223 * be correct for the actual session.
1224 * But keep the negotialtion stuff
1225 * around in case we need to resend this last
1226 * packet. We'll discard it when we move
1227 * from NEWCONNECTED to CONNECTED
1229 sp->pkt_hdr = neg->pkt->pkt_header;
1230 /* Configure ethertype depending on what
1231 * ethertype was used at discovery phase */
1232 if (sp->pkt_hdr.eh.ether_type ==
1233 ETHERTYPE_PPPOE_STUPID_DISC)
1234 sp->pkt_hdr.eh.ether_type
1235 = ETHERTYPE_PPPOE_STUPID_SESS;
1237 sp->pkt_hdr.eh.ether_type
1238 = ETHERTYPE_PPPOE_SESS;
1239 sp->pkt_hdr.ph.code = 0;
1240 pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
1245 * Use the host_uniq tag to find the
1246 * hook this is in response to.
1247 * take the session ID and store it away.
1248 * Also make sure the pre-made header is
1249 * correct and set us into Session mode.
1251 utag = get_tag(ph, PTT_HOST_UNIQ);
1253 || (ntohs(utag->tag_len) != sizeof(sp))) {
1254 LEAVE (ENETUNREACH);
1257 sendhook = pppoe_finduniq(node, utag);
1258 if (sendhook == NULL) {
1263 * Check the session is in the right state.
1264 * It needs to be in PPPOE_SREQ.
1266 sp = NG_HOOK_PRIVATE(sendhook);
1267 if (sp->state != PPPOE_SREQ) {
1271 ng_uncallout(&neg->handle, node);
1272 neg->pkt->pkt_header.ph.sid = wh->ph.sid;
1273 sp->Session_ID = ntohs(wh->ph.sid);
1276 sp->state = PPPOE_CONNECTED;
1278 * Now we have gone to Connected mode,
1279 * Free all resources needed for
1281 * Keep a copy of the header we will be using.
1283 sp->pkt_hdr = neg->pkt->pkt_header;
1284 if (privp->mode->id == PPPOE_NONSTANDARD)
1285 sp->pkt_hdr.eh.ether_type
1286 = ETHERTYPE_PPPOE_STUPID_SESS;
1288 sp->pkt_hdr.eh.ether_type
1289 = ETHERTYPE_PPPOE_SESS;
1290 sp->pkt_hdr.ph.code = 0;
1292 free(sp->neg, M_NETGRAPH_PPPOE);
1294 pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
1298 * Send a 'close' message to the controlling
1299 * process (the one that set us up);
1300 * And then tear everything down.
1302 * Find matching peer/session combination.
1304 sendhook = pppoe_findsession(node, wh);
1305 if (sendhook == NULL) {
1308 /* send message to creator */
1311 ng_rmhook_self(sendhook);
1315 LEAVE(EPFNOSUPPORT);
1318 case ETHERTYPE_PPPOE_STUPID_SESS:
1319 case ETHERTYPE_PPPOE_SESS:
1321 * Find matching peer/session combination.
1323 sendhook = pppoe_findsession(node, wh);
1324 if (sendhook == NULL) {
1325 LEAVE (ENETUNREACH);
1328 sp = NG_HOOK_PRIVATE(sendhook);
1329 m_adj(m, sizeof(*wh));
1330 if (m->m_pkthdr.len < length) {
1331 /* Packet too short, dump it */
1335 /* Also need to trim excess at the end */
1336 if (m->m_pkthdr.len > length) {
1337 m_adj(m, -((int)(m->m_pkthdr.len - length)));
1339 if ( sp->state != PPPOE_CONNECTED) {
1340 if (sp->state == PPPOE_NEWCONNECTED) {
1341 sp->state = PPPOE_CONNECTED;
1343 * Now we have gone to Connected mode,
1344 * Free all resources needed for
1345 * negotiation. Be paranoid about
1346 * whether there may be a timeout.
1348 m_freem(sp->neg->m);
1349 ng_uncallout(&sp->neg->handle, node);
1350 free(sp->neg, M_NETGRAPH_PPPOE);
1353 LEAVE (ENETUNREACH);
1357 NG_FWD_NEW_DATA( error, item, sendhook, m);
1360 LEAVE(EPFNOSUPPORT);
1364 * Not ethernet or debug hook..
1366 * The packet has come in on a normal hook.
1367 * We need to find out what kind of hook,
1368 * So we can decide how to handle it.
1369 * Check the hook's state.
1371 sp = NG_HOOK_PRIVATE(hook);
1372 switch (sp->state) {
1373 case PPPOE_NEWCONNECTED:
1374 case PPPOE_CONNECTED: {
1375 static const u_char addrctrl[] = { 0xff, 0x03 };
1376 struct pppoe_full_hdr *wh;
1379 * Remove PPP address and control fields, if any.
1380 * For example, ng_ppp(4) always sends LCP packets
1381 * with address and control fields as required by
1382 * generic PPP. PPPoE is an exception to the rule.
1384 if (m->m_pkthdr.len >= 2) {
1385 if (m->m_len < 2 && !(m = m_pullup(m, 2)))
1387 if (bcmp(mtod(m, u_char *), addrctrl, 2) == 0)
1391 * Bang in a pre-made header, and set the length up
1392 * to be correct. Then send it to the ethernet driver.
1393 * But first correct the length.
1395 sp->pkt_hdr.ph.length = htons((short)(m->m_pkthdr.len));
1396 M_PREPEND(m, sizeof(*wh), M_DONTWAIT);
1400 wh = mtod(m, struct pppoe_full_hdr *);
1401 bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
1402 NG_FWD_NEW_DATA( error, item, privp->ethernet_hook, m);
1403 privp->packets_out++;
1408 * A PADI packet is being returned by the application
1409 * that has set up this hook. This indicates that it
1410 * wants us to offer service.
1413 if (m->m_len < sizeof(*wh)) {
1414 m = m_pullup(m, sizeof(*wh));
1418 wh = mtod(m, struct pppoe_full_hdr *);
1420 session = ntohs(wh->ph.sid);
1421 length = ntohs(wh->ph.length);
1423 /* Use peers mode in session. */
1424 neg->pkt->pkt_header.eh.ether_type = wh->eh.ether_type;
1425 if (code != PADI_CODE)
1427 ng_uncallout(&neg->handle, node);
1430 * This is the first time we hear
1431 * from the client, so note it's
1432 * unicast address, replacing the
1433 * broadcast address.
1435 bcopy(wh->eh.ether_shost,
1436 neg->pkt->pkt_header.eh.ether_dhost,
1438 sp->state = PPPOE_SOFFER;
1440 neg->pkt->pkt_header.ph.code = PADO_CODE;
1443 * Start working out the tags to respond with.
1445 uniqtag.hdr.tag_type = PTT_AC_COOKIE;
1446 uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(sp));
1447 uniqtag.data.pointer = sp;
1449 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
1450 if ((tag = get_tag(ph, PTT_SRV_NAME)))
1451 insert_tag(sp, tag); /* return service */
1453 * If we have a NULL service request
1454 * and have an extra service defined in this hook,
1455 * then also add a tag for the extra service.
1456 * XXX this is a hack. eventually we should be able
1457 * to support advertising many services, not just one
1459 if (((tag == NULL) || (tag->tag_len == 0)) &&
1460 (neg->service.hdr.tag_len != 0)) {
1461 insert_tag(sp, &neg->service.hdr); /* SERVICE */
1463 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1464 insert_tag(sp, tag); /* returned hostunique */
1465 insert_tag(sp, &uniqtag.hdr);
1472 * Packets coming from the hook make no sense
1473 * to sessions in these states. Throw them away.
1479 case PPPOE_LISTENING:
1493 * Do local shutdown processing..
1494 * If we are a persistant device, we might refuse to go away, and
1495 * we'd only remove our links and reset ourself.
1498 ng_pppoe_shutdown(node_p node)
1500 const priv_p privdata = NG_NODE_PRIVATE(node);
1502 NG_NODE_SET_PRIVATE(node, NULL);
1503 NG_NODE_UNREF(privdata->node);
1504 free(privdata, M_NETGRAPH_PPPOE);
1509 * Hook disconnection
1511 * Clean up all dangling links and information about the session/hook.
1512 * For this type, removal of the last link destroys the node.
1515 ng_pppoe_disconnect(hook_p hook)
1517 node_p node = NG_HOOK_NODE(hook);
1518 priv_p privp = NG_NODE_PRIVATE(node);
1522 hooks = NG_NODE_NUMHOOKS(node); /* This one already not counted. */
1523 if (NG_HOOK_PRIVATE(hook) == &privp->debug_hook) {
1524 privp->debug_hook = NULL;
1525 } else if (NG_HOOK_PRIVATE(hook) == &privp->ethernet_hook) {
1526 privp->ethernet_hook = NULL;
1527 if (NG_NODE_IS_VALID(node))
1528 ng_rmnode_self(node);
1530 sp = NG_HOOK_PRIVATE(hook);
1531 if (sp->state != PPPOE_SNONE ) {
1532 pppoe_send_event(sp, NGM_PPPOE_CLOSE);
1535 * According to the spec, if we are connected,
1536 * we should send a DISC packet if we are shutting down
1539 if ((privp->ethernet_hook)
1540 && ((sp->state == PPPOE_CONNECTED)
1541 || (sp->state == PPPOE_NEWCONNECTED))) {
1543 struct pppoe_full_hdr *wh;
1544 struct pppoe_tag *tag;
1545 int msglen = strlen(SIGNOFF);
1548 /* Revert the stored header to DISC/PADT mode. */
1550 wh->ph.code = PADT_CODE;
1552 * Configure ethertype depending on what was used
1553 * during sessions stage.
1555 if (sp->pkt_hdr.eh.ether_type ==
1556 ETHERTYPE_PPPOE_STUPID_SESS)
1557 wh->eh.ether_type = ETHERTYPE_PPPOE_STUPID_DISC;
1559 wh->eh.ether_type = ETHERTYPE_PPPOE_DISC;
1561 /* Generate a packet of that type. */
1562 MGETHDR(m, M_DONTWAIT, MT_DATA);
1564 printf("pppoe: Session out of mbufs\n");
1566 m->m_pkthdr.rcvif = NULL;
1567 m->m_pkthdr.len = m->m_len = sizeof(*wh);
1568 bcopy((caddr_t)wh, mtod(m, caddr_t),
1571 * Add a General error message and adjust
1574 wh = mtod(m, struct pppoe_full_hdr *);
1576 tag->tag_type = PTT_GEN_ERR;
1577 tag->tag_len = htons((u_int16_t)msglen);
1578 strncpy(tag->tag_data, SIGNOFF, msglen);
1579 m->m_pkthdr.len = (m->m_len += sizeof(*tag) +
1581 wh->ph.length = htons(sizeof(*tag) + msglen);
1582 NG_SEND_DATA_ONLY(error,
1583 privp->ethernet_hook, m);
1587 * As long as we have somewhere to store the timeout handle,
1588 * we may have a timeout pending.. get rid of it.
1591 ng_uncallout(&sp->neg->handle, node);
1593 m_freem(sp->neg->m);
1594 free(sp->neg, M_NETGRAPH_PPPOE);
1596 free(sp, M_NETGRAPH_PPPOE);
1597 NG_HOOK_SET_PRIVATE(hook, NULL);
1600 * Work out how many session hooks there are.
1601 * Node goes away on last session hook removal.
1603 if (privp->ethernet_hook)
1605 if (privp->debug_hook)
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 priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
1621 sessp sp = NG_HOOK_PRIVATE(hook);
1623 struct mbuf *m0 = NULL;
1626 CTR6(KTR_NET, "%20s: node [%x] (%p) hook \"%s\" (%p) session %d",
1627 __func__, node->nd_ID, node, hook->hk_name, hook, sp->Session_ID);
1630 * Resend the last packet, using an exponential backoff.
1631 * After a period of time, stop growing the backoff,
1632 * And either leave it, or revert to the start.
1636 /* Timeouts on these produce resends. */
1637 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1638 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1639 ng_callout(&neg->handle, node, hook, neg->timeout * hz,
1640 pppoe_ticker, NULL, 0);
1641 if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
1642 if (sp->state == PPPOE_SREQ) {
1643 /* Revert to SINIT mode. */
1646 neg->timeout = PPPOE_TIMEOUT_LIMIT;
1652 /* A timeout on these says "give up" */
1653 ng_rmhook_self(hook);
1656 /* Timeouts have no meaning in other states. */
1657 printf("pppoe: unexpected timeout\n");
1663 sendpacket(sessp sp)
1665 struct mbuf *m0 = NULL;
1666 hook_p hook = sp->hook;
1667 node_p node = NG_HOOK_NODE(hook);
1668 priv_p privp = NG_NODE_PRIVATE(node);
1672 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
1674 case PPPOE_LISTENING:
1677 case PPPOE_CONNECTED:
1678 printf("pppoe: sendpacket: unexpected state\n");
1681 case PPPOE_NEWCONNECTED:
1682 /* Send the PADS without a timeout - we're now connected. */
1683 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1684 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1688 /* No packet to send, but set up the timeout. */
1689 ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
1690 pppoe_ticker, NULL, 0);
1695 * Send the offer but if they don't respond
1696 * in PPPOE_OFFER_TIMEOUT seconds, forget about it.
1698 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1699 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1700 ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
1701 pppoe_ticker, NULL, 0);
1706 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1707 NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
1708 ng_callout(&neg->handle, node, hook, PPPOE_INITIAL_TIMEOUT * hz,
1709 pppoe_ticker, NULL, 0);
1710 neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
1715 printf("pppoe: timeout: bad state\n");
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];
1732 * Keep processing tags while a tag header will still fit.
1734 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
1736 while((const char*)(pt + 1) <= end) {
1738 * If the tag data would go past the end of the packet, abort.
1740 ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
1744 switch (pt->tag_type) {
1760 pt = (const struct pppoe_tag*)ptn;
1766 pppoe_send_event(sessp sp, enum cmd cmdid)
1769 struct ng_mesg *msg;
1770 struct ngpppoe_sts *sts;
1772 CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
1774 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
1775 sizeof(struct ngpppoe_sts), M_NOWAIT);
1778 sts = (struct ngpppoe_sts *)msg->data;
1779 strncpy(sts->hook, NG_HOOK_NAME(sp->hook), NG_HOOKSIZ);
1780 NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);