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/drivers/net_user.c | |
parent | 1a80521990a0e30e61a92994a009adc52161b070 (diff) | |
download | linux-cd1ae0e49bdd814cfaa2e5ab28cff21a30e20085.tar.gz |
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/drivers/net_user.c')
-rw-r--r-- | arch/um/drivers/net_user.c | 126 |
1 files changed, 66 insertions, 60 deletions
diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c index da946e3e1bf263..90d7f2e8ead8bc 100644 --- a/arch/um/drivers/net_user.c +++ b/arch/um/drivers/net_user.c @@ -1,34 +1,32 @@ -/* - * 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 <stddef.h> -#include <stdarg.h> -#include <unistd.h> #include <stdio.h> +#include <unistd.h> +#include <stdarg.h> #include <errno.h> -#include <stdlib.h> +#include <stddef.h> #include <string.h> #include <sys/socket.h> #include <sys/wait.h> -#include <sys/time.h> -#include "user.h" -#include "kern_util.h" #include "net_user.h" +#include "kern_constants.h" #include "os.h" #include "um_malloc.h" -#include "kern_constants.h" +#include "user.h" int tap_open_common(void *dev, char *gate_addr) { int tap_addr[4]; - if(gate_addr == NULL) + if (gate_addr == NULL) return 0; - if(sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], - &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4){ - printk("Invalid tap IP address - '%s'\n", gate_addr); + if (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], + &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4) { + printk(UM_KERN_ERR "Invalid tap IP address - '%s'\n", + gate_addr); return -EINVAL; } return 0; @@ -38,15 +36,15 @@ void tap_check_ips(char *gate_addr, unsigned char *eth_addr) { int tap_addr[4]; - if((gate_addr != NULL) && - (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], - &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) && - (eth_addr[0] == tap_addr[0]) && - (eth_addr[1] == tap_addr[1]) && - (eth_addr[2] == tap_addr[2]) && - (eth_addr[3] == tap_addr[3])){ - printk("The tap IP address and the UML eth IP address" - " must be different\n"); + if ((gate_addr != NULL) && + (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0], + &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) && + (eth_addr[0] == tap_addr[0]) && + (eth_addr[1] == tap_addr[1]) && + (eth_addr[2] == tap_addr[2]) && + (eth_addr[3] == tap_addr[3])) { + printk(UM_KERN_ERR "The tap IP address and the UML eth IP " + "address must be different\n"); } } @@ -57,24 +55,28 @@ void read_output(int fd, char *output, int len) char c; char *str; - if(output == NULL){ + if (output == NULL) { output = &c; len = sizeof(c); } - + *output = '\0'; - ret = os_read_file(fd, &remain, sizeof(remain)); + ret = read(fd, &remain, sizeof(remain)); if (ret != sizeof(remain)) { + if (ret < 0) + ret = -errno; expected = sizeof(remain); str = "length"; goto err; } - while(remain != 0){ + while (remain != 0) { expected = (remain < len) ? remain : len; - ret = os_read_file(fd, output, expected); + ret = read(fd, output, expected); if (ret != expected) { + if (ret < 0) + ret = -errno; str = "data"; goto err; } @@ -85,20 +87,22 @@ void read_output(int fd, char *output, int len) err: if (ret < 0) - printk("read_output - read of %s failed, errno = %d\n", str, -ret); + printk(UM_KERN_ERR "read_output - read of %s failed, " + "errno = %d\n", str, -ret); else - printk("read_output - read of %s failed, read only %d of %d bytes\n", str, ret, expected); + printk(UM_KERN_ERR "read_output - read of %s failed, read only " + "%d of %d bytes\n", str, ret, expected); } int net_read(int fd, void *buf, int len) { int n; - n = os_read_file(fd, buf, len); + n = read(fd, buf, len); - if(n == -EAGAIN) + if ((n < 0) && (errno == EAGAIN)) return 0; - else if(n == 0) + else if (n == 0) return -ENOTCONN; return n; } @@ -108,12 +112,12 @@ int net_recvfrom(int fd, void *buf, int len) int n; CATCH_EINTR(n = recvfrom(fd, buf, len, 0, NULL, NULL)); - if(n < 0){ - if(errno == EAGAIN) + if (n < 0) { + if (errno == EAGAIN) return 0; return -errno; } - else if(n == 0) + else if (n == 0) return -ENOTCONN; return n; } @@ -122,11 +126,11 @@ int net_write(int fd, void *buf, int len) { int n; - n = os_write_file(fd, buf, len); + n = write(fd, buf, len); - if(n == -EAGAIN) + if ((n < 0) && (errno == EAGAIN)) return 0; - else if(n == 0) + else if (n == 0) return -ENOTCONN; return n; } @@ -136,12 +140,12 @@ int net_send(int fd, void *buf, int len) int n; CATCH_EINTR(n = send(fd, buf, len, 0)); - if(n < 0){ - if(errno == EAGAIN) + if (n < 0) { + if (errno == EAGAIN) return 0; return -errno; } - else if(n == 0) + else if (n == 0) return -ENOTCONN; return n; } @@ -152,12 +156,12 @@ int net_sendto(int fd, void *buf, int len, void *to, int sock_len) CATCH_EINTR(n = sendto(fd, buf, len, 0, (struct sockaddr *) to, sock_len)); - if(n < 0){ - if(errno == EAGAIN) + if (n < 0) { + if (errno == EAGAIN) return 0; return -errno; } - else if(n == 0) + else if (n == 0) return -ENOTCONN; return n; } @@ -171,7 +175,7 @@ static void change_pre_exec(void *arg) { struct change_pre_exec_data *data = arg; - os_close_file(data->close_me); + close(data->close_me); dup2(data->stdout, 1); } @@ -181,8 +185,9 @@ static int change_tramp(char **argv, char *output, int output_len) struct change_pre_exec_data pe_data; err = os_pipe(fds, 1, 0); - if(err < 0){ - printk("change_tramp - pipe failed, err = %d\n", -err); + if (err < 0) { + printk(UM_KERN_ERR "change_tramp - pipe failed, err = %d\n", + -err); return err; } pe_data.close_me = fds[0]; @@ -192,8 +197,8 @@ static int change_tramp(char **argv, char *output, int output_len) if (pid > 0) /* Avoid hang as we won't get data in failure case. */ read_output(fds[0], output, output_len); - os_close_file(fds[0]); - os_close_file(fds[1]); + close(fds[0]); + close(fds[1]); if (pid > 0) CATCH_EINTR(err = waitpid(pid, NULL, 0)); @@ -206,25 +211,26 @@ static void change(char *dev, char *what, unsigned char *addr, char addr_buf[sizeof("255.255.255.255\0")]; char netmask_buf[sizeof("255.255.255.255\0")]; char version[sizeof("nnnnn\0")]; - char *argv[] = { "uml_net", version, what, dev, addr_buf, + char *argv[] = { "uml_net", version, what, dev, addr_buf, netmask_buf, NULL }; char *output; int output_len, pid; sprintf(version, "%d", UML_NET_VERSION); sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]); - sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1], + sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1], netmask[2], netmask[3]); output_len = UM_KERN_PAGE_SIZE; output = kmalloc(output_len, UM_GFP_KERNEL); - if(output == NULL) - printk("change : failed to allocate output buffer\n"); + if (output == NULL) + printk(UM_KERN_ERR "change : failed to allocate output " + "buffer\n"); pid = change_tramp(argv, output, output_len); - if(pid < 0) return; + if (pid < 0) return; - if(output != NULL){ + if (output != NULL) { printk("%s", output); kfree(output); } @@ -246,13 +252,13 @@ char *split_if_spec(char *str, ...) va_list ap; va_start(ap, str); - while((arg = va_arg(ap, char **)) != NULL){ - if(*str == '\0') + while ((arg = va_arg(ap, char **)) != NULL) { + if (*str == '\0') return NULL; end = strchr(str, ','); - if(end != str) + if (end != str) *arg = str; - if(end == NULL) + if (end == NULL) return NULL; *end++ = '\0'; str = end; |