Hi, as an exercise, I implemented a dummy interface for pfinet. Apply the attached diff, and compile pfinet. The interface name is "dummy". settrans /servers/socket/2 /hurd/pfinet -i dummy -a 192.168.0.1 -m 255.255.255.0 -g 192.168.0.2 The dummy interface is the same as the dummy interface in linux: A bottomless pit. You don't get a single packet out of it, and everything you send to it is lost. Note that the above local address 192.168.0.1 is recognized as local. Stuff sent to this address is not lost, of course. The implementation shows two areas where pfinet lacks: Missing support for multiple interfaces, and no support for different types of drivers (in my patch implemented as a switch on the device name). Thanks, Marcus Changelog: 2000-09-30 Marcus Brinkmann <[EMAIL PROTECTED]> * dummy.c: New file. * Makefile (SRCS): Add dummy.c. * main.c (find_device): If interface name is "dummy", call setup_dummy_device, not setup_ethernet_device. * pfinet.h: Prototype setup_dummy_device. -- `Rhubarb is no Egyptian god.' Debian http://www.debian.org Check Key server Marcus Brinkmann GNU http://www.gnu.org for public PGP Key [EMAIL PROTECTED], [EMAIL PROTECTED] PGP Key ID 36E7CD09 http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/ [EMAIL PROTECTED]
diff -x CVS -Nru /mnt/marcus/gnu/cvs/hurd/pfinet/Makefile pfinet/Makefile --- /mnt/marcus/gnu/cvs/hurd/pfinet/Makefile Sat Feb 5 19:32:57 2000 +++ pfinet/Makefile Sat Sep 30 23:00:30 2000 @@ -61,7 +61,7 @@ LINUXSRCS = $(core-srcs) $(ethernet-srcs) $(ipv4-srcs) $(arch-lib-srcs) SRCS = sched.c timer-emul.c socket.c main.c ethernet.c \ io-ops.c socket-ops.c misc.c time.c options.c loopback.c \ - kmem_cache.c stubs.c + kmem_cache.c stubs.c dummy.c MIGSRCS = ioServer.c socketServer.c startup_notifyServer.c OBJS := $(patsubst %.c,%.o,$(LINUXSRCS) $(SRCS) $(MIGSRCS)) LCLHDRS = config.h mapped-time.h mutations.h pfinet.h diff -x CVS -Nru /mnt/marcus/gnu/cvs/hurd/pfinet/dummy.c pfinet/dummy.c --- /mnt/marcus/gnu/cvs/hurd/pfinet/dummy.c Thu Jan 1 01:00:00 1970 +++ pfinet/dummy.c Sat Sep 30 22:58:20 2000 @@ -0,0 +1,122 @@ +/* + Copyright (C) 1995,96,98,99,2000 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "pfinet.h" + +#include <device/device.h> +#include <device/net_status.h> +#include <netinet/in.h> +#include <string.h> +#include <error.h> + +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/if_arp.h> + + +extern struct device ether_dev; + +struct net_device_stats * +dummy_get_stats (struct device *dev) +{ + struct net_device_stats *stats = (struct net_device_stats *) dev->priv; + return stats; +} + +int +dummy_stop (struct device *dev) +{ + return 0; +} + +void +dummy_set_multi (struct device *dev) +{ +} + +int +dummy_open (struct device *dev) +{ + return 0; +} + +int +dummy_xmit (struct sk_buff *skb, struct device *dev) +{ + struct net_device_stats *stats = (struct net_device_stats *)dev->priv; + + stats->tx_packets++; + stats->tx_bytes += skb->len; + + dev_kfree_skb (skb); + return 0; +} + +void +setup_dummy_device (char *name) +{ + error_t err; + + bzero (ðer_dev, sizeof ether_dev); + + ether_dev.name = strdup (name); + + ether_dev.priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL); + if (ether_dev.priv == NULL) + return ENOMEM; + memset(ether_dev.priv, 0, sizeof(struct net_device_stats)); + ether_dev.get_stats = dummy_get_stats; + + ether_dev.open = dummy_open; + ether_dev.stop = dummy_stop; + ether_dev.hard_start_xmit = dummy_xmit; + ether_dev.set_multicast_list = dummy_set_multi; + + /* These are the ones set by drivers/net/net_init.c::ether_setup. */ + ether_dev.hard_header = eth_header; + ether_dev.rebuild_header = eth_rebuild_header; + ether_dev.hard_header_cache = eth_header_cache; + ether_dev.header_cache_update = eth_header_cache_update; + ether_dev.hard_header_parse = eth_header_parse; + /* We can't do these two (and we never try anyway). */ + /* ether_dev.change_mtu = eth_change_mtu; */ + /* ether_dev.set_mac_address = eth_mac_addr; */ + + /* Some more fields */ + ether_dev.type = ARPHRD_ETHER; + ether_dev.hard_header_len = ETH_HLEN; + ether_dev.addr_len = ETH_ALEN; + memset (ether_dev.broadcast, 0xff, ETH_ALEN); + ether_dev.flags = IFF_BROADCAST | IFF_MULTICAST; + dev_init_buffers (ðer_dev); + + ether_dev.mtu = 1500; + ether_dev.tx_queue_len = 0; + ether_dev.flags |= IFF_NOARP; + ether_dev.flags &= ~IFF_MULTICAST; + + /* That should be enough. */ + + /* This call adds the device to the `dev_base' chain, + initializes its `ifindex' member (which matters!), + and tells the protocol stacks about the device. */ + err = - register_netdevice (ðer_dev); + assert_perror (err); +} diff -x CVS -Nru /mnt/marcus/gnu/cvs/hurd/pfinet/main.c pfinet/main.c --- /mnt/marcus/gnu/cvs/hurd/pfinet/main.c Sat Mar 18 19:37:15 2000 +++ pfinet/main.c Sat Sep 30 22:57:35 2000 @@ -143,7 +147,14 @@ name = already_open = strdup (name); - setup_ethernet_device (name); + if (!strcmp(name, "dummy")) + { + setup_dummy_device (name); + } + else + { + setup_ethernet_device (name); + } /* Turn on device. */ dev_open (ðer_dev); diff -x CVS -Nru /mnt/marcus/gnu/cvs/hurd/pfinet/pfinet.h pfinet/pfinet.h --- /mnt/marcus/gnu/cvs/hurd/pfinet/pfinet.h Wed Feb 9 22:59:19 2000 +++ pfinet/pfinet.h Sat Sep 30 22:13:52 2000 @@ -57,6 +57,7 @@ void ethernet_initialize (void); int ethernet_demuxer (mach_msg_header_t *, mach_msg_header_t *); void setup_ethernet_device (char *); +void setup_dummy_device (char *); struct sock_user *make_sock_user (struct socket *, int, int, int); error_t make_sockaddr_port (struct socket *, int, mach_port_t *, mach_msg_type_name_t *);