Projet

Général

Profil

Télécharger (35,3 ko) Statistiques
| Branche: | Révision:

univnautes-tools / patches / stable / 10 / CP_speedup.diff @ b38dafcf

1
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
2
index 577d644..7d82d34 100644
3
--- a/sbin/ipfw/ipfw2.c
4
+++ b/sbin/ipfw/ipfw2.c
5
@@ -4115,8 +4115,9 @@ ipfw_flush(int force)
6
 }
7
 
8
 
9
+static void table_list_entry(ipfw_table_xentry *);
10
 static void table_list(uint16_t num, int need_header);
11
-static void table_fill_xentry(char *arg, ipfw_table_xentry *xent);
12
+static void table_fill_xentry(int ac, char *av[], ipfw_table_xentry *xent);
13
 
14
 /*
15
  * This one handles all table-related commands
16
@@ -4169,29 +4170,9 @@ ipfw_table_handler(int ac, char *av[])
17
 	if (_substrcmp(*av, "add") == 0 ||
18
 	    _substrcmp(*av, "delete") == 0) {
19
 		do_add = **av == 'a';
20
-		ac--; av++;
21
-		if (!ac)
22
-			errx(EX_USAGE, "address required");
23
 
24
-		table_fill_xentry(*av, &xent);
25
+		table_fill_xentry(ac, av, &xent);
26
 
27
-		ac--; av++;
28
-		if (do_add && ac) {
29
-			unsigned int tval;
30
-			/* isdigit is a bit of a hack here.. */
31
-			if (strchr(*av, (int)'.') == NULL && isdigit(**av))  {
32
-				xent.value = strtoul(*av, NULL, 0);
33
-			} else {
34
-				if (lookup_host(*av, (struct in_addr *)&tval) == 0) {
35
-					/* The value must be stored in host order	 *
36
-					 * so that the values < 65k can be distinguished */
37
-		       			xent.value = ntohl(tval);
38
-				} else {
39
-					errx(EX_NOHOST, "hostname ``%s'' unknown", *av);
40
-				}
41
-			}
42
-		} else
43
-			xent.value = 0;
44
 		if (do_setcmd3(do_add ? IP_FW_TABLE_XADD : IP_FW_TABLE_XDEL,
45
 		    &xent, xent.len) < 0) {
46
 			/* If running silent, don't bomb out on these errors. */
47
@@ -4218,19 +4199,41 @@ ipfw_table_handler(int ac, char *av[])
48
 		do {
49
 			table_list(xent.tbl, is_all);
50
 		} while (++xent.tbl < a);
51
+	} else if (_substrcmp(*av, "entrystats") == 0) {
52
+		table_fill_xentry(ac, av, &xent);
53
+
54
+		if (do_setcmd3(IP_FW_TABLE_XLISTENTRY, &xent, xent.len) < 0) {
55
+			/* If running silent, don't bomb out on these errors. */
56
+			if (!(co.do_quiet))
57
+				err(EX_OSERR, "setsockopt(IP_FW_TABLE_XLISTENTRY)");
58
+		} else
59
+			table_list_entry(&xent);
60
+	} else if (_substrcmp(*av, "entryzerostats") == 0) {
61
+		table_fill_xentry(ac, av, &xent);
62
+
63
+		if (do_setcmd3(IP_FW_TABLE_XZEROENTRY, &xent, xent.len) < 0) {
64
+			/* If running silent, don't bomb out on these errors. */
65
+			if (!(co.do_quiet))
66
+				err(EX_OSERR, "setsockopt(IP_FW_TABLE_XZEROENTRY)");
67
+		}
68
 	} else
69
 		errx(EX_USAGE, "invalid table command %s", *av);
70
 }
71
 
72
 static void
73
-table_fill_xentry(char *arg, ipfw_table_xentry *xent)
74
+table_fill_xentry(int ac, char *av[], ipfw_table_xentry *xent)
75
 {
76
-	int addrlen, mask, masklen, type;
77
+	int addrlen, mask, masklen, type, do_add;
78
 	struct in6_addr *paddr;
79
 	uint32_t *pkey;
80
-	char *p;
81
+	char *p, *arg;
82
 	uint32_t key;
83
 
84
+	do_add = **av == 'a';
85
+	ac--; av++;
86
+	if (!ac)
87
+		errx(EX_USAGE, "address required");
88
+
89
 	mask = 0;
90
 	type = 0;
91
 	addrlen = 0;
92
@@ -4245,7 +4248,23 @@ table_fill_xentry(char *arg, ipfw_table_xentry *xent)
93
 	 * 4) port, uid/gid or other u32 key (base 10 format)
94
 	 * 5) hostname
95
 	 */
