1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
6 #include <linux/if_arp.h>
7 #include <linux/init.h>
8 #include <linux/netdevice.h>
9 #include <linux/string.h>
15 struct arg_list_dummy_wrapper argw; /* XXX should be simpler... */
18 void slirp_init(struct net_device *dev, void *data)
20 struct uml_net_private *private;
21 struct slirp_data *spri;
22 struct slirp_init *init = data;
25 private = netdev_priv(dev);
26 spri = (struct slirp_data *) private->user;
28 spri->argw = init->argw;
33 slip_proto_init(&spri->slip);
35 dev->hard_header_len = 0;
36 dev->header_ops = NULL;
38 dev->type = ARPHRD_SLIP;
39 dev->tx_queue_len = 256;
40 dev->flags = IFF_NOARP;
41 printk("SLIRP backend - command line:");
42 for (i = 0; spri->argw.argv[i] != NULL; i++)
43 printk(" '%s'",spri->argw.argv[i]);
47 static unsigned short slirp_protocol(struct sk_buff *skbuff)
49 return htons(ETH_P_IP);
52 static int slirp_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
54 return slirp_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
55 (struct slirp_data *) &lp->user);
58 static int slirp_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
60 return slirp_user_write(fd, skb->data, skb->len,
61 (struct slirp_data *) &lp->user);
64 const struct net_kern_info slirp_kern_info = {
66 .protocol = slirp_protocol,
71 static int slirp_setup(char *str, char **mac_out, void *data)
73 struct slirp_init *init = data;
76 *init = ((struct slirp_init) { .argw = { { "slirp", NULL } } });
78 str = split_if_spec(str, mac_out, NULL);
80 if (str == NULL) /* no command line given after MAC addr */
84 if (i >= SLIRP_MAX_ARGS - 1) {
85 printk(KERN_WARNING "slirp_setup: truncating slirp "
89 init->argw.argv[i++] = str;
90 while(*str && *str!=',') {
100 init->argw.argv[i] = NULL;
104 static struct transport slirp_transport = {
105 .list = LIST_HEAD_INIT(slirp_transport.list),
107 .setup = slirp_setup,
108 .user = &slirp_user_info,
109 .kern = &slirp_kern_info,
110 .private_size = sizeof(struct slirp_data),
111 .setup_size = sizeof(struct slirp_init),
114 static int register_slirp(void)
116 register_transport(&slirp_transport);
120 late_initcall(register_slirp);