Skip to content

Commit a658a3f

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 2019-04-30 1) A lot of work to remove indirections from the xfrm code. From Florian Westphal. 2) Support ESP offload in combination with gso partial. From Boris Pismenny. 3) Remove some duplicated code from vti4. From Jeremy Sowden. Please note that there is merge conflict between commit: 8742dc8 ("xfrm4: Fix uninitialized memory read in _decode_session4") from the ipsec tree and commit: c53ac41 ("xfrm: remove decode_session indirection from afinfo_policy") from the ipsec-next tree. The merge conflict will appear when those trees get merged during the merge window. The conflict can be solved as it is done in linux-next: https://lkml.org/lkml/2019/4/25/1207 Please pull or let me know if there are problems. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7a1d839 + bb9cd07 commit a658a3f

32 files changed

+1249
-1594
lines changed

include/net/xfrm.h

Lines changed: 23 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ struct xfrm_state_offload {
132132
u8 flags;
133133
};
134134

135+
struct xfrm_mode {
136+
u8 encap;
137+
u8 family;
138+
u8 flags;
139+
};
140+
141+
/* Flags for xfrm_mode. */
142+
enum {
143+
XFRM_MODE_FLAG_TUNNEL = 1,
144+
};
145+
135146
/* Full description of state of transformer. */
136147
struct xfrm_state {
137148
possible_net_t xs_net;
@@ -234,9 +245,9 @@ struct xfrm_state {
234245
/* Reference to data common to all the instances of this
235246
* transformer. */
236247
const struct xfrm_type *type;
237-
struct xfrm_mode *inner_mode;
238-
struct xfrm_mode *inner_mode_iaf;
239-
struct xfrm_mode *outer_mode;
248+
struct xfrm_mode inner_mode;
249+
struct xfrm_mode inner_mode_iaf;
250+
struct xfrm_mode outer_mode;
240251

241252
const struct xfrm_type_offload *type_offload;
242253

@@ -315,13 +326,6 @@ struct xfrm_policy_afinfo {
315326
xfrm_address_t *saddr,
316327
xfrm_address_t *daddr,
317328
u32 mark);
318-
void (*decode_session)(struct sk_buff *skb,
319-
struct flowi *fl,
320-
int reverse);
321-
int (*get_tos)(const struct flowi *fl);
322-
int (*init_path)(struct xfrm_dst *path,
323-
struct dst_entry *dst,
324-
int nfheader_len);
325329
int (*fill_dst)(struct xfrm_dst *xdst,
326330
struct net_device *dev,
327331
const struct flowi *fl);
@@ -347,7 +351,6 @@ struct xfrm_state_afinfo {
347351
struct module *owner;
348352
const struct xfrm_type *type_map[IPPROTO_MAX];
349353
const struct xfrm_type_offload *type_offload_map[IPPROTO_MAX];
350-
struct xfrm_mode *mode_map[XFRM_MODE_MAX];
351354

352355
int (*init_flags)(struct xfrm_state *x);
353356
void (*init_tempsel)(struct xfrm_selector *sel,
@@ -422,78 +425,6 @@ struct xfrm_type_offload {
422425
int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
423426
int xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
424427

425-
struct xfrm_mode {
426-
/*
427-
* Remove encapsulation header.
428-
*
429-
* The IP header will be moved over the top of the encapsulation
430-
* header.
431-
*
432-
* On entry, the transport header shall point to where the IP header
433-
* should be and the network header shall be set to where the IP
434-
* header currently is. skb->data shall point to the start of the
435-
* payload.
436-
*/
437-
int (*input2)(struct xfrm_state *x, struct sk_buff *skb);
438-
439-
/*
440-
* This is the actual input entry point.
441-
*
442-
* For transport mode and equivalent this would be identical to
443-
* input2 (which does not need to be set). While tunnel mode
444-
* and equivalent would set this to the tunnel encapsulation function
445-
* xfrm4_prepare_input that would in turn call input2.
446-
*/
447-
int (*input)(struct xfrm_state *x, struct sk_buff *skb);
448-
449-
/*
450-
* Add encapsulation header.
451-
*
452-
* On exit, the transport header will be set to the start of the
453-
* encapsulation header to be filled in by x->type->output and
454-
* the mac header will be set to the nextheader (protocol for
455-
* IPv4) field of the extension header directly preceding the
456-
* encapsulation header, or in its absence, that of the top IP
457-
* header. The value of the network header will always point
458-
* to the top IP header while skb->data will point to the payload.
459-
*/
460-
int (*output2)(struct xfrm_state *x,struct sk_buff *skb);
461-
462-
/*
463-
* This is the actual output entry point.
464-
*
465-
* For transport mode and equivalent this would be identical to
466-
* output2 (which does not need to be set). While tunnel mode
467-
* and equivalent would set this to a tunnel encapsulation function
468-
* (xfrm4_prepare_output or xfrm6_prepare_output) that would in turn
469-
* call output2.
470-
*/
471-
int (*output)(struct xfrm_state *x, struct sk_buff *skb);
472-
473-
/*
474-
* Adjust pointers into the packet and do GSO segmentation.
475-
*/
476-
struct sk_buff *(*gso_segment)(struct xfrm_state *x, struct sk_buff *skb, netdev_features_t features);
477-
478-
/*
479-
* Adjust pointers into the packet when IPsec is done at layer2.
480-
*/
481-
void (*xmit)(struct xfrm_state *x, struct sk_buff *skb);
482-
483-
struct xfrm_state_afinfo *afinfo;
484-
struct module *owner;
485-
unsigned int encap;
486-
int flags;
487-
};
488-
489-
/* Flags for xfrm_mode. */
490-
enum {
491-
XFRM_MODE_FLAG_TUNNEL = 1,
492-
};
493-
494-
int xfrm_register_mode(struct xfrm_mode *mode, int family);
495-
int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
496-
497428
static inline int xfrm_af2proto(unsigned int family)
498429
{
499430
switch(family) {
@@ -506,13 +437,13 @@ static inline int xfrm_af2proto(unsigned int family)
506437
}
507438
}
508439

509-
static inline struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipproto)
440+
static inline const struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipproto)
510441
{
511442
if ((ipproto == IPPROTO_IPIP && x->props.family == AF_INET) ||
512443
(ipproto == IPPROTO_IPV6 && x->props.family == AF_INET6))
513-
return x->inner_mode;
444+
return &x->inner_mode;
514445
else
515-
return x->inner_mode_iaf;
446+
return &x->inner_mode_iaf;
516447
}
517448

518449
struct xfrm_tmpl {
@@ -1605,15 +1536,18 @@ int xfrm_init_replay(struct xfrm_state *x);
16051536
int xfrm_state_mtu(struct xfrm_state *x, int mtu);
16061537
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload);
16071538
int xfrm_init_state(struct xfrm_state *x);
1608-
int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb);
16091539
int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type);
16101540
int xfrm_input_resume(struct sk_buff *skb, int nexthdr);
16111541
int xfrm_trans_queue(struct sk_buff *skb,
16121542
int (*finish)(struct net *, struct sock *,
16131543
struct sk_buff *));
16141544
int xfrm_output_resume(struct sk_buff *skb, int err);
16151545
int xfrm_output(struct sock *sk, struct sk_buff *skb);
1616-
int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1546+
1547+
#if IS_ENABLED(CONFIG_NET_PKTGEN)
1548+
int pktgen_xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb);
1549+
#endif
1550+
16171551
void xfrm_local_error(struct sk_buff *skb, int mtu);
16181552
int xfrm4_extract_header(struct sk_buff *skb);
16191553
int xfrm4_extract_input(struct xfrm_state *x, struct sk_buff *skb);
@@ -1632,10 +1566,8 @@ static inline int xfrm4_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
16321566
}
16331567

16341568
int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1635-
int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
16361569
int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb);
16371570
int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb);
1638-
int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err);
16391571
int xfrm4_protocol_register(struct xfrm4_protocol *handler, unsigned char protocol);
16401572
int xfrm4_protocol_deregister(struct xfrm4_protocol *handler, unsigned char protocol);
16411573
int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family);
@@ -1651,15 +1583,13 @@ int xfrm6_rcv(struct sk_buff *skb);
16511583
int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
16521584
xfrm_address_t *saddr, u8 proto);
16531585
void xfrm6_local_error(struct sk_buff *skb, u32 mtu);
1654-
int xfrm6_rcv_cb(struct sk_buff *skb, u8 protocol, int err);
16551586
int xfrm6_protocol_register(struct xfrm6_protocol *handler, unsigned char protocol);
16561587
int xfrm6_protocol_deregister(struct xfrm6_protocol *handler, unsigned char protocol);
16571588
int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
16581589
int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
16591590
__be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
16601591
__be32 xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr);
16611592
int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1662-
int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
16631593
int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
16641594
int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb);
16651595
int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
@@ -2051,7 +1981,7 @@ static inline int xfrm_tunnel_check(struct sk_buff *skb, struct xfrm_state *x,
20511981
tunnel = true;
20521982
break;
20531983
}
2054-
if (tunnel && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL))
1984+
if (tunnel && !(x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL))
20551985
return -EINVAL;
20561986

20571987
return 0;

net/core/pktgen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
25212521
skb->_skb_refdst = (unsigned long)&pkt_dev->xdst.u.dst | SKB_DST_NOREF;
25222522

25232523
rcu_read_lock_bh();
2524-
err = x->outer_mode->output(x, skb);
2524+
err = pktgen_xfrm_outer_mode_output(x, skb);
25252525
rcu_read_unlock_bh();
25262526
if (err) {
25272527
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);

net/ipv4/Kconfig

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ config NET_IPVTI
304304
tristate "Virtual (secure) IP: tunneling"
305305
select INET_TUNNEL
306306
select NET_IP_TUNNEL
307-
depends on INET_XFRM_MODE_TUNNEL
307+
select XFRM
308308
---help---
309309
Tunneling means encapsulating data of one protocol type within
310310
another protocol and sending it over a channel that understands the
@@ -396,33 +396,6 @@ config INET_TUNNEL
396396
tristate
397397
default n
398398

