Deleted Added
sdiff udiff text old ( 52443 ) new ( 52448 )
full compact
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 $
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;
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
793printf("got packet\n");
794LEAVE(0);
795
796 privp->packets_in++;
797 m_pullup(m, sizeof(*wh)); /* Checks length */
798 if (m == NULL) {
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");
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) {
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 {
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.
849 *
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))) {
855 LEAVE(ENETUNREACH);
856 }
857
858 sendhook = pppoe_finduniq(node, tag);
859 if (sendhook == NULL) {
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) {
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);
887 insert_tag(sp,&neg->service.hdr); /* Service */
888 insert_tag(sp, tag); /* Host Unique */
889 tag = get_tag(ph, PTT_AC_COOKIE);
890 insert_tag(sp, tag); /* returned 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 =
940 sp->Session_ID = 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);
1004 sp->Session_ID = 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:
1319 printf("pppoe: timeout: 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);
1342 NG_SEND_DATA( error, sp->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 ---