inet_ecn.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:1k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #ifndef _INET_ECN_H_
  2. #define _INET_ECN_H_
  3. static inline int INET_ECN_is_ce(__u8 dsfield)
  4. {
  5. return (dsfield&3) == 3;
  6. }
  7. static inline int INET_ECN_is_not_ce(__u8 dsfield)
  8. {
  9. return (dsfield&3) == 2;
  10. }
  11. static inline int INET_ECN_is_capable(__u8 dsfield)
  12. {
  13. return (dsfield&2);
  14. }
  15. static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
  16. {
  17. outer &= ~3;
  18. if (INET_ECN_is_capable(inner))
  19. outer |= (inner & 3);
  20. return outer;
  21. }
  22. #define INET_ECN_xmit(sk) do { (sk)->protinfo.af_inet.tos |= 2; } while (0)
  23. #define INET_ECN_dontxmit(sk) do { (sk)->protinfo.af_inet.tos &= ~3; } while (0)
  24. #define IP6_ECN_flow_init(label) do {
  25.       (label) &= ~htonl(3<<20);
  26.     } while (0)
  27. #define IP6_ECN_flow_xmit(sk, label) do {
  28. if (INET_ECN_is_capable((sk)->protinfo.af_inet.tos))
  29. (label) |= __constant_htons(2 << 4);
  30.     } while (0)
  31. static inline void IP_ECN_set_ce(struct iphdr *iph)
  32. {
  33. u32 check = iph->check;
  34. check += __constant_htons(0xFFFE);
  35. iph->check = check + (check>=0xFFFF);
  36. iph->tos |= 1;
  37. }
  38. struct ipv6hdr;
  39. static inline void IP6_ECN_set_ce(struct ipv6hdr *iph)
  40. {
  41. *(u32*)iph |= htonl(1<<20);
  42. }
  43. #define ip6_get_dsfield(iph) ((ntohs(*(u16*)(iph)) >> 4) & 0xFF)
  44. #endif