blob: b9d61971220565d004c6dbd0c5e7e8c5d8b53441 [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:
19 RoutingTableEntry()
20 : dst(IPAddress::kAddressFamilyUnknown),
21 dst_prefix(0),
22 src(IPAddress::kAddressFamilyUnknown),
23 src_prefix(0),
24 gateway(IPAddress::kAddressFamilyUnknown),
25 metric(0),
26 scope(0),
27 from_rtnl(false) {}
28
29 RoutingTableEntry(const IPAddress &dst_in,
30 unsigned char dst_prefix_in,
31 const IPAddress &src_in,
32 unsigned char src_prefix_in,
33 const IPAddress &gateway_in,
34 uint32 metric_in,
35 unsigned char scope_in,
36 bool from_rtnl_in)
37 : dst(dst_in.family(), dst_in.address()),
38 dst_prefix(dst_prefix_in),
39 src(src_in.family(), src_in.address()),
40 src_prefix(src_prefix_in),
41 gateway(gateway_in.family(), gateway_in.address()),
42 metric(metric_in),
43 scope(scope_in),
44 from_rtnl(from_rtnl_in) {}
45
46 RoutingTableEntry(const RoutingTableEntry &b)
47 : dst(b.dst.family(), b.dst.address()),
48 dst_prefix(b.dst_prefix),
49 src(b.src.family(), b.src.address()),
50 src_prefix(b.src_prefix),
51 gateway(b.gateway.family(), b.gateway.address()),
52 metric(b.metric),
53 scope(b.scope),
54 from_rtnl(b.from_rtnl) {}
55
56 RoutingTableEntry &operator=(const RoutingTableEntry &b) {
57 dst.Clone(b.dst);
58 dst_prefix = b.dst_prefix;
59 src.Clone(b.src);
60 src_prefix = b.src_prefix;
61 gateway.Clone(b.gateway);
62 metric = b.metric;
63 scope = b.scope;
64 from_rtnl = b.from_rtnl;
65
66 return *this;
67 }
68
69 ~RoutingTableEntry() {}
70
71 bool Equals(const RoutingTableEntry &b) {
72 return (dst.Equals(b.dst) &&
73 dst_prefix == b.dst_prefix &&
74 src.Equals(b.src) &&
75 src_prefix == b.src_prefix &&
76 gateway.Equals(b.gateway) &&
77 metric == b.metric &&
78 scope == b.scope &&
79 from_rtnl == b.from_rtnl);
80 }
81
82 IPAddress dst;
83 unsigned char dst_prefix;
84 IPAddress src;
85 unsigned char src_prefix;
86 IPAddress gateway;
87 uint32 metric;
88 unsigned char scope;
89 bool from_rtnl;
90};
91
92} // namespace shill
93
94
95#endif // SHILL_ROUTING_TABLE_ENTRY_