mcast_kern.c 2.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*
 * user-mode-linux networking multicast transport
 * Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
J
Jeff Dike 已提交
4
 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
L
Linus Torvalds 已提交
5 6
 *
 * based on the existing uml-networking code, which is
J
Jeff Dike 已提交
7
 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
L
Linus Torvalds 已提交
8 9 10 11 12 13 14
 * 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"
J
Jeff Dike 已提交
15
#include <linux/netdevice.h>
L
Linus Torvalds 已提交
16
#include "mcast.h"
J
Jeff Dike 已提交
17
#include "net_kern.h"
L
Linus Torvalds 已提交
18 19 20 21 22 23 24

struct mcast_init {
	char *addr;
	int port;
	int ttl;
};

25
static void mcast_init(struct net_device *dev, void *data)
L
Linus Torvalds 已提交
26 27 28 29 30 31 32 33 34 35 36 37
{
	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;

J
Jeff Dike 已提交
38
	printk("mcast backend multicast address: %s:%u, TTL:%u\n",
L
Linus Torvalds 已提交
39 40 41
	       dpri->addr, dpri->port, dpri->ttl);
}

J
Jeff Dike 已提交
42
static int mcast_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
L
Linus Torvalds 已提交
43
{
J
Jeff Dike 已提交
44 45
	return net_recvfrom(fd, skb_mac_header(skb),
			    skb->dev->mtu + ETH_HEADER_OTHER);
L
Linus Torvalds 已提交
46 47
}

J
Jeff Dike 已提交
48
static int mcast_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
L
Linus Torvalds 已提交
49
{
J
Jeff Dike 已提交
50
	return mcast_user_write(fd, skb->data, skb->len,
J
Jeff Dike 已提交
51
				(struct mcast_data *) &lp->user);
L
Linus Torvalds 已提交
52 53
}

J
Jeff Dike 已提交
54
static const struct net_kern_info mcast_kern_info = {
L
Linus Torvalds 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	.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);
J
Jeff Dike 已提交
74
	if (remain != NULL) {
L
Linus Torvalds 已提交
75 76
		printk(KERN_ERR "mcast_setup - Extra garbage on "
		       "specification : '%s'\n", remain);
J
Jeff Dike 已提交
77
		return 0;
L
Linus Torvalds 已提交
78
	}
J
Jeff Dike 已提交
79 80

	if (port_str != NULL) {
81
		init->port = simple_strtoul(port_str, &last, 10);
J
Jeff Dike 已提交
82 83
		if ((*last != '\0') || (last == port_str)) {
			printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
L
Linus Torvalds 已提交
84
			       port_str);
J
Jeff Dike 已提交
85
			return 0;
L
Linus Torvalds 已提交
86 87 88
		}
	}

J
Jeff Dike 已提交
89
	if (ttl_str != NULL) {
L
Linus Torvalds 已提交
90
		init->ttl = simple_strtoul(ttl_str, &last, 10);
J
Jeff Dike 已提交
91 92
		if ((*last != '\0') || (last == ttl_str)) {
			printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
L
Linus Torvalds 已提交
93
			       ttl_str);
J
Jeff Dike 已提交
94
			return 0;
L
Linus Torvalds 已提交
95 96 97 98 99 100
		}
	}

	printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
	       init->port, init->ttl);

J
Jeff Dike 已提交
101
	return 1;
L
Linus Torvalds 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
}

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);
117
	return 0;
L
Linus Torvalds 已提交
118 119
}

120
late_initcall(register_mcast);