Skip to content

Commit b23dd4f

Browse files
committed
ipv4: Make output route lookup return rtable directly.
Instead of on the stack. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 452edd5 commit b23dd4f

36 files changed

Lines changed: 267 additions & 224 deletions

‎drivers/infiniband/core/addr.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,11 @@ static int addr4_resolve(struct sockaddr_in *src_in,
193193
fl.nl_u.ip4_u.saddr = src_ip;
194194
fl.oif = addr->bound_dev_if;
195195

196-
ret = ip_route_output_key(&init_net, &rt, &fl);
197-
if (ret)
196+
rt = ip_route_output_key(&init_net, &fl);
197+
if (IS_ERR(rt)) {
198+
ret = PTR_ERR(rt);
198199
goto out;
199-
200+
}
200201
src_in->sin_family = AF_INET;
201202
src_in->sin_addr.s_addr = rt->rt_src;
202203

‎drivers/infiniband/hw/cxgb3/iwch_cm.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ static struct rtable *find_route(struct t3cdev *dev, __be32 local_ip,
354354
}
355355
};
356356

357-
if (ip_route_output_flow(&init_net, &rt, &fl, NULL))
357+
rt = ip_route_output_flow(&init_net, &fl, NULL);
358+
if (IS_ERR(rt))
358359
return NULL;
359360
return rt;
360361
}

‎drivers/infiniband/hw/cxgb4/cm.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
331331
}
332332
};
333333

334-
if (ip_route_output_flow(&init_net, &rt, &fl, NULL))
334+
rt = ip_route_output_flow(&init_net, &fl, NULL);
335+
if (IS_ERR(rt))
335336
return NULL;
336337
return rt;
337338
}

‎drivers/infiniband/hw/nes/nes_cm.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,8 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
11121112

11131113
memset(&fl, 0, sizeof fl);
11141114
fl.nl_u.ip4_u.daddr = htonl(dst_ip);
1115-
if (ip_route_output_key(&init_net, &rt, &fl)) {
1115+
rt = ip_route_output_key(&init_net, &fl);
1116+
if (IS_ERR(rt)) {
11161117
printk(KERN_ERR "%s: ip_route_output_key failed for 0x%08X\n",
11171118
__func__, dst_ip);
11181119
return rc;

‎drivers/net/bonding/bond_main.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_
26812681

26822682
static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
26832683
{
2684-
int i, vlan_id, rv;
2684+
int i, vlan_id;
26852685
__be32 *targets = bond->params.arp_targets;
26862686
struct vlan_entry *vlan;
26872687
struct net_device *vlan_dev;
@@ -2708,8 +2708,8 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
27082708
fl.fl4_dst = targets[i];
27092709
fl.fl4_tos = RTO_ONLINK;
27102710

2711-
rv = ip_route_output_key(dev_net(bond->dev), &rt, &fl);
2712-
if (rv) {
2711+
rt = ip_route_output_key(dev_net(bond->dev), &fl);
2712+
if (IS_ERR(rt)) {
27132713
if (net_ratelimit()) {
27142714
pr_warning("%s: no route to arp_ip_target %pI4\n",
27152715
bond->dev->name, &fl.fl4_dst);

‎drivers/net/cnic.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,9 +3397,12 @@ static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
33973397
memset(&fl, 0, sizeof(fl));
33983398
fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr;
33993399

3400-
err = ip_route_output_key(&init_net, &rt, &fl);
3401-
if (!err)
3400+
rt = ip_route_output_key(&init_net, &fl);
3401+
err = 0;
3402+
if (!IS_ERR(rt))
34023403
*dst = &rt->dst;
3404+
else
3405+
err = PTR_ERR(rt);
34033406
return err;
34043407
#else
34053408
return -ENETUNREACH;

‎drivers/net/pptp.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
175175
struct pptp_opt *opt = &po->proto.pptp;
176176
struct pptp_gre_header *hdr;
177177
unsigned int header_len = sizeof(*hdr);
178-
int err = 0;
179178
int islcp;
180179
int len;
181180
unsigned char *data;
@@ -198,8 +197,8 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
198197
.saddr = opt->src_addr.sin_addr.s_addr,
199198
.tos = RT_TOS(0) } },
200199
.proto = IPPROTO_GRE };
201-
err = ip_route_output_key(&init_net, &rt, &fl);
202-
if (err)
200+
rt = ip_route_output_key(&init_net, &fl);
201+
if (IS_ERR(rt))
203202
goto tx_error;
204203
}
205204
tdev = rt->dst.dev;
@@ -477,7 +476,8 @@ static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
477476
.tos = RT_CONN_FLAGS(sk) } },
478477
.proto = IPPROTO_GRE };
479478
security_sk_classify_flow(sk, &fl);
480-
if (ip_route_output_key(&init_net, &rt, &fl)) {
479+
rt = ip_route_output_key(&init_net, &fl);
480+
if (IS_ERR(rt)) {
481481
error = -EHOSTUNREACH;
482482
goto end;
483483
}

‎drivers/scsi/cxgbi/libcxgbi.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ static struct rtable *find_route_ipv4(__be32 saddr, __be32 daddr,
470470
}
471471
};
472472

473-
if (ip_route_output_flow(&init_net, &rt, &fl, NULL))
473+
rt = ip_route_output_flow(&init_net, &fl, NULL);
474+
if (IS_ERR(rt))
474475
return NULL;
475476

476477
return rt;

