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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_ROUTING_TABLE_ENTRY_H_ |
| 6 | #define SHILL_ROUTING_TABLE_ENTRY_H_ |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 7 | |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 8 | #include "shill/net/ip_address.h" |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 9 | |
| 10 | namespace shill { |
| 11 | |
| 12 | // Holds table entries for routing. These are held in an STL vector |
| 13 | // in the RoutingTable object, hence the need for copy contructor and |
| 14 | // operator=. |
| 15 | struct RoutingTableEntry { |
| 16 | public: |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 17 | static const int kDefaultTag = -1; |
| 18 | |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 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), |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 25 | from_rtnl(false), |
| 26 | tag(kDefaultTag) {} |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 27 | |
| 28 | RoutingTableEntry(const IPAddress &dst_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 29 | const IPAddress &src_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 30 | const IPAddress &gateway_in, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 31 | uint32_t metric_in, |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 32 | unsigned char scope_in, |
| 33 | bool from_rtnl_in) |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 34 | : dst(dst_in), |
| 35 | src(src_in), |
| 36 | gateway(gateway_in), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 37 | metric(metric_in), |
| 38 | scope(scope_in), |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 39 | from_rtnl(from_rtnl_in), |
| 40 | tag(kDefaultTag) {} |
| 41 | |
| 42 | RoutingTableEntry(const IPAddress &dst_in, |
| 43 | const IPAddress &src_in, |
| 44 | const IPAddress &gateway_in, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 45 | uint32_t metric_in, |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 46 | unsigned char scope_in, |
| 47 | bool from_rtnl_in, |
| 48 | int tag_in) |
| 49 | : dst(dst_in), |
| 50 | src(src_in), |
| 51 | gateway(gateway_in), |
| 52 | metric(metric_in), |
| 53 | scope(scope_in), |
| 54 | from_rtnl(from_rtnl_in), |
| 55 | tag(tag_in) {} |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 56 | |
| 57 | RoutingTableEntry(const RoutingTableEntry &b) |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 58 | : dst(b.dst), |
| 59 | src(b.src), |
| 60 | gateway(b.gateway), |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 61 | metric(b.metric), |
| 62 | scope(b.scope), |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 63 | from_rtnl(b.from_rtnl), |
| 64 | tag(b.tag) {} |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 65 | |
| 66 | RoutingTableEntry &operator=(const RoutingTableEntry &b) { |
Paul Stewart | 9e3fcd7 | 2011-08-26 15:46:16 -0700 | [diff] [blame] | 67 | dst = b.dst; |
| 68 | src = b.src; |
| 69 | gateway = b.gateway; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 70 | metric = b.metric; |
| 71 | scope = b.scope; |
| 72 | from_rtnl = b.from_rtnl; |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 73 | tag = b.tag; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 74 | |
| 75 | return *this; |
| 76 | } |
| 77 | |
| 78 | ~RoutingTableEntry() {} |
| 79 | |
| 80 | bool Equals(const RoutingTableEntry &b) { |
| 81 | return (dst.Equals(b.dst) && |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 82 | src.Equals(b.src) && |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 83 | gateway.Equals(b.gateway) && |
| 84 | metric == b.metric && |
| 85 | scope == b.scope && |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 86 | from_rtnl == b.from_rtnl && |
| 87 | tag == b.tag); |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | IPAddress dst; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 91 | IPAddress src; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 92 | IPAddress gateway; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 93 | uint32_t metric; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 94 | unsigned char scope; |
| 95 | bool from_rtnl; |
Paul Stewart | e93b038 | 2012-04-24 13:11:28 -0700 | [diff] [blame] | 96 | int tag; |
Paul Stewart | 75e89d2 | 2011-08-01 10:00:02 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace shill |
| 100 | |
| 101 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 102 | #endif // SHILL_ROUTING_TABLE_ENTRY_H_ |