-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmatch_table.c
97 lines (86 loc) · 1.91 KB
/
match_table.c
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
/******************************************************************************
* COPYRIGHT (C) Hisilicon.2013
* All rights reserved.
* ***
* Create by Hisilicon 2013-08-15
*
*****************************************************************************/
#include <linux/string.h>
#include <match_table.h>
/*****************************************************************************/
int reg2type(struct match_reg_type *table, int length, int reg, int def)
{
while (length-- > 0) {
if (table->reg == reg)
return table->type;
table++;
}
return def;
}
int type2reg(struct match_reg_type *table, int length, int type, int def)
{
while (length-- > 0) {
if (table->type == type)
return table->reg;
table++;
}
return def;
}
int str2type(struct match_type_str *table, int length, const char *str,
int size, int def)
{
while (length-- > 0) {
if (!strncmp(table->str, str, size))
return table->type;
table++;
}
return def;
}
const char *type2str(struct match_type_str *table, int length, int type,
const char *def)
{
while (length-- > 0) {
if (table->type == type)
return table->str;
table++;
}
return def;
}
int match_reg_to_type(struct match_t *table, int nr_table, int reg, int def)
{
while (nr_table-- > 0) {
if (table->reg == reg)
return table->type;
table++;
}
return def;
}
int match_type_to_reg(struct match_t *table, int nr_table, int type, int def)
{
while (nr_table-- > 0) {
if (table->type == type)
return table->reg;
table++;
}
return def;
}
int match_data_to_type(struct match_t *table, int nr_table, char *data,
int size, int def)
{
while (nr_table-- > 0) {
if (!memcmp(table->data, data, size))
return table->type;
table++;
}
return def;
}
void *match_type_to_data(struct match_t *table, int nr_table, int type,
void *def)
{
while (nr_table-- > 0) {
if (table->type == type)
return table->data;
table++;
}
return def;
}