- If if_attach() failed in the attach function, free resources and return.
- KNF
This commit is contained in:
parent
2223ce7058
commit
351c2b7262
@ -1,8 +1,8 @@
|
|||||||
/* $NetBSD: if_srt.c,v 1.26 2017/02/14 03:05:06 ozaki-r Exp $ */
|
/* $NetBSD: if_srt.c,v 1.27 2017/10/23 09:32:55 msaitoh Exp $ */
|
||||||
/* This file is in the public domain. */
|
/* This file is in the public domain. */
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.26 2017/02/14 03:05:06 ozaki-r Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.27 2017/10/23 09:32:55 msaitoh Exp $");
|
||||||
|
|
||||||
#ifdef _KERNEL_OPT
|
#ifdef _KERNEL_OPT
|
||||||
#include "opt_inet.h"
|
#include "opt_inet.h"
|
||||||
@ -249,6 +249,7 @@ static int
|
|||||||
srt_clone_create(struct if_clone *cl, int unit)
|
srt_clone_create(struct if_clone *cl, int unit)
|
||||||
{
|
{
|
||||||
struct srt_softc *sc;
|
struct srt_softc *sc;
|
||||||
|
int rv;
|
||||||
|
|
||||||
if (unit < 0 || unit > SRT_MAXUNIT)
|
if (unit < 0 || unit > SRT_MAXUNIT)
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
@ -268,7 +269,13 @@ srt_clone_create(struct if_clone *cl, int unit)
|
|||||||
sc->intf.if_ioctl = &srt_if_ioctl;
|
sc->intf.if_ioctl = &srt_if_ioctl;
|
||||||
sc->intf.if_output = &srt_if_output;
|
sc->intf.if_output = &srt_if_output;
|
||||||
sc->intf.if_dlt = DLT_RAW;
|
sc->intf.if_dlt = DLT_RAW;
|
||||||
if_attach(&sc->intf);
|
rv = if_attach(&sc->intf);
|
||||||
|
if (rv != 0) {
|
||||||
|
aprint_error("%s: if_initialize failed(%d)\n",
|
||||||
|
sc->intf.if_xname, rv);
|
||||||
|
free(sc, M_DEVBUF);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
if_alloc_sadl(&sc->intf);
|
if_alloc_sadl(&sc->intf);
|
||||||
#ifdef BPFILTER_NOW_AVAILABLE
|
#ifdef BPFILTER_NOW_AVAILABLE
|
||||||
bpf_attach(&sc->intf, 0, 0);
|
bpf_attach(&sc->intf, 0, 0);
|
||||||
@ -408,7 +415,8 @@ srt_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
|
|||||||
dr->af = scr->af;
|
dr->af = scr->af;
|
||||||
dr->srcmatch = scr->srcmatch;
|
dr->srcmatch = scr->srcmatch;
|
||||||
dr->srcmask = scr->srcmask;
|
dr->srcmask = scr->srcmask;
|
||||||
strlcpy(&dr->u.dstifn[0],&scr->u.dstifp->if_xname[0],IFNAMSIZ);
|
strlcpy(&dr->u.dstifn[0], &scr->u.dstifp->if_xname[0],
|
||||||
|
IFNAMSIZ);
|
||||||
memcpy(&dr->dst, &scr->dst, scr->dst.sa.sa_len);
|
memcpy(&dr->dst, &scr->dst, scr->dst.sa.sa_len);
|
||||||
return 0;
|
return 0;
|
||||||
case SRT_SETRT:
|
case SRT_SETRT:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: if_stf.c,v 1.101 2016/12/12 03:55:57 ozaki-r Exp $ */
|
/* $NetBSD: if_stf.c,v 1.102 2017/10/23 09:32:55 msaitoh Exp $ */
|
||||||
/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
|
/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -75,7 +75,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.101 2016/12/12 03:55:57 ozaki-r Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.102 2017/10/23 09:32:55 msaitoh Exp $");
|
||||||
|
|
||||||
#ifdef _KERNEL_OPT
|
#ifdef _KERNEL_OPT
|
||||||
#include "opt_inet.h"
|
#include "opt_inet.h"
|
||||||
@ -220,7 +220,7 @@ stf_clone_create(struct if_clone *ifc, int unit)
|
|||||||
/* Only one stf interface is allowed. */
|
/* Only one stf interface is allowed. */
|
||||||
encap_lock_exit();
|
encap_lock_exit();
|
||||||
free(sc, M_DEVBUF);
|
free(sc, M_DEVBUF);
|
||||||
return (EEXIST);
|
return EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
|
sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
|
||||||
@ -229,7 +229,7 @@ stf_clone_create(struct if_clone *ifc, int unit)
|
|||||||
if (sc->encap_cookie == NULL) {
|
if (sc->encap_cookie == NULL) {
|
||||||
printf("%s: unable to attach encap\n", if_name(&sc->sc_if));
|
printf("%s: unable to attach encap\n", if_name(&sc->sc_if));
|
||||||
free(sc, M_DEVBUF);
|
free(sc, M_DEVBUF);
|
||||||
return (EIO); /* XXX */
|
return EIO; /* XXX */
|
||||||
}
|
}
|
||||||
|
|
||||||
sc->sc_if.if_mtu = STF_MTU;
|
sc->sc_if.if_mtu = STF_MTU;
|
||||||
@ -238,11 +238,20 @@ stf_clone_create(struct if_clone *ifc, int unit)
|
|||||||
sc->sc_if.if_output = stf_output;
|
sc->sc_if.if_output = stf_output;
|
||||||
sc->sc_if.if_type = IFT_STF;
|
sc->sc_if.if_type = IFT_STF;
|
||||||
sc->sc_if.if_dlt = DLT_NULL;
|
sc->sc_if.if_dlt = DLT_NULL;
|
||||||
if_attach(&sc->sc_if);
|
error = if_attach(&sc->sc_if);
|
||||||
|
if (error != 0) {
|
||||||
|
aprint_error("%s: if_initialize failed(%d)\n",
|
||||||
|
if_name(&sc->sc_if), error);
|
||||||
|
encap_lock_enter();
|
||||||
|
encap_detach(sc->encap_cookie);
|
||||||
|
encap_lock_exit();
|
||||||
|
free(sc, M_DEVBUF);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
if_alloc_sadl(&sc->sc_if);
|
if_alloc_sadl(&sc->sc_if);
|
||||||
bpf_attach(&sc->sc_if, DLT_NULL, sizeof(u_int));
|
bpf_attach(&sc->sc_if, DLT_NULL, sizeof(u_int));
|
||||||
LIST_INSERT_HEAD(&stf_softc_list, sc, sc_list);
|
LIST_INSERT_HEAD(&stf_softc_list, sc, sc_list);
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -259,7 +268,7 @@ stf_clone_destroy(struct ifnet *ifp)
|
|||||||
rtcache_free(&sc->sc_ro);
|
rtcache_free(&sc->sc_ro);
|
||||||
free(sc, M_DEVBUF);
|
free(sc, M_DEVBUF);
|
||||||
|
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user