Add renegotiation patch from Yuri (ppp-aug10-patch)

Indentation and style cleanups
Make md5.c use standard memcpy and memset
This commit is contained in:
David Parrish 2004-08-13 00:02:50 +00:00
parent 5779efc7ae
commit d490579025
7 changed files with 2628 additions and 2666 deletions

View file

@ -10,7 +10,8 @@
- Add startup script and monitor script from Yuri
- Some logging correctness fixes from Iain Wade
- Add support for LCP Ident and CallBack (rejection only) from Yuri
- Initiate LCP if not attempted by the client
- Initiate LCP if not attempted by the client, or in renegotiation - Yuri
- Indentation and style cleanups
* Tue Jul 13 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.1
- Update INSTALL, Docs/manual.html documentation.

11
bgp.c
View file

@ -10,7 +10,7 @@
* nor RFC2385 (which requires a kernel patch on 2.4 kernels).
*/
char const *cvs_id_bgp = "$Id: bgp.c,v 1.2 2004-06-28 02:43:13 fred_nerk Exp $";
char const *cvs_id_bgp = "$Id: bgp.c,v 1.3 2004-08-13 00:02:50 fred_nerk Exp $";
#include <stdlib.h>
#include <unistd.h>
@ -63,8 +63,7 @@ int bgp_setup(int as)
peer->sock = -1;
peer->state = peer->next_state = Disabled;
if (!((peer->outbuf = malloc(sizeof(*peer->outbuf)))
&& (peer->inbuf = malloc(sizeof(*peer->inbuf)))))
if (!((peer->outbuf = malloc(sizeof(*peer->outbuf))) && (peer->inbuf = malloc(sizeof(*peer->inbuf)))))
{
log(0, 0, 0, 0, "Can't allocate buffers for bgp peer (%s)\n",
strerror(errno));
@ -108,8 +107,7 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int enable)
if (!(h = gethostbyname(name)) || h->h_addrtype != AF_INET)
{
log(0, 0, 0, 0, "Can't get address for BGP peer %s (%s)\n",
name, h ? "no address" : hstrerror(h_errno));
log(0, 0, 0, 0, "Can't get address for BGP peer %s (%s)\n", name, h ? "no address" : hstrerror(h_errno));
return 0;
}
@ -1320,8 +1318,7 @@ int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc)
continue;
addr = inet_toa(bgp_peers[i].addr);
if (argc && strcmp(addr, argv[0]) &&
strncmp(bgp_peers[i].name, argv[0], strlen(argv[0])))
if (argc && strcmp(addr, argv[0]) && strncmp(bgp_peers[i].name, argv[0], strlen(argv[0])))
continue;
bgp_peers[i].cli_flag = BGP_CLI_RESTART;

2
cli.c
View file

@ -2,7 +2,7 @@
// vim: sw=4 ts=8
char const *cvs_name = "$Name: $";
char const *cvs_id_cli = "$Id: cli.c,v 1.10 2004-07-11 07:57:33 bodea Exp $";
char const *cvs_id_cli = "$Id: cli.c,v 1.11 2004-08-13 00:02:50 fred_nerk Exp $";
#include <stdio.h>
#include <stdarg.h>

View file

