示例#1
0
        public override NatOptions BuildNative()
        {
            Target     snat    = Build();
            NatOptions options = new NatOptions();

            options.ranges     = new NatRange[] { NatRange.Default() };
            options.range_size = 1;
            if (snat.TryGetValue(TO_SOURCE_OPT, out var src))
            {
                var range = src.ToIpProtoRange();
                options.ranges[0].min_ip    = ReverceEndian(range.minIp);
                options.ranges[0].max_ip    = ReverceEndian(range.maxIp);
                options.ranges[0].min_proto = ReverceEndian(range.minP);
                options.ranges[0].max_proto = ReverceEndian(range.maxP);
                if (options.ranges[0].min_ip > 0 || options.ranges[0].max_ip < uint.MaxValue)
                {
                    options.ranges[0].flags |= NatRange.NF_NAT_RANGE_MAP_IPS;
                }
                if (options.ranges[0].min_proto > 0 || options.ranges[0].max_proto < ushort.MaxValue)
                {
                    options.ranges[0].flags |= NatRange.NF_NAT_RANGE_PROTO_SPECIFIED;
                }
            }

            if (snat.ContainsKey(RANDOM_OPT))
            {
                options.ranges[0].flags |= NatRange.NF_NAT_RANGE_PROTO_RANDOM;
            }

            if (snat.ContainsKey(RANDOM_FULLY_OPT))
            {
                options.ranges[0].flags |= NatRange.NF_NAT_RANGE_PROTO_RANDOM_FULLY;
            }

            if (snat.ContainsKey(PERSISTENT_OPT))
            {
                options.ranges[0].flags |= NatRange.NF_NAT_RANGE_PROTO_RANDOM_FULLY;
            }

            return(options);
        }
        public override NatOptions BuildNative()
        {
            Target     msqrd   = Build();
            NatOptions options = new NatOptions();

            options.ranges     = new NatRange[] { NatRange.Default() };
            options.range_size = 1;
            if (msqrd.TryGetValue(TO_PORTS_OPT, out var src))
            {
                var range = src.ToRangeProperty('-');
                options.ranges[0].min_proto = ReverceEndian(ushort.Parse(range.Left));
                options.ranges[0].max_proto = ReverceEndian(ushort.Parse(range.Rigt));
                options.ranges[0].flags    |= NatRange.NF_NAT_RANGE_PROTO_SPECIFIED;
            }

            if (msqrd.ContainsKey(RANDOM_OPT))
            {
                options.ranges[0].flags |= NatRange.NF_NAT_RANGE_PROTO_RANDOM;
            }

            return(options);
        }