* mapcalc - MAP parameter calculation
*
* Author: Steven Barth <cyrus@openwrt.org>
- * Copyright (c) 2014 cisco Systems, Inc.
+ * Copyright (c) 2014-2015 cisco Systems, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
if (ealen < 0 && pdlen >= 0)
ealen = pdlen - prefix6len;
- if (psidlen < 0)
+ if (psidlen <= 0) {
psidlen = ealen - (32 - prefix4len);
+ psid = -1;
+ }
if (psid < 0 && psidlen <= 16 && psidlen >= 0 && pdlen >= 0 && ealen >= psidlen) {
bmemcpys64(&psid16, &pd, prefix6len + ealen - psidlen, psidlen);
}
- if (psidlen == 0) {
- printf("RULE_%d_PORTSETS=0-65535\n", rulecnt);
- } else if (psid >= 0) {
+ if (psidlen > 0 && psid >= 0) {
printf("RULE_%d_PORTSETS='", rulecnt);
for (int k = (offset) ? 1 : 0; k < (1 << offset); ++k) {
int start = (k << (16 - offset)) | (psid >> offset);
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");
}