inet.cc (9200:16de812c5f53) inet.cc (9955:5d8722ab804b)
1/*
1/*
2 * Copyright (c) 2013 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;

--- 13 unchanged lines hidden (view full) ---

23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Nathan Binkert
30 * Gabe Black
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2010 Advanced Micro Devices, Inc.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;

--- 13 unchanged lines hidden (view full) ---

35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Nathan Binkert
42 * Gabe Black
43 * Geoffrey Blake
31 */
32
33#include <cstddef>
34#include <cstdio>
35#include <sstream>
36#include <string>
37
38#include "base/cprintf.hh"

--- 161 unchanged lines hidden (view full) ---

200 int tcplen = ip->len() - ip->hlen();
201 int sum = ip_cksum_add(ip->payload(), tcplen, 0);
202 sum = ip_cksum_add(&ip->ip_src, 8, sum); // source and destination
203 sum += htons(ip->ip_p + tcplen);
204 return ip_cksum_carry(sum);
205}
206
207uint16_t
44 */
45
46#include <cstddef>
47#include <cstdio>
48#include <sstream>
49#include <string>
50
51#include "base/cprintf.hh"

--- 161 unchanged lines hidden (view full) ---

213 int tcplen = ip->len() - ip->hlen();
214 int sum = ip_cksum_add(ip->payload(), tcplen, 0);
215 sum = ip_cksum_add(&ip->ip_src, 8, sum); // source and destination
216 sum += htons(ip->ip_p + tcplen);
217 return ip_cksum_carry(sum);
218}
219
220uint16_t
221__tu_cksum6(const Ip6Ptr &ip6)
222{
223 int tcplen = ip6->plen() - ip6->extensionLength();
224 int sum = ip_cksum_add(ip6->payload(), tcplen, 0);
225 sum = ip_cksum_add(ip6->src(), 32, sum);
226 sum += htons(ip6->proto() + tcplen);
227 return ip_cksum_carry(sum);
228}
229
230uint16_t
208cksum(const TcpPtr &tcp)
231cksum(const TcpPtr &tcp)
209{ return __tu_cksum(IpPtr(tcp.packet())); }
232{
233 if (IpPtr(tcp.packet())) {
234 return __tu_cksum(IpPtr(tcp.packet()));
235 } else if (Ip6Ptr(tcp.packet())) {
236 return __tu_cksum6(Ip6Ptr(tcp.packet()));
237 } else {
238 assert(0);
239 }
240 // Should never reach here
241 return 0;
242}
210
211uint16_t
212cksum(const UdpPtr &udp)
243
244uint16_t
245cksum(const UdpPtr &udp)
213{ return __tu_cksum(IpPtr(udp.packet())); }
246{
247 if (IpPtr(udp.packet())) {
248 return __tu_cksum(IpPtr(udp.packet()));
249 } else if (Ip6Ptr(udp.packet())) {
250 return __tu_cksum6(Ip6Ptr(udp.packet()));
251 } else {
252 assert(0);
253 }
254 return 0;
255}
214
215bool
216IpHdr::options(vector<const IpOpt *> &vec) const
217{
218 vec.clear();
219
220 const uint8_t *data = bytes() + sizeof(struct ip_hdr);
221 int all = hlen() - sizeof(struct ip_hdr);

--- 6 unchanged lines hidden (view full) ---

228 vec.push_back(opt);
229 all -= len;
230 data += len;
231 }
232
233 return true;
234}
235
256
257bool
258IpHdr::options(vector<const IpOpt *> &vec) const
259{
260 vec.clear();
261
262 const uint8_t *data = bytes() + sizeof(struct ip_hdr);
263 int all = hlen() - sizeof(struct ip_hdr);

--- 6 unchanged lines hidden (view full) ---

270 vec.push_back(opt);
271 all -= len;
272 data += len;
273 }
274
275 return true;
276}
277
278#define IP6_EXTENSION(nxt) (nxt == IP_PROTO_HOPOPTS) ? true : \
279 (nxt == IP_PROTO_ROUTING) ? true : \
280 (nxt == IP_PROTO_FRAGMENT) ? true : \
281 (nxt == IP_PROTO_AH) ? true : \
282 (nxt == IP_PROTO_ESP) ? true: \
283 (nxt == IP_PROTO_DSTOPTS) ? true : false
284
285/* Scan the IP6 header for all header extensions
286 * and return the number of headers found
287 */
288int
289Ip6Hdr::extensionLength() const
290{
291 const uint8_t *data = bytes() + IP6_HDR_LEN;
292 uint8_t nxt = ip6_nxt;
293 int len = 0;
294 int all = plen();
295
296 while (IP6_EXTENSION(nxt)) {
297 const Ip6Opt *ext = (const Ip6Opt *)data;
298 nxt = ext->nxt();
299 len += ext->len();
300 data += ext->len();
301 all -= ext->len();
302 assert(all >= 0);
303 }
304 return len;
305}
306
307/* Scan the IP6 header for a particular extension
308 * header type and return a pointer to it if it
309 * exists, otherwise return NULL
310 */
311const Ip6Opt*
312Ip6Hdr::getExt(uint8_t ext_type) const
313{
314 const uint8_t *data = bytes() + IP6_HDR_LEN;
315 uint8_t nxt = ip6_nxt;
316 Ip6Opt* opt = NULL;
317 int all = plen();
318
319 while (IP6_EXTENSION(nxt)) {
320 opt = (Ip6Opt *)data;
321 if (nxt == ext_type) {
322 break;
323 }
324 nxt = opt->nxt();
325 data += opt->len();
326 all -= opt->len();
327 opt = NULL;
328 assert(all >= 0);
329 }
330 return (const Ip6Opt*)opt;
331}
332
333/* Scan the IP6 header and any extension headers
334 * to find what type of Layer 4 header exists
335 * after this header
336 */
337uint8_t
338Ip6Hdr::proto() const
339{
340 const uint8_t *data = bytes() + IP6_HDR_LEN;
341 uint8_t nxt = ip6_nxt;
342 int all = plen();
343
344 while (IP6_EXTENSION(nxt)) {
345 const Ip6Opt *ext = (const Ip6Opt *)data;
346 nxt = ext->nxt();
347 data += ext->len();
348 all -= ext->len();
349 assert(all >= 0);
350 }
351 return nxt;
352}
353
236bool
237TcpHdr::options(vector<const TcpOpt *> &vec) const
238{
239 vec.clear();
240
241 const uint8_t *data = bytes() + sizeof(struct tcp_hdr);
242 int all = off() - sizeof(struct tcp_hdr);
243 while (all > 0) {

--- 11 unchanged lines hidden (view full) ---

255}
256
257int
258hsplit(const EthPacketPtr &ptr)
259{
260 int split_point = 0;
261
262 IpPtr ip(ptr);
354bool
355TcpHdr::options(vector<const TcpOpt *> &vec) const
356{
357 vec.clear();
358
359 const uint8_t *data = bytes() + sizeof(struct tcp_hdr);
360 int all = off() - sizeof(struct tcp_hdr);
361 while (all > 0) {

--- 11 unchanged lines hidden (view full) ---

373}
374
375int
376hsplit(const EthPacketPtr &ptr)
377{
378 int split_point = 0;
379
380 IpPtr ip(ptr);
381 Ip6Ptr ip6(ptr);
263 if (ip) {
264 split_point = ip.pstart();
265
266 TcpPtr tcp(ip);
267 if (tcp)
268 split_point = tcp.pstart();
269
270 UdpPtr udp(ip);
271 if (udp)
272 split_point = udp.pstart();
382 if (ip) {
383 split_point = ip.pstart();
384
385 TcpPtr tcp(ip);
386 if (tcp)
387 split_point = tcp.pstart();
388
389 UdpPtr udp(ip);
390 if (udp)
391 split_point = udp.pstart();
392 } else if (ip6) {
393 split_point = ip6.pstart();
394
395 TcpPtr tcp(ip6);
396 if (tcp)
397 split_point = tcp.pstart();
398 UdpPtr udp(ip6);
399 if (udp)
400 split_point = udp.pstart();
273 }
274 return split_point;
275}
276
277
278} // namespace Net
401 }
402 return split_point;
403}
404
405
406} // namespace Net