aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/route.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/route.h')
-rw-r--r--include/net/route.h166
1 files changed, 120 insertions, 46 deletions
diff --git a/include/net/route.h b/include/net/route.h
index 93e10c453f6b..8fce0621cad1 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -49,36 +49,44 @@
49 49
50struct fib_nh; 50struct fib_nh;
51struct inet_peer; 51struct inet_peer;
52struct fib_info;
52struct rtable { 53struct rtable {
53 struct dst_entry dst; 54 struct dst_entry dst;
54 55
55 /* Cache lookup keys */ 56 /* Lookup key. */
56 struct flowi fl; 57 __be32 rt_key_dst;
58 __be32 rt_key_src;
57 59
58 int rt_genid; 60 int rt_genid;
59 unsigned rt_flags; 61 unsigned rt_flags;
60 __u16 rt_type; 62 __u16 rt_type;
63 __u8 rt_tos;
61 64
62 __be32 rt_dst; /* Path destination */ 65 __be32 rt_dst; /* Path destination */
63 __be32 rt_src; /* Path source */ 66 __be32 rt_src; /* Path source */
67 int rt_route_iif;
64 int rt_iif; 68 int rt_iif;
69 int rt_oif;
70 __u32 rt_mark;
65 71
66 /* Info on neighbour */ 72 /* Info on neighbour */
67 __be32 rt_gateway; 73 __be32 rt_gateway;
68 74
69 /* Miscellaneous cached information */ 75 /* Miscellaneous cached information */
70 __be32 rt_spec_dst; /* RFC1122 specific destination */ 76 __be32 rt_spec_dst; /* RFC1122 specific destination */
77 u32 rt_peer_genid;
71 struct inet_peer *peer; /* long-living peer info */ 78 struct inet_peer *peer; /* long-living peer info */
79 struct fib_info *fi; /* for client ref to shared metrics */
72}; 80};
73 81
74static inline bool rt_is_input_route(struct rtable *rt) 82static inline bool rt_is_input_route(struct rtable *rt)
75{ 83{
76 return rt->fl.iif != 0; 84 return rt->rt_route_iif != 0;
77} 85}
78 86
79static inline bool rt_is_output_route(struct rtable *rt) 87static inline bool rt_is_output_route(struct rtable *rt)
80{ 88{
81 return rt->fl.iif == 0; 89 return rt->rt_route_iif == 0;
82} 90}
83 91
84struct ip_rt_acct { 92struct ip_rt_acct {
@@ -115,9 +123,63 @@ extern void ip_rt_redirect(__be32 old_gw, __be32 dst, __be32 new_gw,
115 __be32 src, struct net_device *dev); 123 __be32 src, struct net_device *dev);
116extern void rt_cache_flush(struct net *net, int how); 124extern void rt_cache_flush(struct net *net, int how);
117extern void rt_cache_flush_batch(struct net *net); 125extern void rt_cache_flush_batch(struct net *net);
118extern int __ip_route_output_key(struct net *, struct rtable **, const struct flowi *flp); 126extern struct rtable *__ip_route_output_key(struct net *, const struct flowi4 *flp);
119extern int ip_route_output_key(struct net *, struct rtable **, struct flowi *flp); 127extern struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
120extern int ip_route_output_flow(struct net *, struct rtable **rp, struct flowi *flp, struct sock *sk, int flags); 128 struct sock *sk);
129extern struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig);
130
131static inline struct rtable *ip_route_output_key(struct net *net, struct flowi4 *flp)
132{
133 return ip_route_output_flow(net, flp, NULL);
134}
135
136static inline struct rtable *ip_route_output(struct net *net, __be32 daddr,
137 __be32 saddr, u8 tos, int oif)
138{
139 struct flowi4 fl4 = {
140 .flowi4_oif = oif,
141 .daddr = daddr,
142 .saddr = saddr,
143 .flowi4_tos = tos,
144 };
145 return ip_route_output_key(net, &fl4);
146}
147
148static inline struct rtable *ip_route_output_ports(struct net *net, struct sock *sk,
149 __be32 daddr, __be32 saddr,
150 __be16 dport, __be16 sport,
151 __u8 proto, __u8 tos, int oif)
152{
153 struct flowi4 fl4 = {
154 .flowi4_oif = oif,
155 .flowi4_flags = sk ? inet_sk_flowi_flags(sk) : 0,
156 .flowi4_mark = sk ? sk->sk_mark : 0,
157 .daddr = daddr,
158 .saddr = saddr,
159 .flowi4_tos = tos,
160 .flowi4_proto = proto,
161 .fl4_dport = dport,
162 .fl4_sport = sport,
163 };
164 if (sk)
165 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
166 return ip_route_output_flow(net, &fl4, sk);
167}
168
169static inline struct rtable *ip_route_output_gre(struct net *net,
170 __be32 daddr, __be32 saddr,
171 __be32 gre_key, __u8 tos, int oif)
172{
173 struct flowi4 fl4 = {
174 .flowi4_oif = oif,
175 .daddr = daddr,
176 .saddr = saddr,
177 .flowi4_tos = tos,
178 .flowi4_proto = IPPROTO_GRE,
179 .fl4_gre_key = gre_key,
180 };
181 return ip_route_output_key(net, &fl4);
182}
121 183
122extern int ip_route_input_common(struct sk_buff *skb, __be32 dst, __be32 src, 184extern int ip_route_input_common(struct sk_buff *skb, __be32 dst, __be32 src,
123 u8 tos, struct net_device *devin, bool noref); 185 u8 tos, struct net_device *devin, bool noref);
@@ -146,6 +208,7 @@ extern int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb);
146 208
147struct in_ifaddr; 209struct in_ifaddr;
148extern void fib_add_ifaddr(struct in_ifaddr *); 210extern void fib_add_ifaddr(struct in_ifaddr *);
211extern void fib_del_ifaddr(struct in_ifaddr *, struct in_ifaddr *);
149 212
150static inline void ip_rt_put(struct rtable * rt) 213static inline void ip_rt_put(struct rtable * rt)
151{ 214{
@@ -162,57 +225,68 @@ static inline char rt_tos2priority(u8 tos)
162 return ip_tos2prio[IPTOS_TOS(tos)>>1]; 225 return ip_tos2prio[IPTOS_TOS(tos)>>1];
163} 226}
164 227
165static inline int ip_route_connect(struct rtable **rp, __be32 dst, 228static inline struct rtable *ip_route_connect(__be32 dst, __be32 src, u32 tos,
166 __be32 src, u32 tos, int oif, u8 protocol, 229 int oif, u8 protocol,
167 __be16 sport, __be16 dport, struct sock *sk, 230 __be16 sport, __be16 dport,
168 int flags) 231 struct sock *sk, bool can_sleep)
169{ 232{
170 struct flowi fl = { .oif = oif, 233 struct flowi4 fl4 = {
171 .mark = sk->sk_mark, 234 .flowi4_oif = oif,
172 .fl4_dst = dst, 235 .flowi4_mark = sk->sk_mark,
173 .fl4_src = src, 236 .daddr = dst,
174 .fl4_tos = tos, 237 .saddr = src,
175 .proto = protocol, 238 .flowi4_tos = tos,
176 .fl_ip_sport = sport, 239 .flowi4_proto = protocol,
177 .fl_ip_dport = dport }; 240 .fl4_sport = sport,
178 int err; 241 .fl4_dport = dport,
242 };
179 struct net *net = sock_net(sk); 243 struct net *net = sock_net(sk);
244 struct rtable *rt;
180 245
181 if (inet_sk(sk)->transparent) 246 if (inet_sk(sk)->transparent)
182 fl.flags |= FLOWI_FLAG_ANYSRC; 247 fl4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
248 if (protocol == IPPROTO_TCP)
249 fl4.flowi4_flags |= FLOWI_FLAG_PRECOW_METRICS;
250 if (can_sleep)
251 fl4.flowi4_flags |= FLOWI_FLAG_CAN_SLEEP;
183 252
184 if (!dst || !src) { 253 if (!dst || !src) {
185 err = __ip_route_output_key(net, rp, &fl); 254 rt = __ip_route_output_key(net, &fl4);
186 if (err) 255 if (IS_ERR(rt))
187 return err; 256 return rt;
188 fl.fl4_dst = (*rp)->rt_dst; 257 fl4.daddr = rt->rt_dst;
189 fl.fl4_src = (*rp)->rt_src; 258 fl4.saddr = rt->rt_src;
190 ip_rt_put(*rp); 259 ip_rt_put(rt);
191 *rp = NULL;
192 } 260 }
193 security_sk_classify_flow(sk, &fl); 261 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
194 return ip_route_output_flow(net, rp, &fl, sk, flags); 262 return ip_route_output_flow(net, &fl4, sk);
195} 263}
196 264
197static inline int ip_route_newports(struct rtable **rp, u8 protocol, 265static inline struct rtable *ip_route_newports(struct rtable *rt,
198 __be16 sport, __be16 dport, struct sock *sk) 266 u8 protocol, __be16 orig_sport,
267 __be16 orig_dport, __be16 sport,
268 __be16 dport, struct sock *sk)
199{ 269{
200 if (sport != (*rp)->fl.fl_ip_sport || 270 if (sport != orig_sport || dport != orig_dport) {
201 dport != (*rp)->fl.fl_ip_dport) { 271 struct flowi4 fl4 = {
202 struct flowi fl; 272 .flowi4_oif = rt->rt_oif,
203 273 .flowi4_mark = rt->rt_mark,
204 memcpy(&fl, &(*rp)->fl, sizeof(fl)); 274 .daddr = rt->rt_dst,
205 fl.fl_ip_sport = sport; 275 .saddr = rt->rt_src,
206 fl.fl_ip_dport = dport; 276 .flowi4_tos = rt->rt_tos,
207 fl.proto = protocol; 277 .flowi4_proto = protocol,
278 .fl4_sport = sport,
279 .fl4_dport = dport
280 };
208 if (inet_sk(sk)->transparent) 281 if (inet_sk(sk)->transparent)
209 fl.flags |= FLOWI_FLAG_ANYSRC; 282 fl4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
210 ip_rt_put(*rp); 283 if (protocol == IPPROTO_TCP)
211 *rp = NULL; 284 fl4.flowi4_flags |= FLOWI_FLAG_PRECOW_METRICS;
212 security_sk_classify_flow(sk, &fl); 285 ip_rt_put(rt);
213 return ip_route_output_flow(sock_net(sk), rp, &fl, sk, 0); 286 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
287 return ip_route_output_flow(sock_net(sk), &fl4, sk);
214 } 288 }
215 return 0; 289 return rt;
216} 290}
217 291
218extern void rt_bind_peer(struct rtable *rt, int create); 292extern void rt_bind_peer(struct rtable *rt, int create);