]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/netat/ddp_r_zip.c
xnu-792.6.61.tar.gz
[apple/xnu.git] / bsd / netat / ddp_r_zip.c
index 573fda9e56382092b02d638665edb308b47e1341..bde37beb8ec0899d9f7267a0e05486bd6d3851f8 100644 (file)
@@ -68,6 +68,8 @@
 #include <netat/routing_tables.h>
 #include <netat/debug.h>
 
+#include <sys/kern_event.h>
+
 static void zip_reply_to_getmyzone();
 extern int at_reg_mcast(), at_unreg_mcast();
 
@@ -87,8 +89,8 @@ extern short  ErrorZIPoverflow;
 static int     netinfo_reply_pending;
 static void    zip_netinfo_reply(at_x_zip_t *, at_ifaddr_t *);
 static void    zip_getnetinfo(at_ifaddr_t *);
-static void    zip_getnetinfo_funnel(at_ifaddr_t *);
-static void    send_phony_reply(gbuf_t *);
+static void    zip_getnetinfo_locked(void *);
+static void    send_phony_reply(void *);
 
 /*
  * zip_send_getnetinfo_reply: we received a GetNetInfo packet, we need to reply
@@ -723,6 +725,10 @@ void zip_router_input (m, ifID)
                        bcopy((caddr_t)new_zone, (caddr_t)&ifID->ifZoneName, 
                              new_zone_len+1);
 
+                       /* Send network zone change event and new zone for this interface. */
+                       atalk_post_msg(ifID->aa_ifp, KEV_ATALK_ZONEUPDATED, 0, &(ifID->ifZoneName));
+                       atalk_post_msg(ifID->aa_ifp, KEV_ATALK_ZONELISTCHANGED, 0, 0);
+                       
                        /* add the new zone to the list of local zones */
                        if (!MULTIPORT_MODE && !DEFAULT_ZONE(&ifID->ifZoneName))
                                (void)setLocalZones(&ifID->ifZoneName, 
@@ -736,6 +742,7 @@ void zip_router_input (m, ifID)
                         */
                        ifID->ifNumRetries = ZIP_NETINFO_RETRIES;
                        netinfo_reply_pending = 1;
+                       ifID->ifGNIScheduled = 1;
                        timeout(zip_sched_getnetinfo, (caddr_t) ifID, 
                                 2*ZIP_TIMER_INT);
        
@@ -864,8 +871,10 @@ static void zip_netinfo_reply (netinfo, ifID)
         * to us.
         */
        /* *** Do we really need to check this? *** */
-       if (!zonename_equal((at_nvestr_t *)netinfo->data, &ifID->ifZoneName))
+       if (!zonename_equal((at_nvestr_t *)netinfo->data, &ifID->ifZoneName)) {
+               dPrintf(D_M_ZIP, D_L_INFO, ("zip_netinfo_reply, !zonename_equal!!!"));
                return;
+       }
 
        ifID->ifThisCableStart = NET_VALUE(netinfo->cable_range_start);
        ifID->ifThisCableEnd = NET_VALUE(netinfo->cable_range_end);
@@ -873,6 +882,7 @@ static void zip_netinfo_reply (netinfo, ifID)
                 ifID->ifThisCableStart, ifID->ifThisCableEnd));
 
        /* The packet is in response to our request */
+       ifID->ifGNIScheduled = 0;
        untimeout (zip_sched_getnetinfo, (caddr_t) ifID);
        netinfo_reply_pending = 0;
        zone_name_len = netinfo->data[0];
@@ -932,6 +942,12 @@ static void zip_netinfo_reply (netinfo, ifID)
                ZIPwakeup(ifID, ZIP_RE_AARP);
                return;
        }
+       
+       if (!ifID->startup_inprogress) {
+               /* Send event with zone info. This covers case where we get zone info
+                       after startup. During startup this event is sent from ZIPwakeup. */
+               atalk_post_msg(ifID->aa_ifp, KEV_ATALK_ZONEUPDATED, 0, &(ifID->ifZoneName));
+       }
 
        ZIPwakeup(ifID, 0); /* no error */
        return;
