embox

Форк
0
73 строки · 1.5 Кб
1

2
#include <assert.h>
3
#include <embox/unit.h>
4
#include <errno.h>
5
#include <net/l2/ethernet.h>
6
#include <net/l3/arp.h>
7
#include <net/netdevice.h>
8
#include <net/inetdevice.h>
9
#include <net/skbuff.h>
10
#include <net/l0/net_entry.h>
11
#include <net/net_namespace.h>
12
#include <net/netdevice.h>
13

14
static int veth_xmit(struct net_device *dev,
15
		struct sk_buff *skb) {
16
	struct net_device_stats *lb_stats;
17
	size_t skb_len;
18

19
	if ((skb == NULL) || (dev == NULL)) {
20
		return -EINVAL;
21
	}
22

23
	skb_len = skb->len;
24

25
	lb_stats = &dev->stats;
26

27
	skb->dev = (struct net_device *) dev->priv;
28
	if (netif_rx(skb) == NET_RX_SUCCESS) {
29
		lb_stats->rx_packets++;
30
		lb_stats->rx_bytes += skb_len;
31
	} else {
32
		lb_stats->rx_err++;
33
	}
34

35
	return 0;
36
}
37

38
static const struct net_driver veth_ops = {
39
	.xmit = veth_xmit
40
};
41

42
struct net_device *veth_alloc(struct net_device **v1, struct net_device **v2) {
43
	struct net_device *veth1, *veth2;
44
	int ret;
45

46
	veth1 = etherdev_alloc(sizeof(struct net_device *));
47
	if (!veth1) {
48
		return NULL;
49
	}
50
	ret = inetdev_register_dev(veth1);
51
	if (ret != 0) {
52
		return NULL;
53
	}
54

55
	veth2 = etherdev_alloc(sizeof(struct net_device *));
56
	if (!veth2) {
57
		return NULL;
58
	}
59
	ret = inetdev_register_dev(veth2);
60
	if (ret != 0) {
61
		return NULL;
62
	}
63

64
	assign_net_ns(veth1->net_ns, init_net_ns);
65
	assign_net_ns(veth2->net_ns, init_net_ns);
66
	veth1->priv = (void *)veth2;
67
	veth2->priv = (void *)veth1;
68
	veth1->drv_ops = &veth_ops;
69
	veth2->drv_ops = &veth_ops;
70

71
	*v1 = veth1;
72
	*v2 = veth2;
73
	return (struct net_device *)1;
74
}
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.