src/internet-stack/ipv4-conntrack-l3-protocol.cc
author Qasim Javed <qasimj@gmail.com>
Thu Aug 06 01:55:49 2009 +0600 (2009-08-06)
changeset 4638 19aa5f9b4bdf
parent 4636 be76844f7b75
permissions -rw-r--r--
Source NAT working! Run (examples/netfilter-example.cc)
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /* 
     3  * Copyright (c) 2009 University of Texas at Dallas
     4  * 
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  * 
    18  * Author: Qasim Javed <qasim@utdallas.edu>
    19  */
    20 #include "ns3/log.h"
    21 #include "ns3/ipv4-header.h"
    22 #include "ns3/callback.h"
    23 #include "ns3/conntrack-tag.h"
    24 #include "ipv4-conntrack-l3-protocol.h"
    25 
    26 NS_LOG_COMPONENT_DEFINE ("Ipv4ConntrackL3Protocol");
    27 
    28 namespace ns3 {
    29 
    30 Ipv4ConntrackL3Protocol::Ipv4ConntrackL3Protocol ()
    31 {
    32 }
    33 
    34 uint32_t 
    35 Ipv4ConntrackL3Protocol::Ipv4Confirm (Hooks_t hookNumber, Ptr<Packet> packet, Ptr<NetDevice> in,
    36                       Ptr<NetDevice> out, ContinueCallback& ccb)
    37 {
    38   NS_LOG_DEBUG (":: Executing hook function Ipv4Confirm ::");
    39   /*ConntrackTag ctinfo;
    40   bool tagFound = packet->PeekPacketTag (ctinfo);
    41 
    42   if (!tagFound || ctinfo.GetConntrack () == IP_CT_RELATED + IP_CT_IS_REPLY)
    43   {
    44     NS_LOG_DEBUG ("Conntrack tag not found");
    45     return 0;
    46   }*/
    47 
    48   // Call conntrack helper here
    49 
    50   NS_ASSERT (!ccb.IsNull ());
    51   // NetfilterConntrackConfirm
    52   NS_LOG_DEBUG ("Invoking the ContinueCallback");
    53   ccb (packet);
    54 
    55   return 0;
    56 }
    57 
    58 uint32_t 
    59 Ipv4ConntrackL3Protocol::Ipv4ConntrackPreRoutingHook (Hooks_t hookNumber, Ptr<Packet> p, Ptr<NetDevice> in, Ptr<NetDevice> out, ContinueCallback& ccb)
    60 {
    61   return 0;
    62 }
    63 
    64 uint32_t 
    65 Ipv4ConntrackL3Protocol::Ipv4ConntrackInHook (Hooks_t hookNumber, Ptr<Packet> p, Ptr<NetDevice> in, Ptr<NetDevice> out, ContinueCallback& ccb)
    66 {
    67   return 0;
    68 }
    69 
    70 uint32_t 
    71 Ipv4ConntrackL3Protocol::Ipv4ConntrackOutHook (Hooks_t hookNumber, Ptr<Packet> p, Ptr<NetDevice> in, Ptr<NetDevice> out, ContinueCallback& ccb)
    72 {
    73   return 0;
    74 }
    75 
    76 uint32_t 
    77 Ipv4ConntrackL3Protocol::Ipv4ConntrackPostRoutingHook (Hooks_t hookNumber, Ptr<Packet> p, Ptr<NetDevice> in, Ptr<NetDevice> out, ContinueCallback& ccb)
    78 {
    79   return 0;
    80 }
    81 
    82 uint16_t 
    83 Ipv4ConntrackL3Protocol::RegisterPreRoutingHook ()
    84 {
    85   return 0;
    86 }
    87 
    88 uint16_t 
    89 Ipv4ConntrackL3Protocol::RegisterInHook ()
    90 {
    91   return 0;
    92 }
    93 
    94 uint16_t 
    95 Ipv4ConntrackL3Protocol::RegisterOutHook ()
    96 {
    97   return 0;
    98 }
    99 
   100 uint16_t 
   101 Ipv4ConntrackL3Protocol::RegisterPostRoutingHook ()
   102 {
   103   return 0;
   104 }
   105 
   106 bool 
   107 Ipv4ConntrackL3Protocol::PacketToTuple (Ptr<Packet> packet, NetfilterConntrackTuple& tuple)
   108 {
   109   Ipv4Header ipHeader;
   110 
   111   packet->PeekHeader (ipHeader);
   112 
   113   tuple.SetSource (ipHeader.GetSource ());
   114   tuple.SetDestination (ipHeader.GetDestination ());
   115 
   116   NS_LOG_DEBUG ("Ipv4 Packet To Tuple: " << "( " << tuple.GetSource () << "," << tuple.GetSourcePort () << "," << tuple.GetDestination () << "," << tuple.GetDestinationPort () << ")" );
   117 
   118   return true;
   119 }
   120 
   121 bool 
   122 Ipv4ConntrackL3Protocol::InvertTuple (NetfilterConntrackTuple& inverse, NetfilterConntrackTuple& orig)
   123 {
   124   inverse.SetSource (orig.GetDestination () );
   125   inverse.SetDestination (orig.GetSource () );
   126   return true;
   127 }
   128 
   129 
   130 
   131 }