author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Mon, 16 Aug 2010 08:30:29 -0700 | |
changeset 6576 | 29512368dd2e |
parent 6278 | ba09ab600218 |
child 6580 | ecb0f9a3849a |
permissions | -rw-r--r-- |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2008 University of Washington |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
*/ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
19 |
#include "emu-net-device.h" |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
20 |
#include "emu-encode-decode.h" |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "ns3/log.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
#include "ns3/queue.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
#include "ns3/simulator.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
#include "ns3/ethernet-header.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
#include "ns3/ethernet-trailer.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
#include "ns3/llc-snap-header.h" |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
28 |
#include "ns3/boolean.h" |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
29 |
#include "ns3/uinteger.h" |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
30 |
#include "ns3/pointer.h" |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
31 |
#include "ns3/string.h" |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
#include "ns3/trace-source-accessor.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
#include "ns3/channel.h" |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
#include "ns3/system-thread.h" |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
35 |
#include "ns3/mac48-address.h" |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
36 |
#include "ns3/enum.h" |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
38 |
#include <sys/wait.h> |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
39 |
#include <sys/stat.h> |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
#include <sys/socket.h> |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
41 |
#include <sys/un.h> |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
#include <sys/ioctl.h> |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
#include <net/ethernet.h> |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
#include <net/if.h> |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
#include <netinet/in.h> |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
#include <netpacket/packet.h> |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
#include <arpa/inet.h> |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
48 |
#include <errno.h> |
3851
cc6a7f93dc3f
g++ 4.3.2-1ubuntu7 too picky
Craig Dowell <craigdo@ee.washington.edu>
parents:
3850
diff
changeset
|
49 |
#include <limits> |
cc6a7f93dc3f
g++ 4.3.2-1ubuntu7 too picky
Craig Dowell <craigdo@ee.washington.edu>
parents:
3850
diff
changeset
|
50 |
#include <stdlib.h> |
6576
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
51 |
#include <time.h> |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
53 |
NS_LOG_COMPONENT_DEFINE ("EmuNetDevice"); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
namespace ns3 { |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
57 |
NS_OBJECT_ENSURE_REGISTERED (EmuNetDevice); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
|
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
59 |
#define EMU_MAGIC 65867 |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
60 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
TypeId |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
62 |
EmuNetDevice::GetTypeId (void) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
{ |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
64 |
static TypeId tid = TypeId ("ns3::EmuNetDevice") |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
.SetParent<NetDevice> () |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
66 |
.AddConstructor<EmuNetDevice> () |
6183
8a5e1f9db873
[bug 822] Move Mtu attribute from NetDevice base class to subclasses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6086
diff
changeset
|
67 |
.AddAttribute ("Mtu", "The MAC-level Maximum Transmission Unit", |
8a5e1f9db873
[bug 822] Move Mtu attribute from NetDevice base class to subclasses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6086
diff
changeset
|
68 |
UintegerValue (0), // arbitrary un-used value because no setter |
8a5e1f9db873
[bug 822] Move Mtu attribute from NetDevice base class to subclasses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6086
diff
changeset
|
69 |
MakeUintegerAccessor (&EmuNetDevice::GetMtu), |
8a5e1f9db873
[bug 822] Move Mtu attribute from NetDevice base class to subclasses
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
6086
diff
changeset
|
70 |
MakeUintegerChecker<uint16_t> ()) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
.AddAttribute ("Address", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
"The ns-3 MAC address of this (virtual) device.", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
74 |
MakeMac48AddressAccessor (&EmuNetDevice::m_address), |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
MakeMac48AddressChecker ()) |
4370
a64e987a727a
put DeviceName Attribute back in emu net device
Craig Dowell <craigdo@ee.washington.edu>
parents:
4322
diff
changeset
|
76 |
.AddAttribute ("DeviceName", |
a64e987a727a
put DeviceName Attribute back in emu net device
Craig Dowell <craigdo@ee.washington.edu>
parents:
4322
diff
changeset
|
77 |
"The name of the underlying real device (e.g. eth1).", |
a64e987a727a
put DeviceName Attribute back in emu net device
Craig Dowell <craigdo@ee.washington.edu>
parents:
4322
diff
changeset
|
78 |
StringValue ("eth1"), |
a64e987a727a
put DeviceName Attribute back in emu net device
Craig Dowell <craigdo@ee.washington.edu>
parents:
4322
diff
changeset
|
79 |
MakeStringAccessor (&EmuNetDevice::m_deviceName), |
a64e987a727a
put DeviceName Attribute back in emu net device
Craig Dowell <craigdo@ee.washington.edu>
parents:
4322
diff
changeset
|
80 |
MakeStringChecker ()) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
.AddAttribute ("Start", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
"The simulation time at which to spin up the device thread.", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
TimeValue (Seconds (0.)), |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
84 |
MakeTimeAccessor (&EmuNetDevice::m_tStart), |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
MakeTimeChecker ()) |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
.AddAttribute ("Stop", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
"The simulation time at which to tear down the device thread.", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
TimeValue (Seconds (0.)), |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
89 |
MakeTimeAccessor (&EmuNetDevice::m_tStop), |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
MakeTimeChecker ()) |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
91 |
.AddAttribute ("EncapsulationMode", |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
92 |
"The link-layer encapsulation type to use.", |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
93 |
EnumValue (LLC), |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
94 |
MakeEnumAccessor (&EmuNetDevice::SetEncapsulationMode), |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
95 |
MakeEnumChecker (DIX, "Dix", |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
96 |
LLC, "Llc")) |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
97 |
|
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
98 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
99 |
// Transmit queueing discipline for the device which includes its own set |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
100 |
// of trace hooks. Note that this is really going to run "on top of" the |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
101 |
// queueing discipline that will most likely be present in the devices of |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
102 |
// the underlying operating system. |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
103 |
// |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
.AddAttribute ("TxQueue", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
"A queue to use as the transmit queue in the device.", |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
PointerValue (), |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
107 |
MakePointerAccessor (&EmuNetDevice::m_queue), |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
MakePointerChecker<Queue> ()) |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
109 |
|
6576
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
110 |
.AddAttribute ("RxQueueSize", "Maximum size of the read queue. " |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
111 |
"This value limits number of packets that have been read " |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
112 |
"from the network into a memory buffer but have not yet " |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
113 |
"been processed by the simulator.", |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
114 |
UintegerValue (1000), |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
115 |
MakeUintegerAccessor (&EmuNetDevice::m_maxPendingReads), |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
116 |
MakeUintegerChecker<uint32_t> ()) |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
117 |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
118 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
119 |
// Trace sources at the "top" of the net device, where packets transition |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
120 |
// to/from higher layers. These points do not really correspond to the |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
121 |
// MAC layer of the underlying operating system, but exist to provide |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
122 |
// a consitent tracing environment. These trace hooks should really be |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
123 |
// interpreted as the points at which a packet leaves the ns-3 environment |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
124 |
// destined for the underlying operating system or vice-versa. |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
125 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
126 |
.AddTraceSource ("MacTx", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
127 |
"Trace source indicating a packet has arrived for transmission by this device", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
128 |
MakeTraceSourceAccessor (&EmuNetDevice::m_macTxTrace)) |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
129 |
.AddTraceSource ("MacTxDrop", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
130 |
"Trace source indicating a packet has been dropped by the device before transmission", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
131 |
MakeTraceSourceAccessor (&EmuNetDevice::m_macTxDropTrace)) |
4272
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
132 |
.AddTraceSource ("MacPromiscRx", |
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
133 |
"A packet has been received by this device, has been passed up from the physical layer " |
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
134 |
"and is being forwarded up the local protocol stack. This is a promiscuous trace,", |
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
135 |
MakeTraceSourceAccessor (&EmuNetDevice::m_macPromiscRxTrace)) |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
136 |
.AddTraceSource ("MacRx", |
4272
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
137 |
"A packet has been received by this device, has been passed up from the physical layer " |
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
138 |
"and is being forwarded up the local protocol stack. This is a non-promiscuous trace,", |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
139 |
MakeTraceSourceAccessor (&EmuNetDevice::m_macRxTrace)) |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
140 |
#if 0 |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
141 |
// Not currently implemented for this device |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
142 |
.AddTraceSource ("MacRxDrop", |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
143 |
"Trace source indicating a packet was dropped before being forwarded up the stack", |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
144 |
MakeTraceSourceAccessor (&EmuNetDevice::m_macRxDropTrace)) |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
145 |
#endif |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
146 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
147 |
// In normal ns-3 net devices, these trace souces correspond to the "bottom" |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
148 |
// of the net device, where packets transition to/from the channel. In |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
149 |
// the case of the emu device, there is no physical layer access -- all we |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
150 |
// do is to send packets to another device that is really at a "real" MAC |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
151 |
// level. Since it could be misleading to call anything here PHY, we do not |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
152 |
// implement these trace sources. |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
153 |
// |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
154 |
#if 0 |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
155 |
.AddTraceSource ("PhyTxBegin", |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
156 |
"Trace source indicating a packet has begun transmitting over the channel", |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
157 |
MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxBeginTrace)) |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
158 |
.AddTraceSource ("PhyTxEnd", |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
159 |
"Trace source indicating a packet has been completely transmitted over the channel", |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
160 |
MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxEndTrace)) |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
161 |
.AddTraceSource ("PhyTxDrop", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
162 |
"Trace source indicating a packet has been dropped by the device during transmission", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
163 |
MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxDropTrace)) |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
164 |
.AddTraceSource ("PhyRxBegin", |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
165 |
"Trace source indicating a packet has begun being received by the device", |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
166 |
MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxBeginTrace)) |
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
167 |
.AddTraceSource ("PhyRxEnd", |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
168 |
"Trace source indicating a packet has been completely received by the device", |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
169 |
MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxEndTrace)) |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
170 |
.AddTraceSource ("PhyRxDrop", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
171 |
"Trace source indicating a packet has been dropped by the device during reception", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
172 |
MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxDropTrace)) |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
173 |
#endif |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
174 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
175 |
// Trace sources designed to simulate a packet sniffer facility (tcpdump). |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
176 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
177 |
.AddTraceSource ("Sniffer", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
178 |
"Trace source simulating a non-promiscuous packet sniffer attached to the device", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
179 |
MakeTraceSourceAccessor (&EmuNetDevice::m_snifferTrace)) |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
180 |
.AddTraceSource ("PromiscSniffer", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
181 |
"Trace source simulating a promiscuous packet sniffer attached to the device", |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
182 |
MakeTraceSourceAccessor (&EmuNetDevice::m_promiscSnifferTrace)) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
return tid; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
186 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
187 |
EmuNetDevice::EmuNetDevice () |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
: |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
m_startEvent (), |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
m_stopEvent (), |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
m_sock (-1), |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
m_readThread (0), |
3850
03ebd59f4d06
keep gcc 3.4 from complaining
Craig Dowell <craigdo@ee.washington.edu>
parents:
3847
diff
changeset
|
193 |
m_ifIndex (std::numeric_limits<uint32_t>::max ()), // absurdly large value |
4479
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
194 |
m_sll_ifindex (-1), |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
195 |
m_isBroadcast (true), |
6576
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
196 |
m_isMulticast (false), |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
197 |
m_pendingReadCount (0) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
NS_LOG_FUNCTION (this); |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
200 |
m_packetBuffer = new uint8_t[65536]; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
201 |
Start (m_tStart); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
202 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
203 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
204 |
EmuNetDevice::~EmuNetDevice () |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
205 |
{ |
5829
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
206 |
delete [] m_packetBuffer; |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
207 |
m_packetBuffer = 0; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
209 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
210 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
211 |
EmuNetDevice::DoDispose() |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
212 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
213 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
214 |
m_node = 0; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
215 |
NetDevice::DoDispose (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
216 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
217 |
|
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
218 |
void |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
219 |
EmuNetDevice::SetEncapsulationMode (enum EncapsulationMode mode) |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
220 |
{ |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
221 |
NS_LOG_FUNCTION (mode); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
222 |
m_encapMode = mode; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
223 |
NS_LOG_LOGIC ("m_encapMode = " << m_encapMode); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
224 |
} |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
225 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
226 |
EmuNetDevice::EncapsulationMode |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
227 |
EmuNetDevice::GetEncapsulationMode (void) const |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
228 |
{ |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
229 |
NS_LOG_FUNCTION_NOARGS (); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
230 |
return m_encapMode; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
231 |
} |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
232 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
233 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
234 |
EmuNetDevice::Start (Time tStart) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
NS_LOG_FUNCTION (tStart); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
237 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
238 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
239 |
// Cancel any pending start event and schedule a new one at some relative time in the future. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
241 |
Simulator::Cancel (m_startEvent); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
242 |
m_startEvent = Simulator::Schedule (tStart, &EmuNetDevice::StartDevice, this); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
243 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
244 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
245 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
246 |
EmuNetDevice::Stop (Time tStop) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
NS_LOG_FUNCTION (tStop); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
250 |
// Cancel any pending stop event and schedule a new one at some relative time in the future. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
251 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
252 |
Simulator::Cancel (m_stopEvent); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
253 |
m_startEvent = Simulator::Schedule (tStop, &EmuNetDevice::StopDevice, this); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
254 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
255 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
256 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
257 |
EmuNetDevice::StartDevice (void) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
258 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
259 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
260 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
261 |
// |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
262 |
// Spin up the emu net device and start receiving packets. |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
263 |
// |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
264 |
if (m_sock != -1) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
265 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
266 |
NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Device is already started"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
267 |
} |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
268 |
|
5829
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
269 |
// |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
270 |
// We're going to need a pointer to the realtime simulator implementation. |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
271 |
// It's important to remember that access to that implementation may happen |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
272 |
// in a completely different thread than the simulator is running in (we're |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
273 |
// going to spin up that thread below). We are talking about multiple threads |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
274 |
// here, so it is very, very dangerous to do any kind of reference couning on |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
275 |
// a shared object that is unaware of what is happening. What we are going to |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
276 |
// do to address that is to get a reference to the realtime simulator here |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
277 |
// where we are running in the context of a running simulator scheduler -- |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
278 |
// recall we did a Simulator::Schedule of this method above. We get the |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
279 |
// simulator implementation pointer in a single-threaded way and save the |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
280 |
// underlying raw pointer for use by the (other) read thread. We must not |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
281 |
// free this pointer or we may delete the simulator out from under us an |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
282 |
// everyone else. We assume that the simulator implementation cannot be |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
283 |
// replaced while the emu device is running and so will remain valid through |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
284 |
// the time during which the read thread is running. |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
285 |
// |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
286 |
Ptr<RealtimeSimulatorImpl> impl = DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ()); |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
287 |
m_rtImpl = GetPointer (impl); |
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
288 |
|
6004
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
289 |
// |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
290 |
// A similar story exists for the node ID. We can't just naively do a |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
291 |
// GetNode ()->GetId () since GetNode is going to give us a Ptr<Node> which |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
292 |
// is reference counted. We need to stash away the node ID for use in the |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
293 |
// read thread. |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
294 |
// |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
295 |
m_nodeId = GetNode ()->GetId (); |
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
296 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
297 |
NS_LOG_LOGIC ("Creating socket"); |
5829
d3f02a8dee76
make tap-bridge work and add simpler example
Craig Dowell <craigdo@ee.washington.edu>
parents:
5822
diff
changeset
|
298 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
299 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
300 |
// Call out to a separate process running as suid root in order to get a raw |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
301 |
// socket. We do this to avoid having the entire simulation running as root. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
302 |
// If this method returns, we'll have a raw socket waiting for us in m_sock. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
303 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
304 |
CreateSocket (); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
305 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
306 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
307 |
// Figure out which interface index corresponds to the device name in the corresponding attribute. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
308 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
309 |
struct ifreq ifr; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
310 |
bzero (&ifr, sizeof(ifr)); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
311 |
strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
312 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
313 |
NS_LOG_LOGIC ("Getting interface index"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
314 |
int32_t rc = ioctl (m_sock, SIOCGIFINDEX, &ifr); |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
315 |
if (rc == -1) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
316 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
317 |
NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Can't get interface index"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
318 |
} |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
319 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
320 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
321 |
// Save the real interface index for later calls to sendto |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
322 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
323 |
m_sll_ifindex = ifr.ifr_ifindex; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
324 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
325 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
326 |
// Bind the socket to the interface we just found. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
327 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
328 |
struct sockaddr_ll ll; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
329 |
bzero (&ll, sizeof(ll)); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
330 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
331 |
ll.sll_family = AF_PACKET; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
332 |
ll.sll_ifindex = m_sll_ifindex; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
333 |
ll.sll_protocol = htons(ETH_P_ALL); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
334 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
335 |
NS_LOG_LOGIC ("Binding socket to interface"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
336 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
337 |
rc = bind (m_sock, (struct sockaddr *)&ll, sizeof (ll)); |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
338 |
if (rc == -1) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
339 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
340 |
NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Can't bind to specified interface"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
341 |
} |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
342 |
|
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
343 |
rc = ioctl(m_sock, SIOCGIFFLAGS, &ifr); |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
344 |
if (rc == -1) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
345 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
346 |
NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Can't get interface flags"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
347 |
} |
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
348 |
|
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
349 |
// |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
350 |
// This device only works if the underlying interface is up in promiscuous |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
351 |
// mode. We could have turned it on in the socket creator, but the situation |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
352 |
// is that we expect these devices to be used in conjunction with virtual |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
353 |
// machines with connected host-only (simulated) networks, or in a testbed. |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
354 |
// There is a lot of setup and configuration happening outside of this one |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
355 |
// issue, and we expect that configuration to include choosing a valid |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
356 |
// interface (e.g, "ath1"), ensuring that the device supports promiscuous |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
357 |
// mode, and placing it in promiscuous mode. We just make sure of the |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
358 |
// end result. |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
359 |
// |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
360 |
if ((ifr.ifr_flags & IFF_PROMISC) == 0) |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
361 |
{ |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
362 |
NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): " << m_deviceName << " is not in promiscuous mode"); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
363 |
} |
4479
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
364 |
if ((ifr.ifr_flags & IFF_BROADCAST) != IFF_BROADCAST) |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
365 |
{ |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
366 |
// We default m_isBroadcast to true but turn it off here if not |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
367 |
// supported, because in the common case, overlying IP code will |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
368 |
// assert during configuration time if this is false, before this |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
369 |
// method has a chance to set it during runtime |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
370 |
m_isBroadcast = false; |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
371 |
} |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
372 |
if ((ifr.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST) |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
373 |
{ |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
374 |
// This one is OK to enable at runtime |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
375 |
m_isMulticast = true; |
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
376 |
} |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
377 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
378 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
379 |
// Now spin up a read thread to read packets. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
380 |
// |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
381 |
if (m_readThread != 0) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
382 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
383 |
NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Receive thread is already running"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
384 |
} |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
385 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
386 |
NS_LOG_LOGIC ("Spinning up read thread"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
387 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
388 |
m_readThread = Create<SystemThread> (MakeCallback (&EmuNetDevice::ReadThread, this)); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
389 |
m_readThread->Start (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
390 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
391 |
NotifyLinkUp (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
392 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
393 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
394 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
395 |
EmuNetDevice::CreateSocket (void) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
396 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
397 |
NS_LOG_FUNCTION_NOARGS (); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
398 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
399 |
// We want to create a raw socket for our net device. Unfortunately for us |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
400 |
// you have to have root privileges to do that. Instead of running the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
401 |
// entire simulation as root, we decided to make a small program who's whole |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
402 |
// reason for being is to run as suid root and create a raw socket. We're |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
403 |
// going to fork and exec that program soon, but we need to have a socket |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
404 |
// to talk to it with. So we create a local interprocess (Unix) socket |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
405 |
// for that purpose. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
406 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
407 |
int sock = socket (PF_UNIX, SOCK_DGRAM, 0); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
408 |
if (sock == -1) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
409 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
410 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Unix socket creation error, errno = " << strerror (errno)); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
411 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
412 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
413 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
414 |
// Bind to that socket and let the kernel allocate an endpoint |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
415 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
416 |
struct sockaddr_un un; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
417 |
memset (&un, 0, sizeof (un)); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
418 |
un.sun_family = AF_UNIX; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
419 |
int status = bind (sock, (struct sockaddr*)&un, sizeof (sa_family_t)); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
420 |
if (status == -1) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
421 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
422 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Could not bind(): errno = " << strerror (errno)); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
423 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
424 |
|
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
425 |
NS_LOG_INFO ("Created Unix socket"); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
426 |
NS_LOG_INFO ("sun_family = " << un.sun_family); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
427 |
NS_LOG_INFO ("sun_path = " << un.sun_path); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
428 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
429 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
430 |
// We have a socket here, but we want to get it there -- to the program we're |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
431 |
// going to exec. What we'll do is to do a getsockname and then encode the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
432 |
// resulting address information as a string, and then send the string to the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
433 |
// program as an argument. So we need to get the sock name. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
434 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
435 |
socklen_t len = sizeof (un); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
436 |
status = getsockname (sock, (struct sockaddr*)&un, &len); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
437 |
if (status == -1) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
438 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
439 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Could not getsockname(): errno = " << strerror (errno)); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
440 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
441 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
442 |
// |
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
443 |
// Now encode that socket name (family and path) as a string of hex digits |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
444 |
// |
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
445 |
std::string path = EmuBufferToString((uint8_t *)&un, len); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
446 |
NS_LOG_INFO ("Encoded Unix socket as \"" << path << "\""); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
447 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
448 |
// Fork and exec the process to create our socket. If we're us (the parent) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
449 |
// we wait for the child (the socket creator) to complete and read the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
450 |
// socket it created using the ancillary data mechanism. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
451 |
// |
6086 | 452 |
// Tom Goff reports the possiblility of a deadlock when trying to acquire the |
453 |
// python GIL here. He says that this might be due to trying to access Python |
|
454 |
// objects after fork() without calling PyOS_AfterFork() to properly reset |
|
455 |
// Python state (including the GIL). There is no code to cause the problem |
|
456 |
// here in emu, but this was visible in similar code in tap-bridge. |
|
457 |
// |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
458 |
pid_t pid = ::fork (); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
459 |
if (pid == 0) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
460 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
461 |
NS_LOG_DEBUG ("Child process"); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
462 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
463 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
464 |
// build a command line argument from the encoded endpoint string that |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
465 |
// the socket creation process will use to figure out how to respond to |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
466 |
// the (now) parent process. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
467 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
468 |
std::ostringstream oss; |
3835
8966e68809a6
turn off LOG in emu-sock-creator
Craig Dowell <craigdo@ee.washington.edu>
parents:
3831
diff
changeset
|
469 |
oss << "-p" << path; |
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
470 |
NS_LOG_INFO ("Parameters set to \"" << oss.str () << "\""); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
471 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
472 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
473 |
// Execute the socket creation process image. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
474 |
// |
5975
c85cb9b073a0
comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents:
5834
diff
changeset
|
475 |
status = ::execlp ("emu-sock-creator", |
4417
973e0e873127
expand emu search for creator, don't check FCS
Craig Dowell <craigdo@ee.washington.edu>
parents:
4370
diff
changeset
|
476 |
"emu-sock-creator", // argv[0] (filename) |
973e0e873127
expand emu search for creator, don't check FCS
Craig Dowell <craigdo@ee.washington.edu>
parents:
4370
diff
changeset
|
477 |
oss.str ().c_str (), // argv[1] (-p<path? |
973e0e873127
expand emu search for creator, don't check FCS
Craig Dowell <craigdo@ee.washington.edu>
parents:
4370
diff
changeset
|
478 |
(char *)NULL); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
479 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
480 |
// |
5975
c85cb9b073a0
comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents:
5834
diff
changeset
|
481 |
// If the execlp successfully completes, it never returns. If it returns it failed or the OS is |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
482 |
// broken. In either case, we bail. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
483 |
// |
5975
c85cb9b073a0
comparing with http://code.nsnam.org/ns-3-dev
Craig Dowell <craigdo@ee.washington.edu>
parents:
5834
diff
changeset
|
484 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Back from execlp(), errno = " << ::strerror (errno)); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
485 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
486 |
else |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
487 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
488 |
NS_LOG_DEBUG ("Parent process"); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
489 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
490 |
// We're the process running the emu net device. We need to wait for the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
491 |
// socket creator process to finish its job. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
492 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
493 |
int st; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
494 |
pid_t waited = waitpid (pid, &st, 0); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
495 |
if (waited == -1) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
496 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
497 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): waitpid() fails, errno = " << strerror (errno)); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
498 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
499 |
NS_ASSERT_MSG (pid == waited, "EmuNetDevice::CreateSocket(): pid mismatch"); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
500 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
501 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
502 |
// Check to see if the socket creator exited normally and then take a |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
503 |
// look at the exit code. If it bailed, so should we. If it didn't |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
504 |
// even exit normally, we bail too. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
505 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
506 |
if (WIFEXITED (st)) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
507 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
508 |
int exitStatus = WEXITSTATUS (st); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
509 |
if (exitStatus != 0) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
510 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
511 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): socket creator exited normally with status " << exitStatus); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
512 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
513 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
514 |
else |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
515 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
516 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): socket creator exited abnormally"); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
517 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
518 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
519 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
520 |
// At this point, the socket creator has run successfully and should |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
521 |
// have created our raw socket and sent it back to the socket address |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
522 |
// we provided. Our socket should be waiting on the Unix socket. We've |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
523 |
// got to do a bunch of grunto work to get at it, though. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
524 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
525 |
// The struct iovec below is part of a scatter-gather list. It describes a |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
526 |
// buffer. In this case, it describes a buffer (an integer) that will |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
527 |
// get the data that comes back from the socket creator process. It will |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
528 |
// be a magic number that we use as a consistency/sanity check. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
529 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
530 |
struct iovec iov; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
531 |
uint32_t magic; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
532 |
iov.iov_base = &magic; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
533 |
iov.iov_len = sizeof(magic); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
534 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
535 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
536 |
// The CMSG macros you'll see below are used to create and access control |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
537 |
// messages (which is another name for ancillary data). The ancillary |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
538 |
// data is made up of pairs of struct cmsghdr structures and associated |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
539 |
// data arrays. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
540 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
541 |
// First, we're going to allocate a buffer on the stack to receive our |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
542 |
// data array (that contains the socket). Sometimes you'll see this called |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
543 |
// an "ancillary element" but the msghdr uses the control message termimology |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
544 |
// so we call it "control." |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
545 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
546 |
size_t msg_size = sizeof(int); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
547 |
char control[CMSG_SPACE(msg_size)]; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
548 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
549 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
550 |
// There is a msghdr that is used to minimize the number of parameters |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
551 |
// passed to recvmsg (which we will use to receive our ancillary data). |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
552 |
// This structure uses terminology corresponding to control messages, so |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
553 |
// you'll see msg_control, which is the pointer to the ancillary data and |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
554 |
// controllen which is the size of the ancillary data array. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
555 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
556 |
// So, initialize the message header that describes the ancillary/control |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
557 |
// data we expect to receive and point it to buffer. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
558 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
559 |
struct msghdr msg; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
560 |
msg.msg_name = 0; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
561 |
msg.msg_namelen = 0; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
562 |
msg.msg_iov = &iov; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
563 |
msg.msg_iovlen = 1; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
564 |
msg.msg_control = control; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
565 |
msg.msg_controllen = sizeof (control); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
566 |
msg.msg_flags = 0; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
567 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
568 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
569 |
// Now we can actually receive the interesting bits from the socket |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
570 |
// creator process. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
571 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
572 |
ssize_t bytesRead = recvmsg (sock, &msg, 0); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
573 |
if (bytesRead != sizeof(int)) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
574 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
575 |
NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Wrong byte count from socket creator"); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
576 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
577 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
578 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
579 |
// There may be a number of message headers/ancillary data arrays coming in. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
580 |
// Let's look for the one with a type SCM_RIGHTS which indicates it' the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
581 |
// one we're interested in. |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
582 |
// |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
583 |
struct cmsghdr *cmsg; |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
584 |
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
585 |
{ |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
586 |
if (cmsg->cmsg_level == SOL_SOCKET && |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
587 |
cmsg->cmsg_type == SCM_RIGHTS) |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
588 |
{ |
3831
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
589 |
// |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
590 |
// This is the type of message we want. Check to see if the magic |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
591 |
// number is correct and then pull out the socket we care about if |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
592 |
// it matches |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
593 |
// |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
594 |
if (magic == EMU_MAGIC) |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
595 |
{ |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
596 |
NS_LOG_INFO ("Got SCM_RIGHTS with correct magic " << magic); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
597 |
int *rawSocket = (int*)CMSG_DATA (cmsg); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
598 |
NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
599 |
m_sock = *rawSocket; |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
600 |
return; |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
601 |
} |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
602 |
else |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
603 |
{ |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
604 |
NS_LOG_INFO ("Got SCM_RIGHTS, but with bad magic " << magic); |
16c2970a0344
add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3830
diff
changeset
|
605 |
} |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
606 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
607 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
608 |
NS_FATAL_ERROR ("Did not get the raw socket from the socket creator"); |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
609 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
610 |
} |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
611 |
|
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
612 |
void |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
613 |
EmuNetDevice::StopDevice (void) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
614 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
615 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
616 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
617 |
close (m_sock); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
618 |
m_sock = -1; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
619 |
|
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
620 |
NS_ASSERT_MSG (m_readThread != 0, "EmuNetDevice::StopDevice(): Receive thread is not running"); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
621 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
622 |
NS_LOG_LOGIC ("Joining read thread"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
623 |
m_readThread->Join (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
624 |
m_readThread = 0; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
625 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
626 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
627 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
628 |
EmuNetDevice::ForwardUp (uint8_t *buf, uint32_t len) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
629 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
630 |
NS_LOG_FUNCTION (buf << len); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
631 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
632 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
633 |
// Create a packet out of the buffer we received and free that buffer. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
634 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
635 |
Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
636 |
free (buf); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
637 |
buf = 0; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
638 |
|
6576
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
639 |
{ |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
640 |
CriticalSection cs (m_pendingReadMutex); |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
641 |
//std::cerr << std::endl << "EmuNetDevice main thread: m_pendingReadCount is " << m_pendingReadCount << std::endl; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
642 |
--m_pendingReadCount; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
643 |
} |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
644 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
645 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
646 |
// Trace sinks will expect complete packets, not packets without some of the |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
647 |
// headers. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
648 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
649 |
Ptr<Packet> originalPacket = packet->Copy (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
650 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
651 |
EthernetHeader header (false); |
4676
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
652 |
|
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
653 |
// |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
654 |
// This device could be running in an environment where completely unexpected |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
655 |
// kinds of packets are flying around, so we need to harden things a bit and |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
656 |
// filter out packets we think are completely bogus, so we always check to see |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
657 |
// that the packet is long enough to contain the header we want to remove. |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
658 |
// |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
659 |
if (packet->GetSize() < header.GetSerializedSize()) |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
660 |
{ |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
661 |
m_phyRxDropTrace (originalPacket); |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
662 |
return; |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
663 |
} |
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
664 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
665 |
packet->RemoveHeader (header); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
666 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
667 |
NS_LOG_LOGIC ("Pkt source is " << header.GetSource ()); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
668 |
NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ()); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
669 |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
670 |
uint16_t protocol; |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
671 |
|
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
672 |
switch (m_encapMode) |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
673 |
{ |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
674 |
case LLC: |
4676
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
675 |
// |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
676 |
// If the length/type is less than 1500, it corresponds to a length |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
677 |
// interpretation packet. In this case, it is an 802.3 packet and |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
678 |
// will also have an 802.2 LLC header. If greater than 1500, we |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
679 |
// find the protocol number (Ethernet type) directly. |
4676
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
680 |
// |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
681 |
if (header.GetLengthType () <= 1500) |
4676
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
682 |
{ |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
683 |
LlcSnapHeader llc; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
684 |
// |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
685 |
// Check to see that the packet is long enough to possibly contain the |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
686 |
// header we want to remove before just naively calling. |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
687 |
// |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
688 |
if (packet->GetSize() < llc.GetSerializedSize()) |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
689 |
{ |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
690 |
m_phyRxDropTrace (originalPacket); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
691 |
return; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
692 |
} |
4676
45d880dbe0f8
harden emu net device against malformed packets
Craig Dowell <craigdo@ee.washington.edu>
parents:
4578
diff
changeset
|
693 |
|
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
694 |
packet->RemoveHeader (llc); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
695 |
protocol = llc.GetType (); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
696 |
} |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
697 |
else |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
698 |
{ |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
699 |
protocol = header.GetLengthType (); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
700 |
} |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
701 |
break; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
702 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
703 |
case DIX: |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
704 |
protocol = header.GetLengthType (); |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
705 |
break; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
706 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
707 |
default: |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
708 |
NS_FATAL_ERROR ("invalid encapsulation mode"); |
5834 | 709 |
protocol = 0; /* quiet compiler */ |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
710 |
} |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
711 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
712 |
PacketType packetType; |
4424
af26433b13bc
remove Mac48Address::IsMulticast
Fabian Mauchle <f1mauchl@hsr.ch>
parents:
4417
diff
changeset
|
713 |
|
3842
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
714 |
if (header.GetDestination ().IsBroadcast ()) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
715 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
716 |
packetType = NS3_PACKET_BROADCAST; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
717 |
} |
4424
af26433b13bc
remove Mac48Address::IsMulticast
Fabian Mauchle <f1mauchl@hsr.ch>
parents:
4417
diff
changeset
|
718 |
else if (header.GetDestination ().IsGroup ()) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
719 |
{ |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
720 |
packetType = NS3_PACKET_MULTICAST; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
721 |
} |
3842
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
722 |
else if (header.GetDestination () == m_address) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
723 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
724 |
packetType = NS3_PACKET_HOST; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
725 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
726 |
else |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
727 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
728 |
packetType = NS3_PACKET_OTHERHOST; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
729 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
730 |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
731 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
732 |
// For all kinds of packetType we receive, we hit the promiscuous sniffer |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
733 |
// hook and pass a copy up to the promiscuous callback. Pass a copy to |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
734 |
// make sure that nobody messes with our packet. |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
735 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
736 |
m_promiscSnifferTrace (originalPacket); |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4263
diff
changeset
|
737 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
738 |
if (!m_promiscRxCallback.IsNull ()) |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
739 |
{ |
4272
b40ce56e0247
Add MacPromiscRx, make MacRx non-promisc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4265
diff
changeset
|
740 |
m_macPromiscRxTrace (originalPacket); |
4265
5f837915710a
remove unneeded packet copies, includes. Rescan
Craig Dowell <craigdo@ee.washington.edu>
parents:
4264
diff
changeset
|
741 |
m_promiscRxCallback (this, packet, protocol, header.GetSource (), header.GetDestination (), packetType); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
742 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
743 |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
744 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
745 |
// If this packet is not destined for some other host, it must be for us |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
746 |
// as either a broadcast, multicast or unicast. We need to hit the mac |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
747 |
// packet received trace hook and forward the packet up the stack. |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
748 |
// |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
749 |
if (packetType != NS3_PACKET_OTHERHOST) |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
750 |
{ |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
751 |
m_snifferTrace (originalPacket); |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
752 |
m_macRxTrace (originalPacket); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
753 |
m_rxCallback (this, packet, protocol, header.GetSource ()); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
754 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
755 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
756 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
757 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
758 |
EmuNetDevice::ReadThread (void) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
759 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
760 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
761 |
|
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
762 |
// It's important to remember that we're in a completely different thread than the simulator is running in. |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
763 |
// We are talking about multiple threads here, so it is very, very dangerous to do any kind of reference couning |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
764 |
// on a shared object. |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
765 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
766 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
767 |
int32_t len = -1; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
768 |
struct sockaddr_ll addr; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
769 |
socklen_t addrSize = sizeof (addr); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
770 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
771 |
for (;;) |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
772 |
{ |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
773 |
// |
6576
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
774 |
// Too many pending reads at the same time leads to excessive memory allocations. This counter prevents it. |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
775 |
// |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
776 |
bool skip = false; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
777 |
|
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
778 |
{ |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
779 |
CriticalSection cs (m_pendingReadMutex); |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
780 |
//std::cerr << std::endl << "EmuNetDevice read thread: m_pendingReadCount is " << m_pendingReadCount << std::endl; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
781 |
if (m_pendingReadCount >= m_maxPendingReads) |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
782 |
{ |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
783 |
skip = true; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
784 |
} |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
785 |
else |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
786 |
{ |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
787 |
++m_pendingReadCount; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
788 |
} |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
789 |
} |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
790 |
|
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
791 |
if (skip) |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
792 |
{ |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
793 |
struct timespec time = { 0, 100000000L }; // 100 ms |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
794 |
nanosleep (&time, NULL); |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
795 |
continue; |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
796 |
} |
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
797 |
|
29512368dd2e
bug 939: EmuNetDevice uses too much memory
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6278
diff
changeset
|
798 |
// |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
799 |
// to avoid any issues with a shared reference counted packet, we allocate a buffer on the heap and pass that |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
800 |
// buffer into the ns-3 context thread where it will create the packet, copy the buffer and then free it. |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
801 |
// |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
802 |
uint32_t bufferSize = 65536; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
803 |
uint8_t *buf = (uint8_t *)malloc (bufferSize); |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
804 |
if (buf == 0) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
805 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
806 |
NS_FATAL_ERROR ("EmuNetDevice::ReadThread(): malloc packet buffer failed"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
807 |
} |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
808 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
809 |
NS_LOG_LOGIC ("Calling recvfrom"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
810 |
len = recvfrom (m_sock, buf, bufferSize, 0, (struct sockaddr *)&addr, &addrSize); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
811 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
812 |
if (len == -1) |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
813 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
814 |
free (buf); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
815 |
buf = 0; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
816 |
return; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
817 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
818 |
|
6004
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
819 |
NS_LOG_INFO ("EmuNetDevice::EmuNetDevice(): Received packet on node " << m_nodeId); |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
820 |
NS_LOG_INFO ("EmuNetDevice::ReadThread(): Scheduling handler"); |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
821 |
NS_ASSERT_MSG (m_rtImpl, "EmuNetDevice::ReadThread(): Realtime simulator implementation pointer not set"); |
6004
2ab92cdbaafa
GetNode is bad in multithreaded devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
5975
diff
changeset
|
822 |
m_rtImpl->ScheduleRealtimeNowWithContext (m_nodeId, MakeEvent (&EmuNetDevice::ForwardUp, this, buf, len)); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
823 |
buf = 0; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
824 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
825 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
826 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
827 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
828 |
EmuNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
829 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
830 |
NS_LOG_FUNCTION (packet << dest << protocolNumber); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
831 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
832 |
// The immediate questions here are how are we going to encapsulate packets and what do we use as the MAC source and |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
833 |
// destination (hardware) addresses? |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
834 |
// |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
835 |
// If we return false from EmuNetDevice::NeedsArp, the ArpIpv4Interface will pass the broadcast address as the |
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
836 |
// hardware (Ethernet) destination by default. If we return true from EmuNetDevice::NeedsArp, then the hardware |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
837 |
// destination is actually meaningful, but we'll have an ns-3 ARP running on this device. There can also be an ARP |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
838 |
// running on the underlying OS so we have to be very careful, both about multiple ARPs and also about TCP, UDP, etc. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
839 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
840 |
// We are operating in promiscuous mode on the receive side (all ns-3 net devices are required to implement the |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
841 |
// promiscuous callback in a meaningful way), so we have an option regarding the hardware addresses. We don't actually have |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
842 |
// to use the real hardware addresses and IP addresses of the underlying system. We can completely use MAC-spoofing to |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
843 |
// fake out the OS by using the ns-3 assigned MAC address (and also the ns-3 assigned IP addresses). Ns-3 starts its |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
844 |
// MAC address allocation using the OUI (vendor-code) 00:00:00 which is unassigned to any organization and is a globally |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
845 |
// administered address, so there shouldn't be any collisions with real hardware. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
846 |
// |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
847 |
// So what we do is we return true from EmuNetDevice::NeedsArp which tells ns-3 to use its own ARP. We spoof the |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
848 |
// MAC address of the device and use promiscuous mode to receive traffic destined to that address. |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
849 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
850 |
return SendFrom (packet, m_address, dest, protocolNumber); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
851 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
852 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
853 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
854 |
EmuNetDevice::SendFrom (Ptr<Packet> packet, const Address &src, const Address &dest, uint16_t protocolNumber) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
855 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
856 |
NS_LOG_FUNCTION (packet << src << dest << protocolNumber); |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
857 |
NS_LOG_LOGIC ("packet =" << packet); |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
858 |
NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")"); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
859 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
860 |
if (IsLinkUp () == false) |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
861 |
{ |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
862 |
m_macTxDropTrace (packet); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
863 |
return false; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
864 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
865 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
866 |
Mac48Address destination = Mac48Address::ConvertFrom (dest); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
867 |
Mac48Address source = Mac48Address::ConvertFrom (src); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
868 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
869 |
NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ()); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
870 |
NS_LOG_LOGIC ("Transmit packet from " << source); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
871 |
NS_LOG_LOGIC ("Transmit packet to " << destination); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
872 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
873 |
EthernetHeader header (false); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
874 |
header.SetSource (source); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
875 |
header.SetDestination (destination); |
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
876 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
877 |
switch (m_encapMode) |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
878 |
{ |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
879 |
case LLC: |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
880 |
{ |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
881 |
LlcSnapHeader llc; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
882 |
llc.SetType (protocolNumber); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
883 |
packet->AddHeader (llc); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
884 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
885 |
header.SetLengthType (packet->GetSize ()); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
886 |
} |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
887 |
break; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
888 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
889 |
case DIX: |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
890 |
header.SetLengthType (protocolNumber); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
891 |
break; |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
892 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
893 |
default: |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
894 |
NS_FATAL_ERROR ("invalid encapsulation mode"); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
895 |
} |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
896 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
897 |
packet->AddHeader (header); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
898 |
|
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
899 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
900 |
// there's not much meaning associated with the different layers in this |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
901 |
// device, so don't be surprised when they're all stacked together in |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
902 |
// essentially one place. We do this for trace consistency across devices. |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
903 |
// |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
904 |
m_macTxTrace (packet); |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
905 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
906 |
// |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
907 |
// Enqueue and dequeue the packet to hit the queue tracing hooks. |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
908 |
// |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
909 |
m_queue->Enqueue (packet); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
910 |
packet = m_queue->Dequeue (); |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
911 |
NS_ASSERT_MSG (packet, "EmuNetDevice::SendFrom(): packet zero from queue"); |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
912 |
|
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
913 |
m_promiscSnifferTrace (packet); |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
914 |
m_snifferTrace (packet); |
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
915 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
916 |
struct sockaddr_ll ll; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
917 |
bzero (&ll, sizeof (ll)); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
918 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
919 |
ll.sll_family = AF_PACKET; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
920 |
ll.sll_ifindex = m_sll_ifindex; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
921 |
ll.sll_protocol = htons(ETH_P_ALL); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
922 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
923 |
NS_LOG_LOGIC ("calling sendto"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
924 |
|
5822
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
925 |
NS_ASSERT_MSG (packet->GetSize () <= 65536, "EmuNetDevice::SendFrom(): Packet too big " << packet->GetSize ()); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
926 |
packet->CopyData (m_packetBuffer, packet->GetSize ()); |
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
927 |
|
c16bcd1c6647
Get emu working again: Add Dix/Llc option, add and use contextual realtime schedule ops, don't refcount realtime simulator impl
Craig Dowell <craigdo@ee.washington.edu>
parents:
4764
diff
changeset
|
928 |
int32_t rc = sendto (m_sock, m_packetBuffer, packet->GetSize (), 0, reinterpret_cast<struct sockaddr *> (&ll), sizeof (ll)); |
4263
fec2f830d015
trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
4017
diff
changeset
|
929 |
NS_LOG_LOGIC ("sendto returns " << rc); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
930 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
931 |
return rc == -1 ? false : true; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
932 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
933 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
934 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
935 |
EmuNetDevice::SetDataRate(DataRate bps) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
936 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
937 |
NS_LOG_FUNCTION (this << bps); |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
938 |
NS_FATAL_ERROR ("EmuNetDevice::SetDataRate(): Unable."); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
939 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
940 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
941 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
942 |
EmuNetDevice::SetQueue (Ptr<Queue> q) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
943 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
944 |
NS_LOG_FUNCTION (this << q); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
945 |
m_queue = q; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
946 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
947 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
948 |
Ptr<Queue> |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
949 |
EmuNetDevice::GetQueue(void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
950 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
951 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
952 |
return m_queue; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
953 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
954 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
955 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
956 |
EmuNetDevice::NotifyLinkUp (void) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
957 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
958 |
m_linkUp = true; |
4764
e90e1ef585b0
[Bug 653] NetDevice link change callback (SetLinkChangeCallback -> AddLinkChangeCallback).
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4677
diff
changeset
|
959 |
m_linkChangeCallbacks (); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
960 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
961 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
962 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
963 |
EmuNetDevice::SetIfIndex(const uint32_t index) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
964 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
965 |
m_ifIndex = index; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
966 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
967 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
968 |
uint32_t |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
969 |
EmuNetDevice::GetIfIndex(void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
970 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
971 |
return m_ifIndex; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
972 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
973 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
974 |
Ptr<Channel> |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
975 |
EmuNetDevice::GetChannel (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
976 |
{ |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
977 |
NS_FATAL_ERROR ("EmuNetDevice::GetChannel(): Unable."); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
978 |
return 0; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
979 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
980 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
981 |
void |
4578
88434ff8f0a5
Finally make tap bridge work with VMs (bug 569)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4479
diff
changeset
|
982 |
EmuNetDevice::SetAddress (Address address) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
983 |
{ |
4578
88434ff8f0a5
Finally make tap bridge work with VMs (bug 569)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4479
diff
changeset
|
984 |
NS_LOG_FUNCTION (address); |
88434ff8f0a5
Finally make tap bridge work with VMs (bug 569)
Craig Dowell <craigdo@ee.washington.edu>
parents:
4479
diff
changeset
|
985 |
m_address = Mac48Address::ConvertFrom (address); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
986 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
987 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
988 |
Address |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
989 |
EmuNetDevice::GetAddress (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
990 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
991 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
992 |
return m_address; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
993 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
994 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
995 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
996 |
EmuNetDevice::SetMtu (const uint16_t mtu) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
997 |
{ |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
998 |
NS_FATAL_ERROR ("EmuNetDevice::SetMtu(): Unable."); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
999 |
return false; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1000 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1001 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1002 |
uint16_t |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1003 |
EmuNetDevice::GetMtu (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1004 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1005 |
struct ifreq ifr; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1006 |
bzero (&ifr, sizeof (ifr)); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1007 |
strcpy(ifr.ifr_name, m_deviceName.c_str ()); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1008 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1009 |
int32_t fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1010 |
|
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
1011 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1012 |
int32_t rc = ioctl(fd, SIOCGIFMTU, &ifr); |
3847
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
1013 |
if (rc == -1) |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
1014 |
{ |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
1015 |
NS_FATAL_ERROR ("EmuNetDevice::GetMtu(): Can't ioctl SIOCGIFMTU"); |
784c45b27326
asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents:
3842
diff
changeset
|
1016 |
} |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1017 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1018 |
close (fd); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1019 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1020 |
return ifr.ifr_mtu; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1021 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1022 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1023 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1024 |
EmuNetDevice::IsLinkUp (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1025 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1026 |
return m_linkUp; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1027 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1028 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1029 |
void |
4764
e90e1ef585b0
[Bug 653] NetDevice link change callback (SetLinkChangeCallback -> AddLinkChangeCallback).
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4677
diff
changeset
|
1030 |
EmuNetDevice::AddLinkChangeCallback (Callback<void> callback) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1031 |
{ |
4764
e90e1ef585b0
[Bug 653] NetDevice link change callback (SetLinkChangeCallback -> AddLinkChangeCallback).
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4677
diff
changeset
|
1032 |
m_linkChangeCallbacks.ConnectWithoutContext (callback); |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1033 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1034 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1035 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1036 |
EmuNetDevice::IsBroadcast (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1037 |
{ |
4479
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
1038 |
return m_isBroadcast; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1039 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1040 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1041 |
Address |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1042 |
EmuNetDevice::GetBroadcast (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1043 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1044 |
return Mac48Address ("ff:ff:ff:ff:ff:ff"); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1045 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1046 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1047 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1048 |
EmuNetDevice::IsMulticast (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1049 |
{ |
4479
ba809221f9b3
Enable EmuNetDevice for multicast, based on underlying device (bug 571)
Tom Henderson <tomh@tomh.org>
parents:
4424
diff
changeset
|
1050 |
return m_isMulticast; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1051 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1052 |
|
3842
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
1053 |
Address |
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
1054 |
EmuNetDevice::GetMulticast (Ipv4Address multicastGroup) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1055 |
{ |
3836
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1056 |
NS_LOG_FUNCTION (multicastGroup); |
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1057 |
|
3842
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
1058 |
Mac48Address ad = Mac48Address::GetMulticast (multicastGroup); |
3836
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1059 |
|
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1060 |
// |
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1061 |
// Implicit conversion (operator Address ()) is defined for Mac48Address, so |
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1062 |
// use it by just returning the EUI-48 address which is automagically converted |
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1063 |
// to an Address. |
e3aa8940f23b
enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents:
3835
diff
changeset
|
1064 |
// |
3842
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
1065 |
NS_LOG_LOGIC ("multicast address is " << ad); |
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
1066 |
|
545ddf9398ed
apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents:
3836
diff
changeset
|
1067 |
return ad; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1068 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1069 |
|
3852 | 1070 |
Address |
1071 |
EmuNetDevice::GetMulticast (Ipv6Address addr) const |
|
1072 |
{ |
|
1073 |
NS_LOG_FUNCTION(this << addr); |
|
1074 |
||
1075 |
Mac48Address ad = Mac48Address::GetMulticast (addr); |
|
1076 |
NS_LOG_LOGIC("MAC IPv6 multicast address is " << ad); |
|
1077 |
||
1078 |
return ad; |
|
1079 |
} |
|
1080 |
||
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1081 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1082 |
EmuNetDevice::IsPointToPoint (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1083 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1084 |
return false; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1085 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1086 |
|
3936
e525995ce5dc
implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
3852
diff
changeset
|
1087 |
bool |
e525995ce5dc
implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
3852
diff
changeset
|
1088 |
EmuNetDevice::IsBridge (void) const |
e525995ce5dc
implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
3852
diff
changeset
|
1089 |
{ |
e525995ce5dc
implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
3852
diff
changeset
|
1090 |
return false; |
e525995ce5dc
implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
3852
diff
changeset
|
1091 |
} |
e525995ce5dc
implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents:
3852
diff
changeset
|
1092 |
|
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1093 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1094 |
EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1095 |
{ |
6278
ba09ab600218
Bug 899 - EmuNetDevice::SetPromiscReceiveCallback not implemented
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6183
diff
changeset
|
1096 |
m_promiscRxCallback = cb; |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1097 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1098 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1099 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1100 |
EmuNetDevice::SupportsSendFrom () const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1101 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1102 |
NS_LOG_FUNCTION_NOARGS (); |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1103 |
return true; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1104 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1105 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1106 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1107 |
Ptr<Node> |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1108 |
EmuNetDevice::GetNode (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1109 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1110 |
return m_node; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1111 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1112 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1113 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1114 |
EmuNetDevice::SetNode (Ptr<Node> node) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1115 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1116 |
m_node = node; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1117 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1118 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1119 |
bool |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1120 |
EmuNetDevice::NeedsArp (void) const |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1121 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1122 |
return true; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1123 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1124 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1125 |
void |
3830
8862b9be62bb
rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents:
3827
diff
changeset
|
1126 |
EmuNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) |
3827
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1127 |
{ |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1128 |
m_rxCallback = cb; |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1129 |
} |
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1130 |
|
4b603cd4ee42
give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1131 |
} // namespace ns3 |