Skip to content

Commit 7a49d3d

Browse files
committed
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next
Steffen Klassert says: ==================== pull request (net-next): ipsec-next 2018-07-27 1) Extend the output_mark to also support the input direction and masking the mark values before applying to the skb. 2) Add a new lookup key for the upcomming xfrm interfaces. 3) Extend the xfrm lookups to match xfrm interface IDs. 4) Add virtual xfrm interfaces. The purpose of these interfaces is to overcome the design limitations that the existing VTI devices have. The main limitations that we see with the current VTI are the following: VTI interfaces are L3 tunnels with configurable endpoints. For xfrm, the tunnel endpoint are already determined by the SA. So the VTI tunnel endpoints must be either the same as on the SA or wildcards. In case VTI tunnel endpoints are same as on the SA, we get a one to one correlation between the SA and the tunnel. So each SA needs its own tunnel interface. On the other hand, we can have only one VTI tunnel with wildcard src/dst tunnel endpoints in the system because the lookup is based on the tunnel endpoints. The existing tunnel lookup won't work with multiple tunnels with wildcard tunnel endpoints. Some usecases require more than on VTI tunnel of this type, for example if somebody has multiple namespaces and every namespace requires such a VTI. VTI needs separate interfaces for IPv4 and IPv6 tunnels. So when routing to a VTI, we have to know to which address family this traffic class is going to be encapsulated. This is a lmitation because it makes routing more complex and it is not always possible to know what happens behind the VTI, e.g. when the VTI is move to some namespace. VTI works just with tunnel mode SAs. We need generic interfaces that ensures transfomation, regardless of the xfrm mode and the encapsulated address family. VTI is configured with a combination GRE keys and xfrm marks. With this we have to deal with some extra cases in the generic tunnel lookup because the GRE keys on the VTI are actually not GRE keys, the GRE keys were just reused for something else. All extensions to the VTI interfaces would require to add even more complexity to the generic tunnel lookup. So to overcome this, we developed xfrm interfaces with the following design goal: It should be possible to tunnel IPv4 and IPv6 through the same interface. No limitation on xfrm mode (tunnel, transport and beet). Should be a generic virtual interface that ensures IPsec transformation, no need to know what happens behind the interface. Interfaces should be configured with a new key that must match a new policy/SA lookup key. The lookup logic should stay in the xfrm codebase, no need to change or extend generic routing and tunnel lookups. Should be possible to use IPsec hardware offloads of the underlying interface. 5) Remove xfrm pcpu policy cache. This was added after the flowcache removal, but it turned out to make things even worse. From Florian Westphal. 6) Allow to update the set mark on SA updates. From Nathan Harold. 7) Convert some timestamps to time64_t. From Arnd Bergmann. 8) Don't check the offload_handle in xfrm code, it is an opaque data cookie for the driver. From Shannon Nelson. 9) Remove xfrmi interface ID from flowi. After this pach no generic code is touched anymore to do xfrm interface lookups. From Benedict Wong. 10) Allow to update the xfrm interface ID on SA updates. From Nathan Harold. 11) Don't pass zero to ERR_PTR() in xfrm_resolve_and_create_bundle. From YueHaibing. 12) Return more detailed errors on xfrm interface creation. From Benedict Wong. 13) Use PTR_ERR_OR_ZERO instead of IS_ERR + PTR_ERR. From the kbuild test robot. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ecbcd68 + c6f5e01 commit 7a49d3d

18 files changed

Lines changed: 1331 additions & 246 deletions

‎include/net/dst.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ static inline struct dst_entry *xfrm_lookup(struct net *net,
475475
return dst_orig;
476476
}
477477

478+
static inline struct dst_entry *
479+
xfrm_lookup_with_ifid(struct net *net, struct dst_entry *dst_orig,
480+
const struct flowi *fl, const struct sock *sk,
481+
int flags, u32 if_id)
482+
{
483+
return dst_orig;
484+
}
485+
478486
static inline struct dst_entry *xfrm_lookup_route(struct net *net,
479487
struct dst_entry *dst_orig,
480488
const struct flowi *fl,
@@ -494,6 +502,12 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
494502
const struct flowi *fl, const struct sock *sk,
495503
int flags);
496504

