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>
This commit is contained in:
commit
acc086bfb9
|
@ -11,6 +11,22 @@ static inline struct ip_esp_hdr *ip_esp_hdr(const struct sk_buff *skb)
|
|||
return (struct ip_esp_hdr *)skb_transport_header(skb);
|
||||
}
|
||||
|
||||
static inline void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
|
||||
{
|
||||
/* Fill padding... */
|
||||
if (tfclen) {
|
||||
memset(tail, 0, tfclen);
|
||||
tail += tfclen;
|
||||
}
|
||||
do {
|
||||
int i;
|
||||
for (i = 0; i < plen - 2; i++)
|
||||
tail[i] = i + 1;
|
||||
} while (0);
|
||||
tail[plen - 2] = plen - 2;
|
||||
tail[plen - 1] = proto;
|
||||
}
|
||||
|
||||
struct esp_info {
|
||||
struct ip_esp_hdr *esph;
|
||||
__be64 seqno;
|
||||
|
|
|
@ -341,22 +341,6 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err)
|
|||
esp_output_done(base, err);
|
||||
}
|
||||
|
||||
static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
|
||||
{
|
||||
/* Fill padding... */
|
||||
if (tfclen) {
|
||||
memset(tail, 0, tfclen);
|
||||
tail += tfclen;
|
||||
}
|
||||
do {
|
||||
int i;
|
||||
for (i = 0; i < plen - 2; i++)
|
||||
tail[i] = i + 1;
|
||||
} while (0);
|
||||
tail[plen - 2] = plen - 2;
|
||||
tail[plen - 1] = proto;
|
||||
}
|
||||
|
||||
static struct ip_esp_hdr *esp_output_udp_encap(struct sk_buff *skb,
|
||||
int encap_type,
|
||||
struct esp_info *esp,
|
||||
|
|
|
@ -132,6 +132,36 @@ static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
|
|||
return segs;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_beet_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||
const struct net_offload *ops;
|
||||
int proto = xo->proto;
|
||||
|
||||
skb->transport_header += x->props.header_len;
|
||||
|
||||
if (proto == IPPROTO_BEETPH) {
|
||||
struct ip_beet_phdr *ph = (struct ip_beet_phdr *)skb->data;
|
||||
|
||||
skb->transport_header += ph->hdrlen * 8;
|
||||
proto = ph->nexthdr;
|
||||
} else if (x->sel.family != AF_INET6) {
|
||||
skb->transport_header -= IPV4_BEET_PHMAXLEN;
|
||||
} else if (proto == IPPROTO_TCP) {
|
||||
skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV4;
|
||||
}
|
||||
|
||||
__skb_pull(skb, skb_transport_offset(skb));
|
||||
ops = rcu_dereference(inet_offloads[proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
segs = ops->callbacks.gso_segment(skb, features);
|
||||
|
||||
return segs;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
|
@ -141,6 +171,8 @@ static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
|
|||
return xfrm4_tunnel_gso_segment(x, skb, features);
|
||||
case XFRM_MODE_TRANSPORT:
|
||||
return xfrm4_transport_gso_segment(x, skb, features);
|
||||
case XFRM_MODE_BEET:
|
||||
return xfrm4_beet_gso_segment(x, skb, features);
|
||||
}
|
||||
|
||||
return ERR_PTR(-EOPNOTSUPP);
|
||||
|
|
|
@ -207,22 +207,6 @@ static void esp_output_done_esn(struct crypto_async_request *base, int err)
|
|||
esp_output_done(base, err);
|
||||
}
|
||||
|
||||
static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
|
||||
{
|
||||
/* Fill padding... */
|
||||
if (tfclen) {
|
||||
memset(tail, 0, tfclen);
|
||||
tail += tfclen;
|
||||
}
|
||||
do {
|
||||
int i;
|
||||
for (i = 0; i < plen - 2; i++)
|
||||
tail[i] = i + 1;
|
||||
} while (0);
|
||||
tail[plen - 2] = plen - 2;
|
||||
tail[plen - 1] = proto;
|
||||
}
|
||||
|
||||
int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
|
||||
{
|
||||
u8 *tail;
|
||||
|
|
|
@ -159,6 +159,40 @@ static struct sk_buff *xfrm6_transport_gso_segment(struct xfrm_state *x,
|
|||
return segs;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||
const struct net_offload *ops;
|
||||
int proto = xo->proto;
|
||||
|
||||
skb->transport_header += x->props.header_len;
|
||||
|
||||
if (proto == IPPROTO_BEETPH) {
|
||||
struct ip_beet_phdr *ph = (struct ip_beet_phdr *)skb->data;
|
||||
|
||||
skb->transport_header += ph->hdrlen * 8;
|
||||
proto = ph->nexthdr;
|
||||
}
|
||||
|
||||
if (x->sel.family != AF_INET6) {
|
||||
skb->transport_header -=
|
||||
(sizeof(struct ipv6hdr) - sizeof(struct iphdr));
|
||||
|
||||
if (proto == IPPROTO_TCP)
|
||||
skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
|
||||
}
|
||||
|
||||
__skb_pull(skb, skb_transport_offset(skb));
|
||||
ops = rcu_dereference(inet6_offloads[proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
segs = ops->callbacks.gso_segment(skb, features);
|
||||
|
||||
return segs;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
|
@ -168,6 +202,8 @@ static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
|
|||
return xfrm6_tunnel_gso_segment(x, skb, features);
|
||||
case XFRM_MODE_TRANSPORT:
|
||||
return xfrm6_transport_gso_segment(x, skb, features);
|
||||
case XFRM_MODE_BEET:
|
||||
return xfrm6_beet_gso_segment(x, skb, features);
|
||||
}
|
||||
|
||||
return ERR_PTR(-EOPNOTSUPP);
|
||||
|
|
|
@ -46,6 +46,25 @@ static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
|
|||
pskb_pull(skb, skb->mac_len + x->props.header_len);
|
||||
}
|
||||
|
||||
static void __xfrm_mode_beet_prep(struct xfrm_state *x, struct sk_buff *skb,
|
||||
unsigned int hsize)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
int phlen = 0;
|
||||
|
||||
if (xo->flags & XFRM_GSO_SEGMENT)
|
||||
skb->transport_header = skb->network_header + hsize;
|
||||
|
||||
skb_reset_mac_len(skb);
|
||||
if (x->sel.family != AF_INET6) {
|
||||
phlen = IPV4_BEET_PHMAXLEN;
|
||||
if (x->outer_mode.family == AF_INET6)
|
||||
phlen += sizeof(struct ipv6hdr) - sizeof(struct iphdr);
|
||||
}
|
||||
|
||||
pskb_pull(skb, skb->mac_len + hsize + (x->props.header_len - phlen));
|
||||
}
|
||||
|
||||
/* Adjust pointers into the packet when IPsec is done at layer2 */
|
||||
static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
|
@ -66,9 +85,16 @@ static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
|
|||
return __xfrm_transport_prep(x, skb,
|
||||
sizeof(struct ipv6hdr));
|
||||
break;
|
||||
case XFRM_MODE_BEET:
|
||||
if (x->outer_mode.family == AF_INET)
|
||||
return __xfrm_mode_beet_prep(x, skb,
|
||||
sizeof(struct iphdr));
|
||||
if (x->outer_mode.family == AF_INET6)
|
||||
return __xfrm_mode_beet_prep(x, skb,
|
||||
sizeof(struct ipv6hdr));
|
||||
break;
|
||||
case XFRM_MODE_ROUTEOPTIMIZATION:
|
||||
case XFRM_MODE_IN_TRIGGER:
|
||||
case XFRM_MODE_BEET:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -612,7 +612,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
|
|||
{
|
||||
struct xfrm_state *x;
|
||||
|
||||
x = kmem_cache_alloc(xfrm_state_cache, GFP_ATOMIC | __GFP_ZERO);
|
||||
x = kmem_cache_zalloc(xfrm_state_cache, GFP_ATOMIC);
|
||||
|
||||
if (x) {
|
||||
write_pnet(&x->xs_net, net);
|
||||
|
|
Loading…
Reference in New Issue