blob: 2860525f8ff6d56219e81dd2fe7afa8f3c627c35 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07002 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Licensed under the GPL.
4 */
5
6#include "linux/init.h"
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07007#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include "net_kern.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "pcap_user.h"
10
11struct pcap_init {
12 char *host_if;
13 int promisc;
14 int optimize;
15 char *filter;
16};
17
18void pcap_init(struct net_device *dev, void *data)
19{
20 struct uml_net_private *pri;
21 struct pcap_data *ppri;
22 struct pcap_init *init = data;
23
Wang Chen17c324f2008-12-04 15:07:33 -080024 pri = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 ppri = (struct pcap_data *) pri->user;
26 ppri->host_if = init->host_if;
27 ppri->promisc = init->promisc;
28 ppri->optimize = init->optimize;
29 ppri->filter = init->filter;
Jeff Dike7d982302007-05-08 00:35:04 -070030
31 printk("pcap backend, host interface %s\n", ppri->host_if);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032}
33
Jeff Dikeb53f35a2007-10-16 01:27:31 -070034static int pcap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Jeff Dikeb53f35a2007-10-16 01:27:31 -070036 return pcap_user_read(fd, skb_mac_header(skb),
37 skb->dev->mtu + ETH_HEADER_OTHER,
Jeff Dike7d982302007-05-08 00:35:04 -070038 (struct pcap_data *) &lp->user);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
Jeff Dikeb53f35a2007-10-16 01:27:31 -070041static int pcap_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Jeff Dike7d982302007-05-08 00:35:04 -070043 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
Jeff Dike5e7672e2006-09-27 01:50:33 -070046static const struct net_kern_info pcap_kern_info = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .init = pcap_init,
48 .protocol = eth_protocol,
49 .read = pcap_read,
50 .write = pcap_write,
51};
52
53int pcap_setup(char *str, char **mac_out, void *data)
54{
55 struct pcap_init *init = data;
56 char *remain, *host_if = NULL, *options[2] = { NULL, NULL };
57 int i;
58
59 *init = ((struct pcap_init)
60 { .host_if = "eth0",
61 .promisc = 1,
62 .optimize = 0,
63 .filter = NULL });
64
Jeff Dike7d982302007-05-08 00:35:04 -070065 remain = split_if_spec(str, &host_if, &init->filter,
Jeff Dike0ba34e12007-05-08 00:35:06 -070066 &options[0], &options[1], mac_out, NULL);
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070067 if (remain != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 printk(KERN_ERR "pcap_setup - Extra garbage on "
69 "specification : '%s'\n", remain);
Jeff Dike7d982302007-05-08 00:35:04 -070070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 }
72
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070073 if (host_if != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 init->host_if = host_if;
75
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070076 for (i = 0; i < ARRAY_SIZE(options); i++) {
77 if (options[i] == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 continue;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070079 if (!strcmp(options[i], "promisc"))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 init->promisc = 1;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070081 else if (!strcmp(options[i], "nopromisc"))
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 init->promisc = 0;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070083 else if (!strcmp(options[i], "optimize"))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 init->optimize = 1;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070085 else if (!strcmp(options[i], "nooptimize"))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 init->optimize = 0;
Jeff Dike7d982302007-05-08 00:35:04 -070087 else {
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070088 printk(KERN_ERR "pcap_setup : bad option - '%s'\n",
89 options[i]);
Jeff Dike7d982302007-05-08 00:35:04 -070090 return 0;
91 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
93
Jeff Dike7d982302007-05-08 00:35:04 -070094 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
97static struct transport pcap_transport = {
98 .list = LIST_HEAD_INIT(pcap_transport.list),
99 .name = "pcap",
100 .setup = pcap_setup,
101 .user = &pcap_user_info,
102 .kern = &pcap_kern_info,
103 .private_size = sizeof(struct pcap_data),
104 .setup_size = sizeof(struct pcap_init),
105};
106
107static int register_pcap(void)
108{
109 register_transport(&pcap_transport);
Jeff Dikef4c57a72006-03-31 02:30:10 -0800110 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Jeff Dike8210fd22006-12-06 20:34:55 -0800113late_initcall(register_pcap);