blob: a2e3d76e853dd7d569c8ece331fcacca6b91eb5e [file] [log] [blame]
Paul Stewart75e89d22011-08-01 10:00:02 -07001// 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 Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_ROUTING_TABLE_ENTRY_H_
6#define SHILL_ROUTING_TABLE_ENTRY_H_
Paul Stewart75e89d22011-08-01 10:00:02 -07007
Peter Qiu8d6b5972014-10-28 15:33:34 -07008#include "shill/net/ip_address.h"
Paul Stewart75e89d22011-08-01 10:00:02 -07009
10namespace 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=.
15struct RoutingTableEntry {
16 public:
Paul Stewarte93b0382012-04-24 13:11:28 -070017 static const int kDefaultTag = -1;
18
Paul Stewart75e89d22011-08-01 10:00:02 -070019 RoutingTableEntry()
Paul Stewart7355ce12011-09-02 10:47:01 -070020 : dst(IPAddress::kFamilyUnknown),
21 src(IPAddress::kFamilyUnknown),
22 gateway(IPAddress::kFamilyUnknown),
Paul Stewart75e89d22011-08-01 10:00:02 -070023 metric(0),
24 scope(0),
Paul Stewarte93b0382012-04-24 13:11:28 -070025 from_rtnl(false),
26 tag(kDefaultTag) {}
Paul Stewart75e89d22011-08-01 10:00:02 -070027
28 RoutingTableEntry(const IPAddress &dst_in,
Paul Stewart75e89d22011-08-01 10:00:02 -070029 const IPAddress &src_in,
Paul Stewart75e89d22011-08-01 10:00:02 -070030 const IPAddress &gateway_in,
Ben Chan7fab8972014-08-10 17:14:46 -070031 uint32_t metric_in,
Paul Stewart75e89d22011-08-01 10:00:02 -070032 unsigned char scope_in,
33 bool from_rtnl_in)
Paul Stewart9e3fcd72011-08-26 15:46:16 -070034 : dst(dst_in),
35 src(src_in),
36 gateway(gateway_in),
Paul Stewart75e89d22011-08-01 10:00:02 -070037 metric(metric_in),
38 scope(scope_in),
Paul Stewarte93b0382012-04-24 13:11:28 -070039 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 Chan7fab8972014-08-10 17:14:46 -070045 uint32_t metric_in,
Paul Stewarte93b0382012-04-24 13:11:28 -070046 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 Stewart75e89d22011-08-01 10:00:02 -070056
57 RoutingTableEntry(const RoutingTableEntry &b)
Paul Stewart9e3fcd72011-08-26 15:46:16 -070058 : dst(b.dst),
59 src(b.src),
60 gateway(b.gateway),
Paul Stewart75e89d22011-08-01 10:00:02 -070061 metric(b.metric),
62 scope(b.scope),
Paul Stewarte93b0382012-04-24 13:11:28 -070063 from_rtnl(b.from_rtnl),
64 tag(b.tag) {}
Paul Stewart75e89d22011-08-01 10:00:02 -070065
66 RoutingTableEntry &operator=(const RoutingTableEntry &b) {
Paul Stewart9e3fcd72011-08-26 15:46:16 -070067 dst = b.dst;
68 src = b.src;
69 gateway = b.gateway;
Paul Stewart75e89d22011-08-01 10:00:02 -070070 metric = b.metric;
71 scope = b.scope;
72 from_rtnl = b.from_rtnl;
Paul Stewarte93b0382012-04-24 13:11:28 -070073 tag = b.tag;
Paul Stewart75e89d22011-08-01 10:00:02 -070074
75 return *this;
76 }
77
78 ~RoutingTableEntry() {}
79
80 bool Equals(const RoutingTableEntry &b) {
81 return (dst.Equals(b.dst) &&
Paul Stewart75e89d22011-08-01 10:00:02 -070082 src.Equals(b.src) &&
Paul Stewart75e89d22011-08-01 10:00:02 -070083 gateway.Equals(b.gateway) &&
84 metric == b.metric &&
85 scope == b.scope &&
Paul Stewarte93b0382012-04-24 13:11:28 -070086 from_rtnl == b.from_rtnl &&
87 tag == b.tag);
Paul Stewart75e89d22011-08-01 10:00:02 -070088 }
89
90 IPAddress dst;
Paul Stewart75e89d22011-08-01 10:00:02 -070091 IPAddress src;
Paul Stewart75e89d22011-08-01 10:00:02 -070092 IPAddress gateway;
Ben Chan7fab8972014-08-10 17:14:46 -070093 uint32_t metric;
Paul Stewart75e89d22011-08-01 10:00:02 -070094 unsigned char scope;
95 bool from_rtnl;
Paul Stewarte93b0382012-04-24 13:11:28 -070096 int tag;
Paul Stewart75e89d22011-08-01 10:00:02 -070097};
98
99} // namespace shill
100
101
Ben Chanc45688b2014-07-02 23:50:45 -0700102#endif // SHILL_ROUTING_TABLE_ENTRY_H_