|
Packit |
c22fc9 |
/*
|
|
Packit |
c22fc9 |
* Soft: Keepalived is a failover program for the LVS project
|
|
Packit |
c22fc9 |
* <www.linuxvirtualserver.org>. It monitor & manipulate
|
|
Packit |
c22fc9 |
* a loadbalanced server pool using multi-layer checks.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* Part: check_http.c include file.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* Authors: Alexandre Cassen, <acassen@linux-vs.org>
|
|
Packit |
c22fc9 |
* Jan Holmberg, <jan@artech.net>
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
c22fc9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
c22fc9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
c22fc9 |
* See the GNU General Public License for more details.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* This program is free software; you can redistribute it and/or
|
|
Packit |
c22fc9 |
* modify it under the terms of the GNU General Public License
|
|
Packit |
c22fc9 |
* as published by the Free Software Foundation; either version
|
|
Packit |
c22fc9 |
* 2 of the License, or (at your option) any later version.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* Copyright (C) 2001-2017 Alexandre Cassen, <acassen@gmail.com>
|
|
Packit |
c22fc9 |
*/
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#ifndef _CHECK_HTTP_H
|
|
Packit |
c22fc9 |
#define _CHECK_HTTP_H
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* system includes */
|
|
Packit |
c22fc9 |
#include <sys/types.h>
|
|
Packit |
c22fc9 |
#include <stdbool.h>
|
|
Packit |
c22fc9 |
#include <openssl/md5.h>
|
|
Packit |
c22fc9 |
#include <openssl/ssl.h>
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_CHECK_
|
|
Packit |
c22fc9 |
#define PCRE2_CODE_UNIT_WIDTH 8
|
|
Packit |
c22fc9 |
#include <pcre2.h>
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_TIMERS_
|
|
Packit |
c22fc9 |
#include <time.h>
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
#include <stdbool.h>
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* local includes */
|
|
Packit |
c22fc9 |
#include "scheduler.h"
|
|
Packit |
c22fc9 |
#include "list.h"
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* Checker argument structure */
|
|
Packit |
c22fc9 |
/* ssl specific thread arguments defs */
|
|
Packit |
c22fc9 |
typedef struct _request {
|
|
Packit |
c22fc9 |
char *buffer;
|
|
Packit |
c22fc9 |
char *extracted;
|
|
Packit |
c22fc9 |
int error;
|
|
Packit |
c22fc9 |
int status_code;
|
|
Packit |
c22fc9 |
size_t len;
|
|
Packit |
c22fc9 |
SSL *ssl;
|
|
Packit |
c22fc9 |
BIO *bio;
|
|
Packit |
c22fc9 |
MD5_CTX context;
|
|
Packit |
c22fc9 |
size_t content_len;
|
|
Packit |
c22fc9 |
size_t rx_bytes;
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_CHECK_
|
|
Packit |
c22fc9 |
bool regex_matched;
|
|
Packit |
c22fc9 |
size_t start_offset; /* Offset into buffer to match from */
|
|
Packit |
c22fc9 |
size_t regex_subject_offset; /* Offset into web page of start of buffer */
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_TIMERS_
|
|
Packit |
c22fc9 |
struct timespec req_time;
|
|
Packit |
c22fc9 |
unsigned num_match_calls;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
} request_t;
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_CHECK_
|
|
Packit |
c22fc9 |
typedef struct _regex {
|
|
Packit |
c22fc9 |
unsigned char *pattern;
|
|
Packit |
c22fc9 |
int pcre2_options;
|
|
Packit |
c22fc9 |
pcre2_code *pcre2_reCompiled;
|
|
Packit |
c22fc9 |
pcre2_match_data *pcre2_match_data;
|
|
Packit |
c22fc9 |
uint32_t pcre2_max_lookbehind;
|
|
Packit |
c22fc9 |
unsigned use_count;
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_TIMERS_
|
|
Packit |
c22fc9 |
struct timespec regex_time;
|
|
Packit |
c22fc9 |
unsigned num_match_calls;
|
|
Packit |
c22fc9 |
unsigned num_regex_urls;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
} regex_t;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
typedef struct _url {
|
|
Packit |
c22fc9 |
char *path;
|
|
Packit |
c22fc9 |
uint8_t *digest;
|
|
Packit |
c22fc9 |
int status_code;
|
|
Packit |
c22fc9 |
char *virtualhost;
|
|
Packit |
c22fc9 |
ssize_t len_mismatch;
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_CHECK_
|
|
Packit |
c22fc9 |
bool regex_no_match;
|
|
Packit |
c22fc9 |
regex_t *regex;
|
|
Packit |
c22fc9 |
size_t regex_min_offset;
|
|
Packit |
c22fc9 |
size_t regex_max_offset; /* One beyond max offset */
|
|
Packit |
c22fc9 |
#ifndef PCRE2_DONT_USE_JIT
|
|
Packit |
c22fc9 |
bool regex_use_stack;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
} url_t;
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
typedef struct _http_checker {
|
|
Packit |
c22fc9 |
unsigned proto;
|
|
Packit |
c22fc9 |
unsigned url_it; /* current url checked index */
|
|
Packit |
c22fc9 |
request_t *req; /* GET buffer and SSL args */
|
|
Packit |
c22fc9 |
list url;
|
|
Packit |
c22fc9 |
char *virtualhost;
|
|
Packit |
c22fc9 |
#ifdef _HAVE_SSL_SET_TLSEXT_HOST_NAME_
|
|
Packit |
c22fc9 |
bool enable_sni;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
} http_checker_t;
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* global defs */
|
|
Packit |
c22fc9 |
#define GET_BUFFER_LENGTH 2048U
|
|
Packit |
c22fc9 |
#define MAX_BUFFER_LENGTH 4096U
|
|
Packit |
c22fc9 |
#define PROTO_HTTP 0x01
|
|
Packit |
c22fc9 |
#define PROTO_SSL 0x02
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* GET processing command */
|
|
Packit |
c22fc9 |
#define REQUEST_TEMPLATE "GET %s HTTP/1.0\r\n" \
|
|
Packit |
c22fc9 |
"User-Agent: KeepAliveClient\r\n" \
|
|
Packit |
c22fc9 |
"Host: %s%s\r\n\r\n"
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#define REQUEST_TEMPLATE_IPV6 "GET %s HTTP/1.0\r\n" \
|
|
Packit |
c22fc9 |
"User-Agent: KeepAliveClient\r\n" \
|
|
Packit |
c22fc9 |
"Host: [%s]%s\r\n\r\n"
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* macro utility */
|
|
Packit |
c22fc9 |
#define FMT_HTTP_RS(C) FMT_CHK(C)
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#ifdef _REGEX_DEBUG_
|
|
Packit |
c22fc9 |
extern bool do_regex_debug;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
#ifdef _WITH_REGEX_TIMERS_
|
|
Packit |
c22fc9 |
extern bool do_regex_timers;
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* Define prototypes */
|
|
Packit |
c22fc9 |
extern void install_http_check_keyword(void);
|
|
Packit |
c22fc9 |
extern int timeout_epilog(thread_t *, const char *);
|
|
Packit |
c22fc9 |
extern void http_process_response(request_t *, size_t, url_t *);
|
|
Packit |
c22fc9 |
extern int http_handle_response(thread_t *, unsigned char digest[16], bool);
|
|
Packit |
c22fc9 |
#ifdef THREAD_DUMP
|
|
Packit |
c22fc9 |
extern void register_check_http_addresses(void);
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#endif
|