diff -u squid-2.5.STABLE2/src/cache_manager.c squid-2.5.STABLE2/src/cache_manager.c
--- squid-2.5.STABLE2/src/cache_manager.c	2001-02-23 23:59:50.000000000 +0300
+++ squid-2.5.STABLE2/src/cache_manager.c	2004-04-04 11:38:12.000000000 +0400
@@ -286,11 +286,21 @@
 static void
 cachemgrOfflineToggle(StoreEntry * sentry)
 {
-    Config.onoff.offline = !Config.onoff.offline;
+    switch(Config.offline)
+    {
+	    case 0:
+		    Config.offline=2;
+		    break;
+	case 1:
+		   break;
+	case 2:
+		   Config.offline=0;
+		   break;
+    }
     debug(16, 0) ("offline_mode now %s.\n",
-	Config.onoff.offline ? "ON" : "OFF");
+	Config.offline ? (Config.offline==1?"MAYBE":"ON") : "OFF");
     storeAppendPrintf(sentry, "offline_mode is now %s\n",
-	Config.onoff.offline ? "ON" : "OFF");
+	Config.offline ? (Config.offline==1?"MAYBE":"ON") : "OFF");
 }
 
 static const char *
diff -u squid-2.5.STABLE2/src/cf.data.pre squid-2.5.STABLE2/src/cf.data.pre
--- squid-2.5.STABLE2/src/cf.data.pre	2003-02-05 08:27:50.000000000 +0300
+++ squid-2.5.STABLE2/src/cf.data.pre	2004-04-04 11:40:05.000000000 +0400
@@ -3418,12 +3418,25 @@
 DOC_END
 
 NAME: offline_mode
-TYPE: onoff
-LOC: Config.onoff.offline
-DEFAULT: off
+TYPE: int
+LOC: Config.offline
+DEFAULT: 0
+DOC_START
+       If set to 2, Squid will never try to validate cached objects.
+       If set to 1, Squid will not try to cache objects if network_interface
+               is down
+       If set to 0, Squid will operate normally.
+DOC_END
+
+NAME: network_interface
+TYPE: string
+LOC: Config.network_interface
+DEFAULT: none
 DOC_START
-	Enable this option and Squid will never try to validate cached
-	objects.
+       Used in conjunction with the new offline code. If offline_mode is 1,
+       then the status of this interface (up or down) tells us if
+       we should be operating in offline mode. If it's down, we pretend
+       we're in offline mode. If it's up, we behave normally.
 DOC_END
 
 NAME: uri_whitespace
diff -u squid-2.5.STABLE2/src/client_side.c squid-2.5.STABLE2/src/client_side.c
--- squid-2.5.STABLE2/src/client_side.c	    2003-02-20 02:39:12.000000000 +0300
+++ squid-2.5.STABLE2/src/client_side.c	    2004-04-04 11:40:22.000000000 +0400
@@ -1555,7 +1555,7 @@
 	if (e->mem_status == IN_MEMORY)
 	    http->log_type = LOG_TCP_MEM_HIT;
 	clientSendMoreData(data, buf, size);
-    } else if (!Config.onoff.offline && refreshCheckHTTP(e, r) && !http->flags.internal) {
+    } else if (!check_offline() && refreshCheckHTTP(e, r) && !http->flags.internal) {
 	debug(33, 5) ("clientCacheHit: in refreshCheck() block\n");
 	/*
 	 * We hold a stale copy; it needs to be validated
@@ -1637,7 +1637,7 @@
 	 */
 	if (e->mem_status == IN_MEMORY)
 	    http->log_type = LOG_TCP_MEM_HIT;
-	else if (Config.onoff.offline)
+	else if (check_offline())
 	    http->log_type = LOG_TCP_OFFLINE_HIT;
 	clientSendMoreData(data, buf, size);
     }
