Linux 2.6.17.7
[linux/fpc-iii.git] / arch / um / drivers / pcap_kern.c
blob466ff2c2f9183074b7e0e5faf13d676a617c2fe7
1 /*
2 * Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
3 * Licensed under the GPL.
4 */
6 #include "linux/init.h"
7 #include "linux/netdevice.h"
8 #include "linux/etherdevice.h"
9 #include "net_kern.h"
10 #include "net_user.h"
11 #include "pcap_user.h"
13 struct pcap_init {
14 char *host_if;
15 int promisc;
16 int optimize;
17 char *filter;
20 void pcap_init(struct net_device *dev, void *data)
22 struct uml_net_private *pri;
23 struct pcap_data *ppri;
24 struct pcap_init *init = data;
26 pri = dev->priv;
27 ppri = (struct pcap_data *) pri->user;
28 ppri->host_if = init->host_if;
29 ppri->promisc = init->promisc;
30 ppri->optimize = init->optimize;
31 ppri->filter = init->filter;
34 static int pcap_read(int fd, struct sk_buff **skb,
35 struct uml_net_private *lp)
37 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
38 if(*skb == NULL) return(-ENOMEM);
39 return(pcap_user_read(fd, (*skb)->mac.raw,
40 (*skb)->dev->mtu + ETH_HEADER_OTHER,
41 (struct pcap_data *) &lp->user));
44 static int pcap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
46 return(-EPERM);
49 static struct net_kern_info pcap_kern_info = {
50 .init = pcap_init,
51 .protocol = eth_protocol,
52 .read = pcap_read,
53 .write = pcap_write,
56 int pcap_setup(char *str, char **mac_out, void *data)
58 struct pcap_init *init = data;
59 char *remain, *host_if = NULL, *options[2] = { NULL, NULL };
60 int i;
62 *init = ((struct pcap_init)
63 { .host_if = "eth0",
64 .promisc = 1,
65 .optimize = 0,
66 .filter = NULL });
68 remain = split_if_spec(str, &host_if, &init->filter,
69 &options[0], &options[1], NULL);
70 if(remain != NULL){
71 printk(KERN_ERR "pcap_setup - Extra garbage on "
72 "specification : '%s'\n", remain);
73 return(0);
76 if(host_if != NULL)
77 init->host_if = host_if;
79 for(i = 0; i < sizeof(options)/sizeof(options[0]); i++){
80 if(options[i] == NULL)
81 continue;
82 if(!strcmp(options[i], "promisc"))
83 init->promisc = 1;
84 else if(!strcmp(options[i], "nopromisc"))
85 init->promisc = 0;
86 else if(!strcmp(options[i], "optimize"))
87 init->optimize = 1;
88 else if(!strcmp(options[i], "nooptimize"))
89 init->optimize = 0;
90 else printk("pcap_setup : bad option - '%s'\n", options[i]);
93 return(1);
96 static struct transport pcap_transport = {
97 .list = LIST_HEAD_INIT(pcap_transport.list),
98 .name = "pcap",
99 .setup = pcap_setup,
100 .user = &pcap_user_info,
101 .kern = &pcap_kern_info,
102 .private_size = sizeof(struct pcap_data),
103 .setup_size = sizeof(struct pcap_init),
106 static int register_pcap(void)
108 register_transport(&pcap_transport);
109 return 0;
112 __initcall(register_pcap);