clientlog: refactor CLG_Log*Access functions a bit
This commit is contained in:
parent
37732130e1
commit
46b7148f3b
1 changed files with 21 additions and 39 deletions
60
clientlog.c
60
clientlog.c
|
@ -263,25 +263,31 @@ find_subnet(Subnet *subnet, uint32_t *addr, int addr_len, int bits_consumed)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static Node *
|
||||||
|
get_node(IPAddr *ip)
|
||||||
|
{
|
||||||
|
uint32_t ip6[4];
|
||||||
|
|
||||||
|
switch (ip->family) {
|
||||||
|
case IPADDR_INET4:
|
||||||
|
return (Node *)find_subnet(&top_subnet4, &ip->addr.in4, 1, 0);
|
||||||
|
case IPADDR_INET6:
|
||||||
|
split_ip6(ip, ip6);
|
||||||
|
return (Node *)find_subnet(&top_subnet6, ip6, 4, 0);
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
CLG_LogNTPClientAccess (IPAddr *client, time_t now)
|
CLG_LogNTPClientAccess (IPAddr *client, time_t now)
|
||||||
{
|
{
|
||||||
uint32_t ip6[4];
|
|
||||||
Node *node;
|
Node *node;
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
switch (client->family) {
|
node = get_node(client);
|
||||||
case IPADDR_INET4:
|
|
||||||
node = (Node *) find_subnet(&top_subnet4, &client->addr.in4, 1, 0);
|
|
||||||
break;
|
|
||||||
case IPADDR_INET6:
|
|
||||||
split_ip6(client, ip6);
|
|
||||||
node = (Node *) find_subnet(&top_subnet6, ip6, 4, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
node = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -296,22 +302,10 @@ CLG_LogNTPClientAccess (IPAddr *client, time_t now)
|
||||||
void
|
void
|
||||||
CLG_LogNTPPeerAccess(IPAddr *client, time_t now)
|
CLG_LogNTPPeerAccess(IPAddr *client, time_t now)
|
||||||
{
|
{
|
||||||
uint32_t ip6[4];
|
|
||||||
Node *node;
|
Node *node;
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
switch (client->family) {
|
node = get_node(client);
|
||||||
case IPADDR_INET4:
|
|
||||||
node = (Node *) find_subnet(&top_subnet4, &client->addr.in4, 1, 0);
|
|
||||||
break;
|
|
||||||
case IPADDR_INET6:
|
|
||||||
split_ip6(client, ip6);
|
|
||||||
node = (Node *) find_subnet(&top_subnet6, ip6, 4, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
node = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -326,22 +320,10 @@ CLG_LogNTPPeerAccess(IPAddr *client, time_t now)
|
||||||
void
|
void
|
||||||
CLG_LogCommandAccess(IPAddr *client, CLG_Command_Type type, time_t now)
|
CLG_LogCommandAccess(IPAddr *client, CLG_Command_Type type, time_t now)
|
||||||
{
|
{
|
||||||
uint32_t ip6[4];
|
|
||||||
Node *node;
|
Node *node;
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
switch (client->family) {
|
node = get_node(client);
|
||||||
case IPADDR_INET4:
|
|
||||||
node = (Node *) find_subnet(&top_subnet4, &client->addr.in4, 1, 0);
|
|
||||||
break;
|
|
||||||
case IPADDR_INET6:
|
|
||||||
split_ip6(client, ip6);
|
|
||||||
node = (Node *) find_subnet(&top_subnet6, ip6, 4, 0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
node = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue