1*dbddf429SAlex Dewar // SPDX-License-Identifier: GPL-2.0
2cd1ae0e4SJeff Dike /*
3cd1ae0e4SJeff Dike * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4cd1ae0e4SJeff Dike */
5cd1ae0e4SJeff Dike
6cd1ae0e4SJeff Dike #include <linux/if_arp.h>
7cd1ae0e4SJeff Dike #include <linux/init.h>
8cd1ae0e4SJeff Dike #include <linux/netdevice.h>
937185b33SAl Viro #include <net_kern.h>
101da177e4SLinus Torvalds #include "slip.h"
111da177e4SLinus Torvalds
121da177e4SLinus Torvalds struct slip_init {
131da177e4SLinus Torvalds char *gate_addr;
141da177e4SLinus Torvalds };
151da177e4SLinus Torvalds
slip_init(struct net_device * dev,void * data)16074a0db8SWANG Cong static void slip_init(struct net_device *dev, void *data)
171da177e4SLinus Torvalds {
181da177e4SLinus Torvalds struct uml_net_private *private;
191da177e4SLinus Torvalds struct slip_data *spri;
201da177e4SLinus Torvalds struct slip_init *init = data;
211da177e4SLinus Torvalds
2217c324faSWang Chen private = netdev_priv(dev);
231da177e4SLinus Torvalds spri = (struct slip_data *) private->user;
24854e981cSPaolo 'Blaisorblade' Giarrusso
25854e981cSPaolo 'Blaisorblade' Giarrusso memset(spri->name, 0, sizeof(spri->name));
26854e981cSPaolo 'Blaisorblade' Giarrusso spri->addr = NULL;
27854e981cSPaolo 'Blaisorblade' Giarrusso spri->gate_addr = init->gate_addr;
28854e981cSPaolo 'Blaisorblade' Giarrusso spri->slave = -1;
29854e981cSPaolo 'Blaisorblade' Giarrusso spri->dev = dev;
30854e981cSPaolo 'Blaisorblade' Giarrusso
31854e981cSPaolo 'Blaisorblade' Giarrusso slip_proto_init(&spri->slip);
321da177e4SLinus Torvalds
331da177e4SLinus Torvalds dev->hard_header_len = 0;
34be8ad5a4SJeff Dike dev->header_ops = NULL;
35a3c77c67SJeff Dike dev->addr_len = 0;
36a3c77c67SJeff Dike dev->type = ARPHRD_SLIP;
371da177e4SLinus Torvalds dev->tx_queue_len = 256;
381da177e4SLinus Torvalds dev->flags = IFF_NOARP;
391da177e4SLinus Torvalds printk("SLIP backend - SLIP IP = %s\n", spri->gate_addr);
401da177e4SLinus Torvalds }
411da177e4SLinus Torvalds
slip_protocol(struct sk_buff * skbuff)421da177e4SLinus Torvalds static unsigned short slip_protocol(struct sk_buff *skbuff)
431da177e4SLinus Torvalds {
44cd1ae0e4SJeff Dike return htons(ETH_P_IP);
451da177e4SLinus Torvalds }
461da177e4SLinus Torvalds
slip_read(int fd,struct sk_buff * skb,struct uml_net_private * lp)47b53f35a8SJeff Dike static int slip_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
481da177e4SLinus Torvalds {
49b53f35a8SJeff Dike return slip_user_read(fd, skb_mac_header(skb), skb->dev->mtu,
50cd1ae0e4SJeff Dike (struct slip_data *) &lp->user);
511da177e4SLinus Torvalds }
521da177e4SLinus Torvalds
slip_write(int fd,struct sk_buff * skb,struct uml_net_private * lp)53b53f35a8SJeff Dike static int slip_write(int fd, struct sk_buff *skb, struct uml_net_private *lp)
541da177e4SLinus Torvalds {
55b53f35a8SJeff Dike return slip_user_write(fd, skb->data, skb->len,
56cd1ae0e4SJeff Dike (struct slip_data *) &lp->user);
571da177e4SLinus Torvalds }
581da177e4SLinus Torvalds
59074a0db8SWANG Cong static const struct net_kern_info slip_kern_info = {
601da177e4SLinus Torvalds .init = slip_init,
611da177e4SLinus Torvalds .protocol = slip_protocol,
621da177e4SLinus Torvalds .read = slip_read,
631da177e4SLinus Torvalds .write = slip_write,
641da177e4SLinus Torvalds };
651da177e4SLinus Torvalds
slip_setup(char * str,char ** mac_out,void * data)661da177e4SLinus Torvalds static int slip_setup(char *str, char **mac_out, void *data)
671da177e4SLinus Torvalds {
681da177e4SLinus Torvalds struct slip_init *init = data;
691da177e4SLinus Torvalds
70cd1ae0e4SJeff Dike *init = ((struct slip_init) { .gate_addr = NULL });
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds if (str[0] != '\0')
731da177e4SLinus Torvalds init->gate_addr = str;
74cd1ae0e4SJeff Dike return 1;
751da177e4SLinus Torvalds }
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds static struct transport slip_transport = {
781da177e4SLinus Torvalds .list = LIST_HEAD_INIT(slip_transport.list),
791da177e4SLinus Torvalds .name = "slip",
801da177e4SLinus Torvalds .setup = slip_setup,
811da177e4SLinus Torvalds .user = &slip_user_info,
821da177e4SLinus Torvalds .kern = &slip_kern_info,
831da177e4SLinus Torvalds .private_size = sizeof(struct slip_data),
841da177e4SLinus Torvalds .setup_size = sizeof(struct slip_init),
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds
register_slip(void)871da177e4SLinus Torvalds static int register_slip(void)
881da177e4SLinus Torvalds {
891da177e4SLinus Torvalds register_transport(&slip_transport);
90f4c57a78SJeff Dike return 0;
911da177e4SLinus Torvalds }
921da177e4SLinus Torvalds
938210fd2aSJeff Dike late_initcall(register_slip);
94