Commit cd1ae0e4 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

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: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1a805219
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#ifndef __DAEMON_H__
#define __DAEMON_H__
#include "net_user.h"
#define SWITCH_VERSION 3
......@@ -23,13 +26,4 @@ extern const struct net_user_info daemon_user_info;
extern int daemon_user_write(int fd, void *buf, int len,
struct daemon_data *pri);
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#endif
/*
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/
#include "linux/kernel.h"
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include <linux/netdevice.h>
#include "net_kern.h"
#include "net_user.h"
#include "daemon.h"
struct daemon_init {
......@@ -45,16 +43,17 @@ static int daemon_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
if (*skb == NULL)
return -ENOMEM;
return net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER);
}
static int daemon_write(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(daemon_user_write(fd, (*skb)->data, (*skb)->len,
(struct daemon_data *) &lp->user));
return daemon_user_write(fd, (*skb)->data, (*skb)->len,
(struct daemon_data *) &lp->user);
}
static const struct net_kern_info daemon_kern_info = {
......@@ -75,11 +74,11 @@ static int daemon_setup(char *str, char **mac_out, void *data)
remain = split_if_spec(str, mac_out, &init->sock_type, &init->ctl_sock,
NULL);
if(remain != NULL)
if (remain != NULL)
printk(KERN_WARNING "daemon_setup : Ignoring data socket "
"specification\n");
return(1);
return 1;
}
static struct transport daemon_transport = {
......
/*
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/
#include <errno.h>
#include <unistd.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include "net_user.h"
#include <sys/un.h>
#include "daemon.h"
#include "kern_util.h"
#include "user.h"
#include "net_user.h"
#include "os.h"
#include "um_malloc.h"
#include "user.h"
#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
......@@ -36,8 +37,9 @@ static struct sockaddr_un *new_addr(void *name, int len)
struct sockaddr_un *sun;
sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
if(sun == NULL){
printk("new_addr: allocation of sockaddr_un failed\n");
if (sun == NULL) {
printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
"failed\n");
return NULL;
}
sun->sun_family = AF_UNIX;
......@@ -54,38 +56,39 @@ static int connect_to_switch(struct daemon_data *pri)
int fd, n, err;
pri->control = socket(AF_UNIX, SOCK_STREAM, 0);
if(pri->control < 0){
if (pri->control < 0) {
err = -errno;
printk("daemon_open : control socket failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : control socket failed, "
"errno = %d\n", -err);
return err;
}
if(connect(pri->control, (struct sockaddr *) ctl_addr,
sizeof(*ctl_addr)) < 0){
if (connect(pri->control, (struct sockaddr *) ctl_addr,
sizeof(*ctl_addr)) < 0) {
err = -errno;
printk("daemon_open : control connect failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : control connect failed, "
"errno = %d\n", -err);
goto out;
}
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if(fd < 0){
if (fd < 0) {
err = -errno;
printk("daemon_open : data socket failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : data socket failed, "
"errno = %d\n", -err);
goto out;
}
if(bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0){
if (bind(fd, (struct sockaddr *) local_addr, sizeof(*local_addr)) < 0) {
err = -errno;
printk("daemon_open : data bind failed, errno = %d\n",
-err);
printk(UM_KERN_ERR "daemon_open : data bind failed, "
"errno = %d\n", -err);
goto out_close;
}
sun = kmalloc(sizeof(struct sockaddr_un), UM_GFP_KERNEL);
if(sun == NULL){
printk("new_addr: allocation of sockaddr_un failed\n");
if (sun == NULL) {
printk(UM_KERN_ERR "new_addr: allocation of sockaddr_un "
"failed\n");
err = -ENOMEM;
goto out_close;
}
......@@ -94,18 +97,18 @@ static int connect_to_switch(struct daemon_data *pri)
req.version = SWITCH_VERSION;
req.type = REQ_NEW_CONTROL;
req.sock = *local_addr;
n = os_write_file(pri->control, &req, sizeof(req));
if(n != sizeof(req)){
printk("daemon_open : control setup request failed, err = %d\n",
-n);
n = write(pri->control, &req, sizeof(req));
if (n != sizeof(req)) {
printk(UM_KERN_ERR "daemon_open : control setup request "
"failed, err = %d\n", -errno);
err = -ENOTCONN;
goto out_free;
}
n = os_read_file(pri->control, sun, sizeof(*sun));
if(n != sizeof(*sun)){
printk("daemon_open : read of data socket failed, err = %d\n",
-n);
n = read(pri->control, sun, sizeof(*sun));
if (n != sizeof(*sun)) {
printk(UM_KERN_ERR "daemon_open : read of data socket failed, "
"err = %d\n", -errno);
err = -ENOTCONN;
goto out_free;
}
......@@ -116,9 +119,9 @@ static int connect_to_switch(struct daemon_data *pri)
out_free:
kfree(sun);
out_close:
os_close_file(fd);
close(fd);
out:
os_close_file(pri->control);
close(pri->control);
return err;
}
......@@ -132,7 +135,7 @@ static int daemon_user_init(void *data, void *dev)
int usecs;
} name;
if(!strcmp(pri->sock_type, "unix"))
if (!strcmp(pri->sock_type, "unix"))
pri->ctl_addr = new_addr(pri->ctl_sock,
strlen(pri->ctl_sock) + 1);
name.zero = 0;
......@@ -142,7 +145,7 @@ static int daemon_user_init(void *data, void *dev)
pri->local_addr = new_addr(&name, sizeof(name));
pri->dev = dev;
pri->fd = connect_to_switch(pri);
if(pri->fd < 0){
if (pri->fd < 0) {
kfree(pri->local_addr);
pri->local_addr = NULL;
return pri->fd;
......@@ -161,9 +164,9 @@ static void daemon_remove(void *data)
{
struct daemon_data *pri = data;
os_close_file(pri->fd);
close(pri->fd);
pri->fd = -1;
os_close_file(pri->control);
close(pri->control);
pri->control = -1;
kfree(pri->data_addr);
......
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#ifndef __DRIVERS_MCAST_H
#define __DRIVERS_MCAST_H
#include "net_user.h"
struct mcast_data {
......@@ -18,13 +21,4 @@ extern const struct net_user_info mcast_user_info;
extern int mcast_user_write(int fd, void *buf, int len,
struct mcast_data *pri);
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#endif
/*
* user-mode-linux networking multicast transport
* Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
*
* based on the existing uml-networking code, which is
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
......@@ -10,15 +11,10 @@
* Licensed under the GPL.
*/
#include "linux/kernel.h"
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include "linux/in.h"
#include "linux/inet.h"
#include "net_kern.h"
#include "net_user.h"
#include <linux/netdevice.h>
#include "mcast.h"
#include "net_kern.h"
struct mcast_init {
char *addr;
......@@ -39,23 +35,20 @@ static void mcast_init(struct net_device *dev, void *data)
dpri->ttl = init->ttl;
dpri->dev = dev;
printk("mcast backend ");
printk("multicast address: %s:%u, TTL:%u ",
printk("mcast backend multicast address: %s:%u, TTL:%u\n",
dpri->addr, dpri->port, dpri->ttl);
printk("\n");
}
static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
if (*skb == NULL)
return -ENOMEM;
return net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER);
}
static int mcast_write(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
static int mcast_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
{
return mcast_user_write(fd, (*skb)->data, (*skb)->len,
(struct mcast_data *) &lp->user);
......@@ -81,34 +74,34 @@ int mcast_setup(char *str, char **mac_out, void *data)
remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
NULL);
if(remain != NULL){
if (remain != NULL) {
printk(KERN_ERR "mcast_setup - Extra garbage on "
"specification : '%s'\n", remain);
return(0);
return 0;
}
if(port_str != NULL){
if (port_str != NULL) {
init->port = simple_strtoul(port_str, &last, 10);
if((*last != '\0') || (last == port_str)){
if ((*last != '\0') || (last == port_str)) {
printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
port_str);
return(0);
return 0;
}
}
if(ttl_str != NULL){
if (ttl_str != NULL) {
init->ttl = simple_strtoul(ttl_str, &last, 10);
if((*last != '\0') || (last == ttl_str)){
if ((*last != '\0') || (last == ttl_str)) {
printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
ttl_str);
return(0);
return 0;
}
}
printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
init->port, init->ttl);
return(1);
return 1;
}
static struct transport mcast_transport = {
......
/*
* user-mode-linux networking multicast transport
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
*
* based on the existing uml-networking code, which is
......@@ -11,18 +12,13 @@
*
*/
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include <errno.h>
#include <netinet/in.h>
#include "net_user.h"
#include "mcast.h"
#include "kern_util.h"
#include "user.h"
#include "os.h"
#include "net_user.h"
#include "um_malloc.h"
#include "user.h"
#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
......@@ -31,8 +27,9 @@ static struct sockaddr_in *new_addr(char *addr, unsigned short port)
struct sockaddr_in *sin;
sin = kmalloc(sizeof(struct sockaddr_in), UM_GFP_KERNEL);
if(sin == NULL){
printk("new_addr: allocation of sockaddr_in failed\n");
if (sin == NULL) {
printk(UM_KERN_ERR "new_addr: allocation of sockaddr_in "
"failed\n");
return NULL;
}
sin->sin_family = AF_INET;
......@@ -71,17 +68,17 @@ static int mcast_open(void *data)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0){
if (fd < 0) {
err = -errno;
printk("mcast_open : data socket failed, errno = %d\n",
errno);
printk(UM_KERN_ERR "mcast_open : data socket failed, "
"errno = %d\n", errno);
goto out;
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
err = -errno;
printk("mcast_open: SO_REUSEADDR failed, errno = %d\n",
errno);
printk(UM_KERN_ERR "mcast_open: SO_REUSEADDR failed, "
"errno = %d\n", errno);
goto out_close;
}
......@@ -89,23 +86,24 @@ static int mcast_open(void *data)
if (setsockopt(fd, SOL_IP, IP_MULTICAST_TTL, &pri->ttl,
sizeof(pri->ttl)) < 0) {
err = -errno;
printk("mcast_open: IP_MULTICAST_TTL failed, error = %d\n",
errno);
printk(UM_KERN_ERR "mcast_open: IP_MULTICAST_TTL failed, "
"error = %d\n", errno);
goto out_close;
}
/* set LOOP, so data does get fed back to local sockets */
if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
err = -errno;
printk("mcast_open: IP_MULTICAST_LOOP failed, error = %d\n",
errno);
printk(UM_KERN_ERR "mcast_open: IP_MULTICAST_LOOP failed, "
"error = %d\n", errno);
goto out_close;
}
/* bind socket to mcast address */
if (bind(fd, (struct sockaddr *) sin, sizeof(*sin)) < 0) {
err = -errno;
printk("mcast_open : data bind failed, errno = %d\n", errno);
printk(UM_KERN_ERR "mcast_open : data bind failed, "
"errno = %d\n", errno);
goto out_close;
}
......@@ -115,19 +113,19 @@ static int mcast_open(void *data)
if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
err = -errno;
printk("mcast_open: IP_ADD_MEMBERSHIP failed, error = %d\n",
errno);
printk("There appears not to be a multicast-capable network "
"interface on the host.\n");
printk("eth0 should be configured in order to use the "
"multicast transport.\n");
printk(UM_KERN_ERR "mcast_open: IP_ADD_MEMBERSHIP failed, "
"error = %d\n", errno);
printk(UM_KERN_ERR "There appears not to be a multicast-"
"capable network interface on the host.\n");
printk(UM_KERN_ERR "eth0 should be configured in order to use "
"the multicast transport.\n");
goto out_close;
}
return fd;
out_close:
os_close_file(fd);
close(fd);
out:
return err;
}
......@@ -142,11 +140,11 @@ static void mcast_close(int fd, void *data)
mreq.imr_interface.s_addr = 0;
if (setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP,
&mreq, sizeof(mreq)) < 0) {
printk("mcast_open: IP_DROP_MEMBERSHIP failed, error = %d\n",
errno);
printk(UM_KERN_ERR "mcast_open: IP_DROP_MEMBERSHIP failed, "
"error = %d\n", errno);
}
os_close_file(fd);
close(fd);
}
int mcast_user_write(int fd, void *buf, int len, struct mcast_data *pri)
......
This diff is collapsed.
/*
* 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) &&
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");
(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));
......@@ -218,13 +223,14 @@ static void change(char *dev, char *what, unsigned char *addr,
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;
......
/*
* Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include <linux/netdevice.h>
#include "net_kern.h"
#include "net_user.h"
#include "pcap_user.h"
struct pcap_init {
......@@ -37,7 +35,7 @@ static int pcap_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL)
if (*skb == NULL)
return -ENOMEM;
return pcap_user_read(fd, skb_mac_header(*skb),
......@@ -71,28 +69,29 @@ int pcap_setup(char *str, char **mac_out, void *data)
remain = split_if_spec(str, &host_if, &init->filter,
&options[0], &options[1], mac_out, NULL);
if(remain != NULL){
if (remain != NULL) {
printk(KERN_ERR "pcap_setup - Extra garbage on "
"specification : '%s'\n", remain);
return 0;
}
if(host_if != NULL)
if (host_if != NULL)
init->host_if = host_if;
for(i = 0; i < ARRAY_SIZE(options); i++){
if(options[i] == NULL)
for (i = 0; i < ARRAY_SIZE(options); i++) {
if (options[i] == NULL)
continue;
if(!strcmp(options[i], "promisc"))
if (!strcmp(options[i], "promisc"))
init->promisc = 1;
else if(!strcmp(options[i], "nopromisc"))
else if (!strcmp(options[i], "nopromisc"))
init->promisc = 0;
else if(!strcmp(options[i], "optimize"))
else if (!strcmp(options[i], "optimize"))
init->optimize = 1;
else if(!strcmp(options[i], "nooptimize"))
else if (!strcmp(options[i], "nooptimize"))
init->optimize = 0;
else {
printk("pcap_setup : bad option - '%s'\n", options[i]);
printk(KERN_ERR "pcap_setup : bad option - '%s'\n",
options[i]);
return 0;
}
}
......
/*
* Copyright (C) 2002 Jeff Dike <jdike@karaya.com>
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pcap.h>
#include <string.h>
#include <asm/types.h>
#include "net_user.h"
#include "pcap_user.h"
#include "user.h"
#include "um_malloc.h"
#include "kern_constants.h"
#include "um_malloc.h"
#include "user.h"
#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
......@@ -26,7 +24,7 @@ static int pcap_user_init(void *data, void *dev)
char errors[PCAP_ERRBUF_SIZE];
p = pcap_open_live(pri->host_if, MAX_PACKET, pri->promisc, 0, errors);
if(p == NULL){
if (p == NULL) {
printk(UM_KERN_ERR "pcap_user_init : pcap_open_live failed - "
"'%s'\n", errors);
return -EINVAL;
......@@ -43,18 +41,19 @@ static int pcap_open(void *data)
__u32 netmask;
int err;
if(pri->pcap == NULL)
if (pri->pcap == NULL)
return -ENODEV;
if(pri->filter != NULL){
if (pri->filter != NULL) {
err = dev_netmask(pri->dev, &netmask);
if(err < 0){
if (err < 0) {
printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n");
return -EIO;
}
pri->compiled = kmalloc(sizeof(struct bpf_program), UM_GFP_KERNEL);
if(pri->compiled == NULL){
pri->compiled = kmalloc(sizeof(struct bpf_program),
UM_GFP_KERNEL);
if (pri->compiled == NULL) {
printk(UM_KERN_ERR "pcap_open : kmalloc failed\n");
return -ENOMEM;
}
......@@ -62,31 +61,35 @@ static int pcap_open(void *data)
err = pcap_compile(pri->pcap,
(struct bpf_program *) pri->compiled,
pri->filter, pri->optimize, netmask);
if(err < 0){
if (err < 0) {
printk(UM_KERN_ERR "pcap_open : pcap_compile failed - "
"'%s'\n", pcap_geterr(pri->pcap));
return -EIO;
goto out;
}
err = pcap_setfilter(pri->pcap, pri->compiled);
if(err < 0){
if (err < 0) {
printk(UM_KERN_ERR "pcap_open : pcap_setfilter "
"failed - '%s'\n", pcap_geterr(pri->pcap));
return -EIO;
goto out;
}
}
return PCAP_FD(pri->pcap);
out:
kfree(pri->compiled);
return -EIO;
}
static void pcap_remove(void *data)
{
struct pcap_data *pri = data;
if(pri->compiled != NULL)
if (pri->compiled != NULL)
pcap_freecode(pri->compiled);
if(pri->pcap != NULL)
if (pri->pcap != NULL)
pcap_close(pri->pcap);
}
......@@ -115,12 +118,12 @@ int pcap_user_read(int fd, void *buffer, int len, struct pcap_data *pri)
int n;
n = pcap_dispatch(pri->pcap, 1, handler, (u_char *) &hdata);
if(n < 0){
if (n < 0) {
printk(UM_KERN_ERR "pcap_dispatch failed - %s\n",
pcap_geterr(pri->pcap));
return -EIO;
}
else if(n == 0)
else if (n == 0)
return 0;
return hdata.len;
}
......
#include "linux/kernel.h"
#include "linux/stddef.h"
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/if_arp.h"
/*
* Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include <linux/if_arp.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include "net_kern.h"
#include "net_user.h"
#include "kern.h"
#include "slip.h"
struct slip_init {
......@@ -43,21 +44,21 @@ void slip_init(struct net_device *dev, void *data)
static unsigned short slip_protocol(struct sk_buff *skbuff)
{
return(htons(ETH_P_IP));
return htons(ETH_P_IP);
}
static int slip_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
(struct slip_data *) &lp->user));
return slip_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
(struct slip_data *) &lp->user);
}
static int slip_write(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(slip_user_write(fd, (*skb)->data, (*skb)->len,
(struct slip_data *) &lp->user));
return slip_user_write(fd, (*skb)->data, (*skb)->len,
(struct slip_data *) &lp->user);
}
const struct net_kern_info slip_kern_info = {
......@@ -71,12 +72,11 @@ static int slip_setup(char *str, char **mac_out, void *data)
{
struct slip_init *init = data;
*init = ((struct slip_init)
{ .gate_addr = NULL });
*init = ((struct slip_init) { .gate_addr = NULL });
if(str[0] != '\0')
if (str[0] != '\0')
init->gate_addr = str;
return(1);
return 1;
}
static struct transport slip_transport = {
......
/*
* Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stddef.h>
#include <sched.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/termios.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include "kern_util.h"
#include "user.h"
#include "kern_constants.h"
#include "net_user.h"
#include "slip.h"
#include "slip_common.h"
#include "os.h"
#include "slip.h"
#include "um_malloc.h"
#include "kern_constants.h"
#include "user.h"
static int slip_user_init(void *data, void *dev)
{
......@@ -31,8 +32,9 @@ static int set_up_tty(int fd)
struct termios tios;
if (tcgetattr(fd, &tios) < 0) {
printk("could not get initial terminal attributes\n");
return(-1);
printk(UM_KERN_ERR "could not get initial terminal "
"attributes\n");
return -1;
}
tios.c_cflag = CS8 | CREAD | HUPCL | CLOCAL;
......@@ -48,10 +50,10 @@ static int set_up_tty(int fd)
cfsetispeed(&tios, B38400);
if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
printk("failed to set terminal attributes\n");
return(-1);
printk(UM_KERN_ERR "failed to set terminal attributes\n");
return -1;
}
return(0);
return 0;
}
struct slip_pre_exec_data {
......@@ -64,9 +66,11 @@ static void slip_pre_exec(void *arg)
{
struct slip_pre_exec_data *data = arg;
if(data->stdin >= 0) dup2(data->stdin, 0);
if (data->stdin >= 0)
dup2(data->stdin, 0);
dup2(data->stdout, 1);
if(data->close_me >= 0) os_close_file(data->close_me);
if (data->close_me >= 0)
close(data->close_me);
}
static int slip_tramp(char **argv, int fd)
......@@ -76,8 +80,9 @@ static int slip_tramp(char **argv, int fd)
int status, pid, fds[2], err, output_len;
err = os_pipe(fds, 1, 0);
if(err < 0){
printk("slip_tramp : pipe failed, err = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n",
-err);
goto out;
}
......@@ -86,41 +91,42 @@ static int slip_tramp(char **argv, int fd)
pe_data.stdout = fds[1];
pe_data.close_me = fds[0];
err = run_helper(slip_pre_exec, &pe_data, argv);
if(err < 0)
if (err < 0)
goto out_close;
pid = err;
output_len = UM_KERN_PAGE_SIZE;
output = kmalloc(output_len, UM_GFP_KERNEL);
if(output == NULL){
printk("slip_tramp : failed to allocate output buffer\n");
if (output == NULL) {
printk(UM_KERN_ERR "slip_tramp : failed to allocate output "
"buffer\n");
os_kill_process(pid, 1);
err = -ENOMEM;
goto out_free;
}
os_close_file(fds[1]);
close(fds[1]);
read_output(fds[0], output, output_len);
printk("%s", output);
CATCH_EINTR(err = waitpid(pid, &status, 0));
if(err < 0)
if (err < 0)
err = errno;
else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){
printk("'%s' didn't exit with status 0\n", argv[0]);
else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
printk(UM_KERN_ERR "'%s' didn't exit with status 0\n", argv[0]);
err = -EINVAL;
}
else err = 0;
os_close_file(fds[0]);
close(fds[0]);
out_free:
kfree(output);
return err;
out_close:
os_close_file(fds[0]);
os_close_file(fds[1]);
close(fds[0]);
close(fds[1]);
out:
return err;
}
......@@ -135,55 +141,59 @@ static int slip_open(void *data)
int sfd, mfd, err;
err = get_pty();
if(err < 0){
printk("slip-open : Failed to open pty, err = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "slip-open : Failed to open pty, err = %d\n",
-err);
goto out;
}
mfd = err;
err = os_open_file(ptsname(mfd), of_rdwr(OPENFLAGS()), 0);
if(err < 0){
printk("Couldn't open tty for slip line, err = %d\n", -err);
err = open(ptsname(mfd), O_RDWR, 0);
if (err < 0) {
printk(UM_KERN_ERR "Couldn't open tty for slip line, "
"err = %d\n", -err);
goto out_close;
}
sfd = err;
if(set_up_tty(sfd))
if (set_up_tty(sfd))
goto out_close2;
pri->slave = sfd;
pri->slip.pos = 0;
pri->slip.esc = 0;
if(pri->gate_addr != NULL){
if (pri->gate_addr != NULL) {
sprintf(version_buf, "%d", UML_NET_VERSION);
strcpy(gate_buf, pri->gate_addr);
err = slip_tramp(argv, sfd);
if(err < 0){
printk("slip_tramp failed - err = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "slip_tramp failed - err = %d\n",
-err);
goto out_close2;
}
err = os_get_ifname(pri->slave, pri->name);
if(err < 0){
printk("get_ifname failed, err = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "get_ifname failed, err = %d\n",
-err);
goto out_close2;
}
iter_addresses(pri->dev, open_addr, pri->name);
}
else {
err = os_set_slip(sfd);
if(err < 0){
printk("Failed to set slip discipline encapsulation - "
"err = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "Failed to set slip discipline "
"encapsulation - err = %d\n", -err);
goto out_close2;
}
}
return(mfd);
return mfd;
out_close2:
os_close_file(sfd);
close(sfd);
out_close:
os_close_file(mfd);
close(mfd);
out:
return err;
}
......@@ -196,17 +206,17 @@ static void slip_close(int fd, void *data)
NULL };
int err;
if(pri->gate_addr != NULL)
if (pri->gate_addr != NULL)
iter_addresses(pri->dev, close_addr, pri->name);
sprintf(version_buf, "%d", UML_NET_VERSION);
err = slip_tramp(argv, pri->slave);
if(err != 0)
printk("slip_tramp failed - errno = %d\n", -err);
os_close_file(fd);
os_close_file(pri->slave);
if (err != 0)
printk(UM_KERN_ERR "slip_tramp failed - errno = %d\n", -err);
close(fd);
close(pri->slave);
pri->slave = -1;
}
......@@ -222,7 +232,7 @@ int slip_user_write(int fd, void *buf, int len, struct slip_data *pri)
static int slip_set_mtu(int mtu, void *data)
{
return(mtu);
return mtu;
}
static void slip_add_addr(unsigned char *addr, unsigned char *netmask,
......@@ -230,7 +240,8 @@ static void slip_add_addr(unsigned char *addr, unsigned char *netmask,
{
struct slip_data *pri = data;
if(pri->slave < 0) return;
if (pri->slave < 0)
return;
open_addr(addr, netmask, pri->name);
}
......@@ -239,7 +250,8 @@ static void slip_del_addr(unsigned char *addr, unsigned char *netmask,
{
struct slip_data *pri = data;
if(pri->slave < 0) return;
if (pri->slave < 0)
return;
close_addr(addr, netmask, pri->name);
}
......
#include "linux/kernel.h"
#include "linux/stddef.h"
/*
* Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include <linux/if_arp.h>
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/if_arp.h"
#include <linux/netdevice.h>
#include <linux/string.h>
#include "net_kern.h"
#include "net_user.h"
#include "kern.h"
#include "slirp.h"
struct slirp_init {
......@@ -39,29 +42,28 @@ void slirp_init(struct net_device *dev, void *data)
dev->tx_queue_len = 256;
dev->flags = IFF_NOARP;
printk("SLIRP backend - command line:");
for(i=0;spri->argw.argv[i]!=NULL;i++) {
for (i = 0; spri->argw.argv[i] != NULL; i++)
printk(" '%s'",spri->argw.argv[i]);
}
printk("\n");
}
static unsigned short slirp_protocol(struct sk_buff *skbuff)
{
return(htons(ETH_P_IP));
return htons(ETH_P_IP);
}
static int slirp_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
(struct slirp_data *) &lp->user));
return slirp_user_read(fd, skb_mac_header(*skb), (*skb)->dev->mtu,
(struct slirp_data *) &lp->user);
}
static int slirp_write(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(slirp_user_write(fd, (*skb)->data, (*skb)->len,
(struct slirp_data *) &lp->user));
return slirp_user_write(fd, (*skb)->data, (*skb)->len,
(struct slirp_data *) &lp->user);
}
const struct net_kern_info slirp_kern_info = {
......@@ -76,31 +78,32 @@ static int slirp_setup(char *str, char **mac_out, void *data)
struct slirp_init *init = data;
int i=0;
*init = ((struct slirp_init)
{ .argw = { { "slirp", NULL } } });
*init = ((struct slirp_init) { .argw = { { "slirp", NULL } } });
str = split_if_spec(str, mac_out, NULL);
if(str == NULL) { /* no command line given after MAC addr */
return(1);
}
if (str == NULL) /* no command line given after MAC addr */
return 1;
do {
if(i>=SLIRP_MAX_ARGS-1) {
printk("slirp_setup: truncating slirp arguments\n");
if (i >= SLIRP_MAX_ARGS - 1) {
printk(KERN_WARNING "slirp_setup: truncating slirp "
"arguments\n");
break;
}
init->argw.argv[i++] = str;
while(*str && *str!=',') {
if(*str=='_') *str=' ';
if (*str == '_')
*str=' ';
str++;
}
if(*str!=',')
if (*str != ',')
break;
*str++='\0';
} while(1);
init->argw.argv[i]=NULL;
return(1);
*str++ = '\0';
} while (1);
init->argw.argv[i] = NULL;
return 1;
}
static struct transport slirp_transport = {
......
#include <stdio.h>
#include <stdlib.h>
/*
* Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL.
*/
#include <unistd.h>
#include <stddef.h>
#include <sched.h>
#include <string.h>
#include <errno.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include "kern_util.h"
#include "user.h"
#include "kern_constants.h"
#include "net_user.h"
#include "slirp.h"
#include "slip_common.h"
#include "os.h"
#include "slirp.h"
#include "user.h"
static int slirp_user_init(void *data, void *dev)
{
......@@ -31,8 +30,10 @@ static void slirp_pre_exec(void *arg)
{
struct slirp_pre_exec_data *data = arg;
if(data->stdin != -1) dup2(data->stdin, 0);
if(data->stdout != -1) dup2(data->stdout, 1);
if (data->stdin != -1)
dup2(data->stdin, 0);
if (data->stdout != -1)
dup2(data->stdout, 1);
}
static int slirp_tramp(char **argv, int fd)
......@@ -44,7 +45,7 @@ static int slirp_tramp(char **argv, int fd)
pe_data.stdout = fd;
pid = run_helper(slirp_pre_exec, &pe_data, argv);
return(pid);
return pid;
}
static int slirp_open(void *data)
......@@ -53,12 +54,12 @@ static int slirp_open(void *data)
int fds[2], pid, err;
err = os_pipe(fds, 1, 1);
if(err)
return(err);
if (err)
return err;
err = slirp_tramp(pri->argw.argv, fds[1]);
if(err < 0){
printk("slirp_tramp failed - errno = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "slirp_tramp failed - errno = %d\n", -err);
goto out;
}
pid = err;
......@@ -68,10 +69,10 @@ static int slirp_open(void *data)
pri->slip.esc = 0;
pri->pid = err;
return(fds[0]);
return fds[0];
out:
os_close_file(fds[0]);
os_close_file(fds[1]);
close(fds[0]);
close(fds[1]);
return err;
}
......@@ -80,31 +81,33 @@ static void slirp_close(int fd, void *data)
struct slirp_data *pri = data;
int status,err;
os_close_file(fd);
os_close_file(pri->slave);
close(fd);
close(pri->slave);
pri->slave = -1;
if(pri->pid<1) {
printk("slirp_close: no child process to shut down\n");
if (pri->pid<1) {
printk(UM_KERN_ERR "slirp_close: no child process to shut "
"down\n");
return;
}
#if 0
if(kill(pri->pid, SIGHUP)<0) {
printk("slirp_close: sending hangup to %d failed (%d)\n",
pri->pid, errno);
if (kill(pri->pid, SIGHUP)<0) {
printk(UM_KERN_ERR "slirp_close: sending hangup to %d failed "
"(%d)\n", pri->pid, errno);
}
#endif
CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
if(err < 0) {
printk("slirp_close: waitpid returned %d\n", errno);
if (err < 0) {
printk(UM_KERN_ERR "slirp_close: waitpid returned %d\n", errno);
return;
}
if(err == 0) {
printk("slirp_close: process %d has not exited\n", pri->pid);
if (err == 0) {
printk(UM_KERN_ERR "slirp_close: process %d has not exited\n",
pri->pid);
return;
}
......@@ -123,7 +126,7 @@ int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
static int slirp_set_mtu(int mtu, void *data)
{
return(mtu);
return mtu;
}
const struct net_user_info slirp_user_info = {
......
......@@ -7,10 +7,8 @@
*
*/
#include "linux/kernel.h"
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include <linux/netdevice.h>
#include "net_kern.h"
#include "net_user.h"
#include "vde.h"
......@@ -30,12 +28,12 @@ static void vde_init(struct net_device *dev, void *data)
vpri->conn = NULL;
vpri->dev = dev;
printk(KERN_INFO "vde backend - %s, ", vpri->vde_switch ?
printk("vde backend - %s, ", vpri->vde_switch ?
vpri->vde_switch : "(default socket)");
vde_init_libstuff(vpri, init);
printk(KERN_INFO "\n");
printk("\n");
}
static int vde_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
......
......@@ -3,15 +3,13 @@
* Licensed under the GPL.
*/
#include <stddef.h>
#include <errno.h>
#include <unistd.h>
#include <libvdeplug.h>
#include "net_user.h"
#include "kern_util.h"
#include "kern_constants.h"
#include "user.h"
#include "os.h"
#include "net_user.h"
#include "um_malloc.h"
#include "user.h"
#include "vde.h"
#define MAX_PACKET (ETH_MAX_PACKET + ETH_HEADER_OTHER)
......
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#ifndef __DRIVERS_ETAP_H
#define __DRIVERS_ETAP_H
#include "net_user.h"
struct ethertap_data {
......@@ -15,13 +18,4 @@ struct ethertap_data {
extern const struct net_user_info ethertap_user_info;
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#endif
/*
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 by various other people who didn't put their name here.
* Licensed under the GPL.
*/
#include "linux/init.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include "net_kern.h"
#include "net_user.h"
#include <linux/netdevice.h>
#include "etap.h"
#include "net_kern.h"
struct ethertap_init {
char *dev_name;
......@@ -42,27 +41,30 @@ static int etap_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
int len;
*skb = ether_adjust_skb(*skb, ETH_HEADER_ETHERTAP);
if(*skb == NULL) return(-ENOMEM);
if (*skb == NULL)
return -ENOMEM;
len = net_recvfrom(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + 2 * ETH_HEADER_ETHERTAP);
if(len <= 0) return(len);
if (len <= 0)
return len;
skb_pull(*skb, 2);
len -= 2;
return(len);
return len;
}
static int etap_write(int fd, struct sk_buff **skb, struct uml_net_private *lp)
{
if(skb_headroom(*skb) < 2){
if (skb_headroom(*skb) < 2) {
struct sk_buff *skb2;
skb2 = skb_realloc_headroom(*skb, 2);
dev_kfree_skb(*skb);
if (skb2 == NULL) return(-ENOMEM);
if (skb2 == NULL)
return -ENOMEM;
*skb = skb2;
}
skb_push(*skb, 2);
return(net_send(fd, (*skb)->data, (*skb)->len));
return net_send(fd, (*skb)->data, (*skb)->len);
}
const struct net_kern_info ethertap_kern_info = {
......@@ -79,15 +81,15 @@ int ethertap_setup(char *str, char **mac_out, void *data)
*init = ((struct ethertap_init)
{ .dev_name = NULL,
.gate_addr = NULL });
if(tap_setup_common(str, "ethertap", &init->dev_name, mac_out,
if (tap_setup_common(str, "ethertap", &init->dev_name, mac_out,
&init->gate_addr))
return(0);
if(init->dev_name == NULL){
printk("ethertap_setup : Missing tap device name\n");
return(0);
return 0;
if (init->dev_name == NULL) {
printk(KERN_ERR "ethertap_setup : Missing tap device name\n");
return 0;
}
return(1);
return 1;
}
static struct transport ethertap_transport = {
......
/*
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
* James Leu (jleu@mindspring.net).
* Copyright (C) 2001 by various other people who didn't put their name here.
......@@ -7,20 +8,16 @@
#include <stdio.h>
#include <unistd.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/errno.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <net/if.h>
#include "user.h"
#include "kern_util.h"
#include "net_user.h"
#include "etap.h"
#include "kern_constants.h"
#include "os.h"
#include "net_user.h"
#include "um_malloc.h"
#include "kern_constants.h"
#include "user.h"
#define MAX_PACKET ETH_MAX_PACKET
......@@ -49,16 +46,18 @@ static void etap_change(int op, unsigned char *addr, unsigned char *netmask,
memcpy(change.addr, addr, sizeof(change.addr));
memcpy(change.netmask, netmask, sizeof(change.netmask));
CATCH_EINTR(n = write(fd, &change, sizeof(change)));
if(n != sizeof(change)){
printk("etap_change - request failed, err = %d\n", errno);
if (n != sizeof(change)) {
printk(UM_KERN_ERR "etap_change - request failed, err = %d\n",
errno);
return;
}
output = kmalloc(UM_KERN_PAGE_SIZE, UM_GFP_KERNEL);
if(output == NULL)
printk("etap_change : Failed to allocate output buffer\n");
if (output == NULL)
printk(UM_KERN_ERR "etap_change : Failed to allocate output "
"buffer\n");
read_output(fd, output, UM_KERN_PAGE_SIZE);
if(output != NULL){
if (output != NULL) {
printk("%s", output);
kfree(output);
}
......@@ -107,7 +106,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
sprintf(data_fd_buf, "%d", data_remote);
sprintf(version_buf, "%d", UML_NET_VERSION);
if(gate != NULL){
if (gate != NULL) {
strcpy(gate_buf, gate);
args = setup_args;
}
......@@ -119,24 +118,26 @@ static int etap_tramp(char *dev, char *gate, int control_me,
pe_data.data_me = data_me;
pid = run_helper(etap_pre_exec, &pe_data, args);
if(pid < 0)
if (pid < 0)
err = pid;
close(data_remote);
close(control_remote);
CATCH_EINTR(n = read(control_me, &c, sizeof(c)));
if(n != sizeof(c)){
if (n != sizeof(c)) {
err = -errno;
printk("etap_tramp : read of status failed, err = %d\n", -err);
printk(UM_KERN_ERR "etap_tramp : read of status failed, "
"err = %d\n", -err);
return err;
}
if(c != 1){
printk("etap_tramp : uml_net failed\n");
if (c != 1) {
printk(UM_KERN_ERR "etap_tramp : uml_net failed\n");
err = -EINVAL;
CATCH_EINTR(n = waitpid(pid, &status, 0));
if(n < 0)
if (n < 0)
err = -errno;
else if(!WIFEXITED(status) || (WEXITSTATUS(status) != 1))
printk("uml_net didn't exit with status 1\n");
else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 1))
printk(UM_KERN_ERR "uml_net didn't exit with "
"status 1\n");
}
return err;
}
......@@ -148,22 +149,22 @@ static int etap_open(void *data)
int data_fds[2], control_fds[2], err, output_len;
err = tap_open_common(pri->dev, pri->gate_addr);
if(err)
if (err)
return err;
err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds);
if(err){
if (err) {
err = -errno;
printk("etap_open - data socketpair failed - err = %d\n",
errno);
printk(UM_KERN_ERR "etap_open - data socketpair failed - "
"err = %d\n", errno);
return err;
}
err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds);
if(err){
if (err) {
err = -errno;
printk("etap_open - control socketpair failed - err = %d\n",
errno);
printk(UM_KERN_ERR "etap_open - control socketpair failed - "
"err = %d\n", errno);
goto out_close_data;
}
......@@ -173,15 +174,16 @@ static int etap_open(void *data)
output = kmalloc(output_len, UM_GFP_KERNEL);
read_output(control_fds[0], output, output_len);
if(output == NULL)
printk("etap_open : failed to allocate output buffer\n");
if (output == NULL)
printk(UM_KERN_ERR "etap_open : failed to allocate output "
"buffer\n");
else {
printk("%s", output);
kfree(output);
}
if(err < 0){
printk("etap_tramp failed - err = %d\n", -err);
if (err < 0) {
printk(UM_KERN_ERR "etap_tramp failed - err = %d\n", -err);
goto out_close_control;
}
......@@ -206,14 +208,14 @@ static void etap_close(int fd, void *data)
iter_addresses(pri->dev, etap_close_addr, &pri->control_fd);
close(fd);
if(shutdown(pri->data_fd, SHUT_RDWR) < 0)
printk("etap_close - shutdown data socket failed, errno = %d\n",
errno);
if(shutdown(pri->control_fd, SHUT_RDWR) < 0)
printk("etap_close - shutdown control socket failed, "
if (shutdown(pri->data_fd, SHUT_RDWR) < 0)
printk(UM_KERN_ERR "etap_close - shutdown data socket failed, "
"errno = %d\n", errno);
if (shutdown(pri->control_fd, SHUT_RDWR) < 0)
printk(UM_KERN_ERR "etap_close - shutdown control socket "
"failed, errno = %d\n", errno);
close(pri->data_fd);
pri->data_fd = -1;
close(pri->control_fd);
......@@ -231,7 +233,7 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask,
struct ethertap_data *pri = data;
tap_check_ips(pri->gate_addr, addr);
if(pri->control_fd == -1)
if (pri->control_fd == -1)
return;
etap_open_addr(addr, netmask, &pri->control_fd);
}
......@@ -241,7 +243,7 @@ static void etap_del_addr(unsigned char *addr, unsigned char *netmask,
{
struct ethertap_data *pri = data;
if(pri->control_fd == -1)
if (pri->control_fd == -1)
return;
etap_close_addr(addr, netmask, &pri->control_fd);
......
/*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
......@@ -19,14 +19,3 @@ struct tuntap_data {
extern const struct net_user_info tuntap_user_info;
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#include "linux/stddef.h"
#include "linux/netdevice.h"
#include "linux/etherdevice.h"
#include "linux/skbuff.h"
#include "linux/init.h"
#include "asm/errno.h"
#include <linux/netdevice.h>
#include <linux/init.h>
#include <linux/skbuff.h>
#include <asm/errno.h>
#include "net_kern.h"
#include "net_user.h"
#include "tuntap.h"
struct tuntap_init {
......@@ -42,15 +39,16 @@ static int tuntap_read(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
if(*skb == NULL) return(-ENOMEM);
return(net_read(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER));
if (*skb == NULL)
return -ENOMEM;
return net_read(fd, skb_mac_header(*skb),
(*skb)->dev->mtu + ETH_HEADER_OTHER);
}
static int tuntap_write(int fd, struct sk_buff **skb,
struct uml_net_private *lp)
{
return(net_write(fd, (*skb)->data, (*skb)->len));
return net_write(fd, (*skb)->data, (*skb)->len);
}
const struct net_kern_info tuntap_kern_info = {
......@@ -67,11 +65,11 @@ int tuntap_setup(char *str, char **mac_out, void *data)
*init = ((struct tuntap_init)
{ .dev_name = NULL,
.gate_addr = NULL });
if(tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
if (tap_setup_common(str, "tuntap", &init->dev_name, mac_out,
&init->gate_addr))
return(0);
return 0;
return(1);
return 1;
}
static struct transport tuntap_transport = {
......
/*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <string.h>
#include <linux/if_tun.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include "net_user.h"
#include "kern_constants.h"
#include "os.h"
#include "tuntap.h"
#include "kern_util.h"
#include "user.h"
#include "os.h"
#define MAX_PACKET ETH_MAX_PACKET
......@@ -37,7 +34,7 @@ static void tuntap_add_addr(unsigned char *addr, unsigned char *netmask,
struct tuntap_data *pri = data;
tap_check_ips(pri->gate_addr, addr);
if((pri->fd == -1) || pri->fixed_config)
if ((pri->fd == -1) || pri->fixed_config)
return;
open_addr(addr, netmask, pri->dev_name);
}
......@@ -47,7 +44,7 @@ static void tuntap_del_addr(unsigned char *addr, unsigned char *netmask,
{
struct tuntap_data *pri = data;
if((pri->fd == -1) || pri->fixed_config)
if ((pri->fd == -1) || pri->fixed_config)
return;
close_addr(addr, netmask, pri->dev_name);
}
......@@ -85,14 +82,14 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
pid = run_helper(tuntap_pre_exec, &data, argv);
if(pid < 0)
if (pid < 0)
return -pid;
close(remote);
msg.msg_name = NULL;
msg.msg_namelen = 0;
if(buffer != NULL){
if (buffer != NULL) {
iov = ((struct iovec) { buffer, buffer_len });
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
......@@ -106,22 +103,24 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
msg.msg_flags = 0;
n = recvmsg(me, &msg, 0);
*used_out = n;
if(n < 0){
if (n < 0) {
err = -errno;
printk("tuntap_open_tramp : recvmsg failed - errno = %d\n",
errno);
printk(UM_KERN_ERR "tuntap_open_tramp : recvmsg failed - "
"errno = %d\n", errno);
return err;
}
CATCH_EINTR(waitpid(pid, NULL, 0));
cmsg = CMSG_FIRSTHDR(&msg);
if(cmsg == NULL){
printk("tuntap_open_tramp : didn't receive a message\n");
if (cmsg == NULL) {
printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a "
"message\n");
return -EINVAL;
}
if((cmsg->cmsg_level != SOL_SOCKET) ||
(cmsg->cmsg_type != SCM_RIGHTS)){
printk("tuntap_open_tramp : didn't receive a descriptor\n");
if ((cmsg->cmsg_level != SOL_SOCKET) ||
(cmsg->cmsg_type != SCM_RIGHTS)) {
printk(UM_KERN_ERR "tuntap_open_tramp : didn't receive a "
"descriptor\n");
return -EINVAL;
}
*fd_out = ((int *) CMSG_DATA(cmsg))[0];
......@@ -137,38 +136,39 @@ static int tuntap_open(void *data)
int err, fds[2], len, used;
err = tap_open_common(pri->dev, pri->gate_addr);
if(err < 0)
if (err < 0)
return err;
if(pri->fixed_config){
if (pri->fixed_config) {
pri->fd = os_open_file("/dev/net/tun",
of_cloexec(of_rdwr(OPENFLAGS())), 0);
if(pri->fd < 0){
printk("Failed to open /dev/net/tun, err = %d\n",
-pri->fd);
if (pri->fd < 0) {
printk(UM_KERN_ERR "Failed to open /dev/net/tun, "
"err = %d\n", -pri->fd);
return pri->fd;
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strlcpy(ifr.ifr_name, pri->dev_name, sizeof(ifr.ifr_name));
if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){
if (ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0) {
err = -errno;
printk("TUNSETIFF failed, errno = %d\n", errno);
printk(UM_KERN_ERR "TUNSETIFF failed, errno = %d\n",
errno);
close(pri->fd);
return err;
}
}
else {
err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds);
if(err){
if (err) {
err = -errno;
printk("tuntap_open : socketpair failed - errno = %d\n",
errno);
printk(UM_KERN_ERR "tuntap_open : socketpair failed - "
"errno = %d\n", errno);
return err;
}
buffer = get_output_buffer(&len);
if(buffer != NULL)
if (buffer != NULL)
len--;
used = 0;
......@@ -176,10 +176,11 @@ static int tuntap_open(void *data)
fds[1], buffer, len, &used);
output = buffer;
if(err < 0) {
if (err < 0) {
printk("%s", output);
free_output_buffer(buffer);
printk("tuntap_open_tramp failed - err = %d\n", -err);
printk(UM_KERN_ERR "tuntap_open_tramp failed - "
"err = %d\n", -err);
return err;
}
......@@ -199,7 +200,7 @@ static void tuntap_close(int fd, void *data)
{
struct tuntap_data *pri = data;
if(!pri->fixed_config)
if (!pri->fixed_config)
iter_addresses(pri->dev, close_addr, pri->dev_name);
close(fd);
pri->fd = -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment