MT#55283 upgrade control_ng_process args

Update the sockaddr_t to an endpoint_t and change the generic pointer to
a more type-safe argument

Closes #2176
Closes #2178

Change-Id: Ib734079051a2a8916eeae9942df3ea53a1637985
pull/2188/head
Richard Fuchs 2 months ago
parent b3de179087
commit 69b74ac957

@ -919,9 +919,9 @@ send_resp:
CH(homer_trace_msg_out, hctx, reply);
}
int control_ng_process(str *buf, const endpoint_t *sin, char *addr, const sockaddr_t *local,
void (*cb)(str *, str *, const endpoint_t *, const sockaddr_t *, void *),
void *p1, struct obj *ref)
int control_ng_process(str *buf, const endpoint_t *sin, char *addr, const endpoint_t *local,
void (*cb)(str *, str *, const endpoint_t *, const endpoint_t *, ng_cb_arg),
ng_cb_arg a, struct obj *ref)
{
str data;
str_chr_str(&data, buf, ' ');
@ -941,14 +941,14 @@ int control_ng_process(str *buf, const endpoint_t *sin, char *addr, const sockad
ilogs(control, LOG_INFO, "Detected command from %s as a duplicate", addr);
ng_ctx hctx = {.sin_ep = sin,
.local_ep = p1 ? &(((socket_t*)p1)->local) : NULL,
.local_ep = local ?: NULL,
.cookie = cookie,
.command = cached->command,
.callid = cached->callid,
.should_trace = should_trace_msg(cached->command)};
CH(homer_trace_msg_in, &hctx, &data);
cb(&cookie, &cached->reply, sin, local, p1);
cb(&cookie, &cached->reply, sin, local, a);
CH(homer_trace_msg_out, &hctx, &cached->reply);
cache_entry_free(cached);
@ -959,37 +959,36 @@ int control_ng_process(str *buf, const endpoint_t *sin, char *addr, const sockad
g_autoptr(ng_buffer) ngbuf = NULL;
ng_ctx hctx = {.sin_ep = sin,
.local_ep = p1 ? &(((socket_t*)p1)->local) : NULL,
.local_ep = local ?: NULL,
.cookie = cookie,
.command = -1};
control_ng_process_payload(trace_ng ? &hctx : NULL,
&reply, &data, sin, addr, ref, &ngbuf);
cb(&cookie, &reply, sin, local, p1);
cb(&cookie, &reply, sin, local, a);
cache_entry ce = {.reply = reply, .command = hctx.command, .callid = hctx.callid};
cookie_cache_insert(&ng_cookie_cache, &cookie, &ce);
return 0;
}
int control_ng_process_plain(str *data, const endpoint_t *sin, char *addr, const sockaddr_t *local,
void (*cb)(str *, str *, const endpoint_t *, const sockaddr_t *, void *),
void *p1, struct obj *ref)
int control_ng_process_plain(str *data, const endpoint_t *sin, char *addr, const endpoint_t *local,
void (*cb)(str *, str *, const endpoint_t *, const endpoint_t *, ng_cb_arg),
ng_cb_arg a, struct obj *ref)
{
g_autoptr(ng_buffer) ngbuf = NULL;
str reply;
control_ng_process_payload(NULL, &reply, data, sin, addr, ref, &ngbuf);
cb(NULL, &reply, sin, local, p1);
cb(NULL, &reply, sin, local, a);
return 0;
}
INLINE void control_ng_send_generic(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from,
void *p1)
INLINE void control_ng_send_generic(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
socket_t *ul)
{
socket_t *ul = p1;
struct iovec iov[3];
unsigned int iovlen;
@ -1002,13 +1001,17 @@ INLINE void control_ng_send_generic(str *cookie, str *body, const endpoint_t *si
iov[2].iov_base = body->s;
iov[2].iov_len = body->len;
socket_sendiov(ul, iov, iovlen, sin, from);
socket_sendiov(ul, iov, iovlen, sin, &from->address);
}
static void control_ng_send(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from, void *p1) {
control_ng_send_generic(cookie, body, sin, NULL, p1);
static void control_ng_send(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
socket_t *s)
{
control_ng_send_generic(cookie, body, sin, NULL, s);
}
static void control_ng_send_from(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from, void *p1) {
control_ng_send_generic(cookie, body, sin, from, p1);
static void control_ng_send_from(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
socket_t *s)
{
control_ng_send_generic(cookie, body, sin, from, s);
}
static void control_ng_incoming(struct obj *obj, struct udp_buffer *udp_buf)

@ -59,7 +59,7 @@ static void control_udp_incoming(struct obj *obj, struct udp_buffer *udp_buf) {
iovlen = 2;
}
socket_sendiov(udp_buf->listener, iov, iovlen, &udp_buf->sin, &udp_buf->local_addr);
socket_sendiov(udp_buf->listener, iov, iovlen, &udp_buf->sin, &udp_buf->local_addr.address);
pcre2_substring_list_free((SUBSTRING_FREE_ARG) out);
pcre2_match_data_free(md);
@ -76,7 +76,8 @@ static void control_udp_incoming(struct obj *obj, struct udp_buffer *udp_buf) {
if (ce) {
reply = ce->reply;
ilogs(control, LOG_INFO, "Detected command from udp:%s as a duplicate", udp_buf->addr);
socket_sendto_from(udp_buf->listener, reply.s, reply.len, &udp_buf->sin, &udp_buf->local_addr);
socket_sendto_from(udp_buf->listener, reply.s, reply.len, &udp_buf->sin,
&udp_buf->local_addr.address);
cache_entry_free(ce);
goto out;
}
@ -119,11 +120,12 @@ static void control_udp_incoming(struct obj *obj, struct udp_buffer *udp_buf) {
iov[2].iov_len = 9;
iovlen++;
}
socket_sendiov(udp_buf->listener, iov, iovlen, &udp_buf->sin, &udp_buf->local_addr);
socket_sendiov(udp_buf->listener, iov, iovlen, &udp_buf->sin, &udp_buf->local_addr.address);
}
if (reply.len) {
socket_sendto_from(udp_buf->listener, reply.s, reply.len, &udp_buf->sin, &udp_buf->local_addr);
socket_sendto_from(udp_buf->listener, reply.s, reply.len, &udp_buf->sin,
&udp_buf->local_addr.address);
str callid = STR_NULL;
cache_entry new_ce = {.reply = reply, .callid = callid};

@ -38,10 +38,11 @@ static void udp_listener_incoming(int fd, void *p) {
udp_buf = obj_alloc0(struct udp_buffer, NULL);
udp_buf->str.s = udp_buf->buf + RTP_BUFFER_HEAD_ROOM;
udp_buf->listener = cb->ul;
udp_buf->local_addr.port = cb->ul->local.port;
}
len = socket_recvfrom_to(udp_buf->listener, udp_buf->str.s, MAX_UDP_LENGTH, &udp_buf->sin,
&udp_buf->local_addr);
&udp_buf->local_addr.address);
if (len < 0) {
if (errno == EINTR)
continue;

@ -533,23 +533,20 @@ static const char *websocket_cli_process(struct websocket_message *wm) {
}
static void websocket_ng_send_ws(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from,
void *p1)
static void websocket_ng_send_ws(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
struct websocket_conn *wc)
{
struct websocket_conn *wc = p1;
{
LOCK(&wc->lock);
if (cookie) {
__websocket_queue_raw(wc, cookie->s, cookie->len);
__websocket_queue_raw(wc, " ", 1);
}
__websocket_queue_raw(wc, body->s, body->len);
__websocket_write_binary(wc, NULL, 0);
__websocket_write_done(wc);
LOCK(&wc->lock);
if (cookie) {
__websocket_queue_raw(wc, cookie->s, cookie->len);
__websocket_queue_raw(wc, " ", 1);
}
__websocket_queue_raw(wc, body->s, body->len);
__websocket_write_binary(wc, NULL, 0);
__websocket_write_done(wc);
}
static void websocket_ng_send_http(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from,
static void websocket_ng_send_http(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
struct websocket_conn *wc, const char *content_type)
{
LOCK(&wc->lock);
@ -564,16 +561,16 @@ static void websocket_ng_send_http(str *cookie, str *body, const endpoint_t *sin
__websocket_write_done(wc);
}
static void websocket_ng_send_http_ng(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from,
void *p1)
static void websocket_ng_send_http_ng(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
struct websocket_conn *wc)
{
websocket_ng_send_http(cookie, body, sin, from, p1, "application/x-rtpengine-ng");
websocket_ng_send_http(cookie, body, sin, from, wc, "application/x-rtpengine-ng");
}
static void websocket_ng_send_http_json(str *cookie, str *body, const endpoint_t *sin, const sockaddr_t *from,
void *p1)
static void websocket_ng_send_http_json(str *cookie, str *body, const endpoint_t *sin, const endpoint_t *from,
struct websocket_conn *wc)
{
websocket_ng_send_http(cookie, body, sin, from, p1, "application/json");
websocket_ng_send_http(cookie, body, sin, from, wc, "application/json");
}
static void __ng_buf_free(struct websocket_ng_buf *buf) {

@ -177,10 +177,19 @@ struct control_ng *control_ng_tcp_new(const endpoint_t *);
void notify_ng_tcp_clients(str *);
void control_ng_init(void);
void control_ng_cleanup(void);
int control_ng_process(str *buf, const endpoint_t *sin, char *addr, const sockaddr_t *local,
void (*cb)(str *, str *, const endpoint_t *, const sockaddr_t *, void *), void *p1, struct obj *);
int control_ng_process_plain(str *buf, const endpoint_t *sin, char *addr, const sockaddr_t *local,
void (*cb)(str *, str *, const endpoint_t *, const sockaddr_t *, void *), void *p1, struct obj *);
typedef union {
socket_t *s;
struct websocket_conn *wc;
} ng_cb_arg __attribute__ ((__transparent_union__));
int control_ng_process(str *buf, const endpoint_t *sin, char *addr, const endpoint_t *local,
void (*cb)(str *, str *, const endpoint_t *, const endpoint_t *, ng_cb_arg),
ng_cb_arg, struct obj *);
int control_ng_process_plain(str *buf, const endpoint_t *sin, char *addr, const endpoint_t *local,
void (*cb)(str *, str *, const endpoint_t *, const endpoint_t *, ng_cb_arg),
ng_cb_arg, struct obj *);
void init_ng_tracing(void);
ng_buffer *ng_buffer_new(struct obj *ref);

@ -16,7 +16,7 @@ struct udp_buffer {
char buf[MAX_UDP_LENGTH + RTP_BUFFER_TAIL_ROOM + RTP_BUFFER_HEAD_ROOM + 1];
str str;
endpoint_t sin;
sockaddr_t local_addr;
endpoint_t local_addr;
char addr[64];
socket_t *listener;
};

Loading…
Cancel
Save