OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / support / bpf-lkm / OpenBSD / ether_mod_load.c
1 /*
2  *  $Id: ether_mod_load.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet
5  *  OpenBSD ether_mod_load.c - lkm replacement for ether_output
6  *
7  *  Copyright (c) 1998, 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
8  *  Original code and idea 1997 Thomas Ptacek <tqbf@pobox.com>
9  *  All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  */
33
34
35 #include <sys/param.h>
36 #include <sys/proc.h>
37 #include <sys/systm.h>
38 #include <sys/conf.h>
39 #include <sys/mount.h>
40 #include <sys/exec.h>
41 #include <sys/lkm.h>
42 #include <sys/file.h>
43 #include <sys/errno.h>
44 #include <sys/queue.h>
45 #include <sys/mbuf.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
48 #include <sys/protosw.h>
49 #include <sys/kernel.h>
50 #include <sys/sockio.h>
51 #include <net/if.h>
52 #include <net/if_dl.h>
53 #include <net/if_types.h>
54 #include <net/radix.h>
55                                                                 
56 extern int ether_output_spoof __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
57 int ether_spoof(struct lkm_table *lkp, int cmd, int ver);
58
59 MOD_MISC("etherspoof");
60
61 static int 
62 etherspoof_load(struct lkm_table *lkp, int cmd)
63 {
64     struct ifnet *ifp;
65     int err = 0;
66
67     switch (cmd)
68     {
69         case LKM_E_LOAD:
70             for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_list.tqe_next)
71             {
72                 if (ifp->if_output == ether_output)
73                 {
74                     ifp->if_output = ether_output_spoof;
75                     printf("Interface %s fixed\n", ifp->if_xname);
76                 }
77             }                   
78         
79             printf("Ethernet MAC Address Fix Loaded\n");
80             break;
81
82         case LKM_E_UNLOAD:
83             for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_list.tqe_next)
84             {
85                 if (ifp->if_output == ether_output_spoof)
86                 {
87                     ifp->if_output = ether_output;
88                     printf("Interface %s unfixed\n", ifp->if_xname);
89                 }
90             }
91             printf("Ethernet MAC Address Fix Unloaded\n");
92             break;
93         default:
94             err = EINVAL;
95             break;
96     }
97     return(err);
98 }
99
100
101 int ether_spoof(struct lkm_table *lkp, int cmd, int ver)
102 {
103     DISPATCH(lkp, cmd, ver, etherspoof_load, etherspoof_load, lkm_nofunc);
104 }