Latest...
This commit is contained in:
@@ -680,6 +680,9 @@ ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
|
||||
|
||||
ls = cycle->listening.elts;
|
||||
for (i = 0; i < cycle->listening.nelts; i++) {
|
||||
if (ls[i].ignore) {
|
||||
continue;
|
||||
}
|
||||
p = ngx_sprintf(p, "%ud;", ls[i].fd);
|
||||
}
|
||||
|
||||
|
||||
+12
-3
@@ -11,12 +11,21 @@
|
||||
|
||||
#define nginx_version 1023002
|
||||
#define NGINX_VERSION "1.23.2"
|
||||
#define NGINX_VER "nginx/" NGINX_VERSION
|
||||
#define NGINX_VER "nginx/" NGINX_VERSION " by Hakase"
|
||||
|
||||
#ifndef NGINX_SERVER
|
||||
#define NGINX_SERVER "hakase"
|
||||
#endif
|
||||
|
||||
#define NGINX_SERVER_FULL NGINX_SERVER "/" NGINX_VERSION
|
||||
#define NGINX_ORIG "nginx/" NGINX_VERSION
|
||||
|
||||
#ifdef NGX_BUILD
|
||||
#define NGINX_VER_BUILD NGINX_VER " (" NGX_BUILD ")"
|
||||
#define NGINX_SERVER_FULL_BUILD NGINX_SERVER_FULL " (" NGX_BUILD ")"
|
||||
#define NGINX_VER_BUILD NGINX_VER " (" NGX_BUILD ")"
|
||||
#else
|
||||
#define NGINX_VER_BUILD NGINX_VER
|
||||
#define NGINX_SERVER_FULL_BUILD NGINX_SERVER_FULL
|
||||
#define NGINX_VER_BUILD NGINX_VER
|
||||
#endif
|
||||
|
||||
#define NGINX_VAR "NGINX"
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) Nginx, Inc.
|
||||
*/
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
#define NGX_BPF_LOGBUF_SIZE (16 * 1024)
|
||||
|
||||
|
||||
static ngx_inline int
|
||||
ngx_bpf(enum bpf_cmd cmd, union bpf_attr *attr, unsigned int size)
|
||||
{
|
||||
return syscall(__NR_bpf, cmd, attr, size);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_bpf_program_link(ngx_bpf_program_t *program, const char *symbol, int fd)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
ngx_bpf_reloc_t *rl;
|
||||
|
||||
rl = program->relocs;
|
||||
|
||||
for (i = 0; i < program->nrelocs; i++) {
|
||||
if (ngx_strcmp(rl[i].name, symbol) == 0) {
|
||||
program->ins[rl[i].offset].src_reg = 1;
|
||||
program->ins[rl[i].offset].imm = fd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ngx_bpf_load_program(ngx_log_t *log, ngx_bpf_program_t *program)
|
||||
{
|
||||
int fd;
|
||||
union bpf_attr attr;
|
||||
#if (NGX_DEBUG)
|
||||
char buf[NGX_BPF_LOGBUF_SIZE];
|
||||
#endif
|
||||
|
||||
ngx_memzero(&attr, sizeof(union bpf_attr));
|
||||
|
||||
attr.license = (uintptr_t) program->license;
|
||||
attr.prog_type = program->type;
|
||||
attr.insns = (uintptr_t) program->ins;
|
||||
attr.insn_cnt = program->nins;
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
/* for verifier errors */
|
||||
attr.log_buf = (uintptr_t) buf;
|
||||
attr.log_size = NGX_BPF_LOGBUF_SIZE;
|
||||
attr.log_level = 1;
|
||||
#endif
|
||||
|
||||
fd = ngx_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
||||
if (fd < 0) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
||||
"failed to load BPF program");
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
|
||||
"bpf verifier: %s", buf);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ngx_bpf_map_create(ngx_log_t *log, enum bpf_map_type type, int key_size,
|
||||
int value_size, int max_entries, uint32_t map_flags)
|
||||
{
|
||||
int fd;
|
||||
union bpf_attr attr;
|
||||
|
||||
ngx_memzero(&attr, sizeof(union bpf_attr));
|
||||
|
||||
attr.map_type = type;
|
||||
attr.key_size = key_size;
|
||||
attr.value_size = value_size;
|
||||
attr.max_entries = max_entries;
|
||||
attr.map_flags = map_flags;
|
||||
|
||||
fd = ngx_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
|
||||
if (fd < 0) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
||||
"failed to create BPF map");
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ngx_bpf_map_update(int fd, const void *key, const void *value, uint64_t flags)
|
||||
{
|
||||
union bpf_attr attr;
|
||||
|
||||
ngx_memzero(&attr, sizeof(union bpf_attr));
|
||||
|
||||
attr.map_fd = fd;
|
||||
attr.key = (uintptr_t) key;
|
||||
attr.value = (uintptr_t) value;
|
||||
attr.flags = flags;
|
||||
|
||||
return ngx_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ngx_bpf_map_delete(int fd, const void *key)
|
||||
{
|
||||
union bpf_attr attr;
|
||||
|
||||
ngx_memzero(&attr, sizeof(union bpf_attr));
|
||||
|
||||
attr.map_fd = fd;
|
||||
attr.key = (uintptr_t) key;
|
||||
|
||||
return ngx_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ngx_bpf_map_lookup(int fd, const void *key, void *value)
|
||||
{
|
||||
union bpf_attr attr;
|
||||
|
||||
ngx_memzero(&attr, sizeof(union bpf_attr));
|
||||
|
||||
attr.map_fd = fd;
|
||||
attr.key = (uintptr_t) key;
|
||||
attr.value = (uintptr_t) value;
|
||||
|
||||
return ngx_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) Nginx, Inc.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NGX_BPF_H_INCLUDED_
|
||||
#define _NGX_BPF_H_INCLUDED_
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
|
||||
#include <linux/bpf.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int offset;
|
||||
} ngx_bpf_reloc_t;
|
||||
|
||||
typedef struct {
|
||||
char *license;
|
||||
enum bpf_prog_type type;
|
||||
struct bpf_insn *ins;
|
||||
size_t nins;
|
||||
ngx_bpf_reloc_t *relocs;
|
||||
size_t nrelocs;
|
||||
} ngx_bpf_program_t;
|
||||
|
||||
|
||||
void ngx_bpf_program_link(ngx_bpf_program_t *program, const char *symbol,
|
||||
int fd);
|
||||
int ngx_bpf_load_program(ngx_log_t *log, ngx_bpf_program_t *program);
|
||||
|
||||
int ngx_bpf_map_create(ngx_log_t *log, enum bpf_map_type type, int key_size,
|
||||
int value_size, int max_entries, uint32_t map_flags);
|
||||
int ngx_bpf_map_update(int fd, const void *key, const void *value,
|
||||
uint64_t flags);
|
||||
int ngx_bpf_map_delete(int fd, const void *key);
|
||||
int ngx_bpf_map_lookup(int fd, const void *key, void *value);
|
||||
|
||||
#endif /* _NGX_BPF_H_INCLUDED_ */
|
||||
@@ -72,10 +72,6 @@ ngx_create_listening(ngx_conf_t *cf, struct sockaddr *sockaddr,
|
||||
|
||||
ngx_memcpy(ls->addr_text.data, text, len);
|
||||
|
||||
#if !(NGX_WIN32)
|
||||
ngx_rbtree_init(&ls->rbtree, &ls->sentinel, ngx_udp_rbtree_insert_value);
|
||||
#endif
|
||||
|
||||
ls->fd = (ngx_socket_t) -1;
|
||||
ls->type = SOCK_STREAM;
|
||||
|
||||
@@ -1037,6 +1033,12 @@ ngx_close_listening_sockets(ngx_cycle_t *cycle)
|
||||
ls = cycle->listening.elts;
|
||||
for (i = 0; i < cycle->listening.nelts; i++) {
|
||||
|
||||
#if (NGX_QUIC)
|
||||
if (ls[i].quic) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
c = ls[i].connection;
|
||||
|
||||
if (c) {
|
||||
|
||||
@@ -73,6 +73,7 @@ struct ngx_listening_s {
|
||||
unsigned reuseport:1;
|
||||
unsigned add_reuseport:1;
|
||||
unsigned keepalive:2;
|
||||
unsigned quic:1;
|
||||
|
||||
unsigned deferred_accept:1;
|
||||
unsigned delete_deferred:1;
|
||||
@@ -147,6 +148,10 @@ struct ngx_connection_s {
|
||||
|
||||
ngx_proxy_protocol_t *proxy_protocol;
|
||||
|
||||
#if (NGX_QUIC || NGX_COMPAT)
|
||||
ngx_quic_stream_t *quic;
|
||||
#endif
|
||||
|
||||
#if (NGX_SSL || NGX_COMPAT)
|
||||
ngx_ssl_connection_t *ssl;
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,7 @@ typedef struct ngx_connection_s ngx_connection_t;
|
||||
typedef struct ngx_thread_task_s ngx_thread_task_t;
|
||||
typedef struct ngx_ssl_s ngx_ssl_t;
|
||||
typedef struct ngx_proxy_protocol_s ngx_proxy_protocol_t;
|
||||
typedef struct ngx_quic_stream_s ngx_quic_stream_t;
|
||||
typedef struct ngx_ssl_connection_s ngx_ssl_connection_t;
|
||||
typedef struct ngx_udp_connection_s ngx_udp_connection_t;
|
||||
|
||||
@@ -82,6 +83,9 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
|
||||
#include <ngx_resolver.h>
|
||||
#if (NGX_OPENSSL)
|
||||
#include <ngx_event_openssl.h>
|
||||
#if (NGX_QUIC)
|
||||
#include <ngx_event_quic.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <ngx_process_cycle.h>
|
||||
#include <ngx_conf_file.h>
|
||||
@@ -91,6 +95,9 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
|
||||
#include <ngx_connection.h>
|
||||
#include <ngx_syslog.h>
|
||||
#include <ngx_proxy_protocol.h>
|
||||
#if (NGX_HAVE_BPF)
|
||||
#include <ngx_bpf.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define LF (u_char) '\n'
|
||||
|
||||
@@ -50,3 +50,63 @@ ngx_murmur_hash2(u_char *data, size_t len)
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
uint64_t
|
||||
ngx_murmur_hash2_64(u_char *data, size_t len, uint64_t seed)
|
||||
{
|
||||
uint64_t h, k;
|
||||
|
||||
h = seed ^ len;
|
||||
|
||||
while (len >= 8) {
|
||||
k = data[0];
|
||||
k |= data[1] << 8;
|
||||
k |= data[2] << 16;
|
||||
k |= data[3] << 24;
|
||||
k |= (uint64_t)data[4] << 32;
|
||||
k |= (uint64_t)data[5] << 40;
|
||||
k |= (uint64_t)data[6] << 48;
|
||||
k |= (uint64_t)data[7] << 56;
|
||||
|
||||
k *= 0xc6a4a7935bd1e995ull;
|
||||
k ^= k >> 47;
|
||||
k *= 0xc6a4a7935bd1e995ull;
|
||||
|
||||
h ^= k;
|
||||
h *= 0xc6a4a7935bd1e995ull;
|
||||
|
||||
data += 8;
|
||||
len -= 8;
|
||||
}
|
||||
|
||||
switch (len) {
|
||||
case 7:
|
||||
h ^= (uint64_t)data[6] << 48;
|
||||
/* fall through */
|
||||
case 6:
|
||||
h ^= (uint64_t)data[5] << 40;
|
||||
/* fall through */
|
||||
case 5:
|
||||
h ^= (uint64_t)data[4] << 32;
|
||||
/* fall through */
|
||||
case 4:
|
||||
h ^= data[3] << 24;
|
||||
/* fall through */
|
||||
case 3:
|
||||
h ^= data[2] << 16;
|
||||
/* fall through */
|
||||
case 2:
|
||||
h ^= data[1] << 8;
|
||||
/* fall through */
|
||||
case 1:
|
||||
h ^= data[0];
|
||||
h *= 0xc6a4a7935bd1e995ull;
|
||||
}
|
||||
|
||||
h ^= h >> 47;
|
||||
h *= 0xc6a4a7935bd1e995ull;
|
||||
h ^= h >> 47;
|
||||
|
||||
return h;
|
||||
}
|
||||
@@ -15,5 +15,7 @@
|
||||
|
||||
uint32_t ngx_murmur_hash2(u_char *data, size_t len);
|
||||
|
||||
uint64_t ngx_murmur_hash2_64(u_char *data, size_t len, uint64_t seed);
|
||||
|
||||
|
||||
#endif /* _NGX_MURMURHASH_H_INCLUDED_ */
|
||||
Reference in New Issue
Block a user