dsfield.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. __be16 *p = (__force __be16 *)ipv6h;
  34. *p = (*p & htons((((u16)mask << 4) | 0xf00f))) | htons((u16)value << 4);
  35. }
  36. #endif