96
-	paddr = &xent->k.addr6;
97
+	if (ac > 1 && av) {
98
+		if (_substrcmp(*av, "mac") == 0)  {
99
+			uint8_t _mask[8];
100
+
101
+			type = IPFW_TABLE_MIX;
102
+			get_mac_addr_mask(av[1], (uint8_t *)xent->k.mix.mac, _mask);
103
+			ac-=2; av+=2;
104
+			if (ac <= 0)
105
+				errx(EX_DATAERR, "wrong argument passed.");
106
+
107
+			paddr = (struct in6_addr *)&xent->k.mix.addr;
108
+		} else
109
+			errx(EX_DATAERR, "wrong argument passed.");
110
+	} else
111
+		paddr = &xent->k.addr6;
112
+
113
+	arg = *av;
114
 	if (ishexnumber(*arg) != 0 || *arg == ':') {
115
 		/* Remove / if exists */
116
 		if ((p = strchr(arg, '/')) != NULL) {
117
@@ -4258,7 +4277,8 @@ table_fill_xentry(char *arg, ipfw_table_xentry *xent)
118
 				errx(EX_DATAERR, "bad IPv4 mask width: %s",
119
 				    p + 1);
120
 
121
-			type = IPFW_TABLE_CIDR;
122
+			if (type == 0)
123
+				type = IPFW_TABLE_CIDR;
124
 			masklen = p ? mask : 32;
125
 			addrlen = sizeof(struct in_addr);
126
 		} else if (inet_pton(AF_INET6, arg, paddr) == 1) {
127
@@ -4269,10 +4289,14 @@ table_fill_xentry(char *arg, ipfw_table_xentry *xent)
128
 				errx(EX_DATAERR, "bad IPv6 mask width: %s",
129
 				    p + 1);
130
 
131
-			type = IPFW_TABLE_CIDR;
132
+			if (type == 0)
133
+				type = IPFW_TABLE_CIDR;
134
 			masklen = p ? mask : 128;
135
 			addrlen = sizeof(struct in6_addr);
136
 		} else {
137
+			if (type != 0 && type != IPFW_TABLE_MIX)
138
+				errx(EX_DATAERR, "Wrong value passed as address");
139
+
140
 			/* Port or any other key */
141
 			key = strtol(arg, &p, 10);
142
 			/* Skip non-base 10 entries like 'fa1' */
143
@@ -4304,9 +4328,103 @@ table_fill_xentry(char *arg, ipfw_table_xentry *xent)
144
 		addrlen = sizeof(struct in_addr);
145
 	}
146
 
147
+	ac--; av++;
148
+	if (ac > 1 && av) {
149
+		if (_substrcmp(*av, "mac") == 0)  {
150
+			uint8_t _mask[8];
151
+
152
+			if (type == 0)
153
+				type = IPFW_TABLE_CIDR;
154
+			get_mac_addr_mask(av[1], (uint8_t *)xent->mac_addr, _mask);
155
+			ac-=2; av+=2;
156
+		}
157
+	}
158
+
159
+	if (do_add && ac > 0) {
160
+		unsigned int tval;
161
+		/* isdigit is a bit of a hack here.. */
162
+		if (strchr(*av, (int)'.') == NULL && isdigit(**av))  {
163
+			xent->value = strtoul(*av, NULL, 0);
164
+		} else {
165
+			if (lookup_host(*av, (struct in_addr *)&tval) == 0) {
166
+				/* The value must be stored in host order	 *
167
+				 * so that the values < 65k can be distinguished */
168
+				xent->value = ntohl(tval);
169
+			} else {
170
+				errx(EX_NOHOST, "hostname ``%s'' unknown", *av);
171
+			}
172
+		}
173
+	} else
174
+		xent->value = 0;
175
+
176
 	xent->type = type;
177
 	xent->masklen = masklen;
178
-	xent->len = offsetof(ipfw_table_xentry, k) + addrlen;
179
+	if (type == IPFW_TABLE_MIX)
180
+		xent->len = offsetof(ipfw_table_xentry, k) + addrlen + ETHER_ADDR_LEN;
181
+	else
182
+		xent->len = offsetof(ipfw_table_xentry, k) + addrlen;
183
+}
184
+
185
+static void
186
+table_list_entry(ipfw_table_xentry *xent)
187
+{
188
+	struct in6_addr *addr6;
189
+	uint32_t tval;
190
+	char tbuf[128];
191
+
192
+	switch (xent->type) {
193
+	case IPFW_TABLE_CIDR:
194
+		/* IPv4 or IPv6 prefixes */
195
+		tval = xent->value;
196
+		addr6 = &xent->k.addr6;
197
+
198
+
199
+		if (IN6_IS_ADDR_V4COMPAT(addr6)) {
200
+			/* IPv4 address */
201
+			inet_ntop(AF_INET, &addr6->s6_addr32[3], tbuf, sizeof(tbuf));
202
+		} else {
203
+			/* IPv6 address */
204
+			inet_ntop(AF_INET6, addr6, tbuf, sizeof(tbuf));
205
+		}
206
+
207
+		if (co.do_value_as_ip) {
208
+			tval = htonl(tval);
209
+			printf("%s/%u %s %d %d %u\n", tbuf, xent->masklen,
210
+			    inet_ntoa(*(struct in_addr *)&tval), pr_u64(&xent->packets, 0), pr_u64(&xent->bytes, 0), xent->timestamp);
211
+		} else
212
+			printf("%s/%u %u %d %d %u\n", tbuf, xent->masklen, tval,
213
+			    pr_u64(&xent->packets, 0), pr_u64(&xent->bytes, 0), xent->timestamp);
214
+		break;
215
+	case IPFW_TABLE_INTERFACE:
216
+		/* Interface names */
217
+		tval = xent->value;
218
+		if (co.do_value_as_ip) {
219
+			tval = htonl(tval);
220
+			printf("%s %u %s %d %d %u\n", xent->k.iface, xent->masklen,
221
+			    inet_ntoa(*(struct in_addr *)&tval), pr_u64(&xent->packets, 0), pr_u64(&xent->bytes, 0), xent->timestamp);
222
+		} else
223
+			printf("%s %u %u %d %d %u\n", xent->k.iface, xent->masklen, tval,
224
+			    pr_u64(&xent->packets, 0), pr_u64(&xent->bytes, 0), xent->timestamp);
225
+
226
+		break;
227
+
228
+	case IPFW_TABLE_MIX:
229
+		/* mix of ip+mac */
230
+		tval = xent->value;
231
+
232
+		/* IPv4 address */
233
+		inet_ntop(AF_INET, &xent->k.mix.addr, tbuf, sizeof(tbuf));
234
+
235
+		if (co.do_value_as_ip) {
236
+			tval = htonl(tval);
237
+			printf("%s/%u %s %s %d %d %u\n", tbuf, xent->masklen - (8 * ETHER_ADDR_LEN), ether_ntoa((struct ether_addr *)xent->k.mix.mac),
238
+			    inet_ntoa(*(struct in_addr *)&tval),
239
+			    pr_u64(&xent->packets, 0), pr_u64(&xent->bytes, 0), xent->timestamp);
240
+		} else
241
+			printf("%s/%u %s %u %d %d %u\n", tbuf, xent->masklen - (8 * ETHER_ADDR_LEN), ether_ntoa((struct ether_addr *)xent->k.mix.mac), tval,
242
+			    pr_u64(&xent->packets, 0), pr_u64(&xent->bytes, 0), xent->timestamp);
243
+		break;
244
+	}
245
 }
246
 
247
 static void
248
@@ -4338,6 +4456,7 @@ table_list(uint16_t num, int need_header)
249
 	l = *a;
250
 	tbl = safe_calloc(1, l);
251
 	tbl->opheader.opcode = IP_FW_TABLE_XLIST;
252
+	tbl->opheader.ctxid = co.ctx;
253
 	tbl->tbl = num;
254
 	if (do_cmd(IP_FW3, tbl, (uintptr_t)&l) < 0)
255
 		err(EX_OSERR, "getsockopt(IP_FW_TABLE_XLIST)");
256
@@ -4377,6 +4496,23 @@ table_list(uint16_t num, int need_header)
257
 				    inet_ntoa(*(struct in_addr *)&tval));
258
 			} else
259
 				printf("%s %u\n", xent->k.iface, tval);
260
+
261
+			break;
262
+
263
+		case IPFW_TABLE_MIX:
264
+			/* mix of ip+mac */
265
+			tval = xent->value;
266
+
267
+			/* IPv4 address */
268
+			inet_ntop(AF_INET, &xent->k.mix.addr, tbuf, sizeof(tbuf));
269
+
270
+			if (co.do_value_as_ip) {
271
+				tval = htonl(tval);
272
+				printf("%s/%u %s %s\n", tbuf, xent->masklen - (8 * ETHER_ADDR_LEN), ether_ntoa((struct ether_addr *)xent->k.mix.mac),
273
+				    inet_ntoa(*(struct in_addr *)&tval));
274
+			} else
275
+				printf("%s/%u %s %u\n", tbuf, xent->masklen - (8 * ETHER_ADDR_LEN), ether_ntoa((struct ether_addr *)xent->k.mix.mac), tval);
276
+			break;
277
 		}
278
 
279
 		if (sz < xent->len)
280
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
281
index 1a6ac08..b0df96b 100644
282
--- a/sys/net/if_ethersubr.c
283
+++ b/sys/net/if_ethersubr.c
284
@@ -742,7 +742,10 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
285
 
286
 		if (i != 0 || m == NULL)
287
 			return;
288
-	}
289
+
290
+		i = m->m_flags & M_FASTFWD_OURS;
291
+	} else
292
+		i = 0;
293
 
