// L2TPNS PPP Stuff
-char const *cvs_id_ppp = "$Id: ppp.c,v 1.76 2005/08/29 03:21:14 bodea Exp $";
+char const *cvs_id_ppp = "$Id: ppp.c,v 1.79 2005/08/31 12:41:09 bodea Exp $";
#include <stdio.h>
#include <string.h>
if (session[s].ip || !(r = radiusnew(s)))
{
// respond now, either no RADIUS available or already authenticated
- uint8_t b[MAXCONTROL];
+ uint8_t b[MAXETHER];
uint8_t id = p[1];
uint8_t *p = makeppp(b, sizeof(b), 0, 0, s, t, PPPPAP);
if (!p) return;
// Process LCP messages
void processlcp(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
{
- uint8_t b[MAXCONTROL];
+ uint8_t b[MAXETHER];
uint8_t *q = NULL;
uint32_t magicno = 0;
uint16_t hl;
if (session[s].ppp.lcp == Opened)
lcp_restart(s);
- sendlcp(s, t, sess_local[s].lcp_authtype);
+ sendlcp(s, t);
change_state(s, lcp, RequestSent);
break;
case Stopped:
initialise_restart_count(s, lcp);
- sendlcp(s, t, sess_local[s].lcp_authtype);
+ sendlcp(s, t);
if (*response == ConfigAck)
change_state(s, lcp, AckSent);
else
case Opened:
lcp_restart(s);
- sendlcp(s, t, sess_local[s].lcp_authtype);
+ sendlcp(s, t);
/* fallthrough */
case AckSent:
tunnelsend(b, l + (response - b), t);
}
- else if (*p == ConfigNak)
+ else if (*p == ConfigNak || *p == ConfigRej)
{
int x = l - 4;
uint8_t *o = (p + 4);
switch (type)
{
case 1: // Maximum-Receive-Unit
- session[s].mru = ntohs(*(uint16_t *)(o + 2));
- LOG(3, s, t, " Remote requested MRU of %u\n", session[s].mru);
+ if (*p == ConfigNak)
+ {
+ session[s].mru = ntohs(*(uint16_t *)(o + 2));
+ LOG(3, s, t, " Remote requested MRU of %u\n", session[s].mru);
+ }
+ else
+ {
+ session[s].mru = 0;
+ LOG(3, s, t, " Remote rejected MRU negotiation\n");
+ }
+
break;
case 3: // Authentication-Protocol
if (authtype > 0)
break;
+ if (*p == ConfigNak)
{
int proto = ntohs(*(uint16_t *)(o + 2));
if (proto == PPPPAP)
proto);
}
}
+ else
+ {
+ LOG(2, s, t, "LCP: remote rejected auth negotiation\n");
+ authtype = 0; // shutdown
+ }
break;
default:
- LOG(2, s, t, " Remote NAKed LCP type %u?\n", type);
+ LOG(2, s, t, "LCP: remote sent %s for type %u?\n", ppp_code(*p), type);
break;
}
x -= length;
case RequestSent:
case AckSent:
initialise_restart_count(s, lcp);
- sendlcp(s, t, sess_local[s].lcp_authtype);
+ sendlcp(s, t);
break;
case AckReceived:
LOG(2, s, t, "LCP: ConfigNak in state %s? Sending ConfigReq\n", ppp_state(session[s].ppp.lcp));
- sendlcp(s, t, sess_local[s].lcp_authtype);
+ sendlcp(s, t);
break;
case Opened:
lcp_restart(s);
- sendlcp(s, t, sess_local[s].lcp_authtype);
+ sendlcp(s, t);
break;
default:
{
// Ignore it, last_packet time is set earlier than this.
}
- else
+ else if (*p != CodeRej)
{
int code = *p;
int mru = session[s].mru;
// Process IPCP messages
void processipcp(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
{
- uint8_t b[MAXCONTROL];
+ uint8_t b[MAXETHER];
uint8_t *q = 0;
uint16_t hl;
tunnelsend(b, l + (q - b), t);
change_state(s, ipcp, Stopped);
}
- else
+ else if (*p != CodeRej)
{
int code = *p;
int mru = session[s].mru;
// Process IPV6CP messages
void processipv6cp(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
{
- uint8_t b[MAXCONTROL];
+ uint8_t b[MAXETHER];
uint8_t *q = 0;
uint16_t hl;
tunnelsend(b, l + (q - b), t);
change_state(s, ipv6cp, Stopped);
}
- else
+ else if (*p != CodeRej)
{
int code = *p;
int mru = session[s].mru;
// Process CCP messages
void processccp(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l)
{
- uint8_t b[MAXCONTROL];
+ uint8_t b[MAXETHER];
uint8_t *q;
CSTAT(processccp);
tunnelsend(b, l + (q - b), t);
change_state(s, ccp, Stopped);
}
- else
+ else if (*p != CodeRej)
{
int code = *p;
int mru = session[s].mru;
// send a CHAP challenge
void sendchap(sessionidt s, tunnelidt t)
{
- uint8_t b[MAXCONTROL];
+ uint8_t b[MAXETHER];
uint16_t r;
uint8_t *q;
}
// Send initial LCP ConfigReq for MRU, authentication type and magic no
-void sendlcp(sessionidt s, tunnelidt t, int authtype)
+void sendlcp(sessionidt s, tunnelidt t)
{
uint8_t b[500], *q, *l;
+ int authtype = sess_local[s].lcp_authtype;
if (!(q = makeppp(b, sizeof(b), NULL, 0, s, t, PPPLCP)))
return;
authtype ? (authtype == AUTHCHAP ? "CHAP" : "PAP") : "",
authtype ? ")" : "");
- if (!session[s].mru)
- session[s].mru = DEFAULT_MRU;
-
l = q;
*l++ = ConfigReq;
*l++ = (time_now % 255) + 1; // ID
l += 2; //Save space for length
- *l++ = 1; *l++ = 4; // Maximum-Receive-Unit (length 4)
- *(uint16_t *) l = htons(session[s].mru); l += 2;
+ if (session[s].mru)
+ {
+ *l++ = 1; *l++ = 4; // Maximum-Receive-Unit (length 4)
+ *(uint16_t *) l = htons(session[s].mru); l += 2;
+ }
if (authtype)
l += add_lcp_auth(l, sizeof(b) - (l - b), authtype);