iptables-saveÖÐmatch²¿·Ö´òÓ¡²»³öµÄÎÊÌ⣬¼±¼±£¡£¡£¡Çë¸ßÊÖÖ¸µã
ÎÒ½«iptables-saveµÄ´úÂëÕª³öÀ´£¬¶ÀÁ¢±àÒ룬ʹÓÃÒÔϱàÒëÓï¾ä#!/bin/bash
gcc -Wall -Wunused -DNETFILTER_VERSION=\"1.2.6\" -rdynamic -o $1 $1.c \
/usr/local/lib/iptables.o /usr/local/lib/libiptc.a -ldl
ͨ¹ýprint_rule£¨£©º¯Êý£¨¸½£©À´´òÓ¡iptables¹æÔò£¬
/* Print matchinfo part */
if (e->target_offset) {
IPT_MATCH_ITERATE(e, print_match, &e->ip);
}
·¢ÏÖmatch²¿·Ö´òÓ¡²»³ö£¨Ç°Ã沿·ÖÕý³££©
´íÎóÏÔʾ£ºCan't find library for match mac
(×¢£º½¨Á¢iptables -A FORWARD -m mac --mac-source 00:00:00:00:00:01)
ÇëÎÊÊÇ£¬ÊDz»ÊDZàÒëÀïÉÙÁ˹ØÓÚmatch µÄ.oÎļþ°¡£¿Èçlibiptc_mac.o????
targetÓ¦¸ÃÒ²ÊÇÕâ¸öÎÊÌ⣬ÓÉÓÚÔÚmatch¾Íexit(1)£¬»¹Ã»²éµ½target¡£
Çë¸ßÉÙÖ¸½Ì£¬Ã÷ÌìÔÚÕ½£¬Ð»Ð»£¡£¡£¡£¡£¡£¡
/* We want this to be readable, so only print out neccessary fields.
* Because that's the kind of world I want to live in. */
static void print_rule(const struct ipt_entry *e,
iptc_handle_t *h, const char *chain, int counters)
{
struct ipt_entry_target *t;
const char *target_name;
/* print counters */
if (counters)
printf("[%llu:%llu] ", (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt);
/* print chain name */
printf("-A %s ", chain);
/* Print IP part. */
print_ip("-s", e->ip.src.s_addr,e->ip.smsk.s_addr,
e->ip.invflags & IPT_INV_SRCIP);
print_ip("-d", e->ip.dst.s_addr, e->ip.dmsk.s_addr,
e->ip.invflags & IPT_INV_DSTIP);
print_iface('i', e->ip.iniface, e->ip.iniface_mask,
e->ip.invflags & IPT_INV_VIA_IN);
print_iface('o', e->ip.outiface, e->ip.outiface_mask,
e->ip.invflags & IPT_INV_VIA_OUT);
print_proto(e->ip.proto, e->ip.invflags & IPT_INV_PROTO);
if (e->ip.flags & IPT_F_FRAG)
printf("%s-f ",
e->ip.invflags & IPT_INV_FRAG ? "! " : "");
/* Print matchinfo part */
if (e->target_offset) {
IPT_MATCH_ITERATE(e, print_match, &e->ip);
}
/* Print target name */
target_name = iptc_get_target(e, h);
if (target_name && (*target_name != '\0'))
printf("-j %s ", target_name);
/* Print targinfo part */
t = ipt_get_target((struct ipt_entry *)e);
if (t->u.user.name[0]) {
struct iptables_target *target
= find_target(t->u.user.name, TRY_LOAD);
if (!target) {
fprintf(stderr, "Can't find library for target `%s'\n",
t->u.user.name);
exit(1);
}
if (target->save)
target->save(&e->ip, t);
else {
/* If the target size is greater than ipt_entry_target
* there is something to be saved, we just don't know
* how to print it */
if (t->u.target_size !=
sizeof(struct ipt_entry_target)) {
fprintf(stderr, "Target `%s' is missing "
"save function\n",
t->u.user.name);
exit(1);
}
}
}
printf("\n");
} ¸ã¶¨ÁË£¬ÊÇÄÚºËiptablesrºÍÓû§¿Õ¼äiptablesµÄ°æ±¾²»Ò»ÖÂÔì³ÉµÄ£¬
iptables -version ÏÔʾ1.2.7a
¶øÎÒ±àÒëµÄÊÇ1.3.1°æ±¾£¬
´ÓÍøÉÏdownloadÒ»¸ö1.2.7a°æ±¾¹ûÈ»¸ã¶¨ :)
Ò³:
[1]