505+
struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
506+
struct dst_entry *dst_orig,
507+
const struct flowi *fl,
508+
const struct sock *sk, int flags,
509+
u32 if_id);
510+
497511
struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
498512
const struct flowi *fl, const struct sock *sk,
499513
int flags);

‎include/net/xfrm.h‎

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <net/ipv6.h>
2424
#include <net/ip6_fib.h>
2525
#include <net/flow.h>
26+
#include <net/gro_cells.h>
2627

2728
#include <linux/interrupt.h>
2829

@@ -147,6 +148,7 @@ struct xfrm_state {
147148
struct xfrm_id id;
148149
struct xfrm_selector sel;
149150
struct xfrm_mark mark;
151+
u32 if_id;
150152
u32 tfcpad;
151153

152154
u32 genid;
@@ -166,7 +168,7 @@ struct xfrm_state {
166168
int header_len;
167169
int trailer_len;
168170
u32 extra_flags;
169-
u32 output_mark;
171+
struct xfrm_mark smark;
170172
} props;
171173

172174
struct xfrm_lifetime_cfg lft;
@@ -225,7 +227,7 @@ struct xfrm_state {
225227
long saved_tmo;
226228

227229
/* Last used time */
228-
unsigned long lastused;
230+
time64_t lastused;
229231

230232
struct page_frag xfrag;
231233

@@ -292,6 +294,13 @@ struct xfrm_replay {
292294
int (*overflow)(struct xfrm_state *x, struct sk_buff *skb);
293295
};
294296

297+
struct xfrm_if_cb {
298+
struct xfrm_if *(*decode_session)(struct sk_buff *skb);
299+
};
300+
301+
void xfrm_if_register_cb(const struct xfrm_if_cb *ifcb);
302+
void xfrm_if_unregister_cb(void);
303+
295304
struct net_device;
296305
struct xfrm_type;
297306
struct xfrm_dst;
@@ -323,7 +332,6 @@ int xfrm_policy_register_afinfo(const struct xfrm_policy_afinfo *afinfo, int fam
323332
void xfrm_policy_unregister_afinfo(const struct xfrm_policy_afinfo *afinfo);
324333
void km_policy_notify(struct xfrm_policy *xp, int dir,
325334
const struct km_event *c);
326-
void xfrm_policy_cache_flush(void);
327335
void km_state_notify(struct xfrm_state *x, const struct km_event *c);
328336

329337
struct xfrm_tmpl;
@@ -574,6 +582,7 @@ struct xfrm_policy {
574582
atomic_t genid;
575583
u32 priority;
576584
u32 index;
585+
u32 if_id;
577586
struct xfrm_mark mark;
578587
struct xfrm_selector selector;
579588
struct xfrm_lifetime_cfg lft;
@@ -1037,6 +1046,22 @@ static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
10371046

10381047
void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
10391048

1049+
struct xfrm_if_parms {
1050+
char name[IFNAMSIZ]; /* name of XFRM device */
1051+
int link; /* ifindex of underlying L2 interface */
1052+
u32 if_id; /* interface identifyer */
1053+
};
1054+
1055+
struct xfrm_if {
1056+
struct xfrm_if __rcu *next; /* next interface in list */
1057+
struct net_device *dev; /* virtual device associated with interface */
1058+
struct net_device *phydev; /* physical device */
1059+
struct net *net; /* netns for packet i/o */
1060+
struct xfrm_if_parms p; /* interface parms */
1061+
1062+
struct gro_cells gro_cells;
1063+
};
1064+
10401065
struct xfrm_offload {
10411066
/* Output sequence number for replay protection on offloading. */
10421067
struct {
@@ -1532,8 +1557,8 @@ struct xfrm_state *xfrm_state_find(const xfrm_address_t *daddr,
15321557
const struct flowi *fl,
15331558
struct xfrm_tmpl *tmpl,
15341559
struct xfrm_policy *pol, int *err,
1535-
unsigned short family);
1536-
struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark,
1560+
unsigned short family, u32 if_id);
1561+
struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark, u32 if_id,
15371562
xfrm_address_t *daddr,
15381563
xfrm_address_t *saddr,
15391564
unsigned short family,
@@ -1690,20 +1715,20 @@ int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
16901715
void *);
16911716
void xfrm_policy_walk_done(struct xfrm_policy_walk *walk, struct net *net);
16921717
int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl);
1693-
struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark,
1718+
struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u32 if_id,
16941719
u8 type, int dir,
16951720
struct xfrm_selector *sel,
16961721
struct xfrm_sec_ctx *ctx, int delete,
16971722
int *err);
1698-
struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir,
1699-
u32 id, int delete, int *err);
1723+
struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u32 if_id, u8,
1724+
int dir, u32 id, int delete, int *err);
17001725
int xfrm_policy_flush(struct net *net, u8 type, bool task_valid);
17011726
void xfrm_policy_hash_rebuild(struct net *net);
17021727
u32 xfrm_get_acqseq(void);
17031728
int verify_spi_info(u8 proto, u32 min, u32 max);
17041729
int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);
17051730
struct xfrm_state *xfrm_find_acq(struct net *net, const struct xfrm_mark *mark,
1706-
u8 mode, u32 reqid, u8 proto,
1731+
u8 mode, u32 reqid, u32 if_id, u8 proto,
17071732
const xfrm_address_t *daddr,
17081733
const xfrm_address_t *saddr, int create,
17091734
unsigned short family);
@@ -2012,6 +2037,22 @@ static inline int xfrm_mark_put(struct sk_buff *skb, const struct xfrm_mark *m)
20122037
return ret;
20132038
}
20142039

