Subject: Re: ieee80211_mbuf_adjust
To: None <tech-net@NetBSD.org>
From: David Young <dyoung@pobox.com>
List: tech-net
Date: 08/16/2005 16:02:30
--zaRBsRFn0XYhEU69
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Aug 16, 2005 at 01:58:17PM -0500, David Young wrote:
> Index: sys/net80211/ieee80211_output.c
> ===================================================================
> RCS file: /cvsroot/src/sys/net80211/ieee80211_output.c,v
> retrieving revision 1.35
> diff -u -u -r1.35 ieee80211_output.c
> --- sys/net80211/ieee80211_output.c	16 Aug 2005 02:12:58 -0000	1.35
> +++ sys/net80211/ieee80211_output.c	16 Aug 2005 03:05:31 -0000
> @@ -352,7 +352,7 @@
>  {
>  #define	TO_BE_RECLAIMED	(sizeof(struct ether_header) - sizeof(struct llc))
>  	int needed_space = hdrsize;
> -	int error;
> +	int wlen = 0;
>  
>  	if (key != NULL) {
>  		/* XXX belongs in crypto code? */
> @@ -404,22 +404,26 @@
>  		 */
>  		n->m_next = m;
>  		m = n;
> +	} else {
> +		/* Make sure the 802.11 header + crypto header + LLC is 
> +		 * writable.
> +		 */
> +		wlen = needed_space + sizeof(struct llc);
>  	}

That should be wlen = sizeof(struct ether_header).  I have attached an
updated patch.

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Urbana, IL * (217) 278-3933

--zaRBsRFn0XYhEU69
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mbuf-adj-patch

Index: sys/net80211/ieee80211_output.c
===================================================================
RCS file: /cvsroot/src/sys/net80211/ieee80211_output.c,v
retrieving revision 1.35
diff -u -u -r1.35 ieee80211_output.c
--- sys/net80211/ieee80211_output.c	16 Aug 2005 02:12:58 -0000	1.35
+++ sys/net80211/ieee80211_output.c	16 Aug 2005 21:00:05 -0000
@@ -352,7 +352,7 @@
 {
 #define	TO_BE_RECLAIMED	(sizeof(struct ether_header) - sizeof(struct llc))
 	int needed_space = hdrsize;
-	int error;
+	int wlen = 0;
 
 	if (key != NULL) {
 		/* XXX belongs in crypto code? */
@@ -404,22 +404,27 @@
 		 */
 		n->m_next = m;
 		m = n;
+	} else {
+                /* We will overwrite the ethernet header in the
+                 * 802.11 encapsulation stage.  Make sure that it
+                 * is writable.
+		 */
+		wlen = sizeof(struct ether_header);
 	}
 
 	/*
 	 * If we're going to s/w encrypt the mbuf chain make sure it is
 	 * writable.
 	 */
-	if (key != NULL && (key->wk_flags & IEEE80211_KEY_SWCRYPT) != 0) {
-        	error = m_makewritable(&m, 0, M_COPYALL, M_DONTWAIT);
+	if (key != NULL && (key->wk_flags & IEEE80211_KEY_SWCRYPT) != 0)
+		wlen = M_COPYALL;
 
-        	if (error) {
-                	m_freem(m);
-                	m = NULL;
-        	}
+	if (wlen == 0 || m_makewritable(&m, 0, wlen, M_DONTWAIT) == 0)
+		return m;
+	else {
+		m_freem(m);
+		return NULL;
 	}
-
-	return m;
 #undef TO_BE_RECLAIMED
 }
 

--zaRBsRFn0XYhEU69--