Skip to content

Commit acc086b

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 2020-03-28 1) Use kmem_cache_zalloc() instead of kmem_cache_alloc() in xfrm_state_alloc(). From Huang Zijiang. 2) esp_output_fill_trailer() is the same in IPv4 and IPv6, so share this function to avoide code duplcation. From Raed Salem. 3) Add offload support for esp beet mode. From Xin Long. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ee91a83 + 3084917 commit acc086b

7 files changed

Lines changed: 112 additions & 34 deletions

File tree

‎include/net/esp.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ static inline struct ip_esp_hdr *ip_esp_hdr(const struct sk_buff *skb)
1111
return (struct ip_esp_hdr *)skb_transport_header(skb);
1212
}
1313

14+
static inline void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
15+
{
16+
/* Fill padding... */
17+
if (tfclen) {
18+
memset(tail, 0, tfclen);
19+
tail += tfclen;
20+
}
21+
do {
22+
int i;
23+
for (i = 0; i < plen - 2; i++)
24+
tail[i] = i + 1;
25+
} while (0);
26+
tail[plen - 2] = plen - 2;
27+
tail[plen - 1] = proto;
28+
}
29+
1430
struct esp_info {
1531
struct ip_esp_hdr *esph;
1632
__be64 seqno;

‎net/ipv4/esp4.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,6 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err)
341341
esp_output_done(base, err);
342342
}
343343

344-
static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
345-
{
346-
/* Fill padding... */
347-
if (tfclen) {
348-
memset(tail, 0, tfclen);
349-
tail += tfclen;
350-
}
351-
do {
352-
int i;
353-
for (i = 0; i < plen - 2; i++)
354-
tail[i] = i + 1;
355-
} while (0);
356-
tail[plen - 2] = plen - 2;
357-
tail[plen - 1] = proto;
358-
}
359-
360344
static struct ip_esp_hdr *esp_output_udp_encap(struct sk_buff *skb,
361345
int encap_type,
362346
struct esp_info *esp,

‎net/ipv4/esp4_offload.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,36 @@ static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
132132
return segs;
133133
}
134134

135+
static struct sk_buff *xfrm4_beet_gso_segment(struct xfrm_state *x,
136+
struct sk_buff *skb,
137+
netdev_features_t features)
138+
{
139+
struct xfrm_offload *xo = xfrm_offload(skb);
140+
struct sk_buff *segs = ERR_PTR(-EINVAL);
141+
const struct net_offload *ops;
142+
int proto = xo->proto;
143+
144+
skb->transport_header += x->props.header_len;
145+
146+
if (proto == IPPROTO_BEETPH) {
147+
struct ip_beet_phdr *ph = (struct ip_beet_phdr *)skb->data;
148+
149+
skb->transport_header += ph->hdrlen * 8;
150+
proto = ph->nexthdr;
151+
} else if (x->sel.family != AF_INET6) {
152+
skb->transport_header -= IPV4_BEET_PHMAXLEN;
153+
} else if (proto == IPPROTO_TCP) {
154+
skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4;
155+
}
156+
157+
__skb_pull(skb, skb_transport_offset(skb));
158+
ops = rcu_dereference(inet_offloads[proto]);
159+
if (likely(ops && ops->callbacks.gso_segment))
160+
segs = ops->callbacks.gso_segment(skb, features);
161+
162+
return segs;
163+
}
164+
135165
static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
136166
struct sk_buff *skb,
137167
netdev_features_t features)
@@ -141,6 +171,8 @@ static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
141171
return xfrm4_tunnel_gso_segment(x, skb, features);
142172
case XFRM_MODE_TRANSPORT:
143173
return xfrm4_transport_gso_segment(x, skb, features);
174+
case XFRM_MODE_BEET:
175+
return xfrm4_beet_gso_segment(x, skb, features);
144176
}
145177

146178
return ERR_PTR(-EOPNOTSUPP);

‎net/ipv6/esp6.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,6 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err)
207207
esp_output_done(base, err);
208208
}
209209

