Skip to content

Commit b0fcee8

Browse files
committed
xfrm: Add a secpath_set helper.
Add a new helper to set the secpath to the skb. This avoids code duplication, as this is used in multiple places. Signed-off-by: Steffen Klassert <[email protected]>
1 parent 37b1038 commit b0fcee8

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

include/net/xfrm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ secpath_put(struct sec_path *sp)
10061006
}
10071007

10081008
struct sec_path *secpath_dup(struct sec_path *src);
1009+
int secpath_set(struct sk_buff *skb);
10091010

10101011
static inline void
10111012
secpath_reset(struct sk_buff *skb)

net/ipv6/xfrm6_input.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,9 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
6969
struct xfrm_state *x = NULL;
7070
int i = 0;
7171

72-
/* Allocate new secpath or COW existing one. */
73-
if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) {
74-
struct sec_path *sp;
75-
76-
sp = secpath_dup(skb->sp);
77-
if (!sp) {
78-
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
79-
goto drop;
80-
}
81-
if (skb->sp)
82-
secpath_put(skb->sp);
83-
skb->sp = sp;
72+
if (secpath_set(skb)) {
73+
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
74+
goto drop;
8475
}
8576

8677
if (1 + skb->sp->len == XFRM_MAX_DEPTH) {

net/xfrm/xfrm_input.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ struct sec_path *secpath_dup(struct sec_path *src)
117117
}
118118
EXPORT_SYMBOL(secpath_dup);
119119

120+
int secpath_set(struct sk_buff *skb)
121+
{
122+
struct sec_path *sp;
123+
124+
/* Allocate new secpath or COW existing one. */
125+
if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) {
126+
sp = secpath_dup(skb->sp);
127+
if (!sp)
128+
return -ENOMEM;
129+
130+
if (skb->sp)
131+
secpath_put(skb->sp);
132+
skb->sp = sp;
133+
}
134+
return 0;
135+
}
136+
EXPORT_SYMBOL(secpath_set);
137+
120138
/* Fetch spi and seq from ipsec header */
121139

122140
int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
@@ -212,18 +230,10 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
212230
break;
213231
}
214232

215-
/* Allocate new secpath or COW existing one. */
216-
if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) {
217-
struct sec_path *sp;
218-
219-
sp = secpath_dup(skb->sp);
220-
if (!sp) {
221-
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
222-
goto drop;
223-
}
224-
if (skb->sp)
225-
secpath_put(skb->sp);
226-
skb->sp = sp;
233+
err = secpath_set(skb);
234+
if (err) {
235+
XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
236+
goto drop;
227237
}
228238

229239
seq = 0;

0 commit comments

Comments
 (0)