- ## Dynamic rules (2810):
- 00316 1 120 (10s) LIMIT udp 10.72.208.149 63136 10.72.16.1 53
- 00316 1 120 (10s) LIMIT udp 10.72.176.240 5828 10.72.16.1 53
- 00316 3 324 (5s) LIMIT udp 10.72.176.156 46759 10.72.16.1 53
- 00316 1 204 (2s) LIMIT udp 10.72.177.126 55111 10.72.16.1 53
- 00316 0 0 (4s) PARENT 6 udp 10.72.208.109 0 0.0.0.0 0
于是先请来这段的源代码:
- static void
- show_dyn_ipfw(ipfw_dyn_rule *d, int pcwidth, int bcwidth)
- {
- struct protoent *pe;
- struct in_addr a;
- uint16_t rulenum;
- char buf[INET6_ADDRSTRLEN];
- if (!co.do_expired) {
- if (!d->expire && !(d->dyn_type == O_LIMIT_PARENT))
- return;
- }
- bcopy(&d->rule, &rulenum, sizeof(rulenum));
- printf("%05d", rulenum);
- if (pcwidth > 0 || bcwidth > 0) {
- printf(" ");
- pr_u64(&d->pcnt, pcwidth);
- pr_u64(&d->bcnt, bcwidth);
- printf("(%ds)", d->expire);
- }
- switch (d->dyn_type) {
- case O_LIMIT_PARENT:
- printf(" PARENT %d", d->count);
- break;
- case O_LIMIT:
- printf(" LIMIT");
- break;
- case O_KEEP_STATE: /* bidir, no mask */
- printf(" STATE");
- break;
- }
- if ((pe = getprotobynumber(d->id.proto)) != NULL)
- printf(" %s", pe->p_name);
- else
- printf(" proto %u", d->id.proto);
- if (d->id.addr_type == 4) {
- a.s_addr = htonl(d->id.src_ip);
- printf(" %s %d", inet_ntoa(a), d->id.src_port);
- a.s_addr = htonl(d->id.dst_ip);
- printf(" %s %d", inet_ntoa(a), d->id.dst_port);
- } else if (d->id.addr_type == 6) {
- printf(" %s %d", inet_ntop(AF_INET6, &d->id.src_ip6, buf,
- sizeof(buf)), d->id.src_port);
- printf(" %s %d", inet_ntop(AF_INET6, &d->id.dst_ip6, buf,
- sizeof(buf)), d->id.dst_port);
- } else
- printf(" UNKNOWN UNKNOWN\n");
- printf("\n");
- }
上面这段是完整的输入函数,我们来逐个看一下输入:
printf("%05d", rulenum); 输出规则号,因为最高是65535,所以5位就足够了;
然后又接连来的四句:
printf(" "); 输出空格
pr_u64(&d->pcnt, pcwidth); pcnt:packet count的缩写,包数量
pr_u64(&d->bcnt, bcwidth); bcnt:byte count 的缩写,字节数量
printf("(%ds)", d->expire); 这句明显了,是过期时间,单位是s(秒)
后面是一个switch,表示动态规则的类型:PARENT型为父规则,这个规则的pcnt、bcnt都为零,所有其他规则都必须在这个规则下创建;LIMIT为限制规则,只要在规则中有LIMIT语句,则为LIMIT类型;STATE为状态规则,表示为keep-state的规则。注意 printf(" PARENT %d", d->count);后面有个%d,表示PARENT类型规则下面,有多少个子规则,由此来判断是不是可以limit了。
再后面就好理解了,就是源地址 源端口 目录地址 目标端口
所以画个图,以便理解: