Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/ipp/dscpmk/dscpmk.c
+++ new/usr/src/uts/common/ipp/dscpmk/dscpmk.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <sys/types.h>
30 28 #include <sys/atomic.h>
31 29 #include <sys/pattr.h>
32 30 #include <netinet/in.h>
33 31 #include <netinet/ip6.h>
34 32 #include <inet/common.h>
35 33 #include <inet/ip.h>
36 34 #include <inet/ip6.h>
37 35 #include <ipp/dscpmk/dscpmk_impl.h>
38 36
39 37 /* Module to mark the ToS/DS field for a given packet */
40 38
41 39 /* Debug level */
42 40 int dscpmk_debug = 0;
43 41
44 42 /*
45 43 * Given a packet, this routine marks the ToS or DSCP for IPv4 and IPv6 resp.
46 44 * using the configured dscp_map.
47 45 * Note that this module does not change the ECN bits.
48 46 */
49 47 int
50 48 dscpmk_process(mblk_t **mpp, dscpmk_data_t *dscpmk_data, ip_proc_t proc)
51 49 {
52 50 ipha_t *ipha;
53 51 ip6_t *ip6_hdr;
54 52 boolean_t is_v4;
55 53 uint8_t dscp, new_dscp;
56 54 mblk_t *mp;
57 55
58 56 ASSERT((mpp != NULL) && (*mpp != NULL));
59 57 mp = *mpp;
60 58
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
61 59 /*
62 60 * The action module will receive an M_DATA or an M_CTL followed
63 61 * by an M_DATA. In the latter case skip the M_CTL.
64 62 */
65 63 if (mp->b_datap->db_type != M_DATA) {
66 64 if ((mp->b_cont != NULL) &&
67 65 (mp->b_cont->b_datap->db_type == M_DATA)) {
68 66 mp = mp->b_cont;
69 67 } else {
70 68 dscpmk0dbg(("dscpmk_process: no data\n"));
71 - atomic_add_64(&dscpmk_data->epackets, 1);
69 + atomic_inc_64(&dscpmk_data->epackets);
72 70 return (EINVAL);
73 71 }
74 72 }
75 73
76 74 /* Pull-up needed? */
77 75 if ((mp->b_wptr - mp->b_rptr) < IP_SIMPLE_HDR_LENGTH) {
78 76 if (!pullupmsg(mp, IP_SIMPLE_HDR_LENGTH)) {
79 77 dscpmk0dbg(("dscpmk_process: pullup failed\n"));
80 - atomic_add_64(&dscpmk_data->epackets, 1);
78 + atomic_inc_64(&dscpmk_data->epackets);
81 79 return (EINVAL);
82 80 }
83 81 }
84 82 ipha = (ipha_t *)mp->b_rptr;
85 83
86 84 /* Update global stats */
87 - atomic_add_64(&dscpmk_data->npackets, 1);
85 + atomic_inc_64(&dscpmk_data->npackets);
88 86
89 87 /*
90 88 * This should only be called for outgoing packets. For inbound packets
91 89 * proceed with the next action.
92 90 */
93 91 if ((proc == IPP_LOCAL_IN) || (proc == IPP_FWD_IN)) {
94 92 dscpmk2dbg(("dscpmk_process: cannot mark incoming packets\n"));
95 - atomic_add_64(&dscpmk_data->ipackets, 1);
93 + atomic_inc_64(&dscpmk_data->ipackets);
96 94 return (0);
97 95 }
98 96
99 97 /* Figure out the ToS or the Traffic Class from the message */
100 98 if (IPH_HDR_VERSION(ipha) == IPV4_VERSION) {
101 99 dscp = ipha->ipha_type_of_service;
102 100 is_v4 = B_TRUE;
103 101 } else {
104 102 ip6_hdr = (ip6_t *)mp->b_rptr;
105 103 dscp = __IPV6_TCLASS_FROM_FLOW(ip6_hdr->ip6_vcf);
106 104 is_v4 = B_FALSE;
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
107 105 }
108 106
109 107 /*
110 108 * Select the new dscp from the dscp_map after ignoring the
111 109 * ECN/CU from dscp (hence dscp >> 2). new_dscp will be the
112 110 * 6-bit DSCP value.
113 111 */
114 112 new_dscp = dscpmk_data->dscp_map[dscp >> 2];
115 113
116 114 /* Update stats for this new_dscp */
117 - atomic_add_64(&dscpmk_data->dscp_stats[new_dscp].npackets, 1);
115 + atomic_inc_64(&dscpmk_data->dscp_stats[new_dscp].npackets);
118 116
119 117 /*
120 118 * if new_dscp is same as the original, update stats and
121 119 * return.
122 120 */
123 121 if (new_dscp == (dscp >> 2)) {
124 - atomic_add_64(&dscpmk_data->unchanged, 1);
122 + atomic_inc_64(&dscpmk_data->unchanged);
125 123 return (0);
126 124 }
127 125
128 126 /* Get back the ECN/CU value from the original dscp */
129 127 new_dscp = (new_dscp << 2) | (dscp & 0x3);
130 128
131 - atomic_add_64(&dscpmk_data->changed, 1);
129 + atomic_inc_64(&dscpmk_data->changed);
132 130 /*
133 131 * IPv4 : ToS structure -- RFC 791
134 132 *
135 133 * 0 1 2 3 4 5 6 7
136 134 * +---+---+---+---+---+---+---+---+
137 135 * | IP Precd | D | T | R | 0 | 0 |
138 136 * | | | | | | |
139 137 * +---+---+---+---+---+---+---+---+
140 138 *
141 139 * For Backward Compatability the diff serv DSCP will be mapped
142 140 * to the 3-bits Precedence field. DTR is not supported. Thus,
143 141 * the following Class Seletor CodePoints are reserved from this
144 142 * purpose : xxx000; where x is 0 or 1 (note the last 2 bits are
145 143 * 00) -- see RFC 2474.
146 144 */
147 145
148 146 if (is_v4) {
149 147 ipha->ipha_type_of_service = new_dscp;
150 148 /*
151 149 * If the hardware supports checksumming, we don't need
152 150 * to do anything.
153 151 */
154 152 if (!(mp->b_datap->db_struioun.cksum.flags &
155 153 HCK_IPV4_HDRCKSUM)) {
156 154 ipha->ipha_hdr_checksum = 0;
157 155 ipha->ipha_hdr_checksum = ip_csum_hdr(ipha);
158 156 }
159 157 } else {
160 158
161 159 /*
162 160 * IPv6 : DSCP field structure is as given -- RFC 2474
163 161 *
164 162 * 0 1 2 3 4 5 6 7
165 163 * +---+---+---+---+---+---+---+---+
166 164 * | DSCP | CU |
167 165 * | | |
168 166 * +---+---+---+---+---+---+---+---+
169 167 *
170 168 * CU -- Currently Unused
171 169 *
172 170 * the 32 bit vcf consists of version (4 bits), Traffic class (8 bits)
173 171 * and flow id (20 bits). Need to take care of Big/Little-Endianess.
174 172 */
175 173 #ifdef _BIG_ENDIAN
176 174 ip6_hdr->ip6_vcf = (ip6_hdr->ip6_vcf & TCLASS_MASK) |
177 175 (new_dscp << 20);
178 176 #else
179 177 ip6_hdr->ip6_vcf = (ip6_hdr->ip6_vcf & TCLASS_MASK) |
180 178 ((new_dscp >> 4) | ((new_dscp << 12) & 0xF000));
181 179 #endif
182 180 }
183 181
184 182 return (0);
185 183 }
↓ open down ↓ |
44 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX