Skip to content

Commit e509996

Browse files
ebirgerklassert
authored andcommitted
xfrm: extract dst lookup parameters into a struct
Preparation for adding more fields to dst lookup functions without changing their signatures. Signed-off-by: Eyal Birger <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 7ebf44c commit e509996

File tree

5 files changed

+73
-65
lines changed

5 files changed

+73
-65
lines changed

include/net/xfrm.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,23 @@ struct xfrm_if_cb {
349349
void xfrm_if_register_cb(const struct xfrm_if_cb *ifcb);
350350
void xfrm_if_unregister_cb(void);
351351

352+
struct xfrm_dst_lookup_params {
353+
struct net *net;
354+
int tos;
355+
int oif;
356+
xfrm_address_t *saddr;
357+
xfrm_address_t *daddr;
358+
u32 mark;
359+
};
360+
352361
struct net_device;
353362
struct xfrm_type;
354363
struct xfrm_dst;
355364
struct xfrm_policy_afinfo {
356365
struct dst_ops *dst_ops;
357-
struct dst_entry *(*dst_lookup)(struct net *net,
358-
int tos, int oif,
359-
const xfrm_address_t *saddr,
360-
const xfrm_address_t *daddr,
361-
u32 mark);
362-
int (*get_saddr)(struct net *net, int oif,
363-
xfrm_address_t *saddr,
364-
xfrm_address_t *daddr,
365-
u32 mark);
366+
struct dst_entry *(*dst_lookup)(const struct xfrm_dst_lookup_params *params);
367+
int (*get_saddr)(xfrm_address_t *saddr,
368+
const struct xfrm_dst_lookup_params *params);
366369
int (*fill_dst)(struct xfrm_dst *xdst,
367370
struct net_device *dev,
368371
const struct flowi *fl);
@@ -1764,10 +1767,7 @@ static inline int xfrm_user_policy(struct sock *sk, int optname,
17641767
}
17651768
#endif
17661769

1767-
struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos, int oif,
1768-
const xfrm_address_t *saddr,
1769-
const xfrm_address_t *daddr,
1770-
int family, u32 mark);
1770+
struct dst_entry *__xfrm_dst_lookup(int family, const struct xfrm_dst_lookup_params *params);
17711771

17721772
struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp);
17731773

net/ipv4/xfrm4_policy.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,41 @@
1717
#include <net/ip.h>
1818
#include <net/l3mdev.h>
1919

20-
static struct dst_entry *__xfrm4_dst_lookup(struct net *net, struct flowi4 *fl4,
21-
int tos, int oif,
22-
const xfrm_address_t *saddr,
23-
const xfrm_address_t *daddr,
24-
u32 mark)
20+
static struct dst_entry *__xfrm4_dst_lookup(struct flowi4 *fl4,
21+
const struct xfrm_dst_lookup_params *params)
2522
{
2623
struct rtable *rt;
2724

2825
memset(fl4, 0, sizeof(*fl4));
29-
fl4->daddr = daddr->a4;
30-
fl4->flowi4_tos = tos;
31-
fl4->flowi4_l3mdev = l3mdev_master_ifindex_by_index(net, oif);
32-
fl4->flowi4_mark = mark;
33-
if (saddr)
34-
fl4->saddr = saddr->a4;
35-
36-
rt = __ip_route_output_key(net, fl4);
26+
fl4->daddr = params->daddr->a4;
27+
fl4->flowi4_tos = params->tos;
28+
fl4->flowi4_l3mdev = l3mdev_master_ifindex_by_index(params->net,
29+
params->oif);
30+
fl4->flowi4_mark = params->mark;
31+
if (params->saddr)
32+
fl4->saddr = params->saddr->a4;
33+
34+
rt = __ip_route_output_key(params->net, fl4);
3735
if (!IS_ERR(rt))
3836
return &rt->dst;
3937

4038
return ERR_CAST(rt);
4139
}
4240