294
 	eh = mtod(m, struct ether_header *);
295
 	ether_type = ntohs(eh->ether_type);
296
@@ -781,6 +784,8 @@ ether_demux(struct ifnet *ifp, struct mbuf *m)
297
 	 */
298
 	m->m_flags &= ~M_VLANTAG;
299
 	m_clrprotoflags(m);
300
+	if (i)
301
+		m->m_flags |= M_FASTFWD_OURS;
302
 	m_adj(m, ETHER_HDR_LEN);
303
 
304
 	/*
305
diff --git a/sys/netinet/ip_fw.h b/sys/netinet/ip_fw.h
306
index 14b08f5..2eedd0b 100644
307
--- a/sys/netinet/ip_fw.h
308
+++ b/sys/netinet/ip_fw.h
309
@@ -74,6 +74,8 @@ typedef struct _ip_fw3_opheader {
310
 #define	IP_FW_TABLE_XDEL	87	/* delete entry */
311
 #define	IP_FW_TABLE_XGETSIZE	88	/* get table size */
312
 #define	IP_FW_TABLE_XLIST	89	/* list table contents */
313
+#define	IP_FW_TABLE_XLISTENTRY	90	/* list one table entry contents */
314
+#define	IP_FW_TABLE_XZEROENTRY	91	/* zero one table entry stats */
315
 
316
 /*
317
  * The kernel representation of ipfw rules is made of a list of
318
@@ -600,13 +602,16 @@ struct _ipfw_dyn_rule {
319
 
320
 #define	IPFW_TABLE_CIDR		1	/* Table for holding IPv4/IPv6 prefixes */
321
 #define	IPFW_TABLE_INTERFACE	2	/* Table for holding interface names */
322
-#define	IPFW_TABLE_MAXTYPE	2	/* Maximum valid number */
323
+#define	IPFW_TABLE_MIX		3	/* Table for holding IPv4/mac entries */
324
+#define	IPFW_TABLE_MAC		4	/* Table for holding mac entries */
325
+#define	IPFW_TABLE_MAXTYPE	5	/* Maximum valid number */
326
 
327
 typedef struct	_ipfw_table_entry {
328
 	in_addr_t	addr;		/* network address		*/
329
 	u_int32_t	value;		/* value			*/
330
 	u_int16_t	tbl;		/* table number			*/
331
 	u_int8_t	masklen;	/* mask length			*/
332
+	uint64_t		mac_addr;
333
 } ipfw_table_entry;
334
 
