summaryrefslogtreecommitdiff
path: root/package/libs/libpcap/patches/201-space_optimization.patch
blob: f331a18357a185180ba0b3062c79b8f842ebea82 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
--- a/gencode.c
+++ b/gencode.c
@@ -543,20 +543,6 @@ pcap_compile_nopcap(int snaplen_arg, int
 }
 
 /*
- * Clean up a "struct bpf_program" by freeing all the memory allocated
- * in it.
- */
-void
-pcap_freecode(struct bpf_program *program)
-{
-	program->bf_len = 0;
-	if (program->bf_insns != NULL) {
-		free((char *)program->bf_insns);
-		program->bf_insns = NULL;
-	}
-}
-
-/*
  * Backpatch the blocks in 'list' to 'target'.  The 'sense' field indicates
  * which of the jt and jf fields has been resolved and which is a pointer
  * back to another unresolved block (or nil).  At least one of the fields
--- a/pcap.c
+++ b/pcap.c
@@ -1087,6 +1087,59 @@ static const u_char charmap[] = {
 	(u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
 };
 
+/*
+ * Clean up a "struct bpf_program" by freeing all the memory allocated
+ * in it.
+ */
+void
+pcap_freecode(struct bpf_program *program)
+{
+	program->bf_len = 0;
+	if (program->bf_insns != NULL) {
+		free((char *)program->bf_insns);
+		program->bf_insns = NULL;
+	}
+}
+
+/*
+ * Make a copy of a BPF program and put it in the "fcode" member of
+ * a "pcap_t".
+ *
+ * If we fail to allocate memory for the copy, fill in the "errbuf"
+ * member of the "pcap_t" with an error message, and return -1;
+ * otherwise, return 0.
+ */
+int
+install_bpf_program(pcap_t *p, struct bpf_program *fp)
+{
+	size_t prog_size;
+
+	/*
+	 * Validate the program.
+	 */
+	if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
+		snprintf(p->errbuf, sizeof(p->errbuf),
+			"BPF program is not valid");
+		return (-1);
+	}
+
+	/*
+	 * Free up any already installed program.
+	 */
+	pcap_freecode(&p->fcode);
+
+	prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
+	p->fcode.bf_len = fp->bf_len;
+	p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
+	if (p->fcode.bf_insns == NULL) {
+		snprintf(p->errbuf, sizeof(p->errbuf),
+			 "malloc: %s", pcap_strerror(errno));
+		return (-1);
+	}
+	memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
+	return (0);
+}
+
 int
 pcap_strcasecmp(const char *s1, const char *s2)
 {
--- a/optimize.c
+++ b/optimize.c
@@ -2203,45 +2203,6 @@ icode_to_fcode(struct block *root, u_int
 	return fp;
 }
 
-/*
- * Make a copy of a BPF program and put it in the "fcode" member of
- * a "pcap_t".
- *
- * If we fail to allocate memory for the copy, fill in the "errbuf"
- * member of the "pcap_t" with an error message, and return -1;
- * otherwise, return 0.
- */
-int
-install_bpf_program(pcap_t *p, struct bpf_program *fp)
-{
-	size_t prog_size;
-
-	/*
-	 * Validate the program.
-	 */
-	if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
-		snprintf(p->errbuf, sizeof(p->errbuf),
-			"BPF program is not valid");
-		return (-1);
-	}
-
-	/*
-	 * Free up any already installed program.
-	 */
-	pcap_freecode(&p->fcode);
-
-	prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
-	p->fcode.bf_len = fp->bf_len;
-	p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
-	if (p->fcode.bf_insns == NULL) {
-		snprintf(p->errbuf, sizeof(p->errbuf),
-			 "malloc: %s", pcap_strerror(errno));
-		return (-1);
-	}
-	memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
-	return (0);
-}
-
 #ifdef BDEBUG
 static void
 dot_dump_node(struct block *block, struct bpf_program *prog, FILE *out)
--- a/pcap-common.c
+++ b/pcap-common.c
@@ -1372,14 +1372,23 @@ swap_pseudo_headers(int linktype, struct
 	switch (linktype) {
 
 	case DLT_USB_LINUX:
+#ifndef PCAP_SUPPORT_USB
+		return;
+#endif
 		swap_linux_usb_header(hdr, data, 0);
 		break;
 
 	case DLT_USB_LINUX_MMAPPED:
+#ifndef PCAP_SUPPORT_USB
+		return;
+#endif
 		swap_linux_usb_header(hdr, data, 1);
 		break;
 
 	case DLT_NFLOG:
+#ifndef PCAP_SUPPORT_NETFILTER
+		return;
+#endif
 		swap_nflog_header(hdr, data);
 		break;
 	}