@@ -2276,7 +2276,7 @@
 	debug(33, 3) ("clientProcessRequest2: storeGet() MISS\n");
 	return LOG_TCP_MISS;
     }
-    if (Config.onoff.offline) {
+    if (check_offline()) {
 	debug(33, 3) ("clientProcessRequest2: offline HIT\n");
 	http->entry = e;
 	return LOG_TCP_HIT;
diff -u squid-2.5.STABLE2/src/forward.c squid-2.5.STABLE2/src/forward.c
--- squid-2.5.STABLE2/src/forward.c	2003-03-17 21:34:19.000000000 +0300
+++ squid-2.5.STABLE2/src/forward.c	2004-04-04 11:40:32.000000000 +0400
@@ -610,6 +610,17 @@
 	    return;
 	}
     }
+    if (check_offline()) {
+       /*
+        * Check if we're in offline mode
+        */
+           err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE);
+           err->request = requestLink(r);
+           err->src_addr = r->client_addr;
+           errorAppendEntry(e, err);
+           return;
+    }
+
     debug(17, 3) ("fwdStart: '%s'\n", storeUrl(e));
     e->mem_obj->request = requestLink(r);
     e->mem_obj->fd = fd;
diff -u squid-2.5.STABLE2/src/fqdncache.c squid-2.5.STABLE2/src/fqdncache.c
--- squid-2.5.STABLE2/src/fqdncache.c	2001-10-24 10:16:16.000000000 +0400
+++ squid-2.5.STABLE2/src/fqdncache.c	2004-04-04 11:42:33.000000000 +0400
@@ -126,6 +126,8 @@
 static int
 fqdncacheExpiredEntry(const fqdncache_entry * f)
 {
+    if(check_offline())
+	    return 0; /* In offline mode, don't expire cached entries */
     /* all static entries are locked, so this takes care of them too */
     if (f->locks != 0)
 	return 0;
@@ -197,7 +199,10 @@
     }
     hash_join(fqdn_table, &f->hash);
     dlinkAdd(f, &f->lru, &lru_list);
-    f->lastref = squid_curtime;
+    if(check_offline())
+	    f->lastref = 0;	// Expires instantly when we go online
+    else
+	    f->lastref = squid_curtime;
 }
 
 /* walks down the pending list, calling handlers */
diff -u squid-2.5.STABLE2/src/ipcache.c squid-2.5.STABLE2/src/ipcache.c
--- squid-2.5.STABLE2/src/ipcache.c	2001-11-14 01:16:24.000000000 +0300
+++ squid-2.5.STABLE2/src/ipcache.c	2004-04-04 11:48:21.000000000 +0400
@@ -133,7 +133,9 @@
 static int
 ipcacheExpiredEntry(ipcache_entry * i)
 {
-    /* all static entries are locked, so this takes care of them too */
+    if(check_offline())
+	    return 0; /* In offline mode, don't expire cached entries */
+   /* all static entries are locked, so this takes care of them too */
     if (i->locks != 0)
 	return 0;
     if (i->addrs.count == 0)
@@ -207,7 +209,10 @@
     }
     hash_join(ip_table, &i->hash);
     dlinkAdd(i, &i->lru, &lru_list);
-    i->lastref = squid_curtime;
+    if(check_offline())
+	    i->lastref = 0; // Expires instantly when we go online
+    else
+	    i->lastref = squid_curtime;
 }
 
 /* walks down the pending list, calling handlers */
diff -u squid-2.5.STABLE2/src/protos.h squid-2.5.STABLE2/src/protos.h
--- squid-2.5.STABLE2/src/protos.h	2003-01-03 02:10:46.000000000 +0300
+++ squid-2.5.STABLE2/src/protos.h	2004-04-04 11:50:21.000000000 +0400
@@ -1286,6 +1286,8 @@
 extern void *leakFreeFL(void *, const char *, int);
 #endif
 