335
 typedef struct	_ipfw_table_xentry {
336
@@ -617,9 +622,26 @@ typedef struct	_ipfw_table_xentry {
337
 	uint32_t	value;		/* value			*/
338
 	union {
339
 		/* Longest field needs to be aligned by 4-byte boundary	*/
340
+#ifndef ETHER_ADDR_LEN
341
+#define ETHER_ADDR_LEN 6
342
+#endif
343
+#if 0
344
+		struct {
345
+			struct ether_addr addr;
346
+			struct ether_addr mask;
347
+		} mac;
348
+#endif
349
+		struct {
350
+			struct in_addr addr;
351
+			u_char mac[ETHER_ADDR_LEN];
352
+		} mix;
353
 		struct in6_addr	addr6;	/* IPv6 address 		*/
354
 		char	iface[IF_NAMESIZE];	/* interface name	*/
355
 	} k;
356
+	uint64_t		mac_addr;
357
+	uint64_t               bytes;
358
+	uint64_t               packets;
359
+	uint32_t               timestamp;
360
 } ipfw_table_xentry;
361
 
362
 typedef struct	_ipfw_table {
363
diff --git a/sys/netpfil/ipfw/ip_fw2.c b/sys/netpfil/ipfw/ip_fw2.c
364
index cd466bd..f2f117e 100644
365
--- a/sys/netpfil/ipfw/ip_fw2.c
366
+++ b/sys/netpfil/ipfw/ip_fw2.c
367
@@ -358,8 +358,8 @@ iface_match(struct ifnet *ifp, ipfw_insn_if *cmd, struct ip_fw_chain *chain, uin
368
 	/* Check by name or by IP address */
369
 	if (cmd->name[0] != '\0') { /* match by name */
370
 		if (cmd->name[0] == '\1') /* use tablearg to match */
371
-			return ipfw_lookup_table_extended(chain, cmd->p.glob,
372
-				ifp->if_xname, tablearg, IPFW_TABLE_INTERFACE);
373
+			return (ipfw_lookup_table_extended(chain, cmd->p.glob,
374
+				ifp->if_xname, tablearg, IPFW_TABLE_INTERFACE, NULL) != NULL);
375
 		/* Check name */
376
 		if (cmd->p.glob) {
377
 			if (fnmatch(cmd->name, ifp->if_xname, 0) == 0)
378
@@ -955,6 +955,7 @@ ipfw_chk(struct ip_fw_args *args)
379
 	int dyn_dir = MATCH_UNKNOWN;
380
 	ipfw_dyn_rule *q = NULL;
381
 	struct ip_fw_chain *chain = &V_layer3_chain;
382
+	void *tblent = NULL;
383
 
384
 	/*
385
 	 * We store in ulp a pointer to the upper layer protocol header.
386
@@ -1288,6 +1289,7 @@ do {								\
387
 			continue;
388
 
389
 		skip_or = 0;
390
+		tblent = NULL;
391
 		for (l = f->cmd_len, cmd = f->cmd ; l > 0 ;
392
 		    l -= cmdlen, cmd += cmdlen) {
393
 			int match;
394
@@ -1402,7 +1404,7 @@ do {								\
395
 				break;
396
 
397
 			case O_IN:	/* "out" is "not in" */
398
-				match = (oif == NULL);
399
+				match = (args->dir == DIR_IN);
400
 				break;
401
 
402
 			case O_LAYER2:
403
@@ -1438,11 +1440,18 @@ do {								\
404
 			case O_IP_SRC_LOOKUP:
405
 			case O_IP_DST_LOOKUP:
406
 				if (is_ipv4) {
407
+					struct ether_addr *ea = NULL;
408
+
409
 				    uint32_t key =
410
 					(cmd->opcode == O_IP_DST_LOOKUP) ?
411
 					    dst_ip.s_addr : src_ip.s_addr;
412
 				    uint32_t v = 0;
413
 
414
+					if (args->eh) {
415
+						ea = (struct ether_addr*)((cmd->opcode == O_IP_DST_LOOKUP) ?
416
+							args->eh->ether_dhost :
417
+							args->eh->ether_shost);
418
+					}
419
 				    if (cmdlen > F_INSN_SIZE(ipfw_insn_u32)) {
420
 					/* generic lookup. The key must be
421
 					 * in 32bit big-endian format.
422
@@ -1484,22 +1493,37 @@ do {								\
423
 					} else
424
 					    break;
425
 				    }
426
-				    match = ipfw_lookup_table(chain,
427
-					cmd->arg1, key, &v);
428
-				    if (!match)
429
+				    tblent = ipfw_lookup_table_extended(chain,
430
+					cmd->arg1, &key, &v, IPFW_TABLE_CIDR, ea);
431
+				    if (tblent == NULL) {
432
+					match = 0;
433
 					break;
434
+				    } else
435
+					match = 1;
436
 				    if (cmdlen == F_INSN_SIZE(ipfw_insn_u32))
437
 					match =
438
 					    ((ipfw_insn_u32 *)cmd)->d[0] == v;
439
-				    else
440
+				    if (match)
441
 					tablearg = v;
442
 				} else if (is_ipv6) {
443
+					struct ether_addr *ea = NULL;
444
 					uint32_t v = 0;
445
+
446
+					if (args->eh) {
447
+						ea = (struct ether_addr*)((cmd->opcode == O_IP_DST_LOOKUP) ?
448
+							args->eh->ether_dhost :
449
+							args->eh->ether_shost);
450
+					}
451
 					void *pkey = (cmd->opcode == O_IP_DST_LOOKUP) ?
452
 						&args->f_id.dst_ip6: &args->f_id.src_ip6;
453
-					match = ipfw_lookup_table_extended(chain,
454
+					tblent = ipfw_lookup_table_extended(chain,
455
 							cmd->arg1, pkey, &v,
456
-							IPFW_TABLE_CIDR);
457
+							IPFW_TABLE_CIDR, ea);
458
+				    if (tblent == NULL) {
459
+					match = 0;
460
+					break;
461
+				    } else
462
+					match = 1;
463
 					if (cmdlen == F_INSN_SIZE(ipfw_insn_u32))
464
 						match = ((ipfw_insn_u32 *)cmd)->d[0] == v;
465
 					if (match)
466
@@ -2314,8 +2338,7 @@ do {								\
467
 				break;
468
 
469
 			case O_FORWARD_IP:
470
-				if (args->eh)	/* not valid on layer2 pkts */
471
-					break;
472
+				if (!args->eh)	{/* not valid on layer2 pkts */
473
 				if (q == NULL || q->rule != f ||
474
 				    dyn_dir == MATCH_FORWARD) {
475
 				    struct sockaddr_in *sa;
476
@@ -2330,6 +2353,48 @@ do {								\
477
 					args->next_hop = sa;
478
 				    }
479
 				}
480
+				} else if (args->eh) {
481
+					struct m_tag *fwd_tag;
482
+					struct sockaddr_in *sa;
483
+					u_short sum;
484
+
485
+					/*
486
+					* Checksum correct? (from ip_fastfwd.c)
487
+					*/
488
+					if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
489
+						sum = !(m->m_pkthdr.csum_flags & CSUM_IP_VALID);
490
+					else {
491
+						if (hlen == sizeof(struct ip))
492
+							sum = in_cksum_hdr(ip);
493
+						else
494
+							sum = in_cksum(m, hlen);
495
+					}
496
+					if (sum) {
497
+						IPSTAT_INC(ips_badsum);
498
+						retval = IP_FW_DENY;
499
+						break;
500
+					}
501
+
502
+					/*
503
+					* Remember that we have checked the IP header and found it valid.
504
+					*/
505
+					m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID);
506
+
507
+					sa = &(((ipfw_insn_sa *)cmd)->sa);
508
+					fwd_tag = m_tag_get(PACKET_TAG_IPFORWARD,
509
+						sizeof(struct sockaddr_in), M_NOWAIT);
510
+					if (fwd_tag == NULL)
511
+						retval = IP_FW_DENY;
512
+					else {
513
+						bcopy(sa, (fwd_tag+1), sizeof(struct sockaddr_in));
514
+						m_tag_prepend(m, fwd_tag);
515
+
516
+						if (in_localip(sa->sin_addr))
517
+							m->m_flags |= M_FASTFWD_OURS;
518
+						m->m_flags |= M_IP_NEXTHOP;
519
+					}
520
+				}
521
+
522
 				retval = IP_FW_PASS;
523
 				l = 0;          /* exit inner loop */
524
 				done = 1;       /* exit outer loop */
525
@@ -2337,8 +2402,7 @@ do {								\
526
 
527
 #ifdef INET6
528
 			case O_FORWARD_IP6:
529
-				if (args->eh)	/* not valid on layer2 pkts */
530
-					break;
531
+				if (!args->eh) {/* not valid on layer2 pkts */
532
 				if (q == NULL || q->rule != f ||
533
 				    dyn_dir == MATCH_FORWARD) {
534
 					struct sockaddr_in6 *sin6;
535
@@ -2346,6 +2410,24 @@ do {								\
536
 					sin6 = &(((ipfw_insn_sa6 *)cmd)->sa);
537
 					args->next_hop6 = sin6;
538
 				}
539
+				} else if (args->eh) {
540
+					struct m_tag *fwd_tag;
541
+					struct sockaddr_in6 *sin6;
542
+
543
+					sin6 = &(((ipfw_insn_sa6 *)cmd)->sa);
544
+					fwd_tag = m_tag_get(PACKET_TAG_IPFORWARD,
545
+						sizeof(struct sockaddr_in6), M_NOWAIT);
546
+					if (fwd_tag == NULL)
547
+						retval = IP_FW_DENY;
548
+					else {
549
+						bcopy(sin6, (fwd_tag+1), sizeof(struct sockaddr_in6));
550
+						m_tag_prepend(m, fwd_tag);
551
+
552
+						if (in6_localip(&sin6->sin6_addr))
553
+							m->m_flags |= M_FASTFWD_OURS;
554
+						m->m_flags |= M_IP6_NEXTHOP;
555
+					}
556
+				}
557
 				retval = IP_FW_PASS;
558
 				l = 0;		/* exit inner loop */
559
 				done = 1;	/* exit outer loop */
560
@@ -2505,6 +2587,8 @@ do {								\
561
 		struct ip_fw *rule = chain->map[f_pos];
562
 		/* Update statistics */
563
 		IPFW_INC_RULE_COUNTER(rule, pktlen);
564
+		if (tblent != NULL)
565
+			ipfw_count_table_xentry_stats(tblent, pktlen);
566
 	} else {
567
 		retval = IP_FW_DENY;
568
 		printf("ipfw: ouch!, skip past end of rules, denying packet\n");
569
diff --git a/sys/netpfil/ipfw/ip_fw_pfil.c b/sys/netpfil/ipfw/ip_fw_pfil.c
570
index d1202ff..bf225b8 100644
571
--- a/sys/netpfil/ipfw/ip_fw_pfil.c
572
+++ b/sys/netpfil/ipfw/ip_fw_pfil.c
573
@@ -143,8 +143,9 @@ again:
574
 	}
575
 
576
 	args.m = *m0;
577
-	args.oif = dir == DIR_OUT ? ifp : NULL;
578
+	args.oif = ifp;
579
 	args.inp = inp;
580
+	args.dir = dir;
581
 
582
 	ipfw = ipfw_chk(&args);
583
 	*m0 = args.m;
584
@@ -314,9 +315,8 @@ ipfw_check_frame(void *arg, struct mbuf **m0, struct ifnet *dst, int dir,
585
 		/* XXX can we free it after use ? */
586
 		mtag->m_tag_id = PACKET_TAG_NONE;
587
 		r = (struct ipfw_rule_ref *)(mtag + 1);
588
-		if (r->info & IPFW_ONEPASS)
589
-			return (0);
590
-		args.rule = *r;
591
+		m_tag_delete(*m0, mtag);
592
+		return (0);
593
 	}
594
 
595
 	/* I need some amt of data to be contiguous */
596
@@ -333,12 +333,15 @@ ipfw_check_frame(void *arg, struct mbuf **m0, struct ifnet *dst, int dir,
597
 	save_eh = *eh;			/* save copy for restore below */
598
 	m_adj(m, ETHER_HDR_LEN);	/* strip ethernet header */
599
 
600
+	dir = dir == PFIL_IN ? DIR_IN : DIR_OUT;
601
+
602
 	args.m = m;		/* the packet we are looking at		*/
603
-	args.oif = dir == PFIL_OUT ? dst: NULL;	/* destination, if any	*/
604
+	args.oif = dst;		/* destination, if any	*/
605
 	args.next_hop = NULL;	/* we do not support forward yet	*/
606
 	args.next_hop6 = NULL;	/* we do not support forward yet	*/
607
 	args.eh = &save_eh;	/* MAC header for bridged/MAC packets	*/
608
 	args.inp = NULL;	/* used by ipfw uid/gid/jail rules	*/
609
+	args.dir = dir;         /* pfSense addition                     */
610
 	i = ipfw_chk(&args);
611
 	m = args.m;
612
 	if (m != NULL) {
613
@@ -369,13 +372,12 @@ ipfw_check_frame(void *arg, struct mbuf **m0, struct ifnet *dst, int dir,
614
 
615
 	case IP_FW_DUMMYNET:
616
 		ret = EACCES;
617
-		int dir;
618
 
619
 		if (ip_dn_io_ptr == NULL)
620
 			break; /* i.e. drop */
621
 
622
 		*m0 = NULL;
623
-		dir = PROTO_LAYER2 | (dst ? DIR_OUT : DIR_IN);
624
+		dir = PROTO_LAYER2 | dir;
625
 		ip_dn_io_ptr(&m, dir, &args);
626
 		return 0;
627
 
628
diff --git a/sys/netpfil/ipfw/ip_fw_private.h b/sys/netpfil/ipfw/ip_fw_private.h
629
index a8d7eea..4830124 100644
630
--- a/sys/netpfil/ipfw/ip_fw_private.h
631
+++ b/sys/netpfil/ipfw/ip_fw_private.h
632
@@ -101,6 +101,7 @@ struct ip_fw_args {
633
 
634
 	struct ipfw_flow_id f_id;	/* grabbed from IP header	*/
635
 	//uint32_t	cookie;		/* a cookie depending on rule action */
636
+	uint32_t        dir;            /* direction */
637
 	struct inpcb	*inp;
638
 
639
 	struct _ip6dn_args	dummypar; /* dummynet->ip6_output */
640
@@ -304,13 +305,17 @@ void ipfw_reap_rules(struct ip_fw *head);
641
 struct radix_node;
642
 int ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
643
     uint32_t *val);
644
-int ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
645
-    uint32_t *val, int type);
646
+struct ether_addr;
647
+void *ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
648
+    uint32_t *val, int type, struct ether_addr *);
649
+void ipfw_count_table_xentry_stats(void *, int);
650
+int ipfw_zero_table_xentry_stats(struct ip_fw_chain *, ipfw_table_xentry *);
651
+int ipfw_lookup_table_xentry(struct ip_fw_chain *, ipfw_table_xentry *);
652
 int ipfw_init_tables(struct ip_fw_chain *ch);
653
 void ipfw_destroy_tables(struct ip_fw_chain *ch);
654
 int ipfw_flush_table(struct ip_fw_chain *ch, uint16_t tbl);
655
 int ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
656
-    uint8_t plen, uint8_t mlen, uint8_t type, uint32_t value);
657
+    uint8_t plen, uint8_t mlen, uint8_t type, u_int64_t mac_addr, uint32_t value);
658
 int ipfw_del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
659
     uint8_t plen, uint8_t mlen, uint8_t type);
660
 int ipfw_count_table(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt);
661
diff --git a/sys/netpfil/ipfw/ip_fw_sockopt.c b/sys/netpfil/ipfw/ip_fw_sockopt.c
662
index cb9c89c..d98cac6 100644
663
--- a/sys/netpfil/ipfw/ip_fw_sockopt.c
664
+++ b/sys/netpfil/ipfw/ip_fw_sockopt.c
665
@@ -1124,7 +1124,7 @@ ipfw_ctl(struct sockopt *sopt)
666
 				break;
667
 			error = ipfw_add_table_entry(chain, ent.tbl,
668
 			    &ent.addr, sizeof(ent.addr), ent.masklen, 
669
-			    IPFW_TABLE_CIDR, ent.value);
670
+			    IPFW_TABLE_CIDR, ent.mac_addr, ent.value);
671
 		}
672
 		break;
673
 
674
@@ -1162,7 +1162,7 @@ ipfw_ctl(struct sockopt *sopt)
675
 
676
 			error = (opt == IP_FW_TABLE_XADD) ?
677
 				ipfw_add_table_entry(chain, xent->tbl, &xent->k, 
678
-					len, xent->masklen, xent->type, xent->value) :
679
+					len, xent->masklen, xent->type, xent->mac_addr, xent->value) :
680
 				ipfw_del_table_entry(chain, xent->tbl, &xent->k,
681
 					len, xent->masklen, xent->type);
682
 		}
683
@@ -1245,6 +1245,47 @@ ipfw_ctl(struct sockopt *sopt)
684
 		}
685
 		break;
686
 
687
+	case IP_FW_TABLE_XZEROENTRY: /* IP_FW3 */
688
+		{
689
+			ipfw_table_xentry *xent = (ipfw_table_xentry *)(op3 + 1);
690
+
691
+			/* Check minimum header size */
692
+			if (IP_FW3_OPLENGTH(sopt) < offsetof(ipfw_table_xentry, k)) {
693
+				error = EINVAL;
694
+				break;
695
+			}
696
+
697
+			/* Check if len field is valid */
698
+			if (xent->len > sizeof(ipfw_table_xentry)) {
699
+				error = EINVAL;
700
+				break;
701
+			}
702
+			
703
+			error = ipfw_zero_table_xentry_stats(chain, xent);
704
+		}
705
+		break;
706
+
707
+	case IP_FW_TABLE_XLISTENTRY: /* IP_FW3 */
708
+		{
709
+			ipfw_table_xentry *xent = (ipfw_table_xentry *)(op3 + 1);
710
+
711
+			/* Check minimum header size */
712
+			if (IP_FW3_OPLENGTH(sopt) < offsetof(ipfw_table_xentry, k)) {
713
+				error = EINVAL;
714
+				break;
715
+			}
716
+
717
+			/* Check if len field is valid */
718
+			if (xent->len > sizeof(ipfw_table_xentry)) {
719
+				error = EINVAL;
720
+				break;
721
+			}
722
+			
723
+			error = ipfw_lookup_table_xentry(chain, xent);
724
+			xent->timestamp += boottime.tv_sec;
725
+		}
726
+		break;
727
+
728
 	case IP_FW_TABLE_XLIST: /* IP_FW3 */
729
 		{
730
 			ipfw_xtable *tbl;
731
diff --git a/sys/netpfil/ipfw/ip_fw_table.c b/sys/netpfil/ipfw/ip_fw_table.c
732
index 95cff5c..e916749 100644
733
--- a/sys/netpfil/ipfw/ip_fw_table.c
734
+++ b/sys/netpfil/ipfw/ip_fw_table.c
735
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
736
 #include <net/route.h>
737
 #include <net/vnet.h>
738
 
739
+#include <net/ethernet.h>
740
 #include <netinet/in.h>
741
 #include <netinet/ip_var.h>	/* struct ipfw_rule_ref */
742
 #include <netinet/ip_fw.h>
743
@@ -74,7 +75,11 @@ static MALLOC_DEFINE(M_IPFW_TBL, "ipfw_tbl", "IpFw tables");
744
 struct table_entry {
745
 	struct radix_node	rn[2];
746
 	struct sockaddr_in	addr, mask;
747
+	u_int64_t               mac_addr;
748
 	u_int32_t		value;
749
+	u_int32_t               timestamp;
750
+	u_int64_t               bytes;
751
+	u_int64_t               packets;
752
 };
753
 
754
 struct xaddr_iface {
755
@@ -83,6 +88,22 @@ struct xaddr_iface {
756
 	char 		ifname[IF_NAMESIZE];	/* Interface name */
757
 };
758
 
759
+#if 0
760
+struct xaddr_mac {
761
+	uint8_t		mac_len;		/* length of this struct */
762
+	uint8_t		pad[7];		/* Align name */
763
+	struct ether_addr mac;
764
+};
765
+#endif
766
+
767
+struct xaddr_mix {
768
+	uint8_t		mix_len;		/* length of this struct */
769
+	sa_family_t     sin_family;
770
+        uint8_t		pad[6];
771
+        struct  in_addr sin_addr;
772
+	u_char	mac[ETHER_ADDR_LEN];
773
+};
774
+
775
 struct table_xentry {
776
 	struct radix_node	rn[2];
777
 	union {
778
@@ -90,14 +111,26 @@ struct table_xentry {
779
 		struct sockaddr_in6	addr6;
780
 #endif
781
 		struct xaddr_iface	iface;
782
+#if 0
783
+		struct xaddr_mac	mac;
784
+#endif
785
+		struct xaddr_mix	mix;
786
 	} a;
787
 	union {
788
 #ifdef INET6
789
 		struct sockaddr_in6	mask6;
790
 #endif
791
 		struct xaddr_iface	ifmask;
792
+#if 0
793
+		struct xaddr_mac	macmask;
794
+#endif
795
+		struct xaddr_mix	mixmask;
796
 	} m;
797
+	u_int64_t               mac_addr;
798
 	u_int32_t		value;
799
+	u_int32_t               timestamp;
800
+	u_int64_t               bytes;
801
+	u_int64_t               packets;
802
 };
803
 
804
 /*
805
@@ -117,10 +150,17 @@ struct table_xentry {
806
 #define KEY_LEN_INET	(offsetof(struct sockaddr_in, sin_addr) + sizeof(in_addr_t))
807
 #define KEY_LEN_INET6	(offsetof(struct sockaddr_in6, sin6_addr) + sizeof(struct in6_addr))
808
 #define KEY_LEN_IFACE	(offsetof(struct xaddr_iface, ifname))
809
+#define KEY_LEN_MIX	(offsetof(struct xaddr_mix, sin_addr) + sizeof(in_addr_t) + ETHER_ADDR_LEN)
810
+#if 0
811
+#define KEY_LEN_MAC	(offsetof(struct xaddr_mac, mac) + ETHER_ADDR_LEN)
812
+#endif
813
 
814
 #define OFF_LEN_INET	(8 * offsetof(struct sockaddr_in, sin_addr))
815
 #define OFF_LEN_INET6	(8 * offsetof(struct sockaddr_in6, sin6_addr))
816
 #define OFF_LEN_IFACE	(8 * offsetof(struct xaddr_iface, ifname))
817
+#if 0
818
+#define OFF_LEN_MAC	(8 * offsetof(struct xaddr_mac, mac))
819
+#endif
820
 
821
 
822
 #ifdef INET6
823
@@ -137,7 +177,7 @@ ipv6_writemask(struct in6_addr *addr6, uint8_t mask)
824
 
825
 int
826
 ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
827
-    uint8_t plen, uint8_t mlen, uint8_t type, uint32_t value)
828
+    uint8_t plen, uint8_t mlen, uint8_t type, u_int64_t mac_addr, uint32_t value)
829
 {
830
 	struct radix_node_head *rnh, **rnh_ptr;
831
 	struct table_entry *ent;
832
@@ -161,6 +201,7 @@ ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
833
 				return (EINVAL);
834
 			ent = malloc(sizeof(*ent), M_IPFW_TBL, M_WAITOK | M_ZERO);
835
 			ent->value = value;
836
+			ent->mac_addr = mac_addr;
837
 			/* Set 'total' structure length */
838
 			KEY_LEN(ent->addr) = KEY_LEN_INET;
839
 			KEY_LEN(ent->mask) = KEY_LEN_INET;
840
@@ -182,6 +223,7 @@ ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
841
 				return (EINVAL);
842
 			xent = malloc(sizeof(*xent), M_IPFW_TBL, M_WAITOK | M_ZERO);
843
 			xent->value = value;
844
+			xent->mac_addr = mac_addr;
845
 			/* Set 'total' structure length */
846
 			KEY_LEN(xent->a.addr6) = KEY_LEN_INET6;
847
 			KEY_LEN(xent->m.mask6) = KEY_LEN_INET6;
848
@@ -233,6 +275,52 @@ ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
849
 		mask_ptr = NULL;
850
 		break;
851
 
852
+#if 0
853
+	case IPFW_TABLE_MAC:
854
+		int i;
855
+
856
+		xent = malloc(sizeof(*xent), M_IPFW_TBL, M_WAITOK | M_ZERO);
857
+		xent->value = value;
858
+		/* Set 'total' structure length */
859
+		KEY_LEN(xent->a.mac) = KEY_LEN_MAC;
860
+		KEY_LEN(xent->m.macmask) = KEY_LEN_MAC;
861
+		/* Set offset of address in bits */
862
+		offset = OFF_LEN_MAC;
863
+		xent->a.mac = (struct ether_addr)(*paddr);
864
+		xent->m.mac = (struct ether_addr)(*(((struct ether_addr *)paddr) + 1));
865
+		for (i = 0; i < ETHER_ADDR_LEN; i++)
866
+			xent->a.mac.octet[i] &= xent->m.mac.octet[i];
867
+		/* Set pointers */
868
+		rnh_ptr = &ch->xtables[tbl];
869
+		ent_ptr = xent;
870
+		addr_ptr = (struct sockaddr *)&xent->a.mac;
871
+		mask_ptr = (struct sockaddr *)&xent->m.macmask;
872
+		break;
873
+#endif
874
+
875
+	case IPFW_TABLE_MIX:
876
+		if ((plen - ETHER_ADDR_LEN) != sizeof(in_addr_t))
877
+			return (EINVAL);
878
+
879
+		xent = malloc(sizeof(*xent), M_IPFW_TBL, M_WAITOK | M_ZERO);
880
+		xent->value = value;
881
+		/* Set 'total' structure length */
882
+		KEY_LEN(xent->a.mix) = KEY_LEN_MIX;
883
+		KEY_LEN(xent->m.mixmask) = KEY_LEN_MIX;
884
+		/* Set offset of IPv4 address in bits */
885
+		offset = OFF_LEN_INET;
886
+		/* XXX: Needs to be fixed */
887
+		memcpy(&xent->a.mix.sin_addr, paddr, ETHER_ADDR_LEN + sizeof(struct in_addr));
888
+		/* Only full ips /32 and full masks supported for mac */
889
+		memset(&xent->m.mixmask.sin_addr, 0xFF, sizeof(struct in_addr));
890
+		memset(xent->m.mixmask.mac, 0xFF, ETHER_ADDR_LEN);
891
+		/* Set pointers */
892
+		rnh_ptr = &ch->xtables[tbl];
893
+		ent_ptr = xent;
894
+		addr_ptr = (struct sockaddr *)&xent->a.mix;
895
+		mask_ptr = NULL;
896
+		break;
897
+
898
 	default:
899
 		return (EINVAL);
900
 	}
901
@@ -281,6 +369,19 @@ ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
902
 	IPFW_WUNLOCK(ch);
903
 
904
 	if (rn == NULL) {
905
+		if (type == IPFW_TABLE_CIDR) {
906
+			/* Just update if any new value needed */
907
+			struct table_entry *ent2;
908
+
909
+			ent2 = (struct table_entry *)(rnh->rnh_lookup(&ent->addr, NULL, rnh));
910
+			if (ent2 != NULL) {
911
+				if (ent2->mac_addr) {
912
+					if (!bcmp(&mac_addr, &ent2->mac_addr, ETHER_ADDR_LEN))
913
+						ent2->value = value;
914
+				} else
915
+					ent2->value = value;
916
+			}
917
+		}
918
 		free(ent_ptr, M_IPFW_TBL);
919
 		return (EEXIST);
920
 	}
921
@@ -367,6 +468,41 @@ ipfw_del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
922
 
923
 		break;
924
 
925
+#if 0
926
+	case IPFW_TABLE_MAC:
927
+		struct xaddr_mac mac, macmask;
928
+		memset(&mac, 0, sizeof(mac));
929
+		memset(&macmask, 0, sizeof(macmask));
930
+
931
+		/* Set 'total' structure length */
932
+                KEY_LEN(mac) = KEY_LEN_MAC;
933
+		mac.mac.mac = (struct ether_addr)(*paddr);
934
+                KEY_LEN(macmask) = KEY_LEN_MAC;
935
+		macmask.mac.macmask = (struct ether_addr)(*(((struct ether_addr *)paddr) + 1));
936
+		for (i = 0; i < ETHER_ADDR_LEN; i++)
937
+			mac.mac.octet[i] &= macmask.mac.octet[i];
938
+		rnh_ptr = &ch->xtables[tbl];
939
+		sa_ptr = (struct sockaddr *)&mac;
940
+		mask_ptr = (struct sockaddr *)&macmask;
941
+
942
+		break;
943
+#endif
944
+
945
+	case IPFW_TABLE_MIX:
946
+		if (mlen > (32 + ETHER_ADDR_LEN))
947
+			return (EINVAL);
948
+		struct xaddr_mix mix;
949
+		memset(&mix, 0, sizeof(mix));
950
+
951
+		/* Set 'total' structure length */
952
+		KEY_LEN(mix) = KEY_LEN_MIX;
953
+		memcpy(&mix.sin_addr, paddr, sizeof(struct in_addr) + ETHER_ADDR_LEN);
954
+		rnh_ptr = &ch->xtables[tbl];
955
+		sa_ptr = (struct sockaddr *)&mix;
956
+		mask_ptr = NULL;
957
+
958
+		break;
959
+
960
 	default:
961
 		return (EINVAL);
962
 	}
963
@@ -552,9 +688,152 @@ ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
964
 	return (0);
965
 }
966
 
967
+void
968
+ipfw_count_table_xentry_stats(void *arg, int pktlen)
969
+{
970
+	ipfw_table_xentry *xent= arg;
971
+
972
+	xent->packets++;
973
+	xent->bytes += pktlen;
974
+	xent->timestamp = time_uptime;
975
+}
976
+
977
 int
978
+ipfw_zero_table_xentry_stats(struct ip_fw_chain *ch, ipfw_table_xentry *arg)
979
+{
980
+	struct radix_node_head *rnh;
981
+	struct table_xentry *xent;
982
+	struct sockaddr_in6 sa6;
983
+	struct xaddr_iface iface;
984
+	struct xaddr_mix xm;
985
+
986
+	if (arg->tbl >= V_fw_tables_max)
987
+		return (0);
988
+	if ((rnh = ch->xtables[arg->tbl]) == NULL)
989
+		return (0);
990
+
991
+	switch (arg->type) {
992
+	case IPFW_TABLE_CIDR:
993
+		KEY_LEN(sa6) = KEY_LEN_INET6;
994
+		memcpy(&sa6.sin6_addr, &arg->k.addr6, sizeof(struct in6_addr));
995
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&sa6, NULL, rnh));
996
+		break;
997
+
998
+	case IPFW_TABLE_INTERFACE:
999
+		KEY_LEN(iface) = KEY_LEN_IFACE +
1000
+		    strlcpy(iface.ifname, arg->k.iface, IF_NAMESIZE) + 1;
1001
+		/* Assume direct match */
1002
+		/* FIXME: Add interface pattern matching */
1003
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&iface, NULL, rnh));
1004
+		break;
1005
+
1006
+#if 0
1007
+	case IPFW_TABLE_MAC:
1008
+	{
1009
+		struct xaddr_mac mac;
1010
+
1011
+		KEY_LEN(mac) = KEY_LEN_MAC;
1012
+		&mac.mac = arg->k.mac;
1013
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&mac, NULL, rnh));
1014
+	}
1015
+		break;
1016
+#endif
1017
+
1018
+	case IPFW_TABLE_MIX:
1019
+		KEY_LEN(xm) = KEY_LEN_MIX;
1020
+		memcpy(&xm.sin_addr, &arg->k.mix.addr, sizeof(struct in_addr));
1021
+		memcpy(&xm.mac, arg->k.mix.mac, ETHER_ADDR_LEN);
1022
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&xm, NULL, rnh));
1023
+		break;
1024
+
1025
+	default:
1026
+		return (0);
1027
+	}
1028
+
1029
+	if (xent != NULL) {
1030
+		xent->bytes = 0;
1031
+		xent->packets = 0;
1032
+		xent->timestamp = time_uptime;
1033
+		
1034
+		return (1);
1035
+	}
1036
+	return (0);
1037
+}
1038
+
1039
+int
1040
+ipfw_lookup_table_xentry(struct ip_fw_chain *ch, ipfw_table_xentry *arg)
1041
+{
1042
+	struct radix_node_head *rnh;
1043
+	struct table_xentry *xent;
1044
+
1045
+	if (arg->tbl >= V_fw_tables_max)
1046
+		return (0);
1047
+	if ((rnh = ch->xtables[arg->tbl]) == NULL)
1048
+		return (0);
1049
+
1050
+	switch (arg->type) {
1051
+	case IPFW_TABLE_CIDR:
1052
+	{
1053
+		struct sockaddr_in6 sa6;
1054
+		KEY_LEN(sa6) = KEY_LEN_INET6;
1055
+		memcpy(&sa6.sin6_addr, &arg->k.addr6, sizeof(struct in6_addr));
1056
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&sa6, NULL, rnh));
1057
+	}
1058
+		break;
1059
+
1060
+	case IPFW_TABLE_INTERFACE:
1061
+	{
1062
+		struct xaddr_iface iface;
1063
+
1064
+		KEY_LEN(iface) = KEY_LEN_IFACE +
1065
+		    strlcpy(iface.ifname, arg->k.iface, IF_NAMESIZE) + 1;
1066
+		/* Assume direct match */
1067
+		/* FIXME: Add interface pattern matching */
1068
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&iface, NULL, rnh));
1069
+	}
1070
+		break;
1071
+
1072
+#if 0
1073
+	case IPFW_TABLE_MAC:
1074
+	{
1075
+		struct xaddr_mac mac;
1076
+
1077
+		KEY_LEN(mac) = KEY_LEN_MAC;
1078
+		mac.mac = arg->k.mac.addr;
1079
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&mac, NULL, rnh));
1080
+	}
1081
+		break;
1082
+#endif
1083
+
1084
+	case IPFW_TABLE_MIX:
1085
+	{
1086
+		struct xaddr_mix xm;
1087
+
1088
+		KEY_LEN(xm) = KEY_LEN_MIX;
1089
+		memcpy(&xm.sin_addr, &arg->k.mix.addr, sizeof(struct in_addr));
1090
+		memcpy(&xm.mac, arg->k.mix.mac, ETHER_ADDR_LEN);
1091
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&xm, NULL, rnh));
1092
+	}
1093
+		break;
1094
+
1095
+	default:
1096
+		return (0);
1097
+	}
1098
+
1099
+	if (xent != NULL) {
1100
+		arg->bytes = xent->bytes;
1101
+		arg->packets = xent->packets;
1102
+		arg->value = xent->value;
1103
+		arg->timestamp = xent->timestamp;
1104
+		
1105
+		return (1);
1106
+	}
1107
+	return (0);
1108
+}
1109
+
1110
+void *
1111
 ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