@@ -951,18 +967,24 @@ int zip_control (ifID, control)
        switch (control) {
        case ZIP_ONLINE :
        case ZIP_LATE_ROUTER :
-               ifID->ifNumRetries = 0;
-               /* Get the desired zone name from elap and put it in
-                * ifID for zip_getnetinfo() to use.
-                */
-               if (ifID->startup_zone.len)
-                       ifID->ifZoneName = ifID->startup_zone;
-               zip_getnetinfo(ifID);
+               if (!ifID->ifGNIScheduled) {
+                       ifID->ifNumRetries = 0;
+                       /* Get the desired zone name from elap and put it in
+                       * ifID for zip_getnetinfo() to use.
+                       */
+                       if (ifID->startup_zone.len)
+                               ifID->ifZoneName = ifID->startup_zone;
+                       zip_getnetinfo(ifID);
+               }
                break;
        case ZIP_NO_ROUTER :
                ifID->ifZoneName.len = 1;
                ifID->ifZoneName.str[0] = '*';
                ifID->ifZoneName.str[1] = '\0';
+
+               /* Send event with zone info. */
+               atalk_post_msg(ifID->aa_ifp, KEV_ATALK_ZONEUPDATED, 0, &(ifID->ifZoneName));
+
                break;
        default :
                break;
@@ -970,13 +992,19 @@ int zip_control (ifID, control)
        return (0);
 }
 
-/* funnel version of zip_getnetinfo */
-static void zip_getnetinfo_funnel(ifID)
-     register at_ifaddr_t       *ifID;
+/* locked version of zip_getnetinfo */
+static void zip_getnetinfo_locked(arg)
+     void       *arg;
 {
-        thread_funnel_set(network_flock, TRUE);
-       zip_getnetinfo(ifID);
-        thread_funnel_set(network_flock, FALSE);
+       at_ifaddr_t       *ifID;
+       
+       atalk_lock();
+       if (ifID != NULL) {             // make sure it hasn't been closed
+               ifID = (at_ifaddr_t *)arg;
+               ifID->ifGNIScheduled = 0;
+               zip_getnetinfo(ifID);
+       }
+       atalk_unlock();
 }
 
 
@@ -993,6 +1021,7 @@ static void zip_getnetinfo (ifID)
        void                    zip_sched_getnetinfo();
        register struct atalk_addr      *at_dest;
        register int            size;
+       
 
        size =  DDP_X_HDR_SIZE + ZIP_X_HDR_SIZE + ifID->ifZoneName.len + 1
                + sizeof(struct atalk_addr) + 1;
@@ -1003,7 +1032,8 @@ static void zip_getnetinfo (ifID)
                 */
                dPrintf(D_M_ZIP, D_L_WARNING, ("zip_getnetinfo: no buffer, call later port=%d\n",
                        ifID->ifPort));
-               timeout (zip_getnetinfo_funnel, (caddr_t) ifID, ZIP_TIMER_INT/10);
+               ifID->ifGNIScheduled = 1;
+               timeout (zip_getnetinfo_locked, (caddr_t) ifID, ZIP_TIMER_INT/10);
                return;
        }
 
@@ -1056,7 +1086,7 @@ static void zip_getnetinfo (ifID)
 
        ifID->ifNumRetries++;
        netinfo_reply_pending = 1;
-
+       ifID->ifGNIScheduled = 1;
        timeout (zip_sched_getnetinfo, (caddr_t) ifID, ZIP_TIMER_INT);
 } /* zip_getnetinfo */
 
@@ -1069,9 +1099,10 @@ static void zip_getnetinfo (ifID)
 void   zip_sched_getnetinfo (ifID)
      register at_ifaddr_t           *ifID;
 {
-       boolean_t       funnel_state;
 
-       funnel_state = thread_funnel_set(network_flock, TRUE);
+       atalk_lock();
+       
+       ifID->ifGNIScheduled = 0;
 
        if (ifID->ifNumRetries >= ZIP_NETINFO_RETRIES) {
                /* enough packets sent.... give up! */
@@ -1100,7 +1131,7 @@ void      zip_sched_getnetinfo (ifID)
        } else
                zip_getnetinfo(ifID);
 
-       (void) thread_funnel_set(network_flock, FALSE);
+       atalk_unlock();
 }
 
 
@@ -1240,16 +1271,15 @@ int zip_handle_getmyzone(ifID, m)
 }
 
 static void
-send_phony_reply(rm)
-       gbuf_t  *rm;
+send_phony_reply(arg)
+       void    *arg;
 {
-       boolean_t       funnel_state;
+       gbuf_t  *rm = (gbuf_t *)arg;
 
-       funnel_state = thread_funnel_set(network_flock, TRUE);
-        
+       atalk_lock();
        ddp_input(rm, ifID_home);
+       atalk_unlock();
         
-       (void) thread_funnel_set(network_flock, FALSE);
        return;
 }