diff options
| author | Kuniyuki Iwashima <kuniyu@google.com> | 2026-09-12 23:00:31 +0000 |
|---|---|---|
| committer | Paolo Abeni <pabeni@redhat.com> | 2026-09-15 13:21:33 +0200 |
| commit | 6faf19060bd0123b69d7e9b04244fd577223ac3c (patch) | |
| tree | 64040046da685c59e5395f7fc57b07a485dca0b0 /net/ipv4 | |
| parent | e53013fe10c22fc4e2cc1b45180790a5429c7aa9 (diff) | |
| download | linux-next-6faf19060bd0123b69d7e9b04244fd577223ac3c.tar.gz linux-next-6faf19060bd0123b69d7e9b04244fd577223ac3c.zip | |
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>
Diffstat (limited to 'net/ipv4')
| -rw-r--r-- | net/ipv4/ip_tunnel.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 7d7baaa57741..d560ae9f0222 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -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); |
