static struct xtc_handle *create_handle(const char *tablename)
{
	struct xtc_handle *handle;

	handle = iptc_init(tablename);

	if (!handle) {
		/* try to insmod the module if iptc_init failed */
		xtables_load_ko(xtables_modprobe_program, false);
		handle = iptc_init(tablename);
	}

	if (!handle) {
		xtables_error(PARAMETER_PROBLEM, "%s: unable to initialize "
			"table '%s'\n", prog_name, tablename);
		exit(1);
	}
	return handle;
}
예제 #2
0
static int for_save_table()
{
	int ret = 1;
	FILE *procfile = NULL;
	char tablename[] ="filter";
	const char *returnvalue =NULL;
	time_t now = time(NULL);
	const char *target_name;

	procfile = fopen("/data/ip_tables_save_temp", "w+");
	if (!procfile)
		return ret;


	struct iptc_handle *h;
	const char *chain = NULL;

	h = iptc_init(tablename);
	if (h == NULL) {
		xtables_load_ko(xtables_modprobe_program, false);
		h = iptc_init(tablename);
	}
	if (!h)
		xtables_error(OTHER_PROBLEM, "Cannot initialize: %s\n",
			   iptc_strerror(errno));

		printf("# for_save_table...LGE \n");

		/* Dump out chain names first,
		 * thereby preventing dependency conflicts */

		for (chain = iptc_first_chain(h);
		     chain;
		     chain = iptc_next_chain(h)) {
			const struct ipt_entry *e;

			printf(":%s\n ", chain);
			if(!strcmp(chain,"OUTPUT")){

				/* Dump out rules */
				e = iptc_first_rule(chain, h);
				while(e) {
						target_name = iptc_get_target(e, h);
						
						if(!strcmp(target_name,"DROP")){
							printf("target :%s\n ", target_name);
							printf("out_iface :%s\n ", e->ip.outiface);
							fprintf(procfile,"%s\t%s\n", target_name, e->ip.outiface);
							
						}
						e = iptc_next_rule(e, h);
				}
			}	
		}

	//fputs(returnvalue, procfile);

	iptc_free(h);

	fclose(procfile);
	return ret;
}
예제 #3
0
static int do_output(const char *tablename)
{
	struct ip6tc_handle *h;
	const char *chain = NULL;

	if (!tablename)
		return for_each_table(&do_output);

	h = ip6tc_init(tablename);
	if (h == NULL) {
		xtables_load_ko(xtables_modprobe_program, false);
		h = ip6tc_init(tablename);
	}
	if (!h)
		xtables_error(OTHER_PROBLEM, "Cannot initialize: %s\n",
			   ip6tc_strerror(errno));

	if (!show_binary) {
		time_t now = time(NULL);

		printf("# Generated by ip6tables-save v%s on %s",
		       IPTABLES_VERSION, ctime(&now));
		printf("*%s\n", tablename);

		/* Dump out chain names first,
		 * thereby preventing dependency conflicts */
		for (chain = ip6tc_first_chain(h);
		     chain;
		     chain = ip6tc_next_chain(h)) {

			printf(":%s ", chain);
			if (ip6tc_builtin(chain, h)) {
				struct ip6t_counters count;
				printf("%s ",
				       ip6tc_get_policy(chain, &count, h));
				printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
			} else {
				printf("- [0:0]\n");
			}
		}


		for (chain = ip6tc_first_chain(h);
		     chain;
		     chain = ip6tc_next_chain(h)) {
			const struct ip6t_entry *e;

			/* Dump out rules */
			e = ip6tc_first_rule(chain, h);
			while(e) {
				print_rule(e, h, chain, show_counters);
				e = ip6tc_next_rule(e, h);
			}
		}

		now = time(NULL);
		printf("COMMIT\n");
		printf("# Completed on %s", ctime(&now));
	} else {
		/* Binary, huh?  OK. */
		xtables_error(OTHER_PROBLEM, "Binary NYI\n");
	}

	ip6tc_free(h);

	return 1;
}