Commit 3c2d19cb authored by David S. Miller's avatar David S. Miller

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-07-30

Please note that I did the first time now --no-ff merges
of my testing branch into the master branch to include
the [PATCH 0/n] message of a patchset. Please let me
know if this is desirable, or if I should do it any
different.

1) Introduce a oseq-may-wrap flag to disable anti-replay
   protection for manually distributed ICVs as suggested
   in RFC 4303. From Petr Vaněk.

2) Patchset to fully support IPCOMP for vti4, vti6 and
   xfrm interfaces. From Xin Long.

3) Switch from a linear list to a hash list for xfrm interface
   lookups. From Eyal Birger.

4) Fixes to not register one xfrm(6)_tunnel object twice.
   From Xin Long.

5) Fix two compile errors that were introduced with the
   IPCOMP support for vti and xfrm interfaces.
   Also from Xin Long.

6) Make the policy hold queue work with VTI. This was
   forgotten when VTI was implemented.

Please pull or let me know if there are problems.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 41d707b7 b328ecc4
...@@ -374,7 +374,8 @@ struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family); ...@@ -374,7 +374,8 @@ struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family);
struct xfrm_state_afinfo *xfrm_state_afinfo_get_rcu(unsigned int family); struct xfrm_state_afinfo *xfrm_state_afinfo_get_rcu(unsigned int family);
struct xfrm_input_afinfo { struct xfrm_input_afinfo {
unsigned int family; u8 family;
bool is_ipip;
int (*callback)(struct sk_buff *skb, u8 protocol, int (*callback)(struct sk_buff *skb, u8 protocol,
int err); int err);
}; };
...@@ -1417,6 +1418,7 @@ struct xfrm6_protocol { ...@@ -1417,6 +1418,7 @@ struct xfrm6_protocol {
/* XFRM tunnel handlers. */ /* XFRM tunnel handlers. */
struct xfrm_tunnel { struct xfrm_tunnel {
int (*handler)(struct sk_buff *skb); int (*handler)(struct sk_buff *skb);
int (*cb_handler)(struct sk_buff *skb, int err);
int (*err_handler)(struct sk_buff *skb, u32 info); int (*err_handler)(struct sk_buff *skb, u32 info);
struct xfrm_tunnel __rcu *next; struct xfrm_tunnel __rcu *next;
...@@ -1425,6 +1427,7 @@ struct xfrm_tunnel { ...@@ -1425,6 +1427,7 @@ struct xfrm_tunnel {
struct xfrm6_tunnel { struct xfrm6_tunnel {
int (*handler)(struct sk_buff *skb); int (*handler)(struct sk_buff *skb);
int (*cb_handler)(struct sk_buff *skb, int err);
int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt, int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
u8 type, u8 code, int offset, __be32 info); u8 type, u8 code, int offset, __be32 info);
struct xfrm6_tunnel __rcu *next; struct xfrm6_tunnel __rcu *next;
......
...@@ -387,6 +387,7 @@ struct xfrm_usersa_info { ...@@ -387,6 +387,7 @@ struct xfrm_usersa_info {
}; };
#define XFRM_SA_XFLAG_DONT_ENCAP_DSCP 1 #define XFRM_SA_XFLAG_DONT_ENCAP_DSCP 1
#define XFRM_SA_XFLAG_OSEQ_MAY_WRAP 2
struct xfrm_usersa_id { struct xfrm_usersa_id {
xfrm_address_t daddr; xfrm_address_t daddr;
......
...@@ -91,32 +91,6 @@ static int vti_rcv_proto(struct sk_buff *skb) ...@@ -91,32 +91,6 @@ static int vti_rcv_proto(struct sk_buff *skb)
return vti_rcv(skb, 0, false); return vti_rcv(skb, 0, false);
} }
static int vti_rcv_tunnel(struct sk_buff *skb)
{
struct ip_tunnel_net *itn = net_generic(dev_net(skb->dev), vti_net_id);
const struct iphdr *iph = ip_hdr(skb);
struct ip_tunnel *tunnel;
tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
iph->saddr, iph->daddr, 0);
if (tunnel) {
struct tnl_ptk_info tpi = {
.proto = htons(ETH_P_IP),
};
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
goto drop;
if (iptunnel_pull_header(skb, 0, tpi.proto, false))
goto drop;
return ip_tunnel_rcv(tunnel, skb, &tpi, NULL, false);
}
return -EINVAL;
drop:
kfree_skb(skb);
return 0;
}
static int vti_rcv_cb(struct sk_buff *skb, int err) static int vti_rcv_cb(struct sk_buff *skb, int err)
{ {
unsigned short family; unsigned short family;
...@@ -244,12 +218,15 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -244,12 +218,15 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
} }
dst_hold(dst); dst_hold(dst);
dst = xfrm_lookup(tunnel->net, dst, fl, NULL, 0); dst = xfrm_lookup_route(tunnel->net, dst, fl, NULL, 0);
if (IS_ERR(dst)) { if (IS_ERR(dst)) {
dev->stats.tx_carrier_errors++; dev->stats.tx_carrier_errors++;
goto tx_error_icmp; goto tx_error_icmp;
} }
if (dst->flags & DST_XFRM_QUEUE)
goto queued;
if (!vti_state_check(dst->xfrm, parms->iph.daddr, parms->iph.saddr)) { if (!vti_state_check(dst->xfrm, parms->iph.daddr, parms->iph.saddr)) {
dev->stats.tx_carrier_errors++; dev->stats.tx_carrier_errors++;
dst_release(dst); dst_release(dst);
...@@ -281,6 +258,7 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -281,6 +258,7 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
goto tx_error; goto tx_error;
} }
queued:
skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(dev))); skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(dev)));
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
skb->dev = skb_dst(skb)->dev; skb->dev = skb_dst(skb)->dev;
...@@ -496,11 +474,29 @@ static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = { ...@@ -496,11 +474,29 @@ static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
.priority = 100, .priority = 100,
}; };
static struct xfrm_tunnel ipip_handler __read_mostly = { #if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
static int vti_rcv_tunnel(struct sk_buff *skb)
{
XFRM_SPI_SKB_CB(skb)->family = AF_INET;
XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
return vti_input(skb, IPPROTO_IPIP, ip_hdr(skb)->saddr, 0, false);
}
static struct xfrm_tunnel vti_ipip_handler __read_mostly = {
.handler = vti_rcv_tunnel,
.cb_handler = vti_rcv_cb,
.err_handler = vti4_err,
.priority = 0,
};
static struct xfrm_tunnel vti_ipip6_handler __read_mostly = {
.handler = vti_rcv_tunnel, .handler = vti_rcv_tunnel,
.cb_handler = vti_rcv_cb,
.err_handler = vti4_err, .err_handler = vti4_err,
.priority = 0, .priority = 0,
}; };
#endif
static int __net_init vti_init_net(struct net *net) static int __net_init vti_init_net(struct net *net)
{ {
...@@ -670,10 +666,17 @@ static int __init vti_init(void) ...@@ -670,10 +666,17 @@ static int __init vti_init(void)
if (err < 0) if (err < 0)
goto xfrm_proto_comp_failed; goto xfrm_proto_comp_failed;
#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
msg = "ipip tunnel"; msg = "ipip tunnel";
err = xfrm4_tunnel_register(&ipip_handler, AF_INET); err = xfrm4_tunnel_register(&vti_ipip_handler, AF_INET);
if (err < 0)
goto xfrm_tunnel_ipip_failed;
#if IS_ENABLED(CONFIG_IPV6)
err = xfrm4_tunnel_register(&vti_ipip6_handler, AF_INET6);
if (err < 0) if (err < 0)
goto xfrm_tunnel_failed; goto xfrm_tunnel_ipip6_failed;
#endif
#endif
msg = "netlink interface"; msg = "netlink interface";
err = rtnl_link_register(&vti_link_ops); err = rtnl_link_register(&vti_link_ops);
...@@ -683,8 +686,14 @@ static int __init vti_init(void) ...@@ -683,8 +686,14 @@ static int __init vti_init(void)
return err; return err;
rtnl_link_failed: rtnl_link_failed:
xfrm4_tunnel_deregister(&ipip_handler, AF_INET); #if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
xfrm_tunnel_failed: #if IS_ENABLED(CONFIG_IPV6)
xfrm4_tunnel_deregister(&vti_ipip6_handler, AF_INET6);
xfrm_tunnel_ipip6_failed:
#endif
xfrm4_tunnel_deregister(&vti_ipip_handler, AF_INET);
xfrm_tunnel_ipip_failed:
#endif
xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP); xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
xfrm_proto_comp_failed: xfrm_proto_comp_failed:
xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH); xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
...@@ -700,7 +709,12 @@ static int __init vti_init(void) ...@@ -700,7 +709,12 @@ static int __init vti_init(void)
static void __exit vti_fini(void) static void __exit vti_fini(void)
{ {
rtnl_link_unregister(&vti_link_ops); rtnl_link_unregister(&vti_link_ops);
xfrm4_tunnel_deregister(&ipip_handler, AF_INET); #if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
#if IS_ENABLED(CONFIG_IPV6)
xfrm4_tunnel_deregister(&vti_ipip6_handler, AF_INET6);
#endif
xfrm4_tunnel_deregister(&vti_ipip_handler, AF_INET);
#endif
xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP); xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH); xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP); xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP);
......
...@@ -72,6 +72,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) ...@@ -72,6 +72,7 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
t->props.flags = x->props.flags; t->props.flags = x->props.flags;
t->props.extra_flags = x->props.extra_flags; t->props.extra_flags = x->props.extra_flags;
memcpy(&t->mark, &x->mark, sizeof(t->mark)); memcpy(&t->mark, &x->mark, sizeof(t->mark));
t->if_id = x->if_id;
if (xfrm_init_state(t)) if (xfrm_init_state(t))
goto error; goto error;
......
...@@ -110,6 +110,33 @@ static int tunnel4_rcv(struct sk_buff *skb) ...@@ -110,6 +110,33 @@ static int tunnel4_rcv(struct sk_buff *skb)
return 0; return 0;
} }
#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
static int tunnel4_rcv_cb(struct sk_buff *skb, u8 proto, int err)
{
struct xfrm_tunnel __rcu *head;
struct xfrm_tunnel *handler;
int ret;
head = (proto == IPPROTO_IPIP) ? tunnel4_handlers : tunnel64_handlers;
for_each_tunnel_rcu(head, handler) {
if (handler->cb_handler) {
ret = handler->cb_handler(skb, err);
if (ret <= 0)
return ret;
}
}
return 0;
}
static const struct xfrm_input_afinfo tunnel4_input_afinfo = {
.family = AF_INET,
.is_ipip = true,
.callback = tunnel4_rcv_cb,
};
#endif
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
static int tunnel64_rcv(struct sk_buff *skb) static int tunnel64_rcv(struct sk_buff *skb)
{ {
...@@ -230,6 +257,18 @@ static int __init tunnel4_init(void) ...@@ -230,6 +257,18 @@ static int __init tunnel4_init(void)
#endif #endif
goto err; goto err;
} }
#endif
#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
if (xfrm_input_register_afinfo(&tunnel4_input_afinfo)) {
inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
#if IS_ENABLED(CONFIG_IPV6)
inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6);
#endif
#if IS_ENABLED(CONFIG_MPLS)
inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS);
#endif
goto err;
}
#endif #endif
return 0; return 0;
...@@ -240,6 +279,10 @@ static int __init tunnel4_init(void) ...@@ -240,6 +279,10 @@ static int __init tunnel4_init(void)
static void __exit tunnel4_fini(void) static void __exit tunnel4_fini(void)
{ {
#if IS_ENABLED(CONFIG_INET_XFRM_TUNNEL)
if (xfrm_input_unregister_afinfo(&tunnel4_input_afinfo))
pr_err("tunnel4 close: can't remove input afinfo\n");
#endif
#if IS_ENABLED(CONFIG_MPLS) #if IS_ENABLED(CONFIG_MPLS)
if (inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS)) if (inet_del_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS))
pr_err("tunnelmpls4 close: can't remove protocol\n"); pr_err("tunnelmpls4 close: can't remove protocol\n");
......
...@@ -491,13 +491,16 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) ...@@ -491,13 +491,16 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
} }
dst_hold(dst); dst_hold(dst);
dst = xfrm_lookup(t->net, dst, fl, NULL, 0); dst = xfrm_lookup_route(t->net, dst, fl, NULL, 0);
if (IS_ERR(dst)) { if (IS_ERR(dst)) {
err = PTR_ERR(dst); err = PTR_ERR(dst);
dst = NULL; dst = NULL;
goto tx_err_link_failure; goto tx_err_link_failure;
} }
if (dst->flags & DST_XFRM_QUEUE)
goto queued;
x = dst->xfrm; x = dst->xfrm;
if (!vti6_state_check(x, &t->parms.raddr, &t->parms.laddr)) if (!vti6_state_check(x, &t->parms.raddr, &t->parms.laddr))
goto tx_err_link_failure; goto tx_err_link_failure;
...@@ -533,6 +536,7 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) ...@@ -533,6 +536,7 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
goto tx_err_dst_release; goto tx_err_dst_release;
} }
queued:
skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev))); skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev)));
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
skb->dev = skb_dst(skb)->dev; skb->dev = skb_dst(skb)->dev;
...@@ -1219,6 +1223,33 @@ static struct xfrm6_protocol vti_ipcomp6_protocol __read_mostly = { ...@@ -1219,6 +1223,33 @@ static struct xfrm6_protocol vti_ipcomp6_protocol __read_mostly = {
.priority = 100, .priority = 100,
}; };
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
static int vti6_rcv_tunnel(struct sk_buff *skb)
{
const xfrm_address_t *saddr;
__be32 spi;
saddr = (const xfrm_address_t *)&ipv6_hdr(skb)->saddr;
spi = xfrm6_tunnel_spi_lookup(dev_net(skb->dev), saddr);
return vti6_input_proto(skb, IPPROTO_IPV6, spi, 0);
}
static struct xfrm6_tunnel vti_ipv6_handler __read_mostly = {
.handler = vti6_rcv_tunnel,
.cb_handler = vti6_rcv_cb,
.err_handler = vti6_err,
.priority = 0,
};
static struct xfrm6_tunnel vti_ip6ip_handler __read_mostly = {
.handler = vti6_rcv_tunnel,
.cb_handler = vti6_rcv_cb,
.err_handler = vti6_err,
.priority = 0,
};
#endif
/** /**
* vti6_tunnel_init - register protocol and reserve needed resources * vti6_tunnel_init - register protocol and reserve needed resources
* *
...@@ -1244,6 +1275,15 @@ static int __init vti6_tunnel_init(void) ...@@ -1244,6 +1275,15 @@ static int __init vti6_tunnel_init(void)
err = xfrm6_protocol_register(&vti_ipcomp6_protocol, IPPROTO_COMP); err = xfrm6_protocol_register(&vti_ipcomp6_protocol, IPPROTO_COMP);
if (err < 0) if (err < 0)
goto xfrm_proto_comp_failed; goto xfrm_proto_comp_failed;
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
msg = "ipv6 tunnel";
err = xfrm6_tunnel_register(&vti_ipv6_handler, AF_INET6);
if (err < 0)
goto vti_tunnel_ipv6_failed;
err = xfrm6_tunnel_register(&vti_ip6ip_handler, AF_INET);
if (err < 0)
goto vti_tunnel_ip6ip_failed;
#endif
msg = "netlink interface"; msg = "netlink interface";
err = rtnl_link_register(&vti6_link_ops); err = rtnl_link_register(&vti6_link_ops);
...@@ -1253,6 +1293,12 @@ static int __init vti6_tunnel_init(void) ...@@ -1253,6 +1293,12 @@ static int __init vti6_tunnel_init(void)
return 0; return 0;
rtnl_link_failed: rtnl_link_failed:
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
err = xfrm6_tunnel_deregister(&vti_ip6ip_handler, AF_INET);
vti_tunnel_ip6ip_failed:
err = xfrm6_tunnel_deregister(&vti_ipv6_handler, AF_INET6);
vti_tunnel_ipv6_failed:
#endif
xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP); xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP);
xfrm_proto_comp_failed: xfrm_proto_comp_failed:
xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH); xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH);
...@@ -1271,6 +1317,10 @@ static int __init vti6_tunnel_init(void) ...@@ -1271,6 +1317,10 @@ static int __init vti6_tunnel_init(void)
static void __exit vti6_tunnel_cleanup(void) static void __exit vti6_tunnel_cleanup(void)
{ {
rtnl_link_unregister(&vti6_link_ops); rtnl_link_unregister(&vti6_link_ops);
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
xfrm6_tunnel_deregister(&vti_ip6ip_handler, AF_INET);
xfrm6_tunnel_deregister(&vti_ipv6_handler, AF_INET6);
#endif
xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP); xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP);
xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH); xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH);
xfrm6_protocol_deregister(&vti_esp6_protocol, IPPROTO_ESP); xfrm6_protocol_deregister(&vti_esp6_protocol, IPPROTO_ESP);
......
...@@ -91,6 +91,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) ...@@ -91,6 +91,7 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
t->props.mode = x->props.mode; t->props.mode = x->props.mode;
memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr)); memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr));
memcpy(&t->mark, &x->mark, sizeof(t->mark)); memcpy(&t->mark, &x->mark, sizeof(t->mark));
t->if_id = x->if_id;
if (xfrm_init_state(t)) if (xfrm_init_state(t))
goto error; goto error;
......
...@@ -155,6 +155,33 @@ static int tunnel6_rcv(struct sk_buff *skb) ...@@ -155,6 +155,33 @@ static int tunnel6_rcv(struct sk_buff *skb)
return 0; return 0;
} }
#if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)
static int tunnel6_rcv_cb(struct sk_buff *skb, u8 proto, int err)
{
struct xfrm6_tunnel __rcu *head;
struct xfrm6_tunnel *handler;
int ret;
head = (proto == IPPROTO_IPV6) ? tunnel6_handlers : tunnel46_handlers;
for_each_tunnel_rcu(head, handler) {
if (handler->cb_handler) {
ret = handler->cb_handler(skb, err);
if (ret <= 0)
return ret;
}
}
return 0;
}
static const struct xfrm_input_afinfo tunnel6_input_afinfo = {
.family = AF_INET6,
.is_ipip = true,
.callback = tunnel6_rcv_cb,
};
#endif
static int tunnel46_rcv(struct sk_buff *skb) static int tunnel46_rcv(struct sk_buff *skb)
{ {
struct xfrm6_tunnel *handler; struct xfrm6_tunnel *handler;
...@@ -245,11 +272,25 @@ static int __init tunnel6_init(void) ...@@ -245,11 +272,25 @@ static int __init tunnel6_init(void)
inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP); inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP);
return -EAGAIN; return -EAGAIN;
} }
#if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)
if (xfrm_input_register_afinfo(&tunnel6_input_afinfo)) {
pr_err("%s: can't add input afinfo\n", __func__);
inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6);
inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP);
if (xfrm6_tunnel_mpls_supported())
inet6_del_protocol(&tunnelmpls6_protocol, IPPROTO_MPLS);
return -EAGAIN;
}
#endif
return 0; return 0;
} }
static void __exit tunnel6_fini(void) static void __exit tunnel6_fini(void)
{ {
#if IS_ENABLED(CONFIG_INET6_XFRM_TUNNEL)
if (xfrm_input_unregister_afinfo(&tunnel6_input_afinfo))
pr_err("%s: can't remove input afinfo\n", __func__);
#endif
if (inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP)) if (inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP))
pr_err("%s: can't remove protocol\n", __func__); pr_err("%s: can't remove protocol\n", __func__);
if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6)) if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))
......
...@@ -42,7 +42,7 @@ struct xfrm_trans_cb { ...@@ -42,7 +42,7 @@ struct xfrm_trans_cb {
#define XFRM_TRANS_SKB_CB(__skb) ((struct xfrm_trans_cb *)&((__skb)->cb[0])) #define XFRM_TRANS_SKB_CB(__skb) ((struct xfrm_trans_cb *)&((__skb)->cb[0]))
static DEFINE_SPINLOCK(xfrm_input_afinfo_lock); static DEFINE_SPINLOCK(xfrm_input_afinfo_lock);
static struct xfrm_input_afinfo const __rcu *xfrm_input_afinfo[AF_INET6 + 1]; static struct xfrm_input_afinfo const __rcu *xfrm_input_afinfo[2][AF_INET6 + 1];
static struct gro_cells gro_cells; static struct gro_cells gro_cells;
static struct net_device xfrm_napi_dev; static struct net_device xfrm_napi_dev;
...@@ -53,14 +53,14 @@ int xfrm_input_register_afinfo(const struct xfrm_input_afinfo *afinfo) ...@@ -53,14 +53,14 @@ int xfrm_input_register_afinfo(const struct xfrm_input_afinfo *afinfo)
{ {
int err = 0; int err = 0;
if (WARN_ON(afinfo->family >= ARRAY_SIZE(xfrm_input_afinfo))) if (WARN_ON(afinfo->family > AF_INET6))
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
spin_lock_bh(&xfrm_input_afinfo_lock); spin_lock_bh(&xfrm_input_afinfo_lock);
if (unlikely(xfrm_input_afinfo[afinfo->family] != NULL)) if (unlikely(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family]))
err = -EEXIST; err = -EEXIST;
else else
rcu_assign_pointer(xfrm_input_afinfo[afinfo->family], afinfo); rcu_assign_pointer(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family], afinfo);
spin_unlock_bh(&xfrm_input_afinfo_lock); spin_unlock_bh(&xfrm_input_afinfo_lock);
return err; return err;
} }
...@@ -71,11 +71,11 @@ int xfrm_input_unregister_afinfo(const struct xfrm_input_afinfo *afinfo) ...@@ -71,11 +71,11 @@ int xfrm_input_unregister_afinfo(const struct xfrm_input_afinfo *afinfo)
int err = 0; int err = 0;
spin_lock_bh(&xfrm_input_afinfo_lock); spin_lock_bh(&xfrm_input_afinfo_lock);
if (likely(xfrm_input_afinfo[afinfo->family] != NULL)) { if (likely(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family])) {
if (unlikely(xfrm_input_afinfo[afinfo->family] != afinfo)) if (unlikely(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family] != afinfo))
err = -EINVAL; err = -EINVAL;
else else
RCU_INIT_POINTER(xfrm_input_afinfo[afinfo->family], NULL); RCU_INIT_POINTER(xfrm_input_afinfo[afinfo->is_ipip][afinfo->family], NULL);
} }
spin_unlock_bh(&xfrm_input_afinfo_lock); spin_unlock_bh(&xfrm_input_afinfo_lock);
synchronize_rcu(); synchronize_rcu();
...@@ -83,15 +83,15 @@ int xfrm_input_unregister_afinfo(const struct xfrm_input_afinfo *afinfo) ...@@ -83,15 +83,15 @@ int xfrm_input_unregister_afinfo(const struct xfrm_input_afinfo *afinfo)
} }
EXPORT_SYMBOL(xfrm_input_unregister_afinfo); EXPORT_SYMBOL(xfrm_input_unregister_afinfo);
static const struct xfrm_input_afinfo *xfrm_input_get_afinfo(unsigned int family) static const struct xfrm_input_afinfo *xfrm_input_get_afinfo(u8 family, bool is_ipip)
{ {
const struct xfrm_input_afinfo *afinfo; const struct xfrm_input_afinfo *afinfo;
if (WARN_ON_ONCE(family >= ARRAY_SIZE(xfrm_input_afinfo))) if (WARN_ON_ONCE(family > AF_INET6))
return NULL; return NULL;
rcu_read_lock(); rcu_read_lock();
afinfo = rcu_dereference(xfrm_input_afinfo[family]); afinfo = rcu_dereference(xfrm_input_afinfo[is_ipip][family]);
if (unlikely(!afinfo)) if (unlikely(!afinfo))
rcu_read_unlock(); rcu_read_unlock();
return afinfo; return afinfo;
...@@ -100,9 +100,11 @@ static const struct xfrm_input_afinfo *xfrm_input_get_afinfo(unsigned int family ...@@ -100,9 +100,11 @@ static const struct xfrm_input_afinfo *xfrm_input_get_afinfo(unsigned int family
static int xfrm_rcv_cb(struct sk_buff *skb, unsigned int family, u8 protocol, static int xfrm_rcv_cb(struct sk_buff *skb, unsigned int family, u8 protocol,
int err) int err)
{ {
bool is_ipip = (protocol == IPPROTO_IPIP || protocol == IPPROTO_IPV6);
const struct xfrm_input_afinfo *afinfo;
int ret; int ret;
const struct xfrm_input_afinfo *afinfo = xfrm_input_get_afinfo(family);
afinfo = xfrm_input_get_afinfo(family, is_ipip);
if (!afinfo) if (!afinfo)
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
......
...@@ -48,21 +48,30 @@ static int xfrmi_dev_init(struct net_device *dev); ...@@ -48,21 +48,30 @@ static int xfrmi_dev_init(struct net_device *dev);
static void xfrmi_dev_setup(struct net_device *dev); static void xfrmi_dev_setup(struct net_device *dev);
static struct rtnl_link_ops xfrmi_link_ops __read_mostly; static struct rtnl_link_ops xfrmi_link_ops __read_mostly;
static unsigned int xfrmi_net_id __read_mostly; static unsigned int xfrmi_net_id __read_mostly;
static const struct net_device_ops xfrmi_netdev_ops;
#define XFRMI_HASH_BITS 8
#define XFRMI_HASH_SIZE BIT(XFRMI_HASH_BITS)
struct xfrmi_net { struct xfrmi_net {
/* lists for storing interfaces in use */ /* lists for storing interfaces in use */
struct xfrm_if __rcu *xfrmi[1]; struct xfrm_if __rcu *xfrmi[XFRMI_HASH_SIZE];
}; };
#define for_each_xfrmi_rcu(start, xi) \ #define for_each_xfrmi_rcu(start, xi) \
for (xi = rcu_dereference(start); xi; xi = rcu_dereference(xi->next)) for (xi = rcu_dereference(start); xi; xi = rcu_dereference(xi->next))
static u32 xfrmi_hash(u32 if_id)
{
return hash_32(if_id, XFRMI_HASH_BITS);
}
static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x) static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x)
{ {
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
struct xfrm_if *xi; struct xfrm_if *xi;
for_each_xfrmi_rcu(xfrmn->xfrmi[0], xi) { for_each_xfrmi_rcu(xfrmn->xfrmi[xfrmi_hash(x->if_id)], xi) {
if (x->if_id == xi->p.if_id && if (x->if_id == xi->p.if_id &&
(xi->dev->flags & IFF_UP)) (xi->dev->flags & IFF_UP))
return xi; return xi;
...@@ -74,8 +83,7 @@ static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x) ...@@ -74,8 +83,7 @@ static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x)
static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb, static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb,
unsigned short family) unsigned short family)
{ {
struct xfrmi_net *xfrmn; struct net_device *dev;
struct xfrm_if *xi;
int ifindex = 0; int ifindex = 0;
if (!secpath_exists(skb) || !skb->dev) if (!secpath_exists(skb) || !skb->dev)
...@@ -89,23 +97,26 @@ static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb, ...@@ -89,23 +97,26 @@ static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb,
ifindex = inet_sdif(skb); ifindex = inet_sdif(skb);
break; break;
} }
if (!ifindex)
ifindex = skb->dev->ifindex;
xfrmn = net_generic(xs_net(xfrm_input_state(skb)), xfrmi_net_id); if (ifindex) {
struct net *net = xs_net(xfrm_input_state(skb));
for_each_xfrmi_rcu(xfrmn->xfrmi[0], xi) { dev = dev_get_by_index_rcu(net, ifindex);
if (ifindex == xi->dev->ifindex && } else {
(xi->dev->flags & IFF_UP)) dev = skb->dev;
return xi;
} }
if (!dev || !(dev->flags & IFF_UP))
return NULL; return NULL;
if (dev->netdev_ops != &xfrmi_netdev_ops)
return NULL;
return netdev_priv(dev);
} }
static void xfrmi_link(struct xfrmi_net *xfrmn, struct xfrm_if *xi) static void xfrmi_link(struct xfrmi_net *xfrmn, struct xfrm_if *xi)
{ {
struct xfrm_if __rcu **xip = &xfrmn->xfrmi[0]; struct xfrm_if __rcu **xip = &xfrmn->xfrmi[xfrmi_hash(xi->p.if_id)];
rcu_assign_pointer(xi->next , rtnl_dereference(*xip)); rcu_assign_pointer(xi->next , rtnl_dereference(*xip));
rcu_assign_pointer(*xip, xi); rcu_assign_pointer(*xip, xi);
...@@ -116,7 +127,7 @@ static void xfrmi_unlink(struct xfrmi_net *xfrmn, struct xfrm_if *xi) ...@@ -116,7 +127,7 @@ static void xfrmi_unlink(struct xfrmi_net *xfrmn, struct xfrm_if *xi)
struct xfrm_if __rcu **xip; struct xfrm_if __rcu **xip;
struct xfrm_if *iter; struct xfrm_if *iter;
for (xip = &xfrmn->xfrmi[0]; for (xip = &xfrmn->xfrmi[xfrmi_hash(xi->p.if_id)];
(iter = rtnl_dereference(*xip)) != NULL; (iter = rtnl_dereference(*xip)) != NULL;
xip = &iter->next) { xip = &iter->next) {
if (xi == iter) { if (xi == iter) {
...@@ -160,7 +171,7 @@ static struct xfrm_if *xfrmi_locate(struct net *net, struct xfrm_if_parms *p) ...@@ -160,7 +171,7 @@ static struct xfrm_if *xfrmi_locate(struct net *net, struct xfrm_if_parms *p)
struct xfrm_if *xi; struct xfrm_if *xi;
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
for (xip = &xfrmn->xfrmi[0]; for (xip = &xfrmn->xfrmi[xfrmi_hash(p->if_id)];
(xi = rtnl_dereference(*xip)) != NULL; (xi = rtnl_dereference(*xip)) != NULL;
xip = &xi->next) xip = &xi->next)
if (xi->p.if_id == p->if_id) if (xi->p.if_id == p->if_id)
...@@ -760,12 +771,15 @@ static void __net_exit xfrmi_exit_batch_net(struct list_head *net_exit_list) ...@@ -760,12 +771,15 @@ static void __net_exit xfrmi_exit_batch_net(struct list_head *net_exit_list)
struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id); struct xfrmi_net *xfrmn = net_generic(net, xfrmi_net_id);
struct xfrm_if __rcu **xip; struct xfrm_if __rcu **xip;
struct xfrm_if *xi; struct xfrm_if *xi;
int i;
for (xip = &xfrmn->xfrmi[0]; for (i = 0; i < XFRMI_HASH_SIZE; i++) {
for (xip = &xfrmn->xfrmi[i];
(xi = rtnl_dereference(*xip)) != NULL; (xi = rtnl_dereference(*xip)) != NULL;
xip = &xi->next) xip = &xi->next)
unregister_netdevice_queue(xi->dev, &list); unregister_netdevice_queue(xi->dev, &list);
} }
}
unregister_netdevice_many(&list); unregister_netdevice_many(&list);
rtnl_unlock(); rtnl_unlock();
} }
...@@ -800,6 +814,33 @@ static struct xfrm6_protocol xfrmi_ipcomp6_protocol __read_mostly = { ...@@ -800,6 +814,33 @@ static struct xfrm6_protocol xfrmi_ipcomp6_protocol __read_mostly = {
.priority = 10, .priority = 10,
}; };
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
static int xfrmi6_rcv_tunnel(struct sk_buff *skb)
{
const xfrm_address_t *saddr;
__be32 spi;
saddr = (const xfrm_address_t *)&ipv6_hdr(skb)->saddr;
spi = xfrm6_tunnel_spi_lookup(dev_net(skb->dev), saddr);
return xfrm6_rcv_spi(skb, IPPROTO_IPV6, spi, NULL);
}
static struct xfrm6_tunnel xfrmi_ipv6_handler __read_mostly = {
.handler = xfrmi6_rcv_tunnel,
.cb_handler = xfrmi_rcv_cb,
.err_handler = xfrmi6_err,
.priority = -1,
};
static struct xfrm6_tunnel xfrmi_ip6ip_handler __read_mostly = {
.handler = xfrmi6_rcv_tunnel,
.cb_handler = xfrmi_rcv_cb,
.err_handler = xfrmi6_err,
.priority = -1,
};
#endif
static struct xfrm4_protocol xfrmi_esp4_protocol __read_mostly = { static struct xfrm4_protocol xfrmi_esp4_protocol __read_mostly = {
.handler = xfrm4_rcv, .handler = xfrm4_rcv,
.input_handler = xfrm_input, .input_handler = xfrm_input,
...@@ -824,6 +865,27 @@ static struct xfrm4_protocol xfrmi_ipcomp4_protocol __read_mostly = { ...@@ -824,6 +865,27 @@ static struct xfrm4_protocol xfrmi_ipcomp4_protocol __read_mostly = {
.priority = 10, .priority = 10,
}; };
#if IS_REACHABLE(CONFIG_INET_XFRM_TUNNEL)
static int xfrmi4_rcv_tunnel(struct sk_buff *skb)
{
return xfrm4_rcv_spi(skb, IPPROTO_IPIP, ip_hdr(skb)->saddr);
}
static struct xfrm_tunnel xfrmi_ipip_handler __read_mostly = {
.handler = xfrmi4_rcv_tunnel,
.cb_handler = xfrmi_rcv_cb,
.err_handler = xfrmi4_err,
.priority = -1,
};
static struct xfrm_tunnel xfrmi_ipip6_handler __read_mostly = {
.handler = xfrmi4_rcv_tunnel,
.cb_handler = xfrmi_rcv_cb,
.err_handler = xfrmi4_err,
.priority = -1,
};
#endif
static int __init xfrmi4_init(void) static int __init xfrmi4_init(void)
{ {
int err; int err;
...@@ -837,9 +899,23 @@ static int __init xfrmi4_init(void) ...@@ -837,9 +899,23 @@ static int __init xfrmi4_init(void)
err = xfrm4_protocol_register(&xfrmi_ipcomp4_protocol, IPPROTO_COMP); err = xfrm4_protocol_register(&xfrmi_ipcomp4_protocol, IPPROTO_COMP);
if (err < 0) if (err < 0)
goto xfrm_proto_comp_failed; goto xfrm_proto_comp_failed;
#if IS_REACHABLE(CONFIG_INET_XFRM_TUNNEL)
err = xfrm4_tunnel_register(&xfrmi_ipip_handler, AF_INET);
if (err < 0)
goto xfrm_tunnel_ipip_failed;
err = xfrm4_tunnel_register(&xfrmi_ipip6_handler, AF_INET6);
if (err < 0)
goto xfrm_tunnel_ipip6_failed;
#endif
return 0; return 0;
#if IS_REACHABLE(CONFIG_INET_XFRM_TUNNEL)
xfrm_tunnel_ipip6_failed:
xfrm4_tunnel_deregister(&xfrmi_ipip_handler, AF_INET);
xfrm_tunnel_ipip_failed:
xfrm4_protocol_deregister(&xfrmi_ipcomp4_protocol, IPPROTO_COMP);
#endif
xfrm_proto_comp_failed: xfrm_proto_comp_failed:
xfrm4_protocol_deregister(&xfrmi_ah4_protocol, IPPROTO_AH); xfrm4_protocol_deregister(&xfrmi_ah4_protocol, IPPROTO_AH);
xfrm_proto_ah_failed: xfrm_proto_ah_failed:
...@@ -850,6 +926,10 @@ static int __init xfrmi4_init(void) ...@@ -850,6 +926,10 @@ static int __init xfrmi4_init(void)
static void xfrmi4_fini(void) static void xfrmi4_fini(void)
{ {
#if IS_REACHABLE(CONFIG_INET_XFRM_TUNNEL)
xfrm4_tunnel_deregister(&xfrmi_ipip6_handler, AF_INET6);
xfrm4_tunnel_deregister(&xfrmi_ipip_handler, AF_INET);
#endif
xfrm4_protocol_deregister(&xfrmi_ipcomp4_protocol, IPPROTO_COMP); xfrm4_protocol_deregister(&xfrmi_ipcomp4_protocol, IPPROTO_COMP);
xfrm4_protocol_deregister(&xfrmi_ah4_protocol, IPPROTO_AH); xfrm4_protocol_deregister(&xfrmi_ah4_protocol, IPPROTO_AH);
xfrm4_protocol_deregister(&xfrmi_esp4_protocol, IPPROTO_ESP); xfrm4_protocol_deregister(&xfrmi_esp4_protocol, IPPROTO_ESP);
...@@ -868,9 +948,23 @@ static int __init xfrmi6_init(void) ...@@ -868,9 +948,23 @@ static int __init xfrmi6_init(void)
err = xfrm6_protocol_register(&xfrmi_ipcomp6_protocol, IPPROTO_COMP); err = xfrm6_protocol_register(&xfrmi_ipcomp6_protocol, IPPROTO_COMP);
if (err < 0) if (err < 0)
goto xfrm_proto_comp_failed; goto xfrm_proto_comp_failed;
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
err = xfrm6_tunnel_register(&xfrmi_ipv6_handler, AF_INET6);
if (err < 0)
goto xfrm_tunnel_ipv6_failed;
err = xfrm6_tunnel_register(&xfrmi_ip6ip_handler, AF_INET);
if (err < 0)
goto xfrm_tunnel_ip6ip_failed;
#endif
return 0; return 0;
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
xfrm_tunnel_ip6ip_failed:
xfrm6_tunnel_deregister(&xfrmi_ipv6_handler, AF_INET6);
xfrm_tunnel_ipv6_failed:
xfrm6_protocol_deregister(&xfrmi_ipcomp6_protocol, IPPROTO_COMP);
#endif
xfrm_proto_comp_failed: xfrm_proto_comp_failed:
xfrm6_protocol_deregister(&xfrmi_ah6_protocol, IPPROTO_AH); xfrm6_protocol_deregister(&xfrmi_ah6_protocol, IPPROTO_AH);
xfrm_proto_ah_failed: xfrm_proto_ah_failed:
...@@ -881,6 +975,10 @@ static int __init xfrmi6_init(void) ...@@ -881,6 +975,10 @@ static int __init xfrmi6_init(void)
static void xfrmi6_fini(void) static void xfrmi6_fini(void)
{ {
#if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
xfrm6_tunnel_deregister(&xfrmi_ip6ip_handler, AF_INET);
xfrm6_tunnel_deregister(&xfrmi_ipv6_handler, AF_INET6);
#endif
xfrm6_protocol_deregister(&xfrmi_ipcomp6_protocol, IPPROTO_COMP); xfrm6_protocol_deregister(&xfrmi_ipcomp6_protocol, IPPROTO_COMP);
xfrm6_protocol_deregister(&xfrmi_ah6_protocol, IPPROTO_AH); xfrm6_protocol_deregister(&xfrmi_ah6_protocol, IPPROTO_AH);
xfrm6_protocol_deregister(&xfrmi_esp6_protocol, IPPROTO_ESP); xfrm6_protocol_deregister(&xfrmi_esp6_protocol, IPPROTO_ESP);
......
...@@ -2758,6 +2758,7 @@ static void xfrm_policy_queue_process(struct timer_list *t) ...@@ -2758,6 +2758,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)
struct xfrm_policy_queue *pq = &pol->polq; struct xfrm_policy_queue *pq = &pol->polq;
struct flowi fl; struct flowi fl;
struct sk_buff_head list; struct sk_buff_head list;
__u32 skb_mark;
spin_lock(&pq->hold_queue.lock); spin_lock(&pq->hold_queue.lock);
skb = skb_peek(&pq->hold_queue); skb = skb_peek(&pq->hold_queue);
...@@ -2767,7 +2768,12 @@ static void xfrm_policy_queue_process(struct timer_list *t) ...@@ -2767,7 +2768,12 @@ static void xfrm_policy_queue_process(struct timer_list *t)
} }
dst = skb_dst(skb); dst = skb_dst(skb);
sk = skb->sk; sk = skb->sk;
/* Fixup the mark to support VTI. */
skb_mark = skb->mark;
skb->mark = pol->mark.v;
xfrm_decode_session(skb, &fl, dst->ops->family); xfrm_decode_session(skb, &fl, dst->ops->family);
skb->mark = skb_mark;
spin_unlock(&pq->hold_queue.lock); spin_unlock(&pq->hold_queue.lock);
dst_hold(xfrm_dst_path(dst)); dst_hold(xfrm_dst_path(dst));
...@@ -2799,7 +2805,12 @@ static void xfrm_policy_queue_process(struct timer_list *t) ...@@ -2799,7 +2805,12 @@ static void xfrm_policy_queue_process(struct timer_list *t)
while (!skb_queue_empty(&list)) { while (!skb_queue_empty(&list)) {
skb = __skb_dequeue(&list); skb = __skb_dequeue(&list);
/* Fixup the mark to support VTI. */
skb_mark = skb->mark;
skb->mark = pol->mark.v;
xfrm_decode_session(skb, &fl, skb_dst(skb)->ops->family); xfrm_decode_session(skb, &fl, skb_dst(skb)->ops->family);
skb->mark = skb_mark;
dst_hold(xfrm_dst_path(skb_dst(skb))); dst_hold(xfrm_dst_path(skb_dst(skb)));
dst = xfrm_lookup(net, xfrm_dst_path(skb_dst(skb)), &fl, skb->sk, 0); dst = xfrm_lookup(net, xfrm_dst_path(skb_dst(skb)), &fl, skb->sk, 0);
if (IS_ERR(dst)) { if (IS_ERR(dst)) {
......
...@@ -89,7 +89,8 @@ static int xfrm_replay_overflow(struct xfrm_state *x, struct sk_buff *skb) ...@@ -89,7 +89,8 @@ static int xfrm_replay_overflow(struct xfrm_state *x, struct sk_buff *skb)
if (x->type->flags & XFRM_TYPE_REPLAY_PROT) { if (x->type->flags & XFRM_TYPE_REPLAY_PROT) {
XFRM_SKB_CB(skb)->seq.output.low = ++x->replay.oseq; XFRM_SKB_CB(skb)->seq.output.low = ++x->replay.oseq;
XFRM_SKB_CB(skb)->seq.output.hi = 0; XFRM_SKB_CB(skb)->seq.output.hi = 0;
if (unlikely(x->replay.oseq == 0)) { if (unlikely(x->replay.oseq == 0) &&
!(x->props.extra_flags & XFRM_SA_XFLAG_OSEQ_MAY_WRAP)) {
x->replay.oseq--; x->replay.oseq--;
xfrm_audit_state_replay_overflow(x, skb); xfrm_audit_state_replay_overflow(x, skb);
err = -EOVERFLOW; err = -EOVERFLOW;
...@@ -168,7 +169,8 @@ static int xfrm_replay_overflow_bmp(struct xfrm_state *x, struct sk_buff *skb) ...@@ -168,7 +169,8 @@ static int xfrm_replay_overflow_bmp(struct xfrm_state *x, struct sk_buff *skb)
if (x->type->flags & XFRM_TYPE_REPLAY_PROT) { if (x->type->flags & XFRM_TYPE_REPLAY_PROT) {
XFRM_SKB_CB(skb)->seq.output.low = ++replay_esn->oseq; XFRM_SKB_CB(skb)->seq.output.low = ++replay_esn->oseq;
XFRM_SKB_CB(skb)->seq.output.hi = 0; XFRM_SKB_CB(skb)->seq.output.hi = 0;
if (unlikely(replay_esn->oseq == 0)) { if (unlikely(replay_esn->oseq == 0) &&
!(x->props.extra_flags & XFRM_SA_XFLAG_OSEQ_MAY_WRAP)) {
replay_esn->oseq--; replay_esn->oseq--;
xfrm_audit_state_replay_overflow(x, skb); xfrm_audit_state_replay_overflow(x, skb);
err = -EOVERFLOW; err = -EOVERFLOW;
...@@ -572,7 +574,8 @@ static int xfrm_replay_overflow_offload(struct xfrm_state *x, struct sk_buff *sk ...@@ -572,7 +574,8 @@ static int xfrm_replay_overflow_offload(struct xfrm_state *x, struct sk_buff *sk
XFRM_SKB_CB(skb)->seq.output.hi = 0; XFRM_SKB_CB(skb)->seq.output.hi = 0;
xo->seq.hi = 0; xo->seq.hi = 0;
if (unlikely(oseq < x->replay.oseq)) { if (unlikely(oseq < x->replay.oseq) &&
!(x->props.extra_flags & XFRM_SA_XFLAG_OSEQ_MAY_WRAP)) {
xfrm_audit_state_replay_overflow(x, skb); xfrm_audit_state_replay_overflow(x, skb);
err = -EOVERFLOW; err = -EOVERFLOW;
...@@ -611,7 +614,8 @@ static int xfrm_replay_overflow_offload_bmp(struct xfrm_state *x, struct sk_buff ...@@ -611,7 +614,8 @@ static int xfrm_replay_overflow_offload_bmp(struct xfrm_state *x, struct sk_buff
XFRM_SKB_CB(skb)->seq.output.hi = 0; XFRM_SKB_CB(skb)->seq.output.hi = 0;
xo->seq.hi = 0; xo->seq.hi = 0;
if (unlikely(oseq < replay_esn->oseq)) { if (unlikely(oseq < replay_esn->oseq) &&
!(x->props.extra_flags & XFRM_SA_XFLAG_OSEQ_MAY_WRAP)) {
xfrm_audit_state_replay_overflow(x, skb); xfrm_audit_state_replay_overflow(x, skb);
err = -EOVERFLOW; err = -EOVERFLOW;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment