Skip to content

Commit

Permalink
[PATCH] uml: slirp and slip driver cleanups and fixes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff Dike authored and Linus Torvalds committed Jun 14, 2005
1 parent 98fdffc commit a3c77c6
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 245 deletions.
6 changes: 3 additions & 3 deletions arch/um/drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ obj-y := stdio_console.o fd.o chan_kern.o chan_user.o line.o
obj-$(CONFIG_SSL) += ssl.o
obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o

obj-$(CONFIG_UML_NET_SLIP) += slip.o
obj-$(CONFIG_UML_NET_SLIRP) += slirp.o
obj-$(CONFIG_UML_NET_SLIP) += slip.o slip_common.o
obj-$(CONFIG_UML_NET_SLIRP) += slirp.o slip_common.o
obj-$(CONFIG_UML_NET_DAEMON) += daemon.o
obj-$(CONFIG_UML_NET_MCAST) += mcast.o
#obj-$(CONFIG_UML_NET_PCAP) += pcap.o $(PCAP)
Expand All @@ -41,6 +41,6 @@ obj-$(CONFIG_UML_WATCHDOG) += harddog.o
obj-$(CONFIG_BLK_DEV_COW_COMMON) += cow_user.o
obj-$(CONFIG_UML_RANDOM) += random.o

USER_OBJS := fd.o null.o pty.o tty.o xterm.o
USER_OBJS := fd.o null.o pty.o tty.o xterm.o slip_common.o

include arch/um/scripts/Makefile.rules
23 changes: 2 additions & 21 deletions arch/um/drivers/slip.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
#ifndef __UM_SLIP_H
#define __UM_SLIP_H

#define BUF_SIZE 1500
/* two bytes each for a (pathological) max packet of escaped chars + *
* terminating END char + initial END char */
#define ENC_BUF_SIZE (2 * BUF_SIZE + 2)
#include "slip_common.h"

struct slip_data {
void *dev;
char name[sizeof("slnnnnn\0")];
char *addr;
char *gate_addr;
int slave;
unsigned char ibuf[ENC_BUF_SIZE];
unsigned char obuf[ENC_BUF_SIZE];
int more; /* more data: do not read fd until ibuf has been drained */
int pos;
int esc;
struct slip_proto slip;
};

extern struct net_user_info slip_user_info;

extern int set_umn_addr(int fd, char *addr, char *ptp_addr);
extern int slip_user_read(int fd, void *buf, int len, struct slip_data *pri);
extern int slip_user_write(int fd, void *buf, int len, struct slip_data *pri);

#endif

/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
54 changes: 54 additions & 0 deletions arch/um/drivers/slip_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <string.h>
#include "slip_common.h"
#include "net_user.h"

int slip_proto_read(int fd, void *buf, int len, struct slip_proto *slip)
{
int i, n, size, start;

if(slip->more > 0){
i = 0;
while(i < slip->more){
size = slip_unesc(slip->ibuf[i++], slip->ibuf,
&slip->pos, &slip->esc);
if(size){
memcpy(buf, slip->ibuf, size);
memmove(slip->ibuf, &slip->ibuf[i],
slip->more - i);
slip->more = slip->more - i;
return size;
}
}
slip->more = 0;
}

n = net_read(fd, &slip->ibuf[slip->pos],
sizeof(slip->ibuf) - slip->pos);
if(n <= 0)
return n;

start = slip->pos;
for(i = 0; i < n; i++){
size = slip_unesc(slip->ibuf[start + i], slip->ibuf,&slip->pos,
&slip->esc);
if(size){
memcpy(buf, slip->ibuf, size);
memmove(slip->ibuf, &slip->ibuf[start+i+1],
n - (i + 1));
slip->more = n - (i + 1);
return size;
}
}
return 0;
}

int slip_proto_write(int fd, void *buf, int len, struct slip_proto *slip)
{
int actual, n;

actual = slip_esc(buf, slip->obuf, len);
n = net_write(fd, slip->obuf, actual);
if(n < 0)
return n;
else return len;
}
44 changes: 27 additions & 17 deletions arch/um/drivers/slip_proto.h → arch/um/drivers/slip_common.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __UM_SLIP_COMMON_H
#define __UM_SLIP_COMMON_H

#ifndef __UM_SLIP_PROTO_H__
#define __UM_SLIP_PROTO_H__
#define BUF_SIZE 1500
/* two bytes each for a (pathological) max packet of escaped chars + *
* terminating END char + initial END char */
#define ENC_BUF_SIZE (2 * BUF_SIZE + 2)

/* SLIP protocol characters. */
#define SLIP_END 0300 /* indicates end of frame */
Expand Down Expand Up @@ -80,15 +80,25 @@ static inline int slip_esc(unsigned char *s, unsigned char *d, int len)
return (ptr - d);
}

#endif
struct slip_proto {
unsigned char ibuf[ENC_BUF_SIZE];
unsigned char obuf[ENC_BUF_SIZE];
int more; /* more data: do not read fd until ibuf has been drained */
int pos;
int esc;
};

#define SLIP_PROTO_INIT { \
.ibuf = { '\0' }, \
.obuf = { '\0' }, \
.more = 0, \
.pos = 0, \
.esc = 0 \
}

/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
extern int slip_proto_read(int fd, void *buf, int len,
struct slip_proto *slip);
extern int slip_proto_write(int fd, void *buf, int len,
struct slip_proto *slip);

#endif
12 changes: 6 additions & 6 deletions arch/um/drivers/slip_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ void slip_init(struct net_device *dev, void *data)
.addr = NULL,
.gate_addr = init->gate_addr,
.slave = -1,
.ibuf = { '\0' },
.obuf = { '\0' },
.pos = 0,
.esc = 0,
.slip = SLIP_PROTO_INIT,
.dev = dev });

dev->init = NULL;
dev->header_cache_update = NULL;
dev->hard_header_cache = NULL;
dev->hard_header = NULL;
dev->hard_header_len = 0;
dev->addr_len = 4;
dev->type = ARPHRD_ETHER;
dev->addr_len = 0;
dev->type = ARPHRD_SLIP;
dev->tx_queue_len = 256;
dev->flags = IFF_NOARP;
printk("SLIP backend - SLIP IP = %s\n", spri->gate_addr);
Expand Down
Loading

0 comments on commit a3c77c6

Please sign in to comment.