Пример #1
0
static LogTransport *
afinet_dd_construct_tls_transport(AFInetDestDriver *self, TLSContext *tls_context, gint fd)
{
  TLSSession *tls_session;

  tls_session = tls_context_setup_session(self->tls_context);
  if (!tls_session)
    return NULL;

  tls_session_set_verify(tls_session, afinet_dd_verify_callback, self, NULL);
  return log_transport_tls_new(tls_session, fd);
}
static LogTransport *
transport_mapper_inet_construct_log_transport(TransportMapper *s, gint fd)
{
  TransportMapperInet *self = (TransportMapperInet *) s;

  if (self->tls_context)
    {
      TLSSession *tls_session;

      tls_session = tls_context_setup_session(self->tls_context);
      if (!tls_session)
        return NULL;

      tls_session_set_verify(tls_session, self->tls_verify_callback, self->tls_verify_data, NULL);
      return log_transport_tls_new(tls_session, fd);
    }
  else
    return transport_mapper_construct_log_transport_method(s, fd);
}
Пример #3
0
static gboolean
afsocket_sc_init(LogPipe *s)
{
  AFSocketSourceConnection *self = (AFSocketSourceConnection *) s;
  gint read_flags;
  LogTransport *transport;
  LogProto *proto;

  read_flags = ((self->owner->flags & AFSOCKET_DGRAM) ? LTF_RECV : 0);
  if (!self->reader)
    {
#if ENABLE_SSL
      if (self->owner->tls_context)
        {
          TLSSession *tls_session = tls_context_setup_session(self->owner->tls_context);
          if (!tls_session)
            return FALSE;
          transport = log_transport_tls_new(tls_session, self->sock, read_flags);
        }
      else
#endif
        transport = log_transport_plain_new(self->sock, read_flags);

      if ((self->owner->flags & AFSOCKET_SYSLOG_PROTOCOL) == 0)
        {
          /* plain protocol */

          if (self->owner->flags & AFSOCKET_DGRAM)
            proto = log_proto_dgram_server_new(transport, self->owner->reader_options.msg_size, 0);
          else if (self->owner->reader_options.padding)
            proto = log_proto_record_server_new(transport, self->owner->reader_options.padding, 0);
          else
            proto = log_proto_text_server_new(transport, self->owner->reader_options.msg_size, 0);
        }
      else
        {
          if (self->owner->flags & AFSOCKET_DGRAM)
            {
              /* plain protocol */
              proto = log_proto_dgram_server_new(transport, self->owner->reader_options.msg_size, 0);
            }
          else
            {
              /* framed protocol */
              proto = log_proto_framed_server_new(transport, self->owner->reader_options.msg_size);
            }
        }

      self->reader = log_reader_new(proto);
    }
  log_reader_set_options(self->reader, s, &self->owner->reader_options, 1, afsocket_sc_stats_source(self), self->owner->super.super.id, afsocket_sc_stats_instance(self));
  log_reader_set_peer_addr(self->reader, self->peer_addr);
  log_pipe_append(self->reader, s);
  if (log_pipe_init(self->reader, NULL))
    {
      return TRUE;
    }
  else
    {
      log_pipe_unref(self->reader);
      self->reader = NULL;
    }
  return FALSE;
}
Пример #4
0
static gboolean
afsocket_dd_connected(AFSocketDestDriver *self)
{
  gchar buf1[256], buf2[256];
  int error = 0;
  socklen_t errorlen = sizeof(error);
  LogTransport *transport;
  LogProto *proto;
  guint32 transport_flags = 0;

  main_loop_assert_main_thread();

  if (iv_fd_registered(&self->connect_fd))
    iv_fd_unregister(&self->connect_fd);

  if (self->flags & AFSOCKET_STREAM)
    {
      transport_flags |= LTF_SHUTDOWN;
      if (getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &error, &errorlen) == -1)
        {
          msg_error("getsockopt(SOL_SOCKET, SO_ERROR) failed for connecting socket",
                    evt_tag_int("fd", self->fd),
                    evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)),
                    evt_tag_errno(EVT_TAG_OSERROR, errno),
                    evt_tag_int("time_reopen", self->time_reopen),
                    NULL);
          goto error_reconnect;
        }
      if (error)
        {
          msg_error("Syslog connection failed",
                    evt_tag_int("fd", self->fd),
                    evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)),
                    evt_tag_errno(EVT_TAG_OSERROR, error),
                    evt_tag_int("time_reopen", self->time_reopen),
                    NULL);
          goto error_reconnect;
        }
    }
  msg_notice("Syslog connection established",
              evt_tag_int("fd", self->fd),
              evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)),
              evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)),
              NULL);


