예제 #1
0
int masqmod_main(int argc, const char *argv[])
{
	int c;
	int command = IP_MASQ_CMD_NONE;
	struct ip_masq_ctl mctl;
#define ums mctl.u.user
	struct sockaddr_in m_sin, s_sin, d_sin;
	int tmp;
	int nonames = 0;

	memset (&m_sin, 0, sizeof (m_sin));
	memset (&d_sin, 0, sizeof (d_sin));
	memset (&s_sin, 0, sizeof (s_sin));
	memset (&ums, 0, sizeof (ums));
	ums.protocol = IPPROTO_NONE;

	modname = argv[0];

	while ((c = getopt(argc, (char**) argv, "adsgnP:M:D:S:t:h")) != -1)
		switch (c) {
			case 'a':
				if (command != IP_MASQ_CMD_NONE)
					exit_error(2, "multiple commands specified");
				command = IP_MASQ_CMD_ADD;
				break;
			case 'd':
				if (command != IP_MASQ_CMD_NONE)
					exit_error(2, "multiple commands specified");
				command = IP_MASQ_CMD_DEL;
				break;
			case 's':
				if (command != IP_MASQ_CMD_NONE)
					exit_error(2, "multiple commands specified");
				command = IP_MASQ_CMD_SET;
				break;
			case 'g':
				if (command != IP_MASQ_CMD_NONE)
					exit_error(2, "multiple commands specified");
				command = IP_MASQ_CMD_GET;
				break;

			case 'n':
				nonames++;
				break;

			case 'P':
				if (ums.protocol != IPPROTO_NONE)
					exit_error(2, "multiple protocols specified");

				switch (*optarg) {
					case 't':
						ums.protocol = IPPROTO_TCP;
						break;
					case 'u':
						ums.protocol = IPPROTO_UDP;
						break;
					default:
						exit_error(2, "invalid protocol specified");
				}
				break;
			case 'M':
				if (m_sin.sin_addr.s_addr||m_sin.sin_port)
					exit_error(2, "multiple [M]asq specified");
				tmp = optind-1;
				tmp = parse_addressport(argv+tmp, argc-tmp, &m_sin, nonames);
				if (tmp!=2)
					exit_error(2, "illegal [M]asq address/port specified");
				optind += tmp -1;
				break;
			case 'S':
				if (s_sin.sin_addr.s_addr||s_sin.sin_port)
					exit_error(2, "multiple [S]ource specified");
				tmp = optind-1;
				tmp = parse_addressport(argv+tmp, argc-tmp, &s_sin, nonames);

				if (tmp != 2)
					exit_error(2, "illegal destination specified");
				optind += tmp -1;
				break;
			case 'D':
				if (d_sin.sin_addr.s_addr||d_sin.sin_port)
					exit_error(2, "multiple [D]estinations specified");
				tmp = optind-1;
				tmp = parse_addressport(argv+tmp, argc-tmp, &d_sin, nonames);

				if (tmp != 2)
					exit_error(2, "illegal destination specified");
				optind += tmp -1;
				break;
			case 't':
				ums.timeout = atoi(optarg) * HZ;
				if (ums.timeout <= 0)
					exit_error(2, "illegal timeout value specified");
				break;
			case 'h':
			case '?':
			default:
				exit_display_help();
		}

	if (optind < argc) {
		printf("optind=%d (%s) argc=%d\n", optind, argv[optind-1], argc);
		exit_error(2, "unknown arguments found on commandline");
	}

	if (command == IP_MASQ_CMD_NONE)
		exit_display_help();

	if (ums.protocol == IPPROTO_NONE) {
		exit_error(2,"no protocol specified");
	}

	ums.mport = m_sin.sin_port;
	ums.maddr = m_sin.sin_addr.s_addr;
	ums.dport = d_sin.sin_port;
	ums.daddr = d_sin.sin_addr.s_addr;
	ums.sport = s_sin.sin_port;
	ums.saddr = s_sin.sin_addr.s_addr;

	switch (command) {
		case IP_MASQ_CMD_ADD:
			if (0) 
				exit_error(2, "insufficient options specified");
			break;
		case IP_MASQ_CMD_DEL:
			if ((ums.mport == 0)||(ums.maddr == 0))
				exit_error(2, "insufficient options specified");
			break;
	}

	return(do_setsockopt(command, &mctl, sizeof(mctl)));
}
예제 #2
0
int masqmod_main(int argc, const char *argv[])
{
    int c;
    int command = IP_MASQ_CMD_NONE;
    struct ip_masq_ctl mctl;
#define pfw mctl.u.portfw_user
    struct sockaddr_in local_sin;
    struct sockaddr_in redir_sin;
    int tmp;
    int nonames = 0;

    memset (&local_sin, 0, sizeof (local_sin));
    memset (&redir_sin, 0, sizeof (local_sin));
    pfw.protocol = IPPROTO_NONE;
    pfw.raddr = 0;
    pfw.rport = 0;
    pfw.laddr = 0;
    pfw.lport = 0;
    pfw.pref  = IP_PORTFW_DEF_PREF;

    modname = argv[0];

    while ((c = getopt(argc, (char**) argv, "adflnP:R:L:p:h")) != -1)
        switch (c) {
        case 'a':
            if (command != IP_MASQ_CMD_NONE)
                exit_error(2, "multiple commands specified");
            command = IP_MASQ_CMD_ADD;
            break;
        case 'd':
            if (command != IP_MASQ_CMD_NONE)
                exit_error(2, "multiple commands specified");
            command = IP_MASQ_CMD_DEL;
            break;
        case 'f':
            if (command != IP_MASQ_CMD_NONE)
                exit_error(2, "multiple commands specified");
            command = IP_MASQ_CMD_FLUSH;
            break;
        case 'l':
            if (command != IP_MASQ_CMD_NONE)
                exit_error(2, "multiple commands specified");
            command = IP_MASQ_CMD_LIST;
            break;

        case 'n':
            nonames++;
            break;

        case 'P':
            if (pfw.protocol != IPPROTO_NONE)
                exit_error(2, "multiple protocols specified");

            switch (*optarg) {
            case 't':
                pfw.protocol = IPPROTO_TCP;
                break;
            case 'u':
                pfw.protocol = IPPROTO_UDP;
                break;
            default:
                exit_error(2, "invalid protocol specified");
            }
            break;
        case 'L':
            if (local_sin.sin_addr.s_addr||local_sin.sin_port)
                exit_error(2, "multiple local address/port specified");
            tmp = optind-1;
            tmp = parse_addressport(argv+tmp, argc-tmp, &local_sin, nonames);
            if (tmp!=2)
                exit_error(2, "illegal local address/port specified");
            optind += tmp -1;
            break;
        case 'R':
            if (redir_sin.sin_addr.s_addr||redir_sin.sin_port)
                exit_error(2, "multiple destinations specified");
            tmp = optind-1;
            tmp = parse_addressport(argv+tmp, argc-tmp, &redir_sin, nonames);

            if (tmp != 2)
                exit_error(2, "illegal destination specified");
            optind += tmp -1;
            break;
        case 'p':
            pfw.pref = atoi(optarg);
            if (pfw.pref <= 0)
                exit_error(2, "illegal preference value specified");
            break;
        case 'h':
        case '?':
        default:
            exit_display_help();
        }

    if (optind < argc) {
        printf("optind=%d (%s) argc=%d\n", optind, argv[optind-1], argc);
        exit_error(2, "unknown arguments found on commandline");
    }

    pfw.rport = redir_sin.sin_port;
    pfw.raddr = redir_sin.sin_addr.s_addr;
    pfw.lport = local_sin.sin_port;
    pfw.laddr = local_sin.sin_addr.s_addr;
    if (command == IP_MASQ_CMD_NONE)
        exit_display_help();

    else if (command == IP_MASQ_CMD_ADD &&
             (pfw.protocol == IPPROTO_NONE || pfw.lport == 0 ))
#if 0
        || pfw.rport == 0 || pfw.raddr == 0))
