From patchwork Mon Nov 16 15:06:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schultz X-Patchwork-Id: 545069 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (unknown [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id A57C3140D97 for ; Tue, 17 Nov 2015 02:07:50 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 613979D85; Mon, 16 Nov 2015 15:07:44 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.tpip.net (mail.tpip.net [92.43.49.48]) by lists.osmocom.org (Postfix) with ESMTP id 863169D51 for ; Mon, 16 Nov 2015 15:07:37 +0000 (UTC) Received: from office.tpip.net (office.tpip.net [92.43.51.2]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.tpip.net (Postfix) with ESMTPS id BC3E04F41A; Mon, 16 Nov 2015 15:07:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by office.tpip.net (Postfix) with ESMTP id 05977A2CA8; Mon, 16 Nov 2015 16:07:07 +0100 (CET) Received: from office.tpip.net ([127.0.0.1]) by localhost (office.tpip.net [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id PmZ08pNaXYhp; Mon, 16 Nov 2015 16:07:06 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by office.tpip.net (Postfix) with ESMTP id A6FA0A2CAA; Mon, 16 Nov 2015 16:07:06 +0100 (CET) X-Virus-Scanned: amavisd-new at tpip.net Received: from office.tpip.net ([127.0.0.1]) by localhost (office.tpip.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id eKB063df0Xf2; Mon, 16 Nov 2015 16:07:06 +0100 (CET) Received: from alice.tpip.org (unknown [192.168.13.53]) by office.tpip.net (Postfix) with ESMTPSA id 4F71FA2CA8; Mon, 16 Nov 2015 16:07:06 +0100 (CET) From: Andreas Schultz To: openbsc@lists.osmocom.org Subject: [PATCH 06/16] gtp: add error handling to gtp_newlink Date: Mon, 16 Nov 2015 16:06:47 +0100 Message-Id: <1447686417-3979-7-git-send-email-aschultz@tpip.net> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1447686417-3979-1-git-send-email-aschultz@tpip.net> References: <1447686417-3979-1-git-send-email-aschultz@tpip.net> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pablo Neira Ayuso Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Signed-off-by: Andreas Schultz --- gtp.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/gtp.c b/gtp.c index 11f8fad..4f5729e 100644 --- a/gtp.c +++ b/gtp.c @@ -756,8 +756,12 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, if (!tb[IFLA_MTU]) dev->mtu = real_dev->mtu; - else if (dev->mtu > real_dev->mtu) - return -EINVAL; + else if (dev->mtu > real_dev->mtu) { + netdev_dbg(dev, "GTP mtu greater that transport MTU (%d > %d)\n", + dev->mtu, real_dev->mtu); + err = -EINVAL; + goto out_err; + } gti = netdev_priv(dev); gti->real_dev = real_dev; @@ -765,7 +769,9 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, fd0 = nla_get_u32(data[IFLA_GTP_FD0]); fd1 = nla_get_u32(data[IFLA_GTP_FD1]); - gtp_encap_enable(dev, gti, fd0, fd1); + err = gtp_encap_enable(dev, gti, fd0, fd1); + if (err < 0) + goto out_err; if (!data[IFLA_GTP_HASHSIZE]) hashsize = 1024; @@ -774,21 +780,29 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, err = gtp_hashtable_new(gti, hashsize); if (err < 0) - return err; + goto out_encap; err = register_netdevice(dev); - if (err < 0) - goto err1; + if (err < 0) { + netdev_dbg(dev, "failed to register new netdev %d\n", err); + goto out_hashtable; + } gn = net_generic(dev_net(dev), gtp_net_id); list_add_rcu(>i->list, &gn->gtp_instance_list); - netdev_dbg(dev, "registered new interface\n"); + netdev_dbg(dev, "registered new GTP interface\n"); return 0; -err1: - netdev_dbg(dev, "failed to register new netdev %d\n", err); + +out_hashtable: gtp_hashtable_free(gti); + +out_encap: + gtp_encap_disable(gti); + +out_err: + dev_put(real_dev); return err; }