mirror of
https://passt.top/passt
synced 2024-12-22 13:45:32 +00:00
udp: Rename UDP listening sockets
EPOLL_TYPE_UDP is now only used for "listening" sockets; long lived sockets which can initiate new flows. Rename to EPOLL_TYPE_UDP_LISTEN and associated functions to match. Along with that, remove the .orig field from union udp_listen_epoll_ref, since it is now always true. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
d29fa0856e
commit
882599e180
@ -20,8 +20,8 @@ enum epoll_type {
|
|||||||
EPOLL_TYPE_TCP_LISTEN,
|
EPOLL_TYPE_TCP_LISTEN,
|
||||||
/* timerfds used for TCP timers */
|
/* timerfds used for TCP timers */
|
||||||
EPOLL_TYPE_TCP_TIMER,
|
EPOLL_TYPE_TCP_TIMER,
|
||||||
/* UDP sockets */
|
/* UDP "listening" sockets */
|
||||||
EPOLL_TYPE_UDP,
|
EPOLL_TYPE_UDP_LISTEN,
|
||||||
/* UDP socket for replies on a specific flow */
|
/* UDP socket for replies on a specific flow */
|
||||||
EPOLL_TYPE_UDP_REPLY,
|
EPOLL_TYPE_UDP_REPLY,
|
||||||
/* ICMP/ICMPv6 ping sockets */
|
/* ICMP/ICMPv6 ping sockets */
|
||||||
|
6
passt.c
6
passt.c
@ -66,7 +66,7 @@ char *epoll_type_str[] = {
|
|||||||
[EPOLL_TYPE_TCP_SPLICE] = "connected spliced TCP socket",
|
[EPOLL_TYPE_TCP_SPLICE] = "connected spliced TCP socket",
|
||||||
[EPOLL_TYPE_TCP_LISTEN] = "listening TCP socket",
|
[EPOLL_TYPE_TCP_LISTEN] = "listening TCP socket",
|
||||||
[EPOLL_TYPE_TCP_TIMER] = "TCP timer",
|
[EPOLL_TYPE_TCP_TIMER] = "TCP timer",
|
||||||
[EPOLL_TYPE_UDP] = "UDP socket",
|
[EPOLL_TYPE_UDP_LISTEN] = "listening UDP socket",
|
||||||
[EPOLL_TYPE_UDP_REPLY] = "UDP reply socket",
|
[EPOLL_TYPE_UDP_REPLY] = "UDP reply socket",
|
||||||
[EPOLL_TYPE_PING] = "ICMP/ICMPv6 ping socket",
|
[EPOLL_TYPE_PING] = "ICMP/ICMPv6 ping socket",
|
||||||
[EPOLL_TYPE_NSQUIT_INOTIFY] = "namespace inotify watch",
|
[EPOLL_TYPE_NSQUIT_INOTIFY] = "namespace inotify watch",
|
||||||
@ -347,8 +347,8 @@ loop:
|
|||||||
case EPOLL_TYPE_TCP_TIMER:
|
case EPOLL_TYPE_TCP_TIMER:
|
||||||
tcp_timer_handler(&c, ref);
|
tcp_timer_handler(&c, ref);
|
||||||
break;
|
break;
|
||||||
case EPOLL_TYPE_UDP:
|
case EPOLL_TYPE_UDP_LISTEN:
|
||||||
udp_buf_sock_handler(&c, ref, eventmask, &now);
|
udp_listen_sock_handler(&c, ref, eventmask, &now);
|
||||||
break;
|
break;
|
||||||
case EPOLL_TYPE_UDP_REPLY:
|
case EPOLL_TYPE_UDP_REPLY:
|
||||||
udp_reply_sock_handler(&c, ref, eventmask, &now);
|
udp_reply_sock_handler(&c, ref, eventmask, &now);
|
||||||
|
2
passt.h
2
passt.h
@ -48,7 +48,7 @@ union epoll_ref {
|
|||||||
uint32_t flow;
|
uint32_t flow;
|
||||||
flow_sidx_t flowside;
|
flow_sidx_t flowside;
|
||||||
union tcp_listen_epoll_ref tcp_listen;
|
union tcp_listen_epoll_ref tcp_listen;
|
||||||
union udp_epoll_ref udp;
|
union udp_listen_epoll_ref udp;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
int nsdir_fd;
|
int nsdir_fd;
|
||||||
};
|
};
|
||||||
|
25
udp.c
25
udp.c
@ -448,10 +448,7 @@ static flow_sidx_t udp_flow_from_sock(const struct ctx *c, union epoll_ref ref,
|
|||||||
union flow *flow;
|
union flow *flow;
|
||||||
flow_sidx_t sidx;
|
flow_sidx_t sidx;
|
||||||
|
|
||||||
ASSERT(ref.type == EPOLL_TYPE_UDP);
|
ASSERT(ref.type == EPOLL_TYPE_UDP_LISTEN);
|
||||||
|
|
||||||
if (!ref.udp.orig)
|
|
||||||
return FLOW_SIDX_NONE;
|
|
||||||
|
|
||||||
sidx = flow_lookup_sa(c, IPPROTO_UDP, ref.udp.pif, &meta->s_in, ref.udp.port);
|
sidx = flow_lookup_sa(c, IPPROTO_UDP, ref.udp.pif, &meta->s_in, ref.udp.port);
|
||||||
if ((uflow = udp_at_sidx(sidx))) {
|
if ((uflow = udp_at_sidx(sidx))) {
|
||||||
@ -693,7 +690,7 @@ static int udp_sock_recv(const struct ctx *c, int s, uint32_t events,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* udp_buf_sock_handler() - Handle new data from socket
|
* udp_listen_sock_handler() - Handle new data from socket
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @ref: epoll reference
|
* @ref: epoll reference
|
||||||
* @events: epoll events bitmap
|
* @events: epoll events bitmap
|
||||||
@ -701,8 +698,8 @@ static int udp_sock_recv(const struct ctx *c, int s, uint32_t events,
|
|||||||
*
|
*
|
||||||
* #syscalls recvmmsg
|
* #syscalls recvmmsg
|
||||||
*/
|
*/
|
||||||
void udp_buf_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
|
void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref,
|
||||||
const struct timespec *now)
|
uint32_t events, const struct timespec *now)
|
||||||
{
|
{
|
||||||
struct mmsghdr *mmh_recv = ref.udp.v6 ? udp6_mh_recv : udp4_mh_recv;
|
struct mmsghdr *mmh_recv = ref.udp.v6 ? udp6_mh_recv : udp4_mh_recv;
|
||||||
int n, i;
|
int n, i;
|
||||||
@ -974,7 +971,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif,
|
|||||||
int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
||||||
const void *addr, const char *ifname, in_port_t port)
|
const void *addr, const char *ifname, in_port_t port)
|
||||||
{
|
{
|
||||||
union udp_epoll_ref uref = { .orig = true, .port = port };
|
union udp_listen_epoll_ref uref = { .port = port };
|
||||||
int s, r4 = FD_REF_MAX + 1, r6 = FD_REF_MAX + 1;
|
int s, r4 = FD_REF_MAX + 1, r6 = FD_REF_MAX + 1;
|
||||||
|
|
||||||
ASSERT(!c->no_udp);
|
ASSERT(!c->no_udp);
|
||||||
@ -988,12 +985,12 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
|||||||
uref.v6 = 0;
|
uref.v6 = 0;
|
||||||
|
|
||||||
if (!ns) {
|
if (!ns) {
|
||||||
r4 = s = sock_l4(c, AF_INET, EPOLL_TYPE_UDP, addr,
|
r4 = s = sock_l4(c, AF_INET, EPOLL_TYPE_UDP_LISTEN,
|
||||||
ifname, port, uref.u32);
|
addr, ifname, port, uref.u32);
|
||||||
|
|
||||||
udp_splice_init[V4][port] = s < 0 ? -1 : s;
|
udp_splice_init[V4][port] = s < 0 ? -1 : s;
|
||||||
} else {
|
} else {
|
||||||
r4 = s = sock_l4(c, AF_INET, EPOLL_TYPE_UDP,
|
r4 = s = sock_l4(c, AF_INET, EPOLL_TYPE_UDP_LISTEN,
|
||||||
&in4addr_loopback,
|
&in4addr_loopback,
|
||||||
ifname, port, uref.u32);
|
ifname, port, uref.u32);
|
||||||
udp_splice_ns[V4][port] = s < 0 ? -1 : s;
|
udp_splice_ns[V4][port] = s < 0 ? -1 : s;
|
||||||
@ -1004,12 +1001,12 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
|||||||
uref.v6 = 1;
|
uref.v6 = 1;
|
||||||
|
|
||||||
if (!ns) {
|
if (!ns) {
|
||||||
r6 = s = sock_l4(c, AF_INET6, EPOLL_TYPE_UDP, addr,
|
r6 = s = sock_l4(c, AF_INET6, EPOLL_TYPE_UDP_LISTEN,
|
||||||
ifname, port, uref.u32);
|
addr, ifname, port, uref.u32);
|
||||||
|
|
||||||
udp_splice_init[V6][port] = s < 0 ? -1 : s;
|
udp_splice_init[V6][port] = s < 0 ? -1 : s;
|
||||||
} else {
|
} else {
|
||||||
r6 = s = sock_l4(c, AF_INET6, EPOLL_TYPE_UDP,
|
r6 = s = sock_l4(c, AF_INET6, EPOLL_TYPE_UDP_LISTEN,
|
||||||
&in6addr_loopback,
|
&in6addr_loopback,
|
||||||
ifname, port, uref.u32);
|
ifname, port, uref.u32);
|
||||||
udp_splice_ns[V6][port] = s < 0 ? -1 : s;
|
udp_splice_ns[V6][port] = s < 0 ? -1 : s;
|
||||||
|
12
udp.h
12
udp.h
@ -9,8 +9,8 @@
|
|||||||
#define UDP_TIMER_INTERVAL 1000 /* ms */
|
#define UDP_TIMER_INTERVAL 1000 /* ms */
|
||||||
|
|
||||||
void udp_portmap_clear(void);
|
void udp_portmap_clear(void);
|
||||||
void udp_buf_sock_handler(const struct ctx *c, union epoll_ref ref,
|
void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref,
|
||||||
uint32_t events, const struct timespec *now);
|
uint32_t events, const struct timespec *now);
|
||||||
void udp_reply_sock_handler(const struct ctx *c, union epoll_ref ref,
|
void udp_reply_sock_handler(const struct ctx *c, union epoll_ref ref,
|
||||||
uint32_t events, const struct timespec *now);
|
uint32_t events, const struct timespec *now);
|
||||||
int udp_tap_handler(const struct ctx *c, uint8_t pif,
|
int udp_tap_handler(const struct ctx *c, uint8_t pif,
|
||||||
@ -23,19 +23,17 @@ void udp_timer(struct ctx *c, const struct timespec *now);
|
|||||||
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
|
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* union udp_epoll_ref - epoll reference portion for TCP connections
|
* union udp_listen_epoll_ref - epoll reference for "listening" UDP sockets
|
||||||
* @port: Source port for connected sockets, bound port otherwise
|
* @port: Source port for connected sockets, bound port otherwise
|
||||||
* @pif: pif for this socket
|
* @pif: pif for this socket
|
||||||
* @orig: Set if a spliced socket which can originate "connections"
|
|
||||||
* @v6: Set for IPv6 sockets or connections
|
* @v6: Set for IPv6 sockets or connections
|
||||||
* @u32: Opaque u32 value of reference
|
* @u32: Opaque u32 value of reference
|
||||||
*/
|
*/
|
||||||
union udp_epoll_ref {
|
union udp_listen_epoll_ref {
|
||||||
struct {
|
struct {
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
uint8_t pif;
|
uint8_t pif;
|
||||||
bool orig:1,
|
bool v6:1;
|
||||||
v6:1;
|
|
||||||
};
|
};
|
||||||
uint32_t u32;
|
uint32_t u32;
|
||||||
};
|
};
|
||||||
|
2
util.c
2
util.c
@ -61,7 +61,7 @@ int sock_l4_sa(const struct ctx *c, enum epoll_type type,
|
|||||||
proto = IPPROTO_TCP;
|
proto = IPPROTO_TCP;
|
||||||
socktype = SOCK_STREAM | SOCK_NONBLOCK;
|
socktype = SOCK_STREAM | SOCK_NONBLOCK;
|
||||||
break;
|
break;
|
||||||
case EPOLL_TYPE_UDP:
|
case EPOLL_TYPE_UDP_LISTEN:
|
||||||
case EPOLL_TYPE_UDP_REPLY:
|
case EPOLL_TYPE_UDP_REPLY:
|
||||||
proto = IPPROTO_UDP;
|
proto = IPPROTO_UDP;
|
||||||
socktype = SOCK_DGRAM | SOCK_NONBLOCK;
|
socktype = SOCK_DGRAM | SOCK_NONBLOCK;
|
||||||
|
Loading…
Reference in New Issue
Block a user