@ -4,7 +4,7 @@
// Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced
// vim: sw=8 ts=8
char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.21 2004-08-02 06:06:28 fred_nerk Exp $";
char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.22 2004-08-13 00:02:50 fred_nerk Exp $";
#include <arpa/inet.h>
#include <assert.h>
@ -1780,6 +1780,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr)
// TBA
break;
case 12: // ICCN
if ( amagic == 0) amagic = time_now;
session[s].magic = amagic; // set magic number
session[s].l2tp_flags = aflags; // set flags received
log(3, ntohl(addr->sin_addr.s_addr), s, t, "Magic %X Flags %X\n", amagic, aflags);
@ -2785,6 +2786,7 @@ void snoop_send_packet(char *packet, u16 size, ipt destination, u16 port)
}
void dump_acct_info()
{
char filename[1024];
char timestr[64];
@ -2808,7 +2810,7 @@ void dump_acct_info()
if (!(f = fopen(filename, "w")))
{
log(0, 0, 0, 0, "Can't write accounting info to %s: %s\n", filename, strerror(errno));
return;
return ;
}
log(3, 0, 0, 0, "Dumping accounting information to %s\n", filename);
fprintf(f, "# dslwatch.pl dump file V1.01\n"
@ -2833,7 +2835,8 @@ void dump_acct_info()
session[i].pout = session[i].cout = 0;
}
if (f) fclose(f);
if (f)
fclose(f);
}
// Main program
@ -3088,26 +3091,26 @@ void read_state()
int i;
ippoolt itmp;
FILE *f;
char magic[sizeof(DUMP_MAGIC)-1];
char magic[sizeof(DUMP_MAGIC) - 1];
u32 buf[2];
if (!config->save_state)
{
unlink(STATEFILE);
return;
return ;
}
if (stat(STATEFILE, &sb) < 0)
{
unlink(STATEFILE);
return;
return ;
}
if (sb.st_mtime < (time(NULL) - 60))
{
log(0, 0, 0, 0, "State file is too old to read, ignoring\n");
unlink(STATEFILE);
return;
return ;
}
f = fopen(STATEFILE, "r");
@ -3215,34 +3218,44 @@ void dump_state()
if (!config->save_state)
return;
do {
do
{
if (!(f = fopen(STATEFILE, "w")))
break;
log(1, 0, 0, 0, "Dumping state information\n");
if (fwrite(DUMP_MAGIC, sizeof(DUMP_MAGIC)-1, 1, f) != 1) break;
if (fwrite(DUMP_MAGIC, sizeof(DUMP_MAGIC) - 1, 1, f) != 1)
break;
log(2, 0, 0, 0, "Dumping %u ip addresses\n", ip_pool_size);
buf[0] = ip_pool_size;
buf[1] = sizeof(ippoolt);
if (fwrite(buf, sizeof(buf), 1, f) != 1) break;
if (fwrite(ip_address_pool, sizeof(ippoolt), ip_pool_size, f) != ip_pool_size) break;
if (fwrite(buf, sizeof(buf), 1, f) != 1)
break;
if (fwrite(ip_address_pool, sizeof(ippoolt), ip_pool_size, f) != ip_pool_size)
break;
log(2, 0, 0, 0, "Dumping %u tunnels\n", MAXTUNNEL);
buf[0] = MAXTUNNEL;
buf[1] = sizeof(tunnelt);
if (fwrite(buf, sizeof(buf), 1, f) != 1) break;
if (fwrite(tunnel, sizeof(tunnelt), MAXTUNNEL, f) != MAXTUNNEL) break;
if (fwrite(buf, sizeof(buf), 1, f) != 1)
break;
if (fwrite(tunnel, sizeof(tunnelt), MAXTUNNEL, f) != MAXTUNNEL)
break;
log(2, 0, 0, 0, "Dumping %u sessions\n", MAXSESSION);
buf[0] = MAXSESSION;
buf[1] = sizeof(sessiont);
if (fwrite(buf, sizeof(buf), 1, f) != 1) break;
if (fwrite(session, sizeof(sessiont), MAXSESSION, f) != MAXSESSION) break;
if (fwrite(buf, sizeof(buf), 1, f) != 1)
break;
if (fwrite(session, sizeof(sessiont), MAXSESSION, f) != MAXSESSION)
break;
if (fclose(f) == 0) return; // OK
} while (0);
if (fclose(f) == 0)
return ; // OK
}
while (0);
log(0, 0, 0, 0, "Can't write state information: %s\n", strerror(errno));
unlink(STATEFILE);

2
ll.c
View file