#if ENABLE_SSL
  if (self->tls_context)
    {
      TLSSession *tls_session;

      tls_session = tls_context_setup_session(self->tls_context);
      if (!tls_session)
        {
          goto error_reconnect;
        }

      tls_session_set_verify(tls_session, afsocket_dd_tls_verify_callback, self, NULL);
      transport = log_transport_tls_new(tls_session, self->fd, transport_flags);
    }
  else
#endif
    transport = log_transport_plain_new(self->fd, transport_flags);

  if (self->flags & AFSOCKET_SYSLOG_PROTOCOL)
    {
      if (self->flags & AFSOCKET_STREAM)
        proto = log_proto_framed_client_new(transport);
      else
        proto = log_proto_text_client_new(transport);
    }
  else
    {
      proto = log_proto_text_client_new(transport);
    }

  log_writer_reopen(self->writer, proto);
  return TRUE;
 error_reconnect:
  close(self->fd);
  self->fd = -1;
  afsocket_dd_start_reconnect_timer(self);
  return FALSE;
}
Пример #5
0
static gboolean
afsocket_sc_init(LogPipe *s)
{
  AFSocketSourceConnection *self = (AFSocketSourceConnection *) s;
  gint read_flags;
  LogTransport *transport;
  LogProto *proto;

  read_flags = ((self->owner->flags & AFSOCKET_DGRAM) ? LTF_RECV : 0);

#if ENABLE_SSL
  if (self->owner->tls_context)
    {
      TLSSession *tls_session = tls_context_setup_session(self->owner->tls_context);
      
      if (!tls_session)
        return FALSE;
      transport = log_transport_tls_new(tls_session, self->sock, read_flags);
    }
  else
#endif

  transport = log_transport_plain_new(self->sock, read_flags);

  if ((self->owner->flags & AFSOCKET_SYSLOG_PROTOCOL) == 0)
    {
      /* plain protocol */
      proto = log_proto_plain_new_server(transport, self->owner->reader_options.padding,
                   self->owner->reader_options.msg_size,
                   (self->owner->flags & AFSOCKET_DGRAM) ? (LPPF_PKTTERM + LPPF_IGNORE_EOF) : 0);
    }
  else
    {
      if (self->owner->flags & AFSOCKET_DGRAM)
        {
          /* plain protocol */
          proto = log_proto_plain_new_server(transport, self->owner->reader_options.padding,
                       self->owner->reader_options.msg_size,
                      (self->owner->flags & AFSOCKET_DGRAM) ? (LPPF_PKTTERM + LPPF_IGNORE_EOF) : 0);
        }
      else
        {
          /* framed protocol */
          proto = log_proto_framed_new_server(transport, self->owner->reader_options.msg_size);
        }
    }

  self->reader = log_reader_new(proto,
                                ((self->owner->flags & AFSOCKET_LOCAL) ? LR_LOCAL : 0) |
                                ((self->owner->flags & AFSOCKET_SYSLOG_PROTOCOL) ? LR_SYSLOG_PROTOCOL : 0));
  log_reader_set_options(self->reader, s, &self->owner->reader_options, 1, afsocket_sc_stats_source(self), self->owner->super.id, afsocket_sc_stats_instance(self));
  log_reader_set_peer_addr(self->reader, self->peer_addr);
  log_pipe_append(self->reader, s);
  if (log_pipe_init(self->reader, NULL))
    {
      self->owner->connections = g_list_prepend(self->owner->connections, self);
      return TRUE;
    }
  else
    {
      log_pipe_unref(self->reader);
      self->reader = NULL;
    }
  return FALSE;
}