Commit cd1ae0e49bdd814cfaa2e5ab28cff21a30e20085

Authored by Jeff Dike
Committed by Linus Torvalds
1 parent 1a80521990

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>

Showing 22 changed files with 602 additions and 616 deletions Side-by-side Diff

arch/um/drivers/daemon.h
1   -/*
2   - * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
  1 +/*
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
  6 +#ifndef __DAEMON_H__
  7 +#define __DAEMON_H__
  8 +
6 9 #include "net_user.h"
7 10  
8 11 #define SWITCH_VERSION 3
9 12  
... ... @@ -20,17 +23,8 @@
20 23  
21 24 extern const struct net_user_info daemon_user_info;
22 25  
23   -extern int daemon_user_write(int fd, void *buf, int len,
  26 +extern int daemon_user_write(int fd, void *buf, int len,
24 27 struct daemon_data *pri);
25 28  
26   -/*
27   - * Overrides for Emacs so that we follow Linus's tabbing style.
28   - * Emacs will notice this stuff at the end of the file and automatically
29   - * adjust the settings for this buffer only. This must remain at the end
30   - * of the file.
31   - * ---------------------------------------------------------------------------
32   - * Local variables:
33   - * c-file-style: "linux"
34   - * End:
35   - */
  29 +#endif
arch/um/drivers/daemon_kern.c
1 1 /*
2   - * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  2 + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 3 * James Leu (jleu@mindspring.net).
  4 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 5 * Copyright (C) 2001 by various other people who didn't put their name here.
5 6 * Licensed under the GPL.
6 7 */
7 8  
8   -#include "linux/kernel.h"
9 9 #include "linux/init.h"
10   -#include "linux/netdevice.h"
11   -#include "linux/etherdevice.h"
  10 +#include <linux/netdevice.h>
12 11 #include "net_kern.h"
13   -#include "net_user.h"
14 12 #include "daemon.h"
15 13  
16 14 struct daemon_init {
17 15  
18 16  
19 17  
... ... @@ -36,25 +34,26 @@
36 34 dpri->data_addr = NULL;
37 35 dpri->local_addr = NULL;
38 36  
39   - printk("daemon backend (uml_switch version %d) - %s:%s",
  37 + printk("daemon backend (uml_switch version %d) - %s:%s",
40 38 SWITCH_VERSION, dpri->sock_type, dpri->ctl_sock);
41 39 printk("\n");
42 40 }
43 41  
44   -static int daemon_read(int fd, struct sk_buff **skb,
  42 +static int daemon_read(int fd, struct sk_buff **skb,
45 43 struct uml_net_private *lp)
46 44 {
47 45 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
48   - if(*skb == NULL) return(-ENOMEM);
49   - return(net_recvfrom(fd, skb_mac_header(*skb),
50   - (*skb)->dev->mtu + ETH_HEADER_OTHER));
  46 + if (*skb == NULL)
  47 + return -ENOMEM;
  48 + return net_recvfrom(fd, skb_mac_header(*skb),
  49 + (*skb)->dev->mtu + ETH_HEADER_OTHER);
51 50 }
52 51  
53 52 static int daemon_write(int fd, struct sk_buff **skb,
54 53 struct uml_net_private *lp)
55 54 {
56   - return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
57   - (struct daemon_data *) &lp->user));
  55 + return daemon_user_write(fd, (*skb)->data, (*skb)->len,
  56 + (struct daemon_data *) &lp->user);
58 57 }
59 58  
60 59 static const struct net_kern_info daemon_kern_info = {
61 60  
62 61  
... ... @@ -72,14 +71,14 @@
72 71 *init = ((struct daemon_init)
73 72 { .sock_type = "unix",
74 73 .ctl_sock = "/tmp/uml.ctl" });
75   -
  74 +
76 75 remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
77 76 NULL);
78   - if(remain != NULL)
  77 + if (remain != NULL)
79 78 printk(KERN_WARNING "daemon_setup : Ignoring data socket "
80 79 "specification\n");
81   -
82   - return(1);
  80 +
  81 + return 1;
