Make the server descriptor into a `sort' of struct descriptor.
This commit is contained in:
parent
42d4d39668
commit
77ff88ad4b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33195
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: command.c,v 1.131.2.11 1998/02/07 20:49:32 brian Exp $
|
||||
* $Id: command.c,v 1.131.2.12 1998/02/09 19:20:41 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
@ -66,7 +66,6 @@
|
||||
#include "systems.h"
|
||||
#include "chat.h"
|
||||
#include "bundle.h"
|
||||
#include "server.h"
|
||||
#include "main.h"
|
||||
#include "route.h"
|
||||
#include "ccp.h"
|
||||
@ -77,6 +76,7 @@
|
||||
#include "link.h"
|
||||
#include "descriptor.h"
|
||||
#include "physical.h"
|
||||
#include "server.h"
|
||||
|
||||
struct in_addr ifnetmask;
|
||||
static const char *HIDDEN = "********";
|
||||
@ -1054,10 +1054,9 @@ SetServer(struct cmdargs const *arg)
|
||||
|
||||
if (mask != NULL || passwd != NULL)
|
||||
return -1;
|
||||
oserver = server;
|
||||
ServerClose();
|
||||
if (oserver != -1)
|
||||
LogPrintf(LogPHASE, "Disabling server port.\n");
|
||||
|
||||
if (ServerClose())
|
||||
LogPrintf(LogPHASE, "Disabled server port.\n");
|
||||
res = 0;
|
||||
} else if (*port == '/') {
|
||||
mode_t imask;
|
||||
|
@ -23,10 +23,11 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: descriptor.h,v 1.1.2.1 1998/02/09 19:20:43 brian Exp $
|
||||
*/
|
||||
|
||||
#define PHYSICAL_DESCRIPTOR (1)
|
||||
#define SERVER_DESCRIPTOR (1)
|
||||
|
||||
struct descriptor {
|
||||
int type;
|
||||
|
@ -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.15 1998/02/08 19:29:45 brian Exp $
|
||||
* $Id: main.c,v 1.121.2.16 1998/02/09 19:21:01 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Add commands for traffic summary, version display, etc.
|
||||
@ -68,7 +68,6 @@
|
||||
#include "systems.h"
|
||||
#include "ip.h"
|
||||
#include "sig.h"
|
||||
#include "server.h"
|
||||
#include "main.h"
|
||||
#include "vjcomp.h"
|
||||
#include "async.h"
|
||||
@ -78,6 +77,7 @@
|
||||
#include "link.h"
|
||||
#include "descriptor.h"
|
||||
#include "physical.h"
|
||||
#include "server.h"
|
||||
|
||||
#ifndef O_NONBLOCK
|
||||
#ifdef O_NDELAY
|
||||
@ -724,20 +724,12 @@ StartRedialTimer(int Timeout)
|
||||
}
|
||||
}
|
||||
|
||||
#define IN_SIZE sizeof(struct sockaddr_in)
|
||||
#define UN_SIZE sizeof(struct sockaddr_in)
|
||||
#define ADDRSZ (IN_SIZE > UN_SIZE ? IN_SIZE : UN_SIZE)
|
||||
|
||||
static void
|
||||
DoLoop(struct bundle *bundle)
|
||||
{
|
||||
fd_set rfds, wfds, efds;
|
||||
int pri, i, n, wfd, nfds;
|
||||
char hisaddr[ADDRSZ];
|
||||
struct sockaddr *sa = (struct sockaddr *)hisaddr;
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)hisaddr;
|
||||
struct timeval timeout, *tp;
|
||||
int ssize = ADDRSZ;
|
||||
const u_char *cp;
|
||||
int tries;
|
||||
int qlen;
|
||||
@ -871,12 +863,7 @@ DoLoop(struct bundle *bundle)
|
||||
}
|
||||
|
||||
descriptor_UpdateSet(&bundle->physical->desc, &rfds, &wfds, &efds, &nfds);
|
||||
|
||||
if (server >= 0) {
|
||||
if (server + 1 > nfds)
|
||||
nfds = server + 1;
|
||||
FD_SET(server, &rfds);
|
||||
}
|
||||
descriptor_UpdateSet(&server.desc, &rfds, &wfds, &efds, &nfds);
|
||||
|
||||
#ifndef SIGALRM
|
||||
/*
|
||||
@ -888,8 +875,6 @@ DoLoop(struct bundle *bundle)
|
||||
*/
|
||||
usleep(TICKUNIT);
|
||||
TimerService();
|
||||
#else
|
||||
handle_signals();
|
||||
#endif
|
||||
|
||||
/* If there are aren't many packets queued, look for some more. */
|
||||
@ -898,12 +883,16 @@ DoLoop(struct bundle *bundle)
|
||||
nfds = bundle->tun_fd + 1;
|
||||
FD_SET(bundle->tun_fd, &rfds);
|
||||
}
|
||||
|
||||
if (netfd >= 0) {
|
||||
if (netfd + 1 > nfds)
|
||||
nfds = netfd + 1;
|
||||
FD_SET(netfd, &rfds);
|
||||
FD_SET(netfd, &efds);
|
||||
}
|
||||
|
||||
handle_signals();
|
||||
|
||||
#ifndef SIGALRM
|
||||
|
||||
/*
|
||||
@ -915,8 +904,8 @@ DoLoop(struct bundle *bundle)
|
||||
#else
|
||||
|
||||
/*
|
||||
* When SIGALRM timer is running, a select function will be return -1 and
|
||||
* EINTR after a Time Service signal hundler is done. If the redial
|
||||
* When SIGALRM timer is running, the select function will return -1 and
|
||||
* EINTR after the Time Service signal handler is done. If the redial
|
||||
* timer is not running and we are trying to dial, poll with a 0 value
|
||||
* timer.
|
||||
*/
|
||||
@ -927,6 +916,7 @@ DoLoop(struct bundle *bundle)
|
||||
if (i == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
if (errno == EINTR) {
|
||||
handle_signals();
|
||||
@ -935,48 +925,15 @@ DoLoop(struct bundle *bundle)
|
||||
LogPrintf(LogERROR, "DoLoop: select(): %s\n", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if ((netfd >= 0 && FD_ISSET(netfd, &efds)) ||
|
||||
descriptor_IsSet(&bundle->physical->desc, &efds)) {
|
||||
LogPrintf(LogALERT, "Exception detected.\n");
|
||||
break;
|
||||
}
|
||||
if (server >= 0 && FD_ISSET(server, &rfds)) {
|
||||
wfd = accept(server, sa, &ssize);
|
||||
if (wfd < 0) {
|
||||
LogPrintf(LogERROR, "DoLoop: accept(): %s\n", strerror(errno));
|
||||
continue;
|
||||
}
|
||||
switch (sa->sa_family) {
|
||||
case AF_LOCAL:
|
||||
LogPrintf(LogPHASE, "Connected to local client.\n");
|
||||
break;
|
||||
case AF_INET:
|
||||
if (ntohs(sin->sin_port) < 1024) {
|
||||
LogPrintf(LogALERT, "Rejected client connection from %s:%u"
|
||||
"(invalid port number) !\n",
|
||||
inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
|
||||
close(wfd);
|
||||
continue;
|
||||
}
|
||||
LogPrintf(LogPHASE, "Connected to client from %s:%u\n",
|
||||
inet_ntoa(sin->sin_addr), sin->sin_port);
|
||||
break;
|
||||
default:
|
||||
write(wfd, "Unrecognised access !\n", 22);
|
||||
close(wfd);
|
||||
continue;
|
||||
}
|
||||
if (netfd >= 0) {
|
||||
write(wfd, "Connection already in use.\n", 27);
|
||||
close(wfd);
|
||||
continue;
|
||||
}
|
||||
netfd = wfd;
|
||||
VarTerm = fdopen(netfd, "a+");
|
||||
LocalAuthInit();
|
||||
IsInteractive(1);
|
||||
Prompt(bundle);
|
||||
}
|
||||
|
||||
if (descriptor_IsSet(&server.desc, &rfds))
|
||||
descriptor_Read(&server.desc, bundle);
|
||||
|
||||
if (netfd >= 0 && FD_ISSET(netfd, &rfds))
|
||||
/* something to read from tty */
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: mbuf.c,v 1.13.2.1 1998/01/30 19:45:54 brian Exp $
|
||||
* $Id: mbuf.c,v 1.13.2.2 1998/02/06 02:23:40 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
@ -33,12 +33,11 @@
|
||||
#include "defs.h"
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
#include "server.h"
|
||||
|
||||
static struct memmap {
|
||||
struct mbuf *queue;
|
||||
int count;
|
||||
} MemMap[MB_MAX + 2];
|
||||
} MemMap[MB_MAX + 2];
|
||||
|
||||
static int totalalloced;
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: server.c,v 1.16 1998/01/21 02:15:27 brian Exp $
|
||||
* $Id: server.c,v 1.16.2.1 1998/02/02 19:32:15 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -45,10 +45,108 @@
|
||||
#include "loadalias.h"
|
||||
#include "defs.h"
|
||||
#include "vars.h"
|
||||
#include "descriptor.h"
|
||||
#include "server.h"
|
||||
#include "id.h"
|
||||
|
||||
int server = -1;
|
||||
static int
|
||||
server_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
|
||||
{
|
||||
struct server *s = descriptor2server(d);
|
||||
|
||||
LogPrintf(LogDEBUG, "descriptor2server; %p -> %p\n", d, s);
|
||||
if (s->fd >= 0) {
|
||||
FD_SET(s->fd, r);
|
||||
if (*n < s->fd + 1)
|
||||
*n = s->fd + 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
server_IsSet(struct descriptor *d, fd_set *fdset)
|
||||
{
|
||||
struct server *s = descriptor2server(d);
|
||||
|
||||
LogPrintf(LogDEBUG, "descriptor2server; %p -> %p\n", d, s);
|
||||
return s->fd >= 0 && FD_ISSET(s->fd, fdset);
|
||||
}
|
||||
|
||||
#define IN_SIZE sizeof(struct sockaddr_in)
|
||||
#define UN_SIZE sizeof(struct sockaddr_in)
|
||||
#define ADDRSZ (IN_SIZE > UN_SIZE ? IN_SIZE : UN_SIZE)
|
||||
|
||||
static void
|
||||
server_Read(struct descriptor *d, struct bundle *bundle)
|
||||
{
|
||||
struct server *s = descriptor2server(d);
|
||||
char hisaddr[ADDRSZ];
|
||||
struct sockaddr *sa = (struct sockaddr *)hisaddr;
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)hisaddr;
|
||||
int ssize = ADDRSZ, wfd;
|
||||
|
||||
LogPrintf(LogDEBUG, "descriptor2server; %p -> %p\n", d, s);
|
||||
|
||||
wfd = accept(s->fd, sa, &ssize);
|
||||
if (wfd < 0) {
|
||||
LogPrintf(LogERROR, "server_Read: accept(): %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_LOCAL:
|
||||
LogPrintf(LogPHASE, "Connected to local client.\n");
|
||||
break;
|
||||
|
||||
case AF_INET:
|
||||
if (ntohs(sin->sin_port) < 1024) {
|
||||
LogPrintf(LogALERT, "Rejected client connection from %s:%u"
|
||||
"(invalid port number) !\n",
|
||||
inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
|
||||
close(wfd);
|
||||
return;
|
||||
}
|
||||
LogPrintf(LogPHASE, "Connected to client from %s:%u\n",
|
||||
inet_ntoa(sin->sin_addr), sin->sin_port);
|
||||
break;
|
||||
|
||||
default:
|
||||
write(wfd, "Unrecognised access !\n", 22);
|
||||
close(wfd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (netfd >= 0) {
|
||||
write(wfd, "Connection already in use.\n", 27);
|
||||
close(wfd);
|
||||
} else {
|
||||
netfd = wfd;
|
||||
VarTerm = fdopen(netfd, "a+");
|
||||
LocalAuthInit();
|
||||
IsInteractive(1);
|
||||
Prompt(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
server_Write(struct descriptor *d)
|
||||
{
|
||||
/* We never want to write here ! */
|
||||
LogPrintf(LogERROR, "server_Write: Internal error: Bad call !\n");
|
||||
}
|
||||
|
||||
struct server server = {
|
||||
{
|
||||
SERVER_DESCRIPTOR,
|
||||
NULL,
|
||||
server_UpdateSet,
|
||||
server_IsSet,
|
||||
server_Read,
|
||||
server_Write
|
||||
},
|
||||
-1
|
||||
};
|
||||
|
||||
static struct sockaddr_un ifsun;
|
||||
static char *rm;
|
||||
@ -104,7 +202,7 @@ ServerLocalOpen(const char *name, mode_t mask)
|
||||
return 5;
|
||||
}
|
||||
ServerClose();
|
||||
server = s;
|
||||
server.fd = s;
|
||||
rm = ifsun.sun_path;
|
||||
LogPrintf(LogPHASE, "Listening at local socket %s.\n", name);
|
||||
return 0;
|
||||
@ -150,20 +248,22 @@ ServerTcpOpen(int port)
|
||||
return 9;
|
||||
}
|
||||
ServerClose();
|
||||
server = s;
|
||||
server.fd = s;
|
||||
LogPrintf(LogPHASE, "Listening at port %d.\n", port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
ServerClose()
|
||||
{
|
||||
if (server >= 0) {
|
||||
close(server);
|
||||
if (server.fd >= 0) {
|
||||
close(server.fd);
|
||||
if (rm) {
|
||||
ID0unlink(rm);
|
||||
rm = 0;
|
||||
}
|
||||
server.fd = -1;
|
||||
return 1;
|
||||
}
|
||||
server = -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,11 +23,20 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: server.h,v 1.4 1997/12/21 12:11:08 brian Exp $
|
||||
*/
|
||||
|
||||
extern int server;
|
||||
struct server {
|
||||
struct descriptor desc;
|
||||
int fd;
|
||||
};
|
||||
|
||||
#define server2descriptor(s) (&(s)->desc)
|
||||
#define descriptor2server(d) \
|
||||
((d)->type == SERVER_DESCRIPTOR ? (struct server *)(d) : NULL)
|
||||
|
||||
extern struct server server;
|
||||
|
||||
extern int ServerLocalOpen(const char *, mode_t);
|
||||
extern int ServerTcpOpen(int);
|
||||
extern void ServerClose(void);
|
||||
extern int ServerClose(void);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: systems.c,v 1.35.2.1 1998/02/02 19:32:15 brian Exp $
|
||||
* $Id: systems.c,v 1.35.2.2 1998/02/04 01:03:36 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -41,6 +41,7 @@
|
||||
#include "loadalias.h"
|
||||
#include "pathnames.h"
|
||||
#include "vars.h"
|
||||
#include "descriptor.h"
|
||||
#include "server.h"
|
||||
#include "systems.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user