1
0
mirror of https://passt.top/passt synced 2024-09-28 10:05:47 +00:00

treewide: Use sa_family_t for address family variables

Sometimes we use sa_family_t for variables and parameters containing a
socket address family, other times we use a plain int.  Since sa_family_t
is what's actually used in struct sockaddr and friends, standardise on
that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-02-19 18:56:46 +11:00 committed by Stefano Brivio
parent 1e6f92b995
commit 4e08d9b9c6
11 changed files with 20 additions and 19 deletions

6
icmp.c
View File

@ -62,7 +62,7 @@ static struct icmp_id_sock icmp_id_map[IP_VERSIONS][ICMP_NUM_IDS];
* @af: Address family (AF_INET or AF_INET6) * @af: Address family (AF_INET or AF_INET6)
* @ref: epoll reference * @ref: epoll reference
*/ */
void icmp_sock_handler(const struct ctx *c, int af, union epoll_ref ref) void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref)
{ {
struct icmp_id_sock *const id_sock = af == AF_INET struct icmp_id_sock *const id_sock = af == AF_INET
? &icmp_id_map[V4][ref.icmp.id] : &icmp_id_map[V6][ref.icmp.id]; ? &icmp_id_map[V4][ref.icmp.id] : &icmp_id_map[V6][ref.icmp.id];
@ -156,7 +156,7 @@ static void icmp_ping_close(const struct ctx *c, struct icmp_id_sock *id_sock)
* Return: Newly opened ping socket fd, or -1 on failure * Return: Newly opened ping socket fd, or -1 on failure
*/ */
static int icmp_ping_new(const struct ctx *c, struct icmp_id_sock *id_sock, static int icmp_ping_new(const struct ctx *c, struct icmp_id_sock *id_sock,
int af, uint16_t id) sa_family_t af, uint16_t id)
{ {
uint8_t proto = af == AF_INET ? IPPROTO_ICMP : IPPROTO_ICMPV6; uint8_t proto = af == AF_INET ? IPPROTO_ICMP : IPPROTO_ICMPV6;
const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6"; const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6";
@ -209,7 +209,7 @@ cancel:
* *
* Return: count of consumed packets (always 1, even if malformed) * Return: count of consumed packets (always 1, even if malformed)
*/ */
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
const struct pool *p, const struct timespec *now) const struct pool *p, const struct timespec *now)
{ {

4
icmp.h
View File

@ -10,8 +10,8 @@
struct ctx; struct ctx;
void icmp_sock_handler(const struct ctx *c, int af, union epoll_ref ref); void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref);
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
const struct pool *p, const struct timespec *now); const struct pool *p, const struct timespec *now);
void icmp_timer(const struct ctx *c, const struct timespec *now); void icmp_timer(const struct ctx *c, const struct timespec *now);

View File

@ -60,7 +60,8 @@ static inline bool inany_equals(const union inany_addr *a,
* @af: Address family of @addr * @af: Address family of @addr
* @addr: struct in_addr (IPv4) or struct in6_addr (IPv6) * @addr: struct in_addr (IPv4) or struct in6_addr (IPv6)
*/ */
static inline void inany_from_af(union inany_addr *aa, int af, const void *addr) static inline void inany_from_af(union inany_addr *aa,
sa_family_t af, const void *addr)
{ {
if (af == AF_INET6) { if (af == AF_INET6) {
aa->a6 = *((struct in6_addr *)addr); aa->a6 = *((struct in6_addr *)addr);

12
tcp.c
View File

@ -1262,7 +1262,7 @@ static void tcp_hash_remove(const struct ctx *c,
* Return: connection pointer, if found, -ENOENT otherwise * Return: connection pointer, if found, -ENOENT otherwise
*/ */
static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c, static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c,
int af, const void *faddr, sa_family_t af, const void *faddr,
in_port_t eport, in_port_t fport) in_port_t eport, in_port_t fport)
{ {
union inany_addr aany; union inany_addr aany;
@ -1904,8 +1904,8 @@ static void tcp_bind_outbound(const struct ctx *c, int s, sa_family_t af)
* @optlen: Bytes in options: caller MUST ensure available length * @optlen: Bytes in options: caller MUST ensure available length
* @now: Current timestamp * @now: Current timestamp
*/ */
static void tcp_conn_from_tap(struct ctx *c, static void tcp_conn_from_tap(struct ctx *c, sa_family_t af,
int af, const void *saddr, const void *daddr, const void *saddr, const void *daddr,
const struct tcphdr *th, const char *opts, const struct tcphdr *th, const char *opts,
size_t optlen, const struct timespec *now) size_t optlen, const struct timespec *now)
{ {
@ -2479,7 +2479,7 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn,
* *
* Return: count of consumed packets * Return: count of consumed packets
*/ */
int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, int tcp_tap_handler(struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now) const struct pool *p, int idx, const struct timespec *now)
{ {
@ -2856,7 +2856,7 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events)
* *
* Return: fd for the new listening socket, negative error code on failure * Return: fd for the new listening socket, negative error code on failure
*/ */
static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, static int tcp_sock_init_af(const struct ctx *c, sa_family_t af, in_port_t port,
const void *addr, const char *ifname) const void *addr, const char *ifname)
{ {
union tcp_listen_epoll_ref tref = { union tcp_listen_epoll_ref tref = {
@ -3008,7 +3008,7 @@ static int tcp_ns_socks_init(void *arg)
* @pool: Pool of sockets to refill * @pool: Pool of sockets to refill
* @af: Address family to use * @af: Address family to use
*/ */
void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af) void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af)
{ {
int i; int i;

2
tcp.h
View File

@ -14,7 +14,7 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref);
void tcp_listen_handler(struct ctx *c, union epoll_ref ref, void tcp_listen_handler(struct ctx *c, union epoll_ref ref,
const struct timespec *now); const struct timespec *now);
void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events); void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events);
int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, int tcp_tap_handler(struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now); const struct pool *p, int idx, const struct timespec *now);
int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr,

View File

@ -160,7 +160,7 @@ bool tcp_splice_flow_defer(union flow *flow);
void tcp_splice_timer(const struct ctx *c, union flow *flow); void tcp_splice_timer(const struct ctx *c, union flow *flow);
int tcp_conn_pool_sock(int pool[]); int tcp_conn_pool_sock(int pool[]);
int tcp_conn_new_sock(const struct ctx *c, sa_family_t af); int tcp_conn_new_sock(const struct ctx *c, sa_family_t af);
void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af); void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af);
void tcp_splice_refill(const struct ctx *c); void tcp_splice_refill(const struct ctx *c);
#endif /* TCP_CONN_H */ #endif /* TCP_CONN_H */

View File

@ -399,7 +399,7 @@ static int tcp_splice_new(const struct ctx *c, struct tcp_splice_conn *conn,
*/ */
if (pif == PIF_SPLICE) { if (pif == PIF_SPLICE) {
int *p = CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4; int *p = CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4;
int af = CONN_V6(conn) ? AF_INET6 : AF_INET; sa_family_t af = CONN_V6(conn) ? AF_INET6 : AF_INET;
s = tcp_conn_pool_sock(p); s = tcp_conn_pool_sock(p);
if (s < 0) if (s < 0)

2
udp.c
View File

@ -816,7 +816,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
* #syscalls sendmmsg * #syscalls sendmmsg
*/ */
int udp_tap_handler(struct ctx *c, uint8_t pif, int udp_tap_handler(struct ctx *c, uint8_t pif,
int af, const void *saddr, const void *daddr, sa_family_t af, const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now) const struct pool *p, int idx, const struct timespec *now)
{ {
struct mmsghdr mm[UIO_MAXIOV]; struct mmsghdr mm[UIO_MAXIOV];

2
udp.h
View File

@ -11,7 +11,7 @@
void udp_portmap_clear(void); void udp_portmap_clear(void);
void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
const struct timespec *now); const struct timespec *now);
int udp_tap_handler(struct ctx *c, uint8_t pif, int af, int udp_tap_handler(struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now); const struct pool *p, int idx, const struct timespec *now);
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,

2
util.c
View File

@ -97,7 +97,7 @@ found:
* *
* Return: newly created socket, negative error code on failure * Return: newly created socket, negative error code on failure
*/ */
int sock_l4(const struct ctx *c, int af, uint8_t proto, int sock_l4(const struct ctx *c, sa_family_t af, uint8_t proto,
const void *bind_addr, const char *ifname, uint16_t port, const void *bind_addr, const char *ifname, uint16_t port,
uint32_t data) uint32_t data)
{ {

2
util.h
View File

@ -212,7 +212,7 @@ struct ipv6_opt_hdr {
__attribute__ ((weak)) int ffsl(long int i) { return __builtin_ffsl(i); } __attribute__ ((weak)) int ffsl(long int i) { return __builtin_ffsl(i); }
char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto,
size_t *dlen); size_t *dlen);
int sock_l4(const struct ctx *c, int af, uint8_t proto, int sock_l4(const struct ctx *c, sa_family_t af, uint8_t proto,
const void *bind_addr, const char *ifname, uint16_t port, const void *bind_addr, const char *ifname, uint16_t port,
uint32_t data); uint32_t data);
void sock_probe_mem(struct ctx *c); void sock_probe_mem(struct ctx *c);