ipv4_from_ipv6: move to librb
This commit is contained in:
parent
0807c97e69
commit
4eafa9e62f
10 changed files with 44 additions and 120 deletions
|
@ -7,7 +7,6 @@
|
|||
#include "modules.h"
|
||||
#include "client.h"
|
||||
#include "ircd.h"
|
||||
#include "ipv4_from_ipv6.h"
|
||||
|
||||
static const char extb_desc[] = "Hostmask ($m) extban type";
|
||||
|
||||
|
@ -56,7 +55,7 @@ eb_hostmask(const char *banstr, struct Client *client_p, struct Channel *chptr,
|
|||
|
||||
#ifdef RB_IPV6
|
||||
/* handle Teredo if necessary */
|
||||
if (GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET6 && ipv4_from_ipv6((const struct sockaddr_in6 *) &client_p->localClient->ip, &ip4))
|
||||
if (GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET6 && rb_ipv4_from_ipv6((const struct sockaddr_in6 *) &client_p->localClient->ip, &ip4))
|
||||
{
|
||||
sprintf(src_ip4host, "%s!%s@", client_p->name, client_p->username);
|
||||
s4 = src_ip4host + strlen(src_ip4host);
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* charybdis: An advanced ircd.
|
||||
* ipv4_from_ipv6.h: Finds IPv4 addresses behind IPv6 transition technologies
|
||||
*
|
||||
* Copyright (C) 2012 Jilles Tjoelker
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _IPV4_FROM_IPV6_H_
|
||||
#define _IPV4_FROM_IPV6_H_
|
||||
|
||||
#ifdef RB_IPV6
|
||||
int ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6,
|
||||
struct sockaddr_in *restrict ip4);
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -33,7 +33,6 @@ libircd_la_SOURCES = \
|
|||
hash.c \
|
||||
hook.c \
|
||||
hostmask.c \
|
||||
ipv4_from_ipv6.c \
|
||||
ircd.c \
|
||||
ircd_parser.y \
|
||||
ircd_lexer.l \
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
|
||||
#include "s_newconf.h"
|
||||
#include "logger.h"
|
||||
#include "ipv4_from_ipv6.h"
|
||||
#include "s_assert.h"
|
||||
|
||||
struct config_channel_entry ConfigChannel;
|
||||
|
@ -581,7 +580,7 @@ is_banned_list(struct Channel *chptr, rb_dlink_list *list,
|
|||
}
|
||||
#ifdef RB_IPV6
|
||||
if(GET_SS_FAMILY(&who->localClient->ip) == AF_INET6 &&
|
||||
ipv4_from_ipv6((const struct sockaddr_in6 *)&who->localClient->ip, &ip4))
|
||||
rb_ipv4_from_ipv6((const struct sockaddr_in6 *)&who->localClient->ip, &ip4))
|
||||
{
|
||||
sprintf(src_ip4host, "%s!%s@", who->name, who->username);
|
||||
s4 = src_ip4host + strlen(src_ip4host);
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "numeric.h"
|
||||
#include "send.h"
|
||||
#include "match.h"
|
||||
#include "ipv4_from_ipv6.h"
|
||||
|
||||
#ifdef RB_IPV6
|
||||
static unsigned long hash_ipv6(struct sockaddr *, int);
|
||||
|
@ -425,7 +424,7 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
|
|||
|
||||
#ifdef RB_IPV6
|
||||
if(ip != NULL && ip->sa_family == AF_INET6 &&
|
||||
ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)ip, &ip4))
|
||||
rb_ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)ip, &ip4))
|
||||
{
|
||||
kconf = find_conf_by_address(NULL, NULL, NULL, (struct sockaddr *)&ip4, CONF_KILL, AF_INET, vuser, NULL);
|
||||
if(kconf)
|
||||
|
@ -457,7 +456,7 @@ find_dline(struct sockaddr *addr, int aftype)
|
|||
return aconf;
|
||||
#ifdef RB_IPV6
|
||||
if(addr->sa_family == AF_INET6 &&
|
||||
ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)addr, &addr2))
|
||||
rb_ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)addr, &addr2))
|
||||
{
|
||||
aconf = find_conf_by_address(NULL, NULL, NULL, (struct sockaddr *)&addr2, CONF_DLINE | 1, AF_INET, NULL, NULL);
|
||||
if(aconf)
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* charybdis: A slightly useful ircd.
|
||||
* ipv4_from_ipv6.c: Finds IPv4 addresses behind IPv6 transition technologies
|
||||
*
|
||||
* Copyright (C) 2012 Jilles Tjoelker
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdinc.h"
|
||||
#include "ipv4_from_ipv6.h"
|
||||
|
||||
#ifdef RB_IPV6
|
||||
int
|
||||
ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6,
|
||||
struct sockaddr_in *restrict ip4)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!memcmp(ip6->sin6_addr.s6_addr, "\x20\x02", 2))
|
||||
{
|
||||
/* 6to4 and similar */
|
||||
memcpy(&ip4->sin_addr, ip6->sin6_addr.s6_addr + 2, 4);
|
||||
}
|
||||
else if (!memcmp(ip6->sin6_addr.s6_addr, "\x20\x01\x00\x00", 4))
|
||||
{
|
||||
/* Teredo */
|
||||
for (i = 0; i < 4; i++)
|
||||
((uint8_t *)&ip4->sin_addr)[i] = 0xFF ^
|
||||
ip6->sin6_addr.s6_addr[12 + i];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
SET_SS_LEN(ip4, sizeof(struct sockaddr_in));
|
||||
ip4->sin_family = AF_INET;
|
||||
ip4->sin_port = 0;
|
||||
return 1;
|
||||
}
|
||||
#endif /* RB_IPV6 */
|
|
@ -181,10 +181,11 @@ int rb_supports_ssl(void);
|
|||
unsigned int rb_ssl_handshake_count(rb_fde_t *F);
|
||||
void rb_ssl_clear_handshake_count(rb_fde_t *F);
|
||||
|
||||
|
||||
int rb_pass_fd_to_process(rb_fde_t *, pid_t, rb_fde_t *);
|
||||
rb_fde_t *rb_recv_fd(rb_fde_t *);
|
||||
|
||||
const char *rb_ssl_get_cipher(rb_fde_t *F);
|
||||
|
||||
int rb_ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6, struct sockaddr_in *restrict ip4);
|
||||
|
||||
#endif /* INCLUDED_commio_h */
|
||||
|
|
|
@ -2095,7 +2095,6 @@ rb_setup_fd(rb_fde_t *F)
|
|||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
rb_ignore_errno(int error)
|
||||
{
|
||||
|
@ -2242,7 +2241,7 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz
|
|||
}
|
||||
return sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL);
|
||||
}
|
||||
#else
|
||||
#else /* defined(HAVE_SENDMSG) && !defined(WIN32) */
|
||||
#ifndef _WIN32
|
||||
int
|
||||
rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds)
|
||||
|
@ -2257,5 +2256,38 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz
|
|||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif /* _WIN32 */
|
||||
#endif /* defined(HAVE_SENDMSG) && !defined(WIN32) */
|
||||
|
||||
#ifdef RB_IPV6
|
||||
int
|
||||
rb_ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6, struct sockaddr_in *restrict ip4)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!memcmp(ip6->sin6_addr.s6_addr, "\x20\x02", 2))
|
||||
{
|
||||
/* 6to4 and similar */
|
||||
memcpy(&ip4->sin_addr, ip6->sin6_addr.s6_addr + 2, 4);
|
||||
}
|
||||
else if (!memcmp(ip6->sin6_addr.s6_addr, "\x20\x01\x00\x00", 4))
|
||||
{
|
||||
/* Teredo */
|
||||
for (i = 0; i < 4; i++)
|
||||
((uint8_t *)&ip4->sin_addr)[i] = 0xFF ^
|
||||
ip6->sin6_addr.s6_addr[12 + i];
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
SET_SS_LEN(ip4, sizeof(struct sockaddr_in));
|
||||
ip4->sin_family = AF_INET;
|
||||
ip4->sin_port = 0;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
int
|
||||
rb_ipv4_from_ipv6(const struct sockaddr_in6 *restrict ip6, struct sockaddr_in *restrict ip4)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* RB_IPV6 */
|
||||
|
|
|
@ -84,6 +84,7 @@ rb_init_patricia
|
|||
rb_init_prng
|
||||
rb_init_rawbuffers
|
||||
rb_init_rb_dlink_nodes
|
||||
rb_ipv4_from_ipv6
|
||||
rb_kill
|
||||
rb_lib_die
|
||||
rb_lib_init
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "modules.h"
|
||||
#include "hook.h"
|
||||
#include "s_newconf.h"
|
||||
#include "ipv4_from_ipv6.h"
|
||||
#include "ratelimit.h"
|
||||
#include "s_assert.h"
|
||||
|
||||
|
@ -369,7 +368,7 @@ single_whois(struct Client *source_p, struct Client *target_p, int operspy)
|
|||
if (GET_SS_FAMILY(&target_p->localClient->ip) == AF_INET6 &&
|
||||
(show_ip(source_p, target_p) ||
|
||||
(source_p == target_p && !IsIPSpoof(target_p))) &&
|
||||
ipv4_from_ipv6((struct sockaddr_in6 *)&target_p->localClient->ip, &ip4))
|
||||
rb_ipv4_from_ipv6((struct sockaddr_in6 *)&target_p->localClient->ip, &ip4))
|
||||
{
|
||||
rb_inet_ntop_sock((struct sockaddr *)&ip4,
|
||||
buf, sizeof buf);
|
||||
|
|
Loading…
Reference in a new issue