MINOR: quic: pass quic_dgram as obj_type for quic-initial rules

To extend quic-initial rules, pass quic_dgram instance to argument for
the various actions. As such, quic_dgram is now supported as an obj_type
and can be used in session origin field.
This commit is contained in:
Amaury Denoyelle 2024-07-19 16:04:22 +02:00
parent 1259700763
commit f91be2657e
7 changed files with 42 additions and 12 deletions

View File

@ -43,6 +43,9 @@ enum obj_type {
OBJ_TYPE_SC, /* object is a struct stconn */
OBJ_TYPE_STREAM, /* object is a struct stream */
OBJ_TYPE_CHECK, /* object is a struct check */
#ifdef USE_QUIC
OBJ_TYPE_DGRAM, /* object is a struct quic_dgram */
#endif
OBJ_TYPE_ENTRIES /* last one : number of entries */
} __attribute__((packed)) ;

View File

@ -30,6 +30,7 @@
#include <haproxy/obj_type-t.h>
#include <haproxy/pool.h>
#include <haproxy/proxy-t.h>
#include <haproxy/quic_sock-t.h>
#include <haproxy/server-t.h>
#include <haproxy/stream-t.h>
@ -54,6 +55,9 @@ static inline const char *obj_type_name(const enum obj_type *t)
case OBJ_TYPE_SC: return "SC";
case OBJ_TYPE_STREAM: return "STREAM";
case OBJ_TYPE_CHECK: return "CHECK";
#ifdef USE_QUIC
case OBJ_TYPE_DGRAM: return "DGRAM";
#endif
default: return "!INVAL!";
}
}
@ -185,6 +189,20 @@ static inline struct check *objt_check(enum obj_type *t)
return __objt_check(t);
}
#ifdef USE_QUIC
static inline struct quic_dgram *__objt_dgram(enum obj_type *t)
{
return container_of(t, struct quic_dgram, obj_type);
}
static inline struct quic_dgram *objt_dgram(enum obj_type *t)
{
if (!t || *t != OBJ_TYPE_DGRAM)
return NULL;
return __objt_dgram(t);
}
#endif
static inline void *obj_base_ptr(enum obj_type *t)
{
switch (obj_type(t)) {
@ -199,6 +217,9 @@ static inline void *obj_base_ptr(enum obj_type *t)
case OBJ_TYPE_SC: return __objt_sc(t);
case OBJ_TYPE_STREAM: return __objt_stream(t);
case OBJ_TYPE_CHECK: return __objt_check(t);
#ifdef USE_QUIC
case OBJ_TYPE_DGRAM: return __objt_dgram(t);
#endif
default: return t; // exact pointer for invalid case
}
}

View File

@ -1,17 +1,15 @@
#ifndef _HAPROXY_QUIC_RULES_H
#define _HAPROXY_QUIC_RULES_H
#include <sys/socket.h>
#include <haproxy/action-t.h>
#include <haproxy/quic_sock-t.h>
struct listener;
struct quic_dgram;
extern struct action_kw_list quic_init_actions_list;
int quic_init_exec_rules(struct listener *li,
struct sockaddr_storage *saddr,
struct sockaddr_storage *daddr);
int quic_init_exec_rules(struct listener *li, struct quic_dgram *dgram);
struct action_kw *action_quic_init_custom(const char *kw);

View File

@ -3,6 +3,7 @@
#ifdef USE_QUIC
#include <haproxy/buf-t.h>
#include <haproxy/obj_type-t.h>
/* QUIC socket allocation strategy. */
enum quic_sock_mode {
@ -27,6 +28,7 @@ struct quic_receiver_buf {
/* QUIC datagram */
struct quic_dgram {
enum obj_type obj_type;
void *owner;
unsigned char *buf;
size_t len;

View File

@ -4,14 +4,16 @@
#include <haproxy/action.h>
#include <haproxy/list.h>
#include <haproxy/listener.h>
#include <haproxy/obj_type.h>
#include <haproxy/proxy-t.h>
#include <haproxy/quic_sock-t.h>
#include <haproxy/sample-t.h>
#include <haproxy/session-t.h>
/* Execute registered quic-initial rules on proxy owning <li> listener. */
int quic_init_exec_rules(struct listener *li,
struct sockaddr_storage *saddr,
struct sockaddr_storage *daddr)
/* Execute registered quic-initial rules on proxy owning <li> listener after
* <dgram> reception.
*/
int quic_init_exec_rules(struct listener *li, struct quic_dgram *dgram)
{
static THREAD_LOCAL struct session rule_sess;
struct act_rule *rule;
@ -26,8 +28,9 @@ int quic_init_exec_rules(struct listener *li,
*/
rule_sess.fe = px;
rule_sess.listener = li;
rule_sess.src = saddr;
rule_sess.dst = daddr;
rule_sess.src = &dgram->saddr;
rule_sess.dst = &dgram->daddr;
rule_sess.origin = &dgram->obj_type;
list_for_each_entry(rule, &px->quic_init_rules, list) {
ret = ACL_TEST_PASS;

View File

@ -1607,7 +1607,7 @@ static struct quic_conn *quic_rx_pkt_retrieve_conn(struct quic_rx_packet *pkt,
goto err;
}
if (!quic_init_exec_rules(l, &dgram->saddr, &dgram->daddr)) {
if (!quic_init_exec_rules(l, dgram)) {
TRACE_USER("drop datagram on quic-initial rules", QUIC_EV_CONN_LPKT, NULL, NULL, NULL, pkt->version);
goto err;
}

View File

@ -29,6 +29,7 @@
#include <haproxy/list.h>
#include <haproxy/listener.h>
#include <haproxy/log.h>
#include <haproxy/obj_type.h>
#include <haproxy/pool.h>
#include <haproxy/protocol-t.h>
#include <haproxy/proto_quic.h>
@ -285,6 +286,7 @@ static int quic_lstnr_dgram_dispatch(unsigned char *pos, size_t len, void *owner
}
/* All the members must be initialized! */
dgram->obj_type = OBJ_TYPE_DGRAM;
dgram->owner = owner;
dgram->buf = pos;
dgram->len = len;
@ -849,6 +851,7 @@ int qc_rcv_buf(struct quic_conn *qc)
b_add(&buf, ret);
new_dgram->obj_type = OBJ_TYPE_DGRAM;
new_dgram->buf = dgram_buf;
new_dgram->len = ret;
new_dgram->dcid_len = 0;