コード例 #1
0
ファイル: socket.c プロジェクト: Robert-Xie/h2o
void h2o_socket_close(h2o_socket_t *sock)
{
    if (sock->ssl == NULL) {
        dispose_socket(sock, 0);
    } else {
        shutdown_ssl(sock, 0);
    }
}
コード例 #2
0
static void process_radius(struct radius_packet_t *pack, ssize_t len) {
  int attempts = 0;

try_again:

  if (attempts++ == 5) {
    syslog(LOG_ERR, "%s: Dropping RADIUS packet!", strerror(errno));
    return;
  }

  syslog(LOG_DEBUG, "%s:%s", __FILE__, __FUNCTION__);

  if (!server.conn.connected) {
    syslog(LOG_DEBUG, "RADSEC: Connecting to %s:2083",
           inet_ntoa(_options.radiusserver1));
    if (connect_ssl(&_options.radiusserver1, 2083)) {
      syslog(LOG_ERR, "%d Could not connect to RadSec server %s!",
             errno, inet_ntoa(_options.radiusserver1));
      syslog(LOG_DEBUG, "RADSEC: Connecting to %s:2083",
             inet_ntoa(_options.radiusserver1));
      if (connect_ssl(&_options.radiusserver2, 2083)) {
	syslog(LOG_ERR, "%d Could not connect to RadSec server %s!",
               errno, inet_ntoa(_options.radiusserver2));
      } else {
	syslog(LOG_DEBUG, "RADSEC: Connected to %s:2083",
               inet_ntoa(_options.radiusserver2));
	server.conn.connected = 1;
      }
    } else {
      syslog(LOG_DEBUG, "RADSEC: Connected to %s:2083",
             inet_ntoa(_options.radiusserver1));
      server.conn.connected = 1;
    }
  }

  if (!server.conn.connected) {
    sleep(1);
    goto try_again;
  }

  {
    int l = openssl_write(server.conn.sslcon, (char *)pack, len, 0);
    syslog(LOG_DEBUG, "ssl_write %d",l);
    if (l <= 0) {
      shutdown_ssl();
      /*
       *  Immediately start to reconnect
       */
      goto try_again;
    }
  }
}
コード例 #3
0
static void process_radius_reply() {
  uint8_t *d = (uint8_t *) &server.pack;
  int l = openssl_read(server.conn.sslcon, (char *)d, 4, 0);
  syslog(LOG_DEBUG, "reply %d", l);
  if (l == 4) {
    int len = ntohs(server.pack.length) - 4;
    l = openssl_read(server.conn.sslcon, (char *)(d + 4), len, 0);
    syslog(LOG_DEBUG, "reply %d", l);
    if (l == len) {
      syslog(LOG_DEBUG, "reply +%d", len);
      switch (server.pack.code) {
        case RADIUS_CODE_ACCESS_ACCEPT:
        case RADIUS_CODE_ACCESS_REJECT:
        case RADIUS_CODE_ACCESS_CHALLENGE:
          syslog(LOG_DEBUG, "reply auth %d", len);
          radius_pkt_send(server.radius_auth, &server.pack, &server.auth_peer);
          break;
        case RADIUS_CODE_ACCOUNTING_RESPONSE:
          syslog(LOG_DEBUG, "reply acct %d", len);
          radius_pkt_send(server.radius_acct, &server.pack, &server.acct_peer);
          break;
        case RADIUS_CODE_COA_REQUEST:
        case RADIUS_CODE_DISCONNECT_REQUEST:
        case RADIUS_CODE_STATUS_REQUEST:
          if (_options.coaport) {
            syslog(LOG_DEBUG, "reply coa %d", len);
            radius_pkt_send(server.radius_cli, &server.pack, &server.acct_peer);
          }
          break;
      }
    }
  }
  if (l <= 0) {
    shutdown_ssl();
  }
}