83 82 }
84 83  
85 84 static struct transport daemon_transport = {
arch/um/drivers/daemon_user.c
1 1 /*
2   - * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 4 * James Leu (jleu@mindspring.net).
4 5 * Copyright (C) 2001 by various other people who didn't put their name here.
5 6 * Licensed under the GPL.
6 7 */
7 8  
8   -#include <errno.h>
9   -#include <unistd.h>
10 9 #include <stdint.h>
  10 +#include <unistd.h>
  11 +#include <errno.h>
  12 +#include <sys/types.h>
11 13 #include <sys/socket.h>
12   -#include <sys/un.h>
13 14 #include <sys/time.h>
14   -#include "net_user.h"
  15 +#include <sys/un.h>
15 16 #include "daemon.h"
16   -#include "kern_util.h"
17   -#include "user.h"
  17 +#include "net_user.h"
18 18 #include "os.h"
19 19 #include "um_malloc.h"
  20 +#include "user.h"
20 21  
21 22 #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
22 23  
... ... @@ -36,8 +37,9 @@
36 37 struct sockaddr_un *sun;
37 38  
38 39 sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
39   - if(sun == NULL){
40   - printk("new_addr: allocation of sockaddr_un failed\n");
  40 + if (sun == NULL) {
  41 + printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
  42 + "failed\n");
41 43 return NULL;
42 44 }
43 45 sun->sun_family = AF_UNIX;
44 46  
45 47  
46 48  
47 49  
48 50  
49 51  
50 52  
51 53  
... ... @@ -54,38 +56,39 @@
54 56 int fd, n, err;
55 57  
56 58 pri->control = socket(AF_UNIX, SOCK_STREAM, 0);
57   - if(pri->control < 0){
  59 + if (pri->control < 0) {
58 60 err = -errno;
59   - printk("daemon_open : control socket failed, errno = %d\n",
60   - -err);
  61 + printk(UM_KERN_ERR "daemon_open : control socket failed, "
  62 + "errno = %d\n", -err);
61 63 return err;
62 64 }
63 65  
64   - if(connect(pri->control, (struct sockaddr *) ctl_addr,
65   - sizeof(*ctl_addr)) < 0){
  66 + if (connect(pri->control, (struct sockaddr *) ctl_addr,
  67 + sizeof(*ctl_addr)) < 0) {
66 68 err = -errno;
67   - printk("daemon_open : control connect failed, errno = %d\n",
68   - -err);
  69 + printk(UM_KERN_ERR "daemon_open : control connect failed, "
  70 + "errno = %d\n", -err);
69 71 goto out;
70 72 }
71 73  
72 74 fd = socket(AF_UNIX, SOCK_DGRAM, 0);
73   - if(fd < 0){
  75 + if (fd < 0) {
74 76 err = -errno;
75   - printk("daemon_open : data socket failed, errno = %d\n",
76   - -err);
  77 + printk(UM_KERN_ERR "daemon_open : data socket failed, "
  78 + "errno = %d\n", -err);
77 79 goto out;
78 80 }
79   - if(bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0){
  81 + if (bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0) {
80 82 err = -errno;
81   - printk("daemon_open : data bind failed, errno = %d\n",
82   - -err);
  83 + printk(UM_KERN_ERR "daemon_open : data bind failed, "
  84 + "errno = %d\n", -err);
83 85 goto out_close;
84 86 }
85 87  
86 88 sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
87   - if(sun == NULL){
88   - printk("new_addr: allocation of sockaddr_un failed\n");
  89 + if (sun == NULL) {
  90 + printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
  91 + "failed\n");
89 92 err = -ENOMEM;
90 93 goto out_close;
91 94 }
92 95  
... ... @@ -94,18 +97,18 @@
94 97 req.version = SWITCH_VERSION;
95 98 req.type = REQ_NEW_CONTROL;
96 99 req.sock = *local_addr;
97   - n = os_write_file(pri->control, &req, sizeof(req));
98   - if(n != sizeof(req)){
99   - printk("daemon_open : control setup request failed, err = %d\n",
100   - -n);
  100 + n = write(pri->control, &req, sizeof(req));
  101 + if (n != sizeof(req)) {
  102 + printk(UM_KERN_ERR "daemon_open : control setup request "
  103 + "failed, err = %d\n", -errno);
101 104 err = -ENOTCONN;
102 105 goto out_free;
103 106 }
104 107  
105   - n = os_read_file(pri->control, sun, sizeof(*sun));
106   - if(n != sizeof(*sun)){
107   - printk("daemon_open : read of data socket failed, err = %d\n",
108   - -n);
  108 + n = read(pri->control, sun, sizeof(*sun));
  109 + if (n != sizeof(*sun)) {
  110 + printk(UM_KERN_ERR "daemon_open : read of data socket failed, "
  111 + "err = %d\n", -errno);
109 112 err = -ENOTCONN;
110 113 goto out_free;
111 114 }
112 115  
... ... @@ -116,9 +119,9 @@
116 119 out_free:
117 120 kfree(sun);
118 121 out_close:
119   - os_close_file(fd);
  122 + close(fd);
120 123 out:
121   - os_close_file(pri->control);
  124 + close(pri->control);
122 125 return err;
123 126 }
124 127  
... ... @@ -132,8 +135,8 @@
132 135 int usecs;
133 136 } name;
134 137  
135   - if(!strcmp(pri->sock_type, "unix"))
136   - pri->ctl_addr = new_addr(pri->ctl_sock,
  138 + if (!strcmp(pri->sock_type, "unix"))
  139 + pri->ctl_addr = new_addr(pri->ctl_sock,
137 140 strlen(pri->ctl_sock) + 1);
138 141 name.zero = 0;
139 142 name.pid = os_getpid();
... ... @@ -142,7 +145,7 @@
142 145 pri->local_addr = new_addr(&name, sizeof(name));
143 146 pri->dev = dev;
144 147 pri->fd = connect_to_switch(pri);
145   - if(pri->fd < 0){
  148 + if (pri->fd < 0) {
146 149 kfree(pri->local_addr);
147 150 pri->local_addr = NULL;
148 151 return pri->fd;
149 152  
... ... @@ -161,9 +164,9 @@
161 164 {
162 165 struct daemon_data *pri = data;
163 166  
164   - os_close_file(pri->fd);
  167 + close(pri->fd);
165 168 pri->fd = -1;
166   - os_close_file(pri->control);
  169 + close(pri->control);
167 170 pri->control = -1;
168 171  
169 172 kfree(pri->data_addr);
arch/um/drivers/mcast.h
1 1 /*
2   - * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
  6 +#ifndef __DRIVERS_MCAST_H
  7 +#define __DRIVERS_MCAST_H
  8 +
6 9 #include "net_user.h"
7 10  
8 11 struct mcast_data {
... ... @@ -18,14 +21,5 @@
18 21 extern int mcast_user_write(int fd, void *buf, int len,
19 22 struct mcast_data *pri);
20 23  
21   -/*
22   - * Overrides for Emacs so that we follow Linus's tabbing style.
23   - * Emacs will notice this stuff at the end of the file and automatically
24   - * adjust the settings for this buffer only. This must remain at the end
25   - * of the file.
26   - * ---------------------------------------------------------------------------
27   - * Local variables:
28   - * c-file-style: "linux"
29   - * End:
30   - */
  24 +#endif
arch/um/drivers/mcast_kern.c
1 1 /*
2 2 * user-mode-linux networking multicast transport
3 3 * Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
  4 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 5 *
5 6 * based on the existing uml-networking code, which is
6   - * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  7 + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
7 8 * James Leu (jleu@mindspring.net).
8 9 * Copyright (C) 2001 by various other people who didn't put their name here.
9 10 *
10 11 * Licensed under the GPL.
11 12 */
12 13  
13   -#include "linux/kernel.h"
14 14 #include "linux/init.h"
15   -#include "linux/netdevice.h"
16   -#include "linux/etherdevice.h"
17   -#include "linux/in.h"
18   -#include "linux/inet.h"
19   -#include "net_kern.h"
20   -#include "net_user.h"
  15 +#include <linux/netdevice.h>
21 16 #include "mcast.h"
  17 +#include "net_kern.h"
22 18  
23 19 struct mcast_init {
24 20 char *addr;
25 21  
26 22  
27 23  
28 24  
... ... @@ -39,26 +35,23 @@
39 35 dpri->ttl = init->ttl;
40 36 dpri->dev = dev;
41 37  
42   - printk("mcast backend ");
43   - printk("multicast address: %s:%u, TTL:%u ",
  38 + printk("mcast backend multicast address: %s:%u, TTL:%u\n",
44 39 dpri->addr, dpri->port, dpri->ttl);
45   -
46   - printk("\n");
47 40 }
48 41  
49 42 static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
50 43 {
51 44 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
52   - if(*skb == NULL) return(-ENOMEM);
53   - return(net_recvfrom(fd, skb_mac_header(*skb),
54   - (*skb)->dev->mtu + ETH_HEADER_OTHER));
  45 + if (*skb == NULL)
  46 + return -ENOMEM;
  47 + return net_recvfrom(fd, skb_mac_header(*skb),
  48 + (*skb)->dev->mtu + ETH_HEADER_OTHER);
55 49 }
56 50  
57   -static int mcast_write(int fd, struct sk_buff **skb,
58   - struct uml_net_private *lp)
  51 +static int mcast_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
59 52 {
60   - return mcast_user_write(fd, (*skb)->data, (*skb)->len,
61   - (struct mcast_data *) &lp->user);
  53 + return mcast_user_write(fd, (*skb)->data, (*skb)->len,
  54 + (struct mcast_data *) &lp->user);
62 55 }
63 56  
64 57 static const struct net_kern_info mcast_kern_info = {
65 58  
66 59  
67 60  
68 61  
69 62  
70 63  
71 64  
72 65  
... ... @@ -81,34 +74,34 @@
81 74  
82 75 remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
83 76 NULL);
84   - if(remain != NULL){
  77 + if (remain != NULL) {
85 78 printk(KERN_ERR "mcast_setup - Extra garbage on "
86 79 "specification : '%s'\n", remain);
87   - return(0);
  80 + return 0;
88 81 }
89   -
90   - if(port_str != NULL){
  82 +
  83 + if (port_str != NULL) {
91 84 init->port = simple_strtoul(port_str, &last, 10);
92   - if((*last != '\0') || (last == port_str)){
93   - printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
  85 + if ((*last != '\0') || (last == port_str)) {
  86 + printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
94 87 port_str);
95   - return(0);
  88 + return 0;
96 89 }
97 90 }
98 91  
99   - if(ttl_str != NULL){
  92 + if (ttl_str != NULL) {
100 93 init->ttl = simple_strtoul(ttl_str, &last, 10);
101   - if((*last != '\0') || (last == ttl_str)){
102   - printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
  94 + if ((*last != '\0') || (last == ttl_str)) {
  95 + printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
103 96 ttl_str);
104   - return(0);
  97 + return 0;
105 98 }
106 99 }
107 100  
108 101 printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
109 102 init->port, init->ttl);
110 103  
111   - return(1);
  104 + return 1;
112 105 }
113 106  
114 107 static struct transport mcast_transport = {
arch/um/drivers/mcast_user.c
1 1 /*
2 2 * user-mode-linux networking multicast transport
  3 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 4 * Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
4 5 *
5 6 * based on the existing uml-networking code, which is
6   - * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  7 + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
7 8 * James Leu (jleu@mindspring.net).
8 9 * Copyright (C) 2001 by various other people who didn't put their name here.
9 10 *
10 11  
11 12  
12 13  
13 14  
... ... @@ -11,18 +12,13 @@
11 12 *
12 13 */
13 14  
14   -#include <errno.h>
15 15 #include <unistd.h>
16   -#include <sys/socket.h>
17   -#include <sys/un.h>
18   -#include <sys/time.h>
  16 +#include <errno.h>
19 17 #include <netinet/in.h>
20   -#include "net_user.h"
21 18 #include "mcast.h"
22   -#include "kern_util.h"
23   -#include "user.h"
24   -#include "os.h"
  19 +#include "net_user.h"
25 20 #include "um_malloc.h"
  21 +#include "user.h"
26 22  
27 23 #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
28 24  
... ... @@ -31,8 +27,9 @@
31 27 struct sockaddr_in *sin;
32 28  
33 29 sin = kmalloc(sizeof(struct sockaddr_in), UM_GFP_KERNEL);
34   - if(sin == NULL){
35   - printk("new_addr: allocation of sockaddr_in failed\n");
  30 + if (sin == NULL) {
  31 + printk(UM_KERN_ERR "new_addr: allocation of sockaddr_in "
  32 + "failed\n");
36 33 return NULL;
37 34 }
38 35 sin->sin_family = AF_INET;
39 36  
40 37  
... ... @@ -71,17 +68,17 @@
71 68  
72 69 fd = socket(AF_INET, SOCK_DGRAM, 0);
73 70  
74   - if (fd < 0){
  71 + if (fd < 0) {
75 72 err = -errno;
76   - printk("mcast_open : data socket failed, errno = %d\n",
77   - errno);
  73 + printk(UM_KERN_ERR "mcast_open : data socket failed, "
  74 + "errno = %d\n", errno);
78 75 goto out;
79 76 }
80 77  
81 78 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
82 79 err = -errno;
83   - printk("mcast_open: SO_REUSEADDR failed, errno = %d\n",
84   - errno);
  80 + printk(UM_KERN_ERR "mcast_open: SO_REUSEADDR failed, "
  81 + "errno = %d\n", errno);
85 82 goto out_close;
86 83 }
87 84  
88 85  
89 86  
90 87  
91 88  
92 89  
... ... @@ -89,45 +86,46 @@
89 86 if (setsockopt(fd, SOL_IP, IP_MULTICAST_TTL, &pri->ttl,
90 87 sizeof(pri->ttl)) < 0) {
91 88 err = -errno;
92   - printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n",
93   - errno);
  89 + printk(UM_KERN_ERR "mcast_open: IP_MULTICAST_TTL failed, "
  90 + "error = %d\n", errno);
94 91 goto out_close;
95 92 }
96 93  
97 94 /* set LOOP, so data does get fed back to local sockets */
98 95 if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
99 96 err = -errno;
100   - printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n",
101   - errno);
  97 + printk(UM_KERN_ERR "mcast_open: IP_MULTICAST_LOOP failed, "
  98 + "error = %d\n", errno);
102 99 goto out_close;
103 100 }
104 101  
105 102 /* bind socket to mcast address */
106 103 if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) {
107 104 err = -errno;
108   - printk("mcast_open : data bind failed, errno = %d\n", errno);
  105 + printk(UM_KERN_ERR "mcast_open : data bind failed, "
  106 + "errno = %d\n", errno);
109 107 goto out_close;
110 108 }
111 109  
112 110 /* subscribe to the multicast group */
113 111 mreq.imr_multiaddr.s_addr = sin->sin_addr.s_addr;
114 112 mreq.imr_interface.s_addr = 0;
115   - if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP,
  113 + if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP,
116 114 &mreq, sizeof(mreq)) < 0) {
117 115 err = -errno;
118   - printk("mcast_open: IP_ADD_MEMBERSHIP failed, error = %d\n",
119   - errno);
120   - printk("There appears not to be a multicast-capable network "
121   - "interface on the host.\n");
122   - printk("eth0 should be configured in order to use the "
123   - "multicast transport.\n");
  116 + printk(UM_KERN_ERR "mcast_open: IP_ADD_MEMBERSHIP failed, "
  117 + "error = %d\n", errno);
  118 + printk(UM_KERN_ERR "There appears not to be a multicast-"
  119 + "capable network interface on the host.\n");
  120 + printk(UM_KERN_ERR "eth0 should be configured in order to use "
  121 + "the multicast transport.\n");
124 122 goto out_close;
125 123 }
126 124  
127 125 return fd;
128 126  
129 127 out_close:
130   - os_close_file(fd);
  128 + close(fd);
131 129 out:
132 130 return err;
133 131 }
134 132  
... ... @@ -142,11 +140,11 @@
142 140 mreq.imr_interface.s_addr = 0;
143 141 if (setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP,
144 142 &mreq, sizeof(mreq)) < 0) {
145   - printk("mcast_open: IP_DROP_MEMBERSHIP failed, error = %d\n",
146   - errno);
  143 + printk(UM_KERN_ERR "mcast_open: IP_DROP_MEMBERSHIP failed, "
  144 + "error = %d\n", errno);
147 145 }
148 146  
149   - os_close_file(fd);
  147 + close(fd);
150 148 }
151 149  
152 150 int mcast_user_write(int fd, void *buf, int len, struct mcast_data *pri)
arch/um/drivers/net_kern.c
1 1 /*
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
2 3 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 4 * James Leu (jleu@mindspring.net).
4 5 * Copyright (C) 2001 by various other people who didn't put their name here.
5 6 * Licensed under the GPL.
6 7 */
7 8  
8   -#include "linux/kernel.h"
9   -#include "linux/netdevice.h"
10   -#include "linux/rtnetlink.h"
11   -#include "linux/skbuff.h"
12   -#include "linux/socket.h"
13   -#include "linux/spinlock.h"
14   -#include "linux/module.h"
15   -#include "linux/init.h"
16   -#include "linux/etherdevice.h"
17   -#include "linux/list.h"
18   -#include "linux/inetdevice.h"
19   -#include "linux/ctype.h"
20   -#include "linux/bootmem.h"
21   -#include "linux/ethtool.h"
22   -#include "linux/platform_device.h"
23   -#include "asm/uaccess.h"
24   -#include "kern_util.h"
25   -#include "net_kern.h"
26   -#include "net_user.h"
27   -#include "mconsole_kern.h"
  9 +#include <linux/bootmem.h>
  10 +#include <linux/etherdevice.h>
  11 +#include <linux/ethtool.h>
  12 +#include <linux/inetdevice.h>
  13 +#include <linux/init.h>
  14 +#include <linux/list.h>
  15 +#include <linux/netdevice.h>
  16 +#include <linux/platform_device.h>
  17 +#include <linux/rtnetlink.h>
  18 +#include <linux/skbuff.h>
  19 +#include <linux/spinlock.h>
28 20 #include "init.h"
29   -#include "irq_user.h"
30 21 #include "irq_kern.h"
  22 +#include "irq_user.h"
  23 +#include "mconsole_kern.h"
  24 +#include "net_kern.h"
  25 +#include "net_user.h"
31 26  
32 27 static inline void set_ether_mac(struct net_device *dev, unsigned char *addr)
33 28 {
34 29  
... ... @@ -84,12 +79,12 @@
84 79 struct uml_net_private *lp = dev->priv;
85 80 int err;
86 81  
87   - if(!netif_running(dev))
88   - return(IRQ_NONE);
  82 + if (!netif_running(dev))
  83 + return IRQ_NONE;
89 84  
90 85 spin_lock(&lp->lock);
91   - while((err = uml_net_rx(dev)) > 0) ;
92   - if(err < 0) {
  86 + while ((err = uml_net_rx(dev)) > 0) ;
  87 + if (err < 0) {
93 88 printk(KERN_ERR
94 89 "Device '%s' read returned %d, shutting it down\n",
95 90 dev->name, err);
96 91  
97 92  
... ... @@ -115,20 +110,20 @@
115 110 struct uml_net_private *lp = dev->priv;
116 111 int err;
117 112  
118   - if(lp->fd >= 0){
  113 + if (lp->fd >= 0) {
119 114 err = -ENXIO;
120 115 goto out;
121 116 }
122 117  
123 118 lp->fd = (*lp->open)(&lp->user);
124   - if(lp->fd < 0){
  119 + if (lp->fd < 0) {
125 120 err = lp->fd;
126 121 goto out;
127 122 }
128 123  
129 124 err = um_request_irq(dev->irq, lp->fd, IRQ_READ, uml_net_interrupt,
130 125 IRQF_DISABLED | IRQF_SHARED, dev->name, dev);
131   - if(err != 0){
  126 + if (err != 0) {
132 127 printk(KERN_ERR "uml_net_open: failed to get irq(%d)\n", err);
133 128 err = -ENETUNREACH;
134 129 goto out_close;
... ... @@ -141,7 +136,7 @@
141 136 * is full when we get here. In this case, new data is never queued,
142 137 * SIGIOs never arrive, and the net never works.
143 138 */
144   - while((err = uml_net_rx(dev)) > 0) ;
  139 + while ((err = uml_net_rx(dev)) > 0) ;
145 140  
146 141 spin_lock(&opened_lock);
147 142 list_add(&lp->list, &opened);
... ... @@ -149,7 +144,7 @@
149 144  
150 145 return 0;
151 146 out_close:
152   - if(lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
  147 + if (lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
153 148 lp->fd = -1;
154 149 out:
155 150 return err;
... ... @@ -162,7 +157,7 @@
162 157 netif_stop_queue(dev);
163 158  
164 159 free_irq(dev->irq, dev);
165   - if(lp->close != NULL)
  160 + if (lp->close != NULL)
166 161 (*lp->close)(lp->fd, &lp->user);
167 162 lp->fd = -1;
168 163  
... ... @@ -185,7 +180,7 @@
185 180  
186 181 len = (*lp->write)(lp->fd, &skb, lp);
187 182  
188   - if(len == skb->len) {
  183 + if (len == skb->len) {
189 184 lp->stats.tx_packets++;
190 185 lp->stats.tx_bytes += skb->len;
191 186 dev->trans_start = jiffies;
... ... @@ -194,7 +189,7 @@
194 189 /* this is normally done in the interrupt when tx finishes */
195 190 netif_wake_queue(dev);
196 191 }
197   - else if(len == 0){
  192 + else if (len == 0) {
198 193 netif_start_queue(dev);
199 194 lp->stats.tx_dropped++;
200 195 }
... ... @@ -218,8 +213,10 @@
218 213  
219 214 static void uml_net_set_multicast_list(struct net_device *dev)
220 215 {
221   - if (dev->flags & IFF_PROMISC) return;
222   - else if (dev->mc_count) dev->flags |= IFF_ALLMULTI;
  216 + if (dev->flags & IFF_PROMISC)
  217 + return;
  218 + else if (dev->mc_count)
  219 + dev->flags |= IFF_ALLMULTI;
223 220 else dev->flags &= ~IFF_ALLMULTI;
224 221 }
225 222  
... ... @@ -249,7 +246,7 @@
249 246 spin_lock_irq(&lp->lock);
250 247  
251 248 new_mtu = (*lp->set_mtu)(new_mtu, &lp->user);
252   - if(new_mtu < 0){
  249 + if (new_mtu < 0) {
253 250 err = new_mtu;
254 251 goto out;
255 252 }
256 253  
257 254  
... ... @@ -288,13 +285,13 @@
288 285 char *end;
289 286 int i;
290 287  
291   - if(str == NULL)
  288 + if (str == NULL)
292 289 goto random;
293 290  
294   - for(i=0;i<6;i++){
  291 + for (i = 0;i < 6; i++) {
295 292 addr[i] = simple_strtoul(str, &end, 16);
296   - if((end == str) ||
297   - ((*end != ':') && (*end != ',') && (*end != '\0'))){
  293 + if ((end == str) ||
  294 + ((*end != ':') && (*end != ',') && (*end != '\0'))) {
298 295 printk(KERN_ERR
299 296 "setup_etheraddr: failed to parse '%s' "
300 297 "as an ethernet address\n", str);
... ... @@ -349,7 +346,7 @@
349 346 struct net_device *netdev = device->dev;
350 347 struct uml_net_private *lp = netdev->priv;
351 348  
352   - if(lp->remove != NULL)
  349 + if (lp->remove != NULL)
353 350 (*lp->remove)(&lp->user);
354 351 list_del(&device->list);
355 352 kfree(device);
... ... @@ -413,7 +410,7 @@
413 410 device->pdev.name = DRIVER_NAME;
414 411 device->pdev.dev.release = net_device_release;
415 412 device->pdev.dev.driver_data = device;
416   - if(platform_device_register(&device->pdev))
  413 + if (platform_device_register(&device->pdev))
417 414 goto out_free_netdev;
418 415 SET_NETDEV_DEV(dev,&device->pdev.dev);
419 416  
420 417  
... ... @@ -493,9 +490,9 @@
493 490 struct list_head *ele;
494 491  
495 492 spin_lock(&devices_lock);
496   - list_for_each(ele, &devices){
  493 + list_for_each(ele, &devices) {
497 494 device = list_entry(ele, struct uml_net, list);
498   - if(device->index == n)
  495 + if (device->index == n)
499 496 goto out;
500 497 }
501 498 device = NULL;
502 499  
503 500  
... ... @@ -511,19 +508,19 @@
511 508 int n, err = -EINVAL;;
512 509  
513 510 n = simple_strtoul(str, &end, 0);
514   - if(end == str){
  511 + if (end == str) {
515 512 *error_out = "Bad device number";
516 513 return err;
517 514 }
518 515  
519 516 str = end;
520   - if(*str != '='){
  517 + if (*str != '=') {
521 518 *error_out = "Expected '=' after device number";
522 519 return err;
523 520 }
524 521  
525 522 str++;
526   - if(find_device(n)){
  523 + if (find_device(n)) {
527 524 *error_out = "Device already configured";
528 525 return err;
529 526 }
530 527  
531 528  
532 529  
533 530  
... ... @@ -551,20 +548,20 @@
551 548 int len;
552 549  
553 550 len = strlen(transport->name);
554   - if(strncmp(eth, transport->name, len))
  551 + if (strncmp(eth, transport->name, len))
555 552 return 0;
556 553  
557 554 eth += len;
558   - if(*eth == ',')
  555 + if (*eth == ',')
559 556 eth++;
560   - else if(*eth != '(*eth != '\0')')
  557 + else if (*eth != '(*eth != '\0')')
561 558 return 0;
562 559  
563 560 *init_out = kmalloc(transport->setup_size, GFP_KERNEL);
564   - if(*init_out == NULL)
  561 + if (*init_out == NULL)
565 562 return 1;
566 563  
567   - if(!transport->setup(eth, mac_out, *init_out)){
  564 + if (!transport->setup(eth, mac_out, *init_out)) {
568 565 kfree(*init_out);
569 566 *init_out = NULL;
570 567 }
571 568  
572 569  
... ... @@ -584,13 +581,13 @@
584 581 list_add(&new->list, &transports);
585 582 spin_unlock(&transports_lock);
586 583  
587   - list_for_each_safe(ele, next, &eth_cmd_line){
  584 + list_for_each_safe(ele, next, &eth_cmd_line) {
588 585 eth = list_entry(ele, struct eth_init, list);
589 586 match = check_transport(new, eth->init, eth->index, &init,
590 587 &mac);
591   - if(!match)
  588 + if (!match)
592 589 continue;
593   - else if(init != NULL){
  590 + else if (init != NULL) {
594 591 eth_configure(eth->index, init, mac, new);
595 592 kfree(init);
596 593 }
597 594  
598 595  
... ... @@ -607,11 +604,11 @@
607 604 int found = 0;
608 605  
609 606 spin_lock(&transports_lock);
610   - list_for_each(ele, &transports){
  607 + list_for_each(ele, &transports) {
611 608 transport = list_entry(ele, struct transport, list);
612   - if(!check_transport(transport, str, index, &init, &mac))
  609 + if (!check_transport(transport, str, index, &init, &mac))
613 610 continue;
614   - if(init != NULL){
  611 + if (init != NULL) {
615 612 eth_configure(index, init, mac, transport);
616 613 kfree(init);
617 614 }
618 615  
... ... @@ -630,15 +627,15 @@
630 627 int n, err;
631 628  
632 629 err = eth_parse(str, &n, &str, &error);
633   - if(err){
  630 + if (err) {
634 631 printk(KERN_ERR "eth_setup - Couldn't parse '%s' : %s\n",
635 632 str, error);
636 633 return 1;
637 634 }
638 635  
639 636 new = alloc_bootmem(sizeof(*new));
640   - if (new == NULL){
641   - printk("eth_init : alloc_bootmem failed\n");
  637 + if (new == NULL) {
  638 + printk(KERN_ERR "eth_init : alloc_bootmem failed\n");
642 639 return 1;
643 640 }
644 641  
645 642  
646 643  
647 644  
648 645  
649 646  
650 647  
... ... @@ -661,36 +658,36 @@
661 658 int n, err;
662 659  
663 660 err = eth_parse(str, &n, &str, error_out);
664   - if(err)
  661 + if (err)
665 662 return err;
666 663  
667 664 /* This string is broken up and the pieces used by the underlying
668 665 * driver. So, it is freed only if eth_setup_common fails.
669 666 */
670 667 str = kstrdup(str, GFP_KERNEL);
671   - if(str == NULL){
  668 + if (str == NULL) {
672 669 *error_out = "net_config failed to strdup string";
673 670 return -ENOMEM;
674 671 }
675 672 err = !eth_setup_common(str, n);
676   - if(err)
  673 + if (err)
677 674 kfree(str);
678   - return(err);
  675 + return err;
679 676 }
680 677  
681 678 static int net_id(char **str, int *start_out, int *end_out)
682 679 {
683   - char *end;
684   - int n;
  680 + char *end;
  681 + int n;
685 682  
686 683 n = simple_strtoul(*str, &end, 0);
687   - if((*end != '((*end != '\0') || (end == *str))') || (end == *str))
  684 + if ((*end != '((*end != '\0') || (end == *str))') || (end == *str))
688 685 return -1;
689 686  
690   - *start_out = n;
691   - *end_out = n;
692   - *str = end;
693   - return n;
  687 + *start_out = n;
  688 + *end_out = n;
  689 + *str = end;
  690 + return n;
694 691 }
695 692  
696 693 static int net_remove(int n, char **error_out)
697 694  
... ... @@ -700,12 +697,12 @@
700 697 struct uml_net_private *lp;
701 698  
702 699 device = find_device(n);
703   - if(device == NULL)
  700 + if (device == NULL)
704 701 return -ENODEV;
705 702  
706 703 dev = device->dev;
707 704 lp = dev->priv;
708   - if(lp->fd > 0)
  705 + if (lp->fd > 0)
709 706 return -EBUSY;
710 707 unregister_netdev(dev);
711 708 platform_device_unregister(&device->pdev);
712 709  
... ... @@ -731,13 +728,13 @@
731 728 void (*proc)(unsigned char *, unsigned char *, void *);
732 729 unsigned char addr_buf[4], netmask_buf[4];
733 730  
734   - if(dev->open != uml_net_open)
  731 + if (dev->open != uml_net_open)
735 732 return NOTIFY_DONE;
736 733  
737 734 lp = dev->priv;
738 735  
739 736 proc = NULL;
740   - switch (event){
  737 + switch (event) {
741 738 case NETDEV_UP:
742 739 proc = lp->add_address;
743 740 break;
... ... @@ -745,7 +742,7 @@
745 742 proc = lp->delete_address;
746 743 break;
747 744 }
748   - if(proc != NULL){
  745 + if (proc != NULL) {
749 746 memcpy(addr_buf, &ifa->ifa_address, sizeof(addr_buf));
750 747 memcpy(netmask_buf, &ifa->ifa_mask, sizeof(netmask_buf));
751 748 (*proc)(addr_buf, netmask_buf, &lp->user);
752 749  
753 750  
... ... @@ -773,13 +770,13 @@
773 770 * addresses which have already been set up get handled properly.
774 771 */
775 772 spin_lock(&opened_lock);
776   - list_for_each(ele, &opened){
  773 + list_for_each(ele, &opened) {
777 774 lp = list_entry(ele, struct uml_net_private, list);
778 775 ip = lp->dev->ip_ptr;
779   - if(ip == NULL)
  776 + if (ip == NULL)
780 777 continue;
781 778 in = ip->ifa_list;
782   - while(in != NULL){
  779 + while (in != NULL) {
783 780 uml_inetaddr_event(NULL, NETDEV_UP, in);
784 781 in = in->ifa_next;
785 782 }
786 783  
787 784  
... ... @@ -797,12 +794,12 @@
797 794 struct uml_net_private *lp;
798 795  
799 796 spin_lock(&opened_lock);
800   - list_for_each(ele, &opened){
  797 + list_for_each(ele, &opened) {
801 798 lp = list_entry(ele, struct uml_net_private, list);
802 799 free_irq(lp->dev->irq, lp->dev);
803   - if((lp->close != NULL) && (lp->fd >= 0))
  800 + if ((lp->close != NULL) && (lp->fd >= 0))
804 801 (*lp->close)(lp->fd, &lp->user);
805   - if(lp->remove != NULL)
  802 + if (lp->remove != NULL)
806 803 (*lp->remove)(&lp->user);
807 804 }
808 805 spin_unlock(&opened_lock);
809 806  
... ... @@ -812,15 +809,15 @@
812 809  
813 810 struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
814 811 {
815   - if((skb != NULL) && (skb_tailroom(skb) < extra)){
  812 + if ((skb != NULL) && (skb_tailroom(skb) < extra)) {
816 813 struct sk_buff *skb2;
817 814  
818 815 skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
819 816 dev_kfree_skb(skb);
820 817 skb = skb2;
821 818 }
822   - if(skb != NULL) skb_put(skb, extra);
823   - return(skb);
  819 + if (skb != NULL) skb_put(skb, extra);
  820 + return skb;
824 821 }
825 822  
826 823 void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
827 824  
... ... @@ -832,9 +829,9 @@
832 829 struct in_ifaddr *in;
833 830 unsigned char address[4], netmask[4];
834 831  
835   - if(ip == NULL) return;
  832 + if (ip == NULL) return;
836 833 in = ip->ifa_list;
837   - while(in != NULL){
  834 + while (in != NULL) {
838 835 memcpy(address, &in->ifa_address, sizeof(address));
839 836 memcpy(netmask, &in->ifa_mask, sizeof(netmask));
840 837 (*cb)(address, netmask, arg);
841 838  
842 839  
... ... @@ -849,15 +846,15 @@
849 846 struct in_ifaddr *in;
850 847 __be32 *mask_out = m;
851 848  
852   - if(ip == NULL)
853   - return(1);
  849 + if (ip == NULL)
  850 + return 1;
854 851  
855 852 in = ip->ifa_list;
856   - if(in == NULL)
857   - return(1);
  853 + if (in == NULL)
  854 + return 1;
858 855  
859 856 *mask_out = in->ifa_mask;
860   - return(0);
  857 + return 0;
861 858 }
862 859  
863 860 void *get_output_buffer(int *len_out)
... ... @@ -865,7 +862,7 @@
865 862 void *ret;
866 863  
867 864 ret = (void *) __get_free_pages(GFP_KERNEL, 0);
868   - if(ret) *len_out = PAGE_SIZE;
  865 + if (ret) *len_out = PAGE_SIZE;
869 866 else *len_out = 0;
870 867 return ret;
871 868 }
872 869  
873 870  
... ... @@ -881,17 +878,17 @@
881 878 char *remain;
882 879  
883 880 remain = split_if_spec(str, dev_name, mac_out, gate_addr, NULL);
884   - if(remain != NULL){
885   - printk("tap_setup_common - Extra garbage on specification : "
886   - "'%s'\n", remain);
887   - return(1);
  881 + if (remain != NULL) {
  882 + printk(KERN_ERR "tap_setup_common - Extra garbage on "
  883 + "specification : '%s'\n", remain);
  884 + return 1;
888 885 }
889 886  
890   - return(0);
  887 + return 0;
891 888 }
892 889  
893 890 unsigned short eth_protocol(struct sk_buff *skb)
894 891 {
895   - return(eth_type_trans(skb, skb->dev));
  892 + return eth_type_trans(skb, skb->dev);
896 893 }
arch/um/drivers/net_user.c
1   -/*
2   - * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
  1 +/*
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
6   -#include <stddef.h>
7   -#include <stdarg.h>
8   -#include <unistd.h>
9 6 #include <stdio.h>
  7 +#include <unistd.h>
  8 +#include <stdarg.h>
10 9 #include <errno.h>
11   -#include <stdlib.h>
  10 +#include <stddef.h>
12 11 #include <string.h>
13 12 #include <sys/socket.h>
14 13 #include <sys/wait.h>
15   -#include <sys/time.h>
16   -#include "user.h"
17   -#include "kern_util.h"
18 14 #include "net_user.h"
  15 +#include "kern_constants.h"
19 16 #include "os.h"
20 17 #include "um_malloc.h"
21   -#include "kern_constants.h"
  18 +#include "user.h"
22 19  
23 20 int tap_open_common(void *dev, char *gate_addr)
24 21 {
25 22 int tap_addr[4];
26 23  
27   - if(gate_addr == NULL)
  24 + if (gate_addr == NULL)
28 25 return 0;
29   - if(sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
30   - &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4){
31   - printk("Invalid tap IP address - '%s'\n", gate_addr);
  26 + if (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
  27 + &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4) {
  28 + printk(UM_KERN_ERR "Invalid tap IP address - '%s'\n",
  29 + gate_addr);
32 30 return -EINVAL;
33 31 }
34 32 return 0;
... ... @@ -38,15 +36,15 @@
38 36 {
39 37 int tap_addr[4];
40 38  
41   - if((gate_addr != NULL) &&
42   - (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
43   - &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) &&
44   - (eth_addr[0] == tap_addr[0]) &&
45   - (eth_addr[1] == tap_addr[1]) &&
46   - (eth_addr[2] == tap_addr[2]) &&
47   - (eth_addr[3] == tap_addr[3])){
48   - printk("The tap IP address and the UML eth IP address"
49   - " must be different\n");
  39 + if ((gate_addr != NULL) &&
  40 + (sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
  41 + &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) &&
  42 + (eth_addr[0] == tap_addr[0]) &&
  43 + (eth_addr[1] == tap_addr[1]) &&
  44 + (eth_addr[2] == tap_addr[2]) &&
  45 + (eth_addr[3] == tap_addr[3])) {
  46 + printk(UM_KERN_ERR "The tap IP address and the UML eth IP "
  47 + "address must be different\n");
50 48 }
51 49 }
52 50  
53 51  
54 52  
55 53  
56 54  
57 55  
58 56  
... ... @@ -57,24 +55,28 @@
57 55 char c;
58 56 char *str;
59 57  
60   - if(output == NULL){
  58 + if (output == NULL) {
61 59 output = &c;
62 60 len = sizeof(c);
63 61 }
64   -
  62 +
65 63 *output = '\0';
66   - ret = os_read_file(fd, &remain, sizeof(remain));
  64 + ret = read(fd, &remain, sizeof(remain));
67 65  
68 66 if (ret != sizeof(remain)) {
  67 + if (ret < 0)
  68 + ret = -errno;
69 69 expected = sizeof(remain);
70 70 str = "length";
71 71 goto err;
72 72 }
73 73  
74   - while(remain != 0){
  74 + while (remain != 0) {
75 75 expected = (remain < len) ? remain : len;
76   - ret = os_read_file(fd, output, expected);
  76 + ret = read(fd, output, expected);
77 77 if (ret != expected) {
  78 + if (ret < 0)
  79 + ret = -errno;
78 80 str = "data";
79 81 goto err;
80 82 }
81 83  
82 84  
83 85  
84 86  
... ... @@ -85,20 +87,22 @@
85 87  
86 88 err:
87 89 if (ret < 0)
88   - printk("read_output - read of %s failed, errno = %d\n", str, -ret);
  90 + printk(UM_KERN_ERR "read_output - read of %s failed, "
  91 + "errno = %d\n", str, -ret);
89 92 else
90   - printk("read_output - read of %s failed, read only %d of %d bytes\n", str, ret, expected);
  93 + printk(UM_KERN_ERR "read_output - read of %s failed, read only "
  94 + "%d of %d bytes\n", str, ret, expected);
91 95 }
92 96  
93 97 int net_read(int fd, void *buf, int len)
94 98 {
95 99 int n;
96 100  
97   - n = os_read_file(fd, buf, len);
  101 + n = read(fd, buf, len);
98 102  
99   - if(n == -EAGAIN)
  103 + if ((n < 0) && (errno == EAGAIN))
100 104 return 0;
101   - else if(n == 0)
  105 + else if (n == 0)
102 106 return -ENOTCONN;
103 107 return n;
104 108 }
105 109  
... ... @@ -108,12 +112,12 @@
108 112 int n;
109 113  
110 114 CATCH_EINTR(n = recvfrom(fd, buf, len, 0, NULL, NULL));
111   - if(n < 0){
112   - if(errno == EAGAIN)
  115 + if (n < 0) {
  116 + if (errno == EAGAIN)
113 117 return 0;
114 118 return -errno;
115 119 }
116   - else if(n == 0)
  120 + else if (n == 0)
117 121 return -ENOTCONN;
118 122 return n;
119 123 }
120 124  
121 125  
... ... @@ -122,11 +126,11 @@
122 126 {
123 127 int n;
124 128  
125   - n = os_write_file(fd, buf, len);
  129 + n = write(fd, buf, len);
126 130  
127   - if(n == -EAGAIN)
  131 + if ((n < 0) && (errno == EAGAIN))
128 132 return 0;
129   - else if(n == 0)
  133 + else if (n == 0)
130 134 return -ENOTCONN;
131 135 return n;
132 136 }
133 137  
... ... @@ -136,12 +140,12 @@
136 140 int n;
137 141  
138 142 CATCH_EINTR(n = send(fd, buf, len, 0));
139   - if(n < 0){
140   - if(errno == EAGAIN)
  143 + if (n < 0) {
  144 + if (errno == EAGAIN)
141 145 return 0;
142 146 return -errno;
143 147 }
144   - else if(n == 0)
  148 + else if (n == 0)
145 149 return -ENOTCONN;
146 150 return n;
147 151 }
148 152  
... ... @@ -152,12 +156,12 @@
152 156  
153 157 CATCH_EINTR(n = sendto(fd, buf, len, 0, (struct sockaddr *) to,
154 158 sock_len));
155   - if(n < 0){
156   - if(errno == EAGAIN)
  159 + if (n < 0) {
  160 + if (errno == EAGAIN)
157 161 return 0;
158 162 return -errno;
159 163 }
160   - else if(n == 0)
  164 + else if (n == 0)
161 165 return -ENOTCONN;
162 166 return n;
163 167 }
... ... @@ -171,7 +175,7 @@
171 175 {
172 176 struct change_pre_exec_data *data = arg;
173 177  
174   - os_close_file(data->close_me);
  178 + close(data->close_me);
175 179 dup2(data->stdout, 1);
176 180 }
177 181  
... ... @@ -181,8 +185,9 @@
181 185 struct change_pre_exec_data pe_data;
182 186  
183 187 err = os_pipe(fds, 1, 0);
184   - if(err < 0){
185   - printk("change_tramp - pipe failed, err = %d\n", -err);
  188 + if (err < 0) {
  189 + printk(UM_KERN_ERR "change_tramp - pipe failed, err = %d\n",
  190 + -err);
186 191 return err;
187 192 }
188 193 pe_data.close_me = fds[0];
... ... @@ -192,8 +197,8 @@
192 197 if (pid > 0) /* Avoid hang as we won't get data in failure case. */
193 198 read_output(fds[0], output, output_len);
194 199  
195   - os_close_file(fds[0]);
196   - os_close_file(fds[1]);
  200 + close(fds[0]);
  201 + close(fds[1]);
197 202  
198 203 if (pid > 0)
199 204 CATCH_EINTR(err = waitpid(pid, NULL, 0));
200 205  
201 206  
202 207  
203 208  
... ... @@ -206,25 +211,26 @@
206 211 char addr_buf[sizeof("255.255.255.255\0")];
207 212 char netmask_buf[sizeof("255.255.255.255\0")];
208 213 char version[sizeof("nnnnn\0")];
209   - char *argv[] = { "uml_net", version, what, dev, addr_buf,
  214 + char *argv[] = { "uml_net", version, what, dev, addr_buf,
210 215 netmask_buf, NULL };
211 216 char *output;
212 217 int output_len, pid;
213 218  
214 219 sprintf(version, "%d", UML_NET_VERSION);
215 220 sprintf(addr_buf, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
216   - sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1],
  221 + sprintf(netmask_buf, "%d.%d.%d.%d", netmask[0], netmask[1],
217 222 netmask[2], netmask[3]);
218 223  
219 224 output_len = UM_KERN_PAGE_SIZE;
220 225 output = kmalloc(output_len, UM_GFP_KERNEL);
221   - if(output == NULL)
222   - printk("change : failed to allocate output buffer\n");
  226 + if (output == NULL)
  227 + printk(UM_KERN_ERR "change : failed to allocate output "
  228 + "buffer\n");
223 229  
224 230 pid = change_tramp(argv, output, output_len);
225   - if(pid < 0) return;
  231 + if (pid < 0) return;
226 232  
227   - if(output != NULL){
  233 + if (output != NULL) {
228 234 printk("%s", output);
229 235 kfree(output);
230 236 }
231 237  
232 238  
... ... @@ -246,13 +252,13 @@
246 252 va_list ap;
247 253  
248 254 va_start(ap, str);
249   - while((arg = va_arg(ap, char **)) != NULL){
250   - if(*str == '\0')
  255 + while ((arg = va_arg(ap, char **)) != NULL) {
  256 + if (*str == '\0')
251 257 return NULL;
252 258 end = strchr(str, ',');
253   - if(end != str)
  259 + if (end != str)
254 260 *arg = str;
255   - if(end == NULL)
  261 + if (end == NULL)
256 262 return NULL;
257 263 *end++ = '\0';
258 264 str = end;
arch/um/drivers/pcap_kern.c
1 1 /*
2   - * Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
  2 + * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL.
4 4 */
5 5  
6 6 #include "linux/init.h"
7   -#include "linux/netdevice.h"
8   -#include "linux/etherdevice.h"
  7 +#include <linux/netdevice.h>
9 8 #include "net_kern.h"
10   -#include "net_user.h"
11 9 #include "pcap_user.h"
12 10  
13 11 struct pcap_init {
... ... @@ -37,7 +35,7 @@
37 35 struct uml_net_private *lp)
38 36 {
39 37 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
40   - if(*skb == NULL)
  38 + if (*skb == NULL)
41 39 return -ENOMEM;
42 40  
43 41 return pcap_user_read(fd, skb_mac_header(*skb),
44 42  
45 43  
46 44  
47 45  
48 46  
49 47  
50 48  
... ... @@ -71,28 +69,29 @@
71 69  
72 70 remain = split_if_spec(str, &host_if, &init->filter,
73 71 &options[0], &options[1], mac_out, NULL);
74   - if(remain != NULL){
  72 + if (remain != NULL) {
75 73 printk(KERN_ERR "pcap_setup - Extra garbage on "
76 74 "specification : '%s'\n", remain);
77 75 return 0;
78 76 }
79 77  
80   - if(host_if != NULL)
  78 + if (host_if != NULL)
81 79 init->host_if = host_if;
82 80  
83   - for(i = 0; i < ARRAY_SIZE(options); i++){
84   - if(options[i] == NULL)
  81 + for (i = 0; i < ARRAY_SIZE(options); i++) {
  82 + if (options[i] == NULL)
85 83 continue;
86   - if(!strcmp(options[i], "promisc"))
  84 + if (!strcmp(options[i], "promisc"))
87 85 init->promisc = 1;
88   - else if(!strcmp(options[i], "nopromisc"))
  86 + else if (!strcmp(options[i], "nopromisc"))
89 87 init->promisc = 0;
90   - else if(!strcmp(options[i], "optimize"))
  88 + else if (!strcmp(options[i], "optimize"))
91 89 init->optimize = 1;
92   - else if(!strcmp(options[i], "nooptimize"))
  90 + else if (!strcmp(options[i], "nooptimize"))
93 91 init->optimize = 0;
94 92 else {
95   - printk("pcap_setup : bad option - '%s'\n", options[i]);
  93 + printk(KERN_ERR "pcap_setup : bad option - '%s'\n",
  94 + options[i]);
96 95 return 0;
97 96 }
98 97 }
arch/um/drivers/pcap_user.c
1 1 /*
2   - * Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
  2 + * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL.
4 4 */
5 5  
6   -#include <unistd.h>
7   -#include <stdlib.h>
8   -#include <string.h>
9 6 #include <errno.h>
10 7 #include <pcap.h>
  8 +#include <string.h>
11 9 #include <asm/types.h>
12 10 #include "net_user.h"
13 11 #include "pcap_user.h"
14   -#include "user.h"
15   -#include "um_malloc.h"
16 12 #include "kern_constants.h"
  13 +#include "um_malloc.h"
  14 +#include "user.h"
17 15  
18 16 #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
19 17  
... ... @@ -26,7 +24,7 @@
26 24 char errors[PCAP_ERRBUF_SIZE];
27 25  
28 26 p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors);
29   - if(p == NULL){
  27 + if (p == NULL) {
30 28 printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - "
31 29 "'%s'\n", errors);
32 30 return -EINVAL;
33 31  
34 32  
35 33  
36 34  
37 35  
38 36  
39 37  
40 38  
41 39  
42 40  
43 41  
... ... @@ -43,50 +41,55 @@
43 41 __u32 netmask;
44 42 int err;
45 43  
46   - if(pri->pcap == NULL)
  44 + if (pri->pcap == NULL)
47 45 return -ENODEV;
48 46  
49   - if(pri->filter != NULL){
  47 + if (pri->filter != NULL) {
50 48 err = dev_netmask(pri->dev, &netmask);
51   - if(err < 0){
  49 + if (err < 0) {
52 50 printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
53 51 return -EIO;
54 52 }
55 53  
56   - pri->compiled = kmalloc(sizeof(struct bpf_program), UM_GFP_KERNEL);
57   - if(pri->compiled == NULL){
  54 + pri->compiled = kmalloc(sizeof(struct bpf_program),
  55 + UM_GFP_KERNEL);
  56 + if (pri->compiled == NULL) {
58 57 printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
59 58 return -ENOMEM;
60 59 }
61 60  
62   - err = pcap_compile(pri->pcap,
63   - (struct bpf_program *) pri->compiled,
  61 + err = pcap_compile(pri->pcap,
  62 + (struct bpf_program *) pri->compiled,
64 63 pri->filter, pri->optimize, netmask);
65   - if(err < 0){
  64 + if (err < 0) {
66 65 printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
67 66 "'%s'\n", pcap_geterr(pri->pcap));
68   - return -EIO;
  67 + goto out;
69 68 }
70 69  
71 70 err = pcap_setfilter(pri->pcap, pri->compiled);
72   - if(err < 0){
  71 + if (err < 0) {
73 72 printk(UM_KERN_ERR "pcap_open : pcap_setfilter "
74 73 "failed - '%s'\n", pcap_geterr(pri->pcap));
75   - return -EIO;
  74 + goto out;
76 75 }
77 76 }
78 77  
79 78 return PCAP_FD(pri->pcap);
  79 +
  80 + out:
  81 + kfree(pri->compiled);
  82 + return -EIO;
80 83 }
81 84  
82 85 static void pcap_remove(void *data)
83 86 {
84 87 struct pcap_data *pri = data;
85 88  
86   - if(pri->compiled != NULL)
  89 + if (pri->compiled != NULL)
87 90 pcap_freecode(pri->compiled);
88 91  
89   - if(pri->pcap != NULL)
  92 + if (pri->pcap != NULL)
90 93 pcap_close(pri->pcap);
91 94 }
92 95  
... ... @@ -95,7 +98,7 @@
95 98 int len;
96 99 };
97 100  
98   -static void handler(u_char *data, const struct pcap_pkthdr *header,
  101 +static void handler(u_char *data, const struct pcap_pkthdr *header,
99 102 const u_char *packet)
100 103 {
101 104 int len;
102 105  
... ... @@ -115,12 +118,12 @@
115 118 int n;
116 119  
117 120 n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata);
118   - if(n < 0){
  121 + if (n < 0) {
119 122 printk(UM_KERN_ERR "pcap_dispatch failed - %s\n",
120 123 pcap_geterr(pri->pcap));
121 124 return -EIO;
122 125 }
123   - else if(n == 0)
  126 + else if (n == 0)
124 127 return 0;
125 128 return hdata.len;
126 129 }
arch/um/drivers/slip_kern.c
1   -#include "linux/kernel.h"
2   -#include "linux/stddef.h"
3   -#include "linux/init.h"
4   -#include "linux/netdevice.h"
5   -#include "linux/if_arp.h"
  1 +/*
  2 + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 + * Licensed under the GPL.
  4 + */
  5 +
  6 +#include <linux/if_arp.h>
  7 +#include <linux/init.h>
  8 +#include <linux/netdevice.h>
6 9 #include "net_kern.h"
7   -#include "net_user.h"
8   -#include "kern.h"
9 10 #include "slip.h"
10 11  
11 12 struct slip_init {
12 13  
13 14  
14 15  
... ... @@ -43,21 +44,21 @@
43 44  
44 45 static unsigned short slip_protocol(struct sk_buff *skbuff)
45 46 {
46   - return(htons(ETH_P_IP));
  47 + return htons(ETH_P_IP);
47 48 }
48 49  
49   -static int slip_read(int fd, struct sk_buff **skb,
  50 +static int slip_read(int fd, struct sk_buff **skb,
50 51 struct uml_net_private *lp)
51 52 {
52   - return(slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
53   - (struct slip_data *) &lp->user));
  53 + return slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
  54 + (struct slip_data *) &lp->user);
54 55 }
55 56  
56 57 static int slip_write(int fd, struct sk_buff **skb,
57 58 struct uml_net_private *lp)
58 59 {
59   - return(slip_user_write(fd, (*skb)->data, (*skb)->len,
60   - (struct slip_data *) &lp->user));
  60 + return slip_user_write(fd, (*skb)->data, (*skb)->len,
  61 + (struct slip_data *) &lp->user);
61 62 }
62 63  
63 64 const struct net_kern_info slip_kern_info = {
64 65  
65 66  
... ... @@ -71,12 +72,11 @@
71 72 {
72 73 struct slip_init *init = data;
73 74  
74   - *init = ((struct slip_init)
75   - { .gate_addr = NULL });
  75 + *init = ((struct slip_init) { .gate_addr = NULL });
76 76  
77   - if(str[0] != '\0')
  77 + if (str[0] != '\0')
78 78 init->gate_addr = str;
79   - return(1);
  79 + return 1;
80 80 }
81 81  
82 82 static struct transport slip_transport = {
arch/um/drivers/slip_user.c
  1 +/*
  2 + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 + * Licensed under the GPL.
  4 + */
  5 +
1 6 #include <stdio.h>
2 7 #include <stdlib.h>
3 8 #include <unistd.h>
4   -#include <stddef.h>
5   -#include <sched.h>
6   -#include <string.h>
7 9 #include <errno.h>
  10 +#include <fcntl.h>
  11 +#include <string.h>
8 12 #include <sys/termios.h>
9 13 #include <sys/wait.h>
10   -#include <sys/signal.h>
11   -#include "kern_util.h"
12   -#include "user.h"
  14 +#include "kern_constants.h"
13 15 #include "net_user.h"
14   -#include "slip.h"
15   -#include "slip_common.h"
16 16 #include "os.h"
  17 +#include "slip.h"
17 18 #include "um_malloc.h"
18   -#include "kern_constants.h"
  19 +#include "user.h"
19 20  
20 21 static int slip_user_init(void *data, void *dev)
21 22 {
... ... @@ -31,8 +32,9 @@
31 32 struct termios tios;
32 33  
33 34 if (tcgetattr(fd, &tios) < 0) {
34   - printk("could not get initial terminal attributes\n");
35   - return(-1);
  35 + printk(UM_KERN_ERR "could not get initial terminal "
  36 + "attributes\n");
  37 + return -1;
36 38 }
37 39  
38 40 tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL;
39 41  
... ... @@ -48,10 +50,10 @@
48 50 cfsetispeed(&tios, B38400);
49 51  
50 52 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
51   - printk("failed to set terminal attributes\n");
52   - return(-1);
  53 + printk(UM_KERN_ERR "failed to set terminal attributes\n");
  54 + return -1;
53 55 }
54   - return(0);
  56 + return 0;
55 57 }
56 58  
57 59 struct slip_pre_exec_data {
58 60  
... ... @@ -64,9 +66,11 @@
64 66 {
65 67 struct slip_pre_exec_data *data = arg;
66 68  
67   - if(data->stdin >= 0) dup2(data->stdin, 0);
  69 + if (data->stdin >= 0)
  70 + dup2(data->stdin, 0);
68 71 dup2(data->stdout, 1);
69   - if(data->close_me >= 0) os_close_file(data->close_me);
  72 + if (data->close_me >= 0)
  73 + close(data->close_me);
70 74 }
71 75  
72 76 static int slip_tramp(char **argv, int fd)
... ... @@ -76,8 +80,9 @@
76 80 int status, pid, fds[2], err, output_len;
77 81  
78 82 err = os_pipe(fds, 1, 0);
79   - if(err < 0){
80   - printk("slip_tramp : pipe failed, err = %d\n", -err);
  83 + if (err < 0) {
  84 + printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n",
  85 + -err);
81 86 goto out;
82 87 }
83 88  
84 89  
85 90  
86 91  
87 92  
88 93  
89 94  
... ... @@ -86,41 +91,42 @@
86 91 pe_data.stdout = fds[1];
87 92 pe_data.close_me = fds[0];
88 93 err = run_helper(slip_pre_exec, &pe_data, argv);
89   - if(err < 0)
  94 + if (err < 0)
90 95 goto out_close;
91 96 pid = err;
92 97  
93 98 output_len = UM_KERN_PAGE_SIZE;
94 99 output = kmalloc(output_len, UM_GFP_KERNEL);
95   - if(output == NULL){
96   - printk("slip_tramp : failed to allocate output buffer\n");
  100 + if (output == NULL) {
  101 + printk(UM_KERN_ERR "slip_tramp : failed to allocate output "
  102 + "buffer\n");
97 103 os_kill_process(pid, 1);
98 104 err = -ENOMEM;
99 105 goto out_free;
100 106 }
101 107  
102   - os_close_file(fds[1]);
  108 + close(fds[1]);
103 109 read_output(fds[0], output, output_len);
104 110 printk("%s", output);
105 111  
106 112 CATCH_EINTR(err = waitpid(pid, &status, 0));
107   - if(err < 0)
  113 + if (err < 0)
108 114 err = errno;
109   - else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){
110   - printk("'%s' didn't exit with status 0\n", argv[0]);
  115 + else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
  116 + printk(UM_KERN_ERR "'%s' didn't exit with status 0\n", argv[0]);
111 117 err = -EINVAL;
112 118 }
113 119 else err = 0;
114 120  
115   - os_close_file(fds[0]);
  121 + close(fds[0]);
116 122  
117 123 out_free:
118 124 kfree(output);
119 125 return err;
120 126  
121 127 out_close:
122   - os_close_file(fds[0]);
123   - os_close_file(fds[1]);
  128 + close(fds[0]);
  129 + close(fds[1]);
124 130 out:
125 131 return err;
126 132 }
127 133  
128 134  
129 135  
130 136  
131 137  
132 138  
133 139  
134 140  
135 141  
136 142  
... ... @@ -130,60 +136,64 @@
130 136 struct slip_data *pri = data;
131 137 char version_buf[sizeof("nnnnn\0")];
132 138 char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")];
133   - char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf,
  139 + char *argv[] = { "uml_net", version_buf, "slip", "up", gate_buf,
134 140 NULL };
135 141 int sfd, mfd, err;
136 142  
137 143 err = get_pty();
138   - if(err < 0){
139   - printk("slip-open : Failed to open pty, err = %d\n", -err);
  144 + if (err < 0) {
  145 + printk(UM_KERN_ERR "slip-open : Failed to open pty, err = %d\n",
  146 + -err);
140 147 goto out;
141 148 }
142 149 mfd = err;
143 150  
144   - err = os_open_file(ptsname(mfd), of_rdwr(OPENFLAGS()), 0);
145   - if(err < 0){
146   - printk("Couldn't open tty for slip line, err = %d\n", -err);
  151 + err = open(ptsname(mfd), O_RDWR, 0);
  152 + if (err < 0) {
  153 + printk(UM_KERN_ERR "Couldn't open tty for slip line, "
  154 + "err = %d\n", -err);
147 155 goto out_close;
148 156 }
149 157 sfd = err;
150 158  
151   - if(set_up_tty(sfd))
  159 + if (set_up_tty(sfd))
152 160 goto out_close2;
153 161  
154 162 pri->slave = sfd;
155 163 pri->slip.pos = 0;
156 164 pri->slip.esc = 0;
157   - if(pri->gate_addr != NULL){
  165 + if (pri->gate_addr != NULL) {
158 166 sprintf(version_buf, "%d", UML_NET_VERSION);
159 167 strcpy(gate_buf, pri->gate_addr);
160 168  
161 169 err = slip_tramp(argv, sfd);
162 170  
163   - if(err < 0){
164   - printk("slip_tramp failed - err = %d\n", -err);
  171 + if (err < 0) {
  172 + printk(UM_KERN_ERR "slip_tramp failed - err = %d\n",
  173 + -err);
165 174 goto out_close2;
166 175 }
167 176 err = os_get_ifname(pri->slave, pri->name);
168   - if(err < 0){
169   - printk("get_ifname failed, err = %d\n", -err);
  177 + if (err < 0) {
  178 + printk(UM_KERN_ERR "get_ifname failed, err = %d\n",
  179 + -err);
170 180 goto out_close2;
171 181 }
172 182 iter_addresses(pri->dev, open_addr, pri->name);
173 183 }
174 184 else {
175 185 err = os_set_slip(sfd);
176   - if(err < 0){
177   - printk("Failed to set slip discipline encapsulation - "
178   - "err = %d\n", -err);
  186 + if (err < 0) {
  187 + printk(UM_KERN_ERR "Failed to set slip discipline "
  188 + "encapsulation - err = %d\n", -err);
179 189 goto out_close2;
180 190 }
181 191 }
182   - return(mfd);
  192 + return mfd;
183 193 out_close2:
184   - os_close_file(sfd);
  194 + close(sfd);
185 195 out_close:
186   - os_close_file(mfd);
  196 + close(mfd);
187 197 out:
188 198 return err;
189 199 }
190 200  
191 201  
... ... @@ -192,21 +202,21 @@
192 202 {
193 203 struct slip_data *pri = data;
194 204 char version_buf[sizeof("nnnnn\0")];
195   - char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name,
  205 + char *argv[] = { "uml_net", version_buf, "slip", "down", pri->name,
196 206 NULL };
197 207 int err;
198 208  
199   - if(pri->gate_addr != NULL)
  209 + if (pri->gate_addr != NULL)
200 210 iter_addresses(pri->dev, close_addr, pri->name);
201 211  
202 212 sprintf(version_buf, "%d", UML_NET_VERSION);
203 213  
204 214 err = slip_tramp(argv, pri->slave);
205 215  
206   - if(err != 0)
207   - printk("slip_tramp failed - errno = %d\n", -err);
208   - os_close_file(fd);
209   - os_close_file(pri->slave);
  216 + if (err != 0)
  217 + printk(UM_KERN_ERR "slip_tramp failed - errno = %d\n", -err);
  218 + close(fd);
  219 + close(pri->slave);
210 220 pri->slave = -1;
211 221 }
212 222  
... ... @@ -222,7 +232,7 @@
222 232  
223 233 static int slip_set_mtu(int mtu, void *data)
224 234 {
225   - return(mtu);
  235 + return mtu;
226 236 }
227 237  
228 238 static void slip_add_addr(unsigned char *addr, unsigned char *netmask,
... ... @@ -230,7 +240,8 @@
230 240 {
231 241 struct slip_data *pri = data;
232 242  
233   - if(pri->slave < 0) return;
  243 + if (pri->slave < 0)
  244 + return;
234 245 open_addr(addr, netmask, pri->name);
235 246 }
236 247  
... ... @@ -239,7 +250,8 @@
239 250 {
240 251 struct slip_data *pri = data;
241 252  
242   - if(pri->slave < 0) return;
  253 + if (pri->slave < 0)
  254 + return;
243 255 close_addr(addr, netmask, pri->name);
244 256 }
245 257  
arch/um/drivers/slirp_kern.c
1   -#include "linux/kernel.h"
2   -#include "linux/stddef.h"
  1 +/*
  2 + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 + * Licensed under the GPL.
  4 + */
  5 +
  6 +#include <linux/if_arp.h>
3 7 #include "linux/init.h"
4   -#include "linux/netdevice.h"
5   -#include "linux/if_arp.h"
  8 +#include <linux/netdevice.h>
  9 +#include <linux/string.h>
6 10 #include "net_kern.h"
7 11 #include "net_user.h"
8   -#include "kern.h"
9 12 #include "slirp.h"
10 13  
11 14 struct slirp_init {
12 15  
13 16  
14 17  
15 18  
16 19  
... ... @@ -39,29 +42,28 @@
39 42 dev->tx_queue_len = 256;
40 43 dev->flags = IFF_NOARP;
41 44 printk("SLIRP backend - command line:");
42   - for(i=0;spri->argw.argv[i]!=NULL;i++) {
  45 + for (i = 0; spri->argw.argv[i] != NULL; i++)
43 46 printk(" '%s'",spri->argw.argv[i]);
44   - }
45 47 printk("\n");
46 48 }
47 49  
48 50 static unsigned short slirp_protocol(struct sk_buff *skbuff)
49 51 {
50   - return(htons(ETH_P_IP));
  52 + return htons(ETH_P_IP);
51 53 }
52 54  
53   -static int slirp_read(int fd, struct sk_buff **skb,
  55 +static int slirp_read(int fd, struct sk_buff **skb,
54 56 struct uml_net_private *lp)
55 57 {
56   - return(slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
57   - (struct slirp_data *) &lp->user));
  58 + return slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
  59 + (struct slirp_data *) &lp->user);
58 60 }
59 61  
60 62 static int slirp_write(int fd, struct sk_buff **skb,
61 63 struct uml_net_private *lp)
62 64 {
63   - return(slirp_user_write(fd, (*skb)->data, (*skb)->len,
64   - (struct slirp_data *) &lp->user));
  65 + return slirp_user_write(fd, (*skb)->data, (*skb)->len,
  66 + (struct slirp_data *) &lp->user);
65 67 }
66 68  
67 69 const struct net_kern_info slirp_kern_info = {
68 70  
69 71  
70 72  
71 73  
72 74  
... ... @@ -76,31 +78,32 @@
76 78 struct slirp_init *init = data;
77 79 int i=0;
78 80  
79   - *init = ((struct slirp_init)
80   - { .argw = { { "slirp", NULL } } });
  81 + *init = ((struct slirp_init) { .argw = { { "slirp", NULL } } });
81 82  
82 83 str = split_if_spec(str, mac_out, NULL);
83 84  
84   - if(str == NULL) { /* no command line given after MAC addr */
85   - return(1);
86   - }
  85 + if (str == NULL) /* no command line given after MAC addr */
  86 + return 1;
87 87  
88 88 do {
89   - if(i>=SLIRP_MAX_ARGS-1) {
90   - printk("slirp_setup: truncating slirp arguments\n");
  89 + if (i >= SLIRP_MAX_ARGS - 1) {
  90 + printk(KERN_WARNING "slirp_setup: truncating slirp "
  91 + "arguments\n");
91 92 break;
92 93 }
93 94 init->argw.argv[i++] = str;
94 95 while(*str && *str!=',') {
95   - if(*str=='_') *str=' ';
  96 + if (*str == '_')
  97 + *str=' ';
96 98 str++;
97 99 }
98   - if(*str!=',')
  100 + if (*str != ',')
99 101 break;
100   - *str++='\0';
101   - } while(1);
102   - init->argw.argv[i]=NULL;
103   - return(1);
  102 + *str++ = '\0';
  103 + } while (1);
  104 +
  105 + init->argw.argv[i] = NULL;
  106 + return 1;
104 107 }
105 108  
106 109 static struct transport slirp_transport = {
arch/um/drivers/slirp_user.c
1   -#include <stdio.h>
2   -#include <stdlib.h>
  1 +/*
  2 + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 + * Licensed under the GPL.
  4 + */
  5 +
3 6 #include <unistd.h>
4   -#include <stddef.h>
5   -#include <sched.h>
6   -#include <string.h>
7 7 #include <errno.h>
  8 +#include <string.h>
8 9 #include <sys/wait.h>
9   -#include <sys/signal.h>
10   -#include "kern_util.h"
11   -#include "user.h"
  10 +#include "kern_constants.h"
12 11 #include "net_user.h"
13   -#include "slirp.h"
14   -#include "slip_common.h"
15 12 #include "os.h"
  13 +#include "slirp.h"
  14 +#include "user.h"
16 15  
17 16 static int slirp_user_init(void *data, void *dev)
18 17 {
... ... @@ -31,8 +30,10 @@
31 30 {
32 31 struct slirp_pre_exec_data *data = arg;
33 32  
34   - if(data->stdin != -1) dup2(data->stdin, 0);
35   - if(data->stdout != -1) dup2(data->stdout, 1);
  33 + if (data->stdin != -1)
  34 + dup2(data->stdin, 0);
  35 + if (data->stdout != -1)
  36 + dup2(data->stdout, 1);
36 37 }
37 38  
38 39 static int slirp_tramp(char **argv, int fd)
... ... @@ -44,7 +45,7 @@
44 45 pe_data.stdout = fd;
45 46 pid = run_helper(slirp_pre_exec, &pe_data, argv);
46 47  
47   - return(pid);
  48 + return pid;
48 49 }
49 50  
50 51 static int slirp_open(void *data)
51 52  
... ... @@ -53,12 +54,12 @@
53 54 int fds[2], pid, err;
54 55  
55 56 err = os_pipe(fds, 1, 1);
56   - if(err)
57   - return(err);
  57 + if (err)
  58 + return err;
58 59  
59 60 err = slirp_tramp(pri->argw.argv, fds[1]);
60   - if(err < 0){
61   - printk("slirp_tramp failed - errno = %d\n", -err);
  61 + if (err < 0) {
  62 + printk(UM_KERN_ERR "slirp_tramp failed - errno = %d\n", -err);
62 63 goto out;
63 64 }
64 65 pid = err;
65 66  
... ... @@ -68,10 +69,10 @@
68 69 pri->slip.esc = 0;
69 70 pri->pid = err;
70 71  
71   - return(fds[0]);
  72 + return fds[0];
72 73 out:
73   - os_close_file(fds[0]);
74   - os_close_file(fds[1]);
  74 + close(fds[0]);
  75 + close(fds[1]);
75 76 return err;
76 77 }
77 78  
78 79  
79 80  
80 81  
81 82  
... ... @@ -80,31 +81,33 @@
80 81 struct slirp_data *pri = data;
81 82 int status,err;
82 83  
83   - os_close_file(fd);
84   - os_close_file(pri->slave);
  84 + close(fd);
  85 + close(pri->slave);
85 86  
86 87 pri->slave = -1;
87 88  
88   - if(pri->pid<1) {
89   - printk("slirp_close: no child process to shut down\n");
  89 + if (pri->pid<1) {
  90 + printk(UM_KERN_ERR "slirp_close: no child process to shut "
  91 + "down\n");
90 92 return;
91 93 }
92 94  
93 95 #if 0
94   - if(kill(pri->pid, SIGHUP)<0) {
95   - printk("slirp_close: sending hangup to %d failed (%d)\n",
96   - pri->pid, errno);
  96 + if (kill(pri->pid, SIGHUP)<0) {
  97 + printk(UM_KERN_ERR "slirp_close: sending hangup to %d failed "
  98 + "(%d)\n", pri->pid, errno);
97 99 }
98 100 #endif
99 101  
100 102 CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
101   - if(err < 0) {
102   - printk("slirp_close: waitpid returned %d\n", errno);
  103 + if (err < 0) {
  104 + printk(UM_KERN_ERR "slirp_close: waitpid returned %d\n", errno);
103 105 return;
104 106 }
105 107  
106   - if(err == 0) {
107   - printk("slirp_close: process %d has not exited\n", pri->pid);
  108 + if (err == 0) {
  109 + printk(UM_KERN_ERR "slirp_close: process %d has not exited\n",
  110 + pri->pid);
108 111 return;
109 112 }
110 113  
... ... @@ -123,7 +126,7 @@
123 126  
124 127 static int slirp_set_mtu(int mtu, void *data)
125 128 {
126   - return(mtu);
  129 + return mtu;
127 130 }
128 131  
129 132 const struct net_user_info slirp_user_info = {
arch/um/drivers/vde_kern.c
... ... @@ -7,10 +7,8 @@
7 7 *
8 8 */
9 9  
10   -#include "linux/kernel.h"
11 10 #include "linux/init.h"
12   -#include "linux/netdevice.h"
13   -#include "linux/etherdevice.h"
  11 +#include <linux/netdevice.h>
14 12 #include "net_kern.h"
15 13 #include "net_user.h"
16 14 #include "vde.h"
17 15  
... ... @@ -30,12 +28,12 @@
30 28 vpri->conn = NULL;
31 29 vpri->dev = dev;
32 30  
33   - printk(KERN_INFO "vde backend - %s, ", vpri->vde_switch ?
  31 + printk("vde backend - %s, ", vpri->vde_switch ?
34 32 vpri->vde_switch : "(default socket)");
35 33  
36 34 vde_init_libstuff(vpri, init);
37 35  
38   - printk(KERN_INFO "\n");
  36 + printk("\n");
39 37 }
40 38  
41 39 static int vde_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
arch/um/drivers/vde_user.c
... ... @@ -3,15 +3,13 @@
3 3 * Licensed under the GPL.
4 4 */
5 5  
  6 +#include <stddef.h>
6 7 #include <errno.h>
7   -#include <unistd.h>
8 8 #include <libvdeplug.h>
9   -#include "net_user.h"
10   -#include "kern_util.h"
11 9 #include "kern_constants.h"
12   -#include "user.h"
13   -#include "os.h"
  10 +#include "net_user.h"
14 11 #include "um_malloc.h"
  12 +#include "user.h"
15 13 #include "vde.h"
16 14  
17 15 #define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
arch/um/os-Linux/drivers/etap.h
1 1 /*
2   - * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
  6 +#ifndef __DRIVERS_ETAP_H
  7 +#define __DRIVERS_ETAP_H
  8 +
6 9 #include "net_user.h"
7 10  
8 11 struct ethertap_data {
... ... @@ -15,14 +18,5 @@
15 18  
16 19 extern const struct net_user_info ethertap_user_info;
17 20  
18   -/*
19   - * Overrides for Emacs so that we follow Linus's tabbing style.
20   - * Emacs will notice this stuff at the end of the file and automatically
21   - * adjust the settings for this buffer only. This must remain at the end
22   - * of the file.
23   - * ---------------------------------------------------------------------------
24   - * Local variables:
25   - * c-file-style: "linux"
26   - * End:
27   - */
  21 +#endif
arch/um/os-Linux/drivers/ethertap_kern.c
1 1 /*
2   - * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
  2 + * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 3 * James Leu (jleu@mindspring.net).
  4 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 5 * Copyright (C) 2001 by various other people who didn't put their name here.
5 6 * Licensed under the GPL.
6 7 */
7 8  
8 9 #include "linux/init.h"
9   -#include "linux/netdevice.h"
10   -#include "linux/etherdevice.h"
11   -#include "net_kern.h"
12   -#include "net_user.h"
  10 +#include <linux/netdevice.h>
13 11 #include "etap.h"
  12 +#include "net_kern.h"
14 13  
15 14 struct ethertap_init {
16 15 char *dev_name;
17 16  
18 17  
19 18  
20 19  
21 20  
... ... @@ -42,27 +41,30 @@
42 41 int len;
43 42  
44 43 *skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP);
45   - if(*skb == NULL) return(-ENOMEM);
  44 + if (*skb == NULL)
  45 + return -ENOMEM;
46 46 len = net_recvfrom(fd, skb_mac_header(*skb),
47 47 (*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP);
48   - if(len <= 0) return(len);
  48 + if (len <= 0)
  49 + return len;
49 50 skb_pull(*skb, 2);
50 51 len -= 2;
51   - return(len);
  52 + return len;
52 53 }
53 54  
54 55 static int etap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
55 56 {
56   - if(skb_headroom(*skb) < 2){
  57 + if (skb_headroom(*skb) < 2) {
57 58 struct sk_buff *skb2;
58 59  
59 60 skb2 = skb_realloc_headroom(*skb, 2);
60 61 dev_kfree_skb(*skb);
61   - if (skb2 == NULL) return(-ENOMEM);
  62 + if (skb2 == NULL)
  63 + return -ENOMEM;
62 64 *skb = skb2;
63 65 }
64 66 skb_push(*skb, 2);
65   - return(net_send(fd, (*skb)->data, (*skb)->len));
  67 + return net_send(fd, (*skb)->data, (*skb)->len);
66 68 }
67 69  
68 70 const struct net_kern_info ethertap_kern_info = {
69 71  
70 72  
... ... @@ -79,15 +81,15 @@
79 81 *init = ((struct ethertap_init)
80 82 { .dev_name = NULL,
81 83 .gate_addr = NULL });
82   - if(tap_setup_common(str, "ethertap", &init->dev_name, mac_out,
  84 + if (tap_setup_common(str, "ethertap", &init->dev_name, mac_out,
83 85 &init->gate_addr))
84   - return(0);
85   - if(init->dev_name == NULL){
86   - printk("ethertap_setup : Missing tap device name\n");
87   - return(0);
  86 + return 0;
  87 + if (init->dev_name == NULL) {
  88 + printk(KERN_ERR "ethertap_setup : Missing tap device name\n");
  89 + return 0;
88 90 }
89 91  
90   - return(1);
  92 + return 1;
91 93 }
92 94  
93 95 static struct transport ethertap_transport = {
arch/um/os-Linux/drivers/ethertap_user.c
1 1 /*
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
2 3 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 4 * James Leu (jleu@mindspring.net).
4 5 * Copyright (C) 2001 by various other people who didn't put their name here.
5 6  
6 7  
7 8  
8 9  
... ... @@ -7,20 +8,16 @@
7 8  
8 9 #include <stdio.h>
9 10 #include <unistd.h>
10   -#include <stddef.h>
11   -#include <stdlib.h>
12   -#include <sys/errno.h>
  11 +#include <errno.h>
  12 +#include <string.h>
13 13 #include <sys/socket.h>
14 14 #include <sys/wait.h>
15   -#include <sys/un.h>
16   -#include <net/if.h>
17   -#include "user.h"
18   -#include "kern_util.h"
19   -#include "net_user.h"
20 15 #include "etap.h"
  16 +#include "kern_constants.h"
21 17 #include "os.h"
  18 +#include "net_user.h"
22 19 #include "um_malloc.h"
23   -#include "kern_constants.h"
  20 +#include "user.h"
24 21  
25 22 #define MAX_PACKET ETH_MAX_PACKET
26 23  
27 24  
28 25  
... ... @@ -49,16 +46,18 @@
49 46 memcpy(change.addr, addr, sizeof(change.addr));
50 47 memcpy(change.netmask, netmask, sizeof(change.netmask));
51 48 CATCH_EINTR(n = write(fd, &change, sizeof(change)));
52   - if(n != sizeof(change)){
53   - printk("etap_change - request failed, err = %d\n", errno);
  49 + if (n != sizeof(change)) {
  50 + printk(UM_KERN_ERR "etap_change - request failed, err = %d\n",
  51 + errno);
54 52 return;
55 53 }
56 54  
57 55 output = kmalloc(UM_KERN_PAGE_SIZE, UM_GFP_KERNEL);
58   - if(output == NULL)
59   - printk("etap_change : Failed to allocate output buffer\n");
  56 + if (output == NULL)
  57 + printk(UM_KERN_ERR "etap_change : Failed to allocate output "
  58 + "buffer\n");
60 59 read_output(fd, output, UM_KERN_PAGE_SIZE);
61   - if(output != NULL){
  60 + if (output != NULL) {
62 61 printk("%s", output);
63 62 kfree(output);
64 63 }
... ... @@ -107,7 +106,7 @@
107 106  
108 107 sprintf(data_fd_buf, "%d", data_remote);
109 108 sprintf(version_buf, "%d", UML_NET_VERSION);
110   - if(gate != NULL){
  109 + if (gate != NULL) {
111 110 strcpy(gate_buf, gate);
112 111 args = setup_args;
113 112 }
114 113  
115 114  
116 115  
117 116  
118 117  
... ... @@ -119,24 +118,26 @@
119 118 pe_data.data_me = data_me;
120 119 pid = run_helper(etap_pre_exec, &pe_data, args);
121 120  
122   - if(pid < 0)
  121 + if (pid < 0)
123 122 err = pid;
124 123 close(data_remote);
125 124 close(control_remote);
126 125 CATCH_EINTR(n = read(control_me, &c, sizeof(c)));
127   - if(n != sizeof(c)){
  126 + if (n != sizeof(c)) {
128 127 err = -errno;
129   - printk("etap_tramp : read of status failed, err = %d\n", -err);
  128 + printk(UM_KERN_ERR "etap_tramp : read of status failed, "
  129 + "err = %d\n", -err);
130 130 return err;
131 131 }
132   - if(c != 1){
133   - printk("etap_tramp : uml_net failed\n");
  132 + if (c != 1) {
  133 + printk(UM_KERN_ERR "etap_tramp : uml_net failed\n");
134 134 err = -EINVAL;
135 135 CATCH_EINTR(n = waitpid(pid, &status, 0));
136   - if(n < 0)
  136 + if (n < 0)
137 137 err = -errno;
138   - else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1))
139   - printk("uml_net didn't exit with status 1\n");
  138 + else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 1))
  139 + printk(UM_KERN_ERR "uml_net didn't exit with "
  140 + "status 1\n");
140 141 }
141 142 return err;
142 143 }
143 144  
144 145  
145 146  
146 147  
... ... @@ -148,22 +149,22 @@
148 149 int data_fds[2], control_fds[2], err, output_len;
149 150  
150 151 err = tap_open_common(pri->dev, pri->gate_addr);
151   - if(err)
  152 + if (err)
152 153 return err;
153 154  
154 155 err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds);
155   - if(err){
  156 + if (err) {
156 157 err = -errno;
157   - printk("etap_open - data socketpair failed - err = %d\n",
158   - errno);
  158 + printk(UM_KERN_ERR "etap_open - data socketpair failed - "
  159 + "err = %d\n", errno);
159 160 return err;
160 161 }
161 162  
162 163 err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds);
163   - if(err){
  164 + if (err) {
164 165 err = -errno;
165   - printk("etap_open - control socketpair failed - err = %d\n",
166   - errno);
  166 + printk(UM_KERN_ERR "etap_open - control socketpair failed - "
  167 + "err = %d\n", errno);
167 168 goto out_close_data;
168 169 }
169 170  
170 171  
... ... @@ -173,15 +174,16 @@
173 174 output = kmalloc(output_len, UM_GFP_KERNEL);
174 175 read_output(control_fds[0], output, output_len);
175 176  
176   - if(output == NULL)
177   - printk("etap_open : failed to allocate output buffer\n");
  177 + if (output == NULL)
  178 + printk(UM_KERN_ERR "etap_open : failed to allocate output "
  179 + "buffer\n");
178 180 else {
179 181 printk("%s", output);
180 182 kfree(output);
181 183 }
182 184  
183   - if(err < 0){
184   - printk("etap_tramp failed - err = %d\n", -err);
  185 + if (err < 0) {
  186 + printk(UM_KERN_ERR "etap_tramp failed - err = %d\n", -err);
185 187 goto out_close_control;
186 188 }
187 189  
188 190  
... ... @@ -206,14 +208,14 @@
206 208 iter_addresses(pri->dev, etap_close_addr, &pri->control_fd);
207 209 close(fd);
208 210  
209   - if(shutdown(pri->data_fd, SHUT_RDWR) < 0)
210   - printk("etap_close - shutdown data socket failed, errno = %d\n",
211   - errno);
212   -
213   - if(shutdown(pri->control_fd, SHUT_RDWR) < 0)
214   - printk("etap_close - shutdown control socket failed, "
  211 + if (shutdown(pri->data_fd, SHUT_RDWR) < 0)
  212 + printk(UM_KERN_ERR "etap_close - shutdown data socket failed, "
215 213 "errno = %d\n", errno);
216 214  
  215 + if (shutdown(pri->control_fd, SHUT_RDWR) < 0)
  216 + printk(UM_KERN_ERR "etap_close - shutdown control socket "
  217 + "failed, errno = %d\n", errno);
  218 +
217 219 close(pri->data_fd);
218 220 pri->data_fd = -1;
219 221 close(pri->control_fd);
... ... @@ -231,7 +233,7 @@
231 233 struct ethertap_data *pri = data;
232 234  
233 235 tap_check_ips(pri->gate_addr, addr);
234   - if(pri->control_fd == -1)
  236 + if (pri->control_fd == -1)
235 237 return;
236 238 etap_open_addr(addr, netmask, &pri->control_fd);
237 239 }
... ... @@ -241,7 +243,7 @@
241 243 {
242 244 struct ethertap_data *pri = data;
243 245  
244   - if(pri->control_fd == -1)
  246 + if (pri->control_fd == -1)
245 247 return;
246 248  
247 249 etap_close_addr(addr, netmask, &pri->control_fd);
arch/um/os-Linux/drivers/tuntap.h
1 1 /*
2   - * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
... ... @@ -19,15 +19,4 @@
19 19 extern const struct net_user_info tuntap_user_info;
20 20  
21 21 #endif
22   -
23   -/*
24   - * Overrides for Emacs so that we follow Linus's tabbing style.
25   - * Emacs will notice this stuff at the end of the file and automatically
26   - * adjust the settings for this buffer only. This must remain at the end
27   - * of the file.
28   - * ---------------------------------------------------------------------------
29   - * Local variables:
30   - * c-file-style: "linux"
31   - * End:
32   - */
arch/um/os-Linux/drivers/tuntap_kern.c
1   -/*
2   - * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
  1 +/*
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
6   -#include "linux/stddef.h"
7   -#include "linux/netdevice.h"
8   -#include "linux/etherdevice.h"
9   -#include "linux/skbuff.h"
10   -#include "linux/init.h"
11   -#include "asm/errno.h"
  6 +#include <linux/netdevice.h>
  7 +#include <linux/init.h>
  8 +#include <linux/skbuff.h>
  9 +#include <asm/errno.h>
12 10 #include "net_kern.h"
13   -#include "net_user.h"
14 11 #include "tuntap.h"
15 12  
16 13 struct tuntap_init {
17 14  
18 15  
19 16  
... ... @@ -38,19 +35,20 @@
38 35 printk("\n");
39 36 }
40 37  
41   -static int tuntap_read(int fd, struct sk_buff **skb,
  38 +static int tuntap_read(int fd, struct sk_buff **skb,
42 39 struct uml_net_private *lp)
43 40 {
44 41 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
45   - if(*skb == NULL) return(-ENOMEM);
46   - return(net_read(fd, skb_mac_header(*skb),
47   - (*skb)->dev->mtu + ETH_HEADER_OTHER));
  42 + if (*skb == NULL)
  43 + return -ENOMEM;
  44 + return net_read(fd, skb_mac_header(*skb),
  45 + (*skb)->dev->mtu + ETH_HEADER_OTHER);
48 46 }
49 47  
50   -static int tuntap_write(int fd, struct sk_buff **skb,
  48 +static int tuntap_write(int fd, struct sk_buff **skb,
51 49 struct uml_net_private *lp)
52 50 {
53   - return(net_write(fd, (*skb)->data, (*skb)->len));
  51 + return net_write(fd, (*skb)->data, (*skb)->len);
54 52 }
55 53  
56 54 const struct net_kern_info tuntap_kern_info = {
57 55  
58 56  
... ... @@ -67,11 +65,11 @@
67 65 *init = ((struct tuntap_init)
68 66 { .dev_name = NULL,
69 67 .gate_addr = NULL });
70   - if(tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
  68 + if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
71 69 &init->gate_addr))
72   - return(0);
  70 + return 0;
73 71  
74   - return(1);
  72 + return 1;
75 73 }
76 74  
77 75 static struct transport tuntap_transport = {
arch/um/os-Linux/drivers/tuntap_user.c
1 1 /*
2   - * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
  2 + * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 3 * Licensed under the GPL
4 4 */
5 5  
6 6 #include <stdio.h>
7   -#include <stddef.h>
8   -#include <stdlib.h>
9 7 #include <unistd.h>
10 8 #include <errno.h>
11   -#include <sys/wait.h>
  9 +#include <string.h>
  10 +#include <linux/if_tun.h>
  11 +#include <net/if.h>
  12 +#include <sys/ioctl.h>
12 13 #include <sys/socket.h>
13   -#include <sys/un.h>
  14 +#include <sys/wait.h>
14 15 #include <sys/uio.h>
15   -#include <sys/ioctl.h>
16   -#include <net/if.h>
17   -#include <linux/if_tun.h>
18   -#include "net_user.h"
  16 +#include "kern_constants.h"
  17 +#include "os.h"
19 18 #include "tuntap.h"
20   -#include "kern_util.h"
21 19 #include "user.h"
22   -#include "os.h"
23 20  
24 21 #define MAX_PACKET ETH_MAX_PACKET
25 22  
... ... @@ -37,7 +34,7 @@
37 34 struct tuntap_data *pri = data;
38 35  
39 36 tap_check_ips(pri->gate_addr, addr);
40   - if((pri->fd == -1) || pri->fixed_config)
  37 + if ((pri->fd == -1) || pri->fixed_config)
41 38 return;
42 39 open_addr(addr, netmask, pri->dev_name);
43 40 }
... ... @@ -47,7 +44,7 @@
47 44 {
48 45 struct tuntap_data *pri = data;
49 46  
50   - if((pri->fd == -1) || pri->fixed_config)
  47 + if ((pri->fd == -1) || pri->fixed_config)
51 48 return;
52 49 close_addr(addr, netmask, pri->dev_name);
53 50 }
54 51  
... ... @@ -85,14 +82,14 @@
85 82  
86 83 pid = run_helper(tuntap_pre_exec, &data, argv);
87 84  
88   - if(pid < 0)
  85 + if (pid < 0)
89 86 return -pid;
90 87  
91 88 close(remote);
92 89  
93 90 msg.msg_name = NULL;
94 91 msg.msg_namelen = 0;
95   - if(buffer != NULL){
  92 + if (buffer != NULL) {
96 93 iov = ((struct iovec) { buffer, buffer_len });
97 94 msg.msg_iov = &iov;
98 95 msg.msg_iovlen = 1;
99 96  
100 97  
101 98  
... ... @@ -106,22 +103,24 @@
106 103 msg.msg_flags = 0;
107 104 n = recvmsg(me, &msg, 0);
108 105 *used_out = n;
109   - if(n < 0){
  106 + if (n < 0) {
110 107 err = -errno;
111   - printk("tuntap_open_tramp : recvmsg failed - errno = %d\n",
112   - errno);
  108 + printk(UM_KERN_ERR "tuntap_open_tramp : recvmsg failed - "
  109 + "errno = %d\n", errno);
113 110 return err;
114 111 }
115 112 CATCH_EINTR(waitpid(pid, NULL, 0));
116 113  
117 114 cmsg = CMSG_FIRSTHDR(&msg);
118   - if(cmsg == NULL){
119   - printk("tuntap_open_tramp : didn't receive a message\n");
  115 + if (cmsg == NULL) {
  116 + printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a "
  117 + "message\n");
120 118 return -EINVAL;
121 119 }
122   - if((cmsg->cmsg_level != SOL_SOCKET) ||
123   - (cmsg->cmsg_type != SCM_RIGHTS)){
124   - printk("tuntap_open_tramp : didn't receive a descriptor\n");
  120 + if ((cmsg->cmsg_level != SOL_SOCKET) ||
  121 + (cmsg->cmsg_type != SCM_RIGHTS)) {
  122 + printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a "
  123 + "descriptor\n");
125 124 return -EINVAL;
126 125 }
127 126 *fd_out = ((int *) CMSG_DATA(cmsg))[0];
128 127  
129 128  
130 129  
131 130  
132 131  
133 132  
134 133  
... ... @@ -137,38 +136,39 @@
137 136 int err, fds[2], len, used;
138 137  
139 138 err = tap_open_common(pri->dev, pri->gate_addr);
140   - if(err < 0)
  139 + if (err < 0)
141 140 return err;
142 141  
143   - if(pri->fixed_config){
  142 + if (pri->fixed_config) {
144 143 pri->fd = os_open_file("/dev/net/tun",
145 144 of_cloexec(of_rdwr(OPENFLAGS())), 0);
146   - if(pri->fd < 0){
147   - printk("Failed to open /dev/net/tun, err = %d\n",
148   - -pri->fd);
  145 + if (pri->fd < 0) {
  146 + printk(UM_KERN_ERR "Failed to open /dev/net/tun, "
  147 + "err = %d\n", -pri->fd);
149 148 return pri->fd;
150 149 }
151 150 memset(&ifr, 0, sizeof(ifr));
152 151 ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
153 152 strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
154   - if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){
  153 + if (ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0) {
155 154 err = -errno;
156   - printk("TUNSETIFF failed, errno = %d\n", errno);
  155 + printk(UM_KERN_ERR "TUNSETIFF failed, errno = %d\n",
  156 + errno);
157 157 close(pri->fd);
158 158 return err;
159 159 }
160 160 }
161 161 else {
162 162 err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds);
163   - if(err){
  163 + if (err) {
164 164 err = -errno;
165   - printk("tuntap_open : socketpair failed - errno = %d\n",
166   - errno);
  165 + printk(UM_KERN_ERR "tuntap_open : socketpair failed - "
  166 + "errno = %d\n", errno);
167 167 return err;
168 168 }
169 169  
170 170 buffer = get_output_buffer(&len);
171   - if(buffer != NULL)
  171 + if (buffer != NULL)
172 172 len--;
173 173 used = 0;
174 174  
175 175  
... ... @@ -176,10 +176,11 @@
176 176 fds[1], buffer, len, &used);
177 177  
178 178 output = buffer;
179   - if(err < 0) {
  179 + if (err < 0) {
180 180 printk("%s", output);
181 181 free_output_buffer(buffer);
182   - printk("tuntap_open_tramp failed - err = %d\n", -err);
  182 + printk(UM_KERN_ERR "tuntap_open_tramp failed - "
  183 + "err = %d\n", -err);
183 184 return err;
184 185 }
185 186  
... ... @@ -199,7 +200,7 @@
199 200 {
200 201 struct tuntap_data *pri = data;
201 202  
202   - if(!pri->fixed_config)
  203 + if (!pri->fixed_config)
203 204 iter_addresses(pri->dev, close_addr, pri->dev_name);
204 205 close(fd);
205 206 pri->fd = -1;