Blame view

include/net/dsfield.h 1.11 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
  /* include/net/dsfield.h - Manipulation of the Differentiated Services field */
  
  /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
  
  
  #ifndef __NET_DSFIELD_H
  #define __NET_DSFIELD_H
  
  #include <linux/types.h>
  #include <linux/ip.h>
  #include <linux/ipv6.h>
  #include <asm/byteorder.h>
3c3f48660   Jan Engelhardt   [NET]: Constify i...
14
  static inline __u8 ipv4_get_dsfield(const struct iphdr *iph)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
17
  {
  	return iph->tos;
  }
3c3f48660   Jan Engelhardt   [NET]: Constify i...
18
  static inline __u8 ipv6_get_dsfield(const struct ipv6hdr *ipv6h)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  {
3c3f48660   Jan Engelhardt   [NET]: Constify i...
20
  	return ntohs(*(const __be16 *)ipv6h) >> 4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
23
24
25
26
  }
  
  
  static inline void ipv4_change_dsfield(struct iphdr *iph,__u8 mask,
      __u8 value)
  {
5c78f275e   Al Viro   [NET]: IP header ...
27
          __u32 check = ntohs((__force __be16)iph->check);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
30
31
32
33
34
  	__u8 dsfield;
  
  	dsfield = (iph->tos & mask) | value;
  	check += iph->tos;
  	if ((check+1) >> 16) check = (check+1) & 0xffff;
  	check -= dsfield;
  	check += check >> 16; /* adjust carry */
5c78f275e   Al Viro   [NET]: IP header ...
35
  	iph->check = (__force __sum16)htons(check);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
40
41
42
  	iph->tos = dsfield;
  }
  
  
  static inline void ipv6_change_dsfield(struct ipv6hdr *ipv6h,__u8 mask,
      __u8 value)
  {
a0376db0f   YOSHIFUJI Hideaki / 吉藤英明   ipv6: Optimize ip...
43
  	__be16 *p = (__force __be16 *)ipv6h;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44

a0376db0f   YOSHIFUJI Hideaki / 吉藤英明   ipv6: Optimize ip...
45
  	*p = (*p & htons((((u16)mask << 4) | 0xf00f))) | htons((u16)value << 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
  }
  
  
  #endif