summaryrefslogtreecommitdiffstats
path: root/userspace/patches/incremental-patches/ebtables-v2.0pre7.001.diff
blob: 697b1f903c7e0af613c4df8721ff8d7aa787541d (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
--- ebtables-v2.0pre6/Makefile	Thu May 30 18:39:04 2002
+++ ebtables-v2.0pre7.001/Makefile	Thu Jun  6 19:18:29 2002
@@ -2,7 +2,7 @@
 
 KERNEL_DIR?=/usr/src/linux
 PROGNAME:=ebtables
-PROGVERSION:="2.0pre6 (May 2002)"
+PROGVERSION:="2.0pre7 (June 2002)"
 
 MANDIR?=/usr/local/man
 CFLAGS:=-Wall -Wunused
@@ -29,6 +29,7 @@
 
 .PHONY: symlink
 symlink:
+	rm -f /usr/include/linux
 	ln -fs $(KERNEL_DIR)/include/linux /usr/include/linux
 
 communication.o: communication.c include/ebtables_u.h
@@ -53,6 +54,6 @@
 	ebtables /etc/ethertypes
 
 clean:
-	-rm -f ebtables
+	rm -f ebtables
 	rm -f *.o *.c~
 	rm -f extensions/*.o extensions/*.c~
--- ebtables-v2.0pre6/ebtables.c	Fri May  3 21:33:55 2002
+++ ebtables-v2.0pre7.001/ebtables.c	Wed Jun  5 21:42:17 2002
@@ -31,6 +31,7 @@
 #include <linux/netfilter_bridge/ebtables.h>
 #include <linux/br_db.h> // the database
 #include <netinet/in.h>
+#include <netinet/ether.h>
 #include <asm/types.h>
 #include "include/ebtables_u.h"
 
@@ -349,7 +350,7 @@
 	return 0;
 }
 
-// helper function: processes a line of data from the file /etc/etherproto
+// helper function: processes a line of data from the file /etc/ethertypes
 int get_a_line(char *buffer, char *value, FILE *ifp)
 {
 	int i, hlp;
@@ -389,7 +390,7 @@
 			break;
 	}
 	if (i == 5) return -1;
-	/* discard comments at the end of a line */
+	// discard comments at the end of a line
 	if (value[i] == '\t' || value[i] == ' ')
 		while (1) {
 			hlp = fscanf(ifp, "%c", &anotherhlp);
@@ -493,14 +494,12 @@
 				printf("Broadcast");
 				goto endsrc;
 			}
-			for (j = 0; j < ETH_ALEN; j++)
-				printf("%02x%s", hlp->sourcemac[j],
-				   (j == ETH_ALEN - 1) ? "" : ":");
+			printf("%s", ether_ntoa((struct ether_addr *)
+			   hlp->sourcemac));
 			if (memcmp(hlp->sourcemsk, hlpmsk, 6)) {
 				printf("/");
-				for (j = 0; j < ETH_ALEN; j++)
-					printf("%02x%s", hlp->sourcemsk[j],
-					   (j == ETH_ALEN - 1) ? "" : ":");
+				printf("%s", ether_ntoa((struct ether_addr *)
+				   hlp->sourcemsk));
 			}
 endsrc:
 			printf(", ");
@@ -526,14 +525,12 @@
 				printf("Broadcast");
 				goto enddst;
 			}
-			for (j = 0; j < ETH_ALEN; j++)
-				printf("%02x%s", hlp->destmac[j],
-				   (j == ETH_ALEN - 1) ? "" : ":");
+			printf("%s", ether_ntoa((struct ether_addr *)
+			   hlp->destmac));
 			if (memcmp(hlp->destmsk, hlpmsk, 6)) {
 				printf("/");
-				for (j = 0; j < ETH_ALEN; j++)
-					printf("%02x%s", hlp->destmsk[j],
-					   (j == ETH_ALEN - 1) ? "" : ":");
+				printf("%s", ether_ntoa((struct ether_addr *)
+				   hlp->destmsk));
 			}
 enddst:
 			printf(", ");
@@ -1132,31 +1129,11 @@
 }
 
 // put the mac address into 6 (ETH_ALEN) bytes
-int getmac(char *from, char *to)
-{
-	int i, tmp;
-	char *buffer;
-
-	if (strlen(from) != 3 * ETH_ALEN - 1)
-		return -1;
-	for (i = 1; i < ETH_ALEN; i++) {
-		if (from[i*3 - 1] != ':')
-			return -1;
-		from[i*3 - 1] = '\0';
-	}
-	for (i = 0; i < ETH_ALEN; i++) {
-		tmp = strtol(from + i*3, &buffer, 16);
-		if (*buffer != '\0' || tmp > 255 || tmp < 0)
-			return -1;
-		to[i] = (unsigned char) tmp;
-	}
-	return 0;
-}
-
 int getmac_and_mask(char *from, char *to, char *mask)
 {
 	char *p;
 	int i;
+	struct ether_addr *addr;
 
 	if (strcasecmp(from, "Unicast") == 0) {
 		memcpy(to, mac_type_unicast, ETH_ALEN);
@@ -1175,12 +1152,14 @@
 	}
 	if ( (p = strrchr(from, '/')) != NULL) {
 		*p = '\0';
-		if (getmac(p + 1, mask))
+		if (!(addr = ether_aton(p + 1)))
 			return -1;
+		memcpy(mask, addr, ETH_ALEN);
 	} else
 		memset(mask, 0xff, ETH_ALEN);
-	if (getmac(from, to))
+	if (!(addr = ether_aton(from)))
 		return -1;
+	memcpy(to, addr, ETH_ALEN);
 	for (i = 0; i < ETH_ALEN; i++)
 		to[i] &= mask[i];
 	return 0;
--- ebtables-v2.0pre6/communication.c	Fri May  3 21:08:24 2002
+++ ebtables-v2.0pre7.001/communication.c	Wed Jun  5 20:17:25 2002
@@ -172,8 +172,9 @@
 	// give the data to the kernel
 	optlen = sizeof(struct ebt_replace) + repl->entries_size;
 	if (setsockopt(sockfd, IPPROTO_IP, EBT_SO_SET_ENTRIES, repl, optlen))
-		print_error("Couldn't update kernel chains, you probably need "
-		   "to insmod an extension");	
+		print_error("The kernel doesn't support a certain ebtables"
+		  " extension, consider recompiling your kernel or insmod"
+		  " the extension");	
 }
 
 // gets executed after deliver_table
