diff options
author | Jeff Dike <jdike@addtoit.com> | 2005-06-13 18:52:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-13 23:58:43 -0400 |
commit | a3c77c67a443e631febf708bb0c376caede31657 (patch) | |
tree | 75672c8dec41054de7b635df59a9f014f6a5ad14 /arch/um/drivers/slip_user.c | |
parent | 98fdffccea6cc3fe9dba32c0fcc310bcb5d71529 (diff) |
[PATCH] uml: slirp and slip driver cleanups and fixes
This patch merges a lot of duplicated code in the slip and slirp drivers,
abstracts out the slip protocol, and makes the slip driver work in 2.6.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/drivers/slip_user.c')
-rw-r--r-- | arch/um/drivers/slip_user.c | 152 |
1 files changed, 63 insertions, 89 deletions
diff --git a/arch/um/drivers/slip_user.c b/arch/um/drivers/slip_user.c index d94846b1b4cf..71af444e591f 100644 --- a/arch/um/drivers/slip_user.c +++ b/arch/um/drivers/slip_user.c | |||
@@ -13,7 +13,7 @@ | |||
13 | #include "user.h" | 13 | #include "user.h" |
14 | #include "net_user.h" | 14 | #include "net_user.h" |
15 | #include "slip.h" | 15 | #include "slip.h" |
16 | #include "slip_proto.h" | 16 | #include "slip_common.h" |
17 | #include "helper.h" | 17 | #include "helper.h" |
18 | #include "os.h" | 18 | #include "os.h" |
19 | 19 | ||
@@ -77,41 +77,51 @@ static int slip_tramp(char **argv, int fd) | |||
77 | err = os_pipe(fds, 1, 0); | 77 | err = os_pipe(fds, 1, 0); |
78 | if(err < 0){ | 78 | if(err < 0){ |
79 | printk("slip_tramp : pipe failed, err = %d\n", -err); | 79 | printk("slip_tramp : pipe failed, err = %d\n", -err); |
80 | return(err); | 80 | goto out; |
81 | } | 81 | } |
82 | 82 | ||
83 | err = 0; | 83 | err = 0; |
84 | pe_data.stdin = fd; | 84 | pe_data.stdin = fd; |
85 | pe_data.stdout = fds[1]; | 85 | pe_data.stdout = fds[1]; |
86 | pe_data.close_me = fds[0]; | 86 | pe_data.close_me = fds[0]; |
87 | pid = run_helper(slip_pre_exec, &pe_data, argv, NULL); | 87 | err = run_helper(slip_pre_exec, &pe_data, argv, NULL); |
88 | if(err < 0) | ||
89 | goto out_close; | ||
90 | pid = err; | ||
91 | |||
92 | output_len = page_size(); | ||
93 | output = um_kmalloc(output_len); | ||
94 | if(output == NULL){ | ||
95 | printk("slip_tramp : failed to allocate output buffer\n"); | ||
96 | os_kill_process(pid, 1); | ||
97 | err = -ENOMEM; | ||
98 | goto out_free; | ||
99 | } | ||
88 | 100 | ||
89 | if(pid < 0) err = pid; | 101 | os_close_file(fds[1]); |
90 | else { | 102 | read_output(fds[0], output, output_len); |
91 | output_len = page_size(); | 103 | printk("%s", output); |
92 | output = um_kmalloc(output_len); | 104 | |
93 | if(output == NULL) | 105 | CATCH_EINTR(err = waitpid(pid, &status, 0)); |
94 | printk("slip_tramp : failed to allocate output " | 106 | if(err < 0) |
95 | "buffer\n"); | 107 | err = errno; |
96 | 108 | else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ | |
97 | os_close_file(fds[1]); | 109 | printk("'%s' didn't exit with status 0\n", argv[0]); |
98 | read_output(fds[0], output, output_len); | 110 | err = -EINVAL; |
99 | if(output != NULL){ | ||
100 | printk("%s", output); | ||
101 | kfree(output); | ||
102 | } | ||
103 | CATCH_EINTR(err = waitpid(pid, &status, 0)); | ||
104 | if(err < 0) | ||
105 | err = errno; | ||
106 | else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ | ||
107 | printk("'%s' didn't exit with status 0\n", argv[0]); | ||
108 | err = -EINVAL; | ||
109 | } | ||
110 | } | 111 | } |
112 | else err = 0; | ||
111 | 113 | ||
112 | os_close_file(fds[0]); | 114 | os_close_file(fds[0]); |
113 | 115 | ||
114 | return(err); | 116 | out_free: |
117 | kfree(output); | ||
118 | return err; | ||
119 | |||
120 | out_close: | ||
121 | os_close_file(fds[0]); | ||
122 | os_close_file(fds[1]); | ||
123 | out: | ||
124 | return err; | ||
115 | } | 125 | } |
116 | 126 | ||
117 | static int slip_open(void *data) | 127 | static int slip_open(void *data) |
@@ -123,21 +133,26 @@ static int slip_open(void *data) | |||
123 | NULL }; | 133 | NULL }; |
124 | int sfd, mfd, err; | 134 | int sfd, mfd, err; |
125 | 135 | ||
126 | mfd = get_pty(); | 136 | err = get_pty(); |
127 | if(mfd < 0){ | 137 | if(err < 0){ |
128 | printk("umn : Failed to open pty, err = %d\n", -mfd); | 138 | printk("slip-open : Failed to open pty, err = %d\n", -err); |
129 | return(mfd); | 139 | goto out; |
130 | } | 140 | } |
131 | sfd = os_open_file(ptsname(mfd), of_rdwr(OPENFLAGS()), 0); | 141 | mfd = err; |
132 | if(sfd < 0){ | 142 | |
133 | printk("Couldn't open tty for slip line, err = %d\n", -sfd); | 143 | err = os_open_file(ptsname(mfd), of_rdwr(OPENFLAGS()), 0); |
134 | os_close_file(mfd); | 144 | if(err < 0){ |
135 | return(sfd); | 145 | printk("Couldn't open tty for slip line, err = %d\n", -err); |
146 | goto out_close; | ||
136 | } | 147 | } |
137 | if(set_up_tty(sfd)) return(-1); | 148 | sfd = err; |
149 | |||
150 | if(set_up_tty(sfd)) | ||
151 | goto out_close2; | ||
152 | |||
138 | pri->slave = sfd; | 153 | pri->slave = sfd; |
139 | pri->pos = 0; | 154 | pri->slip.pos = 0; |
140 | pri->esc = 0; | 155 | pri->slip.esc = 0; |
141 | if(pri->gate_addr != NULL){ | 156 | if(pri->gate_addr != NULL){ |
142 | sprintf(version_buf, "%d", UML_NET_VERSION); | 157 | sprintf(version_buf, "%d", UML_NET_VERSION); |
143 | strcpy(gate_buf, pri->gate_addr); | 158 | strcpy(gate_buf, pri->gate_addr); |
@@ -146,12 +161,12 @@ static int slip_open(void *data) | |||
146 | 161 | ||
147 | if(err < 0){ | 162 | if(err < 0){ |
148 | printk("slip_tramp failed - err = %d\n", -err); | 163 | printk("slip_tramp failed - err = %d\n", -err); |
149 | return(err); | 164 | goto out_close2; |
150 | } | 165 | } |
151 | err = os_get_ifname(pri->slave, pri->name); | 166 | err = os_get_ifname(pri->slave, pri->name); |
152 | if(err < 0){ | 167 | if(err < 0){ |
153 | printk("get_ifname failed, err = %d\n", -err); | 168 | printk("get_ifname failed, err = %d\n", -err); |
154 | return(err); | 169 | goto out_close2; |
155 | } | 170 | } |
156 | iter_addresses(pri->dev, open_addr, pri->name); | 171 | iter_addresses(pri->dev, open_addr, pri->name); |
157 | } | 172 | } |
@@ -160,10 +175,16 @@ static int slip_open(void *data) | |||
160 | if(err < 0){ | 175 | if(err < 0){ |
161 | printk("Failed to set slip discipline encapsulation - " | 176 | printk("Failed to set slip discipline encapsulation - " |
162 | "err = %d\n", -err); | 177 | "err = %d\n", -err); |
163 | return(err); | 178 | goto out_close2; |
164 | } | 179 | } |
165 | } | 180 | } |
166 | return(mfd); | 181 | return(mfd); |
182 | out_close2: | ||
183 | os_close_file(sfd); | ||
184 | out_close: | ||
185 | os_close_file(mfd); | ||
186 | out: | ||
187 | return err; | ||
167 | } | 188 | } |
168 | 189 | ||
169 | static void slip_close(int fd, void *data) | 190 | static void slip_close(int fd, void *data) |
@@ -190,48 +211,12 @@ static void slip_close(int fd, void *data) | |||
190 | 211 | ||
191 | int slip_user_read(int fd, void *buf, int len, struct slip_data *pri) | 212 | int slip_user_read(int fd, void *buf, int len, struct slip_data *pri) |
192 | { | 213 | { |
193 | int i, n, size, start; | 214 | return slip_proto_read(fd, buf, len, &pri->slip); |
194 | |||
195 | if(pri->more>0) { | ||
196 | i = 0; | ||
197 | while(i < pri->more) { | ||
198 | size = slip_unesc(pri->ibuf[i++], | ||
199 | pri->ibuf, &pri->pos, &pri->esc); | ||
200 | if(size){ | ||
201 | memcpy(buf, pri->ibuf, size); | ||
202 | memmove(pri->ibuf, &pri->ibuf[i], pri->more-i); | ||
203 | pri->more=pri->more-i; | ||
204 | return(size); | ||
205 | } | ||
206 | } | ||
207 | pri->more=0; | ||
208 | } | ||
209 | |||
210 | n = net_read(fd, &pri->ibuf[pri->pos], sizeof(pri->ibuf) - pri->pos); | ||
211 | if(n <= 0) return(n); | ||
212 | |||
213 | start = pri->pos; | ||
214 | for(i = 0; i < n; i++){ | ||
215 | size = slip_unesc(pri->ibuf[start + i], | ||
216 | pri->ibuf, &pri->pos, &pri->esc); | ||
217 | if(size){ | ||
218 | memcpy(buf, pri->ibuf, size); | ||
219 | memmove(pri->ibuf, &pri->ibuf[start+i+1], n-(i+1)); | ||
220 | pri->more=n-(i+1); | ||
221 | return(size); | ||
222 | } | ||
223 | } | ||
224 | return(0); | ||
225 | } | 215 | } |
226 | 216 | ||
227 | int slip_user_write(int fd, void *buf, int len, struct slip_data *pri) | 217 | int slip_user_write(int fd, void *buf, int len, struct slip_data *pri) |
228 | { | 218 | { |
229 | int actual, n; | 219 | return slip_proto_write(fd, buf, len, &pri->slip); |
230 | |||
231 | actual = slip_esc(buf, pri->obuf, len); | ||
232 | n = net_write(fd, pri->obuf, actual); | ||
233 | if(n < 0) return(n); | ||
234 | else return(len); | ||
235 | } | 220 | } |
236 | 221 | ||
237 | static int slip_set_mtu(int mtu, void *data) | 222 | static int slip_set_mtu(int mtu, void *data) |
@@ -267,14 +252,3 @@ struct net_user_info slip_user_info = { | |||
267 | .delete_address = slip_del_addr, | 252 | .delete_address = slip_del_addr, |
268 | .max_packet = BUF_SIZE | 253 | .max_packet = BUF_SIZE |
269 | }; | 254 | }; |
270 | |||
271 | /* | ||
272 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
273 | * Emacs will notice this stuff at the end of the file and automatically | ||
274 | * adjust the settings for this buffer only. This must remain at the end | ||
275 | * of the file. | ||
276 | * --------------------------------------------------------------------------- | ||
277 | * Local variables: | ||
278 | * c-file-style: "linux" | ||
279 | * End: | ||
280 | */ | ||