src/internet/model/ipv6-raw-socket-impl.cc
changeset 7696 142e062124f4
parent 7485 9bec9af5e3c8
child 7717 cfa1741013dd
--- a/src/internet/model/ipv6-raw-socket-impl.cc	Mon Jan 23 11:53:28 2012 +0000
+++ b/src/internet/model/ipv6-raw-socket-impl.cc	Wed Jan 25 19:13:11 2012 +0100
@@ -51,10 +51,6 @@
                    UintegerValue (0),
                    MakeUintegerAccessor (&Ipv6RawSocketImpl::m_protocol),
                    MakeUintegerChecker<uint16_t> ())
-    .AddAttribute ("IcmpFilter", "Any ICMPv6 header whose type field matches a bit in this filter is dropped.",
-                   UintegerValue (0),
-                   MakeUintegerAccessor (&Ipv6RawSocketImpl::m_icmpFilter),
-                   MakeUintegerChecker<uint32_t> ())
   ;
   return tid;
 }
@@ -69,6 +65,7 @@
   m_protocol = 0;
   m_shutdownSend = false;
   m_shutdownRecv = false;
+  Icmpv6FilterSetPassAll();
 }
 
 Ipv6RawSocketImpl::~Ipv6RawSocketImpl ()
@@ -328,7 +325,7 @@
           copy->PeekHeader (icmpHeader);
           uint8_t type = icmpHeader.GetType ();
 
-          if ((1 << type) & m_icmpFilter)
+          if (Icmpv6FilterWillBlock(type))
             {
               /* packet filtered */
               return false;
@@ -372,5 +369,41 @@
   return true;
 }
 
+void
+Ipv6RawSocketImpl::Icmpv6FilterSetPassAll()
+{
+  memset(&m_icmpFilter, 0xff, sizeof(icmpv6Filter));
+}
+
+void
+Ipv6RawSocketImpl::Icmpv6FilterSetBlockAll()
+{
+  memset(&m_icmpFilter, 0x00, sizeof(icmpv6Filter));
+}
+
+void
+Ipv6RawSocketImpl::Icmpv6FilterSetPass(uint8_t type)
+{
+  (m_icmpFilter.icmpv6Filt[(type) >> 5]) |= (uint32_t(1) << ((type) & 31));
+}
+
+void
+Ipv6RawSocketImpl::Icmpv6FilterSetBlock(uint8_t type)
+{
+  (m_icmpFilter.icmpv6Filt[(type) >> 5]) &= ~(uint32_t(1) << ((type) & 31));
+}
+
+bool
+Ipv6RawSocketImpl::Icmpv6FilterWillPass(uint8_t type)
+{
+  return (((m_icmpFilter.icmpv6Filt[(type) >> 5]) & (uint32_t(1) << ((type) & 31))) != 0);
+}
+
+bool
+Ipv6RawSocketImpl::Icmpv6FilterWillBlock(uint8_t type)
+{
+  return (((m_icmpFilter.icmpv6Filt[(type) >> 5]) & (uint32_t(1) << ((type) & 31))) == 0);
+}
+
 } /* namespace ns3 */