Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
| 3 | * Licensed under the GPL. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/if_arp.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "net_kern.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "slip.h" |
| 11 | |
| 12 | struct slip_init { |
| 13 | char *gate_addr; |
| 14 | }; |
| 15 | |
WANG Cong | 074a0db | 2008-04-28 02:13:57 -0700 | [diff] [blame] | 16 | static void slip_init(struct net_device *dev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | { |
| 18 | struct uml_net_private *private; |
| 19 | struct slip_data *spri; |
| 20 | struct slip_init *init = data; |
| 21 | |
Wang Chen | 17c324f | 2008-12-04 15:07:33 -0800 | [diff] [blame] | 22 | private = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | spri = (struct slip_data *) private->user; |
Paolo 'Blaisorblade' Giarrusso | 854e981 | 2006-02-01 03:06:25 -0800 | [diff] [blame] | 24 | |
| 25 | memset(spri->name, 0, sizeof(spri->name)); |
| 26 | spri->addr = NULL; |
| 27 | spri->gate_addr = init->gate_addr; |
| 28 | spri->slave = -1; |
| 29 | spri->dev = dev; |
| 30 | |
| 31 | slip_proto_init(&spri->slip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | dev->hard_header_len = 0; |
Jeff Dike | be8ad5a | 2007-10-17 19:35:04 -0700 | [diff] [blame] | 34 | dev->header_ops = NULL; |
Jeff Dike | a3c77c6 | 2005-06-13 15:52:18 -0700 | [diff] [blame] | 35 | dev->addr_len = 0; |
| 36 | dev->type = ARPHRD_SLIP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | dev->tx_queue_len = 256; |
| 38 | dev->flags = IFF_NOARP; |
| 39 | printk("SLIP backend - SLIP IP = %s\n", spri->gate_addr); |
| 40 | } |
| 41 | |
| 42 | static unsigned short slip_protocol(struct sk_buff *skbuff) |
| 43 | { |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 44 | return htons(ETH_P_IP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 47 | static int slip_read(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 49 | return slip_user_read(fd, skb_mac_header(skb), skb->dev->mtu, |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 50 | (struct slip_data *) &lp->user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 53 | static int slip_write(int fd, struct sk_buff *skb, struct uml_net_private *lp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Jeff Dike | b53f35a | 2007-10-16 01:27:31 -0700 | [diff] [blame] | 55 | return slip_user_write(fd, skb->data, skb->len, |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 56 | (struct slip_data *) &lp->user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
WANG Cong | 074a0db | 2008-04-28 02:13:57 -0700 | [diff] [blame] | 59 | static const struct net_kern_info slip_kern_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .init = slip_init, |
| 61 | .protocol = slip_protocol, |
| 62 | .read = slip_read, |
| 63 | .write = slip_write, |
| 64 | }; |
| 65 | |
| 66 | static int slip_setup(char *str, char **mac_out, void *data) |
| 67 | { |
| 68 | struct slip_init *init = data; |
| 69 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 70 | *init = ((struct slip_init) { .gate_addr = NULL }); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 72 | if (str[0] != '\0') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | init->gate_addr = str; |
Jeff Dike | cd1ae0e | 2007-10-16 01:27:29 -0700 | [diff] [blame] | 74 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static struct transport slip_transport = { |
| 78 | .list = LIST_HEAD_INIT(slip_transport.list), |
| 79 | .name = "slip", |
| 80 | .setup = slip_setup, |
| 81 | .user = &slip_user_info, |
| 82 | .kern = &slip_kern_info, |
| 83 | .private_size = sizeof(struct slip_data), |
| 84 | .setup_size = sizeof(struct slip_init), |
| 85 | }; |
| 86 | |
| 87 | static int register_slip(void) |
| 88 | { |
| 89 | register_transport(&slip_transport); |
Jeff Dike | f4c57a7 | 2006-03-31 02:30:10 -0800 | [diff] [blame] | 90 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Jeff Dike | 8210fd2 | 2006-12-06 20:34:55 -0800 | [diff] [blame] | 93 | late_initcall(register_slip); |