blob: 93a903a837d377ae8c2a8d43ab8b567a0f1645d0 [file] [log] [blame]
Paul Stewartdd60e452011-08-08 11:38:36 -07001// Copyright (c) 2011 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_CONNECTION_
6#define SHILL_CONNECTION_
7
8#include <string>
9#include <vector>
10
11#include <base/memory/ref_counted.h>
12#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
14#include "shill/refptr_types.h"
15
16namespace shill {
17
Paul Stewart9a908082011-08-31 12:18:48 -070018class DeviceInfo;
Paul Stewartdd60e452011-08-08 11:38:36 -070019class Resolver;
20class RoutingTable;
21class RTNLHandler;
22
23// The Conneciton maintains the implemented state of an IPConfig, e.g,
24// the IP address, routing table and DNS table entries.
25class Connection : public base::RefCounted<Connection> {
26 public:
Paul Stewart9a908082011-08-31 12:18:48 -070027 Connection(int interface_index,
28 const std::string &interface_name,
29 const DeviceInfo *device_info);
Paul Stewartdd60e452011-08-08 11:38:36 -070030 virtual ~Connection();
31
32 // Add the contents of an IPConfig reference to the list of managed state.
33 // This will replace all previous state for this address family.
Paul Stewartc1dec4d2011-12-08 15:25:28 -080034 virtual void UpdateFromIPConfig(const IPConfigRefPtr &config);
Paul Stewartdd60e452011-08-08 11:38:36 -070035
36 // Sets the current connection as "default", i.e., routes and DNS entries
37 // should be used by all system components that don't select explicitly.
38 bool is_default() const { return is_default_; }
Paul Stewartc1dec4d2011-12-08 15:25:28 -080039 virtual void SetIsDefault(bool is_default);
Paul Stewartdd60e452011-08-08 11:38:36 -070040
Paul Stewartc8f4bef2011-12-13 09:45:51 -080041 virtual const std::string &interface_name() const { return interface_name_; }
42 virtual const std::vector<std::string> &dns_servers() const {
43 return dns_servers_;
44 }
45
46 // Request to accept traffic routed to this connection even if it is not
47 // the default. This request is ref-counted so the caller must call
48 // ReleaseRouting() when they no longer need this facility.
49 virtual void RequestRouting();
50 virtual void ReleaseRouting();
Paul Stewartbe5f5b32011-12-07 17:11:11 -080051
Paul Stewartdd60e452011-08-08 11:38:36 -070052 private:
53 friend class ConnectionTest;
54 FRIEND_TEST(ConnectionTest, InitState);
55 FRIEND_TEST(ConnectionTest, AddConfig);
56 FRIEND_TEST(ConnectionTest, AddConfigReverse);
57 FRIEND_TEST(ConnectionTest, Destructor);
58
59 static const uint32 kDefaultMetric;
Paul Stewart7cfca042011-12-08 14:18:17 -080060 static const uint32 kNonDefaultMetricBase;
61
62 uint32 GetMetric(bool is_default);
Paul Stewartdd60e452011-08-08 11:38:36 -070063
64 bool is_default_;
Paul Stewartc8f4bef2011-12-13 09:45:51 -080065 int routing_request_count_;
Paul Stewartdd60e452011-08-08 11:38:36 -070066 int interface_index_;
67 const std::string interface_name_;
68 std::vector<std::string> dns_servers_;
69 std::vector<std::string> dns_domain_search_;
70
71 // Store cached copies of singletons for speed/ease of testing
Paul Stewart9a908082011-08-31 12:18:48 -070072 const DeviceInfo *device_info_;
Paul Stewartdd60e452011-08-08 11:38:36 -070073 Resolver *resolver_;
74 RoutingTable *routing_table_;
75 RTNLHandler *rtnl_handler_;
76
77 DISALLOW_COPY_AND_ASSIGN(Connection);
78};
79
80} // namespace shill
81
82#endif // SHILL_CONNECTION_