Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
API - restore IPv4 address .0 padding and update copyright dates
Browse files Browse the repository at this point in the history
  • Loading branch information
kanoi committed May 22, 2015
1 parent b9bf62b commit b3b1fc3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
58 changes: 49 additions & 9 deletions api.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2014 Andrew Smith
* Copyright 2011-2015 Andrew Smith
* Copyright 2011-2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -4414,11 +4414,11 @@ static void setup_groups()
*/
static void setup_ipaccess()
{
char *buf, *ptr, *comma, *slash, *end;
char *buf, *ptr, *comma, *slash, *end, *dot;
int ipcount, mask, i, shift;
char tmp[64], original[64];
bool ipv6 = false;
char group;
char tmp[30];

buf = cgmalloc(strlen(opt_api_allow) + 1);

Expand Down Expand Up @@ -4448,6 +4448,8 @@ static void setup_ipaccess()
if (comma)
*(comma++) = '\0';

strncpy(original, ptr, sizeof(original));
original[sizeof(original)-1] = '\0';
group = NOPRIVGROUP;

if (isalpha(*ptr) && *(ptr+1) == ':') {
Expand Down Expand Up @@ -4483,8 +4485,12 @@ static void setup_ipaccess()
if (*slash) {
*(slash++) = '\0';
mask = atoi(slash);
if (mask < 1 || (mask += ipv6 ? 0 : 96) > 128 )
if (mask < 1 || (mask += ipv6 ? 0 : 96) > 128) {
applog(LOG_ERR, "API: ignored address with "
"invalid mask (%d) '%s'",
mask, original);
goto popipo; // skip invalid/zero
}

for (i = 0; i < 16; i++)
ipaccess[ips].mask.s6_addr[i] = 0;
Expand All @@ -4503,14 +4509,47 @@ static void setup_ipaccess()
for (i = 0; i < 16; i++)
ipaccess[ips].ip.s6_addr[i] = 0; // missing default to '[::]'
if (ipv6) {
if (INET_PTON(AF_INET6, ptr, &(ipaccess[ips].ip)) != 1)
if (INET_PTON(AF_INET6, ptr, &(ipaccess[ips].ip)) != 1) {
applog(LOG_ERR, "API: ignored invalid "
"IPv6 address '%s'",
original);
goto popipo;
}
}
else {
// v4 mapped v6 address, such as "::ffff:255.255.255.255"
sprintf(tmp, "::ffff:%s", ptr);
if (INET_PTON(AF_INET6, tmp, &(ipaccess[ips].ip)) != 1)
/* v4 mapped v6 address,
* such as "::ffff:255.255.255.255"
* but pad on extra missing .0 as needed */
dot = strchr(ptr, '.');
if (!dot) {
snprintf(tmp, sizeof(tmp),
"::ffff:%s.0.0.0",
ptr);
} else {
dot = strchr(dot+1, '.');
if (!dot) {
snprintf(tmp, sizeof(tmp),
"::ffff:%s.0.0",
ptr);
} else {
dot = strchr(dot+1, '.');
if (!dot) {
snprintf(tmp, sizeof(tmp),
"::ffff:%s.0",
ptr);
} else {
snprintf(tmp, sizeof(tmp),
"::ffff:%s",
ptr);
}
}
}
if (INET_PTON(AF_INET6, tmp, &(ipaccess[ips].ip)) != 1) {
applog(LOG_ERR, "API: ignored invalid "
"IPv4 address '%s' (as %s)",
original, tmp);
goto popipo;
}
}
for (i = 0; i < 16; i++)
ipaccess[ips].ip.s6_addr[i] &= ipaccess[ips].mask.s6_addr[i];
Expand Down Expand Up @@ -4576,12 +4615,13 @@ static bool check_connect(struct sockaddr_storage *cli, char **connectaddr, char
if (opt_api_allow) {
for (i = 0; i < ips; i++) {
match = true;
for (j = 0; j < 16; j++)
for (j = 0; j < 16; j++) {
if ((client_ip.s6_addr[j] & ipaccess[i].mask.s6_addr[j])
!= ipaccess[i].ip.s6_addr[j]) {
match = false;
break;
}
}
if (match) {
addrok = true;
*group = ipaccess[i].group;
Expand Down
1 change: 1 addition & 0 deletions cgminer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2011-2015 Con Kolivas
* Copyright 2011-2015 Andrew Smith
* Copyright 2011-2012 Luke Dashjr
* Copyright 2010 Jeff Garzik
*
Expand Down
2 changes: 1 addition & 1 deletion driver-bitmain.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2012-2013 Lingchao Xu <lingchao.xu@bitmaintech.com>
* Copyright 2014 Andrew Smith
* Copyright 2014-2015 Andrew Smith
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand Down
2 changes: 1 addition & 1 deletion driver-bitmain.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2013 BitMain project
* Copyright 2013 BitMain <xlc1985@126.com>
* Copyright 2014 Andrew Smith
* Copyright 2014-2015 Andrew Smith
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand Down

0 comments on commit b3b1fc3

Please sign in to comment.