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 | |
| 42 | static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp) |
| 43 | { |
| 44 | *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 45 | if (*skb == NULL) |
| 46 | return -ENOMEM; |
| 47 | return net_recvfrom(fd, skb_mac_header(*skb), |
| 48 | (*skb)->dev->mtu + ETH_HEADER_OTHER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 51 | 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] | 52 | { |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 53 | return mcast_user_write(fd, (*skb)->data, (*skb)->len, |
| 54 | (struct mcast_data *) &lp->user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 57 | static const struct net_kern_info mcast_kern_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | .init = mcast_init, |
| 59 | .protocol = eth_protocol, |
| 60 | .read = mcast_read, |
| 61 | .write = mcast_write, |
| 62 | }; |
| 63 | |
| 64 | int mcast_setup(char *str, char **mac_out, void *data) |
| 65 | { |
| 66 | struct mcast_init *init = data; |
| 67 | char *port_str = NULL, *ttl_str = NULL, *remain; |
| 68 | char *last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | *init = ((struct mcast_init) |
| 71 | { .addr = "239.192.168.1", |
| 72 | .port = 1102, |
| 73 | .ttl = 1 }); |
| 74 | |
| 75 | remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str, |
| 76 | NULL); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 77 | if (remain != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | printk(KERN_ERR "mcast_setup - Extra garbage on " |
| 79 | "specification : '%s'\n", remain); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 80 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 82 | |
| 83 | if (port_str != NULL) { |
Jeff Dike | 7c00c31 | 2005-05-20 13:59:09 -0700 | [diff] [blame] | 84 | init->port = simple_strtoul(port_str, &last, 10); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 85 | if ((*last != '\0') || (last == port_str)) { |
| 86 | printk(KERN_ERR "mcast_setup - Bad port : '%s'\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | port_str); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 88 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 92 | if (ttl_str != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | init->ttl = simple_strtoul(ttl_str, &last, 10); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 94 | if ((*last != '\0') || (last == ttl_str)) { |
| 95 | printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | ttl_str); |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 97 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr, |
| 102 | init->port, init->ttl); |
| 103 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame^] | 104 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static struct transport mcast_transport = { |
| 108 | .list = LIST_HEAD_INIT(mcast_transport.list), |
| 109 | .name = "mcast", |
| 110 | .setup = mcast_setup, |
| 111 | .user = &mcast_user_info, |
| 112 | .kern = &mcast_kern_info, |
| 113 | .private_size = sizeof(struct mcast_data), |
| 114 | .setup_size = sizeof(struct mcast_init), |
| 115 | }; |
| 116 | |
| 117 | static int register_mcast(void) |
| 118 | { |
| 119 | register_transport(&mcast_transport); |
Jeff Dike | f4c57a7 | 2006-03-31 02:30:10 -0800 | [diff] [blame] | 120 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Jeff Dike | 8210fd2 | 2006-12-06 20:34:55 -0800 | [diff] [blame] | 123 | late_initcall(register_mcast); |