: ir243_lap_lmp_races-2.diff
PATCH 1/1 : ir243_lap_lmp_races-2.diff
Hi,
Please apply....
Jeanir243_lap_lmp_races-2.diff :
--------------------------
o [CRITICA] Avoid race condition in LSAP closure
o [CORRECT] Remove potential skb leaks
o [CORRECT] Add MEDIA_BUSY_TIMER_EXPIRED event to avoid stack deadlock
o [CORRECT] Do a proper disconnect on RECV_RD_RSP
o [FEATURE] Cleanup handling of pending LAP connect & Ultra Tx
o [FEATURE] Add small busy delay after discovery indication
o [FEATURE] Remove discovery event postponing kludge
o [FEATURE] cleanups, comments
o [FEATURE] Reduce verbosity of the stack
include/net/irda/irlmp.h renamed from include/net/irda/irlmp.d2.h +1 -1
@@ -11,6 +11,7 @@* * Copyright (c) 1998-1999 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -131,7 +132,6 @@ struct lap_cb {struct irlap_cb *irlap;/* Instance of IrLAP layer */ hashbin_t *lsaps;/* LSAP associated with this link */ -int refcount;__u8 caddr;/* Connection address */ __u32 saddr;/* Source device address */
include/net/irda/irlmp_event.h renamed from include/net/irda/irlmp_event.d2.h +1 -4
@@ -11,6 +11,7 @@* * Copyright (c) 1997, 1999 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -102,10 +103,6 @@ extern const char *irlsap_state[];void irlmp_watchdog_timer_expired (void *data);void irlmp_discovery_timer_expired (void *data);void irlmp_idle_timer_expired (void *data); - -void irlmp_next_station_state (IRLMP_STATE state); -void irlmp_next_lsap_state (struct lsap_cb *self,LSAP_STATE state); -void irlmp_next_lap_state (struct lap_cb *self,IRLMP_STATE state);void irlmp_do_lap_event (struct lap_cb *self,IRLMP_EVENT event,struct sk_buff *skb);
include/net/irda/irlap_event.h renamed from include/net/irda/irlap_event.d2.h +2 -0
@@ -12,6 +12,7 @@* * Copyright (c) 1998-1999 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -103,6 +104,7 @@ typedef enum {DISCOVERY_TIMER_EXPIRED ,WD_TIMER_EXPIRED ,BACKOFF_TIMER_EXPIRED , +MEDIA_BUSY_TIMER_EXPIRED , } IRLAP_EVENT;/*
include/net/irda/timer.h renamed from include/net/irda/timer.d2.h +4 -1
@@ -11,6 +11,7 @@* * Copyright (c) 1997, 1998-1999 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -47,7 +48,9 @@* duration of the P-timer. */ #define WD_TIMEOUT (POLL_TIMEOUT*2) +#define MEDIABUSY_TIMEOUT (500*HZ/1000)/* 500 msec */ +#define SMALLBUSY_TIMEOUT (100*HZ/1000)/* 100 msec - IrLAP 6.13.4 */ /* * Slot timer must never exceed 85 ms, and must always be at least 25 ms,
@@ -75,7 +78,7 @@ inline void irlap_start_final_timer(struinline void irlap_start_wd_timer (struct irlap_cb *self,int timeout);inline void irlap_start_backoff_timer (struct irlap_cb *self,int timeout); -void irlap_start_mbusy_timer (struct irlap_cb *); +void irlap_start_mbusy_timer (struct irlap_cb *self,int timeout);void irlap_stop_mbusy_timer (struct irlap_cb *);struct lsap_cb ;
include/net/irda/irda.h renamed from include/net/irda/irda.d2.h +6 -0
@@ -10,6 +10,7 @@* Modified by: Dag Brattli <[email protected]> * * Copyright (c) 1998-2000 Dag Brattli, All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -42,6 +43,11 @@ typedef __u32 magic_t;#ifndef FALSE #define FALSE 0 +#endif + +/* Hack to do small backoff when setting media busy in IrLAP */ +#ifndef SMALL +#define SMALL 5#endif #ifndef IRDA_MIN /* Lets not mix this MIN with other header files */
net/irda/irlmp.c renamed from net/irda/irlmp.d2.c +40 -24
187 lines not on this page · raw message
net/irda/irlmp_event.c renamed from net/irda/irlmp_event.d2.c +34 -36
169 lines not on this page · raw message
net/irda/irlmp_frame.c renamed from net/irda/irlmp_frame.d2.c +10 -52
102 lines not on this page · raw message
net/irda/irlap.c renamed from net/irda/irlap.d2.c +30 -5
@@ -10,6 +10,7 @@* Modified by: Dag Brattli <[email protected]> * * Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -502,10 +503,17 @@ void irlap_discovery_request(struct irlaIRDA_DEBUG (4 , __FUNCTION__"(), discovery only possible in NDM mode\n" );irlap_discovery_confirm (self,NULL ); +/* Note : in theory, if we are not in NDM, we could postpone +* the discovery like we do for connection request. +* In practice, it's not worth it. If the media was busy, +* it's likely next time around it won't be busy. If we are +* in REPLY state, we will get passive discovery info & event. +* Jean II */ return ; } -/* Check if last discovery request finished in time */ +/* Check if last discovery request finished in time, or if +* it was aborted due to the media busy flag. */ if (self->discovery_log !=NULL ) {hashbin_delete (self->discovery_log, (FREE_FUNC ) kfree); self->discovery_log =NULL ;
@@ -555,10 +563,16 @@ void irlap_discovery_confirm(struct irla/* * Check for successful discovery, since we are then allowed to clear -* the media busy condition (irlap p.94). This should allow us to make -* connection attempts much easier. +* the media busy condition (IrLAP 6.13.4 - p.94). This should allow +* us to make connection attempts much faster and easier (i.e. no +* collisions). +* Setting media busy to false will also generate an event allowing +* to process pending events in NDM state machine. +* Note : the spec doesn't define what's a successful discovery is. +* If we want Ultra to work, it's successful even if there is +* nobody discovered - Jean II */ -if (discovery_log &&HASHBIN_GET_SIZE (discovery_log) >0 ) +if (discovery_log)irda_device_set_media_busy (self->netdev, FALSE);/* Inform IrLMP */
@@ -580,7 +594,18 @@ void irlap_discovery_indication(struct i ASSERT(discovery != NULL, return;); ASSERT(self->notify.instance != NULL, return;); - + +/* A device is very likely to connect immediately after it performs +* a successful discovery. This means that in our case, we are much +* more likely to receive a connection request over the medium. +* So, we backoff to avoid collisions. +* IrLAP spec 6.13.4 suggest 100ms... +* Note : this little trick actually make a *BIG* difference. If I set +* my Linux box with discovery enabled and one Ultra frame sent every +* second, my Palm has no trouble connecting to it every time ! +* Jean II */ +irda_device_set_media_busy (self->netdev,SMALL ); +irlmp_link_discovery_indication (self->notify.instance, discovery); }
net/irda/irlap_event.c renamed from net/irda/irlap_event.d2.c +65 -28
156 lines not on this page · raw message
net/irda/irlap_frame.c renamed from net/irda/irlap_frame.d2.c +2 -1
@@ -11,6 +11,7 @@* * Copyright (c) 1998-2000 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -696,7 +697,7 @@ static void irlap_recv_srej_frame(structstatic void irlap_recv_disc_frame (struct irlap_cb *self,struct sk_buff *skb,struct irlap_info *info,int command) { -IRDA_DEBUG (0 , __FUNCTION__"()\n" ); +IRDA_DEBUG (2 , __FUNCTION__"()\n" );/* Check if this is a command or a response frame */ if (command)
net/irda/timer.c renamed from net/irda/timer.d2.c +14 -16
@@ -11,6 +11,7 @@* * Copyright (c) 1997, 1999 Dag Brattli <[email protected]>, * All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -94,29 +95,24 @@ void irlap_start_backoff_timer(struct ir irlap_backoff_timer_expired); } -void irlap_start_mbusy_timer (struct irlap_cb *self) +void irlap_start_mbusy_timer (struct irlap_cb *self,int timeout) { -irda_start_timer (&self->media_busy_timer,MEDIABUSY_TIMEOUT , +irda_start_timer (&self->media_busy_timer, timeout, (void *) self, irlap_media_busy_expired); }void irlap_stop_mbusy_timer (struct irlap_cb *self) {/* If timer is activated, kill it! */ -if (timer_pending (&self->media_busy_timer)) -del_timer (&self->media_busy_timer); +del_timer (&self->media_busy_timer); -#ifdef CONFIG_IRDA_ULTRA -/* Send any pending Ultra frames if any */ -if (!skb_queue_empty (&self->txq_ultra)) -/* Note : we don't send the frame, just post an event. -* Frames will be sent only if we are in NDM mode (see -* irlap_event.c). -* Also, moved this code from irlap_media_busy_expired() -* to here to catch properly all cases... -* Jean II */ -irlap_do_event (self,SEND_UI_FRAME ,NULL ,NULL ); -#endif /* CONFIG_IRDA_ULTRA */ +/* If we are in NDM, there is a bunch of events in LAP that +* that be pending due to the media_busy condition, such as +* CONNECT_REQUEST and SEND_UI_FRAME. If we don't generate +* an event, they will wait forever... +* Jean II */ +if (self->state ==LAP_NDM ) +irlap_do_event (self,MEDIA_BUSY_TIMER_EXPIRED ,NULL ,NULL ); }void irlmp_start_watchdog_timer (struct lsap_cb *self,int timeout)
@@ -237,5 +233,7 @@ void irlap_media_busy_expired(void* data ASSERT(self != NULL, return;);irda_device_set_media_busy (self->netdev, FALSE); -/* Note : will deal with Ultra frames */ +/* Note : the LAP event will be send in irlap_stop_mbusy_timer(), +* to catch other cases where the flag is cleared (for example +* after a discovery) - Jean II */ }
net/irda/irda_device.c renamed from net/irda/irda_device.d2.c +5 -1
@@ -10,6 +10,7 @@* Modified by: Dag Brattli <[email protected]> * * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved. +* Copyright (c) 2000-2001 Jean Tourrilhes <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as
@@ -181,7 +182,10 @@ void irda_device_set_media_busy(struct nif (status) { self->media_busy = TRUE; -irlap_start_mbusy_timer (self); +if (status ==SMALL ) +irlap_start_mbusy_timer (self,SMALLBUSY_TIMEOUT ); +else +irlap_start_mbusy_timer (self,MEDIABUSY_TIMEOUT );IRDA_DEBUG (4 ,"Media busy!\n" ); }else { self->media_busy = FALSE;