Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -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_ROUTING_TABLE_ENTRY_ |
| 6 | #define SHILL_ROUTING_TABLE_ENTRY_ |
| 7 | |
| 8 | #include <base/basictypes.h> |
| 9 | |
| 10 | #include "shill/ip_address.h" |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | // Holds table entries for routing. These are held in an STL vector |
| 15 | // in the RoutingTable object, hence the need for copy contructor and |
| 16 | // operator=. |
| 17 | struct RoutingTableEntry { |
| 18 | public: |
| 19 | RoutingTableEntry() |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 20 | : dst(IPAddress::kFamilyUnknown), |
| 21 | src(IPAddress::kFamilyUnknown), |
| 22 | gateway(IPAddress::kFamilyUnknown), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 23 | metric(0), |
| 24 | scope(0), |
| 25 | from_rtnl(false) {} |
| 26 | |
| 27 | RoutingTableEntry(const IPAddress &dst_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 28 | const IPAddress &src_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 29 | const IPAddress &gateway_in, |
| 30 | uint32 metric_in, |
| 31 | unsigned char scope_in, |
| 32 | bool from_rtnl_in) |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 33 | : dst(dst_in), |
| 34 | src(src_in), |
| 35 | gateway(gateway_in), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 36 | metric(metric_in), |
| 37 | scope(scope_in), |
| 38 | from_rtnl(from_rtnl_in) {} |
| 39 | |
| 40 | RoutingTableEntry(const RoutingTableEntry &b) |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 41 | : dst(b.dst), |
| 42 | src(b.src), |
| 43 | gateway(b.gateway), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 44 | metric(b.metric), |
| 45 | scope(b.scope), |
| 46 | from_rtnl(b.from_rtnl) {} |
| 47 | |
| 48 | RoutingTableEntry &operator=(const RoutingTableEntry &b) { |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 49 | dst = b.dst; |
| 50 | src = b.src; |
| 51 | gateway = b.gateway; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 52 | metric = b.metric; |
| 53 | scope = b.scope; |
| 54 | from_rtnl = b.from_rtnl; |
| 55 | |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | ~RoutingTableEntry() {} |
| 60 | |
| 61 | bool Equals(const RoutingTableEntry &b) { |
| 62 | return (dst.Equals(b.dst) && |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 63 | src.Equals(b.src) && |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 64 | gateway.Equals(b.gateway) && |
| 65 | metric == b.metric && |
| 66 | scope == b.scope && |
| 67 | from_rtnl == b.from_rtnl); |
| 68 | } |
| 69 | |
| 70 | IPAddress dst; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 71 | IPAddress src; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 72 | IPAddress gateway; |
| 73 | uint32 metric; |
| 74 | unsigned char scope; |
| 75 | bool from_rtnl; |
| 76 | }; |
| 77 | |
| 78 | } // namespace shill |
| 79 | |
| 80 | |
| 81 | #endif // SHILL_ROUTING_TABLE_ENTRY_ |