Hi All,

 one month ago I posted a patch for diald 0.16 to [EMAIL PROTECTED],
but I don't know if it's the right way to suggest pathes, so I'll re-post
my message to the newsgroup. Of course, suggestions and objections are
welcome. Flames don't.


        Regards,

                Giuseppe Guerrini <[EMAIL PROTECTED]>


 Here the original message:


 Dear Sir, 

 I'm happyly using diald to give on-demand Internet access to hosts in my
company's intranet, and added a feature I needed to manage correctly my
very particular network environment.
 I'm using only "keepup" and "ignore" rules, because I need full control
on dialup phase: my users have to register themselves on the server in
order to gain access to the Internet (via SOCKS). A set of HTML pages and
CGI scripts controls the registration, logging and dial phases (my boss
wants to know who has used Internet, why, and how much he/she has spent in
phone calls). So, diald receives "up" and "down"  commands via FIFO from
these scripts.  Diald disconnects the line five minutes after the last IP
packet has been sent or received, so the users can freely forget bringing
the link down (as they are used to do :) ). But in Italy the phone is
expensive... So I've given the users a way to force the link down (if they
remember it...).  Another CGI script sends to diald the "down" command. 
But this can diconnect the line while some other person is still using it.
Of course, I could mantain a request counter in a file and handle it in my
scripts, but it's difficult to do it reliably in a script (there are
concurrence issues, locking problems...). I think diald should do this
work. So I've added to diald an "up request" counter and new FIFO command
that decrements the counter and bring the line down only if the counter
reaches 0. When diald goes to the "DOWN" state (due to command or "idle
timeout"), the counter is cleared. The command name is "conddown" (and I
hope someone has a better name to suggest to me). The file attached here
contains the diffs (I worked on diald 0.16 with patch 0.16.5). I've had to
modify only diald.c, diald.h and fsm.c. If you think my idea is good and
useful, you could add this feature in a future release. Maybe the counter
should be manipulated somewhere else, but I don't know your sources
enough to modify them more deeply.

 I hope my suggestion will be useful (and my english tolerable).

 Congratulations for your very good program !

     Regards,

                Giuseppe Guerrini ([EMAIL PROTECTED])


diff -u -N -r diald-0.16.old/diald.c diald-0.16/diald.c
--- diald-0.16.old/diald.c      Thu Mar 12 00:15:27 1998
+++ diald-0.16/diald.c  Wed Mar 11 23:37:14 1998
@@ -54,6 +54,11 @@
 static PIPE fifo_pipe;
 int argc_save;
 char **argv_save;
+/* GG Wed Mar 11 23:20:26 CET 1998
+ This is the line-up request count. Each "up" command from FIFO
+increments it, each "conddown" decrements it. When diald goes into the "DOWN"
+state, this variable is set to 0. */
+int link_up_requests = 0;
 
 void do_config(void)
 {
@@ -347,12 +352,16 @@
     die(1);
 }
 
+/* GG Wed Mar 11 23:20:26 CET 1998
+ Added the "conddown" command and modified "up". */
 /* Read a request off the fifo.
  * Valid requests are:
  *     block           - block diald from calling out.
  *     unblock         - unblock diald from calling out.
  *     down            - bring the link down.
- *     up              - bring the link up.
+ *     up              - bring the link up and increase the "link up" counter.
+ *      conddown        - decrease the "link up" counter and bring the link
+ *                        down if the counter is 0.
  *     delayed-quit    - quit next time diald is idle.
  *     quit            - stop diald in its tracks.
  *     queue           - dump the filter queue.
@@ -404,8 +413,22 @@
                syslog(LOG_INFO, "FIFO: Link down request received.");
                request_down = 1;
                request_up = 0;
+/* GG Wed Mar 11 23:20:26 CET 1998
+  "conddown" command : decrement the "link up" counter and bring link
+  down if 0. */
+           } else if (strcmp(buf,"conddown") == 0) {
+               syslog(LOG_INFO, "FIFO: Conditional down request received.");
+               request_down = 0;
+               if (link_up_requests > 0) {
+                       if (--link_up_requests == 0)
+                               request_down = 1;
+               }
+               request_up = 0;
            } else if (strcmp(buf,"up") == 0) {
                syslog(LOG_INFO, "FIFO: Link up request received.");
+/* GG Wed Mar 11 23:20:26 CET 1998
+  Each "link up" request increments the "link up" counter. */
+               ++link_up_requests;
                request_down = 0;
                request_up = 1;
            } else if (strcmp(buf,"delayed-quit") == 0) {
diff -u -N -r diald-0.16.old/diald.h diald-0.16/diald.h
--- diald-0.16.old/diald.h      Thu Mar 12 00:15:27 1998
+++ diald-0.16/diald.h  Wed Mar 11 23:25:37 1998
@@ -315,6 +315,12 @@
 int redial_rtimeout;           /* current real redial timeout */
 int dial_failures;             /* number of dial failures since last success */
 int ppp_half_dead;             /* is the ppp link half dead? */
+/* GG Wed Mar 11 23:20:26 CET 1998
+ This is the line-up request count. Each "up" command from FIFO
+increments it, each "conddown" decrements it. When diald goes into the "DOWN"
+state, this variable is set to 0. */
+int link_up_requests;
+
 
 /* function prototypes */
 void init_vars(void);
diff -u -N -r diald-0.16.old/fsm.c diald-0.16/fsm.c
--- diald-0.16.old/fsm.c        Thu Mar 12 00:15:28 1998
+++ diald-0.16/fsm.c    Wed Mar 11 23:42:42 1998
@@ -295,6 +295,11 @@
     if (!forced && queue_empty() && state_timeout == -1) {
        syslog(LOG_INFO,"Closing down idle link.");
 take_link_down:
+/* GG Wed Mar 11 23:20:26 CET 1998
+  I think it's time to reset the link up request counter: diald won't
+ try to keep the line up anymore, so all pending "up" request are
+ "out of date". */
+       link_up_requests = 0;
        current_retry_count = 0;
        flush_timeout_queue();
        /* WARNING: You MUST do this before calling idle_filter_proxy(),

Reply via email to