src/devices/emu/emu-net-device.cc
author Craig Dowell <craigdo@ee.washington.edu>
Wed, 29 Oct 2008 22:39:36 -0700
changeset 3830 8862b9be62bb
parent 3827 src/devices/emulated/emulated-net-device.cc@4b603cd4ee42
child 3831 16c2970a0344
permissions -rw-r--r--
rework to address suid root issues
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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/realtime-simulator-impl.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/mac48-address.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "ns3/ethernet-header.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
#include "ns3/ethernet-trailer.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
#include "ns3/llc-snap-header.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
#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
    31
#include "ns3/pointer.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
#include "ns3/channel.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#include "ns3/system-thread.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
#include "ns3/string.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
#include "ns3/boolean.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    37
#include <sys/wait.h>
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    38
#include <sys/stat.h>
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
#include <sys/socket.h>
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    40
#include <sys/un.h>
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
#include <sys/ioctl.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
#include <net/ethernet.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
#include <net/if.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
#include <netinet/in.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
#include <netpacket/packet.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
#include <arpa/inet.h>
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    47
#include <errno.h>
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    49
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
    50
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
namespace ns3 {
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_OBJECT_ENSURE_REGISTERED (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
TypeId 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    56
EmuNetDevice::GetTypeId (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
{
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    58
  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
    59
    .SetParent<NetDevice> ()
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    60
    .AddConstructor<EmuNetDevice> ()
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
    .AddAttribute ("Address", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
                   "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
    63
                   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
    64
                   MakeMac48AddressAccessor (&EmuNetDevice::m_address),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
                   MakeMac48AddressChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
    .AddAttribute ("DeviceName", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
                   "The name of the underlying real device (e.g. eth1).",
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
                   StringValue ("eth1"),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    69
                   MakeStringAccessor (&EmuNetDevice::m_deviceName),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
                   MakeStringChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
    .AddAttribute ("Start", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
                   "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
    73
                   TimeValue (Seconds (0.)),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    74
                   MakeTimeAccessor (&EmuNetDevice::m_tStart),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
                   MakeTimeChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
    .AddAttribute ("Stop", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
                   "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
    78
                   TimeValue (Seconds (0.)),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    79
                   MakeTimeAccessor (&EmuNetDevice::m_tStop),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
                   MakeTimeChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
    .AddAttribute ("TxQueue", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
                   "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
    83
                   PointerValue (),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    84
                   MakePointerAccessor (&EmuNetDevice::m_queue),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
                   MakePointerChecker<Queue> ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
    .AddTraceSource ("Rx", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
                     "Trace source to fire on reception of a MAC packet.",
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    88
                     MakeTraceSourceAccessor (&EmuNetDevice::m_rxTrace))
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
    .AddTraceSource ("Drop", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
                     "Trace source to fire on when a MAC packet is dropped.",
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    91
                     MakeTraceSourceAccessor (&EmuNetDevice::m_dropTrace))
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
    ;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
  return tid;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    97
EmuNetDevice::EmuNetDevice () 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
: 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  m_startEvent (),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  m_stopEvent (),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  m_sock (-1),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
  m_readThread (0),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  m_ifIndex (-1),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  m_sll_ifindex (-1),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   105
  m_name ("Emu NetDevice")
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  NS_LOG_FUNCTION (this);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  Start (m_tStart);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   111
EmuNetDevice::~EmuNetDevice ()
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   116
EmuNetDevice::DoDispose()
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
  m_node = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  NetDevice::DoDispose ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   124
EmuNetDevice::Start (Time tStart)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
  NS_LOG_FUNCTION (tStart);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
  // 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
   130
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
  Simulator::Cancel (m_startEvent);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   132
  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
   133
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
  void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   136
EmuNetDevice::Stop (Time tStop)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
  NS_LOG_FUNCTION (tStop);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
  // 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
   141
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
  Simulator::Cancel (m_stopEvent);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   143
  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
   144
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
  void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   147
EmuNetDevice::StartDevice (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   152
  // 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
   153
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   154
  NS_ASSERT_MSG (m_sock == -1, "EmuNetDevice::StartDevice(): Device is already started");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  NS_LOG_LOGIC ("Creating socket");
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   157
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   158
  // 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
   159
  // 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
   160
  // 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
   161
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   162
  CreateSocket ();
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
  // 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
   166
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
  struct ifreq ifr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
  bzero (&ifr, sizeof(ifr));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
  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
   170
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
  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
   172
  int32_t rc = ioctl (m_sock, SIOCGIFINDEX, &ifr);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   173
  NS_ASSERT_MSG (rc != -1, "EmuNetDevice::StartDevice(): Can't get interface index");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  // 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
   177
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
  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
   179
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
  // 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
   182
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
  struct sockaddr_ll ll;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
  bzero (&ll, sizeof(ll));
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
  ll.sll_family = AF_PACKET;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  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
   188
  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
   189
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  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
   191
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
  rc = bind (m_sock, (struct sockaddr *)&ll, sizeof (ll));
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   193
  NS_ASSERT_MSG (rc != -1, "EmuNetDevice::StartDevice(): Can't bind to specified interface");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  // 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
   197
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   198
  NS_ASSERT_MSG (m_readThread == 0, "EmuNetDevice::StartDevice(): Receive thread is already running");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
  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
   201
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   202
  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
   203
  m_readThread->Start ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
  NotifyLinkUp ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   209
EmuNetDevice::CreateSocket (void)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   210
{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   211
  NS_LOG_FUNCTION_NOARGS ();
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   212
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   213
  // 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
   214
  // 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
   215
  // 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
   216
  // 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
   217
  // 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
   218
  // 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
   219
  // for that purpose.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   220
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   221
  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
   222
  if (sock == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   223
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   224
      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
   225
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   226
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   227
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   228
  // 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
   229
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   230
  struct sockaddr_un un;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   231
  memset (&un, 0, sizeof (un));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   232
  un.sun_family = AF_UNIX;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   233
  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
   234
  if (status == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   235
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   236
      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
   237
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   238
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   239
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   240
  // 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
   241
  // 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
   242
  // 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
   243
  // 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
   244
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   245
  socklen_t len = sizeof (un);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   246
  status = getsockname (sock, (struct sockaddr*)&un, &len);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   247
  if (status == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   248
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   249
      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
   250
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   251
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   252
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   253
  // Now encode that socket name (endpoint information) as a string
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   254
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   255
  std::string endpoint = EmuBufferToString((uint8_t *)&un, len);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   256
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   257
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   258
  // 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
   259
  // 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
   260
  // 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
   261
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   262
  pid_t pid = ::fork ();
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   263
  if (pid == 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   264
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   265
      NS_LOG_DEBUG ("Child process");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   266
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   267
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   268
      // 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
   269
      // 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
   270
      // the (now) parent process.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   271
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   272
      std::ostringstream oss;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   273
      oss << "-p " << endpoint;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   274
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   275
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   276
      // Execute the socket creation process image.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   277
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   278
      status = ::execl (FindCreator ().c_str (), "emu-sock-creator", oss.str ().c_str (), (char *)NULL);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   279
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   280
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   281
      // If the execl successfully completes, it never returns.  If it returns it failed or the OS is
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   282
      // broken.  In either case, we bail.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   283
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   284
      NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Back from execl(), errno = " << ::strerror (errno));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   285
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   286
  else
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   287
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   288
      NS_LOG_DEBUG ("Parent process");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   289
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   290
      // 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
   291
      // socket creator process to finish its job.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   292
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   293
      int st;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   294
      pid_t waited = waitpid (pid, &st, 0);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   295
      if (waited == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   296
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   297
	  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
   298
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   299
      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
   300
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   301
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   302
      // 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
   303
      // 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
   304
      // even exit normally, we bail too.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   305
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   306
      if (WIFEXITED (st))
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   307
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   308
          int exitStatus = WEXITSTATUS (st);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   309
          if (exitStatus != 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   310
            {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   311
              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
   312
            }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   313
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   314
      else 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   315
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   316
          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
   317
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   318
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   319
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   320
      // 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
   321
      // 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
   322
      // 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
   323
      // 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
   324
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   325
      // 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
   326
      // 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
   327
      // 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
   328
      // 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
   329
      // 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   330
      struct iovec iov;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   331
      uint32_t magic;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   332
      iov.iov_base = &magic;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   333
      iov.iov_len = sizeof(magic);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   334
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   335
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   336
      // 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
   337
      // 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
   338
      // 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
   339
      // data arrays.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   340
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   341
      // 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
   342
      // 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
   343
      // 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
   344
      // so we call it "control."
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   345
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   346
      size_t msg_size = sizeof(int);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   347
      char control[CMSG_SPACE(msg_size)];
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   348
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   349
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   350
      // 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
   351
      // 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
   352
      // 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
   353
      // 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
   354
      // 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
   355
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   356
      // 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
   357
      // 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
   358
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   359
      struct msghdr msg;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   360
      msg.msg_name = 0;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   361
      msg.msg_namelen = 0;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   362
      msg.msg_iov = &iov;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   363
      msg.msg_iovlen = 1;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   364
      msg.msg_control = control;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   365
      msg.msg_controllen = sizeof (control);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   366
      msg.msg_flags = 0;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   367
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   368
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   369
      // 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
   370
      // creator process.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   371
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   372
      ssize_t bytesRead = recvmsg (sock, &msg, 0);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   373
      if (bytesRead != sizeof(int))
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   374
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   375
          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
   376
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   377
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   378
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   379
      // 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
   380
      // 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
   381
      // one we're interested in.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   382
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   383
      struct cmsghdr *cmsg;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   384
      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
   385
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   386
	  if (cmsg->cmsg_level == SOL_SOCKET &&
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   387
	      cmsg->cmsg_type == SCM_RIGHTS)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   388
	    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   389
	      int *rawSocket = (int*)CMSG_DATA (cmsg);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   390
	      NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   391
              m_sock = *rawSocket;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   392
              return;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   393
	    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   394
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   395
      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
   396
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   397
}
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
std::string
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   400
EmuNetDevice::FindCreator (void)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   401
{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   402
  struct stat st;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   403
  std::string debug = "./build/debug/src/devices/emu/emu-sock-creator";
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   404
  std::string optimized = "./build/optimized/src/devices/emu/emu-sock-creator";
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   405
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   406
  if (::stat (debug.c_str (), &st) == 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   407
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   408
      return debug;
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
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   411
  if (::stat (optimized.c_str (), &st) == 0)
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
      return optimized;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   414
    }
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
  NS_FATAL_ERROR ("EmuNetDevice::FindCreator(): Couldn't find creator");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   417
  return ""; // quiet compiler
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   418
}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   419
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   420
void
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   421
EmuNetDevice::StopDevice (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   424
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   425
  close (m_sock);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   426
  m_sock = -1;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   428
  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
   429
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
  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
   431
  m_readThread->Join ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
  m_readThread = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   433
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   434
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   436
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
   437
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   438
  NS_LOG_FUNCTION (buf << len);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   440
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   441
  // 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
   442
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   443
  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
   444
  free (buf);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   445
  buf = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   446
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   447
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   448
  // 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
   449
  // headers.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   450
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   451
  Ptr<Packet> originalPacket = packet->Copy ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   452
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   453
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   454
  // Checksum the packet
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   455
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   456
  EthernetTrailer trailer;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   457
  packet->RemoveTrailer (trailer);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   458
  trailer.CheckFcs (packet);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   459
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   460
  EthernetHeader header (false);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   461
  packet->RemoveHeader (header);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   462
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   463
  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
   464
  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
   465
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   466
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   467
  // An IP host group address is mapped to an Ethernet multicast address
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   468
  // by placing the low-order 23-bits of the IP address into the low-order
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   469
  // 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex).
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   470
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   471
  // We are going to receive all packets destined to any multicast address,
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   472
  // which means clearing the low-order 23 bits the header destination 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   473
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   474
  Mac48Address mcDest;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   475
  uint8_t      mcBuf[6];
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   476
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   477
  header.GetDestination ().CopyTo (mcBuf);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   478
  mcBuf[3] &= 0x80;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   479
  mcBuf[4] = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   480
  mcBuf[5] = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   481
  mcDest.CopyFrom (mcBuf);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   482
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   483
  Mac48Address multicast = Mac48Address::ConvertFrom (GetMulticast ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   484
  Mac48Address broadcast = Mac48Address::ConvertFrom (GetBroadcast ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   485
  Mac48Address destination = Mac48Address::ConvertFrom (GetAddress ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   486
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   487
  LlcSnapHeader llc;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   488
  packet->RemoveHeader (llc);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   489
  uint16_t protocol = llc.GetType ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   491
  PacketType packetType;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   492
      
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
  if (header.GetDestination () == broadcast)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   494
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   495
      NS_LOG_LOGIC ("Pkt destination is PACKET_BROADCAST");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   496
      packetType = NS3_PACKET_BROADCAST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   497
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   498
  else if (mcDest == multicast)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   499
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   500
      NS_LOG_LOGIC ("Pkt destination is PACKET_MULTICAST");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   501
      packetType = NS3_PACKET_MULTICAST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   502
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   503
  else if (header.GetDestination () == destination)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   504
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   505
      NS_LOG_LOGIC ("Pkt destination is PACKET_HOST");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   506
      packetType = NS3_PACKET_HOST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
  else
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   509
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   510
      NS_LOG_LOGIC ("Pkt destination is PACKET_OTHERHOST");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   511
      packetType = NS3_PACKET_OTHERHOST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   512
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   513
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   514
  if (!m_promiscRxCallback.IsNull ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   515
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   516
      NS_LOG_LOGIC ("calling m_promiscRxCallback");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   517
      m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), packetType);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   518
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   519
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   520
  if (packetType != NS3_PACKET_OTHERHOST)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   521
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   522
      m_rxTrace (originalPacket);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   523
      NS_LOG_LOGIC ("calling m_rxCallback");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   524
      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
   525
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   526
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   527
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   528
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   529
EmuNetDevice::ReadThread (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   530
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   531
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   532
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   533
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
  // It's important to remember that we're in a completely different thread than the simulator is running in.  We
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   535
  // need to synchronize with that other thread to get the packet up into ns-3.  What we will need to do is to schedule 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   536
  // a method to forward up the packet using the multithreaded simulator we are most certainly running.  However, I just 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   537
  // said it -- we are talking about two threads here, so it is very, very dangerous to do any kind of reference couning
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
  // on a shared object.  Just don't do it.  So what we're going to do is to allocate a buffer on the heap and pass that
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   539
  // buffer into the ns-3 context thread where it will create the packet.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   540
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   541
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   542
  int32_t len = -1;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   543
  struct sockaddr_ll addr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   544
  socklen_t addrSize = sizeof (addr);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   545
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   546
  for (;;) 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   547
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   548
      uint32_t bufferSize = 65536;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   549
      uint8_t *buf = (uint8_t *)malloc (bufferSize);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   550
      NS_ASSERT_MSG (buf, "EmuNetDevice::ReadThread(): malloc packet buffer failed");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   551
      NS_LOG_LOGIC ("Calling recvfrom");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   552
      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
   553
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   554
      if (len == -1)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   555
        {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
          free (buf);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   557
          buf = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   558
          return;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   559
        }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   560
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   561
      NS_LOG_INFO ("EmuNetDevice::ReadThread(): Received packet");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   562
      NS_LOG_INFO ("EmuNetDevice::ReadThread(): Scheduling handler");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   563
      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow (
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   564
        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
   565
      buf = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   566
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   567
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   569
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   570
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
   571
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   572
  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
   573
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
  // 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
   575
  // destination (hardware) addresses?
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   576
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   577
  // 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
   578
  // 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
   579
  // 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
   580
  // 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
   581
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   582
  // 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
   583
  // 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
   584
  // 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
   585
  // 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
   586
  // 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
   587
  // 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
   588
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   589
  // 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
   590
  // 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
   591
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   592
  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
   593
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   594
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   595
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   596
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
   597
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   598
  NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   599
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   600
  if (IsLinkUp () == false)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   601
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   602
      NS_LOG_LOGIC ("Link is down, returning");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   603
      return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   604
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   605
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   606
  Mac48Address destination = Mac48Address::ConvertFrom (dest);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   607
  Mac48Address source = Mac48Address::ConvertFrom (src);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   608
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   609
  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
   610
  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
   611
  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
   612
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   613
#if 0
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
    struct ifreq ifr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   616
    bzero (&ifr, sizeof(ifr));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   617
    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
   618
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   619
    NS_LOG_LOGIC ("Getting MAC address");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   620
    int32_t rc = ioctl (m_sock, SIOCGIFHWADDR, &ifr);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   621
    NS_ASSERT_MSG (rc != -1, "EmuNetDevice::SendFrom(): Can't get MAC address");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   622
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   623
    std::ostringstream oss;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   624
    oss << std::hex <<
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   625
      (ifr.ifr_hwaddr.sa_data[0] & 0xff) << ":" <<
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   626
      (ifr.ifr_hwaddr.sa_data[1] & 0xff) << ":" <<
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   627
      (ifr.ifr_hwaddr.sa_data[2] & 0xff) << ":" <<
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   628
      (ifr.ifr_hwaddr.sa_data[3] & 0xff) << ":" <<
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   629
      (ifr.ifr_hwaddr.sa_data[4] & 0xff) << ":" <<
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   630
      (ifr.ifr_hwaddr.sa_data[5] & 0xff) << std::dec;
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
    NS_LOG_LOGIC ("Fixup source to HW MAC " << oss.str ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   633
    source = Mac48Address (oss.str ().c_str ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   634
    NS_LOG_LOGIC ("source now " << source);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   635
  }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   636
#endif
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   637
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   638
  LlcSnapHeader llc;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   639
  llc.SetType (protocolNumber);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   640
  packet->AddHeader (llc);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   641
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   642
  EthernetHeader header (false);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   643
  header.SetSource (source);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   644
  header.SetDestination (destination);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   645
  header.SetLengthType (packet->GetSize ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   646
  packet->AddHeader (header);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   647
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   648
  EthernetTrailer trailer;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   649
  trailer.CalcFcs (packet);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   650
  packet->AddTrailer (trailer);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   651
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   652
  // 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   653
  // Enqueue and dequeue the packet to hit the tracing hooks.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   654
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   655
  m_queue->Enqueue (packet);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   656
  packet = m_queue->Dequeue ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   657
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   658
  struct sockaddr_ll ll;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   659
  bzero (&ll, sizeof (ll));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   660
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   661
  ll.sll_family = AF_PACKET;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   662
  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
   663
  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
   664
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   665
  NS_LOG_LOGIC ("calling sendto");
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
  int32_t rc;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   668
  rc = sendto (m_sock, packet->PeekData (), packet->GetSize (), 0, reinterpret_cast<struct sockaddr *> (&ll), sizeof (ll));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   669
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   670
  NS_LOG_LOGIC ("sendto returns " << rc);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   671
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   672
  return rc == -1 ? false : true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   673
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   674
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   675
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   676
EmuNetDevice::SetDataRate(DataRate bps)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
  NS_LOG_FUNCTION (this << bps);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   679
  NS_ASSERT_MSG (false, "EmuNetDevice::SetDataRate():  Unable."); 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   680
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   681
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   683
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
   684
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   685
  NS_LOG_FUNCTION (this << q);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   686
  m_queue = q;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   687
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   688
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   689
Ptr<Queue> 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   690
EmuNetDevice::GetQueue(void) const 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   691
{ 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   692
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
  return m_queue;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   696
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   697
EmuNetDevice::NotifyLinkUp (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   698
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   699
  m_linkUp = true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   700
  if (!m_linkChangeCallback.IsNull ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   701
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   702
      m_linkChangeCallback ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   703
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   704
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   705
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   707
EmuNetDevice::SetName(const std::string name)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   708
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   709
  m_name = name;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   710
}
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
std::string 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   713
EmuNetDevice::GetName(void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   714
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   715
  return m_name;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   716
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   717
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   718
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   719
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
   720
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   721
  m_ifIndex = index;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
}
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
uint32_t 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   725
EmuNetDevice::GetIfIndex(void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   726
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   727
  return m_ifIndex;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   728
}
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
Ptr<Channel> 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   731
EmuNetDevice::GetChannel (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
{
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   733
  NS_ASSERT_MSG (false, "EmuNetDevice::GetChannel():  Unable."); 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   734
  return 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   736
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   737
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   738
EmuNetDevice::SetAddress (Mac48Address addr)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   739
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   740
  NS_LOG_FUNCTION (addr);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   741
  m_address = addr;
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
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   744
Address 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   745
EmuNetDevice::GetAddress (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   746
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   748
  return m_address;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   749
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   750
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   751
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   752
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
   753
{
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   754
  NS_ASSERT_MSG (false, "EmuNetDevice::SetMtu():  Unable."); 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   755
  return false;
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
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   758
uint16_t 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   759
EmuNetDevice::GetMtu (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   760
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   761
  struct ifreq ifr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   762
  bzero (&ifr, sizeof (ifr));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   763
  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
   764
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   765
  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
   766
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   767
  int32_t rc = ioctl(fd, SIOCGIFMTU, &ifr);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   768
  NS_ASSERT_MSG (rc != -1, "EmuNetDevice::GetMtu(): Can't ioctl SIOCGIFMTU");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   769
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   770
  close (fd);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   771
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   772
  return ifr.ifr_mtu;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   773
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   774
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   775
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   776
EmuNetDevice::IsLinkUp (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   777
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   778
  return m_linkUp;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   779
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   780
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   781
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   782
EmuNetDevice::SetLinkChangeCallback (Callback<void> callback)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   783
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   784
  m_linkChangeCallback = callback;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   785
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   786
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   787
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   788
EmuNetDevice::IsBroadcast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   789
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   790
  return true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   791
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   792
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   793
Address
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   794
EmuNetDevice::GetBroadcast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   795
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   796
  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
   797
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   798
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   799
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   800
EmuNetDevice::IsMulticast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   801
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   802
  return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   803
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   804
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   805
Address 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   806
EmuNetDevice::GetMulticast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   807
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   808
  return Mac48Address ("01:00:5e:00:00:00");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   809
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   810
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   811
Address 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   812
EmuNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
3827
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
  return Mac48Address ("01:00:5e:00:00:00");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   815
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   816
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   817
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   818
EmuNetDevice::IsPointToPoint (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   819
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   820
  return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   821
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   822
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   823
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   824
EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   825
{
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   826
  NS_ASSERT_MSG (false, "EmuNetDevice::SetPromiscReceiveCallback(): Not implemented");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   827
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   828
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   829
  bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   830
EmuNetDevice::SupportsSendFrom () const
3827
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
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   833
  return true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   834
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   835
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   836
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   837
Ptr<Node> 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   838
EmuNetDevice::GetNode (void) const
3827
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
  return m_node;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   841
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   842
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   843
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   844
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
   845
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   846
  m_node = node;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   847
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   848
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   849
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   850
EmuNetDevice::NeedsArp (void) const
3827
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
  return true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   853
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   854
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   855
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   856
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
   857
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   858
  m_rxCallback = cb;
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
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   861
} // namespace ns3