netdev
[Top] [All Lists]

alignment issues on netif_rx

To: netdev@xxxxxxxxxxx
Subject: alignment issues on netif_rx
From: Kai Germaschewski <kai@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Dec 2000 13:41:32 +0100 (CET)
Sender: owner-netdev@xxxxxxxxxxx
Some people are planning to use the ISDN code in the linux kernel on their
MIPS port.

They ran into some problems with alignment, and use the following patch to
fix their problems.


diff -ur isdn-HEAD/drivers/isdn/isdn_ppp.c isdn-h/drivers/isdn/isdn_ppp.c
--- isdn-HEAD/drivers/isdn/isdn_ppp.c   Tue Nov 28 15:36:36 2000
+++ isdn-h/drivers/isdn/isdn_ppp.c      Fri Dec 15 11:51:38 2000
@@ -984,8 +984,32 @@
 {
        struct net_device *dev = &net_dev->dev;
        struct ippp_struct *is, *mis;
+       
+       struct sk_buff *realign_skb;
+
        int slot;
 
+       /* Re-align skb data to four-byte alignment if nessecary
+         * Stephen Aaskov, EICON Networks dec. 2000
+       */
+       if ((int) (skb->data) & 3) {
+         if( (realign_skb = dev_alloc_skb(skb->len)) == NULL ) {
+           printk(KERN_ERR "isdn_mppp: cannot allocate sk buff "
+                  "of size %d\n", skb->len);
+           kfree_skb(skb);
+           return;
+         } 
+         skb_put (realign_skb,skb->len);
+         memcpy(realign_skb->data, skb->data, skb->len);         
+         kfree_skb(skb);
+         skb = realign_skb;
+         printk (KERN_INFO "skb re-aligned\n");
+       }
+       
+       /*
+        * Data is now correct aligned   
+       */
+       
        slot = lp->ppp_slot;
        if (slot < 0 || slot > ISDN_MAX_CHANNELS) {
                printk(KERN_ERR "isdn_ppp_push_higher: lp->ppp_slot %d\n", 
lp->ppp_slot);

At this point we basically do (for proto = PPP_IP)

        skb->protocol = htons(ETH_P_IP);
        skb->dev = dev;
        skb->mac.raw = skb->data;
        netif_rx(skb);

(BTW: Can someone explain what the mac.raw thing is for w.r.t PPP?)

Without the above fix of aligning skb->data on a 4-byte boundary, the
packet would get dropped later on.

Question is: Is this the right way to handle this problem, or should
netif_rx be smarter and take unalignment skbs?
BTW: Would the above realigning make sense on other archs, too
(for performance reasons)?

--Kai




<Prev in Thread] Current Thread [Next in Thread>