‎include/net/route.h‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ extern void ip_rt_redirect(__be32 old_gw, __be32 dst, __be32 new_gw,
118118
__be32 src, struct net_device *dev);
119119
extern void rt_cache_flush(struct net *net, int how);
120120
extern void rt_cache_flush_batch(struct net *net);
121-
extern int __ip_route_output_key(struct net *, struct rtable **, const struct flowi *flp);
122-
extern int ip_route_output_key(struct net *, struct rtable **, struct flowi *flp);
123-
extern int ip_route_output_flow(struct net *, struct rtable **rp, struct flowi *flp, struct sock *sk);
121+
extern struct rtable *__ip_route_output_key(struct net *, const struct flowi *flp);
122+
extern struct rtable *ip_route_output_key(struct net *, struct flowi *flp);
123+
extern struct rtable *ip_route_output_flow(struct net *, struct flowi *flp,
124+
struct sock *sk);
124125
extern struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig);
125126

126127
extern int ip_route_input_common(struct sk_buff *skb, __be32 dst, __be32 src,
@@ -166,10 +167,10 @@ static inline char rt_tos2priority(u8 tos)
166167
return ip_tos2prio[IPTOS_TOS(tos)>>1];
167168
}
168169

169-
static inline int ip_route_connect(struct rtable **rp, __be32 dst,
170-
__be32 src, u32 tos, int oif, u8 protocol,
171-
__be16 sport, __be16 dport, struct sock *sk,
172-
bool can_sleep)
170+
static inline struct rtable *ip_route_connect(__be32 dst, __be32 src, u32 tos,
171+
int oif, u8 protocol,
172+
__be16 sport, __be16 dport,
173+
struct sock *sk, bool can_sleep)
173174
{
174175
struct flowi fl = { .oif = oif,
175176
.mark = sk->sk_mark,
@@ -179,8 +180,8 @@ static inline int ip_route_connect(struct rtable **rp, __be32 dst,
179180
.proto = protocol,
180181
.fl_ip_sport = sport,
181182
.fl_ip_dport = dport };
182-
int err;
183183
struct net *net = sock_net(sk);
184+
struct rtable *rt;
184185

185186
if (inet_sk(sk)->transparent)
186187
fl.flags |= FLOWI_FLAG_ANYSRC;
@@ -190,42 +191,41 @@ static inline int ip_route_connect(struct rtable **rp, __be32 dst,
190191
fl.flags |= FLOWI_FLAG_CAN_SLEEP;
191192

192193
if (!dst || !src) {
193-
err = __ip_route_output_key(net, rp, &fl);
194-
if (err)
195-
return err;
196-
fl.fl4_dst = (*rp)->rt_dst;
197-
fl.fl4_src = (*rp)->rt_src;
198-
ip_rt_put(*rp);
199-
*rp = NULL;
194+
rt = __ip_route_output_key(net, &fl);
195+
if (IS_ERR(rt))
196+
return rt;
197+
fl.fl4_dst = rt->rt_dst;
198+
fl.fl4_src = rt->rt_src;
199+
ip_rt_put(rt);
200200
}
201201
security_sk_classify_flow(sk, &fl);
202-
return ip_route_output_flow(net, rp, &fl, sk);
202+
return ip_route_output_flow(net, &fl, sk);
203203
}
204204

205-
static inline int ip_route_newports(struct rtable **rp, u8 protocol,
206-
__be16 orig_sport, __be16 orig_dport,
207-
__be16 sport, __be16 dport, struct sock *sk)
205+
static inline struct rtable *ip_route_newports(struct rtable *rt,
206+
u8 protocol, __be16 orig_sport,
207+
__be16 orig_dport, __be16 sport,
208+
__be16 dport, struct sock *sk)
208209
{
209210
if (sport != orig_sport || dport != orig_dport) {
210-
struct flowi fl = { .oif = (*rp)->fl.oif,
211-
.mark = (*rp)->fl.mark,
212-
.fl4_dst = (*rp)->fl.fl4_dst,
213-
.fl4_src = (*rp)->fl.fl4_src,
214-
.fl4_tos = (*rp)->fl.fl4_tos,
215-
.proto = (*rp)->fl.proto,
211+
struct flowi fl = { .oif = rt->fl.oif,
212+
.mark = rt->fl.mark,
213+
.fl4_dst = rt->fl.fl4_dst,
214+
.fl4_src = rt->fl.fl4_src,
215+
.fl4_tos = rt->fl.fl4_tos,
216+
.proto = rt->fl.proto,
216217
.fl_ip_sport = sport,
217218
.fl_ip_dport = dport };
218219

219220
if (inet_sk(sk)->transparent)
220221
fl.flags |= FLOWI_FLAG_ANYSRC;
221222
if (protocol == IPPROTO_TCP)
222223
fl.flags |= FLOWI_FLAG_PRECOW_METRICS;
223-
ip_rt_put(*rp);
224-
*rp = NULL;
224+
ip_rt_put(rt);
225225
security_sk_classify_flow(sk, &fl);
226-
return ip_route_output_flow(sock_net(sk), rp, &fl, sk);
226+
return ip_route_output_flow(sock_net(sk), &fl, sk);
227227
}
228-
return 0;
228+
return rt;
229229
}
230230

231231
extern void rt_bind_peer(struct rtable *rt, int create);

‎net/atm/clip.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
520520
unlink_clip_vcc(clip_vcc);
521521
return 0;
522522
}
523-
error = ip_route_output_key(&init_net, &rt, &fl);
524-
if (error)
525-
return error;
523+
rt = ip_route_output_key(&init_net, &fl);
524+
if (IS_ERR(rt))
525+
return PTR_ERR(rt);
526526
neigh = __neigh_lookup(&clip_tbl, &ip, rt->dst.dev, 1);
527527
ip_rt_put(rt);
528528
if (!neigh)

0 commit comments

Comments
 (0)