ns-3-simu_zebra_ipv6-2nd
diff src/process-manager/unix-datagram-socket-fd.cc @ 4775:fc2c29a13125
After support for TD/NINA on zebra-0.95
| author | tazaki@vmlinux-zak |
|---|---|
| date | Thu Oct 01 23:37:18 2009 +0900 (2 years ago) |
| parents | 6ac4aa4c80ca |
| children | fd1d8c5657a7 |
line diff
1.1 --- a/src/process-manager/unix-datagram-socket-fd.cc Mon Sep 07 13:50:18 2009 +0200
1.2 +++ b/src/process-manager/unix-datagram-socket-fd.cc Thu Oct 01 23:37:18 2009 +0900
1.3 @@ -6,7 +6,11 @@
1.4 #include "ns3/socket.h"
1.5 #include "ns3/packet.h"
1.6 #include "ns3/simulator.h"
1.7 +#include "ns3/node.h"
1.8 #include "ns3/inet-socket-address.h"
1.9 +#include "ns3/ipv6-raw-socket-impl.h"
1.10 +#include "ns3/ipv6.h"
1.11 +//#include "ns3/udp6-socket-impl.h"
1.12 #include "cmsg.h"
1.13 #include <errno.h>
1.14 #include <netinet/in.h>
1.15 @@ -130,7 +134,7 @@
1.16 }
1.17 else
1.18 {
1.19 - msg->msg_controllen = 0;
1.20 + // msg->msg_controllen = 0;
1.21 }
1.22
1.23 if (!WaitRecvDoSignal (flags & MSG_DONTWAIT))
1.24 @@ -151,6 +155,31 @@
1.25 return -1;
1.26 }
1.27 Ns3AddressToPosixAddress (from, (struct sockaddr*)msg->msg_name, &msg->msg_namelen);
1.28 +
1.29 + if(msg->msg_controllen > 0){
1.30 + Cmsg cmsg = Cmsg (msg);
1.31 + if (IsRecvPktInfo ())
1.32 + {
1.33 + struct in6_pktinfo pkt;
1.34 +
1.35 + SocketRecvIfTag tag;
1.36 + bool found;
1.37 + found = packet->FindFirstMatchingByteTag (tag);
1.38 + NS_ASSERT (found);
1.39 +
1.40 + Ptr<Node> node = current->process->manager->GetObject<Node> ();
1.41 + Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
1.42 + pkt.ipi6_ifindex = ipv6->GetInterfaceForDevice (node->GetDevice(tag.GetRecvIf ()));
1.43 + memcpy(&pkt.ipi6_addr, msg->msg_name, sizeof(pkt.ipi6_addr));
1.44 + cmsg.Add (SOL_IPV6, IPV6_PKTINFO, sizeof (struct in6_pktinfo), (const uint8_t*)&pkt);
1.45 +
1.46 + Ipv6Header hdr = Ipv6Header();
1.47 + packet->RemoveHeader (hdr);
1.48 + }
1.49 + cmsg.Finish ();
1.50 + }
1.51 +
1.52 +
1.53 // XXX: we ignore MSG_TRUNC for the return value.
1.54 NS_ASSERT (packet->GetSize () <= count);
1.55 memcpy (buf, packet->PeekData (), packet->GetSize ());
1.56 @@ -162,7 +191,42 @@
1.57 Thread *current = Current ();
1.58 NS_LOG_FUNCTION (this << current);
1.59 NS_ASSERT (current != 0);
1.60 + uint32_t old_ifindex = 0;
1.61
1.62 + // parse cmsg
1.63 + Cmsg cmsg = Cmsg ((struct msghdr *)msg);
1.64 + int level, type, len;
1.65 + uint8_t *data = NULL;
1.66 + if (cmsg.GetNext (&level, &type, &len, &data) == 0)
1.67 + {
1.68 + switch (type){
1.69 + case IPV6_PKTINFO:{
1.70 + struct in6_pktinfo *pktinfo = (struct in6_pktinfo *)data;
1.71 + if (len != sizeof(struct in6_pktinfo))
1.72 + break;
1.73 +
1.74 + // if(m_socket.GetTypeId().IsChildOf (Ipv6RawSocketImpl::GetTypeId ()))
1.75 + if(typeid(* PeekPointer(m_socket)) == typeid(Ipv6RawSocketImpl))
1.76 + {
1.77 + NS_LOG_INFO("sendmsg: set ifindex to " << pktinfo->ipi6_ifindex);
1.78 + old_ifindex = (dynamic_cast<Ipv6RawSocketImpl *>(PeekPointer(m_socket)))->GetIfIndex();
1.79 + (dynamic_cast<Ipv6RawSocketImpl *>(PeekPointer(m_socket)))->SetIfIndex(pktinfo->ipi6_ifindex);
1.80 + }
1.81 +#ifdef FIXME
1.82 + else if(typeid(* PeekPointer(m_socket)) == typeid(Udp6SocketImpl))
1.83 + {
1.84 + NS_LOG_INFO("sendmsg: set ifindex to " << pktinfo->ipi6_ifindex);
1.85 + old_ifindex = (dynamic_cast<Udp6SocketImpl *>(PeekPointer(m_socket)))->GetIfIndex();
1.86 + (dynamic_cast<Udp6SocketImpl *>(PeekPointer(m_socket)))->SetIfIndex(pktinfo->ipi6_ifindex);
1.87 + }
1.88 +#endif
1.89 + }break;
1.90 + default: {
1.91 + NS_LOG_INFO ("cmsg: Currently not supported");
1.92 + }break;
1.93 + }
1.94 + }
1.95 + cmsg.Finish ();
1.96
1.97 ssize_t retval = 0;
1.98 for (uint32_t i = 0; i < msg->msg_iovlen; ++i)
1.99 @@ -181,6 +245,18 @@
1.100 {
1.101 result = m_socket->Send (packet);
1.102 }
1.103 +
1.104 + if(typeid(* PeekPointer(m_socket)) == typeid(Ipv6RawSocketImpl))
1.105 + {
1.106 + (dynamic_cast<Ipv6RawSocketImpl *>(PeekPointer(m_socket)))->SetIfIndex(old_ifindex);
1.107 + }
1.108 +#ifdef FIXME
1.109 + else if(typeid(* PeekPointer(m_socket)) == typeid(Udp6SocketImpl))
1.110 + {
1.111 + (dynamic_cast<Udp6SocketImpl *>(PeekPointer(m_socket)))->SetIfIndex(old_ifindex);
1.112 + }
1.113 +#endif
1.114 +
1.115 if (result == -1)
1.116 {
1.117 current->err = ErrnoToSimuErrno ();
