[PATCH][RFC] 3 net drivers [etherleak]

Maciej Soltysiak (solt@dns.toxicfilms.tv)
Fri, 10 Jan 2003 13:32:08 +0100 (CET)


This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_courier-25879-1042201971-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

about a discussion about padding of ethernet frames, here are 3 patches
to 3 old popular net drivers that should do the padding:
- eexpress.c
- 3c507.c
- eepro.c

I do not have these old cards handy, it would be nice if someone who has
them, could test the drivers (which should be very easy with them compiled
as modules)

Is this a good solution?

Regards,
Maciej Soltysiak

Here are the 3 little patches:

--- linux/drivers/net/eexpress.c 2002-11-29 00:53:13.000000000 +0100
+++ linux.new/drivers/net/eexpress.c 2003-01-10 13:23:01.000000000 +0100
@@ -660,10 +654,16 @@
#endif

{
- unsigned short length = (ETH_ZLEN < buf->len) ? buf->len :
- ETH_ZLEN;
+ unsigned short length;
unsigned short *data = (unsigned short *)buf->data;

+ if (ETH_ZLEN < buf->len) {
+ length = buf->len;
+ } else {
+ length = ETH_ZLEN;
+ memset(data + buf->len, 0, length - buf->len);
+ }
+
lp->stats.tx_bytes += length;

eexp_hw_tx_pio(dev,data,length);

--- linux/drivers/net/3c507.c 2002-02-25 20:37:58.000000000 +0100
+++ linux.new/drivers/net/3c507.c 2003-01-10 13:02:02.000000000 +0100
@@ -19,6 +19,10 @@
Mark Salazar <leslie@access.digex.net> made the changes for cards with
only 16K packet buffers.

+
+ Maciej Soltysiak: Padding of ethernet frames of length less
+ than ETH_ZLEN (RFC 894, RFC 1042)
+
Things remaining to do:
Verify that the tx and rx buffers don't have fencepost errors.
Move the theory of operation and memory map documentation.
@@ -26,8 +30,8 @@
*/

#define DRV_NAME "3c507"
-#define DRV_VERSION "1.10a"
-#define DRV_RELDATE "11/17/2001"
+#define DRV_VERSION "1.11"
+#define DRV_RELDATE "01/10/2003"

static const char version[] =
DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Donald Becker (becker@scyld.com)\n";
@@ -494,9 +498,16 @@
struct net_local *lp = (struct net_local *) dev->priv;
int ioaddr = dev->base_addr;
unsigned long flags;
- short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ short length;
unsigned char *buf = skb->data;

+ if (ETH_ZLEN < skb->len) {
+ length = skb->len;
+ } else {
+ length = ETH_ZLEN;
+ memset(buf + skb->len, 0, length - skb->len);
+ }
+
netif_stop_queue (dev);

spin_lock_irqsave (&lp->lock, flags);

--- linux/drivers/net/eepro.c 2002-11-29 00:53:13.000000000 +0100
+++ linux.new/drivers/net/eepro.c 2003-01-10 13:01:55.000000000 +0100
@@ -23,6 +23,8 @@
This is a compatibility hardware problem.

Versions:
+ 0.14 padding of ethernet frames of length less than
+ ETH_ZLEN (01/10/2003)
0.13a in memory shortage, drop packets also in board
(Michael Westermann <mw@microdata-pos.de>, 07/30/2002)
0.13 irq sharing, rewrote probe function, fixed a nasty bug in
@@ -104,7 +106,7 @@
*/

static const char version[] =
- "eepro.c: v0.13 11/08/2001 aris@cathedrallabs.org\n";
+ "eepro.c: v0.14 01/10/2003 aris@cathedrallabs.org\n";

#include <linux/module.h>

@@ -1138,9 +1140,16 @@
spin_lock_irqsave(&lp->lock, flags);

{
- short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ short length;
unsigned char *buf = skb->data;

+ if (ETH_ZLEN <= skb->len) {
+ length = skb->len
+ } else {
+ length = ETH_ZLEN;
+ memset(buf + skb->len, 0, length - skb->len);
+ }
+
if (hardware_send_packet(dev, buf, length))
/* we won't wake queue here because we're out of space */
lp->stats.tx_dropped++;
--=_courier-25879-1042201971-0001-2
Content-Type: text/plain; name="eexpress.c.padding.diff"; charset=iso-8859-1
Content-Transfer-Encoding: base64
Content-ID: <Pine.LNX.4.51.0301101332071.25610@dns.toxicfilms.tv>
Content-Description: eexpress
Content-Disposition: attachment; filename="eexpress.c.padding.diff"

LS0tIGxpbnV4L2RyaXZlcnMvbmV0L2VleHByZXNzLmMJMjAwMi0xMS0yOSAw
MDo1MzoxMy4wMDAwMDAwMDAgKzAxMDANCisrKyBsaW51eC5uZXcvZHJpdmVy
cy9uZXQvZWV4cHJlc3MuYwkyMDAzLTAxLTEwIDEzOjIzOjAxLjAwMDAwMDAw
MCArMDEwMA0KQEAgLTY2MCwxMCArNjU0LDE2IEBADQogI2VuZGlmDQogICAN
CiAJew0KLQkJdW5zaWduZWQgc2hvcnQgbGVuZ3RoID0gKEVUSF9aTEVOIDwg
YnVmLT5sZW4pID8gYnVmLT5sZW4gOg0KLQkJCUVUSF9aTEVOOw0KKwkJdW5z
aWduZWQgc2hvcnQgbGVuZ3RoOw0KIAkJdW5zaWduZWQgc2hvcnQgKmRhdGEg
PSAodW5zaWduZWQgc2hvcnQgKilidWYtPmRhdGE7DQogDQorCQlpZiAoRVRI
X1pMRU4gPCBidWYtPmxlbikgew0KKwkJCWxlbmd0aCA9IGJ1Zi0+bGVuOw0K
KwkJfSBlbHNlIHsNCisJCQlsZW5ndGggPSBFVEhfWkxFTjsNCisJCQltZW1z
ZXQoZGF0YSArIGJ1Zi0+bGVuLCAwLCBsZW5ndGggLSBidWYtPmxlbik7DQor
CQl9DQorCQkNCiAJCWxwLT5zdGF0cy50eF9ieXRlcyArPSBsZW5ndGg7DQog
DQogCSAgICAgICAgZWV4cF9od190eF9waW8oZGV2LGRhdGEsbGVuZ3RoKTsN
Cg==

--=_courier-25879-1042201971-0001-2
Content-Type: text/plain; name="3c507.c.diff"; charset=iso-8859-1
Content-Transfer-Encoding: base64
Content-ID: <Pine.LNX.4.51.0301101332072.25610@dns.toxicfilms.tv>
Content-Description: 3c507
Content-Disposition: attachment; filename="3c507.c.diff"

LS0tIGxpbnV4L2RyaXZlcnMvbmV0LzNjNTA3LmMJMjAwMi0wMi0yNSAyMDoz
Nzo1OC4wMDAwMDAwMDAgKzAxMDANCisrKyBsaW51eC5uZXcvZHJpdmVycy9u
ZXQvM2M1MDcuYwkyMDAzLTAxLT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IChzdHJ1Y3QgbmV0X2xvY2Fs
ICopIGRldi0+cHJpdjsNCiAJaW50IGlvYWRkciA9IGRldi0+YmFzZV9hZGRy
Ow0KIAl1bnNpZ25lZCBsb25nIGZsYWdzOw0KLQlzaG9ydCBsZW5ndGggPSBF
VEhfWkxFTiA8IHNrYi0+bGVuID8gc2tiLT5sZW4gOiBFVEhfWkxFTjsNCisJ
c2hvcnQgbGVuZ3RoOw0KIAl1bnNpZ25lZCBjaGFyICpidWYgPSBza2ItPmRh
dGE7DQogDQorCWlmIChFVEhfWkxFTiA8IHNrYi0+bGVuKSB7DQorCQlsZW5n
dGggPSBza2ItPmxlbjsNCisJfSBlbHNlIHsNCisJCWxlbmd0aCA9IEVUSF9a
TEVOOw0KKwkJbWVtc2V0KGJ1ZiArIHNrYi0+bGVuLCAwLCBsZW5ndGggLSBz
a2ItPmxlbik7DQorCX0NCisNCiAJbmV0aWZfc3RvcF9xdWV1ZSAoZGV2KTsN
CiANCiAJc3Bpbl9sb2NrX2lycXNhdmUgKCZscC0+bG9jaywgZmxhZ3MpOw0K

--=_courier-25879-1042201971-0001-2
Content-Type: text/plain; name="eepro.c.diff"; charset=iso-8859-1
Content-Transfer-Encoding: base64
Content-ID: <Pine.LNX.4.51.0301101332080.25610@dns.toxicfilms.tv>
Content-Description: eepro
Content-Disposition: attachment; filename="eepro.c.diff"

LS0tIGxpbnV4L2RyaXZlcnMvbmV0L2VlcHJvLmMJMjAwMi0xMS0yOSAwMDo1
MzoxMy4wMDAwMDAwMDAgKzAxMDANCisrKyBsaW51eC5uZXcvZHJpdmVycy9u
ZXQvZWVwcm8uYwkyMDAzLTAxLTEwIDEzOjAxOjU1LjAwMDAwMDAwMCArMDEw
MA0KQEAgLTIzLDYgKzIzLDggQEANCiAJVGhpcyBpcyBhIGNvbXBhdGliaWxp
dHkgaGFyZHdhcmUgcHJvYmxlbS4NCiANCiAJVmVyc2lvbnM6DQorCTAuMTQJ
cGFkZGluZyBvZiBldGhlcm5ldCBm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