]>
Commit | Line | Data |
---|---|---|
cd1ae0e4 JD |
1 | /* |
2 | * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) | |
3 | * Licensed under the GPL. | |
4 | */ | |
5 | ||
6 | #include <linux/if_arp.h> | |
1da177e4 | 7 | #include "linux/init.h" |
cd1ae0e4 JD |
8 | #include <linux/netdevice.h> |
9 | #include <linux/string.h> | |
1da177e4 LT |
10 | #include "net_kern.h" |
11 | #include "net_user.h" | |
1da177e4 LT |
12 | #include "slirp.h" |
13 | ||
14 | struct slirp_init { | |
15 | struct arg_list_dummy_wrapper argw; /* XXX should be simpler... */ | |
16 | }; | |
17 | ||
18 | void 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; | |
854e981c PBG |
27 | |
28 | spri->argw = init->argw; | |
29 | spri->pid = -1; | |
30 | spri->slave = -1; | |
31 | spri->dev = dev; | |
32 | ||
33 | slip_proto_init(&spri->slip); | |
1da177e4 LT |
34 | |
35 | dev->init = NULL; | |
36 | dev->hard_header_len = 0; | |
37 | dev->header_cache_update = NULL; | |
38 | dev->hard_header_cache = NULL; | |
39 | dev->hard_header = NULL; | |
40 | dev->addr_len = 0; | |
41 | dev->type = ARPHRD_SLIP; | |
42 | dev->tx_queue_len = 256; | |
43 | dev->flags = IFF_NOARP; | |
44 | printk("SLIRP backend - command line:"); | |
cd1ae0e4 | 45 | for (i = 0; spri->argw.argv[i] != NULL; i++) |
1da177e4 | 46 | printk(" '%s'",spri->argw.argv[i]); |
1da177e4 LT |
47 | printk("\n"); |
48 | } | |
49 | ||
50 | static unsigned short slirp_protocol(struct sk_buff *skbuff) | |
51 | { | |
cd1ae0e4 | 52 | return htons(ETH_P_IP); |
1da177e4 LT |
53 | } |
54 | ||
cd1ae0e4 | 55 | static int slirp_read(int fd, struct sk_buff **skb, |
1da177e4 LT |
56 | struct uml_net_private *lp) |
57 | { | |
cd1ae0e4 JD |
58 | return slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu, |
59 | (struct slirp_data *) &lp->user); | |
1da177e4 LT |
60 | } |
61 | ||
62 | static int slirp_write(int fd, struct sk_buff **skb, | |
63 | struct uml_net_private *lp) | |
64 | { | |
cd1ae0e4 JD |
65 | return slirp_user_write(fd, (*skb)->data, (*skb)->len, |
66 | (struct slirp_data *) &lp->user); | |
1da177e4 LT |
67 | } |
68 | ||
5e7672ec | 69 | const struct net_kern_info slirp_kern_info = { |
1da177e4 LT |
70 | .init = slirp_init, |
71 | .protocol = slirp_protocol, | |
72 | .read = slirp_read, | |
73 | .write = slirp_write, | |
74 | }; | |
75 | ||
76 | static int slirp_setup(char *str, char **mac_out, void *data) | |
77 | { | |
78 | struct slirp_init *init = data; | |
79 | int i=0; | |
80 | ||
cd1ae0e4 | 81 | *init = ((struct slirp_init) { .argw = { { "slirp", NULL } } }); |
1da177e4 LT |
82 | |
83 | str = split_if_spec(str, mac_out, NULL); | |
84 | ||
cd1ae0e4 JD |
85 | if (str == NULL) /* no command line given after MAC addr */ |
86 | return 1; | |
1da177e4 LT |
87 | |
88 | do { | |
cd1ae0e4 JD |
89 | if (i >= SLIRP_MAX_ARGS - 1) { |
90 | printk(KERN_WARNING "slirp_setup: truncating slirp " | |
91 | "arguments\n"); | |
1da177e4 LT |
92 | break; |
93 | } | |
94 | init->argw.argv[i++] = str; | |
95 | while(*str && *str!=',') { | |
cd1ae0e4 JD |
96 | if (*str == '_') |
97 | *str=' '; | |
1da177e4 LT |
98 | str++; |
99 | } | |
cd1ae0e4 | 100 | if (*str != ',') |
1da177e4 | 101 | break; |
cd1ae0e4 JD |
102 | *str++ = '\0'; |
103 | } while (1); | |
104 | ||
105 | init->argw.argv[i] = NULL; | |
106 | return 1; | |
1da177e4 LT |
107 | } |
108 | ||
109 | static struct transport slirp_transport = { | |
110 | .list = LIST_HEAD_INIT(slirp_transport.list), | |
111 | .name = "slirp", | |
112 | .setup = slirp_setup, | |
113 | .user = &slirp_user_info, | |
114 | .kern = &slirp_kern_info, | |
115 | .private_size = sizeof(struct slirp_data), | |
116 | .setup_size = sizeof(struct slirp_init), | |
117 | }; | |
118 | ||
119 | static int register_slirp(void) | |
120 | { | |
121 | register_transport(&slirp_transport); | |
f4c57a78 | 122 | return 0; |
1da177e4 LT |
123 | } |
124 | ||
8210fd2a | 125 | late_initcall(register_slirp); |