399-
config INET_XFRM_MODE_TRANSPORT
400-
tristate "IP: IPsec transport mode"
401-
default y
402-
select XFRM
403-
---help---
404-
Support for IPsec transport mode.
405-
406-
If unsure, say Y.
407-
408-
config INET_XFRM_MODE_TUNNEL
409-
tristate "IP: IPsec tunnel mode"
410-
default y
411-
select XFRM
412-
---help---
413-
Support for IPsec tunnel mode.
414-
415-
If unsure, say Y.
416-
417-
config INET_XFRM_MODE_BEET
418-
tristate "IP: IPsec BEET mode"
419-
default y
420-
select XFRM
421-
---help---
422-
Support for IPsec BEET mode.
423-
424-
If unsure, say Y.
425-
426399
config INET_DIAG
427400
tristate "INET: socket monitoring interface"
428401
default y

net/ipv4/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ obj-$(CONFIG_INET_ESP) += esp4.o
3737
obj-$(CONFIG_INET_ESP_OFFLOAD) += esp4_offload.o
3838
obj-$(CONFIG_INET_IPCOMP) += ipcomp.o
3939
obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o
40-
obj-$(CONFIG_INET_XFRM_MODE_BEET) += xfrm4_mode_beet.o
4140
obj-$(CONFIG_INET_TUNNEL) += tunnel4.o
42-
obj-$(CONFIG_INET_XFRM_MODE_TRANSPORT) += xfrm4_mode_transport.o
43-
obj-$(CONFIG_INET_XFRM_MODE_TUNNEL) += xfrm4_mode_tunnel.o
4441
obj-$(CONFIG_IP_PNP) += ipconfig.o
4542
obj-$(CONFIG_NETFILTER) += netfilter.o netfilter/
4643
obj-$(CONFIG_INET_DIAG) += inet_diag.o

net/ipv4/esp4_offload.c

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ static void esp4_gso_encap(struct xfrm_state *x, struct sk_buff *skb)
107107
xo->proto = proto;
108108
}
109109

110+
static struct sk_buff *xfrm4_tunnel_gso_segment(struct xfrm_state *x,
111+
struct sk_buff *skb,
112+
netdev_features_t features)
113+
{
114+
__skb_push(skb, skb->mac_len);
115+
return skb_mac_gso_segment(skb, features);
116+
}
117+
118+
static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
119+
struct sk_buff *skb,
120+
netdev_features_t features)
121+
{
122+
const struct net_offload *ops;
123+
struct sk_buff *segs = ERR_PTR(-EINVAL);
124+
struct xfrm_offload *xo = xfrm_offload(skb);
125+
126+
skb->transport_header += x->props.header_len;
127+
ops = rcu_dereference(inet_offloads[xo->proto]);
128+
if (likely(ops && ops->callbacks.gso_segment))
129+
segs = ops->callbacks.gso_segment(skb, features);
130+
131+
return segs;
132+
}
133+
134+
static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
135+
struct sk_buff *skb,
136+
netdev_features_t features)
137+
{
138+
switch (x->outer_mode.encap) {
139+
case XFRM_MODE_TUNNEL:
140+
return xfrm4_tunnel_gso_segment(x, skb, features);
141+
case XFRM_MODE_TRANSPORT:
142+
return xfrm4_transport_gso_segment(x, skb, features);
143+
}
144+
145+
return ERR_PTR(-EOPNOTSUPP);
146+
}
147+
110148
static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
111149
netdev_features_t features)
112150
{
@@ -138,14 +176,16 @@ static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
138176

139177
skb->encap_hdr_csum = 1;
140178

141-
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev)
179+
if ((!(skb->dev->gso_partial_features & NETIF_F_HW_ESP) &&
180+
!(features & NETIF_F_HW_ESP)) || x->xso.dev != skb->dev)
142181
esp_features = features & ~(NETIF_F_SG | NETIF_F_CSUM_MASK);
143-
else if (!(features & NETIF_F_HW_ESP_TX_CSUM))
182+
else if (!(features & NETIF_F_HW_ESP_TX_CSUM) &&
183+
!(skb->dev->gso_partial_features & NETIF_F_HW_ESP_TX_CSUM))
144184
esp_features = features & ~NETIF_F_CSUM_MASK;
145185

146186
xo->flags |= XFRM_GSO_SEGMENT;
147187

148-
return x->outer_mode->gso_segment(x, skb, esp_features);
188+
return xfrm4_outer_mode_gso_segment(x, skb, esp_features);
149189
}
150190

151191
static int esp_input_tail(struct xfrm_state *x, struct sk_buff *skb)
@@ -181,7 +221,9 @@ static int esp_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features_
181221
if (!xo)
182222
return -EINVAL;
183223

184-
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev) {
224+
if ((!(features & NETIF_F_HW_ESP) &&
225+
!(skb->dev->gso_partial_features & NETIF_F_HW_ESP)) ||
226+
x->xso.dev != skb->dev) {
185227
xo->flags |= CRYPTO_FALLBACK;
186228
hw_offload = false;
187229
}

0 commit comments

Comments
 (0)