src/internet-stack/netfilter-conntrack-tuple.h
author Qasim Javed <qasimj@gmail.com>
Thu Aug 06 01:55:49 2009 +0600 (2009-08-06)
changeset 4638 19aa5f9b4bdf
parent 4637 0882bb6eac0b
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 #ifndef NETFILTER_CONNTRACK_TUPLE_H
    21 #define NETFILTER_CONNTRACK_TUPLE_H
    22 
    23 #include "ns3/log.h"
    24 #include "ns3/ipv4-address.h"
    25 #include "ns3/ref-count-base.h"
    26 #include "ns3/object.h"
    27 #include "ip-conntrack-info.h"
    28 //#include "jhash.h"
    29 
    30 
    31 namespace ns3 {
    32 
    33 class Object;
    34 class Ipv4Address;
    35 
    36 class NetfilterConntrackTuple : public RefCountBase {
    37   public:
    38     NetfilterConntrackTuple ();
    39     NetfilterConntrackTuple (Ipv4Address src, uint16_t srcPort, Ipv4Address dst, uint16_t dstPort);
    40     bool operator== (const NetfilterConntrackTuple t) const;
    41     bool SourceEqual (NetfilterConntrackTuple t1, NetfilterConntrackTuple t2);
    42     bool DestinationEqual (NetfilterConntrackTuple t1, NetfilterConntrackTuple t2);
    43     NetfilterConntrackTuple Invert ();
    44 
    45     Ipv4Address GetSource () const;
    46     Ipv4Address GetDestination () const;
    47     uint16_t GetSourcePort () const;
    48     uint16_t GetDestinationPort () const;
    49     char * ToString () const;
    50     uint16_t GetDestinationProtocol () const;
    51     uint8_t GetDirection () const;
    52     uint16_t GetProtocol ();
    53 
    54     void SetSource (Ipv4Address source);
    55     void SetSourcePort (uint16_t source);
    56     void SetDestination (Ipv4Address destination);
    57     void SetDestinationPort (uint16_t destination);
    58     void SetProtocol (uint16_t protocol);
    59     void SetDirection (ConntrackDirection_t direction);
    60 
    61     void Print (std::ostream &os) const;
    62 
    63     NetfilterConntrackTuple& operator= (const NetfilterConntrackTuple&  tuple);
    64     friend std::ostream& operator << (std::ostream& os, NetfilterConntrackTuple const& tuple);
    65 
    66   private:
    67     Ipv4Address m_l3Source;
    68     uint16_t m_l3Protocol;
    69     uint16_t m_l4Source;
    70 
    71     Ipv4Address m_l3Destination;
    72     uint16_t m_l4Destination;
    73     uint8_t m_protocolNumber;
    74     uint8_t m_direction;
    75 };
    76 
    77 
    78 class ConntrackTupleHash : public std::unary_function<NetfilterConntrackTuple, size_t> {
    79 public:
    80   size_t operator()(const NetfilterConntrackTuple &x) const;
    81 };
    82 
    83 }
    84 #endif /* NETFILTER_CONNTRACK_TUPLE_H */