dsfield.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* include/net/dsfield.h - Manipulation of the Differentiated Services field */
  2. /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
  3. #ifndef __NET_DSFIELD_H
  4. #define __NET_DSFIELD_H
  5. #include <linux/types.h>
  6. #include <linux/ip.h>
  7. #include <linux/ipv6.h>
  8. #include <asm/byteorder.h>
  9. static inline __u8 ipv4_get_dsfield(const struct iphdr *iph)
  10. {
  11. return iph->tos;
  12. }
  13. static inline __u8 ipv6_get_dsfield(const struct ipv6hdr *ipv6h)
  14. {
  15. return ntohs(*(const __be16 *)ipv6h) >> 4;
  16. }
  17. static inline void ipv4_change_dsfield(struct iphdr *iph,__u8 mask,
  18. __u8 value)
  19. {
  20. __u32 check = ntohs((__force __be16)iph->check);
  21. __u8 dsfield;
  22. dsfield = (iph->tos & mask) | value;
  23. check += iph->tos;
  24. if ((check+1) >> 16) check = (check+1) & 0xffff;
  25. check -= dsfield;
  26. check += check >> 16; /* adjust carry */
  27. iph->check = (__force __sum16)htons(check);
  28. iph->tos = dsfield;
  29. }
  30. static inline void ipv6_change_dsfield(struct ipv6hdr *ipv6h,__u8 mask,
  31. __u8 value)
  32. {
  33. __u16 tmp;
  34. tmp = ntohs(*(__be16 *) ipv6h);
  35. tmp = (tmp & ((mask << 4) | 0xf00f)) | (value << 4);
  36. *(__be16 *) ipv6h = htons(tmp);
  37. }
  38. #endif