Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 1 | // 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 | |
| 16 | namespace shill { |
| 17 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 18 | class DeviceInfo; |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 19 | class Resolver; |
| 20 | class RoutingTable; |
| 21 | class RTNLHandler; |
| 22 | |
| 23 | // The Conneciton maintains the implemented state of an IPConfig, e.g, |
| 24 | // the IP address, routing table and DNS table entries. |
| 25 | class Connection : public base::RefCounted<Connection> { |
| 26 | public: |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 27 | Connection(int interface_index, |
| 28 | const std::string &interface_name, |
| 29 | const DeviceInfo *device_info); |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 30 | 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. |
| 34 | void UpdateFromIPConfig(const IPConfigRefPtr &config); |
| 35 | |
| 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_; } |
| 39 | void SetDefault(bool is_default); |
| 40 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame^] | 41 | const std::string &interface_name() const { return interface_name_; } |
| 42 | const std::vector<std::string> &dns_servers() const { return dns_servers_; } |
| 43 | |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 44 | private: |
| 45 | friend class ConnectionTest; |
| 46 | FRIEND_TEST(ConnectionTest, InitState); |
| 47 | FRIEND_TEST(ConnectionTest, AddConfig); |
| 48 | FRIEND_TEST(ConnectionTest, AddConfigReverse); |
| 49 | FRIEND_TEST(ConnectionTest, Destructor); |
| 50 | |
| 51 | static const uint32 kDefaultMetric; |
Paul Stewart | 7cfca04 | 2011-12-08 14:18:17 -0800 | [diff] [blame] | 52 | static const uint32 kNonDefaultMetricBase; |
| 53 | |
| 54 | uint32 GetMetric(bool is_default); |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 55 | |
| 56 | bool is_default_; |
| 57 | int interface_index_; |
| 58 | const std::string interface_name_; |
| 59 | std::vector<std::string> dns_servers_; |
| 60 | std::vector<std::string> dns_domain_search_; |
| 61 | |
| 62 | // Store cached copies of singletons for speed/ease of testing |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 63 | const DeviceInfo *device_info_; |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 64 | Resolver *resolver_; |
| 65 | RoutingTable *routing_table_; |
| 66 | RTNLHandler *rtnl_handler_; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(Connection); |
| 69 | }; |
| 70 | |
| 71 | } // namespace shill |
| 72 | |
| 73 | #endif // SHILL_CONNECTION_ |