• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2011 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_ROUTING_TABLE_ENTRY_H_
18 #define SHILL_ROUTING_TABLE_ENTRY_H_
19 
20 #include <linux/rtnetlink.h>
21 
22 #include "shill/net/ip_address.h"
23 
24 namespace shill {
25 
26 // Holds table entries for routing.  These are held in an STL vector
27 // in the RoutingTable object, hence the need for copy contructor and
28 // operator=.
29 struct RoutingTableEntry {
30  public:
31   static const int kDefaultTag = -1;
32 
RoutingTableEntryRoutingTableEntry33   RoutingTableEntry()
34       : dst(IPAddress::kFamilyUnknown),
35         src(IPAddress::kFamilyUnknown),
36         gateway(IPAddress::kFamilyUnknown),
37         metric(0),
38         scope(0),
39         from_rtnl(false),
40         table(RT_TABLE_MAIN),
41         tag(kDefaultTag) {}
42 
RoutingTableEntryRoutingTableEntry43   RoutingTableEntry(const IPAddress& dst_in,
44                     const IPAddress& src_in,
45                     const IPAddress& gateway_in,
46                     uint32_t metric_in,
47                     unsigned char scope_in,
48                     bool from_rtnl_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         table(RT_TABLE_MAIN),
56         tag(kDefaultTag) {}
57 
RoutingTableEntryRoutingTableEntry58   RoutingTableEntry(const IPAddress& dst_in,
59                     const IPAddress& src_in,
60                     const IPAddress& gateway_in,
61                     uint32_t metric_in,
62                     unsigned char scope_in,
63                     bool from_rtnl_in,
64                     int tag_in)
65       : dst(dst_in),
66         src(src_in),
67         gateway(gateway_in),
68         metric(metric_in),
69         scope(scope_in),
70         from_rtnl(from_rtnl_in),
71         table(RT_TABLE_MAIN),
72         tag(tag_in) {}
73 
RoutingTableEntryRoutingTableEntry74   RoutingTableEntry(const IPAddress& dst_in,
75                     const IPAddress& src_in,
76                     const IPAddress& gateway_in,
77                     uint32_t metric_in,
78                     unsigned char scope_in,
79                     bool from_rtnl_in,
80                     unsigned char table_in,
81                     int tag_in)
82       : dst(dst_in),
83         src(src_in),
84         gateway(gateway_in),
85         metric(metric_in),
86         scope(scope_in),
87         from_rtnl(from_rtnl_in),
88         table(table_in),
89         tag(tag_in) {}
90 
RoutingTableEntryRoutingTableEntry91   RoutingTableEntry(const RoutingTableEntry& b)
92       : dst(b.dst),
93         src(b.src),
94         gateway(b.gateway),
95         metric(b.metric),
96         scope(b.scope),
97         from_rtnl(b.from_rtnl),
98         table(b.table),
99         tag(b.tag) {}
100 
101   RoutingTableEntry& operator=(const RoutingTableEntry& b) {
102     dst = b.dst;
103     src = b.src;
104     gateway = b.gateway;
105     metric = b.metric;
106     scope = b.scope;
107     from_rtnl = b.from_rtnl;
108     table = b.table;
109     tag = b.tag;
110 
111     return *this;
112   }
113 
~RoutingTableEntryRoutingTableEntry114   ~RoutingTableEntry() {}
115 
EqualsRoutingTableEntry116   bool Equals(const RoutingTableEntry& b) {
117     return (dst.Equals(b.dst) &&
118             src.Equals(b.src) &&
119             gateway.Equals(b.gateway) &&
120             metric == b.metric &&
121             scope == b.scope &&
122             from_rtnl == b.from_rtnl &&
123             table == b.table &&
124             tag == b.tag);
125   }
126 
127   IPAddress dst;
128   IPAddress src;
129   IPAddress gateway;
130   uint32_t metric;
131   unsigned char scope;
132   bool from_rtnl;
133   unsigned char table;
134   int tag;
135 };
136 
137 }  // namespace shill
138 
139 
140 #endif  // SHILL_ROUTING_TABLE_ENTRY_H_
141