diff options
author | Jeff Dike <jdike@addtoit.com> | 2007-10-16 01:27:29 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-16 09:43:08 -0700 |
commit | cd1ae0e49bdd814cfaa2e5ab28cff21a30e20085 (patch) | |
tree | 1b993b9de4cb9a8578022a4014063c3e87ec996e /arch/um/os-Linux | |
parent | 1a80521990a0e30e61a92994a009adc52161b070 (diff) | |
download | blackbird-op-linux-cd1ae0e49bdd814cfaa2e5ab28cff21a30e20085.tar.gz blackbird-op-linux-cd1ae0e49bdd814cfaa2e5ab28cff21a30e20085.zip |
uml: network formatting
Style and other non-functional changes in the UML networking code, including
include tidying
style violations
copyright updates
printks getting severities
userspace code calling libc directly rather than using the os_*
wrappers
There's also a exit path cleanup in the pcap driver.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r-- | arch/um/os-Linux/drivers/etap.h | 16 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/ethertap_kern.c | 36 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/ethertap_user.c | 86 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/tuntap.h | 13 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/tuntap_kern.c | 34 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/tuntap_user.c | 75 |
6 files changed, 123 insertions, 137 deletions
diff --git a/arch/um/os-Linux/drivers/etap.h b/arch/um/os-Linux/drivers/etap.h index 57ecdaf2f67e..ddffd41c3f3f 100644 --- a/arch/um/os-Linux/drivers/etap.h +++ b/arch/um/os-Linux/drivers/etap.h @@ -1,8 +1,11 @@ /* - * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ +#ifndef __DRIVERS_ETAP_H +#define __DRIVERS_ETAP_H + #include "net_user.h" struct ethertap_data { @@ -15,13 +18,4 @@ struct ethertap_data { extern const struct net_user_info ethertap_user_info; -/* - * 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: - */ +#endif diff --git a/arch/um/os-Linux/drivers/ethertap_kern.c b/arch/um/os-Linux/drivers/ethertap_kern.c index 12689141414d..542bcc58354c 100644 --- a/arch/um/os-Linux/drivers/ethertap_kern.c +++ b/arch/um/os-Linux/drivers/ethertap_kern.c @@ -1,16 +1,15 @@ /* - * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and * James Leu (jleu@mindspring.net). + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Copyright (C) 2001 by various other people who didn't put their name here. * Licensed under the GPL. */ #include "linux/init.h" -#include "linux/netdevice.h" -#include "linux/etherdevice.h" -#include "net_kern.h" -#include "net_user.h" +#include <linux/netdevice.h> #include "etap.h" +#include "net_kern.h" struct ethertap_init { char *dev_name; @@ -42,27 +41,30 @@ static int etap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp) int len; *skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP); - if(*skb == NULL) return(-ENOMEM); + if (*skb == NULL) + return -ENOMEM; len = net_recvfrom(fd, skb_mac_header(*skb), (*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP); - if(len <= 0) return(len); + if (len <= 0) + return len; skb_pull(*skb, 2); len -= 2; - return(len); + return len; } static int etap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) { - if(skb_headroom(*skb) < 2){ + if (skb_headroom(*skb) < 2) { struct sk_buff *skb2; skb2 = skb_realloc_headroom(*skb, 2); dev_kfree_skb(*skb); - if (skb2 == NULL) return(-ENOMEM); + if (skb2 == NULL) + return -ENOMEM; *skb = skb2; } skb_push(*skb, 2); - return(net_send(fd, (*skb)->data, (*skb)->len)); + return net_send(fd, (*skb)->data, (*skb)->len); } const struct net_kern_info ethertap_kern_info = { @@ -79,15 +81,15 @@ int ethertap_setup(char *str, char **mac_out, void *data) *init = ((struct ethertap_init) { .dev_name = NULL, .gate_addr = NULL }); - if(tap_setup_common(str, "ethertap", &init->dev_name, mac_out, + if (tap_setup_common(str, "ethertap", &init->dev_name, mac_out, &init->gate_addr)) - return(0); - if(init->dev_name == NULL){ - printk("ethertap_setup : Missing tap device name\n"); - return(0); + return 0; + if (init->dev_name == NULL) { + printk(KERN_ERR "ethertap_setup : Missing tap device name\n"); + return 0; } - return(1); + return 1; } static struct transport ethertap_transport = { diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c index d74eedb7e682..29404b955f18 100644 --- a/arch/um/os-Linux/drivers/ethertap_user.c +++ b/arch/um/os-Linux/drivers/ethertap_user.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and * James Leu (jleu@mindspring.net). * Copyright (C) 2001 by various other people who didn't put their name here. @@ -7,20 +8,16 @@ #include <stdio.h> #include <unistd.h> -#include <stddef.h> -#include <stdlib.h> -#include <sys/errno.h> +#include <errno.h> +#include <string.h> #include <sys/socket.h> #include <sys/wait.h> -#include <sys/un.h> -#include <net/if.h> -#include "user.h" -#include "kern_util.h" -#include "net_user.h" #include "etap.h" +#include "kern_constants.h" #include "os.h" +#include "net_user.h" #include "um_malloc.h" -#include "kern_constants.h" +#include "user.h" #define MAX_PACKET ETH_MAX_PACKET @@ -49,16 +46,18 @@ static void etap_change(int op, unsigned char *addr, unsigned char *netmask, memcpy(change.addr, addr, sizeof(change.addr)); memcpy(change.netmask, netmask, sizeof(change.netmask)); CATCH_EINTR(n = write(fd, &change, sizeof(change))); - if(n != sizeof(change)){ - printk("etap_change - request failed, err = %d\n", errno); + if (n != sizeof(change)) { + printk(UM_KERN_ERR "etap_change - request failed, err = %d\n", + errno); return; } output = kmalloc(UM_KERN_PAGE_SIZE, UM_GFP_KERNEL); - if(output == NULL) - printk("etap_change : Failed to allocate output buffer\n"); + if (output == NULL) + printk(UM_KERN_ERR "etap_change : Failed to allocate output " + "buffer\n"); read_output(fd, output, UM_KERN_PAGE_SIZE); - if(output != NULL){ + if (output != NULL) { printk("%s", output); kfree(output); } @@ -107,7 +106,7 @@ static int etap_tramp(char *dev, char *gate, int control_me, sprintf(data_fd_buf, "%d", data_remote); sprintf(version_buf, "%d", UML_NET_VERSION); - if(gate != NULL){ + if (gate != NULL) { strcpy(gate_buf, gate); args = setup_args; } @@ -119,24 +118,26 @@ static int etap_tramp(char *dev, char *gate, int control_me, pe_data.data_me = data_me; pid = run_helper(etap_pre_exec, &pe_data, args); - if(pid < 0) + if (pid < 0) err = pid; close(data_remote); close(control_remote); CATCH_EINTR(n = read(control_me, &c, sizeof(c))); - if(n != sizeof(c)){ + if (n != sizeof(c)) { err = -errno; - printk("etap_tramp : read of status failed, err = %d\n", -err); + printk(UM_KERN_ERR "etap_tramp : read of status failed, " + "err = %d\n", -err); return err; } - if(c != 1){ - printk("etap_tramp : uml_net failed\n"); + if (c != 1) { + printk(UM_KERN_ERR "etap_tramp : uml_net failed\n"); err = -EINVAL; CATCH_EINTR(n = waitpid(pid, &status, 0)); - if(n < 0) + if (n < 0) err = -errno; - else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) - printk("uml_net didn't exit with status 1\n"); + else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) + printk(UM_KERN_ERR "uml_net didn't exit with " + "status 1\n"); } return err; } @@ -148,22 +149,22 @@ static int etap_open(void *data) int data_fds[2], control_fds[2], err, output_len; err = tap_open_common(pri->dev, pri->gate_addr); - if(err) + if (err) return err; err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds); - if(err){ + if (err) { err = -errno; - printk("etap_open - data socketpair failed - err = %d\n", - errno); + printk(UM_KERN_ERR "etap_open - data socketpair failed - " + "err = %d\n", errno); return err; } err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds); - if(err){ + if (err) { err = -errno; - printk("etap_open - control socketpair failed - err = %d\n", - errno); + printk(UM_KERN_ERR "etap_open - control socketpair failed - " + "err = %d\n", errno); goto out_close_data; } @@ -173,15 +174,16 @@ static int etap_open(void *data) output = kmalloc(output_len, UM_GFP_KERNEL); read_output(control_fds[0], output, output_len); - if(output == NULL) - printk("etap_open : failed to allocate output buffer\n"); + if (output == NULL) + printk(UM_KERN_ERR "etap_open : failed to allocate output " + "buffer\n"); else { printk("%s", output); kfree(output); } - if(err < 0){ - printk("etap_tramp failed - err = %d\n", -err); + if (err < 0) { + printk(UM_KERN_ERR "etap_tramp failed - err = %d\n", -err); goto out_close_control; } @@ -206,14 +208,14 @@ static void etap_close(int fd, void *data) iter_addresses(pri->dev, etap_close_addr, &pri->control_fd); close(fd); - if(shutdown(pri->data_fd, SHUT_RDWR) < 0) - printk("etap_close - shutdown data socket failed, errno = %d\n", - errno); - - if(shutdown(pri->control_fd, SHUT_RDWR) < 0) - printk("etap_close - shutdown control socket failed, " + if (shutdown(pri->data_fd, SHUT_RDWR) < 0) + printk(UM_KERN_ERR "etap_close - shutdown data socket failed, " "errno = %d\n", errno); + if (shutdown(pri->control_fd, SHUT_RDWR) < 0) + printk(UM_KERN_ERR "etap_close - shutdown control socket " + "failed, errno = %d\n", errno); + close(pri->data_fd); pri->data_fd = -1; close(pri->control_fd); @@ -231,7 +233,7 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask, struct ethertap_data *pri = data; tap_check_ips(pri->gate_addr, addr); - if(pri->control_fd == -1) + if (pri->control_fd == -1) return; etap_open_addr(addr, netmask, &pri->control_fd); } @@ -241,7 +243,7 @@ static void etap_del_addr(unsigned char *addr, unsigned char *netmask, { struct ethertap_data *pri = data; - if(pri->control_fd == -1) + if (pri->control_fd == -1) return; etap_close_addr(addr, netmask, &pri->control_fd); diff --git a/arch/um/os-Linux/drivers/tuntap.h b/arch/um/os-Linux/drivers/tuntap.h index d3e8d3af6245..f17c31586c84 100644 --- a/arch/um/os-Linux/drivers/tuntap.h +++ b/arch/um/os-Linux/drivers/tuntap.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ @@ -19,14 +19,3 @@ struct tuntap_data { extern const struct net_user_info tuntap_user_info; #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: - */ diff --git a/arch/um/os-Linux/drivers/tuntap_kern.c b/arch/um/os-Linux/drivers/tuntap_kern.c index f1714e7fb1d0..9ade1f892ac8 100644 --- a/arch/um/os-Linux/drivers/tuntap_kern.c +++ b/arch/um/os-Linux/drivers/tuntap_kern.c @@ -1,16 +1,13 @@ -/* - * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) +/* + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ -#include "linux/stddef.h" -#include "linux/netdevice.h" -#include "linux/etherdevice.h" -#include "linux/skbuff.h" -#include "linux/init.h" -#include "asm/errno.h" +#include <linux/netdevice.h> +#include <linux/init.h> +#include <linux/skbuff.h> +#include <asm/errno.h> #include "net_kern.h" -#include "net_user.h" #include "tuntap.h" struct tuntap_init { @@ -38,19 +35,20 @@ static void tuntap_init(struct net_device *dev, void *data) printk("\n"); } -static int tuntap_read(int fd, struct sk_buff **skb, +static int tuntap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp) { *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); - if(*skb == NULL) return(-ENOMEM); - return(net_read(fd, skb_mac_header(*skb), - (*skb)->dev->mtu + ETH_HEADER_OTHER)); + if (*skb == NULL) + return -ENOMEM; + return net_read(fd, skb_mac_header(*skb), + (*skb)->dev->mtu + ETH_HEADER_OTHER); } -static int tuntap_write(int fd, struct sk_buff **skb, +static int tuntap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp) { - return(net_write(fd, (*skb)->data, (*skb)->len)); + return net_write(fd, (*skb)->data, (*skb)->len); } const struct net_kern_info tuntap_kern_info = { @@ -67,11 +65,11 @@ int tuntap_setup(char *str, char **mac_out, void *data) *init = ((struct tuntap_init) { .dev_name = NULL, .gate_addr = NULL }); - if(tap_setup_common(str, "tuntap", &init->dev_name, mac_out, + if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out, &init->gate_addr)) - return(0); + return 0; - return(1); + return 1; } static struct transport tuntap_transport = { diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c index 72a2ff61556d..10714a413cfd 100644 --- a/arch/um/os-Linux/drivers/tuntap_user.c +++ b/arch/um/os-Linux/drivers/tuntap_user.c @@ -1,25 +1,22 @@ /* - * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ #include <stdio.h> -#include <stddef.h> -#include <stdlib.h> #include <unistd.h> #include <errno.h> -#include <sys/wait.h> +#include <string.h> +#include <linux/if_tun.h> +#include <net/if.h> +#include <sys/ioctl.h> #include <sys/socket.h> -#include <sys/un.h> +#include <sys/wait.h> #include <sys/uio.h> -#include <sys/ioctl.h> -#include <net/if.h> -#include <linux/if_tun.h> -#include "net_user.h" +#include "kern_constants.h" +#include "os.h" #include "tuntap.h" -#include "kern_util.h" #include "user.h" -#include "os.h" #define MAX_PACKET ETH_MAX_PACKET @@ -37,7 +34,7 @@ static void tuntap_add_addr(unsigned char *addr, unsigned char *netmask, struct tuntap_data *pri = data; tap_check_ips(pri->gate_addr, addr); - if((pri->fd == -1) || pri->fixed_config) + if ((pri->fd == -1) || pri->fixed_config) return; open_addr(addr, netmask, pri->dev_name); } @@ -47,7 +44,7 @@ static void tuntap_del_addr(unsigned char *addr, unsigned char *netmask, { struct tuntap_data *pri = data; - if((pri->fd == -1) || pri->fixed_config) + if ((pri->fd == -1) || pri->fixed_config) return; close_addr(addr, netmask, pri->dev_name); } @@ -85,14 +82,14 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, pid = run_helper(tuntap_pre_exec, &data, argv); - if(pid < 0) + if (pid < 0) return -pid; close(remote); msg.msg_name = NULL; msg.msg_namelen = 0; - if(buffer != NULL){ + if (buffer != NULL) { iov = ((struct iovec) { buffer, buffer_len }); msg.msg_iov = &iov; msg.msg_iovlen = 1; @@ -106,22 +103,24 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, msg.msg_flags = 0; n = recvmsg(me, &msg, 0); *used_out = n; - if(n < 0){ + if (n < 0) { err = -errno; - printk("tuntap_open_tramp : recvmsg failed - errno = %d\n", - errno); + printk(UM_KERN_ERR "tuntap_open_tramp : recvmsg failed - " + "errno = %d\n", errno); return err; } CATCH_EINTR(waitpid(pid, NULL, 0)); cmsg = CMSG_FIRSTHDR(&msg); - if(cmsg == NULL){ - printk("tuntap_open_tramp : didn't receive a message\n"); + if (cmsg == NULL) { + printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a " + "message\n"); return -EINVAL; } - if((cmsg->cmsg_level != SOL_SOCKET) || - (cmsg->cmsg_type != SCM_RIGHTS)){ - printk("tuntap_open_tramp : didn't receive a descriptor\n"); + if ((cmsg->cmsg_level != SOL_SOCKET) || + (cmsg->cmsg_type != SCM_RIGHTS)) { + printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a " + "descriptor\n"); return -EINVAL; } *fd_out = ((int *) CMSG_DATA(cmsg))[0]; @@ -137,38 +136,39 @@ static int tuntap_open(void *data) int err, fds[2], len, used; err = tap_open_common(pri->dev, pri->gate_addr); - if(err < 0) + if (err < 0) return err; - if(pri->fixed_config){ + if (pri->fixed_config) { pri->fd = os_open_file("/dev/net/tun", of_cloexec(of_rdwr(OPENFLAGS())), 0); - if(pri->fd < 0){ - printk("Failed to open /dev/net/tun, err = %d\n", - -pri->fd); + if (pri->fd < 0) { + printk(UM_KERN_ERR "Failed to open /dev/net/tun, " + "err = %d\n", -pri->fd); return pri->fd; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name)); - if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ + if (ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0) { err = -errno; - printk("TUNSETIFF failed, errno = %d\n", errno); + printk(UM_KERN_ERR "TUNSETIFF failed, errno = %d\n", + errno); close(pri->fd); return err; } } else { err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds); - if(err){ + if (err) { err = -errno; - printk("tuntap_open : socketpair failed - errno = %d\n", - errno); + printk(UM_KERN_ERR "tuntap_open : socketpair failed - " + "errno = %d\n", errno); return err; } buffer = get_output_buffer(&len); - if(buffer != NULL) + if (buffer != NULL) len--; used = 0; @@ -176,10 +176,11 @@ static int tuntap_open(void *data) fds[1], buffer, len, &used); output = buffer; - if(err < 0) { + if (err < 0) { printk("%s", output); free_output_buffer(buffer); - printk("tuntap_open_tramp failed - err = %d\n", -err); + printk(UM_KERN_ERR "tuntap_open_tramp failed - " + "err = %d\n", -err); return err; } @@ -199,7 +200,7 @@ static void tuntap_close(int fd, void *data) { struct tuntap_data *pri = data; - if(!pri->fixed_config) + if (!pri->fixed_config) iter_addresses(pri->dev, close_addr, pri->dev_name); close(fd); pri->fd = -1; |