2 * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
10 #include <net_buffer.h>
11 #include <net_device.h>
12 #include <net_stack.h>
14 #include <KernelExport.h>
17 #include <net/if_types.h>
18 #include <net/if_media.h>
24 struct loopback_device
: net_device
{
28 struct net_buffer_module_info
*gBufferModule
;
29 static struct net_stack_module_info
*sStackModule
;
36 loopback_init(const char *name
, net_device
**_device
)
38 loopback_device
*device
;
40 if (strncmp(name
, "loop", 4))
43 status_t status
= get_module(NET_STACK_MODULE_NAME
, (module_info
**)&sStackModule
);
47 status
= get_module(NET_BUFFER_MODULE_NAME
, (module_info
**)&gBufferModule
);
51 device
= new (std::nothrow
) loopback_device
;
57 memset(device
, 0, sizeof(loopback_device
));
59 strcpy(device
->name
, name
);
60 device
->flags
= IFF_LOOPBACK
| IFF_LINK
;
61 device
->type
= IFT_LOOP
;
63 device
->media
= IFM_ACTIVE
;
69 put_module(NET_BUFFER_MODULE_NAME
);
71 put_module(NET_STACK_MODULE_NAME
);
77 loopback_uninit(net_device
*_device
)
79 loopback_device
*device
= (loopback_device
*)_device
;
81 put_module(NET_STACK_MODULE_NAME
);
82 put_module(NET_BUFFER_MODULE_NAME
);
90 loopback_up(net_device
*device
)
97 loopback_down(net_device
*device
)
103 loopback_control(net_device
*device
, int32 op
, void *argument
,
111 loopback_send_data(net_device
*device
, net_buffer
*buffer
)
113 return sStackModule
->device_enqueue_buffer(device
, buffer
);
118 loopback_set_mtu(net_device
*device
, size_t mtu
)
120 if (mtu
> 65536 || mtu
< 16)
129 loopback_set_promiscuous(net_device
*device
, bool promiscuous
)
136 loopback_set_media(net_device
*device
, uint32 media
)
143 loopback_add_multicast(net_device
*device
, const sockaddr
*address
)
150 loopback_remove_multicast(net_device
*device
, const sockaddr
*address
)
157 loopback_std_ops(int32 op
, ...)
161 case B_MODULE_UNINIT
:
170 net_device_module_info sLoopbackModule
= {
172 "network/devices/loopback/v1",
182 NULL
, // receive_data
184 loopback_set_promiscuous
,
186 loopback_add_multicast
,
187 loopback_remove_multicast
,
190 module_info
*modules
[] = {
191 (module_info
*)&sLoopbackModule
,