android_kernel_xiaomi_sm8350/arch/um/drivers/vde_kern.c
Jeff Dike b53f35a809 uml: network driver MTU cleanups
A bunch of MTU-related cleanups in the network code.

First, there is the addition of the notion of a maximally-sized packet, which
is the MTU plus headers.  This is used to size the skb that will receive a
packet.  This allows ether_adjust_skb to go away, as it was used to resize the
skb after it was allocated.

Since the skb passed into the low-level read routine is no longer resized, and
possibly reallocated, there, they (and the write routines) don't need to get
an sk_buff **.  They just need the sk_buff * now.  The callers of
ether_adjust_skb still need to do the skb_put, so that's now inlined.

The MAX_PACKET definitions in most of the drivers are gone.

The set_mtu methods were all the same and did nothing, so they can be
removed.

The ethertap driver had a typo which doubled the size of the packet rather
than adding two bytes to it.  It also wasn't defining its setup_size, causing
a zero-byte kmalloc and crash when the invalid pointer returned from kmalloc
was dereferenced.

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>
2007-10-16 09:43:08 -07:00

130 lines
3.0 KiB
C

/*
* Copyright (C) 2007 Luca Bigliardi (shammash@artha.org).
* Licensed under the GPL.
*
* Transport usage:
* ethN=vde,<vde_switch>,<mac addr>,<port>,<group>,<mode>,<description>
*
*/
#include "linux/init.h"
#include <linux/netdevice.h>
#include "net_kern.h"
#include "net_user.h"
#include "vde.h"
static void vde_init(struct net_device *dev, void *data)
{
struct vde_init *init = data;
struct uml_net_private *pri;
struct vde_data *vpri;
pri = dev->priv;
vpri = (struct vde_data *) pri->user;
vpri->vde_switch = init->vde_switch;
vpri->descr = init->descr ? init->descr : "UML vde_transport";
vpri->args = NULL;
vpri->conn = NULL;
vpri->dev = dev;
printk("vde backend - %s, ", vpri->vde_switch ?
vpri->vde_switch : "(default socket)");
vde_init_libstuff(vpri, init);
printk("\n");
}
static int vde_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
struct vde_data *pri = (struct vde_data *) &lp->user;
if (pri->conn != NULL)
return vde_user_read(pri->conn, skb_mac_header(skb),
skb->dev->mtu + ETH_HEADER_OTHER);
printk(KERN_ERR "vde_read - we have no VDECONN to read from");
return -EBADF;
}
static int vde_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
{
struct vde_data *pri = (struct vde_data *) &lp->user;
if (pri->conn != NULL)
return vde_user_write((void *)pri->conn, skb->data,
skb->len);
printk(KERN_ERR "vde_write - we have no VDECONN to write to");
return -EBADF;
}
static const struct net_kern_info vde_kern_info = {
.init = vde_init,
.protocol = eth_protocol,
.read = vde_read,
.write = vde_write,
};
static int vde_setup(char *str, char **mac_out, void *data)
{
struct vde_init *init = data;
char *remain, *port_str = NULL, *mode_str = NULL, *last;
*init = ((struct vde_init)
{ .vde_switch = NULL,
.descr = NULL,
.port = 0,
.group = NULL,
.mode = 0 });
remain = split_if_spec(str, &init->vde_switch, mac_out, &port_str,
&init->group, &mode_str, &init->descr, NULL);
if (remain != NULL)
printk(KERN_WARNING "vde_setup - Ignoring extra data :"
"'%s'\n", remain);
if (port_str != NULL) {
init->port = simple_strtoul(port_str, &last, 10);
if ((*last != '\0') || (last == port_str)) {
printk(KERN_ERR "vde_setup - Bad port : '%s'\n",
port_str);
return 0;
}
}
if (mode_str != NULL) {
init->mode = simple_strtoul(mode_str, &last, 8);
if ((*last != '\0') || (last == mode_str)) {
printk(KERN_ERR "vde_setup - Bad mode : '%s'\n",
mode_str);
return 0;
}
}
printk(KERN_INFO "Configured vde device: %s\n", init->vde_switch ?
init->vde_switch : "(default socket)");
return 1;
}
static struct transport vde_transport = {
.list = LIST_HEAD_INIT(vde_transport.list),
.name = "vde",
.setup = vde_setup,
.user = &vde_user_info,
.kern = &vde_kern_info,
.private_size = sizeof(struct vde_data),
.setup_size = sizeof(struct vde_init),
};
static int register_vde(void)
{
register_transport(&vde_transport);
return 0;
}
late_initcall(register_vde);