diff -Naur -X exclude-files ac_cur/arch/um/drivers/umn_kern.c ac/arch/um/drivers/umn_kern.c --- ac_cur/arch/um/drivers/umn_kern.c Sun Jun 3 18:18:11 2001 +++ ac/arch/um/drivers/umn_kern.c Wed Dec 31 19:00:00 1969 @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include "linux/init.h" -#include "linux/netdevice.h" -#include "linux/skbuff.h" -#include "linux/if_arp.h" -#include "linux/spinlock.h" -#include "umn.h" -#include "user_util.h" -#include "kern.h" -#include "kern_util.h" - -struct umn { - int used; - int tty_fd; - int slave; - int slipno; - int rcount; - int esc; - char rbuff[3000]; - int buffsize; - struct net_device dev; - char *ptp_addr; - spinlock_t lock; -}; - -struct umn umn = { 0, -1, -1, -1, -1, 0, { }, 0, { }, "192.168.0.254", - SPIN_LOCK_UNLOCKED }; - -static int xmit(struct sk_buff *skb, struct net_device *dev) -{ - unsigned long flags; - int ret; - - spin_lock_irqsave(&umn.lock, flags); - ret = umn_send_packet(umn.tty_fd, skb->data, skb->len); - dev_kfree_skb(skb); - spin_unlock_irqrestore(&umn.lock, flags); - return(ret); -} - -void umn_rcv(char *data, int len) -{ - struct sk_buff *skb; - - skb = dev_alloc_skb(len); - memcpy(skb_put(skb, len), data, len); - skb->mac.raw = skb->data; - skb->dev = &umn.dev; - skb->protocol = htons(ETH_P_IP); - netif_rx(skb); -} - -/* SLIP protocol characters. */ -#define END 0300 /* indicates end of frame */ -#define ESC 0333 /* indicates byte stuffing */ -#define ESC_END 0334 /* ESC ESC_END means END 'data' */ -#define ESC_ESC 0335 /* ESC ESC_ESC means ESC 'data' */ - -void slip_unesc(unsigned char s) -{ - - switch(s) { - case END: - if (umn.rcount > 2) { - umn_rcv(umn.rbuff, umn.rcount); - } - umn.esc = 0; - umn.rcount = 0; - return; - - case ESC: - umn.esc = 1; - return; - case ESC_ESC: - if(umn.esc){ - umn.esc = 0; - s = ESC; - } - break; - case ESC_END: - if(umn.esc){ - umn.esc = 0; - s = END; - } - break; - } - if (umn.rcount < umn.buffsize) { - umn.rbuff[umn.rcount++] = s; - return; - } - printk("umn receive overflow\n"); -} - -spinlock_t umn_lock = SPIN_LOCK_UNLOCKED; - -void umn_handler(int irq, void *dev, struct pt_regs *unused) -{ - umn_read(umn.tty_fd); - reactivate_fd(umn.tty_fd); -} - -static int umn_open(struct net_device *dev) -{ - int err; - - spin_lock(&umn_lock); - if(umn.used){ - spin_unlock(&umn_lock); - return(-ENXIO); - } - umn.used = 1; - spin_unlock(&umn_lock); - umn.tty_fd = open_umn_tty(&umn.slave, &umn.slipno); - umn.rcount = 0; - umn.esc = 0; - umn.buffsize = sizeof(umn.rbuff)/sizeof(umn.rbuff[0]); - if((err = um_request_irq(UMN_IRQ, umn.tty_fd, umn_handler, - SA_INTERRUPT, "umn", &umn)) != 0){ - printk("umn_init : request_irq failed - errno = %d\n", -err); - return(err); - } - if(umn.tty_fd == -1) return(-1); - else return(0); -} - -static int umn_close (struct net_device *dev) -{ - spin_lock(&umn_lock); - if(!umn.used){ - spin_unlock(&umn_lock); - return(-ENXIO); - } - umn.used = 0; - spin_unlock(&umn_lock); - close_umn_tty(umn.tty_fd, umn.slave); - free_irq(UMN_IRQ, &umn); - return(0); -} - -static int umn_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) -{ - printk("umn ioctl = %d\n", cmd); - if((cmd >= SIOCDEVPRIVATE) && (cmd <= SIOCDEVPRIVATE + 15)) - return(-EOPNOTSUPP); - return(-EOPNOTSUPP); -} - -static int set_addr(struct net_device *dev, void *addr) -{ - struct sockaddr *sa; - char in_addr[sizeof("255.255.255.255")]; - unsigned char *eth_addr; - - sa = addr; - eth_addr = (unsigned char *) sa->sa_data; - sprintf(in_addr, "%d.%d.%d.%d", eth_addr[0], eth_addr[1], - eth_addr[2], eth_addr[3]); - return(set_umn_addr(umn.slave, in_addr, umn.ptp_addr)); -} - -static int init_dev(struct net_device *dev) -{ - dev->mtu = 1500; - dev->hard_start_xmit = xmit; - dev->open = umn_open; - dev->stop = umn_close; - dev->get_stats = NULL; - dev->do_ioctl = umn_ioctl; - dev->hard_header_len = 0; - dev->addr_len = 4; - dev->type = ARPHRD_ETHER; - dev->tx_queue_len = 256; - dev->set_mac_address = set_addr; - dev_init_buffers(dev); - dev->flags = IFF_NOARP; - return 0; -} - -int __init umn_init(void) -{ - struct net_device *d; - - d = &umn.dev; - strncpy(d->name, "umn", IFNAMSIZ); - d->init = init_dev; - if(register_netdev(d)) - printk("Couldn't initialize umn\n"); - return(0); -} - -__initcall(umn_init); - -static int umn_setup(char *str) -{ - if(*str++ != '='){ - printk("umn_setup : Expected '='\n"); - return(1); - } - umn.ptp_addr = str; - return(1); -} - -__setup("umn", umn_setup); - -/* - * 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: - */ diff -Naur -X exclude-files ac_cur/arch/um/drivers/umn_user.c ac/arch/um/drivers/umn_user.c --- ac_cur/arch/um/drivers/umn_user.c Sun Jun 3 18:18:11 2001 +++ ac/arch/um/drivers/umn_user.c Wed Dec 31 19:00:00 1969 @@ -1,278 +0,0 @@ -/* - * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "umn.h" -#include "user_util.h" -#include "kern_util.h" -#include "user.h" - -char in_buff[3000]; -char out_buff[3000]; - -/* SLIP protocol characters. */ -#define END 0300 /* indicates end of frame */ -#define ESC 0333 /* indicates byte stuffing */ -#define ESC_END 0334 /* ESC ESC_END means END 'data' */ -#define ESC_ESC 0335 /* ESC ESC_ESC means ESC 'data' */ - -static int slip_esc(unsigned char *s, unsigned char *d, int len) -{ - unsigned char *ptr = d; - unsigned char c; - - /* - * Send an initial END character to flush out any - * data that may have accumulated in the receiver - * due to line noise. - */ - - *ptr++ = END; - - /* - * For each byte in the packet, send the appropriate - * character sequence, according to the SLIP protocol. - */ - - while (len-- > 0) { - switch(c = *s++) { - case END: - *ptr++ = ESC; - *ptr++ = ESC_END; - break; - case ESC: - *ptr++ = ESC; - *ptr++ = ESC_ESC; - break; - default: - *ptr++ = c; - break; - } - } - *ptr++ = END; - return (ptr - d); -} - -int umn_send_packet(int fd, void *data, int len) -{ - int actual, n; - - actual = slip_esc(data, out_buff, len); - n = write(fd, out_buff, actual); - if(n == actual) return(0); - else return(1); -} - -void umn_read(int fd) -{ - int i, n; - - while(1){ - n = read(fd, in_buff, sizeof(in_buff)/sizeof(in_buff[0])); - if(n == 0) printk("umn_read hit EOF\n"); - else if(n < 0){ - if(errno == EIO){ - close(fd); - return; - } - else if((errno == EBADF) || (errno == EAGAIN)) return; - printk("umn_read had error, errno = %d\n", errno); - } - else { - for(i=0;itramp_arg, error[256]; - - execvp(argv[0], argv); - sprintf(error, "exec of %s failed, errno = %d\n", argv[0], errno); - write(args->fd, error, strlen(error)); - return(1); -} - -static int run_ifconfig(char *prog, void *args, char *error_out, - int error_len) -{ - unsigned long stack; - int pid, status, fds[2], n; - struct helper_arg arg; - - stack = alloc_stack(); - pipe(fds); - arg.tramp_arg = args; - arg.fd = fds[1]; - pid = clone(ifconfig_addr_tramp, (void *) stack_sp(stack), SIGCHLD, - &arg); - close(fds[1]); - if(pid < 0){ - printk("clone of \"%s\" failed\n", prog); - return(-1); - } - pid = waitpid(pid, &status, 0); - n = read(fds[0], error_out, error_len - 1); - error_out[n] = '\0'; - if(pid < 0){ - printk("wait for \"%s\" failed - errno = %d\n", prog, errno); - return(-1); - } - if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ - close(fds[0]); - return(-1); - } - close(fds[0]); - free_stack(stack); - return(0); -} - -int open_umn_tty(int *slave_out, int *slipno_out) -{ - int sfd, mfd; - - if((mfd = get_pty()) < 0){ - printk("umn : Failed to open pty\n"); - return(-1); - } - if((sfd = open(ptsname(mfd), O_RDWR)) < 0){ - printk("Couldn't open tty for slip line\n"); - return(-1); - } - if(set_up_tty(sfd)) return(-1); - *slave_out = sfd; - return(mfd); -} - -int slipify(int fd) -{ - int disc, sencap, n; - - disc = N_SLIP; - sencap = 0; - if((n = ioctl(fd, TIOCSETD, &disc)) < 0){ - printk("Failed to set slip line discipline - errno = %d\n", - errno); - return(-1); - } - if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0){ - printk("Couldn't set slip encapsulation - errno = %d\n", - errno); - return(-1); - } - return(n); -} - -int set_umn_addr(int fd, char *addr, char *ptp_addr) -{ - char slip_name[sizeof("slxxxx")], fd_name[sizeof("nnnnn")]; - char errors[3][256]; - char *helper_args[] = { "umn_helper", fd_name, ptp_addr, addr, - NULL }; - char *ifconfig_args[] = { "um_ifconfig", slip_name, ptp_addr, - "pointopoint", addr, "up", NULL }; - int slipno; - - sprintf(fd_name, "%d", fd); - - /* Try running umn_helper first */ - if(!run_ifconfig(helper_args[0], helper_args, errors[0], - sizeof(errors[0]))) - return(0); - - /* Then try setting up slip ourselves and then ifconfiging it - * with the old setuid ifconfig - this is for old 2.2 systems - * that don't have the current permissions checking in the slip - * driver. - */ - slipno = slipify(fd); - sprintf(slip_name, "sl%d", slipno); - if((slipno != -1) && - !run_ifconfig(ifconfig_args[0], ifconfig_args, errors[1], - sizeof(errors[1]))) - return(0); - - /* Now the only hope is that we're running as root and then we - * can run ifconfig directly - */ - if(getuid() == 0){ - ifconfig_args[0] = "ifconfig"; - if(!run_ifconfig(ifconfig_args[0], ifconfig_args, errors[2], - sizeof(errors[2]))) - return(0); - } - else errors[2][0] = '\0'; - printk("umn - umn_helper failed : %s\n", errors[0]); - printk("umn - um_ifconfig failed : %s\n", errors[1]); - if(errors[2][0] != '\0'){ - printk("umn - ifconfig failed : %s\n", errors[2]); - } - return(1); -} - -void close_umn_tty(int master, int slave) -{ - close(slave); - close(master); -} - -/* - * 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: - */