Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * user-mode-linux networking multicast transport |
| 3 | * Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org> |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 4 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * based on the existing uml-networking code, which is |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 7 | * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * James Leu (jleu@mindspring.net). |
| 9 | * Copyright (C) 2001 by various other people who didn't put their name here. |
| 10 | * |
| 11 | * Licensed under the GPL. |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include "linux/init.h" |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 15 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "mcast.h" |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 17 | #include "net_kern.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | struct mcast_init { |
| 20 | char *addr; |
| 21 | int port; |
| 22 | int ttl; |
| 23 | }; |
| 24 | |
Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 25 | static void mcast_init(struct net_device *dev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
| 27 | struct uml_net_private *pri; |
| 28 | struct mcast_data *dpri; |
| 29 | struct mcast_init *init = data; |
| 30 | |
| 31 | pri = dev->priv; |
| 32 | dpri = (struct mcast_data *) pri->user; |
| 33 | dpri->addr = init->addr; |
| 34 | dpri->port = init->port; |
| 35 | dpri->ttl = init->ttl; |
| 36 | dpri->dev = dev; |
| 37 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 38 | printk("mcast backend multicast address: %s:%u, TTL:%u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | dpri->addr, dpri->port, dpri->ttl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 42 | static int mcast_read(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 44 | return net_recvfrom(fd, skb_mac_header(skb), |
| 45 | skb->dev->mtu + ETH_HEADER_OTHER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 48 | static int mcast_write(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 50 | return mcast_user_write(fd, skb->data, skb->len, |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 51 | (struct mcast_data *) &lp->user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 54 | static const struct net_kern_info mcast_kern_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .init = mcast_init, |
| 56 | .protocol = eth_protocol, |
| 57 | .read = mcast_read, |
| 58 | .write = mcast_write, |
| 59 | }; |
| 60 | |
| 61 | int mcast_setup(char *str, char **mac_out, void *data) |
| 62 | { |
| 63 | struct mcast_init *init = data; |
| 64 | char *port_str = NULL, *ttl_str = NULL, *remain; |
| 65 | char *last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | *init = ((struct mcast_init) |
| 68 | { .addr = "239.192.168.1", |
| 69 | .port = 1102, |
| 70 | .ttl = 1 }); |
| 71 | |
| 72 | remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str, |
| 73 | NULL); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 74 | if (remain != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | printk(KERN_ERR "mcast_setup - Extra garbage on " |
| 76 | "specification : '%s'\n", remain); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 77 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 79 | |
| 80 | if (port_str != NULL) { |
Jeff Dike | 7c00c31 | 2005-05-20 13:59:09 -0700 | [diff] [blame] | 81 | init->port = simple_strtoul(port_str, &last, 10); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 82 | if ((*last != '\0') || (last == port_str)) { |
| 83 | printk(KERN_ERR "mcast_setup - Bad port : '%s'\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | port_str); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 85 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 89 | if (ttl_str != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | init->ttl = simple_strtoul(ttl_str, &last, 10); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 91 | if ((*last != '\0') || (last == ttl_str)) { |
| 92 | printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | ttl_str); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 94 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr, |
| 99 | init->port, init->ttl); |
| 100 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 101 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static struct transport mcast_transport = { |
| 105 | .list = LIST_HEAD_INIT(mcast_transport.list), |
| 106 | .name = "mcast", |
| 107 | .setup = mcast_setup, |
| 108 | .user = &mcast_user_info, |
| 109 | .kern = &mcast_kern_info, |
| 110 | .private_size = sizeof(struct mcast_data), |
| 111 | .setup_size = sizeof(struct mcast_init), |
| 112 | }; |
| 113 | |
| 114 | static int register_mcast(void) |
| 115 | { |
| 116 | register_transport(&mcast_transport); |
Jeff Dike | f4c57a7 | 2006-03-31 02:30:10 -0800 | [diff] [blame] | 117 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Jeff Dike | 8210fd2 | 2006-12-06 20:34:55 -0800 | [diff] [blame] | 120 | late_initcall(register_mcast); |