-
Notifications
You must be signed in to change notification settings - Fork 8
/
list.c
51 lines (41 loc) · 1.05 KB
/
list.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
#include <stdlib.h>
#include <string.h>
#include "pf_nattrack.h"
void laddref(struct pf_nattrack_list **head,
struct pf_nattrack_list *no, struct pf_nattrack_list *ref) {
ladd(head, no);
no->ref = ref;
}
void ladd(struct pf_nattrack_list **head, struct pf_nattrack_list *no) {
if (*head) {
(*head)->prev = no;
}
no->next = *head;
no->prev = NULL;
*head = no;
}
void ldel(struct pf_nattrack_list **head, struct pf_nattrack_list *no) {
if (!(*head) || !no) {
return;
}
if (no->prev) no->prev->next = no->next;
if (no->next) no->next->prev = no->prev;
if (*head == no) {
*head = (*head)->next;
if (*head) (*head)->prev = NULL;
}
}
struct pf_nattrack_list *lfind(struct pf_nattrack_list *head,
struct pf_nattrack *nt) {
struct pf_nattrack_list *it;
it = head;
if (!it)
return NULL;
do {
if (memcmp(&it->nt->c, &nt->c, sizeof(struct conn)) == 0
&& it->nt->proto == nt->proto)
return it;
it = it->next;
} while (it);
return NULL;
}