merge
[l2tpns.git] / ppp.c
diff --git a/ppp.c b/ppp.c
index fd17a46..c2c3379 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -1,6 +1,6 @@
 // L2TPNS PPP Stuff
 
 // L2TPNS PPP Stuff
 
-char const *cvs_id_ppp = "$Id: ppp.c,v 1.12 2004-08-13 00:02:50 fred_nerk Exp $";
+char const *cvs_id_ppp = "$Id: ppp.c,v 1.17 2004-10-29 04:01:53 bodea Exp $";
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -251,7 +251,7 @@ void dumplcp(u8 *p, int l)
                {
                        case 1: // Maximum-Receive-Unit
                                if (length == 4)
                {
                        case 1: // Maximum-Receive-Unit
                                if (length == 4)
-                               log(4, 0, 0, 0, "    %s %d\n", lcp_types[type], ntohs(*(u16 *)(o + 2)));
+                                       log(4, 0, 0, 0, "    %s %d\n", lcp_types[type], ntohs(*(u16 *)(o + 2)));
                                else
                                        log(4, 0, 0, 0, "    %s odd length %d\n", lcp_types[type], length);
                                break;
                                else
                                        log(4, 0, 0, 0, "    %s odd length %d\n", lcp_types[type], length);
                                break;
@@ -259,7 +259,7 @@ void dumplcp(u8 *p, int l)
                                {
                                        if (length == 4)
                                        {
                                {
                                        if (length == 4)
                                        {
-                                       int proto = ntohs(*(u16 *)(o + 2));
+                                               int proto = ntohs(*(u16 *)(o + 2));
                                                log(4, 0, 0, 0, "   %s 0x%x (%s)\n", lcp_types[type], proto,
                                                        proto == 0xC223 ? "CHAP" :
                                                        proto == 0xC023 ? "PAP"  : "UNKNOWN");
                                                log(4, 0, 0, 0, "   %s 0x%x (%s)\n", lcp_types[type], proto,
                                                        proto == 0xC223 ? "CHAP" :
                                                        proto == 0xC023 ? "PAP"  : "UNKNOWN");
@@ -278,8 +278,8 @@ void dumplcp(u8 *p, int l)
                                {
                                        if (length == 6)
                                        {
                                {
                                        if (length == 6)
                                        {
-                                       u32 magicno = ntohl(*(u32 *)(o + 2));
-                                       log(4, 0, 0, 0, "    %s %x\n", lcp_types[type], magicno);
+                                               u32 magicno = ntohl(*(u32 *)(o + 2));
+                                               log(4, 0, 0, 0, "    %s %x\n", lcp_types[type], magicno);
                                        }
                                        else
                                                log(4, 0, 0, 0, "   %s odd length %d\n", lcp_types[type], length);
                                        }
                                        else
                                                log(4, 0, 0, 0, "   %s odd length %d\n", lcp_types[type], length);
@@ -328,6 +328,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 * p, u16 l)
        }
        else if (*p == ConfigReq)
        {
        }
        else if (*p == ConfigReq)
        {
+               l =  ntohs(*(u16 *)(p + 2));
                signed int x = l - 4;
                u8 *o = (p + 4);
 
                signed int x = l - 4;
                u8 *o = (p + 4);
 
@@ -411,8 +412,8 @@ void processlcp(tunnelidt t, sessionidt s, u8 * p, u16 l)
                {
                        // Send back a ConfigAck
                        log(3, session[s].ip, s, t, "ConfigReq accepted, sending as Ack\n");
                {
                        // Send back a ConfigAck
                        log(3, session[s].ip, s, t, "ConfigReq accepted, sending as Ack\n");
-                       // for  win2k L2TP clientis  and LCP renegotiation of alive session 
-                       if (magicno || l == 4) initlcp(t, s);
+                       // for win2k L2TP clients and LCP renegotiation of alive session
+                       if (magicno || l == 4 || (session[s].mru && l == 8)) initlcp(t, s);
                        q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
                        if (!q)
                        {
                        q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
                        if (!q)
                        {
@@ -512,7 +513,8 @@ void processipcp(tunnelidt t, sessionidt s, u8 * p, u16 l)
        {
                // happy with our IPCP
                u16 r = session[s].radius;
        {
                // happy with our IPCP
                u16 r = session[s].radius;
-               if ((!r || radius[r].state == RADIUSIPCP) && !session[s].walled_garden) {
+               if ((!r || radius[r].state == RADIUSIPCP) && !session[s].walled_garden)
+               {
                        if (!r)
                                r = radiusnew(s);
                        if (r)
                        if (!r)
                                r = radiusnew(s);
                        if (r)
@@ -636,7 +638,6 @@ void processipin(tunnelidt t, sessionidt s, u8 * p, u16 l)
 {
        ipt ip;
 
 {
        ipt ip;
 
-
        CSTAT(call_processipin);
 
        log_hex(5, "IP", p, l);
        CSTAT(call_processipin);
 
        log_hex(5, "IP", p, l);
@@ -676,7 +677,7 @@ void processipin(tunnelidt t, sessionidt s, u8 * p, u16 l)
 
        if (session[s].snoop_ip && session[s].snoop_port)
        {
 
        if (session[s].snoop_ip && session[s].snoop_port)
        {
-               // Snooping this session, send it to ASIO
+               // Snooping this session
                snoop_send_packet(p, l, session[s].snoop_ip, session[s].snoop_port);
        }
        STAT(tun_tx_packets);
                snoop_send_packet(p, l, session[s].snoop_ip, session[s].snoop_port);
        }
        STAT(tun_tx_packets);
@@ -730,7 +731,7 @@ void processccp(tunnelidt t, sessionidt s, u8 * p, u16 l)
        log_hex(5, "CCP", p, l);
        if (l < 2 || (*p != ConfigReq && *p != TerminateReq))
        {
        log_hex(5, "CCP", p, l);
        if (l < 2 || (*p != ConfigReq && *p != TerminateReq))
        {
-               log(1, 0, s, t, "Unexpecetd CCP request code %d\n", *p);
+               log(1, 0, s, t, "Unexpected CCP request code %d\n", *p);
                STAT(tunnel_rx_errors);
                return ;
        }
                STAT(tunnel_rx_errors);
                return ;
        }
@@ -814,7 +815,6 @@ void sendchap(tunnelidt t, sessionidt s)
 // returns start of PPP frame
 u8 *makeppp(u8 * b, int size, u8 * p, int l, tunnelidt t, sessionidt s, u16 mtype)
 {
 // returns start of PPP frame
 u8 *makeppp(u8 * b, int size, u8 * p, int l, tunnelidt t, sessionidt s, u16 mtype)
 {
-
        if (size < 12)
                return NULL;    // Need more space than this!!
 
        if (size < 12)
                return NULL;    // Need more space than this!!
 
@@ -822,7 +822,7 @@ u8 *makeppp(u8 * b, int size, u8 * p, int l, tunnelidt t, sessionidt s, u16 mtyp
        *(u16 *) (b + 2) = htons(tunnel[t].far); // tunnel
        *(u16 *) (b + 4) = htons(session[s].far); // session
        b += 6;
        *(u16 *) (b + 2) = htons(tunnel[t].far); // tunnel
        *(u16 *) (b + 4) = htons(session[s].far); // session
        b += 6;
-       if (mtype && !(session[s].l2tp_flags & SESSIONACFC))
+       if (mtype == PPPLCP || !(session[s].l2tp_flags & SESSIONACFC))
        {
                *(u16 *) b = htons(0xFF03); // HDLC header
                b += 2;
        {
                *(u16 *) b = htons(0xFF03); // HDLC header
                b += 2;