summaryrefslogtreecommitdiff
path: root/pfinet/dummy.c
blob: b744f0f162dda0508beb7684c319bfea4eb50be9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
   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>

struct dummy_device
{
  struct dummy_device *next;
  struct device dev;
  struct net_device_stats stats;
};

/* Linked list of all dummy devices.  */
struct dummy_device *dummy_dev;

struct net_device_stats *
dummy_get_stats (struct device *dev)
{
  struct dummy_device *ddev = (struct dummy_device *) dev->priv;
  return &ddev->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 dummy_device *ddev = (struct dummy_device *) dev->priv;

  ddev->stats.tx_packets++;
  ddev->stats.tx_bytes += skb->len;

  dev_kfree_skb (skb);
  return 0;
}

void
setup_dummy_device (char *name, struct device **device)
{
  error_t err;
  struct dummy_device *ddev;
  struct device *dev;

  ddev = calloc (1, sizeof (struct dummy_device));
  if (!ddev)
    error (2, ENOMEM, "%s", name);
  ddev->next = dummy_dev;
  dummy_dev = ddev;

  *device = dev = &ddev->dev;

  dev->name = strdup (name);

  dev->priv = ddev;
  dev->get_stats = dummy_get_stats;

  dev->open = dummy_open;
  dev->stop = dummy_stop;
  dev->hard_start_xmit = dummy_xmit;
  dev->set_multicast_list = dummy_set_multi;

  /* These are the ones set by drivers/net/net_init.c::ether_setup.  */
  dev->hard_header = eth_header;
  dev->rebuild_header = eth_rebuild_header;
  dev->hard_header_cache = eth_header_cache;
  dev->header_cache_update = eth_header_cache_update;
  dev->hard_header_parse = eth_header_parse;
  /* We can't do these two (and we never try anyway).  */
  /* dev->change_mtu = eth_change_mtu; */
  /* dev->set_mac_address = eth_mac_addr; */

  /* Some more fields */
  dev->type = ARPHRD_ETHER;
  dev->hard_header_len = ETH_HLEN;
  dev->addr_len = ETH_ALEN;
  memset (dev->broadcast, 0xff, ETH_ALEN);
  dev->flags = IFF_BROADCAST | IFF_MULTICAST;
  dev_init_buffers (dev);

  dev->mtu = 1500;
  dev->tx_queue_len = 0;
  dev->flags |= IFF_NOARP;
  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 (dev);
  assert_perror (err);
}