blob: 3a7af18cf9442f1c890ea674d9a8f33784a825a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * user-mode-linux networking multicast transport
3 * Copyright (C) 2001 by Harald Welte <laforge@gnumonks.org>
4 *
5 * based on the existing uml-networking code, which is
6 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
7 * James Leu (jleu@mindspring.net).
8 * Copyright (C) 2001 by various other people who didn't put their name here.
9 *
10 * Licensed under the GPL.
11 */
12
13#include "linux/kernel.h"
14#include "linux/init.h"
15#include "linux/netdevice.h"
16#include "linux/etherdevice.h"
17#include "linux/in.h"
18#include "linux/inet.h"
19#include "net_kern.h"
20#include "net_user.h"
21#include "mcast.h"
22
23struct mcast_init {
24 char *addr;
25 int port;
26 int ttl;
27};
28
Paolo 'Blaisorblade' Giarrusso42947cb2006-02-01 03:06:29 -080029static void mcast_init(struct net_device *dev, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 struct uml_net_private *pri;
32 struct mcast_data *dpri;
33 struct mcast_init *init = data;
34
35 pri = dev->priv;
36 dpri = (struct mcast_data *) pri->user;
37 dpri->addr = init->addr;
38 dpri->port = init->port;
39 dpri->ttl = init->ttl;
40 dpri->dev = dev;
41
42 printk("mcast backend ");
Jeff Dikedb805812006-02-01 03:06:23 -080043 printk("multicast address: %s:%u, TTL:%u ",
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 dpri->addr, dpri->port, dpri->ttl);
45
46 printk("\n");
47}
48
49static int mcast_read(int fd, struct sk_buff **skb, struct uml_net_private *lp)
50{
51 *skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
52 if(*skb == NULL) return(-ENOMEM);
53 return(net_recvfrom(fd, (*skb)->mac.raw,
54 (*skb)->dev->mtu + ETH_HEADER_OTHER));
55}
56
57static int mcast_write(int fd, struct sk_buff **skb,
58 struct uml_net_private *lp)
59{
60 return mcast_user_write(fd, (*skb)->data, (*skb)->len,
61 (struct mcast_data *) &lp->user);
62}
63
64static struct net_kern_info mcast_kern_info = {
65 .init = mcast_init,
66 .protocol = eth_protocol,
67 .read = mcast_read,
68 .write = mcast_write,
69};
70
71int mcast_setup(char *str, char **mac_out, void *data)
72{
73 struct mcast_init *init = data;
74 char *port_str = NULL, *ttl_str = NULL, *remain;
75 char *last;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 *init = ((struct mcast_init)
78 { .addr = "239.192.168.1",
79 .port = 1102,
80 .ttl = 1 });
81
82 remain = split_if_spec(str, mac_out, &init->addr, &port_str, &ttl_str,
83 NULL);
84 if(remain != NULL){
85 printk(KERN_ERR "mcast_setup - Extra garbage on "
86 "specification : '%s'\n", remain);
87 return(0);
88 }
89
90 if(port_str != NULL){
Jeff Dike7c00c312005-05-20 13:59:09 -070091 init->port = simple_strtoul(port_str, &last, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 if((*last != '\0') || (last == port_str)){
93 printk(KERN_ERR "mcast_setup - Bad port : '%s'\n",
94 port_str);
95 return(0);
96 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
98
99 if(ttl_str != NULL){
100 init->ttl = simple_strtoul(ttl_str, &last, 10);
101 if((*last != '\0') || (last == ttl_str)){
102 printk(KERN_ERR "mcast_setup - Bad ttl : '%s'\n",
103 ttl_str);
104 return(0);
105 }
106 }
107
108 printk(KERN_INFO "Configured mcast device: %s:%u-%u\n", init->addr,
109 init->port, init->ttl);
110
111 return(1);
112}
113
114static struct transport mcast_transport = {
115 .list = LIST_HEAD_INIT(mcast_transport.list),
116 .name = "mcast",
117 .setup = mcast_setup,
118 .user = &mcast_user_info,
119 .kern = &mcast_kern_info,
120 .private_size = sizeof(struct mcast_data),
121 .setup_size = sizeof(struct mcast_init),
122};
123
124static int register_mcast(void)
125{
126 register_transport(&mcast_transport);
Jeff Dikef4c57a72006-03-31 02:30:10 -0800127 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130__initcall(register_mcast);