ip_tunnel: Unify error paths in ip_tunnel_newlink() and ip_tunnel_changelink().

The next patch will introduce per-netns mutex and acquire it
in ip_tunnel_newlink() and ip_tunnel_changelink().

To make the diff cleaner, let's unify the error paths.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260912230043.2586313-6-kuniyu@google.com
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Kuniyuki Iwashima 2026-09-12 23:00:31 +00:00 committed by Paolo Abeni
parent e53013fe10
commit 6faf19060b

View File

@ -1179,21 +1179,23 @@ int ip_tunnel_newlink(struct net *net, struct net_device *dev,
struct nlattr *tb[], struct ip_tunnel_parm_kern *p,
__u32 fwmark)
{
struct ip_tunnel *nt;
struct ip_tunnel_net *itn;
struct ip_tunnel *nt;
int err = 0;
int mtu;
int err;
nt = netdev_priv(dev);
itn = net_generic(net, nt->ip_tnl_net_id);
if (nt->collect_md) {
if (rtnl_dereference(itn->collect_md_tun))
return -EEXIST;
err = -EEXIST;
} else {
if (ip_tunnel_find(itn, p, dev->type))
return -EEXIST;
err = -EEXIST;
}
if (err)
goto out;
nt->net = net;
nt->parms = *p;
@ -1220,22 +1222,26 @@ int ip_tunnel_newlink(struct net *net, struct net_device *dev,
goto err_dev_set_mtu;
ip_tunnel_add(itn, nt);
return 0;
out:
return err;
err_dev_set_mtu:
unregister_netdevice(dev);
err_register_netdevice:
return err;
goto out;
}
EXPORT_SYMBOL_GPL(ip_tunnel_newlink);
int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
struct ip_tunnel_parm_kern *p, __u32 fwmark)
{
struct ip_tunnel *t;
struct ip_tunnel *tunnel = netdev_priv(dev);
struct net *net = tunnel->net;
struct ip_tunnel_net *itn = net_generic(net, tunnel->ip_tnl_net_id);
struct ip_tunnel_net *itn;
struct ip_tunnel *t;
int err = 0;
itn = net_generic(net, tunnel->ip_tnl_net_id);
if (dev == itn->fb_tunnel_dev)
return -EINVAL;
@ -1243,8 +1249,10 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
t = ip_tunnel_find(itn, p, dev->type);
if (t) {
if (t->dev != dev)
return -EEXIST;
if (t->dev != dev) {
err = -EEXIST;
goto out;
}
} else {
t = tunnel;
@ -1257,13 +1265,16 @@ int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
nflags = IFF_POINTOPOINT;
if ((dev->flags ^ nflags) &
(IFF_POINTOPOINT | IFF_BROADCAST))
return -EINVAL;
(IFF_POINTOPOINT | IFF_BROADCAST)) {
err = -EINVAL;
goto out;
}
}
}
ip_tunnel_update(itn, t, dev, p, !tb[IFLA_MTU], fwmark);
return 0;
out:
return err;
}
EXPORT_SYMBOL_GPL(ip_tunnel_changelink);