Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a3c77c67 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds
Browse files

[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: default avatarJeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 98fdffcc
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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)
@@ -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
+2 −21
Original line number Diff line number Diff line
#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;
@@ -12,28 +9,12 @@ struct slip_data {
	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 −0
Original line number Diff line number Diff line
#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;
}
+27 −17
Original line number Diff line number Diff line
/* 
 * 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	*/
@@ -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;
};

/*
 * 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:
 */
#define SLIP_PROTO_INIT { \
	.ibuf  	= { '\0' }, \
	.obuf  	= { '\0' }, \
        .more	= 0, \
	.pos	= 0, \
	.esc	= 0 \
}

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
+6 −6
Original line number Diff line number Diff line
@@ -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);
Loading