blob: c8312e42f033ea449b321d8dcc2bb5f075281d93 [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,
Ben Chan7fab8972014-08-10 17:14:46 -070051 uint16_t local_port,
Ben Chan086d9802013-04-02 16:39:48 -070052 const IPAddress &remote_ip_address,
Ben Chan7fab8972014-08-10 17:14:46 -070053 uint16_t remote_port,
54 uint64_t transmit_queue_value,
55 uint64_t receive_queue_value,
Ben Chan086d9802013-04-02 16:39:48 -070056 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
Ben Chan7fab8972014-08-10 17:14:46 -070077 uint16_t local_port() const { return local_port_; }
78 void set_local_port(uint16_t local_port) { local_port_ = local_port; }
Ben Chan086d9802013-04-02 16:39:48 -070079
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
Ben Chan7fab8972014-08-10 17:14:46 -070085 uint16_t remote_port() const { return remote_port_; }
86 void set_remote_port(uint16_t remote_port) { remote_port_ = remote_port; }
Ben Chan086d9802013-04-02 16:39:48 -070087
Ben Chan7fab8972014-08-10 17:14:46 -070088 uint64_t transmit_queue_value() const { return transmit_queue_value_; }
89 void set_transmit_queue_value(uint64_t transmit_queue_value) {
Ben Chan086d9802013-04-02 16:39:48 -070090 transmit_queue_value_ = transmit_queue_value;
91 }
92
Ben Chan7fab8972014-08-10 17:14:46 -070093 uint64_t receive_queue_value() const { return receive_queue_value_; }
94 void set_receive_queue_value(uint64_t receive_queue_value) {
Ben Chan086d9802013-04-02 16:39:48 -070095 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_;
Ben Chan7fab8972014-08-10 17:14:46 -0700104 uint16_t local_port_;
Ben Chan086d9802013-04-02 16:39:48 -0700105 IPAddress remote_ip_address_;
Ben Chan7fab8972014-08-10 17:14:46 -0700106 uint16_t remote_port_;
107 uint64_t transmit_queue_value_;
108 uint64_t receive_queue_value_;
Ben Chan086d9802013-04-02 16:39:48 -0700109 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_