From 4eafa9e62f1fd0ac4aa67f19f12aaad4050d2757 Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Fri, 8 Apr 2016 03:49:23 -0500 Subject: [PATCH] ipv4_from_ipv6: move to librb --- extensions/extb_hostmask.c | 3 +- include/ipv4_from_ipv6.h | 42 ------------------------- ircd/Makefile.am | 1 - ircd/channel.c | 3 +- ircd/hostmask.c | 5 ++- ircd/ipv4_from_ipv6.c | 63 -------------------------------------- librb/include/rb_commio.h | 3 +- librb/src/commio.c | 40 +++++++++++++++++++++--- librb/src/export-syms.txt | 1 + modules/m_whois.c | 3 +- 10 files changed, 44 insertions(+), 120 deletions(-) delete mode 100644 include/ipv4_from_ipv6.h delete mode 100644 ircd/ipv4_from_ipv6.c diff --git a/extensions/extb_hostmask.c b/extensions/extb_hostmask.c index 9bffe26b..9aa964de 100644 --- a/extensions/extb_hostmask.c +++ b/extensions/extb_hostmask.c @@ -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); diff --git a/include/ipv4_from_ipv6.h b/include/ipv4_from_ipv6.h deleted file mode 100644 index 1bfbe653..00000000 --- a/include/ipv4_from_ipv6.h +++ /dev/null @@ -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 diff --git a/ircd/Makefile.am b/ircd/Makefile.am index e1bd46d1..d4b1e31b 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -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 \ diff --git a/ircd/channel.c b/ircd/channel.c index 4609325a..340525ea 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -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); diff --git a/ircd/hostmask.c b/ircd/hostmask.c index 49f357ca..059c07c7 100644 --- a/ircd/hostmask.c +++ b/ircd/hostmask.c @@ -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) diff --git a/ircd/ipv4_from_ipv6.c b/ircd/ipv4_from_ipv6.c deleted file mode 100644 index b2dee9bf..00000000 --- a/ircd/ipv4_from_ipv6.c +++ /dev/null @@ -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 */ diff --git a/librb/include/rb_commio.h b/librb/include/rb_commio.h index f51e04b1..7123a981 100644 --- a/librb/include/rb_commio.h +++ b/librb/include/rb_commio.h @@ -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 */ diff --git a/librb/src/commio.c b/librb/src/commio.c index 259b900d..fde467c8 100644 --- a/librb/src/commio.c +++ b/librb/src/commio.c @@ -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 */ diff --git a/librb/src/export-syms.txt b/librb/src/export-syms.txt index 21c6b035..bd804eb1 100644 --- a/librb/src/export-syms.txt +++ b/librb/src/export-syms.txt @@ -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 diff --git a/modules/m_whois.c b/modules/m_whois.c index 5f7b42d1..a43b9109 100644 --- a/modules/m_whois.c +++ b/modules/m_whois.c @@ -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);