View | Details | Raw Unified | Return to bug 1319
Collapse All | Expand All

(-)a/src/internet/model/ipv6-raw-socket-impl.cc (-5 / +38 lines)
 Lines 51-60    Link Here 
51
                   UintegerValue (0),
51
                   UintegerValue (0),
52
                   MakeUintegerAccessor (&Ipv6RawSocketImpl::m_protocol),
52
                   MakeUintegerAccessor (&Ipv6RawSocketImpl::m_protocol),
53
                   MakeUintegerChecker<uint16_t> ())
53
                   MakeUintegerChecker<uint16_t> ())
54
    .AddAttribute ("IcmpFilter", "Any ICMPv6 header whose type field matches a bit in this filter is dropped.",
55
                   UintegerValue (0),
56
                   MakeUintegerAccessor (&Ipv6RawSocketImpl::m_icmpFilter),
57
                   MakeUintegerChecker<uint32_t> ())
58
  ;
54
  ;
59
  return tid;
55
  return tid;
60
}
56
}
 Lines 69-74    Link Here 
69
  m_protocol = 0;
65
  m_protocol = 0;
70
  m_shutdownSend = false;
66
  m_shutdownSend = false;
71
  m_shutdownRecv = false;
67
  m_shutdownRecv = false;
68
  Icmpv6FilterSetPassAll();
72
}
69
}
73
70
74
Ipv6RawSocketImpl::~Ipv6RawSocketImpl ()
71
Ipv6RawSocketImpl::~Ipv6RawSocketImpl ()
 Lines 328-334    Link Here 
328
          copy->PeekHeader (icmpHeader);
325
          copy->PeekHeader (icmpHeader);
329
          uint8_t type = icmpHeader.GetType ();
326
          uint8_t type = icmpHeader.GetType ();
330
327
331
          if ((1 << type) & m_icmpFilter)
328
          if (Icmpv6FilterWillBlock(type))
332
            {
329
            {
333
              /* packet filtered */
330
              /* packet filtered */
334
              return false;
331
              return false;
 Lines 372-376    Link Here 
372
  return true;
369
  return true;
373
}
370
}
374
371
372
void
373
Ipv6RawSocketImpl::Icmpv6FilterSetPassAll()
374
{
375
  memset(&m_icmpFilter, 0xff, sizeof(icmpv6Filter));
376
}
377
378
void
379
Ipv6RawSocketImpl::Icmpv6FilterSetBlockAll()
380
{
381
  memset(&m_icmpFilter, 0x00, sizeof(icmpv6Filter));
382
}
383
384
void
385
Ipv6RawSocketImpl::Icmpv6FilterSetPass(uint8_t type)
386
{
387
  (m_icmpFilter.icmpv6Filt[(type) >> 5]) |= (uint32_t(1) << ((type) & 31));
388
}
389
390
void
391
Ipv6RawSocketImpl::Icmpv6FilterSetBlock(uint8_t type)
392
{
393
  (m_icmpFilter.icmpv6Filt[(type) >> 5]) &= ~(uint32_t(1) << ((type) & 31));
394
}
395
396
bool
397
Ipv6RawSocketImpl::Icmpv6FilterWillPass(uint8_t type)
398
{
399
  return (((m_icmpFilter.icmpv6Filt[(type) >> 5]) & (uint32_t(1) << ((type) & 31))) != 0);
400
}
401
402
bool
403
Ipv6RawSocketImpl::Icmpv6FilterWillBlock(uint8_t type)
404
{
405
  return (((m_icmpFilter.icmpv6Filt[(type) >> 5]) & (uint32_t(1) << ((type) & 31))) == 0);
406
}
407
375
} /* namespace ns3 */
408
} /* namespace ns3 */
376
409
(-)a/src/internet/model/ipv6-raw-socket-impl.h (-2 / +47 lines)
 Lines 219-228    Link Here 
219
  virtual bool SetAllowBroadcast (bool allowBroadcast);
219
  virtual bool SetAllowBroadcast (bool allowBroadcast);
220
  virtual bool GetAllowBroadcast () const;
220
  virtual bool GetAllowBroadcast () const;
221
221
222
  /**
223
   * \brief Clean the ICMPv6 filter structure
224
   */
225
  void Icmpv6FilterSetPassAll();
226
227
  /**
228
   * \brief Set the filter to block all the ICMPv6 types
229
   */
230
  void Icmpv6FilterSetBlockAll();
231
232
  /**
233
   * \brief Set the filter to pass one ICMPv6 type
234
   * \param the ICMPv6 type to pass
235
   */
236
  void Icmpv6FilterSetPass(uint8_t type);
237
238
  /**
239
   * \brief Set the filter to block one ICMPv6 type
240
   * \param the ICMPv6 type to block
241
   */
242
  void Icmpv6FilterSetBlock(uint8_t type);
243
244
  /**
245
   * \brief Ask the filter about the status of one ICMPv6 type
246
   * \param the ICMPv6 type
247
   * \return true if the ICMP type is passing through
248
   */
249
  bool Icmpv6FilterWillPass(uint8_t type);
250
251
  /**
252
   * \brief Ask the filter about the status of one ICMPv6 type
253
   * \param the ICMPv6 type
254
   * \return true if the ICMP type is being blocked
255
   */
256
  bool Icmpv6FilterWillBlock(uint8_t type);
257
258
222
private:
259
private:
223
  /**
260
  /**
224
   * \struct Data
261
   * \struct Data
225
   * \brief IPv6 raw data and additionnal information.
262
   * \brief IPv6 raw data and additional information.
226
   */
263
   */
227
  struct Data
264
  struct Data
228
  {
265
  {
 Lines 277-285    Link Here 
277
  bool m_shutdownRecv;
314
  bool m_shutdownRecv;
278
315
279
  /**
316
  /**
317
   * \brief Struct to hold the ICMPv6 filter
318
   */
319
  typedef struct
320
  {
321
    uint32_t icmpv6Filt[8];
322
  } icmpv6Filter;
323
324
  /**
280
   * \brief ICMPv6 filter.
325
   * \brief ICMPv6 filter.
281
   */
326
   */
282
  uint32_t m_icmpFilter;
327
  icmpv6Filter m_icmpFilter;
283
};
328
};
284
329
285
} /* namespace ns3 */
330
} /* namespace ns3 */

Return to bug 1319