blob: 8a42de739c9d0d8a12b525571e1a2abba76f54e0 [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
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
12namespace 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=.
17struct RoutingTableEntry {
18 public:
Paul Stewarte93b0382012-04-24 13:11:28 -070019 static const int kDefaultTag = -1;
20
Paul Stewart75e89d22011-08-01 10:00:02 -070021 RoutingTableEntry()
Paul Stewart7355ce12011-09-02 10:47:01 -070022 : dst(IPAddress::kFamilyUnknown),
23 src(IPAddress::kFamilyUnknown),
24 gateway(IPAddress::kFamilyUnknown),
Paul Stewart75e89d22011-08-01 10:00:02 -070025 metric(0),
26 scope(0),
Paul Stewarte93b0382012-04-24 13:11:28 -070027 from_rtnl(false),
28 tag(kDefaultTag) {}
Paul Stewart75e89d22011-08-01 10:00:02 -070029
30 RoutingTableEntry(const IPAddress &dst_in,
Paul Stewart75e89d22011-08-01 10:00:02 -070031 const IPAddress &src_in,
Paul Stewart75e89d22011-08-01 10:00:02 -070032 const IPAddress &gateway_in,
33 uint32 metric_in,
34 unsigned char scope_in,
35 bool from_rtnl_in)
Paul Stewart9e3fcd72011-08-26 15:46:16 -070036 : dst(dst_in),
37 src(src_in),
38 gateway(gateway_in),
Paul Stewart75e89d22011-08-01 10:00:02 -070039 metric(metric_in),
40 scope(scope_in),
Paul Stewarte93b0382012-04-24 13:11:28 -070041 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 Stewart75e89d22011-08-01 10:00:02 -070058
59 RoutingTableEntry(const RoutingTableEntry &b)
Paul Stewart9e3fcd72011-08-26 15:46:16 -070060 : dst(b.dst),
61 src(b.src),
62 gateway(b.gateway),
Paul Stewart75e89d22011-08-01 10:00:02 -070063 metric(b.metric),
64 scope(b.scope),
Paul Stewarte93b0382012-04-24 13:11:28 -070065 from_rtnl(b.from_rtnl),
66 tag(b.tag) {}
Paul Stewart75e89d22011-08-01 10:00:02 -070067
68 RoutingTableEntry &operator=(const RoutingTableEntry &b) {
Paul Stewart9e3fcd72011-08-26 15:46:16 -070069 dst = b.dst;
70 src = b.src;
71 gateway = b.gateway;
Paul Stewart75e89d22011-08-01 10:00:02 -070072 metric = b.metric;
73 scope = b.scope;
74 from_rtnl = b.from_rtnl;
Paul Stewarte93b0382012-04-24 13:11:28 -070075 tag = b.tag;
Paul Stewart75e89d22011-08-01 10:00:02 -070076
77 return *this;
78 }
79
80 ~RoutingTableEntry() {}
81
82 bool Equals(const RoutingTableEntry &b) {
83 return (dst.Equals(b.dst) &&
Paul Stewart75e89d22011-08-01 10:00:02 -070084 src.Equals(b.src) &&
Paul Stewart75e89d22011-08-01 10:00:02 -070085 gateway.Equals(b.gateway) &&
86 metric == b.metric &&
87 scope == b.scope &&
Paul Stewarte93b0382012-04-24 13:11:28 -070088 from_rtnl == b.from_rtnl &&
89 tag == b.tag);
Paul Stewart75e89d22011-08-01 10:00:02 -070090 }
91
92 IPAddress dst;
Paul Stewart75e89d22011-08-01 10:00:02 -070093 IPAddress src;
Paul Stewart75e89d22011-08-01 10:00:02 -070094 IPAddress gateway;
95 uint32 metric;
96 unsigned char scope;
97 bool from_rtnl;
Paul Stewarte93b0382012-04-24 13:11:28 -070098 int tag;
Paul Stewart75e89d22011-08-01 10:00:02 -070099};
100
101} // namespace shill
102
103
104#endif // SHILL_ROUTING_TABLE_ENTRY_