Exemple #1
0
int route_main(int argc, char **argv)
{
	int opt;
	int what = 0;

#ifdef CONFIG_FEATURE_IPV6
	int af = AF_INET;
#endif

	if (!argv[1] || (argv[1][0] == '-')) {
		/* check options */
		int noresolve = 0;
		int extended = 0;

		while ((opt = getopt(argc, argv, "A:ne")) > 0) {
			switch (opt) {
			case 'n':
				noresolve = 1;
				break;
			case 'e':
				extended = 1;
				break;
			case 'A':
#ifdef CONFIG_FEATURE_IPV6
				if (strcmp(optarg, "inet6") == 0)
					af = AF_INET6;
				break;
#endif
			default:
				bb_show_usage();
			}
		}

#ifdef CONFIG_FEATURE_IPV6
		if (af == AF_INET6)
			INET6_displayroutes(*argv != NULL);
		else
#endif
			displayroutes(noresolve, extended);
		return EXIT_SUCCESS;
	} else {
		/* check verb */
		if (strcmp(argv[1], "add") == 0)
			what = RTACTION_ADD;
		else if (strcmp(argv[1], "del") == 0
				 || strcmp(argv[1], "delete") == 0)
			what = RTACTION_DEL;
		else if (strcmp(argv[1], "flush") == 0)
			what = RTACTION_FLUSH;
		else
			bb_show_usage();
	}

#ifdef CONFIG_FEATURE_IPV6
	if (af == AF_INET6)
		return INET6_setroute(what, 0, argv + 2);
#endif
	return INET_setroute(what, 0, argv + 2);
}
Exemple #2
0
int route_main(int argc, char **argv)
{
	unsigned long opt;
	int what;
	char *family;

	/* First, remap '-net' and '-host' to avoid getopt problems. */
	{
		char **p = argv;

		while (*++p) {
			if ((strcmp(*p, "-net") == 0) || (strcmp(*p, "-host") == 0)) {
				p[0][0] = '#';
			}
		}
	}

	opt = bb_getopt_ulflags(argc, argv, "A:ne", &family);

	if ((opt & ROUTE_OPT_A) && strcmp(family, "inet")) {
#ifdef CONFIG_FEATURE_IPV6
		if (strcmp(family, "inet6") == 0) {
			opt |= ROUTE_OPT_INET6;	/* Set flag for ipv6. */
		} else
#endif
		bb_show_usage();
	}

	argv += optind;

	/* No more args means display the routing table. */
	if (!*argv) {
		int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0;
#ifdef CONFIG_FEATURE_IPV6
		if (opt & ROUTE_OPT_INET6)
			INET6_displayroutes(noresolve);
		else
#endif
			displayroutes(noresolve, opt & ROUTE_OPT_e);

		bb_xferror_stdout();
		bb_fflush_stdout_and_exit(EXIT_SUCCESS);
	}

	/* Check verb.  At the moment, must be add, del, or delete. */
	what = kw_lookup(tbl_verb, &argv);
	if (!what || !*argv) {		/* Unknown verb or no more args. */
		bb_show_usage();
	}

#ifdef CONFIG_FEATURE_IPV6
	if (opt & ROUTE_OPT_INET6)
		INET6_setroute(what, argv);
	else
#endif
		INET_setroute(what, argv);

	return EXIT_SUCCESS;
}
Exemple #3
0
int INET6_rinput(int action, int options, char **args)
{
    if (action == RTACTION_FLUSH) {
	fprintf(stderr, _("Flushing `inet6' routing table not supported\n"));
	return usage(E_OPTERR);
    }
    if (action == RTACTION_HELP)
	return usage(E_USAGE);

    return (INET6_setroute(action, options, args));
}