@ -1,6 +1,6 @@
// L2TPNS Linked List Stuff
char const *cvs_id_ll = "$Id: ll.c,v 1.4 2004-06-28 02:43:13 fred_nerk Exp $";
char const *cvs_id_ll = "$Id: ll.c,v 1.5 2004-08-13 00:02:50 fred_nerk Exp $";
#include <stdio.h>
#include <sys/file.h>

91
md5.c
View file

@ -1,7 +1,7 @@
/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
*/
char const *cvs_id_md5 = "$Id: md5.c,v 1.2 2004-06-28 02:43:13 fred_nerk Exp $";
char const *cvs_id_md5 = "$Id: md5.c,v 1.3 2004-08-13 00:02:50 fred_nerk Exp $";
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
@ -25,6 +25,7 @@ These notices must be retained in any copies of any part of this
documentation and/or software.
*/
#include <string.h>
#include "md5.h"
/* Constants for MD5Transform routine.
@ -50,8 +51,6 @@ documentation and/or software.
static void MD5Transform PROTO_LIST((UINT4[4], unsigned char[64]));
static void Encode PROTO_LIST((unsigned char *, UINT4 *, unsigned int));
static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int));
static void MD5_memcpy PROTO_LIST((POINTER, POINTER, unsigned int));
static void MD5_memset PROTO_LIST((POINTER, int, unsigned int));
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -96,13 +95,10 @@ Rotation is separate from addition to prevent recomputation.
/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
void
MD5Init(context)
MD5_CTX *context; /* context */
void MD5Init(MD5_CTX *context)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
*/
// Load magic initialization constants.
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
@ -113,11 +109,8 @@ MD5Init(context)
operation, processing another message block, and updating the
context.
*/
void
MD5Update(context, input, inputLen)
MD5_CTX *context; /* context */
unsigned char *input; /* input block */
unsigned int inputLen; /* length of input block */
void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen)
{
unsigned int i,
index,
@ -137,7 +130,7 @@ MD5Update(context, input, inputLen)
*/
if (inputLen >= partLen)
{
MD5_memcpy((POINTER) & context->buffer[index], (POINTER) input, partLen);
memcpy(&context->buffer[index], input, partLen);
MD5Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
@ -149,20 +142,16 @@ MD5Update(context, input, inputLen)
i = 0;
/* Buffer remaining input */
MD5_memcpy((POINTER) & context->buffer[index], (POINTER) & input[i], inputLen - i);
memcpy(&context->buffer[index], &input[i], inputLen - i);
}
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
the message digest and zeroizing the context.
*/
void
MD5Final(digest, context)
unsigned char digest[16]; /* message digest */
MD5_CTX *context; /* context */
void MD5Final(unsigned char digest[16], MD5_CTX *context)
{
unsigned char bits[8];
unsigned int index,
padLen;
unsigned int index, padLen;
/* Save number of bits */
Encode(bits, context->count, 8);
@ -181,15 +170,12 @@ MD5Final(digest, context)
/* Zeroize sensitive information.
*/
MD5_memset((POINTER) context, 0, sizeof(*context));
memset(context, 0, sizeof(*context));
}
/* MD5 basic transformation. Transforms state based on block.
*/
static void
MD5Transform(state, block)
UINT4 state[4];
unsigned char block[64];
static void MD5Transform(UINT4 state[4], unsigned char block[64])
{
UINT4 a = state[0],
b = state[1],
@ -277,23 +263,16 @@ MD5Transform(state, block)
state[2] += c;
state[3] += d;
/* Zeroize sensitive information.
*/
MD5_memset((POINTER) x, 0, sizeof(x));
// Zeroize sensitive information.
memset(x, 0, sizeof(x));
}
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
a multiple of 4.
*/
static void
Encode(output, input, len)
unsigned char *output;
UINT4 *input;
unsigned int len;
static void Encode(unsigned char *output, UINT4 *input, unsigned int len)
{
unsigned int i,
j;
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
{
@ -307,45 +286,11 @@ Encode(output, input, len)
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
a multiple of 4.
*/
static void
Decode(output, input, len)
UINT4 *output;
unsigned char *input;
unsigned int len;
static void Decode(UINT4 *output, unsigned char *input, unsigned int len)
{
unsigned int i,
j;
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4) input[j]) | (((UINT4) input[j + 1]) << 8) | (((UINT4) input[j + 2]) << 16) | (((UINT4) input[j + 3]) << 24);
}
/* Note: Replace "for loop" with standard memcpy if possible.
*/
static void
MD5_memcpy(output, input, len)
POINTER output;
POINTER input;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
output[i] = input[i];
}
/* Note: Replace "for loop" with standard memset if possible.
*/
static void
MD5_memset(output, value, len)
POINTER output;
int value;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
((char *) output)[i] = (char) value;
}

