Skip to content

Commit

Permalink
xfrm: ipcomp: add extack to ipcomp{4,6}_init_state
Browse files Browse the repository at this point in the history
And the shared helper ipcomp_init_state.

Signed-off-by: Sabrina Dubroca <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
  • Loading branch information
qsn authored and klassert committed Sep 29, 2022
1 parent 25ec92c commit 6ee5532
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/net/ipcomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct xfrm_state;
int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb);
int ipcomp_output(struct xfrm_state *x, struct sk_buff *skb);
void ipcomp_destroy(struct xfrm_state *x);
int ipcomp_init_state(struct xfrm_state *x);
int ipcomp_init_state(struct xfrm_state *x, struct netlink_ext_ack *extack);

static inline struct ip_comp_hdr *ip_comp_hdr(const struct sk_buff *skb)
{
Expand Down
7 changes: 5 additions & 2 deletions net/ipv4/ipcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,20 @@ static int ipcomp4_init_state(struct xfrm_state *x,
x->props.header_len += sizeof(struct iphdr);
break;
default:
NL_SET_ERR_MSG(extack, "Unsupported XFRM mode for IPcomp");
goto out;
}

err = ipcomp_init_state(x);
err = ipcomp_init_state(x, extack);
if (err)
goto out;

if (x->props.mode == XFRM_MODE_TUNNEL) {
err = ipcomp_tunnel_attach(x);
if (err)
if (err) {
NL_SET_ERR_MSG(extack, "Kernel error: failed to initialize the associated state");
goto out;
}
}

err = 0;
Expand Down
7 changes: 5 additions & 2 deletions net/ipv6/ipcomp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,20 @@ static int ipcomp6_init_state(struct xfrm_state *x,
x->props.header_len += sizeof(struct ipv6hdr);
break;
default:
NL_SET_ERR_MSG(extack, "Unsupported XFRM mode for IPcomp");
goto out;
}

err = ipcomp_init_state(x);
err = ipcomp_init_state(x, extack);
if (err)
goto out;

if (x->props.mode == XFRM_MODE_TUNNEL) {
err = ipcomp6_tunnel_attach(x);
if (err)
if (err) {
NL_SET_ERR_MSG(extack, "Kernel error: failed to initialize the associated state");
goto out;
}
}

err = 0;
Expand Down
10 changes: 7 additions & 3 deletions net/xfrm/xfrm_ipcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,22 @@ void ipcomp_destroy(struct xfrm_state *x)
}
EXPORT_SYMBOL_GPL(ipcomp_destroy);

int ipcomp_init_state(struct xfrm_state *x)
int ipcomp_init_state(struct xfrm_state *x, struct netlink_ext_ack *extack)
{
int err;
struct ipcomp_data *ipcd;
struct xfrm_algo_desc *calg_desc;

err = -EINVAL;
if (!x->calg)
if (!x->calg) {
NL_SET_ERR_MSG(extack, "Missing required compression algorithm");
goto out;
}

if (x->encap)
if (x->encap) {
NL_SET_ERR_MSG(extack, "IPComp is not compatible with encapsulation");
goto out;
}

err = -ENOMEM;
ipcd = kzalloc(sizeof(*ipcd), GFP_KERNEL);
Expand Down

0 comments on commit 6ee5532

Please sign in to comment.