o Make sure we don't dereference NULL when we've lost all our links.

o Use srandomdev() for __FreeBSD__ >= 2, not just >2.
o Use srandom((time(NULL)^getpid())+random()), random() when we
  haven't got srandomdev().
This commit is contained in:
Brian Somers 1998-05-06 18:50:12 +00:00
parent 078c562e54
commit 1bc9b5ba84
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=35791
5 changed files with 36 additions and 19 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.72 1998/05/05 23:29:55 brian Exp $
* $Id: bundle.c,v 1.1.2.73 1998/05/06 18:49:36 brian Exp $
*/
#include <sys/types.h>
@ -347,6 +347,15 @@ bundle_Close(struct bundle *bundle, const char *name, int staydown)
datalink_Close(this_dl, staydown);
}
void
bundle_Down(struct bundle *bundle)
{
struct datalink *dl;
for (dl = bundle->links; dl; dl = dl->next)
datalink_Down(dl, 1);
}
static int
bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
{
@ -363,7 +372,7 @@ bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
result += descriptor_UpdateSet(desc, r, w, e, n);
/* If there are aren't many packets queued, look for some more. */
if (bundle_FillQueues(bundle) < 20) {
if (bundle->links && bundle_FillQueues(bundle) < 20) {
if (*n < bundle->tun_fd + 1)
*n = bundle->tun_fd + 1;
FD_SET(bundle->tun_fd, r);
@ -904,12 +913,19 @@ bundle_FillQueues(struct bundle *bundle)
{
int total;
if (bundle->ncp.mp.active) {
if (bundle->ncp.mp.active)
total = mp_FillQueues(bundle);
} else {
total = link_QueueLen(&bundle->links->physical->link);
if (total == 0 && bundle->links->physical->out == NULL)
total = ip_FlushPacket(&bundle->links->physical->link, bundle);
else {
struct datalink *dl;
int add;
for (total = 0, dl = bundle->links; dl; dl = dl->next)
if (dl->state == DATALINK_OPEN) {
add = link_QueueLen(&dl->physical->link);
if (add == 0 && dl->physical->out == NULL)
add = ip_FlushPacket(&dl->physical->link, bundle);
total += add;
}
}
return total + ip_QueueLen();

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.35 1998/05/02 21:57:44 brian Exp $
* $Id: bundle.h,v 1.1.2.36 1998/05/05 23:29:57 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -113,6 +113,7 @@ extern int bundle_LinkIsUp(const struct bundle *);
extern int bundle_SetRoute(struct bundle *, int, struct in_addr,
struct in_addr, struct in_addr, int);
extern void bundle_Close(struct bundle *, const char *, int);
extern void bundle_Down(struct bundle *);
extern void bundle_Open(struct bundle *, const char *, int);
extern void bundle_LinkClosed(struct bundle *, struct datalink *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: defs.c,v 1.11.4.9 1998/04/23 03:22:50 brian Exp $
* $Id: defs.c,v 1.11.4.10 1998/04/30 23:53:35 brian Exp $
*/
@ -37,7 +37,7 @@
void
randinit()
{
#if __FreeBSD__ > 2
#if __FreeBSD__ >= 2
static int initdone;
if (!initdone) {
@ -45,7 +45,7 @@ randinit()
srandomdev();
}
#else
srandom(time(NULL)^getpid());
srandom((time(NULL)^getpid())+random());
#endif
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.54 1998/05/01 19:25:16 brian Exp $
* $Id: main.c,v 1.121.2.55 1998/05/06 18:49:42 brian Exp $
*
* TODO:
*/
@ -110,12 +110,9 @@ static void
CloseConnection(int signo)
{
/* NOTE, these are manual, we've done a setsid() */
struct datalink *dl;
sig_signal(SIGINT, SIG_IGN);
log_Printf(LogPHASE, "Caught signal %d, abort connection(s)\n", signo);
for (dl = SignalBundle->links; dl; dl = dl->next)
datalink_Down(dl, 1);
bundle_Down(SignalBundle);
sig_signal(SIGINT, CloseConnection);
}
@ -493,7 +490,7 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
sig_Handle();
/* This one comes first 'cos it may nuke a datalink */
/* This may nuke a datalink */
descriptor_UpdateSet(&bundle->ncp.mp.server.desc, &rfds, &wfds,
&efds, &nfds);
descriptor_UpdateSet(&bundle->desc, &rfds, &wfds, &efds, &nfds);
@ -529,6 +526,7 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
if (descriptor_IsSet(&bundle->desc, &wfds))
descriptor_Write(&bundle->desc, bundle, &wfds);
/* This may add a datalink */
if (descriptor_IsSet(&bundle->desc, &rfds))
descriptor_Read(&bundle->desc, bundle, &rfds);
} while (bundle_CleanDatalinks(bundle), !bundle_IsDead(bundle));

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp.c,v 1.1.2.22 1998/05/04 03:00:08 brian Exp $
* $Id: mp.c,v 1.1.2.23 1998/05/04 21:42:41 brian Exp $
*/
#include <sys/types.h>
@ -542,6 +542,8 @@ mp_FillQueues(struct bundle *bundle)
if (!fdl) {
fdl = bundle->links;
if (!fdl)
return 0;
thislink = 0;
}
@ -859,7 +861,7 @@ mpserver_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
return;
}
if (in.sa_family == AF_LOCAL) /* ??? */
if (in.sa_family == AF_LOCAL)
bundle_ReceiveDatalink(bundle, fd, (struct sockaddr_un *)&in);
close(fd);