Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* include/net/dsfield.h - Manipulation of the Differentiated Services field */
0003 
0004 /* Written 1998-2000 by Werner Almesberger, EPFL ICA */
0005 
0006 
0007 #ifndef __NET_DSFIELD_H
0008 #define __NET_DSFIELD_H
0009 
0010 #include <linux/types.h>
0011 #include <linux/ip.h>
0012 #include <linux/ipv6.h>
0013 #include <asm/byteorder.h>
0014 
0015 
0016 static inline __u8 ipv4_get_dsfield(const struct iphdr *iph)
0017 {
0018     return iph->tos;
0019 }
0020 
0021 
0022 static inline __u8 ipv6_get_dsfield(const struct ipv6hdr *ipv6h)
0023 {
0024     return ntohs(*(__force const __be16 *)ipv6h) >> 4;
0025 }
0026 
0027 
0028 static inline void ipv4_change_dsfield(struct iphdr *iph,__u8 mask,
0029     __u8 value)
0030 {
0031         __u32 check = ntohs((__force __be16)iph->check);
0032     __u8 dsfield;
0033 
0034     dsfield = (iph->tos & mask) | value;
0035     check += iph->tos;
0036     if ((check+1) >> 16) check = (check+1) & 0xffff;
0037     check -= dsfield;
0038     check += check >> 16; /* adjust carry */
0039     iph->check = (__force __sum16)htons(check);
0040     iph->tos = dsfield;
0041 }
0042 
0043 
0044 static inline void ipv6_change_dsfield(struct ipv6hdr *ipv6h,__u8 mask,
0045     __u8 value)
0046 {
0047     __be16 *p = (__force __be16 *)ipv6h;
0048 
0049     *p = (*p & htons((((u16)mask << 4) | 0xf00f))) | htons((u16)value << 4);
0050 }
0051 
0052 
0053 #endif