1112
-    uint32_t *val, int type)
1113
+    uint32_t *val, int type, struct ether_addr *ea)
1114
 {
1115
 	struct radix_node_head *rnh;
1116
 	struct table_xentry *xent;
1117
@@ -562,15 +841,21 @@ ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
1118
 	struct xaddr_iface iface;
1119
 
1120
 	if (tbl >= V_fw_tables_max)
1121
-		return (0);
1122
+		return (NULL);
1123
 	if ((rnh = ch->xtables[tbl]) == NULL)
1124
-		return (0);
1125
+		return (NULL);
1126
 
1127
 	switch (type) {
1128
 	case IPFW_TABLE_CIDR:
1129
 		KEY_LEN(sa6) = KEY_LEN_INET6;
1130
 		memcpy(&sa6.sin6_addr, paddr, sizeof(struct in6_addr));
1131
 		xent = (struct table_xentry *)(rnh->rnh_lookup(&sa6, NULL, rnh));
1132
+		if (xent != NULL) {
1133
+			if (ea && xent->mac_addr) {
1134
+				if (bcmp((u_char *)&xent->mac_addr, ea->octet, ETHER_ADDR_LEN) != 0)
1135
+					xent = NULL;
1136
+			}
1137
+		}
1138
 		break;
1139
 
1140
 	case IPFW_TABLE_INTERFACE:
1141
@@ -581,15 +866,37 @@ ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
1142
 		xent = (struct table_xentry *)(rnh->rnh_lookup(&iface, NULL, rnh));
1143
 		break;
1144
 
1145
+#if 0
1146
+	case IPFW_TABLE_MAC:
1147
+	{
1148
+		struct xaddr_mac mac;
1149
+
1150
+		KEY_LEN(mac) = KEY_LEN_MAC;
1151
+		mac.mac = (struct ether_addr)(*paddr);
1152
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&mac, NULL, rnh));
1153
+	}
1154
+		break;
1155
+#endif
1156
+
1157
+	case IPFW_TABLE_MIX:
1158
+	{
1159
+		struct xaddr_mix xm;
1160
+
1161
+		KEY_LEN(xm) = KEY_LEN_MIX;
1162
+		memcpy(((char *)&xm.sin_addr), paddr, sizeof(struct in_addr) + ETHER_ADDR_LEN);
1163
+		xent = (struct table_xentry *)(rnh->rnh_lookup(&xm, NULL, rnh));
1164
+	}
1165
+		break;
1166
+
1167
 	default:
