2005-04-16 18:20:36 -04:00
|
|
|
/*
|
|
|
|
* user-mode-linux networking multicast transport
|
|
|
|
* Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
|
2007-10-16 04:27:29 -04:00
|
|
|
* Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 18:20:36 -04:00
|
|
|
*
|
|
|
|
* based on the existing uml-networking code, which is
|
2007-10-16 04:27:29 -04:00
|
|
|
* Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
|
2005-04-16 18:20:36 -04:00
|
|
|
* James Leu (jleu@mindspring.net).
|
|
|
|
* Copyright (C) 2001 by various other people who didn't put their name here.
|
|
|
|
*
|
|
|
|
* Licensed under the GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "linux/init.h"
|
2007-10-16 04:27:29 -04:00
|
|
|
#include <linux/netdevice.h>
|
2005-04-16 18:20:36 -04:00
|
|
|
#include "mcast.h"
|
2007-10-16 04:27:29 -04:00
|
|
|
#include "net_kern.h"
|
2005-04-16 18:20:36 -04:00
|
|
|
|
|
|
|
struct mcast_init {
|
|
|
|
char *addr;
|
|
|
|
int port;
|
|
|
|
int ttl;
|
|
|
|
};
|
|
|
|
|
2006-02-01 06:06:29 -05:00
|
|
|
static void mcast_init(struct net_device *dev, void *data)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
|
|
|
struct uml_net_private *pri;
|
|
|
|
struct mcast_data *dpri;
|
|
|
|
struct mcast_init *init = data;
|
|
|
|
|
|
|
|
pri = dev->priv;
|
|
|
|
dpri = (struct mcast_data *) pri->user;
|
|
|
|
dpri->addr = init->addr;
|
|
|
|
dpri->port = init->port;
|
|
|
|
dpri->ttl = init->ttl;
|
|
|
|
dpri->dev = dev;
|
|
|
|
|
2007-10-16 04:27:29 -04:00
|
|
|
printk("mcast backend multicast address: %s:%u, TTL:%u\n",
|
2005-04-16 18:20:36 -04:00
|
|
|
dpri->addr, dpri->port, dpri->ttl);
|
|
|
|
}
|
|
|
|
|
2007-10-16 04:27:31 -04:00
|
|
|
static int mcast_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2007-10-16 04:27:31 -04:00
|
|
|
return net_recvfrom(fd, skb_mac_header(skb),
|
|
|
|
skb->dev->mtu + ETH_HEADER_OTHER);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2007-10-16 04:27:31 -04:00
|
|
|
static int mcast_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
|
2005-04-16 18:20:36 -04:00
|
|
|
{
|
2007-10-16 04:27:31 -04:00
|
|
|
return mcast_user_write(fd, skb->data, skb->len,
|
2007-10-16 04:27:29 -04:00
|
|
|
(struct mcast_data *) &lp->user);
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-09-27 04:50:33 -04:00
|
|
|
static const struct net_kern_info mcast_kern_info = {
|
2005-04-16 18:20:36 -04:00
|
|
|
.init = mcast_init,
|
|
|
|
.protocol = eth_protocol,
|
|
|
|
.read = mcast_read,
|
|
|
|
.write = mcast_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
int mcast_setup(char *str, char **mac_out, void *data)
|
|
|
|
{
|
|
|
|
struct mcast_init *init = data;
|
|
|
|
char *port_str = NULL, *ttl_str = NULL, *remain;
|
|
|
|
char *last;
|
|
|
|
|
|
|
|
*init = ((struct mcast_init)
|
|
|
|
{ .addr = "239.192.168.1",
|
|
|
|
.port = 1102,
|
|
|
|
.ttl = 1 });
|
|
|
|
|
|
|
|
remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
|
|
|
|
NULL);
|
2007-10-16 04:27:29 -04:00
|
|
|
if (remain != NULL) {
|
2005-04-16 18:20:36 -04:00
|
|
|
printk(KERN_ERR "mcast_setup - Extra garbage on "
|
|
|
|
"specification : '%s'\n", remain);
|
2007-10-16 04:27:29 -04:00
|
|
|
return 0;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
2007-10-16 04:27:29 -04:00
|
|
|
|
|
|
|
if (port_str != NULL) {
|
2005-05-20 16:59:09 -04:00
|
|
|
init->port = simple_strtoul(port_str, &last, 10);
|
2007-10-16 04:27:29 -04:00
|
|
|
if ((*last != '\0') || (last == port_str)) {
|
|
|
|
printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
|
2005-04-16 18:20:36 -04:00
|
|
|
port_str);
|
2007-10-16 04:27:29 -04:00
|
|
|
return 0;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-16 04:27:29 -04:00
|
|
|
if (ttl_str != NULL) {
|
2005-04-16 18:20:36 -04:00
|
|
|
init->ttl = simple_strtoul(ttl_str, &last, 10);
|
2007-10-16 04:27:29 -04:00
|
|
|
if ((*last != '\0') || (last == ttl_str)) {
|
|
|
|
printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
|
2005-04-16 18:20:36 -04:00
|
|
|
ttl_str);
|
2007-10-16 04:27:29 -04:00
|
|
|
return 0;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
|
|
|
|
init->port, init->ttl);
|
|
|
|
|
2007-10-16 04:27:29 -04:00
|
|
|
return 1;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct transport mcast_transport = {
|
|
|
|
.list = LIST_HEAD_INIT(mcast_transport.list),
|
|
|
|
.name = "mcast",
|
|
|
|
.setup = mcast_setup,
|
|
|
|
.user = &mcast_user_info,
|
|
|
|
.kern = &mcast_kern_info,
|
|
|
|
.private_size = sizeof(struct mcast_data),
|
|
|
|
.setup_size = sizeof(struct mcast_init),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int register_mcast(void)
|
|
|
|
{
|
|
|
|
register_transport(&mcast_transport);
|
2006-03-31 05:30:10 -05:00
|
|
|
return 0;
|
2005-04-16 18:20:36 -04:00
|
|
|
}
|
|
|
|
|
2006-12-06 23:34:55 -05:00
|
|
|
late_initcall(register_mcast);
|