1191418Srwatson/*-
2191418Srwatson * Copyright (c) 2009 Robert N. M. Watson
3191418Srwatson * All rights reserved.
4191418Srwatson *
5191418Srwatson * Redistribution and use in source and binary forms, with or without
6191418Srwatson * modification, are permitted provided that the following conditions
7191418Srwatson * are met:
8191418Srwatson * 1. Redistributions of source code must retain the above copyright
9191418Srwatson *    notice, this list of conditions and the following disclaimer.
10191418Srwatson * 2. Redistributions in binary form must reproduce the above copyright
11191418Srwatson *    notice, this list of conditions and the following disclaimer in the
12191418Srwatson *    documentation and/or other materials provided with the distribution.
13191418Srwatson *
14191418Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15191418Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16191418Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17191418Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18191418Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19191418Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20191418Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21191418Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22191418Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23191418Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24191418Srwatson * SUCH DAMAGE.
25191418Srwatson */
26191418Srwatson
27191418Srwatson/*
28191418Srwatson * When an interface has been detached but not yet freed, we set the various
29191418Srwatson * ifnet function pointers to "ifdead" versions.  This prevents unexpected
30191418Srwatson * calls from the network stack into the device driver after if_detach() has
31191418Srwatson * returned.
32191418Srwatson */
33191418Srwatson
34191418Srwatson#include <sys/cdefs.h>
35191418Srwatson__FBSDID("$FreeBSD$");
36191418Srwatson
37191418Srwatson#include <sys/param.h>
38191418Srwatson#include <sys/mbuf.h>
39191418Srwatson#include <sys/socket.h>
40191418Srwatson
41191418Srwatson#include <net/if.h>
42191418Srwatson#include <net/if_var.h>
43191418Srwatson
44191418Srwatsonstatic int
45249925Sglebiusifdead_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa,
46191418Srwatson    struct route *ro)
47191418Srwatson{
48191418Srwatson
49191418Srwatson	m_freem(m);
50191418Srwatson	return (ENXIO);
51191418Srwatson}
52191418Srwatson
53191418Srwatsonstatic void
54191418Srwatsonifdead_input(struct ifnet *ifp, struct mbuf *m)
55191418Srwatson{
56191418Srwatson
57191418Srwatson	m_freem(m);
58191418Srwatson}
59191418Srwatson
60191418Srwatsonstatic void
61191418Srwatsonifdead_start(struct ifnet *ifp)
62191418Srwatson{
63191418Srwatson
64191418Srwatson}
65191418Srwatson
66191418Srwatsonstatic int
67191418Srwatsonifdead_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
68191418Srwatson{
69191418Srwatson
70191418Srwatson	return (ENXIO);
71191418Srwatson}
72191418Srwatson
73191418Srwatsonstatic int
74191418Srwatsonifdead_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
75191418Srwatson    struct sockaddr *sa)
76191418Srwatson{
77191418Srwatson
78191418Srwatson	*llsa = NULL;
79191418Srwatson	return (ENXIO);
80191418Srwatson}
81191418Srwatson
82191418Srwatsonstatic void
83191418Srwatsonifdead_qflush(struct ifnet *ifp)
84191418Srwatson{
85191418Srwatson
86191418Srwatson}
87191418Srwatson
88191418Srwatsonstatic int
89191418Srwatsonifdead_transmit(struct ifnet *ifp, struct mbuf *m)
90191418Srwatson{
91191418Srwatson
92191418Srwatson	m_freem(m);
93191418Srwatson	return (ENXIO);
94191418Srwatson}
95191418Srwatson
96275730Sjhbstatic uint64_t
97275730Sjhbifdead_get_counter(struct ifnet *ifp, ift_counter cnt)
98275730Sjhb{
99275730Sjhb
100275730Sjhb	return (0);
101275730Sjhb}
102275730Sjhb
103191418Srwatsonvoid
104191418Srwatsonif_dead(struct ifnet *ifp)
105191418Srwatson{
106191418Srwatson
107191418Srwatson	ifp->if_output = ifdead_output;
108191418Srwatson	ifp->if_input = ifdead_input;
109191418Srwatson	ifp->if_start = ifdead_start;
110191418Srwatson	ifp->if_ioctl = ifdead_ioctl;
111191418Srwatson	ifp->if_resolvemulti = ifdead_resolvemulti;
112191418Srwatson	ifp->if_qflush = ifdead_qflush;
113191418Srwatson	ifp->if_transmit = ifdead_transmit;
114275730Sjhb	ifp->if_get_counter = ifdead_get_counter;
115191418Srwatson}
116