|
Lines 369-405
TcpL4Protocol::PrintIpInformation (Ipv6Header const &ipHeader,
|
Link Here
|
|---|
|
| 369 |
|
369 |
|
| 370 |
enum IpL4Protocol::RxStatus |
370 |
enum IpL4Protocol::RxStatus |
| 371 |
TcpL4Protocol::Receive (Ptr<Packet> packet, |
371 |
TcpL4Protocol::Receive (Ptr<Packet> packet, |
| 372 |
Ipv4Header const &ipHeader, |
372 |
Ipv4Header const &incomingIpHeader, |
| 373 |
Ptr<Ipv4Interface> incomingInterface) |
373 |
Ptr<Ipv4Interface> incomingInterface) |
| 374 |
{ |
374 |
{ |
| 375 |
NS_LOG_FUNCTION (this << packet << ipHeader << incomingInterface); |
375 |
NS_LOG_FUNCTION (this << packet << incomingIpHeader << incomingInterface); |
| 376 |
|
376 |
|
| 377 |
TcpHeader tcpHeader; |
377 |
TcpHeader incomingTcpHeader; |
| 378 |
if(Node::ChecksumEnabled ()) |
378 |
if(Node::ChecksumEnabled ()) |
| 379 |
{ |
379 |
{ |
| 380 |
tcpHeader.EnableChecksums (); |
380 |
incomingTcpHeader.EnableChecksums (); |
| 381 |
tcpHeader.InitializeChecksum (ipHeader.GetSource (), |
381 |
incomingTcpHeader.InitializeChecksum (incomingIpHeader.GetSource (), |
| 382 |
ipHeader.GetDestination (), PROT_NUMBER); |
382 |
incomingIpHeader.GetDestination (), |
|
|
383 |
PROT_NUMBER); |
| 383 |
} |
384 |
} |
| 384 |
|
385 |
|
| 385 |
packet->PeekHeader (tcpHeader); |
386 |
packet->PeekHeader (incomingTcpHeader); |
| 386 |
|
387 |
|
| 387 |
NS_LOG_LOGIC ("TcpL4Protocol " << this |
388 |
NS_LOG_LOGIC ("TcpL4Protocol " << this |
| 388 |
<< " receiving seq " << tcpHeader.GetSequenceNumber () |
389 |
<< " receiving seq " << incomingTcpHeader.GetSequenceNumber () |
| 389 |
<< " ack " << tcpHeader.GetAckNumber () |
390 |
<< " ack " << incomingTcpHeader.GetAckNumber () |
| 390 |
<< " flags "<< std::hex << (int)tcpHeader.GetFlags () << std::dec |
391 |
<< " flags "<< std::hex << (int)incomingTcpHeader.GetFlags () << std::dec |
| 391 |
<< " data size " << packet->GetSize ()); |
392 |
<< " data size " << packet->GetSize ()); |
| 392 |
|
393 |
|
| 393 |
if(!tcpHeader.IsChecksumOk ()) |
394 |
if(! incomingTcpHeader.IsChecksumOk ()) |
| 394 |
{ |
395 |
{ |
| 395 |
NS_LOG_INFO ("Bad checksum, dropping packet!"); |
396 |
NS_LOG_INFO ("Bad checksum, dropping packet!"); |
| 396 |
return IpL4Protocol::RX_CSUM_FAILED; |
397 |
return IpL4Protocol::RX_CSUM_FAILED; |
| 397 |
} |
398 |
} |
| 398 |
|
399 |
|
| 399 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
400 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
| 400 |
Ipv4EndPointDemux::EndPoints endPoints = |
401 |
|
| 401 |
m_endPoints->Lookup (ipHeader.GetDestination (), tcpHeader.GetDestinationPort (), |
402 |
Ipv4EndPointDemux::EndPoints endPoints; |
| 402 |
ipHeader.GetSource (), tcpHeader.GetSourcePort (),incomingInterface); |
403 |
endPoints = m_endPoints->Lookup (incomingIpHeader.GetDestination (), |
|
|
404 |
incomingTcpHeader.GetDestinationPort (), |
| 405 |
incomingIpHeader.GetSource (), |
| 406 |
incomingTcpHeader.GetSourcePort (), |
| 407 |
incomingInterface); |
| 408 |
|
| 403 |
if (endPoints.empty ()) |
409 |
if (endPoints.empty ()) |
| 404 |
{ |
410 |
{ |
| 405 |
if (this->GetObject<Ipv6L3Protocol> () != 0) |
411 |
if (this->GetObject<Ipv6L3Protocol> () != 0) |
|
Lines 407-442
TcpL4Protocol::Receive (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 407 |
NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 "<<this); |
413 |
NS_LOG_LOGIC (" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 "<<this); |
| 408 |
Ptr<Ipv6Interface> fakeInterface; |
414 |
Ptr<Ipv6Interface> fakeInterface; |
| 409 |
Ipv6Header ipv6Header; |
415 |
Ipv6Header ipv6Header; |
| 410 |
Ipv6Address src = Ipv6Address::MakeIpv4MappedAddress (ipHeader.GetSource ()); |
416 |
Ipv6Address src, dst; |
| 411 |
Ipv6Address dst = Ipv6Address::MakeIpv4MappedAddress (ipHeader.GetDestination ()); |
417 |
|
|
|
418 |
src = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetSource ()); |
| 419 |
dst = Ipv6Address::MakeIpv4MappedAddress (incomingIpHeader.GetDestination ()); |
| 412 |
ipv6Header.SetSourceAddress (src); |
420 |
ipv6Header.SetSourceAddress (src); |
| 413 |
ipv6Header.SetDestinationAddress (dst); |
421 |
ipv6Header.SetDestinationAddress (dst); |
| 414 |
return (this->Receive (packet, ipv6Header, fakeInterface)); |
422 |
return (this->Receive (packet, ipv6Header, fakeInterface)); |
| 415 |
} |
423 |
} |
| 416 |
|
424 |
|
| 417 |
NS_LOG_LOGIC (" No endpoints matched on TcpL4Protocol "<<this); |
425 |
NS_LOG_LOGIC (" No endpoints matched on TcpL4Protocol "<<this); |
| 418 |
NS_LOG_LOGIC (PrintIpInformation (ipHeader, tcpHeader)); |
426 |
NS_LOG_LOGIC (PrintIpInformation (incomingIpHeader, incomingTcpHeader)); |
| 419 |
|
427 |
|
| 420 |
if (!(tcpHeader.GetFlags () & TcpHeader::RST)) |
428 |
if (! (incomingTcpHeader.GetFlags () & TcpHeader::RST)) |
| 421 |
{ |
429 |
{ |
| 422 |
// build a RST packet and send |
430 |
// build a RST packet and send |
| 423 |
Ptr<Packet> rstPacket = Create<Packet> (); |
431 |
Ptr<Packet> rstPacket = Create<Packet> (); |
| 424 |
TcpHeader header; |
432 |
TcpHeader outgoingTcpHeader; |
| 425 |
if (tcpHeader.GetFlags () & TcpHeader::ACK) |
433 |
if (incomingTcpHeader.GetFlags () & TcpHeader::ACK) |
| 426 |
{ |
434 |
{ |
| 427 |
// ACK bit was set |
435 |
// ACK bit was set |
| 428 |
header.SetFlags (TcpHeader::RST); |
436 |
outgoingTcpHeader.SetFlags (TcpHeader::RST); |
| 429 |
header.SetSequenceNumber (header.GetAckNumber ()); |
437 |
outgoingTcpHeader.SetSequenceNumber (incomingTcpHeader.GetAckNumber ()); |
| 430 |
} |
438 |
} |
| 431 |
else |
439 |
else |
| 432 |
{ |
440 |
{ |
| 433 |
header.SetFlags (TcpHeader::RST | TcpHeader::ACK); |
441 |
outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK); |
| 434 |
header.SetSequenceNumber (SequenceNumber32 (0)); |
442 |
outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0)); |
| 435 |
header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber32 (1)); |
443 |
outgoingTcpHeader.SetAckNumber (incomingTcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
| 436 |
} |
444 |
} |
| 437 |
header.SetSourcePort (tcpHeader.GetDestinationPort ()); |
445 |
|
| 438 |
header.SetDestinationPort (tcpHeader.GetSourcePort ()); |
446 |
outgoingTcpHeader.SetSourcePort (incomingTcpHeader.GetDestinationPort ()); |
| 439 |
SendPacket (rstPacket, header, ipHeader.GetDestination (), ipHeader.GetSource ()); |
447 |
outgoingTcpHeader.SetDestinationPort (incomingTcpHeader.GetSourcePort ()); |
|
|
448 |
|
| 449 |
SendPacket (rstPacket, outgoingTcpHeader, incomingIpHeader.GetDestination (), |
| 450 |
incomingIpHeader.GetSource ()); |
| 440 |
return IpL4Protocol::RX_ENDPOINT_CLOSED; |
451 |
return IpL4Protocol::RX_ENDPOINT_CLOSED; |
| 441 |
} |
452 |
} |
| 442 |
else |
453 |
else |
|
Lines 446-465
TcpL4Protocol::Receive (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 446 |
} |
457 |
} |
| 447 |
NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint"); |
458 |
NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint"); |
| 448 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
459 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
| 449 |
(*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.GetSourcePort (), |
460 |
(*endPoints.begin ())->ForwardUp (packet, incomingIpHeader, |
|
|
461 |
incomingTcpHeader.GetSourcePort (), |
| 450 |
incomingInterface); |
462 |
incomingInterface); |
| 451 |
return IpL4Protocol::RX_OK; |
463 |
return IpL4Protocol::RX_OK; |
| 452 |
} |
464 |
} |
| 453 |
|
465 |
|
| 454 |
enum IpL4Protocol::RxStatus |
466 |
enum IpL4Protocol::RxStatus |
| 455 |
TcpL4Protocol::Receive (Ptr<Packet> packet, |
467 |
TcpL4Protocol::Receive (Ptr<Packet> packet, |
| 456 |
Ipv6Header const &ipHeader, |
468 |
Ipv6Header const &incomingIpHeader, |
| 457 |
Ptr<Ipv6Interface> interface) |
469 |
Ptr<Ipv6Interface> interface) |
| 458 |
{ |
470 |
{ |
| 459 |
NS_LOG_FUNCTION (this << packet << ipHeader.GetSourceAddress () << |
471 |
NS_LOG_FUNCTION (this << packet << incomingIpHeader.GetSourceAddress () << |
| 460 |
ipHeader.GetDestinationAddress ()); |
472 |
incomingIpHeader.GetDestinationAddress ()); |
| 461 |
|
473 |
|
| 462 |
TcpHeader tcpHeader; |
474 |
TcpHeader incomingTcpHeader; |
| 463 |
|
475 |
|
| 464 |
// If we are receving a v4-mapped packet, we will re-calculate the TCP checksum |
476 |
// If we are receving a v4-mapped packet, we will re-calculate the TCP checksum |
| 465 |
// Is it worth checking every received "v6" packet to see if it is v4-mapped in |
477 |
// Is it worth checking every received "v6" packet to see if it is v4-mapped in |
|
Lines 467-486
TcpL4Protocol::Receive (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 467 |
|
479 |
|
| 468 |
if(Node::ChecksumEnabled ()) |
480 |
if(Node::ChecksumEnabled ()) |
| 469 |
{ |
481 |
{ |
| 470 |
tcpHeader.EnableChecksums (); |
482 |
incomingTcpHeader.EnableChecksums (); |
| 471 |
tcpHeader.InitializeChecksum (ipHeader.GetSourceAddress (), |
483 |
incomingTcpHeader.InitializeChecksum (incomingIpHeader.GetSourceAddress (), |
| 472 |
ipHeader.GetDestinationAddress (), PROT_NUMBER); |
484 |
incomingIpHeader.GetDestinationAddress (), PROT_NUMBER); |
| 473 |
} |
485 |
} |
| 474 |
|
486 |
|
| 475 |
packet->PeekHeader (tcpHeader); |
487 |
packet->PeekHeader (incomingTcpHeader); |
| 476 |
|
488 |
|
| 477 |
NS_LOG_LOGIC ("TcpL4Protocol " << this |
489 |
NS_LOG_LOGIC ("TcpL4Protocol " << this |
| 478 |
<< " receiving seq " << tcpHeader.GetSequenceNumber () |
490 |
<< " receiving seq " << incomingTcpHeader.GetSequenceNumber () |
| 479 |
<< " ack " << tcpHeader.GetAckNumber () |
491 |
<< " ack " << incomingTcpHeader.GetAckNumber () |
| 480 |
<< " flags "<< std::hex << (int)tcpHeader.GetFlags () << std::dec |
492 |
<< " flags "<< std::hex << (int)incomingTcpHeader.GetFlags () << std::dec |
| 481 |
<< " data size " << packet->GetSize ()); |
493 |
<< " data size " << packet->GetSize ()); |
| 482 |
|
494 |
|
| 483 |
if(!tcpHeader.IsChecksumOk ()) |
495 |
if(!incomingTcpHeader.IsChecksumOk ()) |
| 484 |
{ |
496 |
{ |
| 485 |
NS_LOG_INFO ("Bad checksum, dropping packet!"); |
497 |
NS_LOG_INFO ("Bad checksum, dropping packet!"); |
| 486 |
return IpL4Protocol::RX_CSUM_FAILED; |
498 |
return IpL4Protocol::RX_CSUM_FAILED; |
|
Lines 488-521
TcpL4Protocol::Receive (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 488 |
|
500 |
|
| 489 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
501 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet"); |
| 490 |
Ipv6EndPointDemux::EndPoints endPoints = |
502 |
Ipv6EndPointDemux::EndPoints endPoints = |
| 491 |
m_endPoints6->Lookup (ipHeader.GetDestinationAddress (), tcpHeader.GetDestinationPort (), |
503 |
m_endPoints6->Lookup (incomingIpHeader.GetDestinationAddress (), incomingTcpHeader.GetDestinationPort (), |
| 492 |
ipHeader.GetSourceAddress (), tcpHeader.GetSourcePort (),interface); |
504 |
incomingIpHeader.GetSourceAddress (), incomingTcpHeader.GetSourcePort (),interface); |
| 493 |
if (endPoints.empty ()) |
505 |
if (endPoints.empty ()) |
| 494 |
{ |
506 |
{ |
| 495 |
NS_LOG_LOGIC (" No IPv6 endpoints matched on TcpL4Protocol "<<this); |
507 |
NS_LOG_LOGIC (" No IPv6 endpoints matched on TcpL4Protocol "<<this); |
| 496 |
NS_LOG_LOGIC (PrintIpInformation (ipHeader, tcpHeader)); |
508 |
NS_LOG_LOGIC (PrintIpInformation (incomingIpHeader, incomingTcpHeader)); |
| 497 |
|
509 |
|
| 498 |
if (!(tcpHeader.GetFlags () & TcpHeader::RST)) |
510 |
if (!(incomingTcpHeader.GetFlags () & TcpHeader::RST)) |
| 499 |
{ |
511 |
{ |
| 500 |
// build a RST packet and send |
512 |
// build a RST packet and send |
| 501 |
Ptr<Packet> rstPacket = Create<Packet> (); |
513 |
Ptr<Packet> rstPacket = Create<Packet> (); |
| 502 |
TcpHeader header; |
514 |
TcpHeader outgoingTcpHeader; |
| 503 |
if (tcpHeader.GetFlags () & TcpHeader::ACK) |
515 |
if (incomingTcpHeader.GetFlags () & TcpHeader::ACK) |
| 504 |
{ |
516 |
{ |
| 505 |
// ACK bit was set |
517 |
// ACK bit was set |
| 506 |
header.SetFlags (TcpHeader::RST); |
518 |
outgoingTcpHeader.SetFlags (TcpHeader::RST); |
| 507 |
header.SetSequenceNumber (header.GetAckNumber ()); |
519 |
outgoingTcpHeader.SetSequenceNumber (incomingTcpHeader.GetAckNumber ()); |
| 508 |
} |
520 |
} |
| 509 |
else |
521 |
else |
| 510 |
{ |
522 |
{ |
| 511 |
header.SetFlags (TcpHeader::RST | TcpHeader::ACK); |
523 |
outgoingTcpHeader.SetFlags (TcpHeader::RST | TcpHeader::ACK); |
| 512 |
header.SetSequenceNumber (SequenceNumber32 (0)); |
524 |
outgoingTcpHeader.SetSequenceNumber (SequenceNumber32 (0)); |
| 513 |
header.SetAckNumber (header.GetSequenceNumber () + SequenceNumber32 (1)); |
525 |
outgoingTcpHeader.SetAckNumber (incomingTcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
| 514 |
} |
526 |
} |
| 515 |
header.SetSourcePort (tcpHeader.GetDestinationPort ()); |
527 |
outgoingTcpHeader.SetSourcePort (incomingTcpHeader.GetDestinationPort ()); |
| 516 |
header.SetDestinationPort (tcpHeader.GetSourcePort ()); |
528 |
outgoingTcpHeader.SetDestinationPort (incomingTcpHeader.GetSourcePort ()); |
| 517 |
SendPacket (rstPacket, header, ipHeader.GetDestinationAddress (), |
529 |
SendPacket (rstPacket, outgoingTcpHeader, incomingIpHeader.GetDestinationAddress (), |
| 518 |
ipHeader.GetSourceAddress ()); |
530 |
incomingIpHeader.GetSourceAddress ()); |
| 519 |
return IpL4Protocol::RX_ENDPOINT_CLOSED; |
531 |
return IpL4Protocol::RX_ENDPOINT_CLOSED; |
| 520 |
} |
532 |
} |
| 521 |
else |
533 |
else |
|
Lines 525-531
TcpL4Protocol::Receive (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 525 |
} |
537 |
} |
| 526 |
NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint"); |
538 |
NS_ASSERT_MSG (endPoints.size () == 1, "Demux returned more than one endpoint"); |
| 527 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
539 |
NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket"); |
| 528 |
(*endPoints.begin ())->ForwardUp (packet, ipHeader, tcpHeader.GetSourcePort (), interface); |
540 |
(*endPoints.begin ())->ForwardUp (packet, incomingIpHeader, incomingTcpHeader.GetSourcePort (), interface); |
| 529 |
return IpL4Protocol::RX_OK; |
541 |
return IpL4Protocol::RX_OK; |
| 530 |
} |
542 |
} |
| 531 |
|
543 |
|