Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 2 | * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * James Leu (jleu@mindspring.net). |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 4 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 2001 by various other people who didn't put their name here. |
| 6 | * Licensed under the GPL. |
| 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "linux/init.h" |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "net_kern.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "daemon.h" |
| 13 | |
| 14 | struct daemon_init { |
| 15 | char *sock_type; |
| 16 | char *ctl_sock; |
| 17 | }; |
| 18 | |
Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 19 | static void daemon_init(struct net_device *dev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | { |
| 21 | struct uml_net_private *pri; |
| 22 | struct daemon_data *dpri; |
| 23 | struct daemon_init *init = data; |
| 24 | |
| 25 | pri = dev->priv; |
| 26 | dpri = (struct daemon_data *) pri->user; |
| 27 | dpri->sock_type = init->sock_type; |
| 28 | dpri->ctl_sock = init->ctl_sock; |
| 29 | dpri->fd = -1; |
| 30 | dpri->control = -1; |
| 31 | dpri->dev = dev; |
Paolo 'Blaisorblade' Giarrusso | c42791b | 2006-01-18 17:42:53 -0800 | [diff] [blame] | 32 | /* We will free this pointer. If it contains crap we're burned. */ |
| 33 | dpri->ctl_addr = NULL; |
| 34 | dpri->data_addr = NULL; |
| 35 | dpri->local_addr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 37 | printk("daemon backend (uml_switch version %d) - %s:%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock); |
| 39 | printk("\n"); |
| 40 | } |
| 41 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 42 | static int daemon_read(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 44 | return net_recvfrom(fd, skb_mac_header(skb), |
| 45 | skb->dev->mtu + ETH_HEADER_OTHER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 48 | static int daemon_write(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 50 | return daemon_user_write(fd, skb->data, skb->len, |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 51 | (struct daemon_data *) &lp->user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 54 | static const struct net_kern_info daemon_kern_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .init = daemon_init, |
| 56 | .protocol = eth_protocol, |
| 57 | .read = daemon_read, |
| 58 | .write = daemon_write, |
| 59 | }; |
| 60 | |
Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 61 | static int daemon_setup(char *str, char **mac_out, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | struct daemon_init *init = data; |
| 64 | char *remain; |
| 65 | |
| 66 | *init = ((struct daemon_init) |
| 67 | { .sock_type = "unix", |
| 68 | .ctl_sock = "/tmp/uml.ctl" }); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock, |
| 71 | NULL); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 72 | if (remain != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | printk(KERN_WARNING "daemon_setup : Ignoring data socket " |
| 74 | "specification\n"); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 75 | |
| 76 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static struct transport daemon_transport = { |
| 80 | .list = LIST_HEAD_INIT(daemon_transport.list), |
| 81 | .name = "daemon", |
| 82 | .setup = daemon_setup, |
| 83 | .user = &daemon_user_info, |
| 84 | .kern = &daemon_kern_info, |
| 85 | .private_size = sizeof(struct daemon_data), |
| 86 | .setup_size = sizeof(struct daemon_init), |
| 87 | }; |
| 88 | |
| 89 | static int register_daemon(void) |
| 90 | { |
| 91 | register_transport(&daemon_transport); |
Jeff Dike | f4c57a7 | 2006-03-31 02:30:10 -0800 | [diff] [blame] | 92 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Jeff Dike | 8210fd2 | 2006-12-06 20:34:55 -0800 | [diff] [blame] | 95 | late_initcall(register_daemon); |