OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium 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 NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| 6 #define NET_DNS_ADDRESS_SORTER_POSIX_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "net/base/address_list.h" |
| 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_export.h" |
| 15 #include "net/base/net_util.h" |
| 16 #include "net/base/network_change_notifier.h" |
| 17 #include "net/dns/address_sorter.h" |
| 18 |
| 19 namespace net { |
| 20 |
| 21 class ClientSocketFactory; |
| 22 |
| 23 // Generic policy entry. |
| 24 struct PolicyEntry { |
| 25 // IPv4 addresses must be mapped to IPv6. |
| 26 unsigned char prefix[kIPv6AddressSize]; |
| 27 unsigned prefix_length; |
| 28 unsigned value; |
| 29 }; |
| 30 |
| 31 typedef std::vector<PolicyEntry> PolicyTable; |
| 32 |
| 33 enum AddressScope { |
| 34 SCOPE_UNDEFINED = 0, |
| 35 SCOPE_NODELOCAL = 1, |
| 36 SCOPE_LINKLOCAL = 2, |
| 37 SCOPE_SITELOCAL = 5, |
| 38 SCOPE_ORGLOCAL = 8, |
| 39 SCOPE_GLOBAL = 14, |
| 40 }; |
| 41 |
| 42 struct SourceAddressInfo { |
| 43 // Values read from policy tables. |
| 44 AddressScope scope; |
| 45 unsigned label; |
| 46 |
| 47 // Values from the OS, matter only if more than one source address is used. |
| 48 unsigned prefix_length; |
| 49 bool deprecated; // vs. preferred RFC4862 |
| 50 bool home; // vs. care-of RFC6275 |
| 51 bool native; |
| 52 }; |
| 53 |
| 54 typedef std::map<IPAddressNumber, SourceAddressInfo> SourceAddressMap; |
| 55 |
| 56 // This implementation uses explicit policy to perform the sorting. It is not |
| 57 // thread-safe and always completes synchronously. |
| 58 class NET_EXPORT_PRIVATE AddressSorterPosix |
| 59 : public AddressSorter, |
| 60 public base::NonThreadSafe, |
| 61 public NetworkChangeNotifier::IPAddressObserver { |
| 62 public: |
| 63 explicit AddressSorterPosix(ClientSocketFactory* socket_factory); |
| 64 virtual ~AddressSorterPosix(); |
| 65 |
| 66 virtual void Sort(const AddressList& list, |
| 67 const CallbackType& callback) const OVERRIDE; |
| 68 |
| 69 private: |
| 70 friend class AddressSorterPosixTest; |
| 71 |
| 72 // NetworkChangeNotifier::IPAddressObserver: |
| 73 virtual void OnIPAddressChanged() OVERRIDE; |
| 74 |
| 75 // Fills |info| with values for |address| from policy tables. |
| 76 void FillPolicy(const IPAddressNumber& address, |
| 77 SourceAddressInfo* info) const; |
| 78 |
| 79 // Mutable to allow using default values for source addresses which were not |
| 80 // found in most recent OnIPAddressChanged. |
| 81 mutable SourceAddressMap source_map_; |
| 82 |
| 83 ClientSocketFactory* socket_factory_; |
| 84 PolicyTable precedence_table_; |
| 85 PolicyTable label_table_; |
| 86 PolicyTable ipv4_scope_table_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(AddressSorterPosix); |
| 89 }; |
| 90 |
| 91 } // namespace net |
| 92 |
| 93 #endif // NET_DNS_ADDRESS_SORTER_POSIX_H_ |
OLD | NEW |