2040+
static inline __u32 xfrm_smark_get(__u32 mark, struct xfrm_state *x)
2041+
{
2042+
struct xfrm_mark *m = &x->props.smark;
2043+
2044+
return (m->v & m->m) | (mark & ~m->m);
2045+
}
2046+
2047+
static inline int xfrm_if_id_put(struct sk_buff *skb, __u32 if_id)
2048+
{
2049+
int ret = 0;
2050+
2051+
if (if_id)
2052+
ret = nla_put_u32(skb, XFRMA_IF_ID, if_id);
2053+
return ret;
2054+
}
2055+
20152056
static inline int xfrm_tunnel_check(struct sk_buff *skb, struct xfrm_state *x,
20162057
unsigned int family)
20172058
{

‎include/uapi/linux/if_link.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ enum {
460460

461461
#define IFLA_MACSEC_MAX (__IFLA_MACSEC_MAX - 1)
462462

463+
/* XFRM section */
464+
enum {
465+
IFLA_XFRM_UNSPEC,
466+
IFLA_XFRM_LINK,
467+
IFLA_XFRM_IF_ID,
468+
__IFLA_XFRM_MAX
469+
};
470+
471+
#define IFLA_XFRM_MAX (__IFLA_XFRM_MAX - 1)
472+
463473
enum macsec_validation_type {
464474
MACSEC_VALIDATE_DISABLED = 0,
465475
MACSEC_VALIDATE_CHECK = 1,

‎include/uapi/linux/xfrm.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,12 @@ enum xfrm_attr_type_t {
305305
XFRMA_ADDRESS_FILTER, /* struct xfrm_address_filter */
306306
XFRMA_PAD,
307307
XFRMA_OFFLOAD_DEV, /* struct xfrm_state_offload */
308-
XFRMA_OUTPUT_MARK, /* __u32 */
308+
XFRMA_SET_MARK, /* __u32 */
309+
XFRMA_SET_MARK_MASK, /* __u32 */
310+
XFRMA_IF_ID, /* __u32 */
309311
__XFRMA_MAX
310312

313+
#define XFRMA_OUTPUT_MARK XFRMA_SET_MARK /* Compatibility */
311314
#define XFRMA_MAX (__XFRMA_MAX - 1)
312315
};
313316

‎net/core/pktgen.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow)
22532253
x = xfrm_state_lookup_byspi(pn->net, htonl(pkt_dev->spi), AF_INET);
22542254
} else {
22552255
/* slow path: we dont already have xfrm_state */
2256-
x = xfrm_stateonly_find(pn->net, DUMMY_MARK,
2256+
x = xfrm_stateonly_find(pn->net, DUMMY_MARK, 0,
22572257
(xfrm_address_t *)&pkt_dev->cur_daddr,
22582258
(xfrm_address_t *)&pkt_dev->cur_saddr,
22592259
AF_INET,

‎net/ipv4/esp4_offload.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
135135

136136
skb->encap_hdr_csum = 1;
137137

138-
if (!(features & NETIF_F_HW_ESP) || !x->xso.offload_handle ||
139-
(x->xso.dev != skb->dev))
138+
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev)
140139
esp_features = features & ~(NETIF_F_SG | NETIF_F_CSUM_MASK);
141140
else if (!(features & NETIF_F_HW_ESP_TX_CSUM))
142141
esp_features = features & ~NETIF_F_CSUM_MASK;
@@ -179,8 +178,7 @@ static int esp_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features_
179178
if (!xo)
180179
return -EINVAL;
181180

182-
if (!(features & NETIF_F_HW_ESP) || !x->xso.offload_handle ||
183-
(x->xso.dev != skb->dev)) {
181+
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev) {
184182
xo->flags |= CRYPTO_FALLBACK;
185183
hw_offload = false;
186184
}

‎net/ipv6/esp6_offload.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ static struct sk_buff *esp6_gso_segment(struct sk_buff *skb,
162162

163163
skb->encap_hdr_csum = 1;
164164

165-
if (!(features & NETIF_F_HW_ESP) || !x->xso.offload_handle ||
166-
(x->xso.dev != skb->dev))
165+
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev)
167166
esp_features = features & ~(NETIF_F_SG | NETIF_F_CSUM_MASK);
168167
else if (!(features & NETIF_F_HW_ESP_TX_CSUM))
169168
esp_features = features & ~NETIF_F_CSUM_MASK;
@@ -207,8 +206,7 @@ static int esp6_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features
207206
if (!xo)
208207
return -EINVAL;
209208

210-
if (!(features & NETIF_F_HW_ESP) || !x->xso.offload_handle ||
211-
(x->xso.dev != skb->dev)) {
209+
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev) {
212210
xo->flags |= CRYPTO_FALLBACK;
213211
hw_offload = false;
214212
}

‎net/ipv6/xfrm6_mode_ro.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
5555
__skb_pull(skb, hdr_len);
5656
memmove(ipv6_hdr(skb), iph, hdr_len);
5757

58-
x->lastused = get_seconds();
58+
x->lastused = ktime_get_real_seconds();
5959

6060
return 0;
6161
}

‎net/key/af_key.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_
13831383
}
13841384

13851385
if (!x)
1386-
x = xfrm_find_acq(net, &dummy_mark, mode, reqid, proto, xdaddr, xsaddr, 1, family);
1386+
x = xfrm_find_acq(net, &dummy_mark, mode, reqid, 0, proto, xdaddr, xsaddr, 1, family);
13871387

13881388
if (x == NULL)
13891389
return -ENOENT;
@@ -2414,7 +2414,7 @@ static int pfkey_spddelete(struct sock *sk, struct sk_buff *skb, const struct sa
24142414
return err;
24152415
}
24162416

2417-
xp = xfrm_policy_bysel_ctx(net, DUMMY_MARK, XFRM_POLICY_TYPE_MAIN,
2417+
xp = xfrm_policy_bysel_ctx(net, DUMMY_MARK, 0, XFRM_POLICY_TYPE_MAIN,
24182418
pol->sadb_x_policy_dir - 1, &sel, pol_ctx,
24192419
1, &err);
24202420
security_xfrm_policy_free(pol_ctx);
@@ -2663,7 +2663,7 @@ static int pfkey_spdget(struct sock *sk, struct sk_buff *skb, const struct sadb_
26632663
return -EINVAL;
26642664

26652665
delete = (hdr->sadb_msg_type == SADB_X_SPDDELETE2);
2666-
xp = xfrm_policy_byid(net, DUMMY_MARK, XFRM_POLICY_TYPE_MAIN,
2666+
xp = xfrm_policy_byid(net, DUMMY_MARK, 0, XFRM_POLICY_TYPE_MAIN,
26672667
dir, pol->sadb_x_policy_id, delete, &err);
26682668
if (xp == NULL)
26692669
return -ENOENT;

‎net/xfrm/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ config XFRM_USER
2525

2626
If unsure, say Y.
2727

28+
config XFRM_INTERFACE
29+
tristate "Transformation virtual interface"
30+
depends on XFRM && IPV6
31+
---help---
32+
This provides a virtual interface to route IPsec traffic.
33+
34+
If unsure, say N.
35+
2836
config XFRM_SUB_POLICY
2937
bool "Transformation sub policy support"
3038
depends on XFRM

0 commit comments

Comments
 (0)