Escolar Documentos
Profissional Documentos
Cultura Documentos
c
--- l2tpd-0.69_old/aaa.c 2002-04-23 13:50:49.000000000 -0600
+++ l2tpd-0.69_new/aaa.c 2005-09-26 01:10:16.000000000 -0600
@@ -25,7 +25,7 @@
/* FIXME: Accounting? */
-static struct addr_ent *uaddr[ADDR_HASH_SIZE];
+struct addr_ent *uaddr[ADDR_HASH_SIZE];
void init_addr ()
{
@@ -317,10 +317,11 @@
(ntohl (t->peer.sin_addr.s_addr) <= ntohl (ipr->end)))
{
#ifdef DEBUG_AAA
+ /* mferd, 29.01.2003: t->addr #ifdef'd out ... */
log (LOG_DEBUG,
"get_lns: Rule %s to %s, sense %s matched %s\n",
IPADDY (ipr->start), IPADDY (ipr->end),
- (ipr->sense ? "allow" : "deny"), IPADDY (t->addr));
+ (ipr->sense ? "allow" : "deny"), IPADDY (t->peer.sin_addr.
s_addr));
#endif
allow = ipr->sense;
}
diff -aur l2tpd-0.69_old/avp.c l2tpd-0.69_new/avp.c
--- l2tpd-0.69_old/avp.c 2002-08-19 09:39:27.000000000 -0600
+++ l2tpd-0.69_new/avp.c 2005-09-26 01:10:01.000000000 -0600
@@ -1596,6 +1596,7 @@
int hidlen;
char *data = buf->start + sizeof (struct control_hdr);
avp = (struct avp_hdr *) data;
+
if (debug_avp)
log (LOG_DEBUG, "%s: handling avp's for tunnel %d, call %d\n",
__FUNCTION__, t->ourtid, c->ourcid);
@@ -1608,7 +1609,7 @@
if (AMBIT (avp->length))
{
log (LOG_WARN,
- "%s: dont know how to handle mandatory attribute %d. Clo
sing %s.\n"
+ "%s: dont know how to handle mandatory attribute %d. Clo
sing %s.\n", /* mf, 04.05.2004: added ,*/
__FUNCTION__, avp->attr,
(c != t->self) ? "call" : "tunnel");
set_error (c, VENDOR_ERROR,
@@ -1643,7 +1644,7 @@
c->needclose = -1;
return -EINVAL;
}
- if (ALENGTH (avp->length) < sizeof (struct avp_hdr))
+ if (ALENGTH (avp->length) < (int) sizeof (struct avp_hdr)) /* mf, 04.0
5.2004: cast to (int), avoid compiler warning */
{
log (LOG_WARN, "%s: AVP with too small of size (%d).\n",
__FUNCTION__, ALENGTH (avp->length));
diff -aur l2tpd-0.69_old/avp.h l2tpd-0.69_new/avp.h
--- l2tpd-0.69_old/avp.h 2002-04-10 14:09:33.000000000 -0600
+++ l2tpd-0.69_new/avp.h 2005-09-26 01:10:01.000000000 -0600
@@ -116,7 +116,8 @@
extern int add_avp_rws (struct buffer *, _u16);
extern int add_tunnelid_avp (struct buffer *, _u16);
extern int add_vendor_avp (struct buffer *);
-extern int add_hostname_avp (struct buffer *);
+/* mferd, 30.01.2003: hostname as arg to add_hostname_avp */
+extern int add_hostname_avp (struct buffer *, char *);
extern int add_firmware_avp (struct buffer *);
extern int add_bearer_caps_avp (struct buffer *buf, _u16 caps);
extern int add_frame_caps_avp (struct buffer *buf, _u16 caps);
diff -aur l2tpd-0.69_old/avpsend.c l2tpd-0.69_new/avpsend.c
--- l2tpd-0.69_old/avpsend.c 2002-04-10 14:09:33.000000000 -0600
+++ l2tpd-0.69_new/avpsend.c 2005-09-26 01:10:01.000000000 -0600
@@ -98,15 +98,14 @@
}
*/
-int add_hostname_avp (struct buffer *buf)
+int add_hostname_avp (struct buffer *buf, char *hostname)
{
- char names[6] = "eriwan";
_u16 *raw = (_u16 *) (buf->start + buf->len);
- raw[0] = htons (0xC | MBIT);
+ raw[0] = htons ((0x6 + strlen(hostname)) | MBIT);
raw[1] = htons (VENDOR_ID);
raw[2] = htons (0x7);
- strcpy ((char *) (&raw[3]), names);
- buf->len += 12;
+ strcpy ((char *) (&raw[3]), hostname);
+ buf->len += 6 + strlen(hostname);
return 0;
}
diff -aur l2tpd-0.69_old/call.c l2tpd-0.69_new/call.c
--- l2tpd-0.69_old/call.c 2002-08-09 18:47:25.000000000 -0600
+++ l2tpd-0.69_new/call.c 2005-09-26 01:10:01.000000000 -0600
@@ -138,7 +138,9 @@
errors++;
log (LOG_DEBUG, "%s: Error %d (%s)\n", __FUNCTION__, errno,
strerror (errno));
- if (errors > 10)
+ /* mf, 08.06.2004: if pppd dies, read return EBADF (Bad File Descrip
tor)
+ in that case, don't bother repeating */
+ if (errors > 10 || errno == EBADF)
{
log (LOG_DEBUG,
"%s: Too many errors. Declaring call dead.\n",
@@ -193,8 +195,7 @@
}
}
/* I should never get here */
- log (LOG_WARN, "%s: You should not see this message. If you do, please
- enter a bug report at http://sourceforge.net/projects/l2t
pd", __FUNCTION__);
+ log (LOG_WARN, "%s: You should not see this message. If you do, please ent
er a bug report at http://sourceforge.net/projects/l2tpd", __FUNCTION__);
return -EINVAL;
}
@@ -313,11 +314,15 @@
call_close (tmp);
tmp = tmp2;
}
+ /* mf, 16.04.2003: change log message to show tunneltag */
+ //log (LOG_LOG,
+ // "%s : Connection %d closed to %s, port %d (%s)\n", __FUNCTION__,
+ // c->container->tid,
+ // IPADDY (c->container->peer.sin_addr),
+ // ntohs (c->container->peer.sin_port), c->errormsg);
log (LOG_LOG,
- "%s : Connection %d closed to %s, port %d (%s)\n", __FUNCTION__,
- c->container->tid,
- IPADDY (c->container->peer.sin_addr),
- ntohs (c->container->peer.sin_port), c->errormsg);
+ "%s : Connection closed with peer %s, reason: %s\n",
+ __FUNCTION__, c->container->tunneltag, c->errormsg);
}
else
{
@@ -524,6 +529,10 @@
tmp->ourcid = 0x6227;
#endif
}
+ else
+ { log(LOG_DEBUG, "%s: initializing ourcid to 0\n", __FUNCTION__);
+ tmp->ourcid=0;
+ }
tmp->dialed[0] = 0;
tmp->dialing[0] = 0;
tmp->subaddy[0] = 0;
@@ -536,6 +545,7 @@
/* tmp->rws = -1; */
tmp->fd = -1;
tmp->oldptyconf = malloc (sizeof (struct termios));
+ tmp->ptyname[0] = '\0'; /* mf, 08.04.2003: no name for pty yet */
tmp->pnu = 0;
tmp->cnu = 0;
tmp->needclose = 0;
diff -aur l2tpd-0.69_old/call.h l2tpd-0.69_new/call.h
--- l2tpd-0.69_old/call.h 2002-04-10 14:09:33.000000000 -0600
+++ l2tpd-0.69_new/call.h 2005-09-26 01:10:01.000000000 -0600
@@ -70,6 +70,7 @@
struct tunnel *container; /* Tunnel we belong to */
int fd; /* File descriptor for pty */
struct termios *oldptyconf;
+ char ptyname[6]; /* mf, 08.04.2003: string for ptyname */
int die;
int nego; /* Show negotiation? */
int pppd; /* PID of pppd */
@@ -82,12 +83,15 @@
int pnu; /* ditto for payload packet */
char errormsg[MAXSTRLEN]; /* Error message */
/* int rws; Receive window size, or -1 for none */
+/* mferd, 30.01.2003: rws missing? */ int rws;
struct timeval lastsent; /* When did we last send something? */
_u16 data_seq_num; /* Sequence for next payload packet */
_u16 data_rec_seq_num; /* Sequence for next received payload packet */
_u16 closeSs; /* What number was in Ns when we started to
close? */
int pLr; /* Last packet received by peer */
+/* mferd, 29.01.2003: pSr missing? */ _u16 pSr;
+/* mferd, 30.01.2003: pSr missing? */ _u16 pSs;
struct lns *lns; /* LNS that owns us */
struct lac *lac; /* LAC that owns us */
char dial_no[128]; /* jz: dialing number for outgoing call */
diff -aur l2tpd-0.69_old/control.c l2tpd-0.69_new/control.c
--- l2tpd-0.69_old/control.c 2002-04-10 14:09:33.000000000 -0600
+++ l2tpd-0.69_new/control.c 2005-09-26 01:10:01.000000000 -0600
@@ -62,6 +62,8 @@
int global_serno = 1;
+
+
struct buffer *new_outgoing (struct tunnel *t)
{
/*
@@ -161,6 +163,28 @@
udp_xmit (buf);
}
#ifdef USE_KERNEL
}
@@ -388,7 +400,11 @@
execv (PPPD, stropt);
log (LOG_WARN, "%s: Exec of %s failed!\n", __FUNCTION__, PPPD);
exit (1);
- };
+ }
+ /* mferd, 05.02.2003: race condition? ppp packets received are echoed until
pppd comes up;
+ workaround: lose some time and hope p
ppd comes up fast enough... */
+ else { /* sleep(1); */ struct timespec req, rem; req.tv_sec=0; req.tv_nsec
= 300000000L; nanosleep(&req,&rem); }
+
close (fd2);
pos = 0;
while (stropt[pos])
@@ -409,6 +425,7 @@
*/
struct call *c, *me;
+ struct call *c2; /* mf, 26.06.2004: needed for walk through list
while freeing it */
struct tunnel *p;
struct timeval tv;
if (!t)
@@ -429,8 +446,9 @@
c = t->call_head;
while (c)
{
+ c2 = c->next; /* mf, 26.06.2004: can't use c->next after freeing c */
destroy_call (c);
- c = c->next;
+ c = c2; /* mf, 26.06.2004: can't use c->next after freei
ng c */
};
/*
* Remove ourselves from the list of tunnels
@@ -483,6 +501,7 @@
*/
if (t->lns)
t->lns->t = NULL;
+ if (t->tunneltag) { free(t->tunneltag); } /* mf, 03.04.2003: also free tun
nel tag if allocated */
free (t);
free (me);
}
@@ -731,6 +750,9 @@
tmp->hostname[0] = 0;
tmp->vendor[0] = 0;
tmp->secret[0] = 0;
+ /* mf, 14.06.2004: valgrind suggested initializing parent->self */
+ tmp->self = (struct call *) NULL;
+
if (!(tmp->self = new_call (tmp)))
{
free (tmp);
@@ -749,6 +771,8 @@
tmp->chal_them.vector = (unsigned char *) malloc (VECTOR_SIZE);
tmp->chal_us.vector = NULL;
tmp->hbit = 0;
+ /* mf, 03.04.2003: tunneltag invalid until after connection is established
*/
+ tmp->tunneltag = NULL;
return tmp;
}
@@ -1002,29 +1026,43 @@
/* Read previous pid file. */
if ((i = open(gconfig.pidfile,O_RDONLY)) > 0) {
l=read(i,buf,sizeof(buf)-1);
- if (i < 0) {
+ /* mf, 27.03.2003: usage of "i" (filedescr) corrected to "l" (length) *
/
+ if (l < 0) {
log(LOG_LOG, "%s: Unable to read pid file [%s]\n",
__FUNCTION__, gconfig.pidfile);
}
- buf[i] = '\0';
+ buf[l] = '\0';
pid = atoi(buf);
/* If the previous server process is not still running,
write a new pid file immediately. */
- if (pid && (pid == getpid () || kill (pid, 0) < 0)) {
+ /* mf, 27.03.2003: also handle case pid=0 (e.g. empty pid file) */
+ if (pid==0 || (pid && (pid == getpid () || kill (pid, 0) < 0))) {
unlink (gconfig.pidfile);
if ((i = open (gconfig.pidfile, O_WRONLY | O_CREAT, 0640)) >= 0)
{
snprintf (buf, sizeof(buf), "%d\n", (int)getpid());
- write (i, buf, strlen(buf));
+ l=write (i, buf, strlen(buf));
+ if (l!=(int)strlen(buf)) /* mf, 04.05.2004: cast to (int)
, avoid compiler warning */
+ { log(LOG_LOG, "%s: error overwriting pid file with %s\n",
+ __FUNCTION__, buf);
+ }
+ else log(LOG_LOG, "overwrote pid file with %s\n", buf);
close (i);
pidfilewritten = 1;
+ log(LOG_LOG, "%s: wrote pid to file %s\n",
+ __FUNCTION__, gconfig.pidfile);
}
+ /* mf, 27.03.2003: cannot write pid file ?!? */
+ else
+ { log(LOG_LOG, "%s: cannot write to pid file %s\n",
+ __FUNCTION__, gconfig.pidfile);
+ }
}
else
{
- log(LOG_LOG, "%s: There's already a l2tpd server running.\n",
- __FUNCTION__);
+ log(LOG_LOG, "%s: There's already a l2tpd server running (pid=%d).\
n",
+ __FUNCTION__, (int) pid);
close(server_socket);
exit(1);
}
@@ -1035,12 +1073,21 @@
if(! pidfilewritten) {
unlink(gconfig.pidfile);
if ((i = open (gconfig.pidfile, O_WRONLY | O_CREAT, 0640)) >= 0) {
- snprintf (buf, strlen(buf), "%d\n", (int)getpid());
- write (i, buf, strlen(buf));
+ /* mf, 27.03.2003: correct strlen(buf) => sizeof(buf) */
+ snprintf (buf, sizeof(buf), "%d\n", (int)getpid());
+ log(LOG_LOG, "pid is %s\n", buf);
+ l=write (i, buf, strlen(buf));
+ if (l!=(int)strlen(buf)) /* mf, 04.05.2004: cast to (int), avoid
compiler warning */
+ { log(LOG_LOG, "%s: error writing pid file\n",
+ __FUNCTION__);
+ }
+ else log(LOG_LOG, "pid file with %s\n", buf);
close (i);
pidfilewritten = 1;
}
}
+ /* mf, 27.03.2003: log successful daemonization */
+ log(LOG_LOG, "daemonize successfully completed\n");
}
@@ -1081,7 +1128,7 @@
__FUNCTION__);
exit (1);
}
- log (LOG_LOG, "l2tpd version " SERVER_VERSION " started on %s PID:%d\n",
+ log (LOG_LOG, "l2tpd version " SERVER_VERSION SPECIAL_VERSION " started on
%s PID:%d\n",
hostname, getpid ());
log (LOG_LOG,
"Written by Mark Spencer, Copyright (C) 1998, Adtran, Inc.\n");
diff -aur l2tpd-0.69_old/l2tp.h l2tpd-0.69_new/l2tp.h
--- l2tpd-0.69_old/l2tp.h 2002-08-19 11:26:23.000000000 -0600
+++ l2tpd-0.69_new/l2tp.h 2005-09-26 01:10:01.000000000 -0600
@@ -37,6 +37,9 @@
#define BINARY "l2tpd"
#define SERVER_VERSION "0.69"
+#ifndef SPECIAL_VERSION
+# define SPECIAL_VERSION ""
+#endif
#define VENDOR_NAME "l2tpd.org"
#define PPPD "/usr/sbin/pppd"
#define CALL_PPP_OPTS "defaultroute"
@@ -88,7 +91,9 @@
#define PAYLOAD_BUF 10 /* Provide 10 expansion bytes
so we can "decompress" the
payloads and simplify coding */
-#define DEFAULT_MAX_RETRIES 5 /* Recommended value from spec */
+/* mf, 05.10.2003: increased DEFAULT_MAX_RETRIES to avoid breakdowns */
+/* #define DEFAULT_MAX_RETRIES 5 */ /* Recommended value from spec */
+#define DEFAULT_MAX_RETRIES 8
#define DEFAULT_RWS_SIZE 4 /* Default max outstanding
control packets in queue */
#define DEFAULT_TX_BPS 10000000 /* For outgoing calls, report th
is speed */
@@ -156,6 +161,8 @@
struct call *self;
struct lns *lns; /* LNS that owns us */
struct lac *lac; /* LAC that owns us */
+ char *tunneltag; /* mf, 03.04.2003: string representing tunnel: p
eer a.b.c.d:p, ltunnelid num, rtunnelid num;
+ valid only after completing
connection! */
};
struct tunnel_list
diff -aur l2tpd-0.69_old/Makefile l2tpd-0.69_new/Makefile
--- l2tpd-0.69_old/Makefile 2002-08-09 18:42:22.000000000 -0600
+++ l2tpd-0.69_new/Makefile 2005-09-26 01:10:01.000000000 -0600
@@ -27,7 +27,9 @@
# become runtime options) debugging flags
#
#DFLAGS= -g -O2 -DDEBUG_PPPD
-DFLAGS= -g -O2 -DDEBUG_PPPD -DDEBUG_CONTROL -DDEBUG_ENTROPY
+#DFLAGS= -g -O2 -DDEBUG_PPPD -DDEBUG_CONTROL -DDEBUG_ENTROPY
+#DFLAGS= -g -DDEBUG_PPPD -DDEBUG_CONTROL -DDEBUG_ENTROPY -DDEBUG_HELLO -DDEBUG_
CLOSE -DDEBUG_CLOSE -DDEBUG_FLOW -DDEBUG_FILE -DDEBUG_AAA -DDEBUG_HIDDEN -DDEBUG
_AUTH -DDEBUG_CONTROL_XMIT -DDEBUG_FLOW_MORE -DDEBUG_MAGIC -DDEBUG_PPPD -DDEBUG_
ZLB
+DFLAGS= -g -O2 -DDEBUG_PPPD -DDEBUG_CONTROL -DDEBUG_ENTROPY -DDEBUG_HELLO -DDEB
UG_CLOSE -DDEBUG_CLOSE -DDEBUG_FLOW -DDEBUG_FILE -DDEBUG_AAA -DDEBUG_HIDDEN -DDE
BUG_AUTH -DDEBUG_CONTROL_XMIT -DDEBUG_MAGIC -DDEBUG_PPPD -DDEBUG_ZLB -DSPECIAL_V
ERSION=$(SPECIAL_VERSION)
#
# Uncomment the next line for Linux
#
@@ -69,5 +71,7 @@
clean:
rm -f $(OBJS) $(BIN)
+$(OBJS): $(HDRS)
+
$(BIN): $(OBJS) $(HDRS)
$(CC) -o $(BIN) $(DFLAGS) $(OBJS) $(LIBS)
diff -aur l2tpd-0.69_old/misc.c l2tpd-0.69_new/misc.c
--- l2tpd-0.69_old/misc.c 2002-08-09 18:42:22.000000000 -0600
+++ l2tpd-0.69_new/misc.c 2005-09-26 01:10:01.000000000 -0600
@@ -32,16 +32,46 @@
void log (int level, const char *fmt, ...)
{
+ /* mf, 08.06.2004: do openlog only once */
+ static int log_opened=0;
+ /* mf, 12.06.2004: try to avoid re-entering syslog call */
+ static int homegrown_syslog_mutex=0;
+ static int homegrown_syslog_lostmsgcount=0;
+
char buf[256];
va_list args;
va_start (args, fmt);
vsnprintf (buf, sizeof (buf), fmt, args);
va_end (args); //bk - otherwise ppc segfaults
va_start (args, fmt); //bk
- vfprintf (stderr, fmt, args);
- fflush (stderr);
- openlog (BINARY, LOG_PID, LOG_DAEMON);
- syslog (level, "%s", buf);
+ /* mferd, 20.03.2003: avoid logging to stderr as daemon or log messages
+ will be fed into pppd
+ (increased error counters in interface stats)
+ */
+ if (!gconfig.daemon)
+ { vfprintf (stderr, fmt, args);
+ fflush (stderr);
+ }
+ /* mf, 08.06.2004: do openlog only once */
+ /* openlog (BINARY, LOG_PID, LOG_DAEMON); */
+ if (!log_opened)
+ { openlog (BINARY, LOG_PID, LOG_DAEMON);
+ log_opened++;
+ }
+ /* mf, 12.06.2004: try to avoid re-entering syslog call */
+ if (homegrown_syslog_mutex++)
+ { /* someone is currently calling syslog and has not exited yet. damn. */
+ /* FIXME: should buffer the message and send to syslog later */
+ homegrown_syslog_lostmsgcount++;
+ }
+ else
+ { if (homegrown_syslog_lostmsgcount)
+ { syslog(level, "ALERT: %d log messages lost\n", homegrown_syslog_los
tmsgcount);
+ homegrown_syslog_lostmsgcount=0;
+ }
+ syslog (level, "%s", buf);
+ }
+ homegrown_syslog_mutex--;
va_end (args);
}
@@ -76,7 +106,8 @@
return b;
}
-inline void recycle_buf (struct buffer *b)
+/* mf, 15.06.2004: de-inline function for easier debugging */
+/*inline*/ void recycle_buf (struct buffer *b)
{
b->start = b->rstart;
b->len = b->maxlen;
@@ -174,7 +205,8 @@