43-
static struct dst_entry *xfrm4_dst_lookup(struct net *net, int tos, int oif,
44-
const xfrm_address_t *saddr,
45-
const xfrm_address_t *daddr,
46-
u32 mark)
41+
static struct dst_entry *xfrm4_dst_lookup(const struct xfrm_dst_lookup_params *params)
4742
{
4843
struct flowi4 fl4;
4944

50-
return __xfrm4_dst_lookup(net, &fl4, tos, oif, saddr, daddr, mark);
45+
return __xfrm4_dst_lookup(&fl4, params);
5146
}
5247

53-
static int xfrm4_get_saddr(struct net *net, int oif,
54-
xfrm_address_t *saddr, xfrm_address_t *daddr,
55-
u32 mark)
48+
static int xfrm4_get_saddr(xfrm_address_t *saddr,
49+
const struct xfrm_dst_lookup_params *params)
5650
{
5751
struct dst_entry *dst;
5852
struct flowi4 fl4;
5953

60-
dst = __xfrm4_dst_lookup(net, &fl4, 0, oif, NULL, daddr, mark);
54+
dst = __xfrm4_dst_lookup(&fl4, params);
6155
if (IS_ERR(dst))
6256
return -EHOSTUNREACH;
6357

net/ipv6/xfrm6_policy.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@
2323
#include <net/ip6_route.h>
2424
#include <net/l3mdev.h>
2525

26-
static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,
27-
const xfrm_address_t *saddr,
28-
const xfrm_address_t *daddr,
29-
u32 mark)
26+
static struct dst_entry *xfrm6_dst_lookup(const struct xfrm_dst_lookup_params *params)
3027
{
3128
struct flowi6 fl6;
3229
struct dst_entry *dst;
3330
int err;
3431

3532
memset(&fl6, 0, sizeof(fl6));
36-
fl6.flowi6_l3mdev = l3mdev_master_ifindex_by_index(net, oif);
37-
fl6.flowi6_mark = mark;
38-
memcpy(&fl6.daddr, daddr, sizeof(fl6.daddr));
39-
if (saddr)
40-
memcpy(&fl6.saddr, saddr, sizeof(fl6.saddr));
33+
fl6.flowi6_l3mdev = l3mdev_master_ifindex_by_index(params->net,
34+
params->oif);
35+
fl6.flowi6_mark = params->mark;
36+
memcpy(&fl6.daddr, params->daddr, sizeof(fl6.daddr));
37+
if (params->saddr)
38+
memcpy(&fl6.saddr, params->saddr, sizeof(fl6.saddr));
4139

42-
dst = ip6_route_output(net, NULL, &fl6);
40+
dst = ip6_route_output(params->net, NULL, &fl6);
4341

4442
err = dst->error;
4543
if (dst->error) {
@@ -50,15 +48,14 @@ static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,
5048
return dst;
5149
}
5250

53-
static int xfrm6_get_saddr(struct net *net, int oif,
54-
xfrm_address_t *saddr, xfrm_address_t *daddr,
55-
u32 mark)
51+
static int xfrm6_get_saddr(xfrm_address_t *saddr,
52+
const struct xfrm_dst_lookup_params *params)
5653
{
5754
struct dst_entry *dst;
5855
struct net_device *dev;
5956
struct inet6_dev *idev;
6057

61-
dst = xfrm6_dst_lookup(net, 0, oif, NULL, daddr, mark);
58+
dst = xfrm6_dst_lookup(params);
6259
if (IS_ERR(dst))
6360
return -EHOSTUNREACH;
6461

@@ -68,7 +65,8 @@ static int xfrm6_get_saddr(struct net *net, int oif,
6865
return -EHOSTUNREACH;
6966
}
7067
dev = idev->dev;
71-
ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6);
68+
ipv6_dev_get_saddr(dev_net(dev), dev, &params->daddr->in6, 0,
69+
&saddr->in6);
7270
dst_release(dst);
7371
return 0;
7472
}

net/xfrm/xfrm_device.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
269269

270270
dev = dev_get_by_index(net, xuo->ifindex);
271271
if (!dev) {
272+
struct xfrm_dst_lookup_params params;
273+
272274
if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) {
273275
saddr = &x->props.saddr;
274276
daddr = &x->id.daddr;
@@ -277,9 +279,12 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
277279
daddr = &x->props.saddr;
278280
}
279281

