Deleted Added
full compact
ng_pppoe.c (52443) ng_pppoe.c (52448)
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@whistle.com>
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@whistle.com>
38 *
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 52443 1999-10-23 15:15:42Z julian $
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.c 52448 1999-10-23 22:46:38Z julian $
40 * $Whistle: ng_pppoe.c,v 1.7 1999/10/16 10:16:43 julian Exp $
41 */
42#if 0
43#define AAA printf("pppoe: %s\n", __FUNCTION__ );
44#else
45#define AAA
46#endif
47

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

392 * Routine to find a particular session that matches an incoming packet *
393 **************************************************************************/
394static hook_p
395pppoe_findsession(node_p node, struct pppoe_full_hdr *wh)
396{
397 sessp sp = NULL;
398 hook_p hook = NULL;
399 priv_p privp = node->private;
40 * $Whistle: ng_pppoe.c,v 1.7 1999/10/16 10:16:43 julian Exp $
41 */
42#if 0
43#define AAA printf("pppoe: %s\n", __FUNCTION__ );
44#else
45#define AAA
46#endif
47

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

392 * Routine to find a particular session that matches an incoming packet *
393 **************************************************************************/
394static hook_p
395pppoe_findsession(node_p node, struct pppoe_full_hdr *wh)
396{
397 sessp sp = NULL;
398 hook_p hook = NULL;
399 priv_p privp = node->private;
400 u_int16_t session = wh->ph.sid;
400 u_int16_t session = ntohs(wh->ph.sid);
401
402 /*
403 * find matching peer/session combination.
404 */
405AAA
406 LIST_FOREACH(hook, &node->hooks, hooks) {
407 /* don't check special hooks */
408 if ((hook->private == &privp->debug_hook)

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

785 privp->packets_out++;
786 } else if (hook->private == &privp->ethernet_hook) {
787 /*
788 * Incoming data.
789 * Dig out various fields from the packet.
790 * use them to decide where to send it.
791 */
792
401
402 /*
403 * find matching peer/session combination.
404 */
405AAA
406 LIST_FOREACH(hook, &node->hooks, hooks) {
407 /* don't check special hooks */
408 if ((hook->private == &privp->debug_hook)

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

785 privp->packets_out++;
786 } else if (hook->private == &privp->ethernet_hook) {
787 /*
788 * Incoming data.
789 * Dig out various fields from the packet.
790 * use them to decide where to send it.
791 */
792
793#if 0
793printf("got packet\n");
794LEAVE(0);
794printf("got packet\n");
795LEAVE(0);
796#endif
795
796 privp->packets_in++;
797 m_pullup(m, sizeof(*wh)); /* Checks length */
798 if (m == NULL) {
797
798 privp->packets_in++;
799 m_pullup(m, sizeof(*wh)); /* Checks length */
800 if (m == NULL) {
801 printf("couldn't m_pullup\n");
799 LEAVE(ENOBUFS);
800 }
801 wh = mtod(m, struct pppoe_full_hdr *);
802 ph = &wh->ph;
803 session = ntohs(wh->ph.sid);
804 length = ntohs(wh->ph.length);
805 code = wh->ph.code;
806 switch(ntohs(wh->eh.ether_type)) {

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

812 * (Linux wouldn't have this problem).
813 */
814 if (m->m_len != m->m_pkthdr.len) {
815 /*
816 * It's not all in one piece.
817 * We need to do extra work.
818 */
819 printf("packet fragmented\n");
802 LEAVE(ENOBUFS);
803 }
804 wh = mtod(m, struct pppoe_full_hdr *);
805 ph = &wh->ph;
806 session = ntohs(wh->ph.sid);
807 length = ntohs(wh->ph.length);
808 code = wh->ph.code;
809 switch(ntohs(wh->eh.ether_type)) {

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

815 * (Linux wouldn't have this problem).
816 */
817 if (m->m_len != m->m_pkthdr.len) {
818 /*
819 * It's not all in one piece.
820 * We need to do extra work.
821 */
822 printf("packet fragmented\n");
823 LEAVE(EMSGSIZE);
820 }
821
822 switch(code) {
823 case PADI_CODE:
824 /*
825 * We are a server:
826 * Look for a hook with the required service
827 * and send the ENTIRE packet up there.
828 * It should come back to a new hook in
829 * PRIMED state. Look there for further
830 * processing.
831 */
832 tag = get_tag(ph, PTT_SRV_NAME);
833 if (tag == NULL) {
824 }
825
826 switch(code) {
827 case PADI_CODE:
828 /*
829 * We are a server:
830 * Look for a hook with the required service
831 * and send the ENTIRE packet up there.
832 * It should come back to a new hook in
833 * PRIMED state. Look there for further
834 * processing.
835 */
836 tag = get_tag(ph, PTT_SRV_NAME);
837 if (tag == NULL) {
838 printf("no service tag\n");
834 LEAVE(ENETUNREACH);
835 }
836 sendhook = pppoe_match_svc(hook->node,
837 tag->tag_data, ntohs(tag->tag_len));
838 if (sendhook) {
839 NG_SEND_DATA(error, sendhook, m, meta);
840 } else {
839 LEAVE(ENETUNREACH);
840 }
841 sendhook = pppoe_match_svc(hook->node,
842 tag->tag_data, ntohs(tag->tag_len));
843 if (sendhook) {
844 NG_SEND_DATA(error, sendhook, m, meta);
845 } else {
846 printf("no such service\n");
841 LEAVE(ENETUNREACH);
842 }
843 break;
844 case PADO_CODE:
845 /*
846 * We are a client:
847 * Use the host_uniq tag to find the
848 * hook this is in response to.
847 LEAVE(ENETUNREACH);
848 }
849 break;
850 case PADO_CODE:
851 /*
852 * We are a client:
853 * Use the host_uniq tag to find the
854 * hook this is in response to.
849 *
855 * Received #2, now send #3
850 * For now simply accept the first we receive.
851 */
852 tag = get_tag(ph, PTT_HOST_UNIQ);
853 if ((tag == NULL)
854 || (ntohs(tag->tag_len) != sizeof(sp))) {
856 * For now simply accept the first we receive.
857 */
858 tag = get_tag(ph, PTT_HOST_UNIQ);
859 if ((tag == NULL)
860 || (ntohs(tag->tag_len) != sizeof(sp))) {
861 printf("no host unique field\n");
855 LEAVE(ENETUNREACH);
856 }
857
858 sendhook = pppoe_finduniq(node, tag);
859 if (sendhook == NULL) {
862 LEAVE(ENETUNREACH);
863 }
864
865 sendhook = pppoe_finduniq(node, tag);
866 if (sendhook == NULL) {
867 printf("no matching session\n");
860 LEAVE(ENETUNREACH);
861 }
862
863 /*
864 * Check the session is in the right state.
865 * It needs to be in PPPOE_SINIT.
866 */
867 sp = sendhook->private;
868 if (sp->state != PPPOE_SINIT) {
868 LEAVE(ENETUNREACH);
869 }
870
871 /*
872 * Check the session is in the right state.
873 * It needs to be in PPPOE_SINIT.
874 */
875 sp = sendhook->private;
876 if (sp->state != PPPOE_SINIT) {
877 printf("session in wrong state\n");
869 LEAVE(ENETUNREACH);
870 }
871 neg = sp->neg;
872 untimeout(pppoe_ticker, sendhook,
873 neg->timeout_handle);
874
875 /*
876 * This is the first time we hear
877 * from the server, so note it's
878 * unicast address, replacing the
879 * broadcast address .
880 */
881 bcopy(wh->eh.ether_shost,
882 neg->pkt->pkt_header.eh.ether_dhost,
883 ETHER_ADDR_LEN);
884 neg->timeout = 0;
885 neg->pkt->pkt_header.ph.code = PADR_CODE;
886 init_tags(sp);
878 LEAVE(ENETUNREACH);
879 }
880 neg = sp->neg;
881 untimeout(pppoe_ticker, sendhook,
882 neg->timeout_handle);
883
884 /*
885 * This is the first time we hear
886 * from the server, so note it's
887 * unicast address, replacing the
888 * broadcast address .
889 */
890 bcopy(wh->eh.ether_shost,
891 neg->pkt->pkt_header.eh.ether_dhost,
892 ETHER_ADDR_LEN);
893 neg->timeout = 0;
894 neg->pkt->pkt_header.ph.code = PADR_CODE;
895 init_tags(sp);
887 insert_tag(sp,&neg->service.hdr); /* Service */
896 insert_tag(sp, &neg->service.hdr); /* Service */
888 insert_tag(sp, tag); /* Host Unique */
889 tag = get_tag(ph, PTT_AC_COOKIE);
897 insert_tag(sp, tag); /* Host Unique */
898 tag = get_tag(ph, PTT_AC_COOKIE);
890 insert_tag(sp, tag); /* returned cookie */
899 if (tag)
900 insert_tag(sp, tag); /* return cookie */
891 scan_tags(sp, ph);
892 make_packet(sp);
893 sp->state = PPPOE_SREQ;
894 sendpacket(sp);
895 break;
896 case PADR_CODE:
897
898 /*

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

932 break;
933 }
934 neg = sp->neg;
935 untimeout(pppoe_ticker, sendhook,
936 neg->timeout_handle);
937 neg->pkt->pkt_header.ph.code = PADS_CODE;
938 if (sp->Session_ID == 0)
939 neg->pkt->pkt_header.ph.sid =
901 scan_tags(sp, ph);
902 make_packet(sp);
903 sp->state = PPPOE_SREQ;
904 sendpacket(sp);
905 break;
906 case PADR_CODE:
907
908 /*

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

942 break;
943 }
944 neg = sp->neg;
945 untimeout(pppoe_ticker, sendhook,
946 neg->timeout_handle);
947 neg->pkt->pkt_header.ph.code = PADS_CODE;
948 if (sp->Session_ID == 0)
949 neg->pkt->pkt_header.ph.sid =
940 sp->Session_ID = get_new_sid(node);
950 htons(sp->Session_ID
951 = get_new_sid(node));
941 neg->timeout = 0;
942 /*
943 * start working out the tags to respond with.
944 */
945 init_tags(sp);
946 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
947 insert_tag(sp, tag); /* ac_cookie */
948 tag = get_tag(ph, PTT_SRV_NAME);

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

996 */
997 sp = sendhook->private;
998 if (sp->state != PPPOE_SREQ) {
999 LEAVE(ENETUNREACH);
1000 }
1001 neg = sp->neg;
1002 untimeout(pppoe_ticker, sendhook,
1003 neg->timeout_handle);
952 neg->timeout = 0;
953 /*
954 * start working out the tags to respond with.
955 */
956 init_tags(sp);
957 insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
958 insert_tag(sp, tag); /* ac_cookie */
959 tag = get_tag(ph, PTT_SRV_NAME);

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

1007 */
1008 sp = sendhook->private;
1009 if (sp->state != PPPOE_SREQ) {
1010 LEAVE(ENETUNREACH);
1011 }
1012 neg = sp->neg;
1013 untimeout(pppoe_ticker, sendhook,
1014 neg->timeout_handle);
1004 sp->Session_ID = wh->ph.sid;
1015 sp->Session_ID = ntohs(wh->ph.sid);
1005 neg->timeout = 0;
1006 sp->state = PPPOE_CONNECTED;
1007 sendpacket(sp);
1008 /*
1009 * Now we have gone to Connected mode,
1010 * Free all resources needed for
1011 * negotiation.
1012 * Keep a copy of the header we will be using.

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

1311
1312AAA
1313 switch(sp->state) {
1314 case PPPOE_LISTENING:
1315 case PPPOE_DEAD:
1316 case PPPOE_SNONE:
1317 case PPPOE_NEWCONNECTED:
1318 case PPPOE_CONNECTED:
1016 neg->timeout = 0;
1017 sp->state = PPPOE_CONNECTED;
1018 sendpacket(sp);
1019 /*
1020 * Now we have gone to Connected mode,
1021 * Free all resources needed for
1022 * negotiation.
1023 * Keep a copy of the header we will be using.

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

1322
1323AAA
1324 switch(sp->state) {
1325 case PPPOE_LISTENING:
1326 case PPPOE_DEAD:
1327 case PPPOE_SNONE:
1328 case PPPOE_NEWCONNECTED:
1329 case PPPOE_CONNECTED:
1319 printf("pppoe: timeout: unexpected state\n");
1330 printf("pppoe: sendpacket: unexpected state\n");
1320 break;
1321
1322 case PPPOE_PRIMED:
1323 /* No packet to send, but set up the timeout */
1324 neg->timeout_handle = timeout(pppoe_ticker,
1325 hook, PPPOE_OFFER_TIMEOUT * hz);
1326 break;
1327

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

1334 NG_SEND_DATA( error, privp->ethernet_hook, m0, dummy);
1335 neg->timeout_handle = timeout(pppoe_ticker,
1336 hook, PPPOE_OFFER_TIMEOUT * hz);
1337 break;
1338
1339 case PPPOE_SINIT:
1340 case PPPOE_SREQ:
1341 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1331 break;
1332
1333 case PPPOE_PRIMED:
1334 /* No packet to send, but set up the timeout */
1335 neg->timeout_handle = timeout(pppoe_ticker,
1336 hook, PPPOE_OFFER_TIMEOUT * hz);
1337 break;
1338

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

1345 NG_SEND_DATA( error, privp->ethernet_hook, m0, dummy);
1346 neg->timeout_handle = timeout(pppoe_ticker,
1347 hook, PPPOE_OFFER_TIMEOUT * hz);
1348 break;
1349
1350 case PPPOE_SINIT:
1351 case PPPOE_SREQ:
1352 m0 = m_copypacket(sp->neg->m, M_DONTWAIT);
1342 NG_SEND_DATA( error, sp->hook, m0, dummy);
1353 NG_SEND_DATA( error, privp->ethernet_hook, m0, dummy);
1343 neg->timeout_handle = timeout(pppoe_ticker, hook, hz);
1344 neg->timeout = 2;
1345 break;
1346
1347 default:
1348 error = EINVAL;
1349 printf("pppoe: timeout: bad state\n");
1350 }

--- 62 unchanged lines hidden ---
1354 neg->timeout_handle = timeout(pppoe_ticker, hook, hz);
1355 neg->timeout = 2;
1356 break;
1357
1358 default:
1359 error = EINVAL;
1360 printf("pppoe: timeout: bad state\n");
1361 }

--- 62 unchanged lines hidden ---