author | Tommaso Pecorella <tommaso.pecorella@unifi.it> |
Wed, 20 Nov 2013 20:15:02 +0100 | |
changeset 10440 | 1e48ff9185f1 |
parent 10410 | 4d4eb8097fa3 |
child 10652 | dc18deba4502 |
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 |
||
10410
4d4eb8097fa3
doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
9710
diff
changeset
|
20 |
NS_OBJECT_ENSURE_REGISTERED (Ipv4RawSocketImpl) |
4d4eb8097fa3
doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents:
9710
diff
changeset
|
21 |
; |
3820 | 22 |
|
23 |
TypeId |
|
24 |
Ipv4RawSocketImpl::GetTypeId (void) |
|
25 |
{ |
|
26 |
static TypeId tid = TypeId ("ns3::Ipv4RawSocketImpl") |
|
27 |
.SetParent<Socket> () |
|
28 |
.AddAttribute ("Protocol", "Protocol number to match.", |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
29 |
UintegerValue (0), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
30 |
MakeUintegerAccessor (&Ipv4RawSocketImpl::m_protocol), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
31 |
MakeUintegerChecker<uint16_t> ()) |
3820 | 32 |
.AddAttribute ("IcmpFilter", |
7697
2a250bff1466
Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
7485
diff
changeset
|
33 |
"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
|
34 |
UintegerValue (0), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
35 |
MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
36 |
MakeUintegerChecker<uint32_t> ()) |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
37 |
// |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
38 |
// 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
|
39 |
// |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
40 |
// | IP_HDRINC on | off | |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
41 |
// ----------+---------------+-------------+- |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
42 |
// 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
|
43 |
// 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
|
44 |
// ----------+---------------+-------------+- |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
45 |
.AddAttribute ("IpHeaderInclude", |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
46 |
"Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).", |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
47 |
BooleanValue (false), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
48 |
MakeBooleanAccessor (&Ipv4RawSocketImpl::m_iphdrincl), |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
49 |
MakeBooleanChecker ()) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
50 |
; |
3820 | 51 |
return tid; |
52 |
} |
|
53 |
||
54 |
Ipv4RawSocketImpl::Ipv4RawSocketImpl () |
|
55 |
{ |
|
56 |
NS_LOG_FUNCTION (this); |
|
57 |
m_err = Socket::ERROR_NOTERROR; |
|
58 |
m_node = 0; |
|
59 |
m_src = Ipv4Address::GetAny (); |
|
60 |
m_dst = Ipv4Address::GetAny (); |
|
61 |
m_protocol = 0; |
|
62 |
m_shutdownSend = false; |
|
63 |
m_shutdownRecv = false; |
|
64 |
} |
|
65 |
||
66 |
void |
|
67 |
Ipv4RawSocketImpl::SetNode (Ptr<Node> node) |
|
68 |
{ |
|
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
69 |
NS_LOG_FUNCTION (this << node); |
3820 | 70 |
m_node = node; |
71 |
} |
|
72 |
||
73 |
void |
|
74 |
Ipv4RawSocketImpl::DoDispose (void) |
|
75 |
{ |
|
76 |
NS_LOG_FUNCTION (this); |
|
77 |
m_node = 0; |
|
78 |
Socket::DoDispose (); |
|
79 |
} |
|
80 |
||
81 |
enum Socket::SocketErrno |
|
82 |
Ipv4RawSocketImpl::GetErrno (void) const |
|
83 |
{ |
|
84 |
NS_LOG_FUNCTION (this); |
|
85 |
return m_err; |
|
86 |
} |
|
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
87 |
|
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
88 |
enum Socket::SocketType |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
89 |
Ipv4RawSocketImpl::GetSocketType (void) const |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
90 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
91 |
NS_LOG_FUNCTION (this); |
6692
591fb1aa0ca4
Avoid enum name collision in socket
Josh Pelkey <jpelkey@gatech.edu>
parents:
6689
diff
changeset
|
92 |
return NS3_SOCK_RAW; |
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
93 |
} |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6448
diff
changeset
|
94 |
|
3820 | 95 |
Ptr<Node> |
96 |
Ipv4RawSocketImpl::GetNode (void) const |
|
97 |
{ |
|
98 |
NS_LOG_FUNCTION (this); |
|
99 |
return m_node; |
|
100 |
} |
|
101 |
int |
|
102 |
Ipv4RawSocketImpl::Bind (const Address &address) |
|
103 |
{ |
|
104 |
NS_LOG_FUNCTION (this << address); |
|
105 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
106 |
{ |
|
107 |
m_err = Socket::ERROR_INVAL; |
|
108 |
return -1; |
|
109 |
} |
|
110 |
InetSocketAddress ad = InetSocketAddress::ConvertFrom (address); |
|
111 |
m_src = ad.GetIpv4 (); |
|
112 |
return 0; |
|
113 |
} |
|
114 |
int |
|
115 |
Ipv4RawSocketImpl::Bind (void) |
|
116 |
{ |
|
117 |
NS_LOG_FUNCTION (this); |
|
118 |
m_src = Ipv4Address::GetAny (); |
|
119 |
return 0; |
|
120 |
} |
|
121 |
int |
|
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
122 |
Ipv4RawSocketImpl::Bind6 (void) |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
123 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
124 |
NS_LOG_FUNCTION (this); |
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
125 |
return (-1); |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
126 |
} |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7697
diff
changeset
|
127 |
int |
3820 | 128 |
Ipv4RawSocketImpl::GetSockName (Address &address) const |
129 |
{ |
|
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
130 |
NS_LOG_FUNCTION (this << address); |
3820 | 131 |
address = InetSocketAddress (m_src, 0); |
132 |
return 0; |
|
133 |
} |
|
134 |
int |
|
135 |
Ipv4RawSocketImpl::Close (void) |
|
136 |
{ |
|
137 |
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
|
138 |
Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> (); |
3820 | 139 |
if (ipv4 != 0) |
140 |
{ |
|
141 |
ipv4->DeleteRawSocket (this); |
|
142 |
} |
|
143 |
return 0; |
|
144 |
} |
|
145 |
int |
|
146 |
Ipv4RawSocketImpl::ShutdownSend (void) |
|
147 |
{ |
|
148 |
NS_LOG_FUNCTION (this); |
|
149 |
m_shutdownSend = true; |
|
150 |
return 0; |
|
151 |
} |
|
152 |
int |
|
153 |
Ipv4RawSocketImpl::ShutdownRecv (void) |
|
154 |
{ |
|
155 |
NS_LOG_FUNCTION (this); |
|
156 |
m_shutdownRecv = true; |
|
157 |
return 0; |
|
158 |
} |
|
159 |
int |
|
160 |
Ipv4RawSocketImpl::Connect (const Address &address) |
|
161 |
{ |
|
162 |
NS_LOG_FUNCTION (this << address); |
|
163 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
164 |
{ |
|
165 |
m_err = Socket::ERROR_INVAL; |
|
166 |
return -1; |
|
167 |
} |
|
168 |
InetSocketAddress ad = InetSocketAddress::ConvertFrom (address); |
|
169 |
m_dst = ad.GetIpv4 (); |
|
170 |
return 0; |
|
171 |
} |
|
172 |
int |
|
173 |
Ipv4RawSocketImpl::Listen (void) |
|
174 |
{ |
|
175 |
NS_LOG_FUNCTION (this); |
|
176 |
m_err = Socket::ERROR_OPNOTSUPP; |
|
177 |
return -1; |
|
178 |
} |
|
179 |
uint32_t |
|
180 |
Ipv4RawSocketImpl::GetTxAvailable (void) const |
|
181 |
{ |
|
182 |
NS_LOG_FUNCTION (this); |
|
183 |
return 0xffffffff; |
|
184 |
} |
|
185 |
int |
|
186 |
Ipv4RawSocketImpl::Send (Ptr<Packet> p, uint32_t flags) |
|
187 |
{ |
|
188 |
NS_LOG_FUNCTION (this << p << flags); |
|
189 |
InetSocketAddress to = InetSocketAddress (m_dst, m_protocol); |
|
190 |
return SendTo (p, flags, to); |
|
191 |
} |
|
192 |
int |
|
193 |
Ipv4RawSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
194 |
const Address &toAddress) |
3820 | 195 |
{ |
196 |
NS_LOG_FUNCTION (this << p << flags << toAddress); |
|
197 |
if (!InetSocketAddress::IsMatchingType (toAddress)) |
|
198 |
{ |
|
199 |
m_err = Socket::ERROR_INVAL; |
|
200 |
return -1; |
|
201 |
} |
|
202 |
if (m_shutdownSend) |
|
203 |
{ |
|
204 |
return 0; |
|
205 |
} |
|
206 |
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
|
207 |
Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> (); |
3820 | 208 |
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
|
209 |
Ipv4Address src = m_src; |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
210 |
if (ipv4->GetRoutingProtocol ()) |
3820 | 211 |
{ |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
212 |
Ipv4Header header; |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
213 |
if (!m_iphdrincl) |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
214 |
{ |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
215 |
header.SetDestination (dst); |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
216 |
header.SetProtocol (m_protocol); |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
217 |
} |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
218 |
else |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
219 |
{ |
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
|
220 |
p->RemoveHeader (header); |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
221 |
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
|
222 |
src = header.GetSource (); |
6334
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
223 |
} |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
224 |
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
|
225 |
Ptr<Ipv4Route> route; |
5856
7fd20c798a7d
bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents:
5680
diff
changeset
|
226 |
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
|
227 |
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
|
228 |
{ |
6428
a3afed368709
update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6336
diff
changeset
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
} |
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
|
234 |
|
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
235 |
// 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
|
236 |
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
|
237 |
if (route != 0) |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
238 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
239 |
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
|
240 |
if (!m_iphdrincl) |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
241 |
{ |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
242 |
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
|
243 |
} |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
244 |
else |
c9373f264dfe
Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6333
diff
changeset
|
245 |
{ |
6723
fff5c512f345
bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents:
6692
diff
changeset
|
246 |
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
|
247 |
} |
6170
21c9ea05058b
bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6169
diff
changeset
|
248 |
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
|
249 |
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
|
250 |
return p->GetSize (); |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
251 |
} |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
252 |
else |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
253 |
{ |
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
254 |
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
|
255 |
return -1; |
4472
e20a31541404
src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4375
diff
changeset
|
256 |
} |
3820 | 257 |
} |
258 |
return 0; |
|
259 |
} |
|
260 |
uint32_t |
|
261 |
Ipv4RawSocketImpl::GetRxAvailable (void) const |
|
262 |
{ |
|
263 |
NS_LOG_FUNCTION (this); |
|
264 |
uint32_t rx = 0; |
|
265 |
for (std::list<Data>::const_iterator i = m_recv.begin (); i != m_recv.end (); ++i) |
|
266 |
{ |
|
267 |
rx += (i->packet)->GetSize (); |
|
268 |
} |
|
269 |
return rx; |
|
270 |
} |
|
271 |
Ptr<Packet> |
|
272 |
Ipv4RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags) |
|
273 |
{ |
|
274 |
NS_LOG_FUNCTION (this << maxSize << flags); |
|
275 |
Address tmp; |
|
276 |
return RecvFrom (maxSize, flags, tmp); |
|
277 |
} |
|
278 |
Ptr<Packet> |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
279 |
Ipv4RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
280 |
Address &fromAddress) |
3820 | 281 |
{ |
282 |
NS_LOG_FUNCTION (this << maxSize << flags << fromAddress); |
|
283 |
if (m_recv.empty ()) |
|
284 |
{ |
|
285 |
return 0; |
|
286 |
} |
|
287 |
struct Data data = m_recv.front (); |
|
288 |
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
|
289 |
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
|
290 |
fromAddress = inet; |
3820 | 291 |
if (data.packet->GetSize () > maxSize) |
292 |
{ |
|
293 |
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
|
294 |
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
|
295 |
{ |
c461f7a25895
Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6173
diff
changeset
|
296 |
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
|
297 |
} |
3820 | 298 |
m_recv.push_front (data); |
299 |
return first; |
|
300 |
} |
|
301 |
return data.packet; |
|
302 |
} |
|
303 |
||
304 |
void |
|
305 |
Ipv4RawSocketImpl::SetProtocol (uint16_t protocol) |
|
306 |
{ |
|
307 |
NS_LOG_FUNCTION (this << protocol); |
|
308 |
m_protocol = protocol; |
|
309 |
} |
|
310 |
||
311 |
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
|
312 |
Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4Interface> incomingInterface) |
3820 | 313 |
{ |
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
|
314 |
NS_LOG_FUNCTION (this << *p << ipHeader << incomingInterface); |
3820 | 315 |
if (m_shutdownRecv) |
5677 | 316 |
{ |
317 |
return false; |
|
318 |
} |
|
9147
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
319 |
|
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
320 |
Ptr<NetDevice> boundNetDevice = Socket::GetBoundNetDevice(); |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
321 |
if (boundNetDevice) |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
322 |
{ |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
323 |
if (boundNetDevice != incomingInterface->GetDevice()) |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
324 |
{ |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
325 |
return false; |
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 |
} |
e9af93287335
Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
8922
diff
changeset
|
328 |
|
5581
d74aff108ddc
AodvProtocol in progress, doesn't work
Pavel Boyko <boyko@iitp.ru>
parents:
4603
diff
changeset
|
329 |
NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst); |
3820 | 330 |
if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) && |
331 |
(m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) && |
|
332 |
ipHeader.GetProtocol () == m_protocol) |
|
333 |
{ |
|
5677 | 334 |
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
|
335 |
// Should check via getsockopt ().. |
7758
c678188af993
Replace references to m_recvpktinfo with method call IsRecvPktInfo()
frederic.urbani@inria.fr
parents:
7717
diff
changeset
|
336 |
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
|
337 |
{ |
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 |
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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
} |
5677 | 343 |
if (m_protocol == 1) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
344 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
345 |
Icmpv4Header icmpHeader; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
346 |
copy->PeekHeader (icmpHeader); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
347 |
uint8_t type = icmpHeader.GetType (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
348 |
if (type < 32 && |
7697
2a250bff1466
Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
7485
diff
changeset
|
349 |
((uint32_t(1) << type) & m_icmpFilter)) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
350 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
351 |
// filter out icmp packet. |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
352 |
return false; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
353 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
354 |
} |
5677 | 355 |
copy->AddHeader (ipHeader); |
356 |
struct Data data; |
|
357 |
data.packet = copy; |
|
358 |
data.fromIp = ipHeader.GetSource (); |
|
359 |
data.fromProtocol = ipHeader.GetProtocol (); |
|
360 |
m_recv.push_back (data); |
|
361 |
NotifyDataRecv (); |
|
362 |
return true; |
|
3820 | 363 |
} |
364 |
return false; |
|
365 |
} |
|
366 |
||
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
|
367 |
bool |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
368 |
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
|
369 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
370 |
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
|
371 |
if (!allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
372 |
{ |
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
|
373 |
return false; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
374 |
} |
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
|
375 |
return true; |
6437
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 |
|
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
378 |
bool |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
379 |
Ipv4RawSocketImpl::GetAllowBroadcast () const |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
380 |
{ |
9710
df21b904fce3
Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents:
9147
diff
changeset
|
381 |
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
|
382 |
return true; |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
383 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6428
diff
changeset
|
384 |
|
3820 | 385 |
} // namespace ns3 |