ipcommon.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* net/atm/ipcommon.c - Common items for all ways of doing IP over ATM */
  2. /* Written 1996-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. #include <linux/module.h>
  4. #include <linux/string.h>
  5. #include <linux/skbuff.h>
  6. #include <linux/netdevice.h>
  7. #include <linux/in.h>
  8. #include <linux/atmdev.h>
  9. #include <linux/atmclip.h>
  10. #include "common.h"
  11. #include "ipcommon.h"
  12. #if 0
  13. #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
  14. #else
  15. #define DPRINTK(format,args...)
  16. #endif
  17. /*
  18. * skb_migrate appends the list at "from" to "to", emptying "from" in the
  19. * process. skb_migrate is atomic with respect to all other skb operations on
  20. * "from" and "to". Note that it locks both lists at the same time, so to deal
  21. * with the lock ordering, the locks are taken in address order.
  22. *
  23. * This function should live in skbuff.c or skbuff.h.
  24. */
  25. void skb_migrate(struct sk_buff_head *from, struct sk_buff_head *to)
  26. {
  27. unsigned long flags;
  28. struct sk_buff *skb_from = (struct sk_buff *) from;
  29. struct sk_buff *skb_to = (struct sk_buff *) to;
  30. struct sk_buff *prev;
  31. if ((unsigned long) from < (unsigned long) to) {
  32. spin_lock_irqsave(&from->lock, flags);
  33. spin_lock_nested(&to->lock, SINGLE_DEPTH_NESTING);
  34. } else {
  35. spin_lock_irqsave(&to->lock, flags);
  36. spin_lock_nested(&from->lock, SINGLE_DEPTH_NESTING);
  37. }
  38. prev = from->prev;
  39. from->next->prev = to->prev;
  40. prev->next = skb_to;
  41. to->prev->next = from->next;
  42. to->prev = from->prev;
  43. to->qlen += from->qlen;
  44. spin_unlock(&to->lock);
  45. from->prev = skb_from;
  46. from->next = skb_from;
  47. from->qlen = 0;
  48. spin_unlock_irqrestore(&from->lock, flags);
  49. }
  50. EXPORT_SYMBOL(skb_migrate);