1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
* Copyright (c) 2002-2012 Balabit
* Copyright (c) 1998-2012 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include "afinet-source.h"
#include "messages.h"
#include "transport-mapper-inet.h"
#include "socket-options-inet.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
void
afinet_sd_set_localport(LogDriver *s, gchar *service)
{
AFInetSourceDriver *self = (AFInetSourceDriver *) s;
if (self->bind_port)
g_free(self->bind_port);
self->bind_port = g_strdup(service);
}
void
afinet_sd_set_localip(LogDriver *s, gchar *ip)
{
AFInetSourceDriver *self = (AFInetSourceDriver *) s;
if (self->bind_ip)
g_free(self->bind_ip);
self->bind_ip = g_strdup(ip);
}
void
afinet_sd_set_tls_context(LogDriver *s, TLSContext *tls_context)
{
AFInetSourceDriver *self = (AFInetSourceDriver *) s;
transport_mapper_inet_set_tls_context((TransportMapperInet *) self->super.transport_mapper, tls_context);
}
static gboolean
afinet_sd_setup_addresses(AFSocketSourceDriver *s)
{
AFInetSourceDriver *self = (AFInetSourceDriver *) s;
if (!afsocket_sd_setup_addresses_method(s))
return FALSE;
if (self->super.proto_factory->default_inet_port)
transport_mapper_inet_set_server_port(self->super.transport_mapper, self->super.proto_factory->default_inet_port);
g_sockaddr_unref(self->super.bind_addr);
if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip))
return FALSE;
if (!self->bind_port)
{
const gchar *port_change_warning = transport_mapper_inet_get_port_change_warning(self->super.transport_mapper);
if (port_change_warning)
{
msg_warning(port_change_warning,
evt_tag_str("id", self->super.super.super.id));
}
g_sockaddr_set_port(self->super.bind_addr, transport_mapper_inet_get_server_port(self->super.transport_mapper));
}
else
g_sockaddr_set_port(self->super.bind_addr, afinet_lookup_service(self->super.transport_mapper, self->bind_port));
self->super.activate_listener = (g_sockaddr_get_port(self->super.bind_addr) != 0);
return TRUE;
}
gboolean
afinet_sd_init(LogPipe *s)
{
AFInetSourceDriver *self = (AFInetSourceDriver *) s;
if (!afsocket_sd_init_method(&self->super.super.super.super))
return FALSE;
return TRUE;
}
void
afinet_sd_free(LogPipe *s)
{
AFInetSourceDriver *self = (AFInetSourceDriver *) s;
g_free(self->bind_ip);
g_free(self->bind_port);
afsocket_sd_free_method(s);
}
static AFInetSourceDriver *
afinet_sd_new_instance(TransportMapper *transport_mapper, GlobalConfig *cfg)
{
AFInetSourceDriver *self = g_new0(AFInetSourceDriver, 1);
afsocket_sd_init_instance(&self->super,
socket_options_inet_new(),
transport_mapper,
cfg);
self->super.super.super.super.init = afinet_sd_init;
self->super.super.super.super.free_fn = afinet_sd_free;
self->super.setup_addresses = afinet_sd_setup_addresses;
return self;
}
AFInetSourceDriver *
afinet_sd_new_tcp(GlobalConfig *cfg)
{
return afinet_sd_new_instance(transport_mapper_tcp_new(), cfg);
}
AFInetSourceDriver *
afinet_sd_new_tcp6(GlobalConfig *cfg)
{
return afinet_sd_new_instance(transport_mapper_tcp6_new(), cfg);
}
AFInetSourceDriver *
afinet_sd_new_udp(GlobalConfig *cfg)
{
return afinet_sd_new_instance(transport_mapper_udp_new(), cfg);
}
AFInetSourceDriver *
afinet_sd_new_udp6(GlobalConfig *cfg)
{
return afinet_sd_new_instance(transport_mapper_udp6_new(), cfg);
}
AFInetSourceDriver *
afinet_sd_new_syslog(GlobalConfig *cfg)
{
AFInetSourceDriver *self = afinet_sd_new_instance(transport_mapper_syslog_new(), cfg);
self->super.reader_options.parse_options.flags |= LP_SYSLOG_PROTOCOL;
return self;
}
AFInetSourceDriver *
afinet_sd_new_network(GlobalConfig *cfg)
{
AFInetSourceDriver *self = afinet_sd_new_instance(transport_mapper_network_new(), cfg);
return self;
}
|