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: |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 19 | static const int kDefaultTag = -1; |
| 20 | |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 21 | RoutingTableEntry() |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 22 | : dst(IPAddress::kFamilyUnknown), |
| 23 | src(IPAddress::kFamilyUnknown), |
| 24 | gateway(IPAddress::kFamilyUnknown), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 25 | metric(0), |
| 26 | scope(0), |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 27 | from_rtnl(false), |
| 28 | tag(kDefaultTag) {} |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 29 | |
| 30 | RoutingTableEntry(const IPAddress &dst_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 31 | const IPAddress &src_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 32 | const IPAddress &gateway_in, |
| 33 | uint32 metric_in, |
| 34 | unsigned char scope_in, |
| 35 | bool from_rtnl_in) |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 36 | : dst(dst_in), |
| 37 | src(src_in), |
| 38 | gateway(gateway_in), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 39 | metric(metric_in), |
| 40 | scope(scope_in), |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 41 | from_rtnl(from_rtnl_in), |
| 42 | tag(kDefaultTag) {} |
| 43 | |
| 44 | RoutingTableEntry(const IPAddress &dst_in, |
| 45 | const IPAddress &src_in, |
| 46 | const IPAddress &gateway_in, |
| 47 | uint32 metric_in, |
| 48 | unsigned char scope_in, |
| 49 | bool from_rtnl_in, |
| 50 | int tag_in) |
| 51 | : dst(dst_in), |
| 52 | src(src_in), |
| 53 | gateway(gateway_in), |
| 54 | metric(metric_in), |
| 55 | scope(scope_in), |
| 56 | from_rtnl(from_rtnl_in), |
| 57 | tag(tag_in) {} |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 58 | |
| 59 | RoutingTableEntry(const RoutingTableEntry &b) |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 60 | : dst(b.dst), |
| 61 | src(b.src), |
| 62 | gateway(b.gateway), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 63 | metric(b.metric), |
| 64 | scope(b.scope), |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 65 | from_rtnl(b.from_rtnl), |
| 66 | tag(b.tag) {} |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 67 | |
| 68 | RoutingTableEntry &operator=(const RoutingTableEntry &b) { |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 69 | dst = b.dst; |
| 70 | src = b.src; |
| 71 | gateway = b.gateway; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 72 | metric = b.metric; |
| 73 | scope = b.scope; |
| 74 | from_rtnl = b.from_rtnl; |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 75 | tag = b.tag; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 76 | |
| 77 | return *this; |
| 78 | } |
| 79 | |
| 80 | ~RoutingTableEntry() {} |
| 81 | |
| 82 | bool Equals(const RoutingTableEntry &b) { |
| 83 | return (dst.Equals(b.dst) && |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 84 | src.Equals(b.src) && |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 85 | gateway.Equals(b.gateway) && |
| 86 | metric == b.metric && |
| 87 | scope == b.scope && |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 88 | from_rtnl == b.from_rtnl && |
| 89 | tag == b.tag); |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | IPAddress dst; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 93 | IPAddress src; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 94 | IPAddress gateway; |
| 95 | uint32 metric; |
| 96 | unsigned char scope; |
| 97 | bool from_rtnl; |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 98 | int tag; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace shill |
| 102 | |
| 103 | |
| 104 | #endif // SHILL_ROUTING_TABLE_ENTRY_ |