• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2013 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_SOCKET_INFO_H_
18 #define SHILL_SOCKET_INFO_H_
19 
20 #include <base/macros.h>
21 
22 #include "shill/net/ip_address.h"
23 
24 namespace shill {
25 
26 class SocketInfo {
27  public:
28   // These connection states (except kConnectionStateUnknown and
29   // kConnectionStateMax) are equivalent to and should be kept in sync with
30   // those defined in kernel/inlude/net/tcp_states.h
31   enum ConnectionState {
32     kConnectionStateUnknown = -1,
33     kConnectionStateEstablished = 1,
34     kConnectionStateSynSent,
35     kConnectionStateSynRecv,
36     kConnectionStateFinWait1,
37     kConnectionStateFinWait2,
38     kConnectionStateTimeWait,
39     kConnectionStateClose,
40     kConnectionStateCloseWait,
41     kConnectionStateLastAck,
42     kConnectionStateListen,
43     kConnectionStateClosing,
44     kConnectionStateMax,
45   };
46 
47   // These timer states (except kTimerStateUnknown and kTimerStateMax) are
48   // equivalent to and should be kept in sync with those specified in
49   // kernel/Documentation/networking/proc_net_tcp.txt
50   enum TimerState {
51     kTimerStateUnknown = -1,
52     kTimerStateNoTimerPending = 0,
53     kTimerStateRetransmitTimerPending,
54     kTimerStateAnotherTimerPending,
55     kTimerStateInTimeWaitState,
56     kTimerStateZeroWindowProbeTimerPending,
57     kTimerStateMax,
58   };
59 
60   SocketInfo();
61   SocketInfo(ConnectionState connection_state,
62              const IPAddress& local_ip_address,
63              uint16_t local_port,
64              const IPAddress& remote_ip_address,
65              uint16_t remote_port,
66              uint64_t transmit_queue_value,
67              uint64_t receive_queue_value,
68              TimerState timer_state);
69   SocketInfo(const SocketInfo& socket_info);
70   ~SocketInfo();
71 
72   SocketInfo& operator=(const SocketInfo& socket_info);
73 
74   // Returns true if this socket info and |socket_info| refer to the same
75   // socket, i.e. both have the same local address, local port, remote address,
76   // and remote port.
77   bool IsSameSocketAs(const SocketInfo& socket_info) const;
78 
connection_state()79   ConnectionState connection_state() const { return connection_state_; }
set_connection_state(ConnectionState connection_state)80   void set_connection_state(ConnectionState connection_state) {
81     connection_state_ = connection_state;
82   }
83 
local_ip_address()84   const IPAddress& local_ip_address() const { return local_ip_address_; }
set_local_ip_address(const IPAddress & local_ip_address)85   void set_local_ip_address(const IPAddress& local_ip_address) {
86     local_ip_address_ = local_ip_address;
87   }
88 
local_port()89   uint16_t local_port() const { return local_port_; }
set_local_port(uint16_t local_port)90   void set_local_port(uint16_t local_port) { local_port_ = local_port; }
91 
remote_ip_address()92   const IPAddress& remote_ip_address() const { return remote_ip_address_; }
set_remote_ip_address(const IPAddress & remote_ip_address)93   void set_remote_ip_address(const IPAddress& remote_ip_address) {
94     remote_ip_address_ = remote_ip_address;
95   }
96 
remote_port()97   uint16_t remote_port() const { return remote_port_; }
set_remote_port(uint16_t remote_port)98   void set_remote_port(uint16_t remote_port) { remote_port_ = remote_port; }
99 
transmit_queue_value()100   uint64_t transmit_queue_value() const { return transmit_queue_value_; }
set_transmit_queue_value(uint64_t transmit_queue_value)101   void set_transmit_queue_value(uint64_t transmit_queue_value) {
102     transmit_queue_value_ = transmit_queue_value;
103   }
104 
receive_queue_value()105   uint64_t receive_queue_value() const { return receive_queue_value_; }
set_receive_queue_value(uint64_t receive_queue_value)106   void set_receive_queue_value(uint64_t receive_queue_value) {
107     receive_queue_value_ = receive_queue_value;
108   }
109 
timer_state()110   TimerState timer_state() const { return timer_state_; }
set_timer_state(TimerState timer_state)111   void set_timer_state(TimerState timer_state) { timer_state_ = timer_state; }
112 
113  private:
114   ConnectionState connection_state_;
115   IPAddress local_ip_address_;
116   uint16_t local_port_;
117   IPAddress remote_ip_address_;
118   uint16_t remote_port_;
119   uint64_t transmit_queue_value_;
120   uint64_t receive_queue_value_;
121   TimerState timer_state_;
122 
123   // No DISALLOW_COPY_AND_ASSIGN(SocketInfo) as SocketInfo needs to be kept in
124   // STL containers.
125 };
126 
127 }  // namespace shill
128 
129 #endif  // SHILL_SOCKET_INFO_H_
130