Skip to content

Commit ea40354

Browse files
committed
Merge tag 'ipsec-next-2024-09-10' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next
Steffen Klassert says: ==================== pull request (net-next): ipsec-next 2024-09-10 1) Remove an unneeded WARN_ON on packet offload. From Patrisious Haddad. 2) Add a copy from skb_seq_state to buffer function. This is needed for the upcomming IPTFS patchset. From Christian Hopps. 3) Spelling fix in xfrm.h. From Simon Horman. 4) Speed up xfrm policy insertions. From Florian Westphal. 5) Add and revert a patch to support xfrm interfaces for packet offload. This patch was just half cooked. 6) Extend usage of the new xfrm_policy_is_dead_or_sk helper. From Florian Westphal. 7) Update comments on sdb and xfrm_policy. From Florian Westphal. 8) Fix a null pointer dereference in the new policy insertion code From Florian Westphal. 9) Fix an uninitialized variable in the new policy insertion code. From Nathan Chancellor. * tag 'ipsec-next-2024-09-10' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next: xfrm: policy: Restore dir assignments in xfrm_hash_rebuild() xfrm: policy: fix null dereference Revert "xfrm: add SA information to the offloaded packet" xfrm: minor update to sdb and xfrm_policy comments xfrm: policy: use recently added helper in more places xfrm: add SA information to the offloaded packet xfrm: policy: remove remaining use of inexact list xfrm: switch migrate to xfrm_policy_lookup_bytype xfrm: policy: don't iterate inexact policies twice at insert time selftests: add xfrm policy insertion speed test script xfrm: Correct spelling in xfrm.h net: add copy from skb_seq_state to buffer function xfrm: Remove documentation WARN_ON to limit return values for offloaded SA ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents e35b051 + e62d393 commit ea40354

File tree

7 files changed

+258
-136
lines changed

7 files changed

+258
-136
lines changed

include/linux/skbuff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from,
14331433
unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
14341434
struct skb_seq_state *st);
14351435
void skb_abort_seq_read(struct skb_seq_state *st);
1436+
int skb_copy_seq_read(struct skb_seq_state *st, int offset, void *to, int len);
14361437

14371438
unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
14381439
unsigned int to, struct ts_config *config);

include/net/xfrm.h

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,27 @@
6767
- instance of a transformer, struct xfrm_state (=SA)
6868
- template to clone xfrm_state, struct xfrm_tmpl
6969
70-
SPD is plain linear list of xfrm_policy rules, ordered by priority.
70+
SPD is organized as hash table (for policies that meet minimum address prefix
71+
length setting, net->xfrm.policy_hthresh). Other policies are stored in
72+
lists, sorted into rbtree ordered by destination and source address networks.
73+
See net/xfrm/xfrm_policy.c for details.
74+
7175
(To be compatible with existing pfkeyv2 implementations,
7276
many rules with priority of 0x7fffffff are allowed to exist and
7377
such rules are ordered in an unpredictable way, thanks to bsd folks.)
7478
75-
Lookup is plain linear search until the first match with selector.
76-
7779
If "action" is "block", then we prohibit the flow, otherwise:
7880
if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
7981
policy entry has list of up to XFRM_MAX_DEPTH transformations,
8082
described by templates xfrm_tmpl. Each template is resolved
8183
to a complete xfrm_state (see below) and we pack bundle of transformations
82-
to a dst_entry returned to requestor.
84+
to a dst_entry returned to requester.
8385
8486
dst -. xfrm .-> xfrm_state #1
8587
|---. child .-> dst -. xfrm .-> xfrm_state #2
8688
|---. child .-> dst -. xfrm .-> xfrm_state #3
8789
|---. child .-> NULL
8890
89-
Bundles are cached at xrfm_policy struct (field ->bundles).
90-
9191
9292
Resolution of xrfm_tmpl
9393
-----------------------
@@ -526,6 +526,36 @@ struct xfrm_policy_queue {
526526
unsigned long timeout;
527527
};
528528

