|
Lines 180-188
UdpSocketImpl::FinishBind (void)
|
Link Here
|
|---|
|
| 180 |
bool done = false; |
180 |
bool done = false; |
| 181 |
if (m_endPoint != 0) |
181 |
if (m_endPoint != 0) |
| 182 |
{ |
182 |
{ |
| 183 |
m_endPoint->SetRxCallback (MakeCallback (&UdpSocketImpl::ForwardUp, Ptr<UdpSocketImpl> (this))); |
183 |
m_endPoint->SetRxCallback (MakeCallback (&UdpSocketImpl::ForwardUp, Ptr<UdpSocketImpl> (this))); |
| 184 |
m_endPoint->SetIcmpCallback (MakeCallback (&UdpSocketImpl::ForwardIcmp, Ptr<UdpSocketImpl> (this))); |
184 |
m_endPoint->SetIcmpCallback (MakeCallback (&UdpSocketImpl::ForwardIcmp, Ptr<UdpSocketImpl> (this))); |
| 185 |
m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocketImpl::Destroy, Ptr<UdpSocketImpl> (this))); |
185 |
m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocketImpl::Destroy, Ptr<UdpSocketImpl> (this))); |
| 186 |
done = true; |
186 |
done = true; |
| 187 |
} |
187 |
} |
| 188 |
if (m_endPoint6 != 0) |
188 |
if (m_endPoint6 != 0) |
|
Lines 194-201
UdpSocketImpl::FinishBind (void)
|
Link Here
|
|---|
|
| 194 |
} |
194 |
} |
| 195 |
if (done) |
195 |
if (done) |
| 196 |
{ |
196 |
{ |
| 197 |
return 0; |
197 |
return 0; |
| 198 |
} |
198 |
} |
| 199 |
return -1; |
199 |
return -1; |
| 200 |
} |
200 |
} |
| 201 |
|
201 |
|
|
Lines 207-213
UdpSocketImpl::Bind (void)
|
Link Here
|
|---|
|
| 207 |
return FinishBind (); |
207 |
return FinishBind (); |
| 208 |
} |
208 |
} |
| 209 |
|
209 |
|
| 210 |
int |
210 |
int |
| 211 |
UdpSocketImpl::Bind6 (void) |
211 |
UdpSocketImpl::Bind6 (void) |
| 212 |
{ |
212 |
{ |
| 213 |
NS_LOG_FUNCTION_NOARGS (); |
213 |
NS_LOG_FUNCTION_NOARGS (); |
|
Lines 222-246
UdpSocketImpl::Bind (const Address &address)
|
Link Here
|
|---|
|
| 222 |
|
222 |
|
| 223 |
if (InetSocketAddress::IsMatchingType (address)) |
223 |
if (InetSocketAddress::IsMatchingType (address)) |
| 224 |
{ |
224 |
{ |
| 225 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
225 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
| 226 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
226 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
| 227 |
uint16_t port = transport.GetPort (); |
227 |
uint16_t port = transport.GetPort (); |
| 228 |
if (ipv4 == Ipv4Address::GetAny () && port == 0) |
228 |
if (ipv4 == Ipv4Address::GetAny () && port == 0) |
| 229 |
{ |
229 |
{ |
| 230 |
m_endPoint = m_udp->Allocate (); |
230 |
m_endPoint = m_udp->Allocate (); |
| 231 |
} |
231 |
} |
| 232 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
232 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
| 233 |
{ |
233 |
{ |
| 234 |
m_endPoint = m_udp->Allocate (port); |
234 |
m_endPoint = m_udp->Allocate (port); |
| 235 |
} |
235 |
} |
| 236 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
236 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
| 237 |
{ |
237 |
{ |
| 238 |
m_endPoint = m_udp->Allocate (ipv4); |
238 |
m_endPoint = m_udp->Allocate (ipv4); |
| 239 |
} |
239 |
} |
| 240 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
240 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
| 241 |
{ |
241 |
{ |
| 242 |
m_endPoint = m_udp->Allocate (ipv4, port); |
242 |
m_endPoint = m_udp->Allocate (ipv4, port); |
| 243 |
} |
243 |
} |
| 244 |
} |
244 |
} |
| 245 |
else if (Inet6SocketAddress::IsMatchingType (address)) |
245 |
else if (Inet6SocketAddress::IsMatchingType (address)) |
| 246 |
{ |
246 |
{ |
|
Lines 310-320
UdpSocketImpl::Connect (const Address & address)
|
Link Here
|
|---|
|
| 310 |
NS_LOG_FUNCTION (this << address); |
310 |
NS_LOG_FUNCTION (this << address); |
| 311 |
if (InetSocketAddress::IsMatchingType(address) == true) |
311 |
if (InetSocketAddress::IsMatchingType(address) == true) |
| 312 |
{ |
312 |
{ |
| 313 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
313 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
| 314 |
m_defaultAddress = Address(transport.GetIpv4 ()); |
314 |
m_defaultAddress = Address(transport.GetIpv4 ()); |
| 315 |
m_defaultPort = transport.GetPort (); |
315 |
m_defaultPort = transport.GetPort (); |
| 316 |
m_connected = true; |
316 |
m_connected = true; |
| 317 |
NotifyConnectionSucceeded (); |
317 |
NotifyConnectionSucceeded (); |
| 318 |
} |
318 |
} |
| 319 |
else if (Inet6SocketAddress::IsMatchingType(address) == true) |
319 |
else if (Inet6SocketAddress::IsMatchingType(address) == true) |
| 320 |
{ |
320 |
{ |
|
Lines 393-403
UdpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
|
Link Here
|
|---|
|
| 393 |
NS_LOG_LOGIC ("Not connected"); |
393 |
NS_LOG_LOGIC ("Not connected"); |
| 394 |
if (InetSocketAddress::IsMatchingType(address) == true) |
394 |
if (InetSocketAddress::IsMatchingType(address) == true) |
| 395 |
{ |
395 |
{ |
| 396 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
396 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
| 397 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
397 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
| 398 |
uint16_t port = transport.GetPort (); |
398 |
uint16_t port = transport.GetPort (); |
| 399 |
return DoSendTo (p, ipv4, port); |
399 |
return DoSendTo (p, ipv4, port); |
| 400 |
} |
400 |
} |
| 401 |
else if (Inet6SocketAddress::IsMatchingType(address) == true) |
401 |
else if (Inet6SocketAddress::IsMatchingType(address) == true) |
| 402 |
{ |
402 |
{ |
| 403 |
Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); |
403 |
Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); |
|
Lines 405-412
UdpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
|
Link Here
|
|---|
|
| 405 |
uint16_t port = transport.GetPort (); |
405 |
uint16_t port = transport.GetPort (); |
| 406 |
return DoSendTo (p, ipv6, port); |
406 |
return DoSendTo (p, ipv6, port); |
| 407 |
} |
407 |
} |
| 408 |
else |
408 |
else |
| 409 |
{ |
409 |
{ |
| 410 |
return -1; |
410 |
return -1; |
| 411 |
} |
411 |
} |
| 412 |
} |
412 |
} |
|
Lines 417-427
UdpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
|
Link Here
|
|---|
|
| 417 |
if (Ipv4Address::IsMatchingType(m_defaultAddress)) |
417 |
if (Ipv4Address::IsMatchingType(m_defaultAddress)) |
| 418 |
{ |
418 |
{ |
| 419 |
return DoSendTo (p, Ipv4Address::ConvertFrom(m_defaultAddress), m_defaultPort); |
419 |
return DoSendTo (p, Ipv4Address::ConvertFrom(m_defaultAddress), m_defaultPort); |
| 420 |
} |
420 |
} |
| 421 |
else if (Ipv6Address::IsMatchingType(m_defaultAddress)) |
421 |
else if (Ipv6Address::IsMatchingType(m_defaultAddress)) |
| 422 |
{ |
422 |
{ |
| 423 |
return DoSendTo (p, Ipv6Address::ConvertFrom(m_defaultAddress), m_defaultPort); |
423 |
return DoSendTo (p, Ipv6Address::ConvertFrom(m_defaultAddress), m_defaultPort); |
| 424 |
} |
424 |
} |
| 425 |
} |
425 |
} |
| 426 |
m_errno = ERROR_AFNOSUPPORT; |
426 |
m_errno = ERROR_AFNOSUPPORT; |
| 427 |
return(-1); |
427 |
return(-1); |
|
Lines 468-495
UdpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address dest, uint16_t port)
|
Link Here
|
|---|
|
| 468 |
// the same as a unicast, but it will be fixed further down the stack |
468 |
// the same as a unicast, but it will be fixed further down the stack |
| 469 |
if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) |
469 |
if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) |
| 470 |
{ |
470 |
{ |
| 471 |
SocketIpTtlTag tag; |
471 |
Ptr<SocketIpTtlTag> tag = CreateObject<SocketIpTtlTag> (); |
| 472 |
tag.SetTtl (m_ipMulticastTtl); |
472 |
tag->SetTtl (m_ipMulticastTtl); |
| 473 |
p->AddPacketTag (tag); |
473 |
p->AddPacketTag (tag); |
| 474 |
} |
474 |
} |
| 475 |
else if (m_ipTtl != 0 && !dest.IsMulticast () && !dest.IsBroadcast ()) |
475 |
else if (m_ipTtl != 0 && !dest.IsMulticast () && !dest.IsBroadcast ()) |
| 476 |
{ |
476 |
{ |
| 477 |
SocketIpTtlTag tag; |
477 |
Ptr<SocketIpTtlTag> tag = CreateObject<SocketIpTtlTag> (); |
| 478 |
tag.SetTtl (m_ipTtl); |
478 |
tag->SetTtl (m_ipTtl); |
| 479 |
p->AddPacketTag (tag); |
479 |
p->AddPacketTag (tag); |
| 480 |
} |
480 |
} |
| 481 |
{ |
481 |
{ |
| 482 |
SocketSetDontFragmentTag tag; |
482 |
|
| 483 |
bool found = p->RemovePacketTag (tag); |
483 |
// !!! Previously, header was removed, checked, but never added back. Guess, this was wrong |
| 484 |
if (!found) |
484 |
if (p->PeekPacketTag<SocketSetDontFragmentTag> () == 0) |
| 485 |
{ |
485 |
{ |
|
|
486 |
Ptr<SocketSetDontFragmentTag> tag = CreateObject<SocketSetDontFragmentTag> (); |
| 486 |
if (m_mtuDiscover) |
487 |
if (m_mtuDiscover) |
| 487 |
{ |
488 |
{ |
| 488 |
tag.Enable (); |
489 |
tag->Enable (); |
| 489 |
} |
490 |
} |
| 490 |
else |
491 |
else |
| 491 |
{ |
492 |
{ |
| 492 |
tag.Disable (); |
493 |
tag->Disable (); |
| 493 |
} |
494 |
} |
| 494 |
p->AddPacketTag (tag); |
495 |
p->AddPacketTag (tag); |
| 495 |
} |
496 |
} |
|
Lines 656-669
UdpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv6Address dest, uint16_t port)
|
Link Here
|
|---|
|
| 656 |
// the same as a unicast, but it will be fixed further down the stack |
657 |
// the same as a unicast, but it will be fixed further down the stack |
| 657 |
if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) |
658 |
if (m_ipMulticastTtl != 0 && dest.IsMulticast ()) |
| 658 |
{ |
659 |
{ |
| 659 |
SocketIpTtlTag tag; |
660 |
Ptr<SocketIpTtlTag> tag = CreateObject<SocketIpTtlTag> (); |
| 660 |
tag.SetTtl (m_ipMulticastTtl); |
661 |
tag->SetTtl (m_ipMulticastTtl); |
| 661 |
p->AddPacketTag (tag); |
662 |
p->AddPacketTag (tag); |
| 662 |
} |
663 |
} |
| 663 |
else if (m_ipTtl != 0 && !dest.IsMulticast ()) |
664 |
else if (m_ipTtl != 0 && !dest.IsMulticast ()) |
| 664 |
{ |
665 |
{ |
| 665 |
SocketIpTtlTag tag; |
666 |
Ptr<SocketIpTtlTag> tag = CreateObject<SocketIpTtlTag> (); |
| 666 |
tag.SetTtl (m_ipTtl); |
667 |
tag->SetTtl (m_ipTtl); |
| 667 |
p->AddPacketTag (tag); |
668 |
p->AddPacketTag (tag); |
| 668 |
} |
669 |
} |
| 669 |
// There is no analgous to an IPv4 broadcast address in IPv6. |
670 |
// There is no analgous to an IPv4 broadcast address in IPv6. |
|
Lines 734-744
UdpSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address)
|
Link Here
|
|---|
|
| 734 |
NS_LOG_FUNCTION (this << p << flags << address); |
735 |
NS_LOG_FUNCTION (this << p << flags << address); |
| 735 |
if (InetSocketAddress::IsMatchingType (address)) |
736 |
if (InetSocketAddress::IsMatchingType (address)) |
| 736 |
{ |
737 |
{ |
| 737 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
738 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
| 738 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
739 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
| 739 |
uint16_t port = transport.GetPort (); |
740 |
uint16_t port = transport.GetPort (); |
| 740 |
return DoSendTo (p, ipv4, port); |
741 |
return DoSendTo (p, ipv4, port); |
| 741 |
} |
742 |
} |
| 742 |
else if (Inet6SocketAddress::IsMatchingType (address)) |
743 |
else if (Inet6SocketAddress::IsMatchingType (address)) |
| 743 |
{ |
744 |
{ |
| 744 |
Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); |
745 |
Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address); |
|
Lines 788-798
UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
Link Here
|
|---|
|
| 788 |
Ptr<Packet> packet = Recv (maxSize, flags); |
789 |
Ptr<Packet> packet = Recv (maxSize, flags); |
| 789 |
if (packet != 0) |
790 |
if (packet != 0) |
| 790 |
{ |
791 |
{ |
| 791 |
SocketAddressTag tag; |
792 |
Ptr<const SocketAddressTag> tag = packet->PeekPacketTag<SocketAddressTag> (); |
| 792 |
bool found; |
793 |
NS_ASSERT (tag != 0); |
| 793 |
found = packet->PeekPacketTag (tag); |
794 |
fromAddress = tag->GetAddress (); |
| 794 |
NS_ASSERT (found); |
|
|
| 795 |
fromAddress = tag.GetAddress (); |
| 796 |
} |
795 |
} |
| 797 |
return packet; |
796 |
return packet; |
| 798 |
} |
797 |
} |
|
Lines 874-890
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port,
|
Link Here
|
|---|
|
| 874 |
// Should check via getsockopt ().. |
873 |
// Should check via getsockopt ().. |
| 875 |
if (IsRecvPktInfo ()) |
874 |
if (IsRecvPktInfo ()) |
| 876 |
{ |
875 |
{ |
| 877 |
Ipv4PacketInfoTag tag; |
876 |
Ptr<const Ipv4PacketInfoTag> origTag = packet->RemovePacketTag<Ipv4PacketInfoTag> (); |
| 878 |
packet->RemovePacketTag (tag); |
877 |
Ptr<Ipv4PacketInfoTag> tag = CreateObject<Ipv4PacketInfoTag> (*origTag); |
| 879 |
tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); |
878 |
tag->SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); |
| 880 |
packet->AddPacketTag (tag); |
879 |
packet->AddPacketTag (tag); |
| 881 |
} |
880 |
} |
| 882 |
|
881 |
|
| 883 |
if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) |
882 |
if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) |
| 884 |
{ |
883 |
{ |
| 885 |
Address address = InetSocketAddress (header.GetSource (), port); |
884 |
Address address = InetSocketAddress (header.GetSource (), port); |
| 886 |
SocketAddressTag tag; |
885 |
Ptr<SocketAddressTag> tag = CreateObject<SocketAddressTag> (); |
| 887 |
tag.SetAddress (address); |
886 |
tag->SetAddress (address); |
| 888 |
packet->AddPacketTag (tag); |
887 |
packet->AddPacketTag (tag); |
| 889 |
m_deliveryQueue.push (packet); |
888 |
m_deliveryQueue.push (packet); |
| 890 |
m_rxAvailable += packet->GetSize (); |
889 |
m_rxAvailable += packet->GetSize (); |
|
Lines 902-908
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port,
|
Link Here
|
|---|
|
| 902 |
} |
901 |
} |
| 903 |
} |
902 |
} |
| 904 |
|
903 |
|
| 905 |
void |
904 |
void |
| 906 |
UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Address saddr, Ipv6Address daddr, uint16_t port) |
905 |
UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Address saddr, Ipv6Address daddr, uint16_t port) |
| 907 |
{ |
906 |
{ |
| 908 |
NS_LOG_FUNCTION (this << packet << saddr << port); |
907 |
NS_LOG_FUNCTION (this << packet << saddr << port); |
|
Lines 915-922
UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Address saddr, Ipv6Address da
|
Link Here
|
|---|
|
| 915 |
if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) |
914 |
if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) |
| 916 |
{ |
915 |
{ |
| 917 |
Address address = Inet6SocketAddress (saddr, port); |
916 |
Address address = Inet6SocketAddress (saddr, port); |
| 918 |
SocketAddressTag tag; |
917 |
Ptr<SocketAddressTag> tag = CreateObject<SocketAddressTag> (); |
| 919 |
tag.SetAddress (address); |
918 |
tag->SetAddress (address); |
| 920 |
packet->AddPacketTag (tag); |
919 |
packet->AddPacketTag (tag); |
| 921 |
m_deliveryQueue.push (packet); |
920 |
m_deliveryQueue.push (packet); |
| 922 |
m_rxAvailable += packet->GetSize (); |
921 |
m_rxAvailable += packet->GetSize (); |