#endif
        exit_error(2, "insufficient options specified");

        else if (command == IP_MASQ_CMD_DEL &&
예제 #3
0
int masqmod_main(int argc, const char *argv[])
{
	int c;
	int command = IP_MASQ_CMD_NONE;
	struct ip_masq_ctl mctl;
#define mfw mctl.u.mfw_user
	struct sockaddr_in redir_sin;
	int tmp;
	int nonames = 0;

	memset (&redir_sin, 0, sizeof (redir_sin));
	mfw.fwmark = 0;
	mfw.raddr = 0;
	mfw.rport = 0;
	mfw.flags = 0;
	mfw.pref  = IP_MARKFW_DEF_PREF;

	modname = argv[0];

	while ((c = getopt(argc, (char**) argv, "AEDFSLnm:r:p:h")) != -1)
		switch (c) {
		case 'A':
			if (command != IP_MASQ_CMD_NONE)
				exit_error(2, "multiple commands specified");
			command = IP_MASQ_CMD_ADD;
			break;
		case 'E':
			if (command != IP_MASQ_CMD_NONE)
				exit_error(2, "multiple commands specified");
			command = IP_MASQ_CMD_SET;
			break;
		case 'D':
			if (command != IP_MASQ_CMD_NONE)
				exit_error(2, "multiple commands specified");
			command = IP_MASQ_CMD_DEL;
			break;
		case 'F':
			if (command != IP_MASQ_CMD_NONE)
				exit_error(2, "multiple commands specified");
			command = IP_MASQ_CMD_FLUSH;
			break;
		case 'S':
			if (command != IP_MASQ_CMD_NONE)
				exit_error(2, "multiple commands specified");
			command = IP_MASQ_CMD_SET;
			mfw.flags |= IP_MASQ_MFW_SCHED;
			break;
                case 'L':
                        if (command != IP_MASQ_CMD_NONE)
				exit_error(2, "multiple commands specified");
			command = IP_MASQ_CMD_LIST;
			break;

		case 'n':
			nonames++;
			break;

		case 'm':
			mfw.fwmark = atoi(optarg);
			break;
		case 'r':
			if (redir_sin.sin_addr.s_addr||redir_sin.sin_port)
				exit_error(2, "multiple destinations specified");
			tmp = optind-1;
			tmp = parse_addressport(argv+tmp, argc-tmp, &redir_sin, nonames);

			if (tmp < 1)
				exit_error(2, "illegal destination specified");
			optind += tmp -1;
			break;
                case 'p':
                        mfw.pref = atoi(optarg);

			/*
			 *	pref == 0 marks the entry as un-schedulable
			 */
                        if (mfw.pref < 0)
                                exit_error(2, "illegal preference value specified");
                        break;
		case 'h':
		case '?':
		default:
			exit_display_help();
		}

        if (optind < argc) {
		printf("optind=%d (%s) argc=%d\n", optind, argv[optind-1], argc);
                exit_error(2, "unknown arguments found on commandline");
	}

	mfw.rport = redir_sin.sin_port;
	mfw.raddr = redir_sin.sin_addr.s_addr;
	if (command == IP_MASQ_CMD_NONE)
		exit_display_help();

	else if (command == IP_MASQ_CMD_ADD && (mfw.fwmark == 0 ))
#if 0
		 || mfw.rport == 0 || mfw.raddr == 0))
#endif
		exit_error(2, "insufficient options specified");

	else if (command == IP_MASQ_CMD_DEL &&