+extern int check_offline(void);
+
 /* logfile.c */
 extern Logfile *logfileOpen(const char *path, size_t bufsz, int);
 extern void logfileClose(Logfile * lf);
diff -u squid-2.5.STABLE2/src/refresh.c squid-2.5.STABLE2/src/refresh.c
--- squid-2.5.STABLE2/src/refresh.c	2002-07-18 13:22:17.000000000 +0400
+++ squid-2.5.STABLE2/src/refresh.c	2004-04-04 11:50:59.000000000 +0400
@@ -359,6 +359,8 @@
 int
 refreshCheckHTTP(const StoreEntry * entry, request_t * request)
 {
+    if(check_offline())
+	    return 0;	/* If we're offline, we're always fresh */
     int reason = refreshCheck(entry, request, 0);
     refreshCounts[rcHTTP].total++;
     refreshCounts[rcHTTP].status[reason]++;
diff -u squid-2.5.STABLE2/src/structs.h squid-2.5.STABLE2/src/structs.h
--- squid-2.5.STABLE2/src/structs.h	2003-01-21 03:06:39.000000000 +0300
+++ squid-2.5.STABLE2/src/structs.h	2004-04-04 11:51:57.000000000 +0400
@@ -574,7 +574,6 @@
 #if HTTP_VIOLATIONS
 	int reload_into_ims;
 #endif
-	int offline;
 	int redir_rewrites_host;
 	int prefer_direct;
 	int nonhierarchical_direct;
@@ -592,6 +591,8 @@
 	int pipeline_prefetch;
 	int request_entities;
     } onoff;
+    int offline;
+    char *network_interface;
     acl *aclList;
     struct {
 	acl_access *http;
diff -u squid-2.5.STABLE2/src/tools.c squid-2.5.STABLE2/src/tools.c
--- squid-2.5.STABLE2/src/tools.c	2003-02-08 05:31:10.000000000 +0300
+++ squid-2.5.STABLE2/src/tools.c	2004-04-04 11:52:20.000000000 +0400
@@ -944,6 +944,72 @@
     return 0;
 }
 
+
+#include <net/if.h>
+#include <sys/ioctl.h>
+
+/* int is_interface_down(const char *interface_name)
+ *
+ * returns 0 if the interface exists and is UP
+ * returns 1 if the interface is down, does not exist or there is an
+ *     error trying to create a datagram socket to query interface status
+ */
+int
+is_interface_down(const char *interface_name)
+{
+       int     r,sockfd;
+
+
+       struct ifreq ifr;
+
+       sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+       if (sockfd < 0)
+               {
+               return 1; /* Cannot create a socket.
+                            I guess we can assume that the network is
+                            nil operandum */
+               }
+       strncpy(ifr.ifr_name, interface_name, IFNAMSIZ);
+       ifr.ifr_name[IFNAMSIZ-1] = '\0';
+       if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) == -1)
+               {
+               close(sockfd);
+               return 1;       /* Interface probably doesn't exist */
+               }
+       if ((ifr.ifr_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+               r=1; // Down
+       else
+               r=0; // UP
+
+       close(sockfd);
+       return r;
+}
+
+/*
+ * int check_offline(void)
+ * Returns 0 if offline_mode is 0.
+ * Returns 0 if offline_mode is 1 and the network_interface is up.
+ * Returns 1 if offline_mode is 1 and the network_interface is down.
+ * Returns 1 if offline_mode is 2.
+ */
+int
+check_offline(void)
+{
+       static time_t last_checked=0;
+       static int    last_status=0;
+       time_t now;
+
+       // Only check once per second or so.
+       time(&now);
+       if(now==last_checked)
+	       return last_status;
+       last_checked=now;
+       if(Config.offline!=1)
+               return Config.offline;
+       last_status=is_interface_down(Config.network_interface);
+       return last_status;
+}
+
 /*
  * isPowTen returns true if its argument is an integer power of
  * 10.  Its used for logging of certain error messages that can

