From owner-p4-projects@FreeBSD.ORG Mon Mar 17 18:57:15 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5F0D31065873; Mon, 17 Mar 2008 18:57:15 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E8C671065740 for ; Mon, 17 Mar 2008 18:57:14 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id DB2B08FC4A for ; Mon, 17 Mar 2008 18:57:14 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m2HIvEJg082809 for ; Mon, 17 Mar 2008 18:57:14 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m2HIvEFl082807 for perforce@freebsd.org; Mon, 17 Mar 2008 18:57:14 GMT (envelope-from sam@freebsd.org) Date: Mon, 17 Mar 2008 18:57:14 GMT Message-Id: <200803171857.m2HIvEFl082807@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 137936 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Mar 2008 18:57:16 -0000 http://perforce.freebsd.org/chv.cgi?CH=137936 Change 137936 by sam@sam_ebb on 2008/03/17 18:56:44 Defer state change on disassociate to avoid unnecessarily dropping the lease; we set a timer on disassociate and if we re-associate to the same ap then we just continue using the current lease; otherwise we reboot the state machine as before. May need to tweak the timer and/or fix other edge cases in the dhcp state machine but I think link state change events should handle other reasons to clock the state machine. Affected files ... .. //depot/projects/vap/sbin/dhclient/dhclient.c#4 edit Differences ... ==== //depot/projects/vap/sbin/dhclient/dhclient.c#4 (text+ko) ==== @@ -176,8 +176,30 @@ return (NULL); } + struct iaddr defaddr = { 4 }; +uint8_t curbssid[6]; + +static void +disassoc(void *arg) +{ + struct interface_info *ifi = arg; + /* + * Clear existing state. + */ + if (ifi->client->active != NULL) { + script_init("EXPIRE", NULL); + script_write_params("old_", + ifi->client->active); + if (ifi->client->alias) + script_write_params("alias_", + ifi->client->alias); + script_go(); + } + ifi->client->state = S_INIT; +} + /* ARGSUSED */ void routehandler(struct protocol *p) @@ -187,6 +209,7 @@ struct if_msghdr *ifm; struct ifa_msghdr *ifam; struct if_announcemsghdr *ifan; + struct ieee80211_join_event *jev; struct client_lease *l; time_t t = time(NULL); struct sockaddr *sa; @@ -255,24 +278,28 @@ switch (ifan->ifan_what) { case RTM_IEEE80211_ASSOC: case RTM_IEEE80211_REASSOC: + cancel_timeout(disassoc, ifi); + jev = (struct ieee80211_join_event *) &ifan[1]; + if (memcmp(curbssid, jev->iev_addr, 6)) + disassoc(ifi); state_reboot(ifi); + memcpy(curbssid, jev->iev_addr, 6); break; case RTM_IEEE80211_DISASSOC: /* - * Clear existing state; transition to the init - * state and then wait for either a link down - * notification or an associate event. + * Defer state change in case we are re-associating + * to the same ap after a deauth (e.g. due to being + * idle). We'll get an associate event and if we + * roamed we'll handle it (see above). Otherwise we'll + * eventually clear state. The only question is how + * long to wait before doing this. Give it 45 seconds + * as this should be plenty to scan multiple bands + * and complete a WPA handshake. If this event is a + * precursor to our being marked down or the interface + * going away that'll be handled by the link state + * change. */ - if (ifi->client->active != NULL) { - script_init("EXPIRE", NULL); - script_write_params("old_", - ifi->client->active); - if (ifi->client->alias) - script_write_params("alias_", - ifi->client->alias); - script_go(); - } - ifi->client->state = S_INIT; + add_timeout(t+45, disassoc, ifi); break; } break;