if_dead.c revision 191418
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: head/sys/net/if_dead.c 191418 2009-04-23 11:51:53Z rwatson $");
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
45191418Srwatsonifdead_output(struct ifnet *ifp, struct mbuf *m, 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 void
74191418Srwatsonifdead_watchdog(struct ifnet *ifp)
75191418Srwatson{
76191418Srwatson
77191418Srwatson}
78191418Srwatson
79191418Srwatsonstatic int
80191418Srwatsonifdead_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
81191418Srwatson    struct sockaddr *sa)
82191418Srwatson{
83191418Srwatson
84191418Srwatson	*llsa = NULL;
85191418Srwatson	return (ENXIO);
86191418Srwatson}
87191418Srwatson
88191418Srwatsonstatic void
89191418Srwatsonifdead_qflush(struct ifnet *ifp)
90191418Srwatson{
91191418Srwatson
92191418Srwatson}
93191418Srwatson
94191418Srwatsonstatic int
95191418Srwatsonifdead_transmit(struct ifnet *ifp, struct mbuf *m)
96191418Srwatson{
97191418Srwatson
98191418Srwatson	m_freem(m);
99191418Srwatson	return (ENXIO);
100191418Srwatson}
101191418Srwatson
102191418Srwatsonvoid
103191418Srwatsonif_dead(struct ifnet *ifp)
104191418Srwatson{
105191418Srwatson
106191418Srwatson	ifp->if_output = ifdead_output;
107191418Srwatson	ifp->if_input = ifdead_input;
108191418Srwatson	ifp->if_start = ifdead_start;
109191418Srwatson	ifp->if_ioctl = ifdead_ioctl;
110191418Srwatson	ifp->if_watchdog = ifdead_watchdog;
111191418Srwatson	ifp->if_resolvemulti = ifdead_resolvemulti;
112191418Srwatson	ifp->if_qflush = ifdead_qflush;
113191418Srwatson	ifp->if_transmit = ifdead_transmit;
114191418Srwatson}
115