Blame view
include/net/dsfield.h
1.1 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 |
/* 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 [NET]: Constify i... |
13 |
static inline __u8 ipv4_get_dsfield(const struct iphdr *iph) |
1da177e4c Linux-2.6.12-rc2 |
14 15 16 |
{ return iph->tos; } |
3c3f48660 [NET]: Constify i... |
17 |
static inline __u8 ipv6_get_dsfield(const struct ipv6hdr *ipv6h) |
1da177e4c Linux-2.6.12-rc2 |
18 |
{ |
3c3f48660 [NET]: Constify i... |
19 |
return ntohs(*(const __be16 *)ipv6h) >> 4; |
1da177e4c Linux-2.6.12-rc2 |
20 21 22 23 24 25 |
} static inline void ipv4_change_dsfield(struct iphdr *iph,__u8 mask, __u8 value) { |
5c78f275e [NET]: IP header ... |
26 |
__u32 check = ntohs((__force __be16)iph->check); |
1da177e4c Linux-2.6.12-rc2 |
27 28 29 30 31 32 33 |
__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 [NET]: IP header ... |
34 |
iph->check = (__force __sum16)htons(check); |
1da177e4c Linux-2.6.12-rc2 |
35 36 37 38 39 40 41 42 |
iph->tos = dsfield; } static inline void ipv6_change_dsfield(struct ipv6hdr *ipv6h,__u8 mask, __u8 value) { __u16 tmp; |
8a9ae2110 [NET]: annotate d... |
43 |
tmp = ntohs(*(__be16 *) ipv6h); |
1da177e4c Linux-2.6.12-rc2 |
44 |
tmp = (tmp & ((mask << 4) | 0xf00f)) | (value << 4); |
8a9ae2110 [NET]: annotate d... |
45 |
*(__be16 *) ipv6h = htons(tmp); |
1da177e4c Linux-2.6.12-rc2 |
46 47 48 49 |
} #endif |