529+
/**
530+
* struct xfrm_policy - xfrm policy
531+
* @xp_net: network namespace the policy lives in
532+
* @bydst: hlist node for SPD hash table or rbtree list
533+
* @byidx: hlist node for index hash table
534+
* @lock: serialize changes to policy structure members
535+
* @refcnt: reference count, freed once it reaches 0
536+
* @pos: kernel internal tie-breaker to determine age of policy
537+
* @timer: timer
538+
* @genid: generation, used to invalidate old policies
539+
* @priority: priority, set by userspace
540+
* @index: policy index (autogenerated)
541+
* @if_id: virtual xfrm interface id
542+
* @mark: packet mark
543+
* @selector: selector
544+
* @lft: liftime configuration data
545+
* @curlft: liftime state
546+
* @walk: list head on pernet policy list
547+
* @polq: queue to hold packets while aqcuire operaion in progress
548+
* @bydst_reinsert: policy tree node needs to be merged
549+
* @type: XFRM_POLICY_TYPE_MAIN or _SUB
550+
* @action: XFRM_POLICY_ALLOW or _BLOCK
551+
* @flags: XFRM_POLICY_LOCALOK, XFRM_POLICY_ICMP
552+
* @xfrm_nr: number of used templates in @xfrm_vec
553+
* @family: protocol family
554+
* @security: SELinux security label
555+
* @xfrm_vec: array of templates to resolve state
556+
* @rcu: rcu head, used to defer memory release
557+
* @xdo: hardware offload state
558+
*/
529559
struct xfrm_policy {
530560
possible_net_t xp_net;
531561
struct hlist_node bydst;
@@ -555,7 +585,6 @@ struct xfrm_policy {
555585
u16 family;
556586
struct xfrm_sec_ctx *security;
557587
struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
558-
struct hlist_node bydst_inexact_list;
559588
struct rcu_head rcu;
560589

561590
struct xfrm_dev_offload xdo;
@@ -1016,7 +1045,7 @@ void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
10161045

10171046
struct xfrm_if_parms {
10181047
int link; /* ifindex of underlying L2 interface */
1019-
u32 if_id; /* interface identifyer */
1048+
u32 if_id; /* interface identifier */
10201049
bool collect_md;
10211050
};
10221051

net/core/skbuff.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,6 +4411,41 @@ void skb_abort_seq_read(struct skb_seq_state *st)
44114411
}
44124412
EXPORT_SYMBOL(skb_abort_seq_read);
44134413

4414+
/**
4415+
* skb_copy_seq_read() - copy from a skb_seq_state to a buffer
4416+
* @st: source skb_seq_state
4417+
* @offset: offset in source
4418+
* @to: destination buffer
4419+
* @len: number of bytes to copy
4420+
*
4421+
* Copy @len bytes from @offset bytes into the source @st to the destination
4422+
* buffer @to. `offset` should increase (or be unchanged) with each subsequent
4423+
* call to this function. If offset needs to decrease from the previous use `st`
4424+
* should be reset first.
4425+
*
4426+
* Return: 0 on success or -EINVAL if the copy ended early
4427+
*/
4428+
int skb_copy_seq_read(struct skb_seq_state *st, int offset, void *to, int len)
4429+
{
4430+
const u8 *data;
4431+
u32 sqlen;
4432+
4433+
for (;;) {
4434+
sqlen = skb_seq_read(offset, &data, st);
4435+
if (sqlen == 0)
4436+
return -EINVAL;
4437+
if (sqlen >= len) {
4438+
memcpy(to, data, len);
4439+
return 0;
4440+
}
4441+
memcpy(to, data, sqlen);
4442+
to += sqlen;
4443+
offset += sqlen;
4444+
len -= sqlen;
4445+
}
4446+
}
4447+
EXPORT_SYMBOL(skb_copy_seq_read);
4448+
44144449
#define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb))
44154450

44164451
static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text,

net/xfrm/xfrm_device.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,8 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,
328328
/* User explicitly requested packet offload mode and configured
329329
* policy in addition to the XFRM state. So be civil to users,
330330
* and return an error instead of taking fallback path.
331-
*
332-
* This WARN_ON() can be seen as a documentation for driver
333-
* authors to do not return -EOPNOTSUPP in packet offload mode.
334331
*/
335-
WARN_ON(err == -EOPNOTSUPP && is_packet_offload);
336-
if (err != -EOPNOTSUPP || is_packet_offload) {
332+
if ((err != -EOPNOTSUPP && !is_packet_offload) || is_packet_offload) {
337333
NL_SET_ERR_MSG_WEAK(extack, "Device failed to offload this state");
338334
return err;
339335
}

0 commit comments

Comments
 (0)