Commit aa9667e7 authored by Simon Horman's avatar Simon Horman Committed by David S. Miller

tunnels: correct conditional build of MPLS and IPv6

Using a combination if #if conditionals and goto labels to unwind
tunnel4_init seems unwieldy. This patch takes a simpler approach of
directly unregistering previously registered protocols when an error
occurs.

This fixes a number of problems with the current implementation
including the potential presence of labels when they are unused
and the potential absence of unregister code when it is needed.

Fixes: 8afe97e5 ("tunnels: support MPLS over IPv4 tunnels")
Signed-off-by: default avatarSimon Horman <simon.horman@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4154cb40
...@@ -208,24 +208,25 @@ static const struct net_protocol tunnelmpls4_protocol = { ...@@ -208,24 +208,25 @@ static const struct net_protocol tunnelmpls4_protocol = {
static int __init tunnel4_init(void) static int __init tunnel4_init(void)
{ {
if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP))
goto err_ipip; goto err;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
if (inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)) if (inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)) {
goto err_ipv6; inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
goto err;
}
#endif #endif
#if IS_ENABLED(CONFIG_MPLS) #if IS_ENABLED(CONFIG_MPLS)
if (inet_add_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS)) if (inet_add_protocol(&tunnelmpls4_protocol, IPPROTO_MPLS)) {
goto err_mpls; inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
#if IS_ENABLED(CONFIG_IPV6)
inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6);
#endif
goto err;
}
#endif #endif
return 0; return 0;
#if IS_ENABLED(CONFIG_IPV6) err:
err_mpls:
inet_del_protocol(&tunnel4_protocol, IPPROTO_IPV6);
#endif
err_ipv6:
inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);
err_ipip:
pr_err("%s: can't add protocol\n", __func__); pr_err("%s: can't add protocol\n", __func__);
return -EAGAIN; return -EAGAIN;
} }
......
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