1168
-		return (0);
1169
+		return (NULL);
1170
 	}
1171
 
1172
 	if (xent != NULL) {
1173
 		*val = xent->value;
1174
-		return (1);
1175
+		return (xent);
1176
 	}
1177
-	return (0);
1178
+	return (NULL);
1179
 }
1180
 
1181
 static int
1182
@@ -698,6 +1005,9 @@ dump_table_xentry_base(struct radix_node *rn, void *arg)
1183
 	/* Save IPv4 address as deprecated IPv6 compatible */
1184
 	xent->k.addr6.s6_addr32[3] = n->addr.sin_addr.s_addr;
1185
 	xent->value = n->value;
1186
+	xent->bytes = n->bytes;
1187
+	xent->packets = n->packets;
1188
+	xent->timestamp = n->timestamp;
1189
 	tbl->cnt++;
1190
 	return (0);
1191
 }
1192
@@ -735,12 +1045,31 @@ dump_table_xentry_extended(struct radix_node *rn, void *arg)
1193
 		memcpy(&xent->k, &n->a.iface.ifname, IF_NAMESIZE);
1194
 		break;
1195
 	
1196
+#if 0
1197
+	case IPFW_TABLE_MAC:
1198
+		/* Assume exact mask */
1199
+		xent->masklen = 8 * ETHER_ADDR_LEN;
1200
+		xent->k.mac.addr = n->a.mac.mac;
1201
+		xent->k.mac.mask = n->m.mac.mac;
1202
+		break;
1203
+#endif
1204
+	
1205
+	case IPFW_TABLE_MIX:
1206
+		/* Assume exact mask */
1207
+		xent->masklen = 8 * (ETHER_ADDR_LEN + sizeof(struct in_addr));
1208
+		memcpy(&xent->k.mix.addr, &n->a.mix.sin_addr, sizeof(struct in_addr));
1209
+		memcpy(xent->k.mix.mac, &n->a.mix.mac, ETHER_ADDR_LEN);
1210
+		break;
1211
+
1212
 	default:
1213
 		/* unknown, skip entry */
1214
 		return (0);
1215
 	}
1216
 
1217
 	xent->value = n->value;
1218
+	xent->bytes = n->bytes;
1219
+	xent->packets = n->packets;
1220
+	xent->timestamp = n->timestamp;
1221
 	tbl->cnt++;
1222
 	return (0);
1223
 }
(2-2/64)