blob: d987af277db9d8f1cc943aa72ab46201e57cbb58 [file] [log] [blame]
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07001/*
2 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL.
4 */
5
6#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include "linux/init.h"
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07008#include <linux/netdevice.h>
9#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include "net_kern.h"
11#include "net_user.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "slirp.h"
13
14struct slirp_init {
15 struct arg_list_dummy_wrapper argw; /* XXX should be simpler... */
16};
17
18void slirp_init(struct net_device *dev, void *data)
19{
20 struct uml_net_private *private;
21 struct slirp_data *spri;
22 struct slirp_init *init = data;
23 int i;
24
25 private = dev->priv;
26 spri = (struct slirp_data *) private->user;
Paolo 'Blaisorblade' Giarrusso854e9812006-02-01 03:06:25 -080027
28 spri->argw = init->argw;
29 spri->pid = -1;
30 spri->slave = -1;
31 spri->dev = dev;
32
33 slip_proto_init(&spri->slip);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 dev->init = NULL;
36 dev->hard_header_len = 0;
Jeff Dikebe8ad5a2007-10-17 19:35:04 -070037 dev->header_ops = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 dev->addr_len = 0;
39 dev->type = ARPHRD_SLIP;
40 dev->tx_queue_len = 256;
41 dev->flags = IFF_NOARP;
42 printk("SLIRP backend - command line:");
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070043 for (i = 0; spri->argw.argv[i] != NULL; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 printk(" '%s'",spri->argw.argv[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 printk("\n");
46}
47
48static unsigned short slirp_protocol(struct sk_buff *skbuff)
49{
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070050 return htons(ETH_P_IP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Jeff Dikeb53f35a2007-10-16 01:27:31 -070053static int slirp_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Jeff Dikeb53f35a2007-10-16 01:27:31 -070055 return slirp_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
56 (struct slirp_data *) &lp->user);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Jeff Dikeb53f35a2007-10-16 01:27:31 -070059static int slirp_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Jeff Dikeb53f35a2007-10-16 01:27:31 -070061 return slirp_user_write(fd, skb->data, skb->len,
62 (struct slirp_data *) &lp->user);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Jeff Dike5e7672e2006-09-27 01:50:33 -070065const struct net_kern_info slirp_kern_info = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 .init = slirp_init,
67 .protocol = slirp_protocol,
68 .read = slirp_read,
69 .write = slirp_write,
70};
71
72static int slirp_setup(char *str, char **mac_out, void *data)
73{
74 struct slirp_init *init = data;
75 int i=0;
76
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070077 *init = ((struct slirp_init) { .argw = { { "slirp", NULL } } });
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 str = split_if_spec(str, mac_out, NULL);
80
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070081 if (str == NULL) /* no command line given after MAC addr */
82 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 do {
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070085 if (i >= SLIRP_MAX_ARGS - 1) {
86 printk(KERN_WARNING "slirp_setup: truncating slirp "
87 "arguments\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 break;
89 }
90 init->argw.argv[i++] = str;
91 while(*str && *str!=',') {
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070092 if (*str == '_')
93 *str=' ';
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 str++;
95 }
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070096 if (*str != ',')
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 break;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070098 *str++ = '\0';
99 } while (1);
100
101 init->argw.argv[i] = NULL;
102 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105static struct transport slirp_transport = {
106 .list = LIST_HEAD_INIT(slirp_transport.list),
107 .name = "slirp",
108 .setup = slirp_setup,
109 .user = &slirp_user_info,
110 .kern = &slirp_kern_info,
111 .private_size = sizeof(struct slirp_data),
112 .setup_size = sizeof(struct slirp_init),
113};
114
115static int register_slirp(void)
116{
117 register_transport(&slirp_transport);
Jeff Dikef4c57a72006-03-31 02:30:10 -0800118 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
Jeff Dike8210fd22006-12-06 20:34:55 -0800121late_initcall(register_slirp);