]> git.saurik.com Git - apple/network_cmds.git/blobdiff - racoon.tproj/session.c
network_cmds-245.8.tar.gz
[apple/network_cmds.git] / racoon.tproj / session.c
index 1c21779cd586b6e4e74e5bb7fd099ff8ab47cd7e..bdd29755dadd6958261f1f1c8e5217269baca12d 100644 (file)
@@ -57,6 +57,7 @@
 #include <unistd.h>
 #endif
 #include <signal.h>
+#include <sys/stat.h>
 
 #include "libpfkey.h"
 
@@ -121,8 +122,7 @@ session(void)
 
        sigreq = 0;
        while (1) {
-               rfds = mask0;
-
+       
                /*
                 * asynchronous requests via signal.
                 * make sure to reset sigreq to 0.
@@ -131,7 +131,7 @@ session(void)
 
                /* scheduling */
                timeout = schedular();
-
+               rfds = mask0;
                error = select(nfds, &rfds, (fd_set *)0, (fd_set *)0, timeout);
                if (error < 0) {
                        switch (errno) {
@@ -145,7 +145,6 @@ session(void)
                        }
                        /*NOTREACHED*/
                }
-
 #ifdef ENABLE_ADMINPORT
                if (FD_ISSET(lcconf->sock_admin, &rfds))
                        admin_handler();
@@ -154,22 +153,38 @@ session(void)
                for (p = lcconf->myaddrs; p; p = p->next) {
                        if (!p->addr)
                                continue;
+                       
                        if (FD_ISSET(p->sock, &rfds))
-                               isakmp_handler(p->sock);
+                               if ((error = isakmp_handler(p->sock)) == -2)
+                                       break;
+                                       
+                                       
 #ifdef IKE_NAT_T
                        if (p->nattsock >= 0 && FD_ISSET(p->nattsock, &rfds))
-                               isakmp_natt_handler(p->nattsock);
+                               if ((error = isakmp_natt_handler(p->nattsock)) == -2)
+                                       break;
 #endif
                }
+               if (error == -2) {
+                       if (lcconf->autograbaddr) {
+                               /* serious socket problem - close all listening sockets and re-open */
+                               isakmp_close(); 
+                               initfds();
+                               sched_new(5, check_rtsock, NULL);
+                               continue;
+                       } else {
+                               isakmp_close_sockets();
+                               isakmp_open();
+                       }
+                               
+               }
 
                if (FD_ISSET(lcconf->sock_pfkey, &rfds))
                        pfkey_handler();
 
-               if (lcconf->rtsock >= 0 && FD_ISSET(lcconf->rtsock, &rfds)) {
+               if (lcconf->rtsock >= 0 && FD_ISSET(lcconf->rtsock, &rfds))
                        if (update_myaddrs() && lcconf->autograbaddr)
                                sched_new(5, check_rtsock, NULL);
-                       initfds();
-               }
        }
 }
 
@@ -185,14 +200,15 @@ close_session()
        exit(0);
 }
 
+
 static void
 check_rtsock(p)
        void *p;
-{
-       isakmp_close();
+{      
        grab_myaddrs();
+       isakmp_close_unused();
        autoconf_myaddrsport();
-       isakmp_open();
+       isakmp_open();  
 
        /* initialize socket list again */
        initfds();