OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / support / bpf-lkm / FreeBSD / 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  *  FreeBSD 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 #define INET
35
36 #include <sys/param.h>
37 #include <sys/proc.h>
38 #include <sys/systm.h>
39 #include <sys/sysproto.h>
40 #include <sys/conf.h>
41 #include <sys/mount.h>
42 #include <sys/exec.h>
43 #include <sys/sysent.h>
44 #include <sys/lkm.h>
45 #include <sys/file.h>
46 #include <sys/errno.h>
47 #include <sys/queue.h>
48 #include <sys/mbuf.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/protosw.h>
52 #include <sys/kernel.h>
53 #include <sys/sockio.h>
54 #include <net/if.h>
55 #include <net/if_dl.h>
56 #include <net/if_types.h>
57 #include <net/if_var.h>
58 #include <net/radix.h>
59                                                                 
60 extern int ether_output_spoof __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
61 int ether_spoof(struct lkm_table *lkp, int cmd, int ver);
62
63 MOD_MISC(etherspoof);
64
65 static int 
66 etherspoof_load(struct lkm_table *lkp, int cmd)
67 {
68     struct ifnet *ifp;
69     int err = 0;
70
71     switch (cmd)
72     {
73         case LKM_E_LOAD:
74             for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next)
75             {
76                 if (ifp->if_output == ether_output)
77                 {
78                     ifp->if_output = ether_output_spoof;
79                     printf("Interface %s fixed\n", ifp->if_name);
80                 }
81             }                   
82         
83             printf("Ethernet MAC Address Fix Loaded\n");
84             break;
85
86         case LKM_E_UNLOAD:
87             for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next)
88             {
89                 if (ifp->if_output == ether_output_spoof)
90                 {
91                     ifp->if_output = ether_output;
92                     printf("Interface %s unfixed\n", ifp->if_name);
93                 }
94             }
95             printf("Ethernet MAC Address Fix Unloaded\n");
96             break;
97         default:
98             err = EINVAL;
99             break;
100     }
101     return(err);
102 }
103
104
105 int ether_spoof(struct lkm_table *lkp, int cmd, int ver)
106 {
107     DISPATCH(etherspoof, lkp, cmd, ver, etherspoof_load, etherspoof_load, lkm_nullcmd);
108 }