blob: d19faec7046e5cdb05eba59ff32c1c1beb477beb [file] [log] [blame]
Jeff Dikecd1ae0e2007-10-16 01:27:29 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -07009#include "net_kern.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include "slip.h"
11
12struct slip_init {
13 char *gate_addr;
14};
15
WANG Cong074a0db2008-04-28 02:13:57 -070016static void slip_init(struct net_device *dev, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017{
18 struct uml_net_private *private;
19 struct slip_data *spri;
20 struct slip_init *init = data;
21
22 private = dev->priv;
23 spri = (struct slip_data *) private->user;
Paolo 'Blaisorblade' Giarrusso854e9812006-02-01 03:06:25 -080024
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 Torvalds1da177e2005-04-16 15:20:36 -070032
33 dev->init = NULL;
34 dev->hard_header_len = 0;
Jeff Dikebe8ad5a2007-10-17 19:35:04 -070035 dev->header_ops = NULL;
Jeff Dikea3c77c62005-06-13 15:52:18 -070036 dev->addr_len = 0;
37 dev->type = ARPHRD_SLIP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 dev->tx_queue_len = 256;
39 dev->flags = IFF_NOARP;
40 printk("SLIP backend - SLIP IP = %s\n", spri->gate_addr);
41}
42
43static unsigned short slip_protocol(struct sk_buff *skbuff)
44{
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070045 return htons(ETH_P_IP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Jeff Dikeb53f35a2007-10-16 01:27:31 -070048static int slip_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Jeff Dikeb53f35a2007-10-16 01:27:31 -070050 return slip_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070051 (struct slip_data *) &lp->user);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Jeff Dikeb53f35a2007-10-16 01:27:31 -070054static int slip_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Jeff Dikeb53f35a2007-10-16 01:27:31 -070056 return slip_user_write(fd, skb->data, skb->len,
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070057 (struct slip_data *) &lp->user);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
WANG Cong074a0db2008-04-28 02:13:57 -070060static const struct net_kern_info slip_kern_info = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 .init = slip_init,
62 .protocol = slip_protocol,
63 .read = slip_read,
64 .write = slip_write,
65};
66
67static int slip_setup(char *str, char **mac_out, void *data)
68{
69 struct slip_init *init = data;
70
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070071 *init = ((struct slip_init) { .gate_addr = NULL });
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070073 if (str[0] != '\0')
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 init->gate_addr = str;
Jeff Dikecd1ae0e2007-10-16 01:27:29 -070075 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
78static struct transport slip_transport = {
79 .list = LIST_HEAD_INIT(slip_transport.list),
80 .name = "slip",
81 .setup = slip_setup,
82 .user = &slip_user_info,
83 .kern = &slip_kern_info,
84 .private_size = sizeof(struct slip_data),
85 .setup_size = sizeof(struct slip_init),
86};
87
88static int register_slip(void)
89{
90 register_transport(&slip_transport);
Jeff Dikef4c57a72006-03-31 02:30:10 -080091 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Jeff Dike8210fd22006-12-06 20:34:55 -080094late_initcall(register_slip);