From 4462d9febb1aa11dde43bf1a2e16275b6dae978c Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 23 Mar 2002 13:12:29 +0000 Subject: [PATCH] Added TCP/IP trafic limits --- ChangeLog | 8 ++++++++ lib/clcomm.c | 7 +++++++ lib/clcomm.h | 1 + mbcico/call.c | 8 ++++++-- mbcico/mbcico.c | 1 + mbtask/mbtask.c | 3 ++- mbtask/taskcomm.c | 14 ++++++++++++++ mbtask/taskregs.c | 38 ++++++++++++++++++++++++++++++++++---- mbtask/taskregs.h | 3 +++ 9 files changed, 76 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 914a9b00..b63d35b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4604,6 +4604,9 @@ v0.33.20 10-Feb-2002 Added support for ext3 filesystem in diskspace check. Fixed lharc archives return code to LHA. + clcomm.a + Added counter for mailer TCP/IP sessions. + mbsetup: In message groups added default settings for auto area creation. @@ -4691,6 +4694,10 @@ v0.33.20 10-Feb-2002 mbcico gets the tty to use as option on the commandline. Keeps track of the number of mailers running. Added default path for arealists. + Keeps track of total mailer TCP/IP sessions and will not start + new sessions if the limit from the setup is reached. This will + hopefully prevent that mbcico will use too much bandwidth on + TCP/IP trafic. mbcico: Fixed binkp driver to accept incoming unprotected sessions. @@ -4702,6 +4709,7 @@ v0.33.20 10-Feb-2002 Disabled creation of .spl files dusing mail sessions for test. Added experimental support for binkp GET command frame, under test now. + Registers TCP/IP sessions with mbtask. mbout: The status display has now 9 digits for the outbound size. diff --git a/lib/clcomm.c b/lib/clcomm.c index e5b9f9f3..b0b66c2e 100644 --- a/lib/clcomm.c +++ b/lib/clcomm.c @@ -336,6 +336,13 @@ void IsDoing(const char *format, ...) +void RegTCP(void) +{ + SockS("ATCP:1,%d;", mypid); +} + + + void SetTTY(char *tty) { SockS("ATTY:2,%d,%s;", mypid, tty); diff --git a/lib/clcomm.h b/lib/clcomm.h index abeb62ca..023462fc 100644 --- a/lib/clcomm.h +++ b/lib/clcomm.h @@ -65,6 +65,7 @@ char *SockR(const char *, ...); void WriteError(const char *, ...); void Syslog(int, const char *, ...); void Syslogp(int, char *); +void RegTCP(void); void IsDoing(const char *, ...); void SetTTY(char *); void UserCity(pid_t, char *, char *); diff --git a/mbcico/call.c b/mbcico/call.c index f08d6d75..a5d55226 100644 --- a/mbcico/call.c +++ b/mbcico/call.c @@ -185,6 +185,7 @@ int call(faddr *addr) * If we have an internet address, set protocol */ if (inetaddr) { + RegTCP(); Syslog('d', "TCP/IP node \"%s\"", MBSE_SS(inetaddr)); if (tcp_mode == TCPMODE_NONE) { @@ -207,8 +208,11 @@ int call(faddr *addr) Syslog('d', "TCP mode set to %d", tcp_mode); } } else { - Syslog('d', "No IP address, fallback to dial"); - tcp_mode = TCPMODE_NONE; + WriteError("No IP address, abort call"); + rc = ST_NOCALL8; + putstatus(addr, 10, rc); + nodeulock(addr); + return rc; } } diff --git a/mbcico/mbcico.c b/mbcico/mbcico.c index 675c040c..f3c4cd98 100644 --- a/mbcico/mbcico.c +++ b/mbcico/mbcico.c @@ -256,6 +256,7 @@ int main(int argc, char *argv[]) die(101); } free(p); + RegTCP(); break; case 'a': inetaddr = optarg; diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index a11a827e..4c02b359 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -101,6 +101,7 @@ extern int isdn_lines; /* ISDN lines available */ extern int pots_free; /* POTS lines free */ extern int isdn_free; /* ISDN lines free */ extern pp_list *pl; /* List of tty ports */ +extern int ipmailers; /* TCP/IP mail sessions */ @@ -1157,7 +1158,7 @@ void scheduler(void) */ if (calllist[call_entry].addr.zone && !calllist[call_entry].calling && (calllist[call_entry].cst.trytime < now)) { - if ((calllist[call_entry].callmode == CM_INET) && (runtasktype(CM_INET) < TCFG.max_tcp) && internet) { + if ((calllist[call_entry].callmode == CM_INET) && (ipmailers < TCFG.max_tcp) && internet) { found = TRUE; break; } diff --git a/mbtask/taskcomm.c b/mbtask/taskcomm.c index 2cda0bf2..d1f5203b 100644 --- a/mbtask/taskcomm.c +++ b/mbtask/taskcomm.c @@ -143,6 +143,20 @@ char *exe_cmd(char *in) } } + /* + * ATCP:1,pid; + * 100:0; + * 200:1,Syntax Error; + */ + if (strncmp(cmd, "ATCP", 4) == 0) { + if (reg_ip(token) == 0) + return obuf; + else { + stat_inc_serr(); + return ebuf; + } + } + /* * ATTY:2,pid,tty; * 100:0; diff --git a/mbtask/taskregs.c b/mbtask/taskregs.c index 8af6e81a..77c539ee 100644 --- a/mbtask/taskregs.c +++ b/mbtask/taskregs.c @@ -37,6 +37,7 @@ extern reg_info reginfo[MAXCLIENT]; /* Array with clients */ static int entrypos = 0; /* Status pointer */ static int mailers = 0; /* Registered mailers */ +int ipmailers = 0; /* TCP/IP mail sessions */ /*********************************************************************** @@ -104,7 +105,8 @@ int reg_newcon(char *data) stat_inc_clients(); if (strcmp(prg, (char *)"mbcico") == 0) mailers++; - tasklog('-', "Registered client pgm \"%s\", pid %s, slot %d, mailers %d", prg, pid, retval, mailers); + tasklog('-', "Registered client pgm \"%s\", pid %s, slot %d, mailers %d, TCP/IP %d", + prg, pid, retval, mailers, ipmailers); return retval; } @@ -122,7 +124,10 @@ int reg_closecon(char *data) if (strcmp(reginfo[rec].prg, (char *)"mbcico") == 0) mailers--; - tasklog('-', "Unregistered client pgm \"%s\", pid %s, slot %d, mailers %d", reginfo[rec].prg, pid, rec, mailers); + if (reginfo[rec].istcp) + ipmailers--; + tasklog('-', "Unregistered client pgm \"%s\", pid %s, slot %d, mailers %d, TCP/IP %d", + reginfo[rec].prg, pid, rec, mailers, ipmailers); memset(®info[rec], 0, sizeof(reg_info)); stat_dec_clients(); return 0; @@ -145,8 +150,10 @@ void reg_check(void) if (errno == ESRCH) { if (strcmp(reginfo[i].prg, (char *)"mbcico") == 0) mailers--; - tasklog('?', "Stale registration found for pid %d (%s), mailers now %d", - reginfo[i].pid, reginfo[i].prg, mailers); + if (reginfo[i].istcp) + ipmailers--; + tasklog('?', "Stale registration found for pid %d (%s), mailers now %d, TCP/IP now %d", + reginfo[i].pid, reginfo[i].prg, mailers, ipmailers); memset(®info[i], 0, sizeof(reg_info)); stat_dec_clients(); } @@ -197,6 +204,29 @@ int reg_doing(char *data) +/* + * Registrate connection as TCP/IP connection + */ +int reg_ip(char *data) +{ + char *cnt, *pid; + int rec; + + cnt = strtok(data, ","); + pid = strtok(NULL, ";"); + + if ((rec = reg_find(pid)) == -1) + return -1; + + reginfo[rec].istcp = TRUE; + reginfo[rec].lastcon = time(NULL); + ipmailers++; + tasklog('?', "TCP/IP session registered, now %d sessions", ipmailers); + return 0; +} + + + /* * Update timer using NOP */ diff --git a/mbtask/taskregs.h b/mbtask/taskregs.h index b70c1f6d..1f2eb232 100644 --- a/mbtask/taskregs.h +++ b/mbtask/taskregs.h @@ -22,6 +22,7 @@ typedef struct _reg_info { unsigned silent : 1; /* Do not disturb */ unsigned chatting : 1; /* User is chatting */ unsigned ismsg : 1; /* Message waiting */ + unsigned istcp : 1; /* Is a TCP/IP session */ int channel; /* Chat channel */ int ptr_in; /* Input buffer pointer */ int ptr_out; /* Output buffer ptr */ @@ -30,11 +31,13 @@ typedef struct _reg_info { } reg_info; + void reg_init(void); int reg_newcon(char *); int reg_closecon(char *); void reg_check(void); int reg_doing(char *); +int reg_ip(char *); int reg_nop(char *); int reg_timer(int, char *); int reg_tty(char *);