blob: 824386974f88902469f2d95713ae9e4bf6a2928f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 * James Leu (jleu@mindspring.net).
4 * Copyright (C) 2001 by various other people who didn't put their name here.
5 * Licensed under the GPL.
6 */
7
8#include "linux/kernel.h"
9#include "linux/init.h"
10#include "linux/netdevice.h"
11#include "linux/etherdevice.h"
12#include "net_kern.h"
13#include "net_user.h"
14#include "daemon.h"
15
16struct daemon_init {
17 char *sock_type;
18 char *ctl_sock;
19};
20
Paolo 'Blaisorblade' Giarrusso42947cb2006-02-01 03:06:29 -080021static void daemon_init(struct net_device *dev, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
23 struct uml_net_private *pri;
24 struct daemon_data *dpri;
25 struct daemon_init *init = data;
26
27 pri = dev->priv;
28 dpri = (struct daemon_data *) pri->user;
29 dpri->sock_type = init->sock_type;
30 dpri->ctl_sock = init->ctl_sock;
31 dpri->fd = -1;
32 dpri->control = -1;
33 dpri->dev = dev;
Paolo 'Blaisorblade' Giarrussoc42791b2006-01-18 17:42:53 -080034 /* We will free this pointer. If it contains crap we're burned. */
35 dpri->ctl_addr = NULL;
36 dpri->data_addr = NULL;
37 dpri->local_addr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39 printk("daemon backend (uml_switch version %d) - %s:%s",
40 SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
41 printk("\n");
42}
43
44static int daemon_read(int fd, struct sk_buff **skb,
45 struct uml_net_private *lp)
46{
47 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
48 if(*skb == NULL) return(-ENOMEM);
49 return(net_recvfrom(fd, (*skb)->mac.raw,
50 (*skb)->dev->mtu + ETH_HEADER_OTHER));
51}
52
53static int daemon_write(int fd, struct sk_buff **skb,
54 struct uml_net_private *lp)
55{
56 return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
57 (struct daemon_data *) &lp->user));
58}
59
Jeff Dike5e7672e2006-09-27 01:50:33 -070060static const struct net_kern_info daemon_kern_info = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 .init = daemon_init,
62 .protocol = eth_protocol,
63 .read = daemon_read,
64 .write = daemon_write,
65};
66
Paolo 'Blaisorblade' Giarrusso42947cb2006-02-01 03:06:29 -080067static int daemon_setup(char *str, char **mac_out, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 struct daemon_init *init = data;
70 char *remain;
71
72 *init = ((struct daemon_init)
73 { .sock_type = "unix",
74 .ctl_sock = "/tmp/uml.ctl" });
75
76 remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
77 NULL);
78 if(remain != NULL)
79 printk(KERN_WARNING "daemon_setup : Ignoring data socket "
80 "specification\n");
81
82 return(1);
83}
84
85static struct transport daemon_transport = {
86 .list = LIST_HEAD_INIT(daemon_transport.list),
87 .name = "daemon",
88 .setup = daemon_setup,
89 .user = &daemon_user_info,
90 .kern = &daemon_kern_info,
91 .private_size = sizeof(struct daemon_data),
92 .setup_size = sizeof(struct daemon_init),
93};
94
95static int register_daemon(void)
96{
97 register_transport(&daemon_transport);
Jeff Dikef4c57a72006-03-31 02:30:10 -080098 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101__initcall(register_daemon);