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
|
#include "flowood.h"
#include "flowood_fun.h"
#include "flwd_net.h"
#include "MESA_htable.h"
#include "MESA_list_queue.h"
#include "MESA_handle_logger.h"
#include "MESA_list_count.h"
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <assert.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
uchar * flwd_nat_htable_key_dup(const uchar *key, uint key_size)
{
const flwd_tuple5_t *stack_tuple5 = (flwd_tuple5_t *)key;
flwd_tuple5_t *heap_tuple5 = (flwd_tuple5_t *)malloc(sizeof(flwd_tuple5_t));
memcpy(heap_tuple5, stack_tuple5, sizeof(flwd_tuple5_t));
if(FLWD_IP_ADDR_TYPE_V6 == stack_tuple5->addr_type){
/* �����v6, ��Ҫ����mallo, memcpyIP��ַ, ע��free!! */
heap_tuple5->ippair_v6 = (flwd_ippair_v6_t *)malloc(sizeof(flwd_ippair_v6_t));
memcpy(&heap_tuple5->ippair_v6->sip_net_order, &stack_tuple5->ippair_v6->sip_net_order, sizeof(struct in6_addr));
memcpy(&heap_tuple5->ippair_v6->dip_net_order, &stack_tuple5->ippair_v6->dip_net_order, sizeof(struct in6_addr));
}
return (uchar *)heap_tuple5;
}
void flwd_nat_htable_key_free(uchar *key, uint key_size)
{
flwd_tuple5_t *raw_tuple5 = (flwd_tuple5_t *)key;
if(FLWD_IP_ADDR_TYPE_V6 == raw_tuple5->addr_type){
free(raw_tuple5->ippair_v6);
}
free(key);
return;
}
uint flwd_nat_htable_key2index(const MESA_htable_handle table, const uchar * key, uint size)
{
const flwd_tuple5_t *tuple5 = (flwd_tuple5_t *)key;
return flwd_tuple5_hash(tuple5, 0);
}
int flwd_nat_htable_key_cmp(const uchar * key1, uint size1, const uchar * key2, uint size2)
{
const flwd_tuple5_t *tp1;
const flwd_tuple5_t *tp2;
tp1 = (flwd_tuple5_t *)key1;
tp2 = (flwd_tuple5_t *)key2;
if(tp1->addr_type != tp2->addr_type){
return -1;
}
if(tp1->protocol != tp2->protocol){
return -1;
}
if(tp1->sport_net_order != tp2->sport_net_order){
return -1;
}
if(tp1->dport_net_order != tp2->dport_net_order){
return -1;
}
if(flwd_likely(FLWD_IP_ADDR_TYPE_V4 == tp1->addr_type)){
if(tp1->ippair_v4.sip_net_order != tp2->ippair_v4.sip_net_order){
return -1;
}
if(tp1->ippair_v4.dip_net_order != tp2->ippair_v4.dip_net_order){
return -1;
}
}else{
if(memcmp(&tp1->ippair_v6->sip_net_order, &tp2->ippair_v6->sip_net_order, sizeof(struct in6_addr))){
return -1;
}
if(memcmp(&tp1->ippair_v6->dip_net_order, &tp2->ippair_v6->dip_net_order, sizeof(struct in6_addr))){
return -1;
}
}
return 0;
}
|