210-
static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
211-
{
212-
/* Fill padding... */
213-
if (tfclen) {
214-
memset(tail, 0, tfclen);
215-
tail += tfclen;
216-
}
217-
do {
218-
int i;
219-
for (i = 0; i < plen - 2; i++)
220-
tail[i] = i + 1;
221-
} while (0);
222-
tail[plen - 2] = plen - 2;
223-
tail[plen - 1] = proto;
224-
}
225-
226210
int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
227211
{
228212
u8 *tail;

‎net/ipv6/esp6_offload.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,40 @@ static struct sk_buff *xfrm6_transport_gso_segment(struct xfrm_state *x,
159159
return segs;
160160
}
161161

162+
static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,
163+
struct sk_buff *skb,
164+
netdev_features_t features)
165+
{
166+
struct xfrm_offload *xo = xfrm_offload(skb);
167+
struct sk_buff *segs = ERR_PTR(-EINVAL);
168+
const struct net_offload *ops;
169+
int proto = xo->proto;
170+
171+
skb->transport_header += x->props.header_len;
172+
173+
if (proto == IPPROTO_BEETPH) {
174+
struct ip_beet_phdr *ph = (struct ip_beet_phdr *)skb->data;
175+
176+
skb->transport_header += ph->hdrlen * 8;
177+
proto = ph->nexthdr;
178+
}
179+
180+
if (x->sel.family != AF_INET6) {
181+
skb->transport_header -=
182+
(sizeof(struct ipv6hdr) - sizeof(struct iphdr));
183+
184+
if (proto == IPPROTO_TCP)
185+
skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
186+
}
187+
188+
__skb_pull(skb, skb_transport_offset(skb));
189+
ops = rcu_dereference(inet6_offloads[proto]);
190+
if (likely(ops && ops->callbacks.gso_segment))
191+
segs = ops->callbacks.gso_segment(skb, features);
192+
193+
return segs;
194+
}
195+
162196
static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
163197
struct sk_buff *skb,
164198
netdev_features_t features)
@@ -168,6 +202,8 @@ static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
168202
return xfrm6_tunnel_gso_segment(x, skb, features);
169203
case XFRM_MODE_TRANSPORT:
170204
return xfrm6_transport_gso_segment(x, skb, features);
205+
case XFRM_MODE_BEET:
206+
return xfrm6_beet_gso_segment(x, skb, features);
171207
}
172208

173209
return ERR_PTR(-EOPNOTSUPP);

‎net/xfrm/xfrm_device.c‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
4646
pskb_pull(skb, skb->mac_len + x->props.header_len);
4747
}
4848

49+
static void __xfrm_mode_beet_prep(struct xfrm_state *x, struct sk_buff *skb,
50+
unsigned int hsize)
51+
{
52+
struct xfrm_offload *xo = xfrm_offload(skb);
53+
int phlen = 0;
54+
55+
if (xo->flags & XFRM_GSO_SEGMENT)
56+
skb->transport_header = skb->network_header + hsize;
57+
58+
skb_reset_mac_len(skb);
59+
if (x->sel.family != AF_INET6) {
60+
phlen = IPV4_BEET_PHMAXLEN;
61+
if (x->outer_mode.family == AF_INET6)
62+
phlen += sizeof(struct ipv6hdr) - sizeof(struct iphdr);
63+
}
64+
65+
pskb_pull(skb, skb->mac_len + hsize + (x->props.header_len - phlen));
66+
}
67+
4968
/* Adjust pointers into the packet when IPsec is done at layer2 */
5069
static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
5170
{
@@ -66,9 +85,16 @@ static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
6685
return __xfrm_transport_prep(x, skb,
6786
sizeof(struct ipv6hdr));
6887
break;
88+
case XFRM_MODE_BEET:
89+
if (x->outer_mode.family == AF_INET)
90+
return __xfrm_mode_beet_prep(x, skb,
91+
sizeof(struct iphdr));
92+
if (x->outer_mode.family == AF_INET6)
93+
return __xfrm_mode_beet_prep(x, skb,
94+
sizeof(struct ipv6hdr));
95+
break;
6996
case XFRM_MODE_ROUTEOPTIMIZATION:
7097
case XFRM_MODE_IN_TRIGGER:
71-
case XFRM_MODE_BEET:
7298
break;
7399
}
74100
}

‎net/xfrm/xfrm_state.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
612612
{
613613
struct xfrm_state *x;
614614

615-
x = kmem_cache_alloc(xfrm_state_cache, GFP_ATOMIC | __GFP_ZERO);
615+
x = kmem_cache_zalloc(xfrm_state_cache, GFP_ATOMIC);
616616

617617
if (x) {
618618
write_pnet(&x->xs_net, net);

0 commit comments

Comments
 (0)