blob: 7e1b263451a3ebc3003bae29b965411756710707 [file] [log] [blame]
Ben Chan086d9802013-04-02 16:39:48 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_SOCKET_INFO_H_
6#define SHILL_SOCKET_INFO_H_
7
8#include <base/basictypes.h>
9
10#include "shill/ip_address.h"
11
12namespace shill {
13
14class SocketInfo {
15 public:
16 // These connection states (except kConnectionStateUnknown and
17 // kConnectionStateMax) are equivalent to and should be kept in sync with
18 // those defined in kernel/inlude/net/tcp_states.h
19 enum ConnectionState {
20 kConnectionStateUnknown = -1,
21 kConnectionStateEstablished = 1,
22 kConnectionStateSynSent,
23 kConnectionStateSynRecv,
24 kConnectionStateFinWait1,
25 kConnectionStateFinWait2,
26 kConnectionStateTimeWait,
27 kConnectionStateClose,
28 kConnectionStateCloseWait,
29 kConnectionStateLastAck,
30 kConnectionStateListen,
31 kConnectionStateClosing,
32 kConnectionStateMax,
33 };
34
35 // These timer states (except kTimerStateUnknown and kTimerStateMax) are
36 // equivalent to and should be kept in sync with those specified in
37 // kernel/Documentation/networking/proc_net_tcp.txt
38 enum TimerState {
39 kTimerStateUnknown = -1,
40 kTimerStateNoTimerPending = 0,
41 kTimerStateRetransmitTimerPending,
42 kTimerStateAnotherTimerPending,
43 kTimerStateInTimeWaitState,
44 kTimerStateZeroWindowProbeTimerPending,
45 kTimerStateMax,
46 };
47
48 SocketInfo();
49 SocketInfo(ConnectionState connection_state,
50 const IPAddress &local_ip_address,
51 uint16 local_port,
52 const IPAddress &remote_ip_address,
53 uint16 remote_port,
54 uint64 transmit_queue_value,
55 uint64 receive_queue_value,
56 TimerState timer_state);
57 SocketInfo(const SocketInfo &socket_info);
58 ~SocketInfo();
59
60 SocketInfo &operator=(const SocketInfo &socket_info);
61
62 // Returns true if this socket info and |socket_info| refer to the same
63 // socket, i.e. both have the same local address, local port, remote address,
64 // and remote port.
65 bool IsSameSocketAs(const SocketInfo &socket_info) const;
66
67 ConnectionState connection_state() const { return connection_state_; }
68 void set_connection_state(ConnectionState connection_state) {
69 connection_state_ = connection_state;
70 }
71
72 const IPAddress &local_ip_address() const { return local_ip_address_; }
73 void set_local_ip_address(const IPAddress &local_ip_address) {
74 local_ip_address_ = local_ip_address;
75 }
76
77 uint16 local_port() const { return local_port_; }
78 void set_local_port(uint16 local_port) { local_port_ = local_port; }
79
80 const IPAddress &remote_ip_address() const { return remote_ip_address_; }
81 void set_remote_ip_address(const IPAddress &remote_ip_address) {
82 remote_ip_address_ = remote_ip_address;
83 }
84
85 uint16 remote_port() const { return remote_port_; }
86 void set_remote_port(uint16 remote_port) { remote_port_ = remote_port; }
87
88 uint64 transmit_queue_value() const { return transmit_queue_value_; }
89 void set_transmit_queue_value(uint64 transmit_queue_value) {
90 transmit_queue_value_ = transmit_queue_value;
91 }
92
93 uint64 receive_queue_value() const { return receive_queue_value_; }
94 void set_receive_queue_value(uint64 receive_queue_value) {
95 receive_queue_value_ = receive_queue_value;
96 }
97
98 TimerState timer_state() const { return timer_state_; }
99 void set_timer_state(TimerState timer_state) { timer_state_ = timer_state; }
100
101 private:
102 ConnectionState connection_state_;
103 IPAddress local_ip_address_;
104 uint16 local_port_;
105 IPAddress remote_ip_address_;
106 uint16 remote_port_;
107 uint64 transmit_queue_value_;
108 uint64 receive_queue_value_;
109 TimerState timer_state_;
110
111 // No DISALLOW_COPY_AND_ASSIGN(SocketInfo) as SocketInfo needs to be kept in
112 // STL containers.
113};
114
115} // namespace shill
116
117#endif // SHILL_SOCKET_INFO_H_