tcpd/tcp_wrappers_7.6-ipv6-subnet.diff

102 lines
2.4 KiB
Diff

--- hosts_access.c 2014/10/11 17:16:13 1.57
+++ hosts_access.c 2014/10/12 16:11:45
@@ -367,41 +367,10 @@
/* For simplicity we convert everything to IPv6 (or v4 mapped) */
struct in6_addr pat, addr;
int len, ret, prefixlen=128, nof_periods = 0;
- char ch, token[INET6_ADDRSTRLEN+1], *mask, *ptok = tok, *addition;
- len = strlen(tok);
- if (tok[(n = strlen(tok)) - 1] == '.') { /* prefix */
- while ((ptok = strchr(ptok, '.')) != NULL){
- nof_periods++;
- ptok++;
- }
- switch(nof_periods){
- case 1:
- addition = "0.0.0/8";
- break;
- case 2:
- addition = "0.0/16";
- break;
- case 3:
- addition = "0/24";
- break;
- default:
- tcpd_warn ("Wrong prefix %s", tok);
- return (NO);
- }
- snprintf(token, sizeof(token), "%s%s", tok, addition);
- }
- else if (*tok == '[' && tok[len - 1] == ']')
- {
- ch = tok[len - 1];
- tok[len - 1] = '\0';
- snprintf(token, sizeof(token), "%s", tok+1);
- tok[len - 1] = ch;
- }
- else
- snprintf(token, sizeof(token), "%s", tok);
-
+ char ch, token[INET6_ADDRSTRLEN+1], *mask, *addition;
+
/* If prefix was given, handle it */
- if ((mask = split_at(token, '/')) != 0)
+ if ((mask = split_at(tok, '/')) != 0)
{
if (strchr(mask, '.') != NULL) /* We have something
like 255.255.0.0 */
@@ -428,7 +397,7 @@
return (NO);
}
- if (is_v4_string (token))
+ if (is_v4_string (tok))
prefixlen += 96; /* extend to v4mapped */
if (prefixlen > 128)
@@ -437,6 +406,44 @@
return (NO);
}
}
+
+ len = strlen(tok);
+ if (tok[len - 1] == '.') { /* prefix */
+ char *ptok = tok;
+
+ while ((ptok = strchr(ptok, '.')) != NULL){
+ nof_periods++;
+ ptok++;
+ }
+ switch(nof_periods){
+ case 1:
+ addition = "0.0.0";
+ prefixlen = 8;
+ break;
+ case 2:
+ addition = "0.0";
+ prefixlen = 16;
+ break;
+ case 3:
+ addition = "0";
+ prefixlen = 24;
+ break;
+ default:
+ tcpd_warn ("Wrong prefix %s", tok);
+ return (NO);
+ }
+ snprintf(token, sizeof(token), "%s%s", tok, addition);
+ prefixlen += 96; /* extend to v4mapped */
+ }
+ else if (*tok == '[' && tok[len - 1] == ']')
+ {
+ ch = tok[len - 1];
+ tok[len - 1] = '\0';
+ snprintf(token, sizeof(token), "%s", tok+1);
+ tok[len - 1] = ch;
+ }
+ else
+ snprintf(token, sizeof(token), "%s", tok);
memset (&pat, 0, sizeof(pat));
memset (&addr, 0, sizeof(addr));