From: <ja...@us...> - 2003-12-15 11:04:15
|
Update of /cvsroot/iptables-p2p/iptables-p2p/iptables In directory sc8-pr-cvs1:/tmp/cvs-serv32580/iptables Modified Files: libipt_p2p.c Log Message: greatly improved inverted protocol logic by simply parsing the option differently Index: libipt_p2p.c =================================================================== RCS file: /cvsroot/iptables-p2p/iptables-p2p/iptables/libipt_p2p.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- libipt_p2p.c 14 Dec 2003 16:05:53 -0000 1.4 +++ libipt_p2p.c 15 Dec 2003 11:04:07 -0000 1.5 @@ -116,7 +116,6 @@ /* Initialize default match options. */ pinfo->proto = IPT_P2P_PROTO_ALL; - pinfo->proto_inverse = 0; } static int arg_to_proto(const char *arg) @@ -160,11 +159,16 @@ * 0x6 = IPT_P2P_PROTO_GNUTELLA | IPT_P2P_PROTO_EDONKEY * edonkey,16 = IPT_P2P_PROTO_EDONKEY | IPT_P2P_PROTO_BITTORRENT */ -static int arglist_to_proto(const char *arg) +static int arglist_to_proto(const char *arg, int invert) { char buf[32]; /* Large enough to store proto name. */ size_t protolen; - int protoret = 0; + int protoret; + + if (invert) + protoret = IPT_P2P_PROTO_ALL; + else + protoret = 0; while (1) { @@ -178,7 +182,10 @@ buf[protolen] = '\0'; /* Handle a single parameter */ - protoret |= arg_to_proto(arg); + if (invert) + protoret &= ~(arg_to_proto(arg)); + else + protoret |= arg_to_proto(arg); arg += protolen; @@ -217,10 +224,9 @@ /* Where the hell is check_inverse() defined, and what the hell does it do? */ check_inverse(optarg, &invert, &optind, 0); - pinfo->proto = arglist_to_proto(argv[optind-1]); - pinfo->proto_inverse = invert; + pinfo->proto = arglist_to_proto(argv[optind-1], invert); - if (pinfo->proto == IPT_P2P_PROTO_ALL && pinfo->proto_inverse) + if (pinfo->proto == 0) { exit_error(PARAMETER_PROBLEM, "P2P match: May not specify inverted 'all'"); @@ -248,18 +254,12 @@ printf("P2P match "); - if (pinfo->proto_inverse) - fputc('!', stdout); - fputs(proto_to_arg(pinfo->proto), stdout); } static void save(const struct ipt_ip *ip, const struct ipt_entry_match *m) { const struct ipt_p2p_info *pinfo = IPT_P2P_INFO_const(m); - - if (pinfo->proto_inverse) - printf("! "); printf("--p2p-protocol %s", proto_to_arg(pinfo->proto)); } |