// L2TPNS PPP Stuff
-char const *cvs_id_ppp = "$Id: ppp.c,v 1.33 2004-11-29 02:17:18 bodea Exp $";
+char const *cvs_id_ppp = "$Id: ppp.c,v 1.37 2004-11-30 01:35:19 bodea Exp $";
#include <stdio.h>
#include <string.h>
{
int x = l - 4;
u8 *o = (p + 4);
- u8 response = 0;
+ u8 *response = 0;
LOG(3, s, t, "LCP: ConfigReq (%d bytes)...\n", l);
if (config->debug > 3) dumplcp(p, l);
{
int type = o[0];
int length = o[1];
+
if (length == 0 || type == 0 || x < length) break;
switch (type)
{
if (!ntohl(*(u32 *)(o + 2))) // all bits zero is OK
break;
- if (response && response != ConfigNak) // rej already queued
+ if (response && *response != ConfigNak) // rej already queued
break;
LOG(2, s, t, " Remote requesting asyncmap. Rejecting.\n");
if (!response)
{
- q = makeppp(b, sizeof(b), NULL, 0, t, s, PPPLCP);
+ q = response = makeppp(b, sizeof(b), p, 2, t, s, PPPLCP);
if (!q) break;
- response = *q++ = ConfigNak;
+ *q = ConfigNak;
+ q += 4;
}
if ((q - b + 11) > sizeof(b))
*q++ = 6;
memset(q, 0, 4); // asyncmap 0
q += 4;
+ *((u16 *) (response + 2)) = q - response; // LCP header length
break;
case 3: // Authentication-Protocol
if (proto == PPPPAP)
break;
- if (response && response != ConfigNak) // rej already queued
+ if (response && *response != ConfigNak) // rej already queued
break;
if (proto == PPPCHAP)
if (!response)
{
- q = makeppp(b, sizeof(b), NULL, 0, t, s, PPPLCP);
+ q = response = makeppp(b, sizeof(b), p, 2, t, s, PPPLCP);
if (!q) break;
- response = *q++ = ConfigNak;
+ *q = ConfigNak;
+ q += 4;
}
if ((q - b + length) > sizeof(b))
memcpy(q, o, length);
*(u16 *)(q += 2) = htons(PPPPAP); // NAK -> Use PAP instead
q += length;
+ *((u16 *) (response + 2)) = q - response;
}
break;
default: // Reject any unknown options
LOG(2, s, t, " Rejecting PPP LCP Option type %d\n", type);
- if (!response || response != ConfigRej) // drop nak in favour of rej
+ if (!response || *response != ConfigRej) // drop nak in favour of rej
{
- q = makeppp(b, sizeof(b), NULL, 0, t, s, PPPLCP);
- if (!q) return;
- response = *q++ = ConfigRej;
+ q = response = makeppp(b, sizeof(b), p, 2, t, s, PPPLCP);
+ if (!q) break;
+ *q = ConfigRej;
+ q += 4;
}
if ((q - b + length) > sizeof(b))
memcpy(q, o, length);
q += length;
+ *((u16 *) (response + 2)) = q - response; // LCP header length
}
x -= length;
o += length;
if (!response)
{
// Send back a ConfigAck
- q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
+ q = response = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
if (!q) return;
- response = *q = ConfigAck;
+ *q = ConfigAck;
}
- LOG(3, s, t, "Sending %s\n", ppp_lcp_types[response]);
+ LOG(3, s, t, "Sending %s\n", ppp_lcp_types[*response]);
tunnelsend(b, l + (q - b), t);
if (!(session[s].flags & SF_LCP_ACKED))
{
*(u32 *) (i + 2) = htonl(session[s].dns1);
*p = ConfigNak;
- LOG(5, s, t, " DNS1 = %s\n", fmtaddr(session[s].dns1, 0));
+ LOG(5, s, t, " DNS1 = %s\n",
+ fmtaddr(htonl(session[s].dns1), 0));
}
}
if ((i = findppp(p, 0x83))) // Secondary DNS address (TBA, is it)
{
*(u32 *) (i + 2) = htonl(session[s].dns2);
*p = ConfigNak;
- LOG(5, s, t, " DNS2 = %s\n", fmtaddr(session[s].dns2, 0));
+ LOG(5, s, t, " DNS2 = %s\n",
+ fmtaddr(htonl(session[s].dns2), 0));
}
}
i = findppp(p, 3); // IP address