Deleted Added
full compact
ng_pppoe.c (68876) ng_pppoe.c (69922)
1
2/*
3 * ng_pppoe.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@freebsd.org>
38 *
1
2/*
3 * ng_pppoe.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@freebsd.org>
38 *
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 68876 2000-11-18 15:17:43Z dwmalone $
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 69922 2000-12-12 18:52:14Z julian $
40 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
41 */
42#if 0
43#define AAA printf("pppoe: %s\n", __FUNCTION__ );
44#define BBB printf("-%d-", __LINE__ );
45#else
46#define AAA
47#define BBB

--- 64 unchanged lines hidden (view full) ---

112 NGM_PPPOE_COOKIE,
113 NGM_PPPOE_OFFER,
114 "pppoe_offer",
115 &ngpppoe_init_data_state_type,
116 NULL
117 },
118 {
119 NGM_PPPOE_COOKIE,
40 * $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
41 */
42#if 0
43#define AAA printf("pppoe: %s\n", __FUNCTION__ );
44#define BBB printf("-%d-", __LINE__ );
45#else
46#define AAA
47#define BBB

--- 64 unchanged lines hidden (view full) ---

112 NGM_PPPOE_COOKIE,
113 NGM_PPPOE_OFFER,
114 "pppoe_offer",
115 &ngpppoe_init_data_state_type,
116 NULL
117 },
118 {
119 NGM_PPPOE_COOKIE,
120 NGM_PPPOE_SERVICE,
121 "pppoe_service",
122 &ngpppoe_init_data_state_type,
123 NULL
124 },
125 {
126 NGM_PPPOE_COOKIE,
120 NGM_PPPOE_SUCCESS,
121 "pppoe_success",
122 &ng_pppoe_sts_state_type,
123 NULL
124 },
125 {
126 NGM_PPPOE_COOKIE,
127 NGM_PPPOE_FAIL,

--- 18 unchanged lines hidden (view full) ---

146 NULL,
147 ng_pppoe_constructor,
148 ng_pppoe_rcvmsg,
149 ng_pppoe_rmnode,
150 ng_pppoe_newhook,
151 NULL,
152 ng_pppoe_connect,
153 ng_pppoe_rcvdata,
127 NGM_PPPOE_SUCCESS,
128 "pppoe_success",
129 &ng_pppoe_sts_state_type,
130 NULL
131 },
132 {
133 NGM_PPPOE_COOKIE,
134 NGM_PPPOE_FAIL,

--- 18 unchanged lines hidden (view full) ---

153 NULL,
154 ng_pppoe_constructor,
155 ng_pppoe_rcvmsg,
156 ng_pppoe_rmnode,
157 ng_pppoe_newhook,
158 NULL,
159 ng_pppoe_connect,
160 ng_pppoe_rcvdata,
154 ng_pppoe_rcvdata,
155 ng_pppoe_disconnect,
156 ng_pppoe_cmds
157};
158NETGRAPH_INIT(pppoe, &typestruct);
159
160/*
161 * States for the session state machine.
162 * These have no meaning if there is no hook attached yet.

--- 356 unchanged lines hidden (view full) ---

519/*
520 * Allocate the private data structure and the generic node
521 * and link them together.
522 *
523 * ng_make_node_common() returns with a generic node struct
524 * with a single reference for us.. we transfer it to the
525 * private structure.. when we free the private struct we must
526 * unref the node so it gets freed too.
161 ng_pppoe_disconnect,
162 ng_pppoe_cmds
163};
164NETGRAPH_INIT(pppoe, &typestruct);
165
166/*
167 * States for the session state machine.
168 * These have no meaning if there is no hook attached yet.

--- 356 unchanged lines hidden (view full) ---

525/*
526 * Allocate the private data structure and the generic node
527 * and link them together.
528 *
529 * ng_make_node_common() returns with a generic node struct
530 * with a single reference for us.. we transfer it to the
531 * private structure.. when we free the private struct we must
532 * unref the node so it gets freed too.
527 *
528 * If this were a device node than this work would be done in the attach()
529 * routine and the constructor would return EINVAL as you should not be able
530 * to creatednodes that depend on hardware (unless you can add the hardware :)
531 */
532static int
533ng_pppoe_constructor(node_p *nodep)
534{
535 priv_p privdata;
536 int error;
537
538AAA

--- 17 unchanged lines hidden (view full) ---

556
557/*
558 * Give our ok for a hook to be added...
559 * point the hook's private info to the hook structure.
560 *
561 * The following hook names are special:
562 * Ethernet: the hook that should be connected to a NIC.
563 * debug: copies of data sent out here (when I write the code).
533 */
534static int
535ng_pppoe_constructor(node_p *nodep)
536{
537 priv_p privdata;
538 int error;
539
540AAA

--- 17 unchanged lines hidden (view full) ---

558
559/*
560 * Give our ok for a hook to be added...
561 * point the hook's private info to the hook structure.
562 *
563 * The following hook names are special:
564 * Ethernet: the hook that should be connected to a NIC.
565 * debug: copies of data sent out here (when I write the code).
566 * All other hook names need only be unique. (the framework checks this).
564 */
565static int
566ng_pppoe_newhook(node_p node, hook_p hook, const char *name)
567{
568 const priv_p privp = node->private;
569 sessp sp;
570
571AAA

--- 41 unchanged lines hidden (view full) ---

613AAA
614 /* Deal with message according to cookie and command */
615 switch (msg->header.typecookie) {
616 case NGM_PPPOE_COOKIE:
617 switch (msg->header.cmd) {
618 case NGM_PPPOE_CONNECT:
619 case NGM_PPPOE_LISTEN:
620 case NGM_PPPOE_OFFER:
567 */
568static int
569ng_pppoe_newhook(node_p node, hook_p hook, const char *name)
570{
571 const priv_p privp = node->private;
572 sessp sp;
573
574AAA

--- 41 unchanged lines hidden (view full) ---

616AAA
617 /* Deal with message according to cookie and command */
618 switch (msg->header.typecookie) {
619 case NGM_PPPOE_COOKIE:
620 switch (msg->header.cmd) {
621 case NGM_PPPOE_CONNECT:
622 case NGM_PPPOE_LISTEN:
623 case NGM_PPPOE_OFFER:
624 case NGM_PPPOE_SERVICE:
621 ourmsg = (struct ngpppoe_init_data *)msg->data;
622 if (msg->header.arglen < sizeof(*ourmsg)) {
623 printf("pppoe: init data too small\n");
624 LEAVE(EMSGSIZE);
625 }
626 if (msg->header.arglen - sizeof(*ourmsg) >
627 PPPOE_SERVICE_NAME_SIZE) {
628 printf("pppoe_rcvmsg: service name too big");

--- 19 unchanged lines hidden (view full) ---

648 if (hook == NULL) {
649 LEAVE(ENOENT);
650 }
651 if ((hook->private == &privp->debug_hook)
652 || (hook->private == &privp->ethernet_hook)) {
653 LEAVE(EINVAL);
654 }
655 sp = hook->private;
625 ourmsg = (struct ngpppoe_init_data *)msg->data;
626 if (msg->header.arglen < sizeof(*ourmsg)) {
627 printf("pppoe: init data too small\n");
628 LEAVE(EMSGSIZE);
629 }
630 if (msg->header.arglen - sizeof(*ourmsg) >
631 PPPOE_SERVICE_NAME_SIZE) {
632 printf("pppoe_rcvmsg: service name too big");

--- 19 unchanged lines hidden (view full) ---

652 if (hook == NULL) {
653 LEAVE(ENOENT);
654 }
655 if ((hook->private == &privp->debug_hook)
656 || (hook->private == &privp->ethernet_hook)) {
657 LEAVE(EINVAL);
658 }
659 sp = hook->private;
660
661 /*
662 * PPPOE_SERVICE advertisments are set up
663 * on sessions that are in PRIMED state.
664 */
665 if (msg->header.cmd == NGM_PPPOE_SERVICE) {
666 break;
667 }
656 if (sp->state |= PPPOE_SNONE) {
657 printf("pppoe: Session already active\n");
658 LEAVE(EISCONN);
659 }
660
661 /*
662 * set up prototype header
663 */

--- 66 unchanged lines hidden (view full) ---

730 break;
731 case NGM_PPPOE_LISTEN:
732 /*
733 * Check the hook exists and is Uninitialised.
734 * Install the service matching string.
735 * Store the originator of this message so we can send
736 * a success of fail message to them later.
737 * Move the hook to 'LISTENING'
668 if (sp->state |= PPPOE_SNONE) {
669 printf("pppoe: Session already active\n");
670 LEAVE(EISCONN);
671 }
672
673 /*
674 * set up prototype header
675 */

--- 66 unchanged lines hidden (view full) ---

742 break;
743 case NGM_PPPOE_LISTEN:
744 /*
745 * Check the hook exists and is Uninitialised.
746 * Install the service matching string.
747 * Store the originator of this message so we can send
748 * a success of fail message to them later.
749 * Move the hook to 'LISTENING'
738
739 */
740 neg->service.hdr.tag_type = PTT_SRV_NAME;
741 neg->service.hdr.tag_len =
742 htons((u_int16_t)ourmsg->data_len);
743
744 if (ourmsg->data_len)
745 bcopy(ourmsg->data, neg->service.data,
746 ourmsg->data_len);

--- 19 unchanged lines hidden (view full) ---

766 ourmsg->data_len);
767 neg->ac_name_len = ourmsg->data_len;
768 neg->pkt->pkt_header.ph.code = PADO_CODE;
769 /*
770 * Wait for PADI packet coming from hook
771 */
772 sp->state = PPPOE_PRIMED;
773 break;
750 */
751 neg->service.hdr.tag_type = PTT_SRV_NAME;
752 neg->service.hdr.tag_len =
753 htons((u_int16_t)ourmsg->data_len);
754
755 if (ourmsg->data_len)
756 bcopy(ourmsg->data, neg->service.data,
757 ourmsg->data_len);

--- 19 unchanged lines hidden (view full) ---

777 ourmsg->data_len);
778 neg->ac_name_len = ourmsg->data_len;
779 neg->pkt->pkt_header.ph.code = PADO_CODE;
780 /*
781 * Wait for PADI packet coming from hook
782 */
783 sp->state = PPPOE_PRIMED;
784 break;
785 case NGM_PPPOE_SERVICE:
786 /*
787 * Check the session is primed.
788 * for now just allow ONE service to be advertised.
789 * If you do it twice you just overwrite.
790 */
791 if (sp->state |= PPPOE_PRIMED) {
792 printf("pppoe: Session not primed\n");
793 LEAVE(EISCONN);
794 }
795 neg->service.hdr.tag_type = PTT_SRV_NAME;
796 neg->service.hdr.tag_len =
797 htons((u_int16_t)ourmsg->data_len);
798
799 if (ourmsg->data_len)
800 bcopy(ourmsg->data, neg->service.data,
801 ourmsg->data_len);
802 neg->service_len = ourmsg->data_len;
803 break;
774 default:
775 LEAVE(EINVAL);
776 }
777 break;
778 default:
779 LEAVE(EINVAL);
780 }
781

--- 41 unchanged lines hidden (view full) ---

823
824/*
825 * Receive data, and do something with it.
826 * The caller will never free m or meta, so
827 * if we use up this data or abort we must free BOTH of these.
828 */
829static int
830ng_pppoe_rcvdata(hook_p hook, struct mbuf *m, meta_p meta,
804 default:
805 LEAVE(EINVAL);
806 }
807 break;
808 default:
809 LEAVE(EINVAL);
810 }
811

--- 41 unchanged lines hidden (view full) ---

853
854/*
855 * Receive data, and do something with it.
856 * The caller will never free m or meta, so
857 * if we use up this data or abort we must free BOTH of these.
858 */
859static int
860ng_pppoe_rcvdata(hook_p hook, struct mbuf *m, meta_p meta,
831 struct mbuf **ret_m, meta_p *ret_meta)
861 struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp)
832{
833 node_p node = hook->node;
834 const priv_p privp = node->private;
835 sessp sp = hook->private;
836 struct pppoe_full_hdr *wh;
837 struct pppoe_hdr *ph;
838 int error = 0;
839 u_int16_t session;

--- 423 unchanged lines hidden (view full) ---

1263 */
1264 uniqtag.hdr.tag_type = PTT_AC_COOKIE;
1265 uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(sp));
1266 uniqtag.data.pointer = sp;
1267 init_tags(sp);
1268 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
1269 if ((tag = get_tag(ph, PTT_SRV_NAME)))
1270 insert_tag(sp, tag); /* return service */
862{
863 node_p node = hook->node;
864 const priv_p privp = node->private;
865 sessp sp = hook->private;
866 struct pppoe_full_hdr *wh;
867 struct pppoe_hdr *ph;
868 int error = 0;
869 u_int16_t session;

--- 423 unchanged lines hidden (view full) ---

1293 */
1294 uniqtag.hdr.tag_type = PTT_AC_COOKIE;
1295 uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(sp));
1296 uniqtag.data.pointer = sp;
1297 init_tags(sp);
1298 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
1299 if ((tag = get_tag(ph, PTT_SRV_NAME)))
1300 insert_tag(sp, tag); /* return service */
1301 /*
1302 * If we have a NULL service request
1303 * and have an extra service defined in this hook,
1304 * then also add a tag for the extra service.
1305 * XXX this is a hack. eventually we should be able
1306 * to support advertising many services, not just one
1307 */
1308 if (((tag == NULL) || (tag->tag_len == 0))
1309 && (neg->service.hdr.tag_len != 0)) {
1310 insert_tag(sp, &neg->service.hdr); /* SERVICE */
1311 }
1271 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1272 insert_tag(sp, tag); /* returned hostunique */
1273 insert_tag(sp, &uniqtag.hdr);
1312 if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
1313 insert_tag(sp, tag); /* returned hostunique */
1314 insert_tag(sp, &uniqtag.hdr);
1274 /* XXX maybe put the tag in the session store */
1275 scan_tags(sp, ph);
1276 make_packet(sp);
1277 sendpacket(sp);
1278 break;
1279
1280 /*
1281 * Packets coming from the hook make no sense
1282 * to sessions in these states. Throw them away.

--- 295 unchanged lines hidden (view full) ---

1578{
1579 int error;
1580 struct ng_mesg *msg;
1581 struct ngpppoe_sts *sts;
1582
1583AAA
1584 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
1585 sizeof(struct ngpppoe_sts), M_NOWAIT);
1315 scan_tags(sp, ph);
1316 make_packet(sp);
1317 sendpacket(sp);
1318 break;
1319
1320 /*
1321 * Packets coming from the hook make no sense
1322 * to sessions in these states. Throw them away.

--- 295 unchanged lines hidden (view full) ---

1618{
1619 int error;
1620 struct ng_mesg *msg;
1621 struct ngpppoe_sts *sts;
1622
1623AAA
1624 NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
1625 sizeof(struct ngpppoe_sts), M_NOWAIT);
1626 if (msg == NULL)
1627 return (ENOMEM);
1586 sts = (struct ngpppoe_sts *)msg->data;
1587 strncpy(sts->hook, sp->hook->name, NG_HOOKLEN + 1);
1628 sts = (struct ngpppoe_sts *)msg->data;
1629 strncpy(sts->hook, sp->hook->name, NG_HOOKLEN + 1);
1588 error = ng_send_msg(sp->hook->node, msg, sp->creator, NULL);
1630 error = ng_send_msg(sp->hook->node, msg, sp->creator, NULL, NULL, NULL);
1589 return (error);
1590}
1631 return (error);
1632}