32
ppp.c
View file

@ -1,6 +1,6 @@
// L2TPNS PPP Stuff
char const *cvs_id_ppp = "$Id: ppp.c,v 1.11 2004-08-02 06:06:28 fred_nerk Exp $";
char const *cvs_id_ppp = "$Id: ppp.c,v 1.12 2004-08-13 00:02:50 fred_nerk Exp $";
#include <stdio.h>
#include <string.h>
@ -95,7 +95,8 @@ void processpap(tunnelidt t, sessionidt s, u8 * p, u16 l)
tunnelsend(b, 5 + (p - b), t); // send it
}
else
{ // set up RADIUS request
{
// set up RADIUS request
u16 r = session[s].radius;
// Run PRE_AUTH plugins
@ -410,15 +411,16 @@ 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");
// for win2k L2TP clientis and LCP renegotiation of alive session
if (magicno || l == 4) initlcp(t, s);
q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
if (!q) {
if (!q)
{
log(3, session[s].ip, s, t, " failed to create packet.\n");
return;
}
*q = ConfigAck;
tunnelsend(b, l + (q - b), t);
// For win2k L2TP clients, LCP should be initiated by the LNS
if (magicno) initlcp(t, s);
}
else
{
@ -537,7 +539,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 * p, u16 l)
if (!session[s].ip)
{
log(3, 0, s, t, "Waiting on radius reply\n");
return ; // have to wait on RADIUS reply
return; // have to wait on RADIUS reply
}
// form a config reply quoting the IP in the session
{
@ -775,7 +777,8 @@ void sendchap(tunnelidt t, sessionidt s)
return ;
}
log(1, 0, s, t, "Send CHAP challenge\n");
{ // new challenge
{
// new challenge
int n;
for (n = 0; n < 15; n++)
radius[r].auth[n] = rand();
@ -797,7 +800,7 @@ void sendchap(tunnelidt t, sessionidt s)
log(1, 0, s, t, "failed to send CHAP challenge.\n");
return;
}
*q = 1; // challenhe
*q = 1; // challenge
q[1] = radius[r].id; // ID
q[4] = 16; // length
memcpy(q + 5, radius[r].auth, 16); // challenge
@ -874,11 +877,14 @@ void initlcp(tunnelidt t, sessionidt s)
log(4, 0, s, t, "Sending LCP ConfigReq for PAP\n");
*q = ConfigReq;
*(u8 *)(q + 1) = (time_now % 255) + 1; // ID
*(u16 *)(q + 2) = htons(8); // Length
*(u8 *)(q + 4) = 3;
*(u8 *)(q + 5) = 4;
*(u16 *)(q + 6) = htons(0xC023); // PAP
tunnelsend(b, 12 + 8, t);
*(u16 *)(q + 2) = htons(14); // Length
*(u8 *)(q + 4) = 5;
*(u8 *)(q + 5) = 6;
*(u32 *)(q + 6) = htonl(session[s].magic);
*(u8 *)(q + 10) = 3;
*(u8 *)(q + 11) = 4;
*(u16 *)(q + 12) = htons(0xC023); // PAP
tunnelsend(b, 12 + 14, t);
}
// Send CCP reply