map: fix portsets starting with 0 and use regular NAT for 1:1 MAP

Signed-off-by: Steven Barth <steven@midlink.org>

git-svn-id: svn://svn.openwrt.org/openwrt/branches/barrier_breaker@42742 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
cyrus 2014-10-02 19:16:17 +00:00
parent 9787f8390f
commit d26726dbc7
3 changed files with 31 additions and 19 deletions

View File

@ -8,8 +8,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=map PKG_NAME:=map
PKG_VERSION:=1 PKG_VERSION:=2
PKG_RELEASE:=2 PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk include $(INCLUDE_DIR)/cmake.mk

View File

@ -122,19 +122,28 @@ proto_map_setup() {
[ "$zone" != "-" ] && json_add_string zone "$zone" [ "$zone" != "-" ] && json_add_string zone "$zone"
json_add_array firewall json_add_array firewall
for portset in $(eval "echo \$RULE_${k}_PORTSETS"); do if [ -z "$(eval "echo \$RULE_${k}_PORTSETS")" ]; then
for proto in icmp tcp udp; do json_add_object ""
json_add_object "" json_add_string type nat
json_add_string type nat json_add_string target SNAT
json_add_string target SNAT json_add_string family inet
json_add_string family inet json_add_string snat_ip $(eval "echo \$RULE_${k}_IPV4ADDR")
json_add_string proto "$proto" json_close_object
json_add_boolean connlimit_ports 1 else
json_add_string snat_ip $(eval "echo \$RULE_${k}_IPV4ADDR") for portset in $(eval "echo \$RULE_${k}_PORTSETS"); do
json_add_string snat_port "$portset" for proto in icmp tcp udp; do
json_close_object json_add_object ""
done json_add_string type nat
done json_add_string target SNAT
json_add_string family inet
json_add_string proto "$proto"
json_add_boolean connlimit_ports 1
json_add_string snat_ip $(eval "echo \$RULE_${k}_IPV4ADDR")
json_add_string snat_port "$portset"
json_close_object
done
done
fi
if [ "$type" = "map-t" ]; then if [ "$type" = "map-t" ]; then
json_add_object "" json_add_object ""
json_add_string type rule json_add_string type rule

View File

@ -343,14 +343,17 @@ int main(int argc, char *argv[])
} }
if (psidlen == 0) { if (psidlen > 0 && psid >= 0) {
printf("RULE_%d_PORTSETS=0-65535\n", rulecnt);
} else if (psid >= 0) {
printf("RULE_%d_PORTSETS='", rulecnt); printf("RULE_%d_PORTSETS='", rulecnt);
for (int k = (offset) ? 1 : 0; k < (1 << offset); ++k) { for (int k = (offset) ? 1 : 0; k < (1 << offset); ++k) {
int start = (k << (16 - offset)) | (psid >> offset); int start = (k << (16 - offset)) | (psid >> offset);
int end = start + (1 << (16 - offset - psidlen)) - 1; int end = start + (1 << (16 - offset - psidlen)) - 1;
printf("%d-%d ", start, end);
if (start == 0)
start = 1;
if (start <= end)
printf("%d-%d ", start, end);
} }
printf("'\n"); printf("'\n");
} }