author | Brian Swenson <bswenson3@gatech.edu> |
Tue, 22 Apr 2014 11:52:55 -0400 | |
changeset 10694 | 4af272d94cfd |
parent 10652 | dc18deba4502 |
child 10968 | 2d29fee2b7b8 |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7256
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
6333
c461f7a25895
Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6173
diff
changeset
|
2 |
#include <netinet/in.h> |
7485
9bec9af5e3c8
make ns-3 compile on FreeBSD-8.2
Colin Perkins <csp@csperkins.org>
parents:
7385
diff
changeset
|
3 |
#include <sys/socket.h> |
9bec9af5e3c8
make ns-3 compile on FreeBSD-8.2
Colin Perkins <csp@csperkins.org>
parents:
7385
diff
changeset
|
4 |
#include <sys/types.h> |
3820 | 5 |
#include "ipv4-raw-socket-impl.h" |
6 |
#include "ipv4-l3-protocol.h" |
|
7 |
#include "icmpv4.h" |
|
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
8 |
#include "ns3/ipv4-packet-info-tag.h" |
3820 | 9 |
#include "ns3/inet-socket-address.h" |
10 |
#include "ns3/node.h" |
|
11 |
#include "ns3/packet.h" |
|
12 |
#include "ns3/uinteger.h" |
|
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
13 |
#include "ns3/boolean.h" |
3820 | 14 |
#include "ns3/log.h" |
15 |
||
16 |
NS_LOG_COMPONENT_DEFINE ("Ipv4RawSocketImpl"); |
|
17 |
||
18 |
namespace ns3 { |
|
19 |
||
10652
dc18deba4502
[doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
10410
diff
changeset
|
20 |
NS_OBJECT_ENSURE_REGISTERED (Ipv4RawSocketImpl); |
3820 | 21 |
|
22 |
TypeId |
|
23 |
Ipv4RawSocketImpl::GetTypeId (void) |
|
24 |
{ |
|
25 |
static TypeId tid = TypeId ("ns3::Ipv4RawSocketImpl") |
|
26 |
.SetParent<Socket> () |
|
27 |
.AddAttribute ("Protocol", "Protocol number to match.", |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
28 |
UintegerValue (0), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
29 |
MakeUintegerAccessor (&Ipv4RawSocketImpl::m_protocol), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
30 |
MakeUintegerChecker<uint16_t> ()) |
3820 | 31 |
.AddAttribute ("IcmpFilter", |
7697
2a250bff1466
Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
7485
diff
changeset
|
32 |
"Any icmp header whose type field matches a bit in this filter is dropped. Type must be less than 32.", |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
33 |
UintegerValue (0), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
34 |
MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
35 |
MakeUintegerChecker<uint32_t> ()) |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
36 |
// |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
37 |
// from raw (7), linux, returned length of Send/Recv should be |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
38 |
// |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
39 |
// | IP_HDRINC on | off | |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
40 |
// ----------+---------------+-------------+- |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
41 |
// Send(Ipv4)| hdr + payload | payload | |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
42 |
// Recv(Ipv4)| hdr + payload | hdr+payload | |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
43 |
// ----------+---------------+-------------+- |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
44 |
.AddAttribute ("IpHeaderInclude", |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
45 |
"Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).", |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
46 |
BooleanValue (false), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
47 |
MakeBooleanAccessor (&Ipv4RawSocketImpl::m_iphdrincl), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
48 |
MakeBooleanChecker ()) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
49 |
; |
3820 | 50 |
return tid; |
51 |
} |
|
52 |
||
53 |
Ipv4RawSocketImpl::Ipv4RawSocketImpl () |
|
54 |
{ |
|
55 |
NS_LOG_FUNCTION (this); |
|
56 |
m_err = Socket::ERROR_NOTERROR; |
|
57 |
m_node = 0; |
|
58 |
m_src = Ipv4Address::GetAny (); |
|
59 |
m_dst = Ipv4Address::GetAny (); |
|
60 |
m_protocol = 0; |
|
61 |
m_shutdownSend = false; |
|
62 |
m_shutdownRecv = false; |
|
63 |
} |
|
64 |
||
65 |
void |
|
66 |
Ipv4RawSocketImpl::SetNode (Ptr<Node> node) |
|
67 |
{ |
|
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
68 |
NS_LOG_FUNCTION (this << node); |
3820 | 69 |
m_node = node; |
70 |
} |
|
71 |
||
72 |
void |
|
73 |
Ipv4RawSocketImpl::DoDispose (void) |
|
74 |
{ |
|
75 |
NS_LOG_FUNCTION (this); |
|
76 |
m_node = 0; |
|
77 |
Socket::DoDispose (); |
|
78 |
} |
|
79 |
||
80 |
enum Socket::SocketErrno |
|
81 |
Ipv4RawSocketImpl::GetErrno (void) const |
|
82 |
{ |
|
83 |
NS_LOG_FUNCTION (this); |
|
84 |
return m_err; |
|
85 |
} |
|
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
86 |
|
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
87 |
enum Socket::SocketType |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
88 |
Ipv4RawSocketImpl::GetSocketType (void) const |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
89 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
90 |
NS_LOG_FUNCTION (this); |
6692
591fb1aa0ca4
Avoid enum name collision in socket
Josh Pelkey <jpelkey@gatech.edu>
parents:
6689
diff
changeset
|
91 |
return NS3_SOCK_RAW; |
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
92 |
} |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
93 |
|
3820 | 94 |
Ptr<Node> |
95 |
Ipv4RawSocketImpl::GetNode (void) const |
|
96 |
{ |
|
97 |
NS_LOG_FUNCTION (this); |
|
98 |
return m_node; |
|
99 |
} |
|
100 |
int |
|
101 |
Ipv4RawSocketImpl::Bind (const Address &address) |
|
102 |
{ |
|
103 |
NS_LOG_FUNCTION (this << address); |
|
104 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
105 |
{ |
|
106 |
m_err = Socket::ERROR_INVAL; |
|
107 |
return -1; |
|
108 |
} |
|
109 |
InetSocketAddress ad = InetSocketAddress::ConvertFrom (address); |
|
110 |
m_src = ad.GetIpv4 (); |
|
111 |
return 0; |
|
112 |
} |
|
113 |
int |
|
114 |
Ipv4RawSocketImpl::Bind (void) |
|
115 |
{ |
|
116 |
NS_LOG_FUNCTION (this); |
|
117 |
m_src = Ipv4Address::GetAny (); |
|
118 |
return 0; |
|
119 |
} |
|
120 |
int |
|
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
121 |
Ipv4RawSocketImpl::Bind6 (void) |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
122 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
123 |
NS_LOG_FUNCTION (this); |
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
124 |
return (-1); |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
125 |
} |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
126 |
int |
3820 | 127 |
Ipv4RawSocketImpl::GetSockName (Address &address) const |
128 |
{ |
|
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
129 |
NS_LOG_FUNCTION (this << address); |
3820 | 130 |
address = InetSocketAddress (m_src, 0); |
131 |
return 0; |
|
132 |
} |
|
133 |
int |
|
134 |
Ipv4RawSocketImpl::Close (void) |
|
135 |
{ |
|
136 |
NS_LOG_FUNCTION (this); |
|
8922
922350836734
Bug 1477: Click doesn't work with raw sockets
Lalith Suresh <suresh.lalith@gmail.com>
parents:
7758
diff
changeset
|
137 |
Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> (); |
3820 | 138 |
if (ipv4 != 0) |
139 |
{ |
|
140 |
ipv4->DeleteRawSocket (this); |
|
141 |
} |
|
142 |
return 0; |
|
143 |
} |
|
144 |
int |
|
145 |
Ipv4RawSocketImpl::ShutdownSend (void) |
|
146 |
{ |
|
147 |
NS_LOG_FUNCTION (this); |
|
148 |
m_shutdownSend = true; |
|
149 |
return 0; |
|
150 |
} |
|
151 |
int |
|
152 |
Ipv4RawSocketImpl::ShutdownRecv (void) |
|
153 |
{ |
|
154 |
NS_LOG_FUNCTION (this); |
|
155 |
m_shutdownRecv = true; |
|
156 |
return 0; |
|
157 |
} |
|
158 |
int |
|
159 |
Ipv4RawSocketImpl::Connect (const Address &address) |
|
160 |
{ |
|
161 |
NS_LOG_FUNCTION (this << address); |
|
162 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
163 |
{ |
|
164 |
m_err = Socket::ERROR_INVAL; |
|
165 |
return -1; |
|
166 |
} |
|
167 |
InetSocketAddress ad = InetSocketAddress::ConvertFrom (address); |
|
168 |
m_dst = ad.GetIpv4 (); |
|
169 |
return 0; |
|
170 |
} |
|
171 |
int |
|
172 |
Ipv4RawSocketImpl::Listen (void) |
|
173 |
{ |
|
174 |
NS_LOG_FUNCTION (this); |
|
175 |
m_err = Socket::ERROR_OPNOTSUPP; |
|
176 |
return -1; |
|
177 |
} |
|
178 |
uint32_t |
|
179 |
Ipv4RawSocketImpl::GetTxAvailable (void) const |
|
180 |
{ |
|
181 |
NS_LOG_FUNCTION (this); |
|
182 |
return 0xffffffff; |
|
183 |
} |
|
184 |
int |
|
185 |
Ipv4RawSocketImpl::Send (Ptr<Packet> p, uint32_t flags) |
|
186 |
{ |
|
187 |
NS_LOG_FUNCTION (this << p << flags); |
|
188 |
InetSocketAddress to = InetSocketAddress (m_dst, m_protocol); |
|
189 |
return SendTo (p, flags, to); |
|
190 |
} |
|
191 |
int |
|
192 |
Ipv4RawSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
193 |
const Address &toAddress) |
3820 | 194 |
{ |
195 |
NS_LOG_FUNCTION (this << p << flags << toAddress); |
|
196 |
if (!InetSocketAddress::IsMatchingType (toAddress)) |
|
197 |
{ |
|
198 |
m_err = Socket::ERROR_INVAL; |
|
199 |
return -1; |
|
200 |
} |
|
201 |
if (m_shutdownSend) |
|
202 |
{ |
|
203 |
return 0; |
|
204 |
} |
|
205 |
InetSocketAddress ad = InetSocketAddress::ConvertFrom (toAddress); |
|
8922
922350836734
Bug 1477: Click doesn't work with raw sockets
Lalith Suresh <suresh.lalith@gmail.com>
parents:
7758
diff
changeset
|
206 |
Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> (); |
3820 | 207 |
Ipv4Address dst = ad.GetIpv4 (); |
6428
a3afed368709
update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6336
diff
changeset
|
208 |
Ipv4Address src = m_src; |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
209 |
if (ipv4->GetRoutingProtocol ()) |
3820 | 210 |
{ |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
211 |
Ipv4Header header; |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
212 |
if (!m_iphdrincl) |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
213 |
{ |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
214 |
header.SetDestination (dst); |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
215 |
header.SetProtocol (m_protocol); |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
216 |
} |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
217 |
else |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
218 |
{ |
6336
464e8093700d
update Bug 932 (Support IP_HDRINCL option for Ipv4RawSocket) again: regarding w/ Tom's comments.
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6334
diff
changeset
|
219 |
p->RemoveHeader (header); |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
220 |
dst = header.GetDestination (); |
6428
a3afed368709
update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6336
diff
changeset
|
221 |
src = header.GetSource (); |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
222 |
} |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
223 |
SocketErrno errno_ = ERROR_NOTERROR; //do not use errno as it is the standard C last error number |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
224 |
Ptr<Ipv4Route> route; |
5856
7fd20c798a7d
bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents:
5680
diff
changeset
|
225 |
Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address |
6428
a3afed368709
update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6336
diff
changeset
|
226 |
if (!oif && src != Ipv4Address::GetAny ()) |
6173
6ff89f45451c
bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6170
diff
changeset
|
227 |
{ |
6428
a3afed368709
update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6336
diff
changeset
|
228 |
int32_t index = ipv4->GetInterfaceForAddress (src); |
6173
6ff89f45451c
bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6170
diff
changeset
|
229 |
NS_ASSERT (index >= 0); |
6ff89f45451c
bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6170
diff
changeset
|
230 |
oif = ipv4->GetNetDevice (index); |
6428
a3afed368709
update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6336
diff
changeset
|
231 |
NS_LOG_LOGIC ("Set index " << oif << "from source " << src); |
6173
6ff89f45451c
bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6170
diff
changeset
|
232 |
} |
6ff89f45451c
bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6170
diff
changeset
|
233 |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
234 |
// TBD-- we could cache the route and just check its validity |
4603
67a0a49c1db4
bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents:
4567
diff
changeset
|
235 |
route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
236 |
if (route != 0) |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
237 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
238 |
NS_LOG_LOGIC ("Route exists"); |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
239 |
if (!m_iphdrincl) |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
240 |
{ |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
241 |
ipv4->Send (p, route->GetSource (), dst, m_protocol, route); |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
242 |
} |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
243 |
else |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
244 |
{ |
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6692
diff
changeset
|
245 |
ipv4->SendWithHeader (p, header, route); |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
246 |
} |
6170
21c9ea05058b
bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6169
diff
changeset
|
247 |
NotifyDataSent (p->GetSize ()); |
21c9ea05058b
bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6169
diff
changeset
|
248 |
NotifySend (GetTxAvailable ()); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
249 |
return p->GetSize (); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
250 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
251 |
else |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
252 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
253 |
NS_LOG_DEBUG ("dropped because no outgoing route."); |
6170
21c9ea05058b
bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6169
diff
changeset
|
254 |
return -1; |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
255 |
} |
3820 | 256 |
} |
257 |
return 0; |
|
258 |
} |
|
259 |
uint32_t |
|
260 |
Ipv4RawSocketImpl::GetRxAvailable (void) const |
|
261 |
{ |
|
262 |
NS_LOG_FUNCTION (this); |
|
263 |
uint32_t rx = 0; |
|
264 |
for (std::list<Data>::const_iterator i = m_recv.begin (); i != m_recv.end (); ++i) |
|
265 |
{ |
|
266 |
rx += (i->packet)->GetSize (); |
|
267 |
} |
|
268 |
return rx; |
|
269 |
} |
|
270 |
Ptr<Packet> |
|
271 |
Ipv4RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags) |
|
272 |
{ |
|
273 |
NS_LOG_FUNCTION (this << maxSize << flags); |
|
274 |
Address tmp; |
|
275 |
return RecvFrom (maxSize, flags, tmp); |
|
276 |
} |
|
277 |
Ptr<Packet> |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
278 |
Ipv4RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
279 |
Address &fromAddress) |
3820 | 280 |
{ |
281 |
NS_LOG_FUNCTION (this << maxSize << flags << fromAddress); |
|
282 |
if (m_recv.empty ()) |
|
283 |
{ |
|
284 |
return 0; |
|
285 |
} |
|
286 |
struct Data data = m_recv.front (); |
|
287 |
m_recv.pop_front (); |
|
6169
bef40786d55b
bug 865: Ipv4RawSocketImpl::RecvFrom does not return from address all the time
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
5856
diff
changeset
|
288 |
InetSocketAddress inet = InetSocketAddress (data.fromIp, data.fromProtocol); |
bef40786d55b
bug 865: Ipv4RawSocketImpl::RecvFrom does not return from address all the time
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
5856
diff
changeset
|
289 |
fromAddress = inet; |
3820 | 290 |
if (data.packet->GetSize () > maxSize) |
291 |
{ |
|
292 |
Ptr<Packet> first = data.packet->CreateFragment (0, maxSize); |
|
6333
c461f7a25895
Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6173
diff
changeset
|
293 |
if (!(flags & MSG_PEEK)) |
c461f7a25895
Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6173
diff
changeset
|
294 |
{ |
c461f7a25895
Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6173
diff
changeset
|
295 |
data.packet->RemoveAtStart (maxSize); |
c461f7a25895
Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6173
diff
changeset
|
296 |
} |
3820 | 297 |
m_recv.push_front (data); |
298 |
return first; |
|
299 |
} |
|
300 |
return data.packet; |
|
301 |
} |
|
302 |
||
303 |
void |
|
304 |
Ipv4RawSocketImpl::SetProtocol (uint16_t protocol) |
|
305 |
{ |
|
306 |
NS_LOG_FUNCTION (this << protocol); |
|
307 |
m_protocol = protocol; |
|
308 |
} |
|
309 |
||
310 |
bool |
|
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
311 |
Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4Interface> incomingInterface) |
3820 | 312 |
{ |
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
313 |
NS_LOG_FUNCTION (this << *p << ipHeader << incomingInterface); |
3820 | 314 |
if (m_shutdownRecv) |
5677 | 315 |
{ |
316 |
return false; |
|
317 |
} |
|
9147
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
318 |
|
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
319 |
Ptr<NetDevice> boundNetDevice = Socket::GetBoundNetDevice(); |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
320 |
if (boundNetDevice) |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
321 |
{ |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
322 |
if (boundNetDevice != incomingInterface->GetDevice()) |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
323 |
{ |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
324 |
return false; |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
325 |
} |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
326 |
} |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
327 |
|
5581
d74aff108ddc
AodvProtocol in progress, doesn't work
Pavel Boyko <boyko@iitp.ru>
parents:
4603
diff
changeset
|
328 |
NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst); |
3820 | 329 |
if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) && |
330 |
(m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) && |
|
331 |
ipHeader.GetProtocol () == m_protocol) |
|
332 |
{ |
|
5677 | 333 |
Ptr<Packet> copy = p->Copy (); |
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
334 |
// Should check via getsockopt ().. |
7758
c678188af993
Replace references to m_recvpktinfo with method call IsRecvPktInfo()
frederic.urbani@inria.fr
parents:
7717
diff
changeset
|
335 |
if (IsRecvPktInfo ()) |
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
336 |
{ |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
337 |
Ipv4PacketInfoTag tag; |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
338 |
copy->RemovePacketTag (tag); |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
339 |
tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ()); |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
340 |
copy->AddPacketTag (tag); |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
341 |
} |
5677 | 342 |
if (m_protocol == 1) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
343 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
344 |
Icmpv4Header icmpHeader; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
345 |
copy->PeekHeader (icmpHeader); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
346 |
uint8_t type = icmpHeader.GetType (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
347 |
if (type < 32 && |
7697
2a250bff1466
Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
7485
diff
changeset
|
348 |
((uint32_t(1) << type) & m_icmpFilter)) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
349 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
350 |
// filter out icmp packet. |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
351 |
return false; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
352 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
353 |
} |
5677 | 354 |
copy->AddHeader (ipHeader); |
355 |
struct Data data; |
|
356 |
data.packet = copy; |
|
357 |
data.fromIp = ipHeader.GetSource (); |
|
358 |
data.fromProtocol = ipHeader.GetProtocol (); |
|
359 |
m_recv.push_back (data); |
|
360 |
NotifyDataRecv (); |
|
361 |
return true; |
|
3820 | 362 |
} |
363 |
return false; |
|
364 |
} |
|
365 |
||
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
366 |
bool |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
367 |
Ipv4RawSocketImpl::SetAllowBroadcast (bool allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
368 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
369 |
NS_LOG_FUNCTION (this << allowBroadcast); |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
370 |
if (!allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
371 |
{ |
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
372 |
return false; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
373 |
} |
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
374 |
return true; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
375 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
376 |
|
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
377 |
bool |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
378 |
Ipv4RawSocketImpl::GetAllowBroadcast () const |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
379 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
380 |
NS_LOG_FUNCTION (this); |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
381 |
return true; |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
382 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
383 |
|
3820 | 384 |
} // namespace ns3 |