embox

Форк
0
/
skbuff_match.c 
98 строк · 1.9 Кб
1
/**
2
 * @file
3
 * @brief NET packet matchers
4
 *
5
 * @date 23.10.11
6
 * @author Alexander Kalmuk
7
 */
8

9

10
#include <util/member.h>
11
#include <string.h>
12
#include <mem/objalloc.h>
13
#include <linux/list.h>
14
#include <assert.h>
15
#include <stdio.h>
16
#include <embox/unit.h>
17

18
#include <net/l3/ipv4/ip.h>
19
#include <net/l4/udp.h>
20

21
#include <pnet/core/node.h>
22
#include <pnet/pack/pnet_pack.h>
23

24
#include <pnet/core/repo.h>
25
#include <pnet/node/skbuff_match/netfilter/match_lin.h>
26
#include <pnet/core/core.h>
27
#include <pnet/core/types.h>
28

29

30
#define NET_NODES_CNT 0x10
31
#define PRINT_WAYS
32

33
OBJALLOC_DEF(matcher_nodes, struct net_node_matcher, NET_NODES_CNT);
34

35
#ifdef PRINT_WAYS
36
static void print_pack_way(struct pnet_pack *pack, match_rule_t rule , int n) {
37
	net_node_t node;
38

39
	printf("%s->", "matcher");
40

41
	if (n == 0) {
42
		node = rule->next_node;
43
		printf("%s->", node->proto->name);
44
	} else {
45
		node = pack->node->rx_dfault;
46
		printf("%s->", node->proto->name);
47
	}
48

49
	while (node->rx_dfault != NULL) {
50
		node = node->rx_dfault;
51
		printf("%s->", node->proto->name);
52
	}
53

54
	printf("%s\n", ";");
55
}
56
#endif
57

58
int match_lin(struct pnet_pack *pack) {
59
	unsigned char *pack_curr, *rule_curr;
60
	net_node_matcher_t node;
61
	struct list_head *h;
62
	match_rule_t curr = NULL;
63
	size_t n = 0;
64

65
	node = (net_node_matcher_t) pack->node;
66

67
	list_for_each (h, &node->match_rx_rules) {
68
		struct sk_buff *skb = pack->data;
69
		curr = member_cast_out(h, struct match_rule, lnk);
70
		rule_curr = curr->skbuf->mac.raw;
71

72
		pack_curr = skb->mac.raw;
73

74
		for (n = MAX_PACK_HEADER_SIZE;
75
				(((*rule_curr == 255) || *pack_curr == *rule_curr)) && n;
76
				--n, ++pack_curr, ++rule_curr)
77
			;
78

79
		if (n == 0) {
80
			pack->node = curr->next_node;
81
			pack->priority = curr->priority;
82
#ifdef PRINT_WAYS
83
		print_pack_way(pack,curr,n);
84
#endif
85
			return NET_HND_FORWARD;
86
		}
87
	}
88
#ifdef PRINT_WAYS
89
		print_pack_way(pack,curr,n);
90
#endif
91
	return NET_HND_FORWARD_DEFAULT;
92
}
93

94
PNET_PROTO_DEF("matcher", {
95
	.rx_hnd = match_lin,
96
	.alloc  = matcher_alloc,
97
	.free   = matcher_free
98
});
99

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

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

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

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