280-
dst = __xfrm_dst_lookup(net, 0, 0, saddr, daddr,
281-
x->props.family,
282-
xfrm_smark_get(0, x));
282+
memset(&params, 0, sizeof(params));
283+
params.net = net;
284+
params.saddr = saddr;
285+
params.daddr = daddr;
286+
params.mark = xfrm_smark_get(0, x);
287+
dst = __xfrm_dst_lookup(x->props.family, &params);
283288
if (IS_ERR(dst))
284289
return (is_packet_offload) ? -EINVAL : 0;
285290

net/xfrm/xfrm_policy.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,8 @@ static const struct xfrm_if_cb *xfrm_if_get_cb(void)
270270
return rcu_dereference(xfrm_if_cb);
271271
}
272272

273-
struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos, int oif,
274-
const xfrm_address_t *saddr,
275-
const xfrm_address_t *daddr,
276-
int family, u32 mark)
273+
struct dst_entry *__xfrm_dst_lookup(int family,
274+
const struct xfrm_dst_lookup_params *params)
277275
{
278276
const struct xfrm_policy_afinfo *afinfo;
279277
struct dst_entry *dst;
@@ -282,7 +280,7 @@ struct dst_entry *__xfrm_dst_lookup(struct net *net, int tos, int oif,
282280
if (unlikely(afinfo == NULL))
283281
return ERR_PTR(-EAFNOSUPPORT);
284282

285-
dst = afinfo->dst_lookup(net, tos, oif, saddr, daddr, mark);
283+
dst = afinfo->dst_lookup(params);
286284

287285
rcu_read_unlock();
288286

@@ -296,6 +294,7 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x,
296294
xfrm_address_t *prev_daddr,
297295
int family, u32 mark)
298296
{
297+
struct xfrm_dst_lookup_params params;
299298
struct net *net = xs_net(x);
300299
xfrm_address_t *saddr = &x->props.saddr;
301300
xfrm_address_t *daddr = &x->id.daddr;
@@ -310,7 +309,14 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x,
310309
daddr = x->coaddr;
311310
}
312311

313-
dst = __xfrm_dst_lookup(net, tos, oif, saddr, daddr, family, mark);
312+
params.net = net;
313+
params.saddr = saddr;
314+
params.daddr = daddr;
315+
params.tos = tos;
316+
params.oif = oif;
317+
params.mark = mark;
318+
319+
dst = __xfrm_dst_lookup(family, &params);
314320

315321
if (!IS_ERR(dst)) {
316322
if (prev_saddr != saddr)
@@ -2432,15 +2438,15 @@ int __xfrm_sk_clone_policy(struct sock *sk, const struct sock *osk)
24322438
}
24332439

24342440
static int
2435-
xfrm_get_saddr(struct net *net, int oif, xfrm_address_t *local,
2436-
xfrm_address_t *remote, unsigned short family, u32 mark)
2441+
xfrm_get_saddr(unsigned short family, xfrm_address_t *saddr,
2442+
const struct xfrm_dst_lookup_params *params)
24372443
{
24382444
int err;
24392445
const struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family);
24402446

24412447
if (unlikely(afinfo == NULL))
24422448
return -EINVAL;
2443-
err = afinfo->get_saddr(net, oif, local, remote, mark);
2449+
err = afinfo->get_saddr(saddr, params);
24442450
rcu_read_unlock();
24452451
return err;
24462452
}
@@ -2469,9 +2475,14 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl,
24692475
remote = &tmpl->id.daddr;
24702476
local = &tmpl->saddr;
24712477
if (xfrm_addr_any(local, tmpl->encap_family)) {
2472-
error = xfrm_get_saddr(net, fl->flowi_oif,
2473-
&tmp, remote,
2474-
tmpl->encap_family, 0);
2478+
struct xfrm_dst_lookup_params params;
2479+
2480+
memset(&params, 0, sizeof(params));
2481+
params.net = net;
2482+
params.oif = fl->flowi_oif;
2483+
params.daddr = remote;
2484+
error = xfrm_get_saddr(tmpl->encap_family, &tmp,
2485+
&params);
24752486
if (error)
24762487
goto fail;
24772488
local = &tmp;

0 commit comments

Comments
 (0)