Skip to content

Commit 78fbfd8

Browse files
committed
ipv4: Create and use route lookup helpers.
The idea here is this minimizes the number of places one has to edit in order to make changes to how flows are defined and used. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1561747 commit 78fbfd8

23 files changed

Lines changed: 206 additions & 326 deletions

File tree

‎drivers/infiniband/core/addr.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,11 @@ static int addr4_resolve(struct sockaddr_in *src_in,
183183
{
184184
__be32 src_ip = src_in->sin_addr.s_addr;
185185
__be32 dst_ip = dst_in->sin_addr.s_addr;
186-
struct flowi fl;
187186
struct rtable *rt;
188187
struct neighbour *neigh;
189188
int ret;
190189

191-
memset(&fl, 0, sizeof fl);
192-
fl.nl_u.ip4_u.daddr = dst_ip;
193-
fl.nl_u.ip4_u.saddr = src_ip;
194-
fl.oif = addr->bound_dev_if;
195-
196-
rt = ip_route_output_key(&init_net, &fl);
190+
rt = ip_route_output(&init_net, dst_ip, src_ip, 0, addr->bound_dev_if);
197191
if (IS_ERR(rt)) {
198192
ret = PTR_ERR(rt);
199193
goto out;

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,23 +338,10 @@ static struct rtable *find_route(struct t3cdev *dev, __be32 local_ip,
338338
__be16 peer_port, u8 tos)
339339
{
340340
struct rtable *rt;
341-
struct flowi fl = {
342-
.oif = 0,
343-
.nl_u = {
344-
.ip4_u = {
345-
.daddr = peer_ip,
346-
.saddr = local_ip,
347-
.tos = tos}
348-
},
349-
.proto = IPPROTO_TCP,
350-
.uli_u = {
351-
.ports = {
352-
.sport = local_port,
353-
.dport = peer_port}
354-
}
355-
};
356-
357-
rt = ip_route_output_flow(&init_net, &fl, NULL);
341+
342+
rt = ip_route_output_ports(&init_net, NULL, peer_ip, local_ip,
343+
peer_port, local_port, IPPROTO_TCP,
344+
tos, 0);
358345
if (IS_ERR(rt))
359346
return NULL;
360347
return rt;

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,10 @@ static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
315315
__be16 peer_port, u8 tos)
316316
{
317317
struct rtable *rt;
318-
struct flowi fl = {
319-
.oif = 0,
320-
.nl_u = {
321-
.ip4_u = {
322-
.daddr = peer_ip,
323-
.saddr = local_ip,
324-
.tos = tos}
325-
},
326-
.proto = IPPROTO_TCP,
327-
.uli_u = {
328-
.ports = {
329-
.sport = local_port,
330-
.dport = peer_port}
331-
}
332-
};
333-
334-
rt = ip_route_output_flow(&init_net, &fl, NULL);
318+
319+
rt = ip_route_output_ports(&init_net, NULL, peer_ip, local_ip,
320+
peer_port, local_port, IPPROTO_TCP,
321+
tos, 0);
335322
if (IS_ERR(rt))
336323
return NULL;
337324
return rt;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,15 +1104,12 @@ static inline int mini_cm_accelerated(struct nes_cm_core *cm_core,
11041104
static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpindex)
11051105
{
11061106
struct rtable *rt;
1107-
struct flowi fl;
11081107
struct neighbour *neigh;
11091108
int rc = arpindex;
11101109
struct net_device *netdev;
11111110
struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
11121111

1113-
memset(&fl, 0, sizeof fl);
1114-
fl.nl_u.ip4_u.daddr = htonl(dst_ip);
1115-
rt = ip_route_output_key(&init_net, &fl);
1112+
rt = ip_route_output(&init_net, htonl(dst_ip), 0, 0, 0);
11161113
if (IS_ERR(rt)) {
11171114
printk(KERN_ERR "%s: ip_route_output_key failed for 0x%08X\n",
11181115
__func__, dst_ip);

‎drivers/net/bonding/bond_main.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,6 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
26762676
__be32 *targets = bond->params.arp_targets;
26772677
struct vlan_entry *vlan;
26782678
struct net_device *vlan_dev;
2679-
struct flowi fl;
26802679
struct rtable *rt;
26812680

26822681
for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
@@ -2695,15 +2694,12 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
26952694
* determine which VLAN interface would be used, so we
26962695
* can tag the ARP with the proper VLAN tag.
26972696
*/
2698-
memset(&fl, 0, sizeof(fl));
2699-
fl.fl4_dst = targets[i];
2700-
fl.fl4_tos = RTO_ONLINK;
2701-
2702-
rt = ip_route_output_key(dev_net(bond->dev), &fl);
2697+
rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
2698+
RTO_ONLINK, 0);
27032699
if (IS_ERR(rt)) {
27042700
if (net_ratelimit()) {
27052701
pr_warning("%s: no route to arp_ip_target %pI4\n",
2706-
bond->dev->name, &fl.fl4_dst);
2702+
bond->dev->name, &targets[i]);
27072703
}
27082704
continue;
27092705
}
@@ -2739,7 +2735,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
27392735

27402736
if (net_ratelimit()) {
27412737
pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
2742-
bond->dev->name, &fl.fl4_dst,
2738+
bond->dev->name, &targets[i],
27432739
rt->dst.dev ? rt->dst.dev->name : "NULL");
27442740
}
27452741
ip_rt_put(rt);

‎drivers/net/cnic.c‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,20 +3407,14 @@ static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
34073407
struct dst_entry **dst)
34083408
{
34093409
#if defined(CONFIG_INET)
3410-
struct flowi fl;
3411-
int err;
34123410
struct rtable *rt;
34133411

3414-
memset(&fl, 0, sizeof(fl));
3415-
fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr;
3416-
3417-
rt = ip_route_output_key(&init_net, &fl);
3418-
err = 0;
3419-
if (!IS_ERR(rt))
3412+
rt = ip_route_output(&init_net, dst_addr->sin_addr.s_addr, 0, 0, 0);
3413+
if (!IS_ERR(rt)) {
34203414
*dst = &rt->dst;
3421-
else
3422-
err = PTR_ERR(rt);
3423-
return err;
3415+
return 0;
3416+
}
3417+
return PTR_ERR(rt);
34243418
#else
34253419
return -ENETUNREACH;
34263420
#endif

‎drivers/net/pptp.c‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,14 @@ static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
189189
if (sk_pppox(po)->sk_state & PPPOX_DEAD)
190190
goto tx_error;
191191

192-
{
193-
struct flowi fl = { .oif = 0,
194-
.nl_u = {
195-
.ip4_u = {
196-
.daddr = opt->dst_addr.sin_addr.s_addr,
197-
.saddr = opt->src_addr.sin_addr.s_addr,
198-
.tos = RT_TOS(0) } },
199-
.proto = IPPROTO_GRE };
200-
rt = ip_route_output_key(&init_net, &fl);
201-
if (IS_ERR(rt))
202-
goto tx_error;
203-
}
192+
rt = ip_route_output_ports(&init_net, NULL,
193+
opt->dst_addr.sin_addr.s_addr,
194+
opt->src_addr.sin_addr.s_addr,
195+
0, 0, IPPROTO_GRE,
196+
RT_TOS(0), 0);
197+
if (IS_ERR(rt))
198+
goto tx_error;
199+
204200
tdev = rt->dst.dev;
205201

206202
max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(*iph) + sizeof(*hdr) + 2;
@@ -467,22 +463,17 @@ static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
467463
po->chan.private = sk;
468464
po->chan.ops = &pptp_chan_ops;
469465

470-
{
471-
struct flowi fl = {
472-
.nl_u = {
473-
.ip4_u = {
474-
.daddr = opt->dst_addr.sin_addr.s_addr,
475-
.saddr = opt->src_addr.sin_addr.s_addr,
476-
.tos = RT_CONN_FLAGS(sk) } },
477-
.proto = IPPROTO_GRE };
478-
security_sk_classify_flow(sk, &fl);
479-
rt = ip_route_output_key(&init_net, &fl);
480-
if (IS_ERR(rt)) {
481-
error = -EHOSTUNREACH;
482-
goto end;
483-
}
484-
sk_setup_caps(sk, &rt->dst);
466+
rt = ip_route_output_ports(&init_net, sk,
467+
opt->dst_addr.sin_addr.s_addr,
468+
opt->src_addr.sin_addr.s_addr,
469+
0, 0,
470+
IPPROTO_GRE, RT_CONN_FLAGS(sk), 0);
471+
if (IS_ERR(rt)) {
472+
error = -EHOSTUNREACH;
473+
goto end;
485474
}
475+
sk_setup_caps(sk, &rt->dst);
476+
486477
po->chan.mtu = dst_mtu(&rt->dst);
487478
if (!po->chan.mtu)
488479
po->chan.mtu = PPP_MTU;

‎drivers/scsi/cxgbi/libcxgbi.c‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -451,26 +451,12 @@ static struct cxgbi_sock *cxgbi_sock_create(struct cxgbi_device *cdev)
451451
}
452452

453453
static struct rtable *find_route_ipv4(__be32 saddr, __be32 daddr,
454-
__be16 sport, __be16 dport, u8 tos)
454+
__be16 sport, __be16 dport, u8 tos)
455455
{
456456
struct rtable *rt;
457-
struct flowi fl = {
458-
.oif = 0,
459-
.nl_u = {
460-
.ip4_u = {
461-
.daddr = daddr,
462-
.saddr = saddr,
463-
.tos = tos }
464-
},
465-
.proto = IPPROTO_TCP,
466-
.uli_u = {
467-
.ports = {
468-
.sport = sport,
469-
.dport = dport }
470-
}
471-
};
472457

473-
rt = ip_route_output_flow(&init_net, &fl, NULL);
458+
rt = ip_route_output_ports(&init_net, NULL, daddr, saddr,
459+
dport, sport, IPPROTO_TCP, tos, 0);
474460
if (IS_ERR(rt))
475461
return NULL;
476462

‎include/net/route.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,54 @@ static inline struct rtable *ip_route_output_key(struct net *net, struct flowi *
132132
return ip_route_output_flow(net, flp, NULL);
133133
}
134134

135+
static inline struct rtable *ip_route_output(struct net *net, __be32 daddr,
136+
__be32 saddr, u8 tos, int oif)
137+
{
138+
struct flowi fl = {
139+
.oif = oif,
140+
.fl4_dst = daddr,
141+
.fl4_src = saddr,
142+
.fl4_tos = tos,
143+
};
144+
return ip_route_output_key(net, &fl);
145+
}
146+
147+
static inline struct rtable *ip_route_output_ports(struct net *net, struct sock *sk,
148+
__be32 daddr, __be32 saddr,
149+
__be16 dport, __be16 sport,
150+
__u8 proto, __u8 tos, int oif)
151+
{
152+
struct flowi fl = {
153+
.oif = oif,
154+
.flags = sk ? inet_sk_flowi_flags(sk) : 0,
155+
.mark = sk ? sk->sk_mark : 0,
156+
.fl4_dst = daddr,
157+
.fl4_src = saddr,
158+
.fl4_tos = tos,
159+
.proto = proto,
160+
.fl_ip_dport = dport,
161+
.fl_ip_sport = sport,
162+
};
163+
if (sk)
164+
security_sk_classify_flow(sk, &fl);
165+
return ip_route_output_flow(net, &fl, sk);
166+
}
167+
168+
static inline struct rtable *ip_route_output_gre(struct net *net,
169+
__be32 daddr, __be32 saddr,
170+
__be32 gre_key, __u8 tos, int oif)
171+
{
172+
struct flowi fl = {
173+
.oif = oif,
174+
.fl4_dst = daddr,
175+
.fl4_src = saddr,
176+
.fl4_tos = tos,
177+
.proto = IPPROTO_GRE,
178+
.fl_gre_key = gre_key,
179+
};
180+
return ip_route_output_key(net, &fl);
181+
}
182+
135183
extern int ip_route_input_common(struct sk_buff *skb, __be32 dst, __be32 src,
136184
u8 tos, struct net_device *devin, bool noref);
137185

‎net/atm/clip.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
502502
struct atmarp_entry *entry;
503503
int error;
504504
struct clip_vcc *clip_vcc;
505-
struct flowi fl = { .fl4_dst = ip,
506-
.fl4_tos = 1 };
507505
struct rtable *rt;
508506

509507
if (vcc->push != clip_push) {
@@ -520,7 +518,7 @@ static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
520518
unlink_clip_vcc(clip_vcc);
521519
return 0;
522520
}
523-
rt = ip_route_output_key(&init_net, &fl);
521+
rt = ip_route_output(&init_net, ip, 0, 1, 0);
524522
if (IS_ERR(rt))
525523
return PTR_ERR(rt);
526524
neigh = __neigh_lookup(&clip_tbl, &ip, rt->dst.dev, 1);

0 commit comments

Comments
 (0)