@@ -379,9 +380,9 @@
 	optlen = sizeof(struct ebt_replace);
 	strcpy(repl.name, u_repl->name);
 	if (getsockopt(sockfd, IPPROTO_IP, EBT_SO_GET_INFO, &repl, &optlen))
-		print_error("A kernel module needed by your command is probably"
-		            " not loaded. Try insmod ebtables or"
-		            " insmod ebtable_%s", repl.name);
+		print_error("The %s table is not supported by the kernel,"
+		  " consider recompiling your kernel or try insmod ebt_%s",
+		  repl.name, repl.name);
 
 	if ( !(repl.entries = (char *) malloc(repl.entries_size)) )
 		print_memory();
--- ebtables-v2.0pre6/extensions/ebt_nat.c	Sat Apr 27 22:31:21 2002
+++ ebtables-v2.0pre7.001/extensions/ebt_nat.c	Wed Jun  5 21:43:11 2002
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
+#include <netinet/ether.h>
 #include <linux/netfilter_bridge/ebtables.h>
 #include <getopt.h>
 #include "../include/ebtables_u.h"
@@ -74,13 +75,15 @@
 {
 	int i;
 	struct ebt_nat_info *natinfo = (struct ebt_nat_info *)(*target)->data;
+	struct ether_addr *addr;
 
 	switch (c) {
 	case NAT_S:
 		check_option(flags, OPT_SNAT);
 		to_source_supplied = 1;
-		if (getmac(optarg, natinfo->mac))
+		if (!(addr = ether_aton(optarg)))
 			print_error("Problem with specified to-source mac");
+		memcpy(natinfo->mac, addr, ETH_ALEN);
 		break;
 	case NAT_S_TARGET:
 		check_option(flags, OPT_SNAT_TARGET);
@@ -106,14 +109,16 @@
 {
 	int i;
 	struct ebt_nat_info *natinfo = (struct ebt_nat_info *)(*target)->data;
+	struct ether_addr *addr;
 
 	switch (c) {
 	case NAT_D:
 		check_option(flags, OPT_DNAT);
 		to_dest_supplied = 1;
-		if (getmac(optarg, natinfo->mac))
+		if (!(addr = ether_aton(optarg)))
 			print_error("Problem with specified "
 			            "to-destination mac");
+		memcpy(natinfo->mac, addr, ETH_ALEN);
 		break;
 	case NAT_D_TARGET:
 		check_option(flags, OPT_DNAT_TARGET);
@@ -155,12 +160,9 @@
    const struct ebt_entry_target *target)
 {
 	struct ebt_nat_info *natinfo = (struct ebt_nat_info *)target->data;
-	int i;
 
 	printf("snat - to: ");
-	for (i = 0; i < ETH_ALEN; i++)
-		printf("%02x%s",
-		   natinfo->mac[i], (i == ETH_ALEN - 1) ? "" : ":");
+	printf("%s", ether_ntoa((struct ether_addr *)natinfo->mac));
 	printf(" --snat-target %s", standard_targets[natinfo->target]);
 }
 
@@ -168,12 +170,9 @@
    const struct ebt_entry_target *target)
 {
 	struct ebt_nat_info *natinfo = (struct ebt_nat_info *)target->data;
-	int i;
 
 	printf("dnat - to: ");
-	for (i = 0; i < ETH_ALEN; i++)
-		printf("%02x%s",
-		   natinfo->mac[i], (i == ETH_ALEN - 1) ? "" : ":");
+	printf("%s", ether_ntoa((struct ether_addr *)natinfo->mac));
 	printf(" --dnat-target %s", standard_targets[natinfo->target]);
 }
 
--- ebtables-v2.0pre6/ChangeLog	Mon May 20 13:49:27 2002
+++ ebtables-v2.0pre7.001/ChangeLog	Thu Jun  6 19:22:14 2002
@@ -1,3 +1,6 @@
+20020606
+	* more useful message when the kernel can't find an ebtables module
+	* some minor code clean-up (no real impact).
 20020520
 	* update help for -s and -d
 	* add VLAN in ethertypes
--- ebtables-v2.0pre6/include/ebtables_u.h	Fri May  3 21:08:25 2002
+++ ebtables-v2.0pre7.001/include/ebtables_u.h	Wed Jun  5 21:43:27 2002
@@ -185,7 +185,7 @@
 void get_dbinfo(struct brdb_dbinfo *nr);
 void get_db(int len, struct brdb_dbentry *db);
 void deliver_allowdb(__u16 *decision);
-int getmac(char *from, char *to);
+int name_to_protocol(char *name);
 void check_option(unsigned int *flags, unsigned int mask);
 int check_inverse(const char option[]);
 #define print_bug(format, args...) \